Four complete projects — from a 5-instruction reset vector to a 4-hart SMP payload running on real OpenSBI firmware. Full source, Eclipse-debuggable, documented line by line.
Four self-contained RISC-V bare-metal projects that run on QEMU virt. Each project builds on the previous, progressing from raw M-mode assembly to a full S-mode payload running under production OpenSBI firmware. No OS. Fully debuggable in Eclipse CDT.
Simplest possible RV64I bare-metal
main.S, linker.ld, MakefileTwo-stage boot with SBI timer interrupts
mretReal OpenSBI + SBI v1.0 S-mode demo
riscv64-linux-gnu-)stimecmp directly from S-mode4-hart multiprocessing, HSM, IPI, atomic spinlock
hart_startProjects 1 and 2 need only the bare-metal toolchain, QEMU, and GDB. Projects 3 and 4 additionally require the Linux RISC-V toolchain to build OpenSBI from source.
GCC cross-compiler for bare-metal. Used by all 3 projects for the payload/app code.
Required only for Project 3 to build OpenSBI from source. Supports PIE relocation.
RISC-V system emulator. Version 6.x or later. Ships with most Linux distros.
Required for Eclipse CDT hardware debug and standalone GDB sessions.
# QEMU and GDB sudo apt update sudo apt install qemu-system-misc gdb-multiarch make # Linux RISC-V toolchain (Project 3 — OpenSBI build only) sudo apt install gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu # Bare-metal toolchain — Option A: distro package sudo apt install gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf # Option B: SiFive prebuilt GCC 10.2 (matches this project) # Download from https://github.com/sifive/freedom-tools/releases export PATH="/path/to/riscv64-unknown-elf-toolchain/bin:$PATH"
# Clone git clone https://github.com/vwire/riscv-bare-metal-qemu.git cd riscv-bare-metal-qemu # ── Project 1: bare metal ───────────────────────────────────── cd bare_metal_qemu && make qemu-run # Loops silently (no UART output) — Ctrl-A X to quit # ── Project 2: ZSBL + Supervisor ────────────────────────────── cd ../zsbl_supervisor && make qemu-run # Prints full demo output and 3 timer interrupts # ── Project 3: OpenSBI Payload ──────────────────────────────── # Step 1: build OpenSBI from source (one-time setup) git clone https://github.com/riscv-software-src/opensbi.git ~/eclipse-workspace/opensbi cd ~/eclipse-workspace/opensbi sed -i 's/firmware-genflags-y += -DFW_TEXT_START=0x0/firmware-genflags-y += -DFW_TEXT_START=0x80000000/' \ firmware/objects.mk make CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic \ FW_JUMP=y FW_JUMP_ADDR=0x80200000 -j$(nproc) # Step 2: build and run the S-mode payload cd ~/eclipse-workspace/riscv-bare-metal-qemu/opensbi_payload && make qemu-run # ── Project 4: SMP Payload ──────────────────────────────────── # (uses same OpenSBI build from Project 3 — no rebuild needed) cd ~/eclipse-workspace/riscv-bare-metal-qemu/smp_payload && make qemu-run # Starts 4 harts. Prints timer IRQs and IPI demo. Ctrl-A X to quit.
All 50 questions and answers from the development sessions — covering OpenSBI source walkthrough, RISC-V architecture, PMP, cache, SMP boot, and every bug found and fixed in Project 4. Filterable by category.