d0iasm/rvemu - RISC-V online emulator with WebAssembly generated by Rust

栏目: IT技术 · 发布时间: 4年前

内容简介:RISC-V online emulator with WebAssembly generated by Rust. The emulator implements the standard extensions RV64G (RV64IMAFD, Zicsr, Zifencei) and complies withThe online emulator is available here:The emulator supports the following features:

rvemu: RISC-V Online Emulataor

RISC-V online emulator with WebAssembly generated by Rust. The emulator implements the standard extensions RV64G (RV64IMAFD, Zicsr, Zifencei) and complies with the RISC-V specifications .

The online emulator is available here:

The emulator supports the following features:

  • RV64G ISAs
    • RV64I (v2.1): supports 52/52 instructions (FENCE, ECALL and EBREAK do nothing for now)
    • RV64M (v2.0): supports 13/13 instructions
    • RV64A (v2.1): 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 does nothing for now)
    • Zicsr (v2.0): supports 6/6 instructions (No atomicity for now)
  • RV64C ISAs
  • Privileged ISAs: supports 7/7 instructions (WFI, SFENCE.VMA, HFENCE.BVMA and HFENCE.GVMA do nothing for now)
  • Control and status registers (CSRs)
    • Machine-level CSRs
    • Supervisor-level CSRs
    • User-level CSRs
  • Virtual memory system (Sv39)
  • Devices
    • UART: universal asynchronous receiver-transmitter
    • CLINT: core local interruptor
    • PLIC: platform level interrupt controller
    • Virtio: virtual I/O

These features are compliant with "The RISC-V Instruction Set ManualVolume I: Unprivileged ISADocument Version 20191213" and "The RISC-V Instruction Set ManualVolume II: Privileged ArchitectureDocument Version 20190608-Priv-MSU-Ratified".

Usage

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

d0iasm/rvemu - RISC-V online emulator with WebAssembly generated by Rust

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.

Build and run on the local browser

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

Build and run as a CLI tool

The emulator can be executed as a CLI tool too. You can build it by make rvemu-cli command which is the alias of cargo build --release --manifest-path lib/rvemu-cli/Cargo.toml .

To execute the RISC-V ELF binary, xv6 in the folloing example, you can use --kernel or -k options to specify the kernel image. Note that xv6-kernel.text is an ELF file without headers by the command riscv64-unknown-elf-objcopy -O binary kernel xv6-kernel.text

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

You can see the details of how to use by the help option.

$ ./target/release/rvemu-cli --help
rvemu: RISC-V emulator 0.0.1
Asami Doi <@d0iasm>

USAGE:
    rvemu-cli [FLAGS] [OPTIONS] --kernel <kernel>

FLAGS:
    -d, --debug      Enables to output debug messages
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -f, --file <file>        A raw disk image
    -k, --kernel <kernel>    A kernel ELF image without headers

Build RISC-V binary

The emulator starts to execute at the address 0x8000_0000, the start address of DRAM, so you need to extract .text section and place it to the address.

// Make an assembly file from a C file.
$ riscv64-unknown-elf-gcc -S -nostdlib hoge.c
// Make a binary file from an assembly file with start position 0.
$l riscv64-unknown-elf-gcc -Wl,-Ttext=0x80000000 -nostdlib -o hoge hoge.s
// Extract a text section from a binary file.
$ riscv64-unknown-elf-objcopy -O binary hoge hoge.text

Testing

You can see the binaries for unit testings in riscv/riscv-tests . The following command executes all rv64ua/d/f/i/m-p-* binaries. TODO: not all tests are passed for now.

$ make test

Analyzing with perf

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

Publish

The site is hosted by a firebase.

$ firebase deploy

Dependencies

  • wasm-pack
  • npm

Resources

Documents

Implementation of other emulators

Helpful tools

Articles about this project


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

ANTLR 4权威指南

ANTLR 4权威指南

Terence Parr / 张博 / 机械工业出版社 / 2017-5-1 / 69元

ANTLR是一款强大的语法分析器生成工具,可用于读取、处理、执行和翻译结构化的文本或二进制文件。它被广泛应用于学术领域和工业生产实践,是众多语言、工具和框架的基石。Twitter搜索使用ANTLR进行语法分析,每天处理超过20亿次查询;Hadoop生态系统中的Hive、Pig、数据仓库和分析系统所使用的语言都用到了ANTLR;Lex Machina将ANTLR用于分析法律文本;Oracle公司在S......一起来看看 《ANTLR 4权威指南》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具