A simple RISC-V emulator
Find a file
2024-12-09 20:17:21 +00:00
example Keep symbols in the example app to allow debugging with gdb 2024-12-08 23:41:29 +00:00
src Implement gdb single-stepping 2024-12-09 20:17:21 +00:00
.clang-format Add clangd and clang-format configs 2024-12-09 00:48:40 +00:00
.clangd Add clangd and clang-format configs 2024-12-09 00:48:40 +00:00
.gitignore Make the C-compiled program actually work 2024-12-07 01:19:22 +00:00
CMakeLists.txt Add a trivial gdb stub, runnable but not yet fully working 2024-12-08 23:32:45 +00:00
flake.lock Initial commit 2024-12-06 19:44:09 +00:00
flake.nix Add an example program in C 2024-12-06 22:40:52 +00:00
README.md Make an example program a bit more interesting 2024-12-07 20:02:32 +00:00
rve.nix Add a trivial gdb stub, runnable but not yet fully working 2024-12-08 23:32:45 +00:00

A simple RISC-V emulator

This is a toy emulator for RISC-V, made for educational purposes. The goal is to have a base rv32i instruction set (the bare minimum) plus a M-extension for division and multiplication. In theory, it should be enough to execute simple C programs compiled with GCC and sprinkled with a few linker scripts. Of course, no libc because there's no OS.

Compiling and running

You'd need nix package manager in order to build the project. This is because installing cross-toolchain to compile an example project is difficult, and I don't know of other ways except nix that make it easy.

If you don't have it, install it like this:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

Now, to build the emulator:

nix develop

eval "$configurePhase"
ninja

As a result you should get an executable called rve

Cross-toolchain and an example program in C

There is an example program which you can compile. It requires some custom toolchain so currently not built with CMake. To compile it:

cd example
make

As a result, you'll get an example.raw binary. To execute it:

./rve ../example/example.raw

The expected output of the example program is 40320.