Page 1 of 1
recursive page directory?
Posted: Wed Sep 22, 2010 5:24 pm
by bohunter11
I'm tring to setup a recursive page directory and was wondering, do I have to completly map
the last page table and pages? I would think so but this paging has been realy hard for me
to totally understand and I'm not sure.
Thank You
Bo Hunter
Re: recursive page directory?
Posted: Wed Sep 22, 2010 6:57 pm
by gerryg400
If you're new to paging and finding it hard to grasp, it might be easier to not use the so-called 'recursive' pgdir straight away. It certainly is a good 'trick', and can be used without understanding how it works, but it's not necessarily the best way if you're still in learning mode.
Re: recursive page directory?
Posted: Thu Sep 23, 2010 2:44 am
by egos
It's simple. You must have one self link in page dir. Just one important point: you should protect kernel on PDE level, else user space will be invalid.
Re: recursive page directory?
Posted: Thu Sep 23, 2010 9:57 am
by bohunter11
"Just one important point: you should protect kernel on PDE level, else user space will be invalid."
You mean I should set pagetable to present,rw only for the pagetable that the kernel is mapped?
What do you mean that user pace will be invalid. I know what userspace is, I just don't know what
you mean by invalid.
Thank You
Bo Hunter
Re: recursive page directory?
Posted: Thu Sep 23, 2010 12:53 pm
by egos
You must control U/S bit in self link PDE to protect full 4 mb page tab region, else page tab will be accessible from user space i.e. user space will be invalid. I missed when I said about all kernel because I use only PDE level protection.
Re: recursive page directory?
Posted: Thu Dec 09, 2010 1:37 pm
by bluemoon
Hi,
I found the recursive page directory easier to understand if you try to calculate how the linear address translation yourself.
For example, I choose the PDE #1023 entry to link with itself
Code: Select all
mov dword [PHYADDR(PDE) + 1023*4], PHYADDR(PDE) +1
(I set just the present bit for simplification)
So, upon any access with the last 4M address, the MMU will lookup the PDE itself as a PTE entry
Now try some address,
0xFFC00000 -> the physical address is recorded on the 1st entry of the PDE, which is the page of #0 PTE entry
0xFFC10000 -> the #1 PTE
etc
0xFFFFF000 -> the #1023 entry, which is the physical address of the PDE itself.
This trick will be extremely convenient for example if you need to add a new PTE entry when you write your MM,
without recursive you may need to map the PTE somewhere else, zero/setup and un-map it.