riscv-rust 是一个用 Rust 编写并编译为 WebAssembly 的RISC-V处理器和外围设备模拟器项目

riscv-rust



riscv-rust is a RISC-V processor and peripheral devices emulator project written in Rust and compiled to WebAssembly. You can import RISC-V emulator into your Rust or JavaScript project. Refer to the Slides for more detail.

Online Demo

You can run Linux or xv6 on the emulator in your browser. Online demo is here

Screenshots


Documents

Features

  • Emulate RISC-V processor and peripheral devices
  • Stable as Linux and xv6-riscv run on it
  • Linux OpenSBI and legacy BBL boot support
  • Runnable locally
  • Also runnable in browser with WebAssembly
  • Debugger
  • You can import RISC-V emulator into your Rust or JavaScript project

Instructions/Features support status

  • RV32/64I
  • RV32/64M
  • RV32/64F (almost)
  • RV32/64D (almost)
  • RV32/64Q
  • RV32/64A (almost)
  • RV64C/32C (almost)
  • RV32/64Zifencei (almost)
  • RV32/64Zicsr (almost)
  • CSR (almost)
  • SV32/39
  • SV48
  • Privileged instructions (almost)
  • PMP

etc...

The emulator supports almost all instructions listed above but some instructions which are not used in Linux or xv6 are not implemented yet. Your contribution is very welcome.

How to import into your Rust project

The emulator module is released at crates.io. Add the following line into Cargo.toml of your Rust project.

复制代码
[dependencies]
riscv_emu_rust = "0.2.0"

Refer to Document for the API.

How to build core library locally

sh 复制代码
$ git clone https://github.com/takahirox/riscv-rust.git
$ cd riscv-rust
$ cargo build --release

How to run Linux or xv6 as desktop application

sh 复制代码
$ cd riscv-rust/cli
# Run Linux
$ cargo run --release ../resources/linux/opensbi/fw_payload.elf -f ../resources/linux/rootfs.img
# Run xv6
$ cargo run --release ../resources/xv6/kernel -f ../resources/xv6/fs.img

How to run riscv-tests

Prerequirements

sh 复制代码
$ cd riscv-rust/cli
$ cargo run $path_to_riscv_tets/isa/rv32ui-p-add -n

How to import and use WebAssembly RISC-V emulator in a web browser

See wasm/web

How to install and use WebAssembly RISC-V emulator npm package

See wasm/npm

Linux RISC-V port

Running 64- and 32-bit RISC-V Linux on QEMU

xv6-riscv

xv6-riscv is the RISC-V port of xv6 which is UNIX V6 rewritten by MIT for x86 in the current C language.

Specifications

相关推荐
mikuyyds9 小时前
geo-toolbox 插件算法解析:RUSLE 与 MUSLE 的工程化落地
算法·rust·gis
qq_4523962310 小时前
第十四篇:《系统编程实战:用 Rust 编写高性能 HTTP 服务器》
rust
Amos_Web14 小时前
Rspack 源码解析(十一):资产 Hook 与增量构建
前端·rust·源码阅读
孙启超15 小时前
【AI开发之Rust】第 12 课:并发模型与同步原语
开发语言·后端·rust
柯南466815 小时前
【AI开发之Rust】第 13 课:async/await 与 tokio 异步运行时
rust·编程语言
RISCV_Explorer16 小时前
RISC-V处理器性能优化:从指令集到微架构的协同设计
后端·risc-v
传奇开心果编程16 小时前
【Rust入门练中学】第4课:函数与所有权入门
开发语言·学习·rust
右耳朵猫AI16 小时前
Rust周刊2026W38 | mold重写Rust、认证级Rust裸机、Slint 1.18发布、lint提速3133倍
后端·rust·系统编程