Page 1 of 1

Doubt on paging...

Posted: Wed Apr 13, 2011 1:03 am
by osdevkid
Dear All,

Currently I am go throughing OSDev Wiki page for "PAGING". In this page http://wiki.osdev.org/Paging, I have found a function definition to convert virtual address to physical address.

Code: Select all

void * get_physaddr(void * virtualaddr)
{
    unsigned long pdindex = (unsigned long)virtualaddr >> 22;
    unsigned long ptindex = (unsigned long)virtualaddr >> 12 & 0x03FF;

    unsigned long * pd = (unsigned long *)0xFFFFF000;      //=====> ?????????????????
    // Here you need to check whether the PD entry is present.

    unsigned long * pt = ((unsigned long *)0xFFC00000) + (0x400 * pdindex); //=====> ?????????????????
    // Here you need to check whether the PT entry is present.

    return (void *)((pt[ptindex] & ~0xFFF) + ((unsigned long)virtualaddr & 0xFFF));
}
In the above code, they have used two hex address 0xFFFFF000 (assigned to unsigned long * pd) and 0xFFC00000 (assigned to unsigned long * pt), from where these hex values are comes in to an account ?

Actually the *pd value should be taken from the register CR3 and *pt value should taken from the *pd along with the offset.

Can you explain it better ? why they have used these two hex values ?

Re: Doubt on paging...

Posted: Wed Apr 13, 2011 5:49 am
by Combuster
An address is cut into three parts:
nnnn nnnn nn | nn nnnn nnnn | nnnn nnnn nnnn
the first part is used as the index into the page directory, the second as index into the page table the third as offset.

0xFFFFF000 points to byte 0 of pt 1023 of pd 1023 - which in the recursive scheme point to the physical location of the pd itself.
0xFFC00000 points to byte 0 of pt 0 of pd 1023, the virtual address of pagetable 0. You can add the offset and get the pagetable entry for any address.

Re: Doubt on paging...

Posted: Thu Apr 14, 2011 2:43 am
by thomasloven
I just wrote a tutorial on recursive page directories.
It might be helpful.
http://www.thomasloven.com/P14/OSDEV-tutorial---Memory-management-part-1/ -- BROKEN LINK --

Edit 2016-10-10: Apparently I still get hits from here...
Try this instead: http://thomasloven.com/blog/2012/06/Rec ... Directory/