Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSE 120 -- Nachos VM Worksheet [16 pts] In Project #2, Task 2, you need to creat

ID: 662448 • Letter: C

Question

CSE 120 -- Nachos VM Worksheet

[16 pts] In Project #2, Task 2, 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 UserProcess class in userprog/UserProcess.java and the Processor class in machine/Processor.java.

Hint: Open the Javadoc pages for Process and UserProcess and reference them as you work.

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.processor().getMemory()) to virtual pages (in UserProcess.pageTable).

What is the value of the UserProcess variable numPages?

What is the value of the Processor variable pageSize?

What is the value of Processor getNumPhysPages?

What are the values of the pageTable mappings? Remember these are vpn (virtual page number) and ppn (physical page number) represent page numbers and not addresses.

UserProcess.pageTable[0].vpn =

UserProcess.pageTable[0].ppn =

UserProcess.pageTable[1].vpn =

UserProcess.pageTable[1].ppn =

UserProcess.pageTable[2].vpn =

UserProcess.pageTable[2].ppn =

UserProcess.pageTable[3].vpn =

UserProcess.pageTable[3].ppn =

What is the virtual address of virtual page two number two (the start of virtual page 2 in the virtual address space)?

What is the physical address of virtual page number two?

What physical page does the virtual address 298 reside in?

What is the offset of the virtual address 298?

What is the physical address of the virtual address 298?

In the diagram below, we want to load the section one and section two segments from the COFF executable file into the virtual address space of the process. Assume that section zero has the value 0xF0 as an offset in the executable file, section(0) begins at address 0x00 in the virtual address space, and section(0) is 0x130 bytes long. Also assume that section one is 0x220 in the executable file, section(1) begins at address is 0x130 in the virtual address space, and section(1) is 0x010 bytes long.

Hint: At this point you may also want to reference the CoffSection Javadoc.

Final Helpful Tip: After you are done with the worksheet, take a quick look at the implementation of the UserProcess method "load" in your Nachos distribution to see how this all gets implemented in practice.

Virtual Address Space Physical Address Space (getMemory)[) (pageTable[]) 0 1 2 3 2 4 7

Explanation / Answer

What is the value of the UserProcess variable numPages? 4

What is the value of the Processor variable pageSize? 128 bytes

What is the value of Processor getNumPhysPages? 8

What are the values of the pageTable mappings? Remember these are vpn (virtual page number) and ppn (physical page number) represent page numbers and not addresses.

UserProcess.pageTable[0].vpn = 0

UserProcess.pageTable[0].ppn = 1

UserProcess.pageTable[1].vpn = 1

UserProcess.pageTable[1].ppn = 0

UserProcess.pageTable[2].vpn = 2

UserProcess.pageTable[2].ppn = 7

UserProcess.pageTable[3].vpn = 3

UserProcess.pageTable[3].ppn = 4

What is the virtual address of virtual page two number two (the start of virtual page 2 in the virtual address space)?

2

What is the physical address of virtual page number two? 7

What physical page does the virtual address 298 reside in? 6

What is the offset of the virtual address 298? 0xF9

What is the physical address of the virtual address 298? 1

10. What is the physical address that corresponds to the first byte in section(0)? 0xF0
11. What physical pages is the section zero loaded into (answer in page numbers)? 0
12. What is the physical address that corresponds to the first byte in section section(1)? 0x220
13. What physical page(s) is the section one loaded into ? 7
14. At what virtual address does the section one end? 3
15. Now assume that the length of section(1) is 0x0A0 bytes. What additional physical page is the section one loaded into? 5
16. Now at what virtual address does the initialized data end? 3