Shipped this project!
I built an emulator for the RISC-V unprivileged architecture, it emulates over a hundred instructions, 4 different extensions (Rv64IMF + Zicsr), and 6 different Linux system calls.
RISC-V is an open architecture developed by UC Berkley and other universities, “open” here does not mean open source, as there is no source, but it means anyone is allowed to create hardware for it without paying any license fees. Development of the ISA is also public. These characteristics resonate a lot with what I personally thought of flavortown, so I figured it would be an interesting project to do and ship.
RvRun was written in accordance to the RISC-V specification 1, as a matter of fact, I’d say I spent more time reading it than writing code. There are almost 700 pages, after all. I also tried following IEE-754-2008 2 whenever I could, but I must admit that was almost impossible, since it’s not exactly a free document.
Due to the very nature of RvRun, it cannot be used outside of Linux. For that reason, I added several asciinema recordings of it working. All of the .cast files are in the asciinema/ directory in the repository, but you can also watch them on the web. The URL for each example program is in the README, under the “Asciinema recordings” section.
RvRun does not have any dependencies, I implemented everything from scratch in C. Example programs were written in assembly.
Implementing floating point instructions was quite hard (as you might guess by my devlogs). It took Berkley to write a library to handle it, so doing everything myself wasn’t exactly the smartest of the choices. Regardless, I am very proud of my somewhat successful implementation.
The demo includes a pre-compiled binary for x86-64 Linux, and six different RISC-V 64bit binaries that can be emulated by RvRun. Simply download the RvRun-v1.1.zip file and unzip it. If you’d prefer, compilation is also supported with both clang and gcc, instructions on how to do that are in the README.
You can find the pre-compiled example programs in the examples/ directory, the repository only contains the code for them, but the release includes the ELF files too. Simply run rvrun examples/<PROGRAM>.elf to test it, instructions on how each example can be used are found in examples/README.md
If you want to write your own assembly programs and emulate them under RISC-V, use the riscv64-elf-linux-gnu-* toolchain for compilation. Keep in mind you’ll need to add the -march=rv64imf (or your assembler’s equivalent) argument to your assembling command, because even if you only use the instructions present in these extensions, there are other extensions (e.g. the C one) that can be added transparently to the programmer, and that are not supported by RvRun. You will also need to keep your programs statically linked, and without a libc.