Note: The source code and comments are currently in French but are being progressively translated.
- Structure: Linker script
kernel.lds
- Boot: Initialization via
crt0.Sandenter_smode.Sthen callingkernel_start(C code) - Privilege Modes: Transition from Machine mode to Supervisor mode; execution happens in User mode (and S-mode for idle).
- Paging (Virtual Memory): Implementation of the Sv39 standard with a 3-level page table (page walk).
- Isolation: Separation of kernel and user address spaces (Segfault errors are triggered).
- Physical Memory Allocation: Frame allocator using a free list.
- Heaps (Buddy System Algorithm):
- kheap: Dynamic heap for the kernel.
- uheap: Dynamic heap for user processes.
- Scheduler: Preemptive Round-Robin scheduler.
- Process Management:
- States:
RUNNING,READY,SLEEPING,ZOMBIE,WAITING. - Primitives:
create_process,waitpid,sleep,ps. idleprocess: Executed when no other process is ready (useswfi).
- States:
- Context Switching: Saving and restoring registers via
ctx_sw.
- Trap Handler:
- Centralized management of exceptions (syscalls and page faults) and interrupts (Timer, UART interrupts raised by the PLIC).
- Switching stacks (
mscratch,sscratch,sp)
- System Calls:
ecallinterface allowing user processes to interact with the kernel (I/O, processes, FS).
- A simple file system residing entirely in RAM.
- Support for directories and files (WIP).
- Commands:
mkdir,ls,pwd,cd,rm.
- UART: Serial communication for logs and text-mode keyboard input.
- Screen (Framebuffer): Graphic support via
bochs-displayand PCIe with custom font rendering (font.c).
- Shell (bash custom): CLI to navigate the FS and launch processes.
- Commands:
echo,clear,bash,... &(background process), etc
- Commands:
- RISC-V Toolchain:
gcc-riscv64-unknown-elf - Emulator:
qemu-system-riscv64 - Make:
make - GDB (optional):
gdb-multiarch
-
Console mode (nographic):
make run
-
Graphic mode:
make rung
-
Console mode (nographic):
make debug
-
Graphic mode:
make debugg
Then open a new terminal and run:
gdb-multiarch kernel.bin -tui