Hi! In fact, I am completely new to operating systems and particularly to this forum, so, please, be patient
I have read the
Paging wiki article and now I doubt if I understand it correctly or, which is more unlikely, it has mistakes.
Inside the
Code: Select all
void * get_physaddr(void * virtualaddr)
and
there's a line where we obtain a virtual address of a page table, and it looks like
Code: Select all
unsigned long * pt = ((unsigned long *)0xFFC00000) + (0x400 * pdindex);
. Let's take a look at how it will be computed with the value of virtual address 0x00400000.
pdindex will get the value of 0x1 in the definition and then gets multiplied by 0x400, resulting in 0x00000400. So, finally,
pt will get the value of 0xFFC00400. When hardware will try to resolve this address, what will happen is it looks at the last page directory entry which points in that example to itself, then choose the 0th entry again, and then add 0x400 to the address inside it, effectively selecting the 256th element of the 0th table. You can see that this line has no meaning. In my opinion, in place of 0x400, it should be 0x1000, so that actually the 1st-page directory entry will be selected, or, instead, we can fetch directly the needed page directory entry and extract from it the base of a page table, but it will require additional memory reference.
I am inclined to think that I am wrong at some moment, but I can't point it out. Thanks in advance