简体   繁体   English

将虚拟地址(逻辑地址)映射到物理地址

[英]mapping virtual address (logical address) to physical address

This question refers to an architecture using segmentation with paging.这个问题是指使用分段和分页的架构。 In this architecture, the 32-bit virtual address is divided into fields as follows:在此架构中,32 位虚拟地址分为以下字段:

4 bit segment number | 4位段数| 12 bit page number | 12 位页码 | 16 bit offset 16 位偏移

Find the physical address corresponding to each of the following virtual addresses (answer "bad virtual address" if the virtual address is invalid).找到以下每个虚拟地址对应的物理地址(如果虚拟地址无效,请回答“bad virtual address”)。

1.00000000 1.00000000

2.20022002 2.20022002

3.10015555 3.10015555

Please help me with this, i dont know how to create page table and segment table for this mapping !!!请帮帮我,我不知道如何为这个映射创建页表和段表!!!

You are a little shy on details, so lets fill in a few:你对细节有点害羞,所以让我们填写一些:

  1. Each segment has a 4096 (=2^12) entry translation table associated with it;每个段都有一个与之关联的 4096 (=2^12) 个条目翻译表; otherwise it would not be interesting.否则就没意思了。
  2. Each entry will contain a physical base address.每个条目将包含一个物理基地址。
  3. The extra offset will be added to this base address to find the final one.额外的偏移量将被添加到这个基地址以找到最后一个。

So, in this hypothetical MMU, we could have a function like:因此,在这个假设的 MMU 中,我们可以有一个 function,如:

paddr_t translate(uint32_t vaddr) {
    return segment[vaddr>>28].page[(vaddr>>16)&0xfff] + (vaddr & 0xffff);
}

A real (useful) mmu would have a bit more like:一个真正的(有用的)mmu 会更像:

paddr_t   translate(uint32_t vaddr) {
    seg_t *seg;
    page_t *page;
    if ((seg = segment[vaddr>>28]) && (page = seg->pagetab[(vaddr>>16)&0xfff])) {
         return page->base + (vaddr & 0xffff);
    } else {
         raise(SEGV);
    }
}

this is showing the sparseness of both segments and page mappings.这显示了段和页面映射的稀疏性。 It would likely have some permissions, as well, but this should help get you to the next obstacle.它也可能具有一些权限,但这应该有助于您克服下一个障碍。

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

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