⇡ lowRISC tagged memory tutorial

Using the C++ emulator generated by Chisel

The Rocket core is written in Chisel. The Chisel compiler is able to generate cycle-accurate C++ simulation models. It is also possible to generate VCD waveform from these to aid debugging.

To compile the Rocket core into a C++ simulation model:

# requirement: riscv-gnu-toolchain, riscv-fesvr
# set up the RISCV environment variables
cd $TOP/emulator
make

This will generate the executable simulator as emulator-DefaultCPPConfig assuming the Default configuration is used. For simulating a different lowRISC configuration, take TAGW32S2T4 for an example, you can either change the CONFIG variable in the Makefile or temporarily run make as:

CONFIG=TAGW32S2T4 make

However, if you decide to the temporary CONFIG target, you need to add the temporary target before all make commands, such as make run.

If the VCD/VPD waveform is needed, you need to compile the C++ simulation model using make debug:

# set up the RISCV environment variables
cd $TOP/emulator
make debug

There are multiple pre-build test cases to test the Rocket core. To run the pre-built tests:

# build and run the basic ISA test cases
make run-asm-tests
# build and run the bench-mark tests
make run-bmarks-test
# build and run the tag cache tests
make run-tag-tests

# build and run all the above tests in a single run
make run

# when VCD is required
make run-asm-tests-vcd 
make run-bmarks-test-vcd
make run-tag-tests-vcd

# all tests in a single run
make run-vcd 

# when VPD is required, you need to have the Synopsys VCS installed
# set up the VCS environment variables
make run-asm-tests-vpd
make run-bmarks-test-vpd
make run-tag-tests-vpd

# all tests in a single run
make run-vpd

To simulate the hello program in the three different modes (assume the program is compiled according to the instructions at the beginning of this document):

Bare metal mode

Requirements: riscv-isa-sim, riscv-fesvr, riscv-gnu-toolchain

# No VCD/VPD file
./emulator-DefaultCPPConfig +dramsim +max-cycles=100000000 +verbose \
  $TOP/riscv-tools/hello/hello.bare 3>&1 1>&2 2>&3 | \
  spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

# VCD file
./emulator-DefaultCPPConfig-debug +dramsim +max-cycles=100000000 \
  +verbose -vhello.vcd $TOP/riscv-tools/hello/hello.bare 3>&1 1>&2 2>&3 | \
  spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

# VPD file, you need to have the Synopsys VCS installed
# set up the VCS environment variables
vcd2vpd hello.vpd.vcd hello.vpd > /dev/null &
./emulator-DefaultCPPConfig-debug +dramsim +max-cycles=100000000 \
  +verbose -vhello.vpd.vcd $TOP/riscv-tools/hello/hello.bare \
  3>&1 1>&2 2>&3 | spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

In the command line, +dramsim loads the dramsim library for modelling the DDRAM; +max-cycles defines the maximal cycles before an enforced stop; spike-dasm translates the instruction binary in the hello.out log file into human readable assembly codes.

With proxy kernel and newlib

Requirements: riscv-isa-sim, riscv-fesvr, riscv-pk, riscv-gnu-toolchain

# No VCD/VPD file
./emulator-DefaultCPPConfig +dramsim +max-cycles=100000000 +verbose \
  pk $TOP/riscv-tools/hello/hello.pk 3>&1 1>&2 2>&3 | \
  spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

# VCD file
# set up the VCS environment variables
./emulator-DefaultCPPConfig-debug +dramsim +max-cycles=100000000 \
  +verbose -vhello.vcd pk $TOP/riscv-tools/hello/hello.pk 3>&1 1>&2 2>&3 | \
  spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

# VPD file, you need to have the Synopsys VCS installed
# set up the VCS environment variables
vcd2vpd hello.vpd.vcd hello.vpd > /dev/null &
./emulator-DefaultCPPConfig-debug +dramsim +max-cycles=100000000 \
  +verbose -vhello.vpd.vcd pk $TOP/riscv-tools/hello/hello.pk \
  3>&1 1>&2 2>&3 | spike-dasm  > hello.out && [ $PIPESTATUS -eq 0 ]

With a full Linux OS

Requirements: riscv-isa-sim, riscv-fesvr, riscv-gcc, riscv-linux, root.bin

# boot the linux
./emulator-DefaultCPPConfig +dramsim +max-cycles=1000000000 +verbose \
  +disk=../riscv-tools/busybox-1.21.1/root.bin \
  ../riscv-tools/linux-3.14.13/vmlinux \
  3>&1 1>&2 2>&3 | spike-dasm  > vmlinux.out && [ $PIPESTATUS -eq 0 ]
# in the booted linux
# /hello

The full Linux test can take HOURS and use up MULTIPLE GB space for log files.