A small educational operating-system kernel for the 64-bit RISC-V architecture, developed as part of the Operating Systems 1 course at the University of Belgrade School of Electrical Engineering.
The kernel runs in QEMU and provides memory management, lightweight threads, synchronization primitives, timed sleeping, system calls, user-mode execution, and interrupt-driven console I/O. User programs can access kernel services through both C and C++ APIs.
- Block-based heap allocator with allocation, release, validation, and adjacent-block coalescing
- Thread creation, termination, synchronous dispatch, and FIFO scheduling
- Preemptive context switching driven by timer interrupts
- Thread sleeping for a specified number of timer periods
- Kernel semaphores with
wait,signal,close,wait_n, andsignal_n - C system-call API and object-oriented C++ API
- User-mode execution through RISC-V privilege-level transitions
- Buffered console input and output driven by external interrupts
- Public tests for threads, semaphores, producer-consumer synchronization, sleeping, and user-mode protection
.
|-- h/ Kernel and API header files
|-- src/ Kernel, system-call, and API implementations
|-- test/ Public tests and the interactive test selector
|-- lib/ Provided hardware, memory, and console libraries
|-- Makefile Build, run, and debug targets
`-- kernel.ld RISC-V linker script
The project is intended to be built in the provided Linux development environment. A compatible setup requires:
- GNU Make
- A 64-bit RISC-V GCC/binutils cross-toolchain
qemu-system-riscv64gdb-multiarchfor optional debugging
The Makefile automatically detects common RISC-V toolchain prefixes. A prefix can also be supplied explicitly if needed.
Build the kernel:
makeRun it in QEMU:
make qemuWhen prompted, enter a test number from 1 to 7. Tests 1-6 exercise the implemented APIs and kernel functionality. Test 7 checks user-mode protection and is expected not to terminate normally.
To stop QEMU in a terminal, press Ctrl+A, release the keys, and then press X.
Remove generated files:
make cleanStart QEMU and wait for a debugger connection:
make qemu-gdbIn another terminal, start GDB:
gdb-multiarch kernelThe generated .gdbinit file contains the remote target configuration and uses a per-user GDB port selected by the Makefile.
The C API is declared in h/syscall_c.h and includes memory allocation, thread management, semaphores, sleeping, and console operations.
The C++ API is declared in h/syscall_cpp.hpp and provides the Thread, Semaphore, PeriodicThread, and Console classes as wrappers around the C system-call interface.
This project is based on the educational xv6-derived environment supplied by the University of Belgrade. See LICENSE for copyright and license details.