
Use OpenSBI and SBI Calls From a RISC-V Kernel
Call the RISC-V SBI from supervisor mode: probe extensions, print through DBCN, set timers, start harts and shut down, with the ecall rules and errors.
Tag
8 posts

Call the RISC-V SBI from supervisor mode: probe extensions, print through DBCN, set timers, start harts and shut down, with the ecall rules and errors.

Build the smallest RISC-V kernel that boots on QEMU virt: a linker script at 0x80200000, an entry stub, a C main printing through the UART, and a GDB check.

A tour of the RISC-V supervisor CSRs a kernel touches: sstatus, sie, stvec, scause, sepc, stval, satp and sscratch, with instructions and exact bits.

Drive the NS16550A UART at 0x10000000 on QEMU's RISC-V virt machine with volatile MMIO in C: initialize it, send and poll bytes, then add receive interrupts.

Learn what machine, supervisor and user mode each control on RISC-V, how traps are delegated between them, and how firmware drops into S mode with mret.

Compare Linux system calls on x86-64, ARM64 and RISC-V: the trap instruction, number register, argument registers and the same hello program in each.

Write a RISC-V machine-mode trap handler in assembly: set mtvec, save registers, decode mcause, advance mepc past ecall and return with mret.

Write a 64-bit RISC-V kernel in C and assembly for QEMU virt: boot through OpenSBI, traps, timer, paging with Sv39, a page allocator, tasks and user mode.