Operating Systems


Homework: virtual memory

Assignment Part 1

On x86 using 4KB pages only, we wish to map virtual address 0x80100000 to physical address 0x00100000 with read-only permissions. Assume that all segments are setup to [0:0xffffffff] and use only paging. You will need to describe the offset at which the page directory and the page table need to be modified and to what values.

Assignment Part 2

Let's look at the page table (kpgdir) that setupkvm produces
(gdb) break kvmalloc
(gdb) next
(gdb) print/x kpgdir[0]
why is this zero?

let's look up a virtual address
how about the first instruction of kvmalloc
(gdb) x/i kvmalloc
0x80107990 :  push   %ebp
how would we translate 0x80107990 to a physical address?

(gdb) print/x 0x80107990 >> 22
$4 = 0x200
(gdb) print/x kpgdir[0x200]
$6 = 0x114007
Q: what is this?
Q: what is the PPN?
Q: what does the 7 mean?
(gdb) print/x (0x80107990 >> 12) & 0xfff
$6 = 0x107
(gdb) print/x ((int*)0x114000)[0x107]
$12 = 0x107001
Q: what is this?
Q: why 1 in the low bits?
(gdb) print/x 0x107000 + 0x990
$13 = 0x107990
(gdb) x/i 0x107990

why did the physical address work in gdb?

back to kvmalloc
it called setupkvm to create a page table
now it calls switchkvm to start using it
switchkvm loads kpgdir into %cr3

and now 0x170990 won't work:
(gdb) x/i 0x107990
0x107990:       Cannot access memory at address 0x107990

why?

Assignment Part 3

Suppose you wanted bootmain() to load the kernel at 0x80200000 instead of 0x80100000, and you did so by modifying bootmain() to add 0x100000 to the va/pa of each ELF section. Something would go wrong. What?

Assignment Part 4 (pintos submissions)

You should have submitted Lab1 by now using os-submit-lab1 script.

You should now download the pintos source code here. Next, you should submit the base version of pintos using os-submit-pintos script (we need that you submit the base version to be able to correctly submit your next lab). You will need to create a Subversion repository for yourself to do this. See instructions on the tools page for instructions on using Subversion.

On successful submission, you should have seen a "Congratulations" message with your submission ID if your submission was successful. At any time, you can check if your submission has been made by typing "os-get-submission base". For future assignments just replace base with userprog, vm, etc. The os-get-submission script should create a directory with your submission-id. This directory should contain a submit.note file.

You should build your solution to Lab2 (userprog) on top of the base pintos version that you submitted. We encourage you to use the SVN repository actively during development. Use good and illustrative commit messages. We will examine your repository log during demos.

Study the grading policy on the Administrivia page. You can check your current score using os-score script. In case of multiple submissions by the same person/group, we will use the date of your last submission to compute the late days. Notice that late days are counted at the granularity of hours. So if you are late by 4 hours for Lab1 and late by 5 hours for Lab2, your total late "days" is only 9 hours (not 2 days). Nothing to turn in for this part.