Machine Structures. Fall 2003, UC Berkeley
Project 5: Cache Simulator

In this project, we provide an entire MIPS instruction set simulator called TIPS (thousands of instructions per second). It is similar to the simulator you wrote for project 3. This one has a graphical user interface (GUI) a little like xspim. The big feature of our simulator, though, is that it has a cache - which you have to write.

Setup

Copy ~cs61c/lib/proj5/* to a new directory. You should be able to run gmake to build the "tips" program and try it out. The given code has a default cache size of 0, because it has no cache logic written into it yet. After you build and run tips, try experimenting with the three entry fields on the control panel: 'numsets', 'assoc', and 'blocksize'. Type in a new value for each of these followed by a return. You should see the display update to reflect the change in the cache organization.

User instructions

The tips program optionally takes the name of a dump file as its argument. Alternatively, you can load dump files through the graphical interface.

The GUI shows the contents of the cache, registers, and PC. It also dumps the output of the disassembler so you can see what's running. The bottom of the window holds all the controls and inputs for the program.

The cache display draws sets of blocks on top of each other. The first column, "index", is the index of the set within the cache. The next column, "val", shows each block's valid bit. The tags in the third column are shown left-aligned, just as they're stored in the program. No matter how big your cache is, the tag values will always be 32 bits, with the lower bits zero. The "blknum" column numbers the blocks within each associative set. The rest of the columns are the data words in the block. The block size in tips is in terms of words (not bytes).

The register display works just like spim's. The log listing shows the output from the disassembler and any other output messages from the program. You can clear the log with the "Clear output" button on the control panel.

On the control panel, "Init" (or the 'i' key) resets the PC. "Step" (or the 's' key) steps the program. The "Run" checkbutton enables continuous operation when it is checked. When Run is activated, the "Run speed" slider adjusts the delay between steps from 1000 to 50 ms. "Flush cache" calls the flushcache() function in cachelogic.c.

On the control panel are 3 entry fields for 'numsets', 'assoc', and 'blocksize'. These are the variables described in memory.h. You can type new values for these parameters at any time. You can even reshape the cache while your program is running! Press return after changing a number for it to take effect. You can also switch the cache's replacement policy between random and LRU. You have to implement both of those policies in your code.

Files

First, read tips.h. The comments and declarations there describe the API you need to use for your code.

All your code should go in cachelogic.c. In fact, it all has to get called in initMemory, flushcache, and accessMemory. Read the comments in each function to see what it needs to do. You can add other functions in cachelogic.c only to help you. Don't change anything else in the code, including the prototypes of the functions whose bodies you're writing.

To make the GUI work, your code needs to call some functions when certain actions take place. tips.h describes these functions.

Submission

Follow the instructions in cachelogic.c to finish the required functions. You may want to test your code with dump files besides the samples we gave you.

All your code must be in cachelogic.c. When we test your project, we will use all our own files (including the makefile) except for cachelogic.c.