Skip to content

About

Educational 64-bit RISC-V kernel featuring memory management, threads, semaphores, system calls, timer interrupts, and buffered console I/O.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

RISC-V Kernel - OS1 Project

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.

Features

  • 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, and signal_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

Project Structure

.
|-- 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

Requirements

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-riscv64
  • gdb-multiarch for optional debugging

The Makefile automatically detects common RISC-V toolchain prefixes. A prefix can also be supplied explicitly if needed.

Build and Run

Build the kernel:

make

Run it in QEMU:

make qemu

When 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 clean

Debugging

Start QEMU and wait for a debugger connection:

make qemu-gdb

In another terminal, start GDB:

gdb-multiarch kernel

The generated .gdbinit file contains the remote target configuration and uses a per-user GDB port selected by the Makefile.

System-Call APIs

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.

License

This project is based on the educational xv6-derived environment supplied by the University of Belgrade. See LICENSE for copyright and license details.

About

Educational 64-bit RISC-V kernel featuring memory management, threads, semaphores, system calls, timer interrupts, and buffered console I/O.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages