了解两级分页翻译

I want to make sure that I'm understanding paging correctly. I have the following example (32 bit) memory layout: enter image description here Assuming the standard x86 two-level page structure where %cr3 = 0xffff1000, I want to know what happens when I execute something like

int *ptr = (int *) 0x200ffc;
printf("%x\n", *ptr);

Here's my walkthrough: the first 10 bits of 0x200ffc is just 0x0 so I want the zeroth entry of the page directory, which gives me 0xf0f02007. The first 20 bits of this gives me the PPN, which is 0xf0f02 and gives me the left-most page. The next 10 bits in the virtual address 0x200ffc is 0x200 and so I need to index (0xf0f02 << 12) + (0x200 * 4) since each entry is 4 bytes.

This finally gives me 0xf0f02800, which indexes to 0xff005007 and so the physical address is just the first 20 bits of this plus the last 12 bits of my virtual address: (0xff005 << 12) + 0xffc = 0xff005ffc. Since my C program prints whatever is referenced at the ptr then 0xff005ffc points to 0xbebeebee.

这听起来正确吗,我的推理声音正确吗?

评论