Git Product home page Git Product logo

riscv-vm's Introduction

riscv is a computer architecture just like x86 or arm, the only difference is it's open. it's simpler compared to x86 or arm. riscv is just a specification of the isa which is an abstract model that people could use to create a real cpu, or virtual machine that emulate it; so this is what I did, I made a software emulation layer that execute riscv instructions and provide io's to the programs.

1. Build

building the project is straight forward:

make

2. Run

the virtual machine is ready. the only missing part is the software. so we need a full system with a kernel and user programs to run on the vm, because the kernel will setup the environment, including io communication, and memory protection, then launches user space programs. for demo purposes you can just run the shipped in kernel:

make run

wait for the system to boot and you will get a shell.

custom image:

if you want to build your own kernel image follow these instructions:

your directory structure should look like after you setup all projects:

.
├── buildroot
├── linux
├── opensbi
├── config
├── core
├── devices
├── dts
├── helpers
├── include
├── kernel
├── main.c
├── Makefile
├── patches
├── README.md
└── soc

means all the cloning is done in the root directory.

a. rootfs

the rootfs contains the necessary programs to run in user space. we will use buildroot project for this to build an initramfs for the linux kernel.

download buildroot:

git clone --depth 1 --branch 2021.02.6 git://git.buildroot.net/buildroot buildroot

copy the config:

cp config/rv64_buildroot_config buildroot/.config

build:

(cd buildroot; make -j$(nproc))

b. Kernel

first of all we need rv64 cross compiler toolchain, checkout your distro package that has that, in my case it's archlinux:

doas pacman -S riscv64-linux-gnu-gcc

then we need to download the linux kernel source (torvalds tree):

git clone --depth 1 --branch v6.3 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux

copy the config:

cp config/rv64_linux_config linux/.config

build the kernel:

(cd linux; make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc))

c. opensbi

opensbi is a supervisor interface that run in machine mode and provides services for the supervisor (the kernel). it's like the firmware and it helps operating systems to access the soc services in a portable way.

download opensbi:

git clone https://github.com/riscv-software-src/opensbi.git opensbi

(cd opensbi; git checkout v1.2)

build:

(cd opensbi; make CROSS_COMPILE=riscv64-linux-gnu- PLATFORM_RISCV_XLEN=64 PLATFORM_RISCV_ISA=rv64ima_zicsr_zifencei PLATFORM=generic FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image)

d. run the image

the final image will have the following structure:

┌──────────┬───────────┬────────────────────┐
│          │           │                    │
│ opensbi  │   linux   │     buildroot      │
│          │           │                    │
└──────────┴───────────┴────────────────────┘

we also need the device tree:

make ./dts/rv64_dt.dtb

let's boot the vm:

./riscv-vm dts/rv64_dt.dtb ./opensbi/build/platform/generic/firmware/fw_payload.bin

riscv-vm's People

Contributors

noureddine-taleb avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.