made the jump to ring 3

This commit is contained in:
2026-06-16 21:53:38 -04:00
parent 171cbd21bc
commit 0cb7311911
4 changed files with 35 additions and 278 deletions

View File

@@ -13,4 +13,28 @@ enable_interrupts:
.global io_wait
io_wait:
outb %al, $0x80
ret
ret
.global liftoff
liftoff:
cli
mov 4(%esp), %ecx
mov 8(%esp), %ebx
mov $0x23, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
push $0x23
push %ebx
push $0x202
push $0x1B
push %ecx
xor %eax, %eax
xor %edx, %edx
iret

View File

@@ -49,13 +49,13 @@ void common_interrupt_handler(struct registers *args) {
uint32_t faulting_address;
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("\n--- PAGE FAULT ---\n");
kprintf("Faulting Virtual Address (CR2): 0x%x\n", faulting_address);
kprintf("Faulted Virtual Address: 0x%x\n", faulting_address);
kprintf("Error Code: 0x%x\n", args->error_code);
kprintf("Instruction Pointer (EIP): 0x%x\n", args->eip);
kprintf("Instruction Pointer: 0x%x\n", args->eip);
kprintf("Caused by: %s, %s, running in %s mode\n",
(args->error_code & 0x01) ? "Page protection violation" : "Non-present page",
(args->error_code & 0x02) ? "Write operation" : "Read operation",
(args->error_code & 0x04) ? "User (Ring 3)" : "Supervisor (Ring 0)");
(args->error_code & 0x01) ? "Protection Violation" : "Page Not Present",
(args->error_code & 0x02) ? "Write" : "Read",
(args->error_code & 0x04) ? "User" : "Supervisor");
while(1);
break;
}

View File

@@ -86,6 +86,11 @@ void load_origin_program(multiboot_info* mbi) {
map_page(0xBFFFF000, stack_paddr, PAGE_PRESENT | PAGE_WRITABLE | PAGE_USER);
kprintf("program loaded into memory @ [virt] 0x%x\n", elf->e_entry);
extern void liftoff(uint32_t entry, uint32_t stack_top);
kprintf("launching origin process");
uint32_t stack_top = 0xBFFFF000 + 4095;
liftoff(elf->e_entry, stack_top);
}
void kmain(uint32_t magic, multiboot_info* mbi) {