mapping virtual address (logical address) to physical address

631 Views Asked by At

This question refers to an architecture using segmentation with paging. In this architecture, the 32-bit virtual address is divided into fields as follows:

                       4 bit segment number | 12 bit page number | 16 bit offset

Find the physical address corresponding to each of the following virtual addresses (answer "bad virtual address" if the virtual address is invalid).

1.00000000

2.20022002

3.10015555

Please help me with this, i dont know how to create page table and segment table for this mapping !!!

1

There are 1 best solutions below

0
On

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; 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:

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:

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.