简体   繁体   English

将虚拟地址转换为物理地址

[英]translate virtual address to physical address

The following page table is for a system with 16-bit virtual and physical addresses and with 4,096-byte pages. 下表页适用于具有16位虚拟和物理地址以及4,096字节页面的系统。 The reference bit is set to 1 when the page has been referenced. 引用页面后,参考位设置为1。 Periodically, a thread zeroes out all values of the reference bit.All numbers are provided in decimal. 线程会定期将参考位的所有值清零。所有数字均以十进制提供。 在此处输入图片说明

I want to convert the following virtual addresses (in hexadecimal) to the equivalent physical addresses. 我想将以下虚拟地址(十六进制)转换为等效的物理地址。 Also I want to set the reference bit for the appropriate entry in the page table. 另外,我想为页表中的相应条目设置参考位。

0xE12C 0xE12C

0x3A9D 0x3A9D

0xA9D9 0xA9D9

0x7001 0x7001

0xACA1 0xACA1

I know the answers are but I want to know how can I achieve these answers: 我知道答案是但我想知道如何获得这些答案:

0xE12C → 0x312C
0x3A9D → 0xAA9D
0xA9D9 → 0x59D9
0x7001 → 0xF001
0xACA1 → 0x5CA1

I found and tried This but it did not help me much. 我找到并尝试了此方法,但并没有太大帮助。

It is given that virtual address is 16 bit long. 假定虚拟地址为16位长。
Hence, there are 2^16 addresses in the virtual address space. 因此,虚拟地址空间中有2 ^ 16个地址。
Page Size is given to be 4 KB ( there are 4K (4 * (2 ^ 10) )addresses in a page), so the number of pages will be ( 2^16 ) / ( 2 ^ 12 ) = 2 ^ 4. 页面大小为4 KB(页面中有4K(4 *(2 ^ 10))个地址),因此页面数将为(2 ^ 16)/(2 ^ 12)= 2 ^ 4。
To address each page 4 bits are required. 要寻址每个页面,需要4位。
The most significant 4 bits in the virtual address will denote the page number being referred and the remaining 12 bits will be the page offset. 虚拟地址中的最高4位将表示所引用的页码,其余12位将为页面偏移量。

One thing to remember is page size (in the virtual address space ) is always same as the frame size in the main memory. 要记住的一件事是页面大小(在虚拟地址空间中)总是与主存储器中的帧大小相同。 Hence the last 12 bits will remain same in the physical address as that of the virtual address. 因此,最后12位将在物理地址中与虚拟地址保持相同。

To get the frame address in the main memory just use the first 4 bits. 要获得主存储器中的帧地址,只需使用前4位。
Example: Consider the virtual address 0xACA1 示例:考虑虚拟地址0xACA1
Here A in A CA1 denotes the page number ( 10 ) and corresponding frame no is 5 ( 0101) hence the resulting physical address will be → 0x5CA1. 此处A CA1中的A表示页码(10),而对应的帧号为5(0101),因此所得的物理地址将为→0x5CA1。

To translate a virtual address to a physical address (applies ONLY to this homework question), we need to know 2 things: 要翻译的虚拟地址到物理地址( 适用于本次作业中的问题),我们需要知道件事情:

  • Page Size 页面大小
  • Number of bits for virtual address 虚拟地址的位数

In this example: 16-bit system , 4KB page size and physical memory size is 64KB . 在此示例中: 16位系统页面大小为4KB物理内存大小64KB

First of all we need to determine the number of needed bits to act as offset inside page. 首先,我们需要确定充当页内偏移量所需的位数。
log2(Page-Size) = log2(4096) = 12 bits for offset log2(Page-Size) = log2(4096) = 12偏移

Out of the 16 bits for virtual address, 12 are for offset, that means each process has 2^4 = 16 virtual pages. 虚拟地址的16位中有12位用于偏移量,这意味着每个进程都有2^4 = 16虚拟页。 Each entry in page table stores the corresponding frame accommodating the page. 页面表中的每个条目都存储了容纳页面的相应框架。 For example: 例如:

在此处输入图片说明

Now lets translate! 现在开始翻译!

First of all for ease of work lets convert 0xE12C to binary . 首先,为了简化工作,将0xE12C转换为binary

0xE12C = (1110 0001 0010 1100) in base 2
1110 = 14 in decimal
Entry 14 in P.T => Page frame 3.

