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.
White-spirit wrote:Thanks very much, it works perfectly :-)
Glad I could be of help. This trick should also be used for other structures that need to be alligned at a certain boundary, e.g. TSS (also needs 4Kb allignment) and GDT/IDT (which should have 8 byte allignment, for cache optimalization, see Intel manuals).
Just one more question, it is normal that many GPF happen after a page fault ?
I'm trying to access 0xFFFFFFFF to see if the page fault handler works, effectively, an interrupt 14 is executed, but after, I get so many GPFs, with this error message in Bochs :
White-spirit wrote:Just one more question, it is normal that many GPF happen after a page fault ?
No, I'm afraid not :).
I'm trying to access 0xFFFFFFFF to see if the page fault handler works, effectively, an interrupt 14 is executed, but after, I get so many GPFs, with this error message in Bochs :
It's after IRET according to Bochs's debugger .
I've tested int $0xE ( instead of initializing a pointer to 0xFFFFFFFF ) to test a page fault exception, and I get an interrupt 14 followed by GPFs, in the bochs console I see this : "check_cs: conforming code seg descriptor dpl > cpl" .
Yup - as I said, that would indicate your stack is becoming misaligned. Check that you really are popping everything which you push in your PFE handler. For example, if your PFE handler starts with:
as many people seem to do, make sure you add 8 to your ESP before doing an IRET.
OTOH, If you don't push an interrupt # and error code, make sure you haven't copied code from a stub which does, because it will add 8 to ESP and you don't need to.
In the example above, I have assumed that you are in 32 bit PMode. In long mode, you will of course need to add 16 to RSP (rather than adding 8 to ESP) and do an IRETQ instead of an IRET(D).
The processor automatically pushes the error code, so there's only one push. On non-error-code faults, you need to push a fake error code (hence two pushes).
The processor automatically pushes the error code, so there's only one push. On non-error-code faults, you need to push a fake error code (hence two pushes).