CSCI-UA.0202 Spring 2015 Homework 6

Handed out Friday, March 20, 2015
Due 10:00 AM, Friday, March 27, 2015

Homework 6

These problems should be done on your own. As usual, we're not going to grade these strictly (we'll mainly look at whether you attempted them). But they reinforce knowledge and skills that the remaining labs will assume, so you ought to work through them carefully.

Virtual memory brushup

If you have not done it yet, do the VM fundamentals reading. This reading includes practice problems, and we ask about those here.

  1. Give your answer to problem 9.1 (p779)
  2. Give your answer to problem 9.2 (p781)
  3. Give your answer to problem 9.3 (p790)
  4. Give your answer to problem 9.4 (p798)

Segmentation

Based on the 14-bit segmentation scheme that we saw in lecture (in which the top two bits select a segment, the bottom 12 bits represent the offset, etc.), choose True or False for the following assertions, and justify:
  1. T/F Two different virtual addresses in the same segment can point to the same physical address.
  2. T/F Two different virtual addresses in different segments can point to the same physical address.
  3. T/F Using segmentation, a virtual address can be mapped into arbitrary physical address if configured properly.
    (e.g. virtual address 0x1424 can be mapped to any address in [0x0, 0x3fff].)

Page table walking

In this question, you are going to manually simulate the page table walking that the x86 does to translate virtual addresses to physical addresses. You will translate two virtual addresses. Some notes:
 
             +------------+            +------------+            +------------+            +------------+
 0xf0f02ffc  | 0xf00f3007 | 0xff005ffc | 0xbebeebee | 0xffff1ffc | 0xd5202007 | 0xffff5ffc | 0xdeadbeef |
             +------------+            +------------+            +------------+            +------------+
             | ...        |            | ...        |            | ...        |            | ...        |
             +------------+            +------------+            +------------+            +------------+
 0xf0f02800  | 0xff005007 | 0xff005800 | 0xf00f8000 | 0xffff1800 | 0xef005007 | 0xffff5800 | 0xff005000 |
             +------------+            +------------+            +------------+            +------------+
             | ...        |            | ...        |            | ...        |            | ...        |
             +------------+            +------------+            +------------+            +------------+
 0xf0f02000  | 0xffff5007 | 0xff005000 | 0xc5201000 | 0xffff1000 | 0xf0f02007 | 0xffff5000 | 0xc5202000 |
             +------------+            +------------+            +------------+            +------------+
    
Based on the pages and %cr3 value above, what's the output of the following C excerpt? (Note: %x in printf means printing out the integer in hexadecimal format.)
  int *ptr1 = (int *) 0x0;
  int *ptr2 = (int *) 0x200ffc;
  printf("%x %x\n", *ptr1, *ptr2);

TLB, page faults

Assume that the assembly code below is executed after a context switch. Make the following additional assumptions:
[context switch]
0x500     movl 0x200000, %eax    # move data in address 0x200000 to register %eax
0x504     incl %eax, 1           # add one to %eax
0x508     movl %eax, 0x300000    # move register %eax to memory location 0x300000
Answer the following questions:
  1. How many TLB misses will happen, and for which pages?
  2. How many page faults will happen, and for which pages?

Last updated: Mon May 04 11:24:46 -0400 2015 [validate xhtml]