riscv_emu_rust_wasm
riscv_emu_rust_wasm is a WebAssembly RISC-V processor and peripheral devices emulator based on riscv-rust.
How to install
$ npm install riscv_emu_rust_wasm
How to use
const riscv = WasmRiscv;// Setup program content binaryriscv;// Setup filesystem content binaryriscv; // Emulator needs to break program regularly to handle input/output// because the emulator is currenlty designed to run in a single thread.// Once `SharedArrayBuffer` lands and becomes stable// we would run input/output handler in another thread.const runCycles = { // Run 0x100000 (or certain) cycles, handle input/out, // and fire next cycles. // Note: Evety instruction is completed in a cycle. ; riscv; // Output handling while true const data = riscv; if data !== 0 // print data else break; // Input handling. Assuming inputs holds // input ascii data. while inputslength > 0 riscv; };;
API
Refer to the comments in WasmRiscv
How to build WebAssembly RISC-V emulator locally
Prerequirements
- Install wasm-bindgen client
$ git clone https://github.com/takahirox/riscv-rust.git$ cd riscv-rust/wasm$ bash build.sh