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!
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.
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.
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.
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.
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.