Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

mrisc32/mrisc32-simulator

Repository files navigation

MRISC32 simulator

This repository contains a simple CPU simulator for the MRISC32 ISA, written in C++.

DOOM

Above: MRISC32 port of DOOM running in the simulator.

Features

  • Implements the complete MRISC32 ISA.
  • Is portable (works on Linux, macOS and Windows).
  • Implements host OS hooks for newlib, enabling file and console I/O etc.
  • Can display a section of the simulator RAM as (animated) graphics.
  • Simulates parts of MC1 memory mapped I/O (e.g. keyboard and mouse input).

Installation

Pre-built binaries

Pre-built binaries for Linux, macOS and Windows are available here.

Unpack the archive, and add mrisc32-simulator/bin to your PATH environment variable.

Building from source

Use CMake and a C++ compiler to build the simulator:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../sim
cmake --build .

Linux

You need to install X.Org development packages to properly build the simulator on Linux.

For Ubuntu, do: sudo apt install xorg-dev

Compiling programs

Use the MRISC32 GNU toolchain to compile and link programs for MRISC32.

To make the executable suitable for running in the simulator:

  • Pass the -msim flag when linking the executable.

For example:

mrisc32-elf-g++ -O2 -o program.elf program.cpp -msim

Running programs

The ELF32 binary file can be executed by the simulator, like so:

mr32sim program.elf

For additional options and more information, run mr32sim --help.

Debug trace inspector

Debug traces from the simulator (or the MRISC32-A1 VHDL test bench) can be inspected using mrisc32-trace-tool.py. It can be useful for finding differences between different simulation runs.

Function profiling

It is possible to extract dynamic function profiling information from the simulator.

To do profiling you need to generate a symbol/address map file, e.g. using mrisc32-elf-readelf as follows:

mrisc32-elf-readelf -sW program.elf | grep FUNC | awk '{print $2,$8}' > program-symbols

Then run the simulator with the -P and -v flags as follows, which will print the profiling information when the simulator terminates:

mr32sim -P program-symbols -v program.elf