RISC-V
This page describes the status of the FreeBSD/RISC-V port, an adaptation of the FreeBSD Operating System to run on the RISC-V Instruction-Set Architecture (ISA). As a result of this work, FreeBSD is able to boot to multi-user mode on the Spike simulator and QEMU emulator. Following a number of commits to the FreeBSD subversion repository in January 2016 (see below), FreeBSD is the first operating system to have bootable in-tree support for RISC-V. This work was described in an EE Times article on the January 2016 RISC-V workshop. Next steps include multicore support, and the ability to boot on budding RISC-V SoCs such as Cambridge's lowRISC open-source SoC. This work was supported by the DARPA CTSRD Project at the University of Cambridge Computer Laboratory and is led by RuslanBukin.
The FreeBSD Foundation posted a blog article describing the RISC-V porting effort and merge of architectural support to the FreeBSD base system in January 2016.
Though RISC-V can support up to a 48-bit virtual addressing scheme, the FreeBSD/RISC-V port currently supports the 39-bit virtual addressing scheme (r298580).
Current status
Spike |
fully supported |
SMP |
||
QEMU |
fully supported |
SMP, virtio-block, virtio-net |
||
Rocketchip |
status unknown |
|
||
lowRISC |
status unknown |
|
Source
Delivery into head:
Review |
Commit |
Description |
kernel-toolchain |
||
includes |
||
rtld-elf |
||
libc/libstand |
||
kernel |
||
xlint |
||
jemalloc |
||
compiler-rt |
||
libunwind stubs |
||
gcc config |
||
libproc support |
||
elftoolchain |
||
usr.bin/ldd |
||
libthread_db |
||
libthr |
||
reuse gp for pcpup |
||
N/A |
SMP support |
|
N/A |
DDB support |
|
N/A |
Privilege v1.9 update |
|
N/A |
Operation in machine mode removed |
|
Full softfloat and hardfloat support |
||
Compiler built-in macros changes |
||
Support for privilege spec v1.10 |
||
N/A |
PLIC |
People
RuslanBukin, ArunThomas, and EdMaste are doing the work. RobertWatson, AndrewTurner, DavidChisnall, and others are providing advice and moral support.
IRC channel
The related IRC channel related to this port is #freebsd-riscv in EFnet.
Mailing list
Toolchain
The only toolchain is supported at this moment is GNU one.
We would welcome efforts to improve RISC-V support in clang/LLVM, so we can switch. Clang/LLVM work is happening in the riscv-trunk branches of the RISC-V clang and LLVM repos:
https://github.com/riscv/riscv-clang/tree/riscv-trunk
https://github.com/riscv/riscv-llvm/tree/riscv-trunk
Sources
https://github.com/freebsd-riscv
Instructions
Setup toolchain installation directory
setenv PREFIX $HOME/riscv
Install required packages
sudo pkg install bison gmp mpfr mpc gawk gsed
Build Toolchain
git clone https://github.com/freebsd-riscv/riscv-gnu-toolchain cd riscv-gnu-toolchain git submodule update --init --recursive ./configure --prefix=$PREFIX gmake -j16 freebsd mv ${PREFIX}/lib/gcc/riscv64-unknown-freebsd11.2/8.1.0/include-fixed ${PREFIX}/lib/gcc/riscv64-unknown-freebsd11.2/8.1.0/include-fixed.rm
Alternatively, install devel/riscv64-xtoolchain-gcc, which gives you both devel/riscv64-binutils and devel/riscv64-gcc and a pre-defined riscv64-gcc.mk .
Build FreeBSD world
cd svn co http://svn.freebsd.org/base/head freebsd-riscv cd freebsd-riscv
When using toolchain built by hand:
setenv MAKEOBJDIRPREFIX /home/${USER}/obj/ setenv CROSS_BINUTILS_PREFIX $PREFIX/riscv64-unknown-freebsd12.0/bin/ setenv CROSS_COMPILER_PREFIX $PREFIX/bin/riscv64-unknown-freebsd12.0- setenv XCC ${CROSS_COMPILER_PREFIX}gcc setenv XCXX ${CROSS_COMPILER_PREFIX}c++ setenv XCPP ${CROSS_COMPILER_PREFIX}cpp setenv STRIPBIN ${CROSS_COMPILER_PREFIX}strip setenv X_COMPILER_TYPE gcc make TARGET_ARCH=riscv64 buildworld
When using devel/riscv64-xtoolchain-gcc:
setenv MAKEOBJDIRPREFIX /home/${USER}/obj/ setenv WITHOUT_FORMAT_EXTENSIONS yes make CROSS_TOOLCHAIN=riscv64-gcc TARGET_ARCH=riscv64 buildworld
Build complete rootfs image to run in QEMU
setenv DESTDIR /home/${USER}/riscv-world make TARGET_ARCH=riscv64 -DNO_ROOT DESTDIR=$DESTDIR installworld make TARGET_ARCH=riscv64 -DNO_ROOT DESTDIR=$DESTDIR distribution cd /home/${USER}/riscv-world echo 'hostname="qemu"' > etc/rc.conf echo "/dev/vtbd0 / ufs ro 1 1" > etc/fstab echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> METALOG echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> METALOG makefs -D -f 5000000 -o version=2 -s 20g riscv.img METALOG
Build small rootfs for Spike / mdroot
fetch https://raw.githubusercontent.com/bukinr/riscv-tools/master/image/basic.files tools/tools/makeroot/makeroot.sh -s 32m -f basic.files riscv.img $DESTDIR
Or get from https://artifact.ci.freebsd.org/snapshot/head/latest/riscv/riscv64/riscv.img.xz
Ensure you have correct path to riscv.img in your kernel config for Spike:
options MD_ROOT options MD_ROOT_SIZE=32768 # 32MB ram disk makeoptions MFS_IMAGE=/path/to/riscv.img options ROOTDEVNAME=\"ufs:/dev/md0\"
Build FreeBSD kernel
make TARGET_ARCH=riscv64 buildkernel
When using devel/riscv64-xtoolchain-gcc, add CROSS_TOOLCHAIN=riscv64-gcc in make parameters.
Or get from: https://artifact.ci.freebsd.org/snapshot/head/latest/riscv/riscv64/kernel.xz
Build bbl
You must build BBL in order to boot FreeBSD
git clone https://github.com/freebsd-riscv/riscv-pk cd riscv-pk mkdir build && cd build setenv PATH ${PATH}:${PREFIX}/bin setenv CPP cpp setenv CFLAGS "-nostdlib" setenv OBJCOPY riscv64-freebsd-objcopy setenv READELF riscv64-freebsd-readelf setenv RANLIB riscv64-freebsd-ranlib ../configure --enable-logo --prefix=$PREFIX --host=riscv64-unknown-freebsd12.0 --with-payload=path_to_freebsd_kernel gmake bbl unsetenv CFLAGS unsetenv CPP
Or get from: https://artifact.ci.freebsd.org/snapshot/head/latest/riscv/riscv64/bbl.xz
Build Spike simulator
# Use clang on FreeBSD setenv CXX c++ setenv PREFIX $HOME/riscv git clone https://github.com/freebsd-riscv/riscv-fesvr cd riscv-fesvr mkdir build && cd build ../configure --prefix=$PREFIX gmake install git clone https://github.com/freebsd-riscv/riscv-isa-sim cd riscv-isa-sim mkdir build && cd build setenv CPPFLAGS -DRISCV_ENABLE_DIRTY=1 ../configure --prefix=$PREFIX --with-fesvr=$PREFIX gmake install
Or install emulators/riscv-isa-sim
Run Spike simulator
Note: we rely on FDT data built-in to the kernel, so by default we have to run spike with 2 cores. Amount of memory can be any because we use sbi_query_memory() machine call instead of FDT data at this moment.
./riscv-isa-sim/build/spike -m2048 -p2 /path/to/bbl
Run RocketChip
Create sdcard using 'Quick instructions' on https://github.com/ucb-bar/fpga-zynq, then copy bbl to sdcard (to the first msdos partition). Once you have booted linux from sdcard on Zedboard, then you can run FreeBSD/RISC-V:
./fesvr-zynq /mnt/boot/bbl
Build QEMU emulator
git clone https://github.com/riscv/riscv-qemu cd riscv-qemu mkdir build && cd build ../configure --target-list=riscv64-softmmu --prefix=$PREFIX gmake gmake install
Or install emulators/qemu-riscv
Run QEMU emulator
sudo qemu-system-riscv64 -machine virt -m 2048M -kernel /path/to/bbl -nographic -drive file=/path/to/riscv.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev tap,ifname=tap0,script=no,id=net0 -device virtio-net-device,netdev=net0
TODO
Project |
Owner |
Comments |
Bootloader |
|
FreeBSD boot loader |
32-bit kernel |
|
All the Syntacore RISC-V CPUs are 32-bit, including Unix-capable. |
QEMU user mode |
|
Implement FreeBSD-bits in QEMU for user-mode emulation, required for cross-building ports |
PMC |
|
No counters available yet in hardware |
busdma |
|
The implementation of busdma(9) |
DTrace FBT provider |
|
Support for C-compressed extension has to be added |
DTrace SDT provider |
|
SDT MD part missing for new SDT implementation by markj@ |
KDB disassembler |
br |
Support for C-compressed extension has to be added |
KDB disassembler |
br |
Needs update KDB disassembler to new ISA (instruction format changed) |
pmap fixes |
markj |
Address TODO comments in riscv/pmap.c |
kgdb and kernel dumps |
|
Need to support offline kernel debugging |
br |
Reduce failed test cases |
|
SSTATUS_SUM |
|
Set SUM (Supervisor User Modify) bit in sstatus register only when we need it |
minidump machdep |
|
Implement machine dependent part for minidump |
Known issues
Issue |
Comments |
No known issues
Useful links
FreeBSD/RISC-V workshop slides video