Recursive mapping questions
Posted: Sun Nov 16, 2014 10:37 pm
Hi,
I have been trying to work through recursive mapping of my paging tables in my mind off and on for a couple of weeks now. Some days I feel I have better success, than others. In reality, I haven't got a clue. At this point, I am so confused I probably will not be able to articulate my questions well and I'm likely to have many follow-up questions. I might even ramble. I'm also going to try to use the words "physical" and "virtual" in front of each instance of "address" (and synonym) to help me keep them straight in my mind. Thanks in advance for being patient.
I'm setting up recursive mapping (in a 64-bit system) and let's say that I am going to use entry/index 511 for my recursive map. My first thought is that I want to map PML4[511] point to the physical address of my PML4 table. This way, when I want to access a PML4 entry, I can refer to the proper offset from 0xfffffffffffff000 and get to the proper PLML4 entry. However, on closer inspection, that logic does not seem sound. What if I need to add a new PD to a PDPT, how would I get to that structure? Besides, it would make a mess of accessing the other pages above 0xffffff8000000000. So, my current thinking is that I need to drive the actual mapping down to the page level, so that if I set up PML4[511][511][511][511] (meaning PML4[511] to get a PDPT; PDPT[511] to get a PD; PD[511] to get a PT; PT[511] to get the physical address [or page] of the PML4 table), I'm in much better shape. Is this current thinking correct?
Now, I am calculating that I have 1 page for the PML4 table. I am calculating that I have 511 pages for each of the possible PDPTables. 0xfffffffffffff000 - 0xffffffffffe00000 = 0x1ff000 / 0x1000 = 0x1ff = 511. So, if I needed to maintain the Page Table at PML4[511][511][511], how would I access that table? Same thing with the PD tables (255 * 256 -- 1 less than I am expecting in my mind). Or are these all statically at initialization? This then requires 1 PDPT + 512 PD + 512 X 512 PT frames (or 262,657 frames, or 1GB + 2MB + 4K) to be statically setup at initialization. I'm missing something very fundamental here.
Now, if I nave to add a new Page Table (or Page Directory or PDP Table) to my paging structures, I need to allocate a frame for this new structure. (I think I just answered this question as I'm trying to write it, but I'm going to continue anyway in case I'm wrong -- very like at this point ) Before I insert this new frame into my paging structures, I want to clear it to make sure nothing accesses it while it still has garbage in it. So, I want to clear it, of course. But I cannot do that with a physical address; I need to make that structure available at a virtual address in order to clear it. Do I need to put this into a temporary page to clear it before adding it to the recursive page location? I think several people would say, "No, that's what the recursive location is for." Which is why I think I've answered this question in my head since I forgot the actual page will appear in the entire page structures twice -- once as a page and once in it's real location in the paging structure tree. Do I at least have this part right???
Thanks in advance for the assistance!!
I have been trying to work through recursive mapping of my paging tables in my mind off and on for a couple of weeks now. Some days I feel I have better success, than others. In reality, I haven't got a clue. At this point, I am so confused I probably will not be able to articulate my questions well and I'm likely to have many follow-up questions. I might even ramble. I'm also going to try to use the words "physical" and "virtual" in front of each instance of "address" (and synonym) to help me keep them straight in my mind. Thanks in advance for being patient.
I'm setting up recursive mapping (in a 64-bit system) and let's say that I am going to use entry/index 511 for my recursive map. My first thought is that I want to map PML4[511] point to the physical address of my PML4 table. This way, when I want to access a PML4 entry, I can refer to the proper offset from 0xfffffffffffff000 and get to the proper PLML4 entry. However, on closer inspection, that logic does not seem sound. What if I need to add a new PD to a PDPT, how would I get to that structure? Besides, it would make a mess of accessing the other pages above 0xffffff8000000000. So, my current thinking is that I need to drive the actual mapping down to the page level, so that if I set up PML4[511][511][511][511] (meaning PML4[511] to get a PDPT; PDPT[511] to get a PD; PD[511] to get a PT; PT[511] to get the physical address [or page] of the PML4 table), I'm in much better shape. Is this current thinking correct?
Now, I am calculating that I have 1 page for the PML4 table. I am calculating that I have 511 pages for each of the possible PDPTables. 0xfffffffffffff000 - 0xffffffffffe00000 = 0x1ff000 / 0x1000 = 0x1ff = 511. So, if I needed to maintain the Page Table at PML4[511][511][511], how would I access that table? Same thing with the PD tables (255 * 256 -- 1 less than I am expecting in my mind). Or are these all statically at initialization? This then requires 1 PDPT + 512 PD + 512 X 512 PT frames (or 262,657 frames, or 1GB + 2MB + 4K) to be statically setup at initialization. I'm missing something very fundamental here.
Now, if I nave to add a new Page Table (or Page Directory or PDP Table) to my paging structures, I need to allocate a frame for this new structure. (I think I just answered this question as I'm trying to write it, but I'm going to continue anyway in case I'm wrong -- very like at this point ) Before I insert this new frame into my paging structures, I want to clear it to make sure nothing accesses it while it still has garbage in it. So, I want to clear it, of course. But I cannot do that with a physical address; I need to make that structure available at a virtual address in order to clear it. Do I need to put this into a temporary page to clear it before adding it to the recursive page location? I think several people would say, "No, that's what the recursive location is for." Which is why I think I've answered this question in my head since I forgot the actual page will appear in the entire page structures twice -- once as a page and once in it's real location in the paging structure tree. Do I at least have this part right???
Thanks in advance for the assistance!!