Ancient CS 61 Content Warning!!!!!1!!!
This is not the current version of the class.
This site was automatically translated from a wiki. The translation may have introduced mistakes (and the content might have been wrong to begin with).

Virtual Memory Questions

Part A. What is:

  1. PAGEOFFSET(0)? 0
  2. L2PAGEINDEX(0)? 0
  3. L1PAGEINDEX(0x9000)? 0
  4. PAGEOFFSET(1023)? 1023
  5. L4PAGEINDEX(0x0000000070000000)? 0
  6. L4PAGEINDEX(0x0000000070000FFF)? 0
  7. L3PAGEINDEX(0x0000000070000FFF)? 0x300
  8. L2PAGEINDEX(0x0000000070000FFF)? 1
  9. PAGEOFFSET(0x0000000000801000)? 0
  10. L4PAGEINDEX(0x00F0089A00801000)? 1
  11. L1PAGEINDEX(0x00F0089A00801000)? 17
  12. PAGEOFFSET(0x0080100000F0089A)? 0x89A (2202)
  13. L3PAGEINDEX(0x0080100000F0089A)? 7
  14. L2PAGEINDEX(0x0080100000F0089A)? 0

Part B. For each question, give a virtual address that satisfies the constraints.

  1. PAGEOFFSET = 0: 0x97865000 (anything that has lower three hex digits 0)
  2. PAGEOFFSET = 0 and L1PAGEINDEX = 12: 0x0000060000000000
  3. L1PAGEINDEX = 5, L2PAGEINDEX=64, L3PAGEINDEX=32 L4PAGEINDEX = 128, PAGEOFFSET = 256: 0x0000029004080100

Part C. Your problem set defines the following function. Can you define it as a single expression?

int PAGEINDEX(uint64_t va, int level) {
`    // Returns the `level` page index of `va`. `
   // level==0 returns L1PAGEINDEX, level==1 returns L2PAGEINDEX, etc.
   return YOUR CODE HERE;
}

Answer:

int PAGEINDEX(uint64_t va, int level) {
`    // Returns the `level` page index of `va`. `
   // level==0 returns L1PAGEINDEX, level==1 returns L2PAGEINDEX, etc.
   return (va >> (39 - 9*level)) & 0x1FF;
}