I was reading about paging in OS , and one of the things I saw was the page table base register (PTBR).
If the CPU generates a logical address (Consists of Page number + Offset) it needs to be mapped to Physical address (Consists of Frame number + Offset).
In the mapping process there must be first a lookup in the Page table of the process to get the Frame corresponding to that page .
Now to get to the page table we need to get the location of the page table of that process in the main memory .
The starting location of the page table is stored in a register called page table base register (PTBR) .
Now the page number part of the logical address is added with the value in the PTBR and the corresponding frame is found in the table as the following :

Since the PTBR stores the base physical address of the page table in memory (e.g. 14000), and the logical address contains the page number that the CPU wants to read data from , Now here is my question :
Is the page Number part of the logical address is the starting address of the page ?
like for example : the virtual address is 16 bit and the size of each page is 1KB
page 0 --->starts at virtual address 0
page 1 --->starts at virtual address 1024
page 2 --->Starts at virtual address 2048
and so on ...
so if the CPU wants to read data from page 1 , then the page number is "1024" and then this value is added to the value in the PTBR ?
OR
The page number itself is added for example : if the CPU wants to read data from "page 1" , then the number "1" represents the Page number value and when it is added to PTBR value ? in other way does the CPU deals with page Number or Starting address ?
I know this is silly for a lot of you ,but it really got me confused because I couldn't find any real example about it .
Regards
The page number starts at 0 and finishes at N.
So this is wrong:
so if the CPU wants to read data from page 1 , then the page number is "1024" and then this value is added to the value in the PTBR ?
Let's use your example.
the virtual address is 16 bit and the size of each page is 1KB
If the page size is 1KB it means that to access any data in it we need 10 bits. Because 2^10 = 1024.
If the CPU wants to access the address 1024 of the logical address space of the process, the CPU will ask the MMU (Memory Management Unit) to give him the value at this address.
1024 in binary is 1 0000 0000 00.
The MMU is then going to divide the address so
6 + 10 = 16 bits
where the first 6 (16 - 10) bits represent the page number.
And the last 10 bits the offset.
Hence, we have an offset of 0 and a page number of 1 (five 0 and one 1 (the one that makes 1024)).
If the page table is represented by a table:
unsigned int page_table[MAX_PAGES];
The address of this table will be PTBR.
So the MMU will see the frame number in this address:
PTBR + page_number (e.g. 1) * entry_size (e.g. sizeof(unsigned int))
Feel free to correct me if I am making a mistake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With