This project is a very-very commented and detailed explanation on writing your own small kernel for 32-bit RISC-V.
It is built upon QEMU - an emulation software, using virt
.
- Install Zig programming language:
- Linux: https://ziglang.org/download
- Install QEMU system for RISC-V:
- Ubuntu:
apt install qemu-system-misc
- Arch:
pacman -S qemu-system-riscv
- Install Just command runner:
- Ubuntu:
apt install just
- Arch:
pacman -S just
- Install
gdb
debugger:
- Ubuntu:
apt install gdb
- Arch:
pacman -S gdb
- Run or build in an appropriate way:
just build
: builds a whole project as a single binaryjust run
: builds a whole project and runs built binary in a QEMUjust dbg
: builds a whole project and runs build binary in a QEMU with open debugging portjust gdb
: connects to the open QEMU debugging port (seejust dbg
) usinggdb
There is also
helper.gdb
GDB script for printing relevant information while debugging. You may find it useful.
Order of look-through:
src/linker.lds
src/boot.s
src/kernel.zig
src/uart.zig
Just read comments from file in a provided order.
Kernel is built for 4-core RV32IM ISA compatible CPU with ILP32 ABI using GNU toolchain (see GCC). The source code does not implement BIOS, only the kernel itself!