#GP after #PF
Posted: Sun Jun 22, 2008 4:47 pm
Hi, I'm writing my very own kernel like everyone else and I am very happy to be at this wonderful forum! This is my first post and I like to ask for help in making my kernel! I want to ask more than one question here so that I don't have multiple topics so here I go:
- Problem with Page Testing
When my kernel starts up, not only paging is initialized, but it does a test page fault. It does this by writing 0x1234 to first non-present page. In page initialization the first 4 pages(pages 0 - 3) are set to present, cachability is enabled(i don't think it matters, it performs global page invalidation), global flag is set, page size is set(with PSE flag set). And a temporary page fault handler is assigned. After this is all done, I make a pointer that points to the first byte at page 4(Same as rest except for present flag) and writes the value 0x1234 to it. It generates a PF like it should. The temp PF handler simply sets the present flag in the faulted page(other fields are already valid). And in the handler, it even write to the faulted virtual address and everything work! BUT! When the handler returns and when the iret instruction is executed, for some reason it generates a GP exception! The error code said that it tried loading an invalid segment and I looked at the register dump and stack dump and saw that the iret instruction was trying to load a segment with the low word of the eip register that was saved on the stack when the PF was generated. I have practically tried all that I know and I can't seem to solve the problem. I have the timer at interrupt vector 32 working correctly and the iret works fine. So what is the problem?
- How do I detect both 8259A and 8259A-2 PIC? I know how to detect a APIC built on chip x86 arch processors but I have no clue how to detect the two PICs. I want to know how to do this so my kernel can utilized the one available if an APIC is not detected.
Thank you for reading my questions!
- Problem with Page Testing
When my kernel starts up, not only paging is initialized, but it does a test page fault. It does this by writing 0x1234 to first non-present page. In page initialization the first 4 pages(pages 0 - 3) are set to present, cachability is enabled(i don't think it matters, it performs global page invalidation), global flag is set, page size is set(with PSE flag set). And a temporary page fault handler is assigned. After this is all done, I make a pointer that points to the first byte at page 4(Same as rest except for present flag) and writes the value 0x1234 to it. It generates a PF like it should. The temp PF handler simply sets the present flag in the faulted page(other fields are already valid). And in the handler, it even write to the faulted virtual address and everything work! BUT! When the handler returns and when the iret instruction is executed, for some reason it generates a GP exception! The error code said that it tried loading an invalid segment and I looked at the register dump and stack dump and saw that the iret instruction was trying to load a segment with the low word of the eip register that was saved on the stack when the PF was generated. I have practically tried all that I know and I can't seem to solve the problem. I have the timer at interrupt vector 32 working correctly and the iret works fine. So what is the problem?
- How do I detect both 8259A and 8259A-2 PIC? I know how to detect a APIC built on chip x86 arch processors but I have no clue how to detect the two PICs. I want to know how to do this so my kernel can utilized the one available if an APIC is not detected.
Thank you for reading my questions!