CSE 120 -- Nachos VM Worksheet

Fall 2004

[16 pts] In Project #2, part 1, you need to create a page table for a new address space, allocate physical memory for the address space, and then load the program code and data segments into the address space. This worksheet is intended to give you practice with Nachos page tables so that you are comfortable implementing these operations. The context of this worksheet is the AddrSpace constructor (i.e., interpret references to variables in the context of the AddrSpace constructor method).

For the purposes of this worksheet, assume that PageSize is 128 bytes, the program being loaded requires 4 pages, and physical memory has 8 pages. In the diagram below, we have assigned a set of physical pages (from machine->mainMemory) to virtual pages (in pageTable).

  1. What is the value of the AddrSpace variable numPages?

  2. What is the value of size?

  3. What is the value of NumPhysPages?

  4. What are the values of the pageTable mappings?

  5. What is the virtual address of virtual page 2 (the start of virtual page 2 in the virtual address space)?

  6. What is the physical address of virtual page 2?

  7. What physical page does the virtual address 298 reside in?

  8. What is the offset of the virtual address 298?

  9. What is the physical address of the virtual address 298?

    In the diagram below, we want to load the code (".text") and initialized data (".rdata") segments from the executable file into the virtual address space of the process. Assume that code.inFileAddr has the value 0xF0 as an offset in the executable file, code.virtualAddr is 0x00 in the virtual address space, and code.size is 0x130 bytes. Also assume that initData.inFileAddr is 0x220 in the executable file, initData.virtualAddr is 0x130 in the virtual address space, and initData.size is 0x010 bytes.

  10. What is the physical address that corresponds to code.virtualAddr?

  11. What physical pages is the code loaded into?

  12. What is the physical address that corresponds to initData.virtualAddr?

  13. What physical page is the initialized data loaded into?

  14. At what virtual address does the initialized data end?

  15. Now assume that initData.size is 0x0A0 bytes. What additional physical page is the initialized data loaded into?

  16. Now at what virtual address does the initialized data end?



voelker@cs.ucsd.edu