GithubHelp home page GithubHelp logo

rv64_emulator's Introduction

rv64_emualtor

Simple RISC-V 64bit emulator, which can boot linux kernel.

The rv64_emulator project is a RISC-V ISA emulation suite which contains a full system emulator and an ELF instruction frequency analyzer:

  • rv64_emulator - full system emulator with soft MMU
  • rv_analyzer - ELF file instruction frequency analyzer

RISC-V full system emulator

The rv64_emulator includes a full system emulator that implements the RISC-V privileged ISA with support for interrupts, MMIO (memory mapped input output) devices, a soft MMU with TLB. It has the following features:

  • riscv64ima plus privileged ISA
  • Soft MMU supporting sv39 page translation modes
  • Abstract MMIO device interface for device emulation
  • Extensible decoder and interpreter generated from riscv-opcodes ISA metadata

Project Goals

The future goals of this project are:

  • Support F, D, C and more ISA extensions
  • High performance emulation, binary translation and JIT
  • Virtio devic support

Getting Started

Step 0: Install Dependencies

  • Necessary Dependencies
    • xmake
    • gcc-8.1 or clang-5.0 (C++17 minimum)
  • Optional Dependencies
    • Customized RISC-V GNU Toolchain (If you want to build rootfs and kernel by yourself. Step 2 for more details)
    • riscv64-unknown-elf Toolchain (If you want to build opensbi by yourself and run unittest. It can be installed by apt)
    • Device Tree Compiler (If you want to build dtb by yourself. It can be installed by apt)
    • lcov and genhtml (If you want to generate code coverage rate report. It can be installed by apt)

Step 1: Building rv64_emulator

$ git clone https://github.com/WadeGao/rv64_emulator.git
$ cd rv64_emulator
$ git submodule update --init --recursive --remote
$ xmake

After finish building rv64_emulator, if you don't want to waste time on compiling customized riscv toolchain and essential components of the bootable kernel, just download the pre-build bootable kernel from GitHub release pages and download fw_payload.bin and then jump to Step 4

Step 2: Building riscv-gnu-toolchain

Assume that the customized toolchain will be installed to /data/riscv-gnu-toolchains

$ sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat1-dev
$ git clone https://github.com/riscv/riscv-gnu-toolchain.git
$ cd riscv-gnu-toolchain
$ git rm qemu
$ git submodule update --init --recursive --remote
$ ./configure --prefix=/data/riscv-gnu-toolchains --with-arch=rv64ima --with-abi=lp64
$ make linux

After the compilation finish, make sure to add the installation path of the toolchain (/data/riscv-gnu-toolchains/bin) into your PATH.

Step 3: Build the bootable kernel

Option dependencies should be installed. An one-click kernel building script has been provided.

$ ./scripts/build_kernel.sh

About 15 ~ 20 minutes will be taken for this script to finish. The exact time depends on your network and the performance of your computer.

After the compilation finishes succcessfully, the bootable kernel will be found at ./build/kernel/fw_payload.bin

Step 4: Booting Linux kernel using rv64_emulator

If you reach here from Step 1, assuming the download path is ~/Download/fw_payload.bin, just run the following command to boot the kernel:

$ ./build/rv64_emulator ~/Download/fw_payload.bin

If you reach here from Step 3 and have compiled the customized toolchain and the bootable kernel by yourself, run this command:

$ ./build/rv64_emulator ./build/kernel/fw_payload.bin

Run unittest and generate code coverage report

Run unittest

one-click officical testcase building script is also provided. Considering that the emulator supports risv64ima and privilege ISA, so we need to build the corresponding ISA extension testcase (rv64ui, rv64si, rv64mi, rv64ua, rv64um)

$ ./scripts/build_riscv_tests.sh rv64ui
$ ./scripts/build_riscv_tests.sh rv64si
$ ./scripts/build_riscv_tests.sh rv64mi
$ ./scripts/build_riscv_tests.sh rv64ua
$ ./scripts/build_riscv_tests.sh rv64um

After the compilation finished,the elf format testcases can be found at test/elf

2. Build unittest and run
$ xmake
$ ./build/unittest

Then the unittest results will be shown on terminal.

Code coverage report

The code coverage rate is about 96.3%. Run the following command if report is needed:

$ xmake clean
$ xmake f -c
$ xmake f -m coverage
$ xmake

Then the code coverage report will be found at build/coverage/index.html, view it using brower.

Screenshots

Running Linux kernel

Analyze Linux Kernel Instruction Frequency

Project Structure

Directory Description
src/cpu riscv64ima and privilege ISA
src/device MMIO devices
src/libs common functions and portable arithmetic
test Unittest cases
tools tools like rv_analyzer src

rv64_emulator's People

Contributors

wadegao avatar

Stargazers

Zheng Quancheng avatar Organism avatar dus avatar  avatar Resbi avatar  avatar Jossieee avatar  avatar  avatar

Watchers

 avatar Jossieee avatar

Forkers

zhengquancheng

rv64_emulator's Issues

构建项目出错

您好,执行 xmake 会出错,报错信息如下所示(与 asmjit 有关):
PixPin_2024-07-13_09-43-57

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.