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.
I am trying to set up paging for my kernel, however it is just triggering a page fault. I have followed the wiki as close as I can, but the issue is still occurring. Any help would be greatly appreciated
This can happen with interrupts enabled because by default the timer chip uses the same interrupt as page faults. Set up IRQs and you should be alright
If I see one more magic number in wiki code then I'm going to lose it.
CeriseSky wrote: ↑Thu Jun 26, 2025 7:47 am
This can happen with interrupts enabled because by default the timer chip uses the same interrupt as page faults. Set up IRQs and you should be alright
That is false. The timer interrupt in BIOS-compatible configuration maps to the double fault. However, it is apparent from the OP that they need to fix their debug outputs first and foremost. If this was the timer interrupt, it would be happening at ca. 18Hz, which should leave more than enough time to print a couple of hex numbers to screen.
No, I suspect this is an access error, and then an access error happening while attempting to print the message. Which is normal for someone attempting paging the first time. I suspect something wrong with the page tables.
nullplan wrote: ↑Thu Jun 26, 2025 9:31 am
That is false. The timer interrupt in BIOS-compatible configuration maps to the double fault.
Right that's my bad. I remembered the timer causing some kind of issue if it wasn't remapped but either way OP has done that. You're probably right about the access error, it might be useful for OP to run it through bochs and keep track of what the setup function is actually putting in memory. It's crude but it might expose the problem if its obvious enough
If I see one more magic number in wiki code then I'm going to lose it.
torii wrote: ↑Thu Jun 26, 2025 6:55 amI am trying to set up paging for my kernel, however it is just triggering a page fault.
Do you have any more information about that page fault? For example, where in your code it occurs (EIP) and what address is being accessed that causes the fault (CR2).
Since your exception handler doesn't work, try running QEMU with "-d int" so you can get that information out of QEMU's logs.
I think you should consider iansjack question about malloc returning page aligned memory. I don't even get as far as you do since the paging fails immediately after the paging bit is set in CR0. I see this when debugging:
Breakpoint 2 at 0x2004c0: file mmu.c, line 19.
(gdb) c
Continuing.
Breakpoint 2, setupPageDirectory () at mmu.c:19
19 page_tables = (page_table_t*)malloc(page_table_list_cap * sizeof(page_table_t));
(gdb) n
32 for(int i = 0; i < 1024; ++i) {
(gdb) p page_tables
$1 = (page_table_t *) 0x20b5a0 <heap+32>
(gdb)
`page_tables` is clearly not 4096 byte aligned. Is the code in your Github the version you are running? If not please commit the latest code you are using.
Okay, heres an update: I managed to fix the issue by rewriting my page allocator. There must have been *something* wrong with it somewhere, as it now appears to be working fine.