wiki Paging artictle question

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
rednhot
Posts: 2
Joined: Mon Jun 07, 2021 7:30 pm

wiki Paging artictle question

Post by rednhot »

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

Code: Select all

void * get_physaddr(void * virtualaddr)
and

Code: Select all

void map_page(...)
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 :)
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: wiki Paging artictle question

Post by thepowersgang »

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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
rednhot
Posts: 2
Joined: Mon Jun 07, 2021 7:30 pm

Re: wiki Paging artictle question

Post by rednhot »

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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: wiki Paging artictle question

Post by thepowersgang »

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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply