Virtual Memory Questions
Part A. What is:
- PAGEOFFSET(0)? 0
- L2PAGEINDEX(0)? 0
- L1PAGEINDEX(0x9000)? 0
- PAGEOFFSET(1023)? 1023
- L4PAGEINDEX(0x0000000070000000)? 0
- L4PAGEINDEX(0x0000000070000FFF)? 0
- L3PAGEINDEX(0x0000000070000FFF)? 0x300
- L2PAGEINDEX(0x0000000070000FFF)? 1
- PAGEOFFSET(0x0000000000801000)? 0
- L4PAGEINDEX(0x00F0089A00801000)? 1
- L1PAGEINDEX(0x00F0089A00801000)? 17
- PAGEOFFSET(0x0080100000F0089A)? 0x89A (2202)
- L3PAGEINDEX(0x0080100000F0089A)? 7
- L2PAGEINDEX(0x0080100000F0089A)? 0
Part B. For each question, give a virtual address that satisfies the constraints.
- PAGEOFFSET = 0: 0x97865000 (anything that has lower three hex digits 0)
- PAGEOFFSET = 0 and L1PAGEINDEX = 12: 0x0000060000000000
- 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;
}