Tackling RISC-V as a beginner at osdev

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
pearmypie
Posts: 21
Joined: Sat Mar 01, 2025 8:06 pm
GitHub: https://github.com/ionutcatana

Tackling RISC-V as a beginner at osdev

Post by pearmypie »

Hello and thank you in advance to anyone reading my post :)

To preface, I am an employed junior programmer, not a complete beginner.

I've read through the code of xv6-riscv and I've been wondering how I could approach making a basic OS for RISC-V that would run on qemu's "virt" machine.

My goals are to implement a simple OS with drivers for PS/2 keyboards and mice, video output (not just serial console) and disk storage. My timeframe is about 13 months to do this.

I've investigated the boot process and it seems pretty straightforward, but there aren't any "wiki-like" examples and sources that I could find in regards to OSDev.

My questions are as follows:
Should I do without U-Boot? Loading my kernel using `-kernel mykernel.elf` is very straightforward and I am sure I have access to all OpenSBI BIOS-like functions.

On the contrary, should I use the U-Boot SPL -> OpenSBI -> U-Boot sequence? As I understand, it implements a subset of UEFI. Is this a big advantage?

I greatly appreciate all advice.
Octocontrabass
Member
Member
Posts: 6247
Joined: Mon Mar 25, 2013 7:01 pm

Re: Tackling RISC-V as a beginner at osdev

Post by Octocontrabass »

The advantage of U-Boot and its subset UEFI implementation is that it works the same way on lots of different hardware. If you want to see your OS running on bare metal, that's probably the best way to go.

For something that only needs to work in QEMU, U-Boot is probably not worth the trouble. You can always switch to using U-Boot later.
User avatar
Demindiro
Member
Member
Posts: 165
Joined: Fri Jun 11, 2021 6:02 am
Libera.chat IRC: demindiro
Location: Belgium
Contact:

Re: Tackling RISC-V as a beginner at osdev

Post by Demindiro »

I wrote my first barely-functional OS for RISC-V, motivation being that I wanted to focus on OS theory first and avoid the large amount legacy cruft found in x86.

I started from the official RISC-V specifications. I found them very easy to comprehend and at the time it was quite short too (though it has grown a lot in size). They elaborate often on design decisions, which helps with understanding why some things are the way they are.

At the time I used fw_jump.bin as bootloader. I no longer remember the details, but IIRC all it does is load the kernel and enter it. I image other options (like U-Boot) are more mature now, though fw_jump.bin is very simple.

PS/2 is not relevant for RISC-V I believe. If you only intend to target Qemu, then virtio_input is probably your best bet. I also used virtio_gpu and virtio_block.

If you are interested, here is my first OS. Be aware that it is a mess and outdated though. In particular: PLIC got superseded by (I think) APLIC and is no longer present in the Privileged Architecture specification.
GeneSYS exokernel (Codeberg)
Lemmings! micro-/multikernel (Github, Codeberg)
Waddle container tool (Codeberg)
Post Reply