Hi,
Quote:
- I didn't really understand the setup of recursive paging, is the only thing I need to do is make the last entry of PD point to PD(the start of it)?
Technically it can be any entry. Most implementations (like Linux 32 bit) uses the last entry. Some implementations use a different index - like Windows (32 bit) uses the 768'th entry. But yes, that PDE[1023]=Page Directory is literally it.
Quote:
- How do I access tables other then PD(e.g. PT or others in 4 level paging)?
This is where it gets hard to explain due to the recursive definition. Basically, when you map the last page directory entry, any address in the last 4MB region of the address space become effected. What happens is that, during the address translation process, we will go through PDE[1023] to find the page table -- so it will next read the page directory again but this time treating it as a page table. So all page frame numbers in each page table entry refer to the page containing the contents of that respective page table -- keep in mind this is just the page directory being looked at as a page table hence the contents is the same. So to find the page table virtual addresses, we just need to know what page each page table / page directory entry maps to. You have already found one of them: the page directory itself is the last page table -- 1023.
Code:
0xfffff000 is PDE[1023] which is the last page table
0xffffe000 is PDE[1022] which is second to last page table.
0xffffd000 is PDE[1021]
...
0xfff00000 is PDE[768] this is typically the kernel page table for higher half kernels at 3GB
...
0xffc00000 is PDE[0]
So, lets say you need to update the kernel page table. Its respective page directory entry is the 768'th index from 0xfffff000 (MM_PAGE_DIRECTORY_BASE). If you need to update the page table itself, it will always and forever be at 0xfff00000 (MM_KERNEL_PAGE_TABLE_BASE).
Keep in mind all of this assumes you selected the PDE[1023] as the recursive index.
--
I will reiterate that there is no advantage to using recursive paging in 64 bit long mode. You don't lose anything by mapping all of physical memory into kernel space. If you did that, then you can easily determine the actual address and update paging structures. You wouldn't lose memory: in fact, doing this doesn't effect require additional memory at all. Recursive paging was used a lot in 32 bit protected mode as the size of the address space is the same as what was expected of physical memory at the time, so there was few good options available. Using multiple techniques to memory management is important to any good manager: you need to adjust the method depending on the environment to decide how best to manage memory. Even if the intent is trying to make things easier you will end up making it harder by not doing so.
--
As Recursive Paging comes up often, I started writing a small tutorial on it
here. It is still a work in progress, but please feel free to point out any potential confusing parts and I will be happy to expand on them as needed.