#embedded-devices #risc-v #emulator

no-std rv64emu

A riscv64 emulator written in rust,it can run on Linux, Windows and MacOS. Even on the embedded device, such as ESP32 and STM32 which support Embeded RUST

2 releases

0.1.1 Aug 31, 2023
0.1.0 Aug 30, 2023

#1991 in Embedded development

35 downloads per month

MIT license

315KB
8K SLoC

Introduction

run_linux

RV64emu is a riscv64 emulator written in rust,It can run CoreMark,RT-thread and Linux now. And it is easy to add new devices and support new instructions. The rv64emu is now as a crate, you can use it in your project. Due to RUST's cross-platform feature, it can run on Linux, Windows and MacOS.Even on the embedded device, such as ESP32 and STM32 which support Embeded RUST.

Features

ISA Specification:

  • RV64I
  • RV64M
  • RV64A
  • RV64C
  • RV64F
  • RV64D
  • MachineMode
  • SupervisorMode
  • UserMode
  • Sv39
  • Sv48
  • Sv57
  • PMP

Caches:

  • InstCache
  • DecodeCache
  • DataCache (no performance optimization)
  • Tlb

Devices

  • SifiveUart (full support, including interrupt)
  • 16550AUart (basic support, no interrupt)
  • SifiveClint
  • SifivePlic

Example

The simplest example of using rv64emu as a crate.You can find it in examples directory.

  • simple_system : the simplest example, only have uart and dram
  • ysyx_am_system : support AM environment, use ebread to terminate emulation
  • linux_system : support linux, you can run linux directly

features

Name Function Comment
device_sdl2 support sdl2 device, such vga and keyboard
support_am support AM environment, use ebread to terminate emulation AM github AM pdf
caches support caches,including inst_cache and decode_cache
rv_debug_trace support debug trace,including itrace and ftrace the log file is in /tmp

Run

Run abstract machine applications

The following command will run hello.bin ,which is a simple application in ready_to_run directory. And for details of ysyx_am_system example, please refer to examples/ysyx_am_system.rs.

cargo run --release --example=ysyx_am_system --features="std device_sdl2" -- --img ready_to_run/hello.bin

Apart from hello.bin, there are other applications in ready_to_run directory:

  • hello.bin
  • coremark-riscv64-nemu.bin
  • nanos-lite-riscv64-nemu.bin
  • rtthread.bin

These applications above were build for AM environment.

Run linux

cargo run --release --example=linux_system -- --img ready_to_run/linux.elf

Build linux kernel by yourself

Please refer to rv64emu-sdk for details.

Test

test with riscv-tests

cargo riscv-tests

test with riscof

todo!

No_std support

What a magic feature of rust! You can run rv64emu on the embedded device, such as ESP32 and STM32 which support embeded rust.

But before build your embeded project, you need to disable some features, such as device_sdl2,rv_debug_trace.

  • device_sdl2: because the embedded device does not support sdl2,and some devices, such as vga and keyboard are based on sdl2.

  • rv_debug_trace: because it used crossbeam-channel crate,which is not support no_std. More over, the embedded device does not support file system,and the log file is too large to store.

  • caches: because the embedded device does not have enough memory

No_std examples

  • nostd_esp32s3 :A no_std example about how to use rv64emu in esp32s3.

reference

Dependencies

~3–11MB
~265K SLoC