All Projects → d0iasm → Rvemu

d0iasm / Rvemu

Licence: mit
RISC-V emulator for CLI and Web written in Rust with WebAssembly. It supports xv6 and Linux (ongoing).

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Rvemu

Rvemu For Book
Reference implementation for the book "Writing a RISC-V Emulator in Rust".
Stars: ✭ 141 (-51.21%)
Mutual labels:  riscv, emulator
Unicorn
Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, X86)
Stars: ✭ 4,934 (+1607.27%)
Mutual labels:  emulator, riscv
Rv8
RISC-V simulator for x86-64
Stars: ✭ 476 (+64.71%)
Mutual labels:  riscv, emulator
ravel
A RISC-V simulator
Stars: ✭ 24 (-91.7%)
Mutual labels:  emulator, riscv
sedna
Sedna - a pure Java RISC-V emulator.
Stars: ✭ 52 (-82.01%)
Mutual labels:  emulator, riscv
rv32emu
RISC-V RV32I[MAC] emulator with ELF support
Stars: ✭ 61 (-78.89%)
Mutual labels:  emulator, riscv
riscv em
Simple risc-v emulator, able to run linux, written in C.
Stars: ✭ 51 (-82.35%)
Mutual labels:  emulator, riscv
Riscv Rust
RISC-V processor emulator written in Rust+WASM
Stars: ✭ 253 (-12.46%)
Mutual labels:  riscv, emulator
project-migration-tools
Project Migration tools to help you migrating to IAR Embedded Workbench more efficiently.
Stars: ✭ 36 (-87.54%)
Mutual labels:  riscv
Webmsx
WebMSX - Online MSX Emulator
Stars: ✭ 269 (-6.92%)
Mutual labels:  emulator
NMSIS
Nuclei Microcontroller Software Interface Standard Development Repo
Stars: ✭ 24 (-91.7%)
Mutual labels:  riscv
PokemonBattleEngine
A C# library that can emulate Pokémon battles.
Stars: ✭ 92 (-68.17%)
Mutual labels:  emulator
Road To Yuzu Without Switch
This Repo explains how to install the Yuzu Switch Emulator without a Switch
Stars: ✭ 267 (-7.61%)
Mutual labels:  emulator
OldScape
Oldschool Runescape Emulation
Stars: ✭ 30 (-89.62%)
Mutual labels:  emulator
Ps4delta
Experimental PlayStation 4 Emulator
Stars: ✭ 277 (-4.15%)
Mutual labels:  emulator
speljongen
gameboy emulator written in c++
Stars: ✭ 15 (-94.81%)
Mutual labels:  emulator
wcecl
Allows to run Windows CE applications on Windows!
Stars: ✭ 54 (-81.31%)
Mutual labels:  emulator
Apple2js
An Apple II emulator written in Javascript
Stars: ✭ 284 (-1.73%)
Mutual labels:  emulator
Maxine Vm
Maxine VM: A meta-circular research VM
Stars: ✭ 274 (-5.19%)
Mutual labels:  riscv
Jsbeeb
Javascript BBC micro emulator
Stars: ✭ 261 (-9.69%)
Mutual labels:  emulator

rvemu: RISC-V Emulataor

Build Status Actions Status docs.rs crate.io License

RISC-V online/CLI emulator in Rust.

The online emulator is available here:

The emulator supports RV64GC ISA (RV64IMAFD, Zicsr, Zifencei, RV64C), privileged ISA, CSRs, virtual memory system (Sv39), peripheral devices (UART, CLINT, PLIC, Virtio), and device tree. See the "Features List" section for the details of features.

These features are compliant with "The RISC-V Instruction Set Manual Volume I: Unprivileged ISA Document Version 20191214-draft" and "The RISC-V Instruction Set Manual Volume II: Privileged Architecture Document Version 1.12-draft" in the RISC-V specifications.

Usage

The emulator can run both in your browser and in your terminal. Also, the emulator can be embedded in your project by the crate registry.

On Browser

You can run xv6, a simple Unix-like operating system, in rvemu.app/xv6.

Demo

