Mapping the PD to itself

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
mgoppold
Posts: 9
Joined: Wed Feb 13, 2013 9:12 pm

Mapping the PD to itself

Post 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?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Mapping the PD to itself

Post 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.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: Mapping the PD to itself

Post 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.
mgoppold
Posts: 9
Joined: Wed Feb 13, 2013 9:12 pm

Re: Mapping the PD to itself

Post by mgoppold »

What does the recursive mapping accomplish? Specifically, mapping the PD to itself.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Mapping the PD to itself

Post 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
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Mapping the PD to itself

Post 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.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: Mapping the PD to itself

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