Individual Lab 4 - Virtual Memory

CS3410 Spring 2014

Due in class during your lab section


We give you the source code to the MIPS simulator that we have been using in previous assignments. Modify the simulator to simulate virtual memory, including a shared memory system call with copy-on-write semantics.

The original simulator code did not implement virtual memory: for each load and store, the simulator simply used the address to index into a large array (allocated using malloc). We have modified the simulator in a few simple ways to get you started. In particular, we have implemented the simulation for the hardware part of the the virtual memory system, but not the software part:

What is left for you to do is implement the simulation of what would normally be done by the operating system:

We provide a header file that describes precisely what each function should do.

What to submit

Submit your well-commented vmem.c file and your vsimulate binary. You should not have to change any other files. Not including comments, it is feasible to complete this lab in about 50 lines of code.

Overview of source files

All of the source files for the simulator are available in the course directory in the CSUG Lab. The top level directory contains the simulator source code and a Makefile for compiling it. You should copy the files to your own directory to work on them:

 $ cp -r /courses/cs3410/lab4 ~/lab4
 $ cd ~/lab4

If you will be using the VM instead of CSUG then follow the instructions here.

The mips subdirectory contains an example MIPS program that uses shared memory (you can also write your own MIPS test programs if needed), and a Makefile for compiling it.

The most relevant files for you are:

The _mem_ref() function is used by the simulator to traverse the page tables on each memory access to a virtual address; it is implemented in mem.c. You may find it helpful to at least look at this function to be sure you understand what it is doing. Otherwise, most of the simulator code is not terribly interesting. In rough order of interest, are:

Compiling the Code

To compile the simulator (do this each time you edit vmem.c or anything in the lab4/ dir) from the lab4/ directory:

$ make

To compile the test program (only do this once) from the lab4/ directory:

$ cd mips/
$ make
$ cd ..

To run the test program:

./vsimulate mips/hello


We have slightly upgraded the simulator's built-in interactive debugger (the "-d" option) so that it can work with simulated virtual memory. The "info memory" command now prints out information about both simulated physical and virtual memory. And the "x" command to examine memory has been replaced with two commands: "vx" for examining simulated virtual memory; and "px" for examining simulated physical memory.

The simulator itself runs on x86 linux platforms, and so is compiled with regular gcc instead of mipsel-linux-gcc. If you need to debug the simulator, try the gdb interactive debugger. You should find that it has an interface much like the simulator's built-in MIPS debugger:

    $ gdb vsimulate
    GNU gdb 6.8-debian
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i486-linux-gnu"...
    (gdb) break map_page 
    Breakpoint 1 at 0x8050c0d: file vmem.c, line 25.
    (gdb) run mips/hello
    Starting program: /home/hw342/hw4/vsimulate mips/hello
    [Thread debugging using libthread_db enabled]
    [New Thread 0xb7ea16c0 (LWP 6124)]
    [Switching to Thread 0xb7ea16c0 (LWP 6124)]
    Breakpoint 1, map_page (context=290816, vaddr=4194304, writeable=0, executable=0) at vmem.c:25