wiki Paging artictle question
Page 1 of 1

Author:  rednhot [ Tue Jun 08, 2021 5:21 pm ]
Post subject:  wiki Paging artictle question

Hi! In fact, I am completely new to operating systems and particularly to this forum, so, please, be patient :roll:

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
void * get_physaddr(void * virtualaddr)
void map_page(...)
there's a line where we obtain a virtual address of a page table, and it looks like
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 :)

Author:  thepowersgang [ Tue Jun 08, 2021 9:34 pm ]
Post subject:  Re: wiki Paging artictle question

Adding to pointers in C advances the pointer by one entry per value added (i.e. if you do `(uint16_t*)0xB8000 + 4` the new pointer will be `0xB8008`)
So here the pointer changes by 0x1000, not 0x400 (since the size of `unsigned int` is usually 4 bytes)

Author:  rednhot [ Wed Jun 09, 2021 5:09 pm ]
Post subject:  Re: wiki Paging artictle question

Oh, my inattentiveness will bury me one day... :oops: Ok, I got it, thanks. :D But what about the statement
To get the physical address of any virtual address in the range 0x00000000-0xFFFFF000 is then just a matter of
? Why we don't include the last page of virtual addess space in the range above? For me it seems that it's also convertible.

Author:  thepowersgang [ Wed Jun 09, 2021 7:06 pm ]
Post subject:  Re: wiki Paging artictle question

0xFFFFF000 is the start of the last addressable page ... seems like a bit of a quirk/oversight in the way it's phrased - but the intent seems to be saying that the entire address space can be converted.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group