popovicu/zig-riscv-interrupts
No description provided.
This project builds a bare-metal binary using Zig and assembly, and uses OpenSBI for printing and working with timers.
The code here is a Zig rewrite of the original C code from here.
To build the binary, simply run make
:
make
This will compile main.zig
and startup.S
into an executable named kernel
.
If you don't have zig
on your PATH
, you can specify the full path to your zig
binary like this:
make ZIG=/tmp/zig/zig-x86_64-linux-0.15.0-dev.1283+1fcaf90dd/zig
You can run the compiled binary using QEMU:
qemu-system-riscv64 -machine virt -nographic -bios PATH_TO_YOUR_SBI_BINARY -kernel kernel
Without a relatively new OpenSBI, this can happen:
ERROR: OpenSBI debug console not available! You need the latest OpenSBI.
Falling back to direct UART at 0x10000000...
Timer functionality requires working OpenSBI. Stopping...
Otherwise, the output looks like this:
Hello world! We're about to use the timer.
Setting up interrupts!
Main thread still running.
Main thread still running.
Main thread still running.
Hello from the timer interrupt!
Main thread still running.
Main thread still running.
Hello from the timer interrupt!
Main thread still running.
Main thread still running.
Main thread still running.
Hello from the timer interrupt!
Main thread still running.
Main thread still running.
Hello from the timer interrupt!
Main thread still running.
Main thread still running.
Main thread still running.
Hello from the timer interrupt!
Main thread still running.