A simple RISCV32I/RISCV64I emulator that can execute an ELF executable file compiled with gnu tool chain and Newlib.
Following instructions are partially supported
Support of privilege instruction is partial and not complete.
Some system calls are emulated with limitation
$ make
$ ./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32
$ make -j
$ riscv32-unknown-elf-gcc file_name.c -o file_name -Wall -march=rv32i -mabi=ilp32 -static
Move to the emulator folder, then run the following command.
$ ./RISCV_Emulator file_name
To run the RISCV tests with this emulator, first set $RISCV to the location of where m99_riscv_emulator is placed.
$ RISCV=/folder/where/the/emulator/is/placed
Then, follow the instruction on riscv-tests page as below.
$ git clone https://github.com/riscv/riscv-tests
$ cd riscv-tests
$ git submodule update --init --recursive
$ autoconf
$ ./configure --prefix=$RISCV/target
$ make
$ make install
The test suite is generated under $RISCV/target/
Now you can run test.
$ make test
-v
: Verbose. Emulator output the current PC, disassembled instruction, register status
-e
: System call emulation enabled. See the next section.
-64
: Run in 64 bit mode.
-m
: Disable machine interrupt delegation to supervisor mode. This is for compatibility with QEMU.
-h
: Use "tohost" and "fromhost" functions in riscv-test suite. This is only for riscv-test purpose.
-d:
Device emulation. Enable uart output, virtio disk, and interrupt timer. Press Ctrl-a to exit. (This option is work-in-progress.)
-s <filename>
: Load -d
option.
-p
: Paging enabled. This is for testing purpose.
Following system calls are supported with -e
option with limitation.
Support of xv6 is still under development.
This emulator is able to run xv6 for riscv to show sh prompt.
You first need to compile xv6 for riscv with CPUS=1 option.
Then, you need to copy kernel/kernel
in the Emulator directory.
Also, you need fs.img
(disk image) from xv6 too. fs.img
is generated when running xv6 with QEMU
option.
Run the emulator with -64 -m -d -s fs.img
options (64 bit mode, disable machine interrupt delegation, device emulation, load fs.img
as storage image).
$ ./RISCV_Emulator -64 -m -d -s fs.img kernel
You will eventually see the prompt ($
) pops up.
You can run the commands, for example by typing ls
or cat README
.
Press Ctrl-a
to exit.