I've been reading about paging for 2 weeks now and I really don't get it.
There are bits I get and other bits I don't get. (Pun intended)
I'll just post some questions from the osdev wiki on paging: http://wiki.osdev.org/Paging
It says:
Many prefer to map the last PDE to itself. The page directory will look like a page table to the system. To get the physical address of any virtual address in the range 0x00000000-0xFFFFF000 is then just a matter of:
Code: Select all
// All in all I don't understand even slightly where the MMU is in all of this and when does it kick in?
// If the address translation is transparent to code then the function below doesn't make sense to me at all!
void * get_physaddr(void * virtualaddr)
{
//So this means currently the last page dir entry is mapped to itself?
//so this virtualaddr can represent a 0 to 4GB address right,
//but it's virtual, I mean, it really maps to a physical address so how do the below lines works?
unsigned long pdindex = (unsigned long)virtualaddr >> 22; //this is like dividing by 2^22 right?
unsigned long ptindex = (unsigned long)virtualaddr >> 12 & 0x03FF; // why divide by 12 and & with 1023 ?
//both these operations don't make sense at all, you have a virtual address that is mapped to a physical addr
//WHEN? does the MMU kick in and really translate these? If they are transparent to code
//how will bit twiddling ever get the pde/pdt ? The actual physical addresses are something else right?
unsigned long * pd = (unsigned long *)0xFFFFF000; //I understand the address is the last 1KB in 0-4GB
//but again, that's a virtual address right? Wouldn't the MMU translate that into a physical address?
unsigned long * pt = ((unsigned long *)0xFFC00000) + (0x400 * pdindex);
//again this looks as if the pde and pdt were in virtual memory, or the virtual addresses are NOT virtual addresses?
// Or the MMU doesn't translate these? So when does it translate them! :/
return (void *)((pt[ptindex] & ~0xFFF) + ((unsigned long)virtualaddr & 0xFFF));
}
Regards,
Gideon