I sat on it for a few hours, then re-ran the code under Bochs. Then I noticed something interesting...
...The address of the PDE I was modifying was suspicioulsy similar to ESP...
...And ESP pointed somewhere inside my boot page directory!
My initial thought was that my stack was too small, but I found it difficult to believe that I was consuming 64kB of stack. Then, I noticed something.
My stack is defined in kmain.c:
Code: Select all
__attribute__((aligned(32))) u32 BootStack[0x4000];
u32* BootStackTop = BootStack + 0x4000;
Code: Select all
movl $BootStackTop, %esp
BootStackTop is the address of a pointer which points to the stack. I should have been doing
Code: Select all
movl BootStackTop, %esp
BootStackTop is, coincidentally, located just above the page tables.
And I now know that I use about 256 bytes of stack :p