RISC-V online emulator with WebAssembly generated by Rust. The emulator implements the standard extensions RV64G (RV64IMAFD) and cimplies with the RISC-V specifications.
The online emulator is available here: rvemu.app
Supports the following RISC-V ISAs (RV64G): - RV64I (v2.1): supports 52/52 instructions (FENCE, ECALL, and EBREAK don't do anything for now) - RV64M (v2.0): supports 13/13 instructions - RV64A (v2.0): supports 22/22 instructions (No atomicity for now) - RV64F (v2.2): supports 30/30 instructions - RV64D (v2.2): supports 32/32 instructions - Zifencei (v2.0): supports 1/1 instructions (FENCE.i doesn't do anything for now) - Zicsr (v2.0): supports 6/6 instructions (no unittests and no atomicity)
NOTE: This project is currently under intensely development. The source code might be changed dramatically. What to do next is: 1. devices interrupt (refers to memlayout.h in xv6) 1. keyboards 2. timer 3. uart 4. virtio 5. block devices 2. virtual memory
The emulator supports the following commands: - upload: Upload a local RISC-V binary/local RISC-V binaries for an execution on the emulator. - ls: List the files you uploaded. - run [file]: Execute a file. - help: Print all commands you can use.
The wasm-pack build
command generates a pkg directory and makes Rust source code into .wasm
binary. It also generates the JavaScript API for using our Rust-generated WebAssembly. The toolchain's supported target is wasm32-unknown-unknown
.
You need to execute this command whenever you change your Rust code.
$ make rvemu-wasm
// This is the alias of `wasm-pack build lib/rvemu-wasm --out-dir <path-to-rvemu>/public/pkg --target web`.
This command installs dependencies in the node_modules
directory. Need npm install --save
in the public
directory at the first time and whenever you change dependencies in package.json.
$ npm install --save // at the public directory
You can see the website via http://localhost:8000. npm start
is the alias of python3 -m http.server
so you need Python3 in your environment.
$ npm start // at the public directory
The emulator can be executed as a CLI tool.
$ make rvemu-cli
// This is the alias of `cargo build --release --manifest-path lib/rvemu-cli/Cargo.toml`.
The binary file is generated in the target directory.
$ ./target/release/rvemu-cli <binary-file-name>
This emulator starts to execute at the address 0, so you need to extract .text section to execute your binary file on the emulator.
// Make an assembly file from a C file.
$ riscv64-unknown-elf-gcc -S hoge.c -nostdlib
// Make a binary file from an assembly file with start position 0.
$ riscv64-unknown-elf-gcc -o hoge hoge.s -Wl,-Ttext=0 -nostdlib
// Extract a text section from a binary file.
$ riscv64-unknown-elf-objcopy -O binary --only-section=.text hoge hoge.text
You can see the binaries for unit testings in riscv/riscv-tests.
The following command executes all rv64ua/d/f/i/m-p-*
binaries.
$ make test-isa
NOTE: This is deprecated bacause I'll delete them in the future. This tests are
implemented in the lib/rvemu-wasm/tests
directory.
You need to install a Firefox browser, a Chrome browser, or a Safari browser to run the integration testings. A browser can be specified by a --firefox
or a --chrome
flag.
$ make test-wasm
The site is hosted by a firebase.
$ firebase deploy