Question about 32-bits paging
Posted: Fri Sep 20, 2019 10:54 am
Hi all!
I'm getting back into osdev and there is one thing I can't figure out about paging.
My code for getting a page table entry from a virtual address looks basically like this
It's about the same code given in the wiki page about paging (https://wiki.osdev.org/Paging#Manipulation) and it works like a charm.
My question: why is table not calculated like in the following code? Why does my current code work?
Why do we multiply the index by 0x400 (i.e left-shift by 10) instead of multiplying by 0x1000? Multiplying by 0x400 is like left-shifting by 10 bits, so the index in the page directory should be mangled by 2 bits... I don't get it. Isn't that address translated the same way every other linear address is?
That's the last thing standing in my way for understanding paging
I'm getting back into osdev and there is one thing I can't figure out about paging.
My code for getting a page table entry from a virtual address looks basically like this
Code: Select all
uint32_t dir_index = DIRECTORY_INDEX(virt);
uint32_t table_index = TABLE_INDEX(virt);
directory_entry_t* dir = (directory_entry_t*) 0xFFFFF000;
page_t* table = ((uint32_t*) 0xFFC00000) + (0x400 * dir_index);
if (dir[dir_index] & PAGE_PRESENT) {
return &table[table_index];
}
My question: why is table not calculated like in the following code? Why does my current code work?
Code: Select all
page_t* table = ((uint32_t*) 0xFFC00000) + (dir_index << 12);
That's the last thing standing in my way for understanding paging