This is a RISC-V emulator for the RV32I architecture, based on TinyEMU and stripped down for RV32I only.
Requires libelf-dev:
$ sudo apt-get install libelf-devHow to compile it:
$ gcc -O3 -Wall -lelf emu-rv32i.c -o emu-rv32ior
$ make emu-rv32iPassed RV32I compliance tests from https://github.com/riscv/riscv-compliance
- Must install the risc-v toolchain
$ git clone https://github.com/riscv/riscv-compliance
$ cd riscv-compliance
$ make RISCV_PREFIX=riscv-none-embed- RISCV_DEVICE=rv32i TARGET_SIM=emu-rv32i variantCompiling and running simple code:
$ make test1then
$ ./emu-rv32i test1
Hello RISC-V!- RV32M and RV32A instructions may be enabled by commenting
#define STRICT_RV32I.
Passed RV32C compliance tests from https://github.com/riscv/riscv-compliance
make C-ADDI.logIf there is no accident, it will output the TEST PASSED
- RV32C instructions can be enabled by commenting
#define RV32C
https://github.com/riscv/riscv-gnu-toolchain
64-bit universal version (riscv64-unknown-elf-* that can build 32-bit code too):
$ ./configure --prefix=/opt/riscv
$ make32-bit version (riscv32-unknown-elf-*):
$ ./configure --prefix=/opt/riscv32 --with-arch=rv32i --with-abi=ilp32
$ make