In Task 2 in Project 2, you will be creating and initializing the page tables used by user-level processes running on Nachos. This worksheet is intended to give you practice with Nachos page tables so that you are comfortable understanding how virtual memory works in Nachos. The page table for a user-level process is represented by the TranslationEntry[] pageTable array in the UserProcess class. In the UserProcess constructor, you will be initializing each TranslationEntry in the array to have each virtual page point to an allocated physical page.
The size of a memory page in Nachos (Processor.pageSize) is 1024 (0x400) bytes. For the purposes of this worksheet, assume that 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 Processor.mainMemory) to virtual pages (in UserProcess.pageTable).
The initial implementations with System.arraycopy assume that the virtual and physical page numbers are the same, and hence that the physical pages are contiguous in mainMemory. As a result, even if the data spans multiple pages, a simple arraycopy will work correctly.
In the more general implementation, however, there can be an arbitrary mapping between virtual and physical pages. So if the data spans two virtual pages, the physical pages holding the actual data bytes will likely not be contiguous. Using arraycopy on the entire data array will therefore break because it assumes that the data bytes are all contiguous in the array.