Page 1 of 1

Mapping the PD to itself

Posted: Sun Feb 24, 2013 9:37 am
by mgoppold
Let's refer to this page. http://wiki.osdev.org/Setting_Up_Paging_With_PAE

Code: Select all

page_dir[511] = (uint64_t)page_dir; // map pd to itself
page_dir[510] = page_dir_ptr_tab[2]; // map pd3 to it
page_dir[509] = page_dir_ptr_tab[1]; // map pd2 to it
page_dir[508] = page_dir_ptr_tab[0]; // map pd1 to it
This is incorrect because entries in the Page Directory table must point to a Page Table. But here it's a Page Directory entry pointing to a Page Directory. Incorrect data type.

Code: Select all

page_dir[507] = (uint64_t)&page_dir_ptr_tab; /* map the PDPT to the directory
This is incorrect because you have a Page Directory entry pointing to a Page Directory Pointer. Incorrect data type.

I've read the chapter in the AMD64 manual on paging. It DOES NOT mention circular mappings.

Isnt it impossible to map a PD to itself?

Re: Mapping the PD to itself

Posted: Sun Feb 24, 2013 9:44 am
by bluemoon
The MMU do not care if it is PDE or PTE, it only care about the bits.
Due to the great similarity of those structures, it is possible to do recursive mapping, and it is in fact a technique adopted by many os developers.

Re: Mapping the PD to itself

Posted: Sun Feb 24, 2013 11:05 am
by rdos
bluemoon wrote:The MMU do not care if it is PDE or PTE, it only care about the bits.
Due to the great similarity of those structures, it is possible to do recursive mapping, and it is in fact a technique adopted by many os developers.
Yes. It is in fact also possible to use an PAE mapping along with a long mode mapping, as the structures are similar enough, and provide two different recursive mappings.

Re: Mapping the PD to itself

Posted: Sun Feb 24, 2013 12:08 pm
by mgoppold
What does the recursive mapping accomplish? Specifically, mapping the PD to itself.

Re: Mapping the PD to itself

Posted: Sun Feb 24, 2013 12:44 pm
by AJ
Hi,

It means that, in effect (assuming 32 bit with no PAE) the last 4 MiB of virtual memory contains supervisor-level entries in the the paging structures themselves. This makes allocating and reading/writing to your paging structures extremely easy.

Cheers,
Adam

Re: Mapping the PD to itself

Posted: Mon Feb 25, 2013 6:52 am
by bluemoon
Just a side note, while the usual example do the mapping at the last 4MB, there is nothing prevent you to do the mapping at other address.

Re: Mapping the PD to itself

Posted: Mon Feb 25, 2013 9:37 am
by rdos
bluemoon wrote:Just a side note, while the usual example do the mapping at the last 4MB, there is nothing prevent you to do the mapping at other address.
Right. I have a configurable mapping address.

Also, in order to do a recursive PAE-mode mapping, there is a need to map four PDs recursively.