[SOLVED] Stuck on page fault when loading new page directory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
exbotanical
Posts: 2
Joined: Mon Oct 30, 2023 9:12 pm
Libera.chat IRC: goldmund

[SOLVED] Stuck on page fault when loading new page directory

Post by exbotanical »

Hi all,
I've been stuck on this issue for a week now and am trying to figure out what I did wrong. I'm writing a higher half kernel - in the loader, I enable paging using a temporary page table, which I later replace with a permanent one. Problem is, when I load the address of the permanent page directory into the CR3 register, I get a page fault.

I've tried a few things including setting up a page fault handler to inspect the state of the world when the fault happens but my interrupt handler doesn't execute. I wrote it hastily and probably don't know what I'm doing yet so not really surprised there.

Code can be found on the 0xe branch here.

Relevant files: QEMU debug log:
qemu_log.txt
(19.95 KiB) Downloaded 36 times
Last edited by exbotanical on Thu Sep 26, 2024 8:25 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4682
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Stuck on page fault when loading new page directory

Post by iansjack »

The address that is faulting in the first page fault is that of the page table that you have loaded into cr3. It looks as if you are trying to access the page table in your program (when you map vga memory?) but haven’t mapped the address of the page table.

I’d recommend that you run your os under gdb and set breakpoints at likely places. Also, disassemble your kernel using objdump to determine what part of your program corresponds to the faulting instruction (c01027aa).
exbotanical
Posts: 2
Joined: Mon Oct 30, 2023 9:12 pm
Libera.chat IRC: goldmund

Re: Stuck on page fault when loading new page directory

Post by exbotanical »

Thanks! I disassembled the binary using objdump and found the instruction like you suggested. Looks like the stack was messed up right after returning from the loadcr3 function that sets the new page table. I did some hunting and found that I forgot to set the kernel_end address. This was crucial because it's where I remap the entire address space to work with the new paging setup. Solved!
Post Reply