Testing Your Non-Pipelined Processor (Lab 3)

CSE 372 (Spring 2006): Digital Systems Organization and Design Lab

Overview

Testing your processor is accomplished by comparing its output to the simulator's output. "Output" in this case means comparing the PC, the current instruction, the data memory signals and the data going into the register file on every cycle. The output generated by a particular run of a program is known as a trace. Your single-cycle processor should produce the same exact trace as the simulator for a given program.

Requirements

The latest and greatest version (1.1.3) of the PennSim simulator.

The testbench itself. Note that the .tf file extension causes Xilinx to automatically recognize the file as a Verilog test fixture. You'll also need two of the files from the zip archive available in the hardware tutorial.

Instructions

Simulator Instructions

You can generate a trace from the simulator by using the simulator's aptly-named trace command.

  • First, load your program into the simulator.
  • Set the PC to the instruction at which you want tracing to begin. Optionally, you can set a breakpoint at which you want tracing to stop. You can only turn tracing off after the simulator has halted, or hit a breakpoint.
  • Now that you've loaded the program into memory, you need to save an image of memory that you can load into your processor's memory. Run the dump -readmemh <start> <end> <filename> command in the simulator.
  • start and end specify the range of memory to dump; typically you'll want to grab 0x0000 all the way up to 0xFFFF. Creating a memory dump is fast, as is loading this dump into the simulated memory. The dump is written to the file you specify; the -readmemh flag ensures the memory dump is in the correct format for Verilog's $readmemh() function.
  • NB: The dumped memory image gets loaded into your processor's memory starting at address 0x0000, so you can't just dump the 5 words of memory that actually constitute your program - you need to begin at 0x0000 and capture all the memory that your program uses. It's easiest to just always dump the entire contents of memory.
  • Run the trace on <filename> command in the simulator. This will send trace output to the specified file, in the directory in which the simulator is located.
  • Use the continue to set the simulator going. For every instruction executed, a line will be printed to the trace file.
  • When the program finishes, or hits your breakpoint, run the command trace off. This is necessary to ensure all trace output is flushed to the trace file.

Testbench Instructions

You will need to modify your processor to accept your newly-created memory image and trace file. This requires editing the value of the MEMORY_IMAGE_FILE macro at the top of the memory module bram.v. This memory module is used both for simulation and for synthesis, so if you change it in one place it will affect the other.

You also need to edit which trace file is used by the testbench. This line is clearly marked in test_sc_datapath.v with a comment.

Running the testbench in ModelSim will then load the memory with your program, and then let your processor begin executing. On every cycle, the simulator's trace output is compared with the real signals coming out of your processor, and errors are printed accordingly. No news is good news!

Suggestions for Testing

Start small - Worm isn't the ideal first test case. Write some code to test just one kind of instruction at a time (e.g. ALU operations, loads, branches) and build up as you go. Worm may also not actually test every instruction; our reference implementation doesn't use any JSRR instructions, for example.

Addenda

[23 March] - Explained how to generate memory dumps in more detail.

[22 March] - fixed the testbench - a new testbench (v1.1) and p37x skeleton archive are available. There is now a version comment at the top of the testbench and all provided Verilog files, so you can be sure you have the right version. Also, you'll need the newest version of the simulator to create trace files.

[19 March] - updated instructions to reflect new testbench that uses the same memory as the real p37x_processor module.