Doubt on paging...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Doubt on paging...

Post 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 ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Doubt on paging...

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: Doubt on paging...

Post 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/
Post Reply