Menu

BuildCPU

Roy van Koten

Building the CPU

Before compiling one of the projects in Quartus, multiple other files are needed or need to be build first.

The CPU itself, and thus all the projects, will need the build microcode memory file. The microcode definition file is stored in the ucode directory. This file is in a custom format which can be read by the UCodeBuilder tool. This tool creates the microcode memory file and stores it in the rt/cpu directory. A precompiled microcode file should already be included with this package.

The CPU still needs something to run. There are several tests, for checking the CPUs functional correctness, located in the test directory. Most of these files come from the Zet processor project by Zeus Gomez Marmolejo. The Zet project is licensed under the GNU v3 license. See http://zet.aluzina.org/ for more info. The assembly source code of these tests is located in the test/src directory. The test/bin subdirectory contains the compiled binaries. The cpu needs these files in hex format, which will be located in the test/hex directory. The test programs can be compiled with the tools given in the previous section.

To compile and create the binary files run:

    make all

To compile and create the binary and hex files run:

    make allhex

After compilation copy the bin and hex files to the appropriate directories.

The last thing we need before compiling and simulating is the test bench and a simulation script. The bench directory contains test benches and scripts for running the simulations. Test benches and scripts are located in different subdirectories corresponding to the project or simulation they belong to. For the cpu project we can choose between two scripts: one for running a specific test (OSOC86_cpu.do) and another for running all the tests one after another (OSOC86_cpu_all_tests.do). When running one specific test we will need to select the test in the test bench. Look for the code shown below in testbench.v:

   initial
   begin
      for (i=0; i < 1048576; i=i+1)
         RAM[i] = 8'b0;

      //--- testing ---
      tmpID = 5'h01;

      $sformat(tmpStr, "instlog%h.txt", tmpID);
      file = $fopen(tmpStr, "w");
      $sformat(memFile, "..\\..\\..\\..\\test\\hex\\testmem%h.txt", tmpID);
      $readmemh( memFile, RAM, 983040, 1048575);
   end

The value of tmpID needs to be changed to correspond to a test file located in test/hex/. For simulating all the tests with OSOC86_cpu_all_tests.do this value will be overwritten by the script and can thus be ignored.

Now the cpu project can be compiled and simulated with Quartus/Modelsim. The simulation results are written to project/cpu/simulation/modelsim/instlogXX.txt where XX refers to the corresponding test. The CompareTestResults tool can be used for comparing the results produced by simulation to the results file in the test directory.


Related

Wiki: Description
Wiki: Home

MongoDB Logo MongoDB