MichaelPetch wrote:
tabz wrote:
1. Use 4MiB paging at first, disable 4MiB pages then change to the new page directory. This causes a fault since as soon as you disable 4MiB pages it can't execute the next instruction since the page directory is set up for 4MiB pages.
I may be misunderstanding. What do you mean by "disabling" 4iM pages?
While using the original boot page directory you can create a new page directory and pages tables(s) with 4KiB pages that include the mappings for the kernel so it is mapped to lower memory. Then you just update CR3 to the address of the new page directory. As long as the new page structure contains a mapping for the kernel from lower to upper memory it shouldn't fault at all.
What I mean is the inverse of the following asm snippet (from the snippet from the other forum post you shared):
Code:
mov %cr4, %ecx
# Enable 4MB pages
or $0x00000010, %ecx
mov %ecx, %cr4
Which enables 4MiB pages. From my uinderstanding of this, it means the MMU interprets each page table directory as mapping to a 4MiB space, where as if 4MiB pages were disabled, i.e doing (cr4 &= ~(0x00000010)), the MMU would interpret each page directory entry as pointing to 1024 page table entries, each of which maps 4KiB of space. In my mind you can't have that one bit in cr4 enabled if you want to use 4KiB pages, thus the situations above arise. Please do correct me if I'm wrong.