CS 39 -- Assignment 2


Supporting virtual memory

There is a new version of the virtual machine (hereafter the CPU) that now sports a memory management unit (MMU). As a result, some things have disappeared from the CPU: specifically, the base and limit registers that controlled memory access.

Along with their disappearence comes the need, in the kernel, to add offsets (such as getMemoryBegin()) in order to access the contents within the virtual machine's main memory. Thus, all access to that main memory will be via the MMU.

This MMU will perform mapping from virtual addresses to physical addresses (which are within the virtual machine's main memory). The MMU, at any given moment, will only be able to translate virtual to physical addresses for a small set of pages. These few mappings will be TLB Mapping Information Entries (MIEs) held in the Translation Lookaside Buffer (TLB).

The CPU itself (particularly the LOAD and STOR instructions) have been modified to work through the MMU. One other addition to the CPU has been a current process ID register. The integer identifier for the current process must be loaded into this register, as the MMU uses that identifier to distinguish between pages belonging to different processes that may have the same virtual address.

So, your goal in this assignment will be to provide virtual memory for processes running on the virtual platform. The details are described below, but first, a note: You will not be implementing a full virtual memory system! There are simplifications to the virtual memory support that we want for this assignment, so be sure to read the requirements carefully, and ask questions if the requirements aren't clear!


The MMU interface

We describe here how the kernel can interact with the new CPU/MMU features. We will break the interaction into two categories: Submitting MMU requests, and Handling MMU-generated traps.

Submitting MMU requests

The MMU allows the kernel (or the CPU) to read from or write to a specific location in the virtual memory space of the current process. (It is important to note that the MMU uses the current process ID when mapping pages.) Below are descriptions of the four functions that allow this access, plus one function needed for TLB management:

Handling MMU-generated traps

When the four functions above attempt to translate the given virtual address to a physical address, that mapping can fail in a number of ways. When the failure occurs, the MMU/CPU trap into the kernel for assistance. There are two kinds of traps that your kernel must support:

The format of the page table, stored and managed within the kernel, is completely up to you. Within these trap handlers, you can do whatever is needed to translate information between the MMU's format (specifically MIE's) and your own, internal, kernel format for PTE's.


Your assignment (specifically)

Login to your account on the CS UNIX systems. You should copy the following tarball into your group's project directory:

~sfkaplan/cs39/assignment-2-code.tar.gz

(If you don't recall how to decompress and un-archive the tarball, revisit the Getting Started page under the course's Projects page.)

Note that, unlike last time, the tarball does not include a kernel -- it's just the machine itself. You will have to adapt your kernel to the new and different capabilities of the CPU and MMU. There are also some new executables that load some data and manipulate it, thus stressing the correctness of your page swapping.

The following points should describe what you need to do:

  1. Create a page table structure. This structure should allow you to look up any requested virtual page and find it's corresponding physical address (if any) and attributes (read/write permissions, modified/referenced bits, etc.)
  2. Write functions/methods that allow for insertion, deletion, and modification of the page table. These may evolve as you see how other parts of your kernel will use them.
  3. Write the TLB miss handler. It should be able to take evicted TLB entries and use them to update the page table as needed. It should also be able to provide an appropriate MIE to the MMU for a given virtual address.
  4. Write the invalid memory access handler. It should be able to determine the cause of the trap, and then deal with it appropriately, either by killing an offending process, or by managing the pages so that the MMU can succeed the next time. This handler should include the capability for automatic page swapping to a backing store. Backing store space should be "fake" -- that is, your kernel should allocate a chunk of space that it can use as a backing store, outside of the virtual machine's main memory. Note that your PTEs must be able to indicate not only that a page isn't resident, but that it resides at a specific location in the backing store.
  5. Change how space is allocated for a process. Before, you took a fixed slice of space from main memory, and allocated that to a given process. Instead, if the kernel needs to allocate space for a process, it should create a new page mapping in the address space of that process, and insert the mapping into its page table. Then, when the process or the kernel attempts to use that space, the MMU (along with the trap handlers) can successfully provide access to it.
  6. Update the function for loading an executable image for a new process. In particular, ensure that it uses the allocation facilities created in the previous step, and that it loads the executable image into the virtual machine's main memory via the MMU functions.
  7. Create a new system call, MMAP, which should have the constant 0x11111100. When a process issues this system call, the register specified by operand-1 will contain a virtual address. The kernel should create a new page table entry for the virtual page that contains the given virtual address. If such a page is already mapped, the system call should simply ignore the request.
  8. Update the FORK system call -- specifically, update the part of that system call which makes an identical copy of the main memory space for the child process. Unlike before, this copying will require the mapping of new pages in the context of the new process, as well as the copying of the data itself from the parent's virtual pages to the child's virtual pages.

Remember, no changes to the virtual machine, including the MMU, should be needed. Bugs should be reported to me, as I may need to modify the virtual machine and issue an update to all of the groups.


Submitting your work

All of your work should be done in your project directory. More specifically, within your project directory, be sure to create a new subdirectory for this assignment -- Don't clobber your old work!

When your group has completed its project, it should gather all of the files that are part of the completed project, and place a copy of those files in a directory named assignment-2 within your group's project directory. I will go and find them there. Some groups forgot this step on the last assignment!

This assignment is due on Friday, November 2nd at 11:59 pm!

Scott F. Kaplan
Last modified: Wed Oct 3 22:42:42 EDT 2001