recursive page directory?

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.
Post Reply
bohunter11
Posts: 9
Joined: Tue Sep 14, 2010 5:13 pm

recursive page directory?

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: recursive page directory?

Post 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.
If a trainstation is where trains stop, what is a workstation ?
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: recursive page directory?

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
bohunter11
Posts: 9
Joined: Tue Sep 14, 2010 5:13 pm

Re: recursive page directory?

Post 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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: recursive page directory?

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: recursive page directory?

Post 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.
Post Reply