OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Aug 05, 2021 12:37 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: wiki Paging artictle question
PostPosted: Tue Jun 08, 2021 5:21 pm 
Offline

Joined: Mon Jun 07, 2021 7:30 pm
Posts: 2
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:
void * get_physaddr(void * virtualaddr)
and
Code:
void map_page(...)
there's a line where we obtain a virtual address of a page table, and it looks like
Code:
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 :)


Top
 Profile  
 
 Post subject: Re: wiki Paging artictle question
PostPosted: Tue Jun 08, 2021 9:34 pm 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 731
Location: Perth, Western Australia
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


Top
 Profile  
 
 Post subject: Re: wiki Paging artictle question
PostPosted: Wed Jun 09, 2021 5:09 pm 
Offline

Joined: Mon Jun 07, 2021 7:30 pm
Posts: 2
Oh, my inattentiveness will bury me one day... :oops: Ok, I got it, thanks. :D But what about the statement
Quote:
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.


Top
 Profile  
 
 Post subject: Re: wiki Paging artictle question
PostPosted: Wed Jun 09, 2021 7:06 pm 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 731
Location: Perth, Western Australia
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group