Hard time understanding recursive mapping
Posted: Thu Mar 12, 2015 5:03 pm
Previously when I had to modify the data of a page (such as a page table, page directory, etc, as they are also one page long each), I just mapped them to a page called an "ISP", and I switched the frame of the ISP whenever I had to work with a different page. This proved extremely inefficient when trying to copy address spaces (e.g. when calling fork()).
I'm trying to do recursive mapping. I don't need to do this for the entire PML4 - each process only gets one PDPT (mapped as the first PML4 entry) and I want to recursive-map that. So the equations for a PD and PT would be as follows:
But if I substitute 511 into i_pd, I get addr_pd = addr_pdpt, so the PD struct for the last directory would be at the same address as the address of the PDPT struct. Then how do I access the last PD so that I can map more tables into it (as tables in the last PD contain pages that map to PTs of other PDs).
Am I missing something here? If I treat the PDPT and the last PD as the same structure, then setting its first entry to some frame would mean that adress 0 would simultaneously contain the page data and all levels of paging structures, which clearly makes no sense.
Could someone show some sample code maybe? (or pseudo-code?)
Please help
P.S. I'm in 64-bit Long Mode.
I'm trying to do recursive mapping. I don't need to do this for the entire PML4 - each process only gets one PDPT (mapped as the first PML4 entry) and I want to recursive-map that. So the equations for a PD and PT would be as follows:
Code: Select all
addr_pdpt = 0xFFFFFFFFF000;
addr_pd = 0xFFFFFFE00000 + i_pd * 0x1000;
addr_pt = 0xFFFFC0000000 + i_pd * 0x200000 + i_pt * 0x1000;
Am I missing something here? If I treat the PDPT and the last PD as the same structure, then setting its first entry to some frame would mean that adress 0 would simultaneously contain the page data and all levels of paging structures, which clearly makes no sense.
Could someone show some sample code maybe? (or pseudo-code?)
Please help
P.S. I'm in 64-bit Long Mode.