You also be able to run an arbitrary RISC-V binary in rvemu.app. The online emulator supports the following commands:

  • upload: Upload local RISC-V binaries for the execution on the emulator.
  • ls: List the files you uploaded.
  • run [file]: Execute a file which you uploaded or some files are already embedded.
  • help: Print all commands you can use.

See the "Build RISC-V binary" section for more information to build RISC-V binary.

On Terminal

The option --kernel or -k specifies a kernel image, and --file or -f specifies a root filesystem image.

Linux

$ ./target/release/rvemu-cli -k bin/linux/bbl.bin -f bin/linux/busybear.bin

xv6

$ ./target/release/rvemu-cli -k bin/xv6/kernel.bin -f bin/xv6/fs.img

Bare-metal binary

You can use an arbitrary RISC-V binary and you can skip the -f option. An ELF binary should have no headers.

$ ./target/release/rvemu-cli -k <your-binary>

Build

For Web Application

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.

// This is the alias of
// `wasm-pack build lib/rvemu-wasm --out-dir <path-to-rvemu>/public/pkg --target web --no-typescript`.
$ make rvemu-wasm

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

For CLI Tool

Build the emulator as a CLI tool.

$ make rvemu-cli

Build RISC-V Binary

You might need to build RISC-V toolchain.

$ git clone --recursive [email protected]:riscv/riscv-gnu-toolchain.git
$ cd riscv-gnu-toolchain
$ ./configure --prefix=/opt/riscv --with-arch=rv64gc
$ make
$ make linux

Bare-metal C Program

You need to make an ELF file without headers, which starts at the address 0x8000_0000 by the following instructions:

// Make an assembly file from a C file.
$ riscv64-unknown-elf-gcc -S -nostdlib foo.c

// Make a binary file from an assembly file with start position 0x8000_0000.
$ riscv64-unknown-elf-gcc -Wl,-Ttext=0x80000000 -nostdlib -o foo foo.s

// Remove headers from a binary file.
$ riscv64-unknown-elf-objcopy -O binary foo foo.text

Linux

The page Running 64- and 32-bit RISC-V Linux on QEMU helps to build a Linux image. When you compile this project in a x86 computer, you may need to:

  • update CC := gcc to CC := riscv64-unknown-elf-gcc in riscv-pk/build/Makefile
  • comment out the "build bbl" part in busybear-linux/scripts/build.sh

because the build script for cross compiling in riscv-pk is broken. See https://github.com/riscv/riscv-pk/blob/master/configure#L1146-L1148

Testing

You can see the binaries for unit testings in riscv/riscv-tests.

$ make test

Analyzing with Perf

$ perf record -F99 --call-graph dwarf ./target/release/rvemu-cli -k bin/xv6/kernel.bin -f bin/xv6/fs.img
$ perf report

Publish

The site is hosted by a firebase.

$ firebase deploy

Features List

The emulator supports the following features:

  • [x] RV64G ISA
    • [x] RV64I (v2.1): supports 52/52 instructions (fence does nothing for now)
    • [x] RV64M (v2.0): supports 13/13 instructions
    • [x] RV64A (v2.1): supports 22/22 instructions (No atomicity for now)
    • [x] RV64F (v2.2): supports 30/30 instructions
    • [x] RV64D (v2.2): supports 32/32 instructions
    • [x] Zifencei (v2.0): supports 1/1 instructions (fence.i does nothing for now)
    • [x] Zicsr (v2.0): supports 6/6 instructions (No atomicity for now)
  • [x] RV64C ISA (v2.0): support 36/36 instructions
  • [x] Privileged ISA: supports 7/7 instructions (sfence.vma, hfence.bvma, and hfence.gvma do nothing for now)
  • [x] Control and status registers (CSRs)
    • [x] Machine-level CSRs
    • [x] Supervisor-level CSRs
    • [ ] User-level CSRs
  • [x] Virtual memory system (Sv39)
  • [x] Devices
    • [x] UART: universal asynchronous receiver-transmitter
    • [x] CLINT: core local interruptor
    • [x] PLIC: platform level interrupt controller
    • [x] Virtio: virtual I/O
  • [x] Device tree

Dependencies

dtc can be installed by apt install device-tree-compiler on Ubuntu.

Resources

Helpful Tools

Articles about This Project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].