A simple RISC-V emulator
Find a file
2024-12-06 23:11:24 +00:00
example Add readme file and make the example compile 2024-12-06 23:11:24 +00:00
src Add an example program in C 2024-12-06 22:40:52 +00:00
.gitignore Add an example program in C 2024-12-06 22:40:52 +00:00
CMakeLists.txt Implement basic opcodes (not yet all of them) 2024-12-06 21:27:44 +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 Add readme file and make the example compile 2024-12-06 23:11:24 +00:00
rve.nix Add an example program in C 2024-12-06 22:40:52 +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. Install it and run:

nix develop

eval "$configurePhase"
ninja

You should get the rve binary. Run it:

./rve

At the moment the program is hardcoded into the main() function directly in machine code. As a follow-up, I'm working on compiling programs with the gcc cross-toolchain, but it will require some time to fiddle with options.

Cross-toolchain and an example program in C

There is an example program which you can compile, but not yet run. Do this:

cd example
make

As a result, you'll get an example binary. To view the disassembly:

riscv32-none-elf-objdump -D example

As you can see, it's quite barebones, with the program starting at 0x1000. The reason it can't yet be run with the emulator is mostly in the absence of the boot section which initializes the stack and calls the main function. Stay tuned.