A bare-metal bootloader for RISC-V. Part of the bedrock[RTOS] ecosystem, but deliberately self-contained, you can drop it into any hobby osdev project without dragging in the rest of bedrock.
Targets RISC-V 32-bit (RV32IMA) and 64-bit (RV64GC). Primary development environment is QEMU virt machine.
You need a RISC-V cross-compiler and QEMU. On most distributions:
# Arch Linux
pacman -S riscv64-elf-gcc qemu-system-riscv
# Ubuntu / Debian
apt install gcc-riscv64-unknown-elf qemu-system-misc
# macOS (Homebrew)
brew install riscv-gnu-toolchain qemumakemake ARCH=rv32make ARCH=rv64 MODE=sbimake ARCH=rv64 DEBUG=1Build artifacts land in build/<arch>-<platform>-<mode>/.
# RV64, M-mode bare-metal
make run
# RV32
make ARCH=rv32 runExpected output:
Genesis v0.1.0
RISC-V bootloader — part of bedrock[RTOS]
[INF] core/main.c:18 (genesis_main): hart 0 started
[INF] core/main.c:24 (genesis_main): timer frequency: 10000000 Hz
[INF] core/main.c:30 (genesis_main): Genesis initialized successfully
[INF] core/main.c:31 (genesis_main): no kernel image to load in v0.1.0 — halting
Genesis halted. Attach GDB or reset the machine.
Press Ctrl-A X to exit QEMU.
make debugThis starts QEMU with -s -S (GDB server on port 1234, CPU halted at reset) and prints connection
instructions. In a second terminal:
riscv64-elf-gdb build/rv64-qemu_virt-baremetal/genesis.elfInside GDB:
(gdb) target remote :1234
(gdb) break genesis_main
(gdb) continue
For RV32 debugging, use the same riscv64-elf-gdb binary — it handles both widths.
| Target | Description |
|---|---|
make build |
Compile and link (default) |
make run |
Build and launch in QEMU |
make debug |
Build and launch with GDB server |
make size |
Print ELF section sizes |
make disasm |
Disassemble the binary with source interleaving |
make clean |
Remove the build directory |
- Create
platform/<your_board>/platform.h— defineUART0_BASE,DRAM_BASE, and any peripheral addresses. - Create
platform/<your_board>/platform.c— implementplatform_uart_init,platform_uart_putc,platform_uart_getc,platform_uart_rx_ready, andplatform_init. - Build with
make PLATFORM=<your_board>.
The HAL layer (hal/uart.c, hal/timer.c) calls these functions — everything else in core/ is portable C.
GNU General Public License v3.0. See LICENSE for details.
This project is part of bedrock[RTOS].