this is a tiny educational operating system for the RISC-V architecture,
designed to run on QEMU's virt machine. It was generated and then extended by using ChatGPT, and serves as a starting point for exploring:
- Bare-metal boot on RISC-V
- Memory-mapped I/O via UART
- A simple cooperative scheduler
- Simulated "processes" (programs)
- Basic synchronization via a spinlock
- A toy in-memory file system
- A minimal command-line shell
- Loading separate programs
- "Programs" are registered as tasks (
tasks_register_demo_programs) and can be extended by adding new functions and registering them viatasks_add.
- "Programs" are registered as tasks (
- Running multiple programs simultaneously
- The scheduler calls each active task's
stepfunction round-robin.
- The scheduler calls each active task's
- Synchronization
- Shared
shared_counterguarded by a spinlock (lock()/unlock()).
- Shared
- Protection
- Logical separation: each task has an ID and only cooperatively accesses shared state. (Physical protection/MMU is not implemented but could be a future extension.)
- File system
- In-memory "files" in
fs.cwithlsandcatcommands in the shell.
- In-memory "files" in
- Create/load new programs
- New programs can be added by:
- Writing a new
void myprog_step(void)function - Adding it via
tasks_add("myprog", myprog_step) - Calling
tick/run Nin the shell to schedule them.
- Writing a new
- New programs can be added by:
The exact commands may vary depending on how RISC-V tools are installed in the lab. Replace the toolchain prefix if needed (e.g.,
riscv64-linux-gnu-).
-
Clone or copy this directory to your home:
cd ~/riscv-os
Run these lines: "/c/Program Files/qemu/qemu-system-riscv64.exe"
-machine virt -nographic
-bios none
-kernel kernel.elf
-serial mon:stdio
Go to DOCUMENTATION.md for the documentation process.