Lets concatenate it to the 12 offset bits 让它连接到12个偏移位

Answer: (0011 0001 0010 1100) = 0x312C

Another example: 0x3A9D 另一个示例: 0x3A9D

0x3A9D = 0011 1010 1001 1101
0011 = 3
PageTable[3] = 10
10 in decimal = 1010 in binary
1010 1010 1001 1101 in binary = 0xAA9D

To help you solve this question, we need to get our details right: 为了帮助您解决此问题,我们需要正确了解我们的详细信息:

  1. 16 bit of virtual address space = 2^16 = 65,536 address space 16位虚拟地址空间= 2 ^ 16 = 65,536地址空间
  2. 16 bit of physical address space = 2^16 = 65,536 address space 16位物理地址空间= 2 ^ 16 = 65,536地址空间
  3. 4096 Byte page size determines the offset, which is Log(4096) / Log (2) = 12 bit. 4096字节页面大小确定偏移量,即Log(4096)/ Log(2)= 12位。 This means, 2^12 for Page size 也就是说,页面大小为2 ^ 12
  4. As per @Akash Mahapatra, the offset from virtual address is directly mapped to the offset onto physical address 根据@Akash Mahapatra,虚拟地址的偏移量直接映射到物理地址的偏移量

As such, we now have: 因此,我们现在有:

  • 2^16 (16bit) for virtual address - 2^12 (12bit) for offset = 4-bit for pages, or rather total number of pages available. 虚拟地址2 ^ 16(16位)-偏移量2 ^ 12(12位)=页面4位,或者可用页面总数。
  • I won't repeat the calculation for physical since it's the same numbers. 我不会重复物理计算,因为它是相同的数字。
  • 2^4 (4bit) for pages = 16, which correlates to the number of table entries above! 页面的2 ^ 4(4位)= 16,这与上面的表条目数有关!

We're getting there... be patient! 我们到达那里...请耐心等待! :) :)

Memory Address 0xE12C in hex notation is also known to be holding 16-bit of address. 还以十六进制表示的内存地址0xE12C拥有16位地址。 (Since it's stated in the question.) (因为问题中已经说明。)

Let's butcher the address now... 现在让我们屠宰地址...

We first remove '0x' from the info. 我们首先从信息中删除“ 0x”。

We can convert E12C to binary notation like @Tony Tannous, but I am going to apply a little short-cut. 我们可以将E12C转换为@Tony Tannous之类的二进制符号,但是我将应用一些捷径。

地址和偏移量的映射

I simply use a ratio. 我只是使用一个比率。 Well, the address is notated in 4 characters above, and since 16/4 = 4, I can define the first letter as virtual address, while the other 3 are offset address. 好吧,该地址用上面的4个字符表示,由于16/4 = 4,我可以将第一个字母定义为虚拟地址,而其他3个为偏移地址。

With the information, 'E' in hexadecimal format, I need to convert to Decimal = 14. Then I look at your table provided, and I found page frame '3'. 有了信息“ E”(十六进制格式),我需要转换为Decimal =14。然后查看您提供的表,发现页面框架为“ 3”。 Page frame 3 is noted in decimal format, which then need to be converted back to Hexadecimal format... Duh!... which is 3! 页面框架3以十进制格式标注,然后需要转换回十六进制格式... Duh!...这是3!

So, the Physical address mapping of the virtual memory location of 0xE12C can be found at 0x312C on the physical memory. 因此,可以在物理内存上的0x312C处找到虚拟内存位置0xE12C的物理地址映射。

You will then go back to the table, and refer to the reference bit column and put a '1' to the row 14. 然后,您将返回表,并参考参考位列,并在第14行中添加“ 1”。

Apply the same concept for these - 对这些应用相同的概念-

0x3A9D → 0xAA9D
0xA9D9 → 0x59D9
0x7001 → 0xF001
0xACA1 → 0x5CA1

If you notice, the last 3 digits are the same (which determines the offset). 如果您注意到,最后3位数字相同(这决定了偏移量)。 And the 1st of the 4-digits are mapped according to the table: 并且四位数字中的第一位根据表格进行映射:

table entry 3 -> page frame 10 -> hex notation A
table entry A (10) -> page frame 5 -> hex notation 5
table entry 7 -> page frame 15 -> hex notation F
table entry A (10) -> page frame 5 -> hex notation 5

Hope this explanation helps you and others like me! 希望这种解释对您和其他像我一样的人有帮助! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM