hypocaust-2, a type-1 hypervisor with H extension run on RISC-V machine
MIT License
Hypocaust-2 is an experimental type-1 hypervisor with H extension run on RISC-V machine. It depends on the RISC -V H extension, which currently runs on QEMU 7.1.0 or above. It is the successor of the hypocaust project.
My plan is to build a high-performance riscv64 hypervisor that physically maps the cpu cores, so there is no need to schedule guests in the hypervisor. In addition, the passthrough method for IO devices has achieved good performance.
The purpose of this project is to run on bare metal or embedded devices, but it is not ruled out that kvm technology will be used and run on linux in the future.
./srcipts/rCore-Tutorial-v3.sh && make qemu PLATFORM=rCore-Tutorial-v3
./srcipts/rt-thread.sh && make qemu PLATFORM=rt-thread
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 libexpat-dev git \
libglib2.0-dev libfdt-dev libpixman-1-dev \
libncurses5-dev libncursesw5-dev
# install riscv linux toolchain
$ git clone https://gitee.com/mirrors/riscv-gnu-toolchain --depth=1
$ cd riscv-gnu-toolchain
$ git rm qemu
$ git submodule update --init --recursive
$ ./configure --prefix=/opt/riscv64 --with-arch=rv64imac --with-abi=lp64
$ sudo make linux -j8
$ export PATH=$PATH:/opt/riscv64/bin
Build Linux:
$ git clone https://github.com/torvalds/linux -b v6.2
$ cd linux
$ git am ${HYPOCAUST_2_DIR}/guest/linux/patches/*.patch
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- defconfig
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- menuconfig
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- all -j8
Run bare Linux on qemu:
$ qemu-system-riscv64 -M virt -m 256M -nographic -bios $(BOOTLOADER)/rustsbi-qemu.bin -kernel $(linux)/arch/riscv/boot/Image
Docker Command(MacOS/Windows):
# run docker container, mount workspace in docker
docker run -itd --name riscv-env --privileged -v {WORKSPACE}:/workspace riscv-gnu-toolchain /bin/bash
# run docker
docker exec -it riscv-env /bin/bash
Make rootfs:
git clone https://gitee.com/mirrors/busyboxsource.git
cd busyboxsource
# Select: Settings -> Build Options -> Build static binary
CROSS_COMPILE=riscv64-unknown-linux-gnu- make menuconfig
## Build && Install
CROSS_COMPILE=riscv64-unknown-linux-gnu- make -j10
CROSS_COMPILE=riscv64-unknown-linux-gnu- make install
# Make minimal root file system
cd ../
qemu-img create rootfs.img 1g
mkfs.ext4 rootfs.img
# mount file system && copy busybox
mkdir rootfs
mount -o loop rootfs.img rootfs
cd rootfs
cp -r ../busyboxsource/_install/* .
mkdir proc dev tec etc/init.d
cd etc/init.d/
touch rcS
vim rcS
#####
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
#####
chmod +x rcS
umount rootfs
qemu-system-riscv64 -M virt -m 256M -nographic -bios {BOOTLOADR} -kernel {KERNEL_ELF} -drive file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0"
hgatp
.console_putchar
, console_getchar
and set_timer
and base
related)Two types of device tree(DT):
hcounteren
register to all 1, because it is possible to read the time
register in VU mode or VS mode.(refs: The counter-enable register hcounteren
is a 32-bit register that controls the availability of the hardware performance monitoring counters to the guest virtual machine.hcounteren
and scounteren
.hcounteren
must be implemented. However, any of the bits may be read-only zero, indicatingInstructionGuestPageFault
.