A lightweight, bare-metal microkernel and operating system developed in C and AArch64 Assembly for the Raspberry Pi 3B.
TycheOS is designed to run on the emulated Raspberry Pi 3 Model B (utilizing a Broadcom BCM2837 SoC with ARM Cortex-A53 cores) in QEMU. It provides a clean, instructional codebase showcasing core operating systems concepts, from boot and exception routing to scheduling and custom file systems.
- EL3 Entry to EL1 Execution: Starts execution at Exception Level 3 (EL3), configures essential system registers (SCTLR, HCR, SCR, SPSR), and performs a controlled switch down to EL1 (Kernel Mode) using ARMv8 exception returns (
eret). - Hardware Initialization: Configures stacks, zeroes out the BSS segment, and initializes low-level peripherals before jumping to the C entrypoint (main).
- Implementation: Written in boot.S.
-
ARMv8 Vector Table: Implements a fully-aligned (
$2^{11}$ -byte) vector table handling synchronous exceptions, IRQs, FIQs, and system errors across different privilege states (EL1h, EL1t, EL0 64-bit, and EL0 32-bit). - Preemptive & Cooperative Timer Interrupts: Integrates the Raspberry Pi System Timer interrupt to drive the scheduler's quantum tick.
- Implementation: Defined in entry.S and managed in irq.c and timer.c.
- State Management: Fully supports thread creation via copy_process (cloning registers and stack state).
- MLFQ Scheduling: Features a 3-level Multi-Level Feedback Queue scheduler (_schedule) supporting priority boosting, timeslice demotion (quantum sizes: 2, 4, 8 ticks), and preemption.
- Context Switching: Performs low-level context switches via assembly register saves (x19-x29, SP, and LR).
- Implementation: Managed in scheduler.c and fork.c.
- VFS Abstraction: Clean separation of concerns using generic
filesystem,vnode, andfilestructures. - In-Memory File System (TmpFS): Supports creation and navigation of directory trees, file writing, reading, and lookup resolution.
- Implementation: Initialized via vfs_init and implemented across fs.c and tmpfs.c.
- Kernel Transitions: Userspace processes request kernel services via the
SVCinstruction. - Syscall Table: Implements syscall routing for critical operations, currently supporting:
sys_write(Console writing)sys_malloc(Dynamic memory page allocation)sys_clone(Process cloning)sys_exit(Process termination stub)
- Implementation: Table defined in sys.c and handled in entry.S.
- Interactive CLI: Runs an interactive shell (shell) over the bare-metal PL011 UART driver.
- Text Editing & Execution: Implements standard input buffering, character echoing, backspace handling, and command dispatching.
- Built-in Commands:
help- Show instructionsclear- Clear terminal screenecho [msg]- Echo text back to consolels- List folder contentspwd- Print working directorymkdir [name]- Create subdirectorytouch [name]- Create blank filecat [name]- Print file contentcd [path]- Navigate directories
- Implementation: Driven by shell.c and uart.c.
You need a cross-compiler toolchain targeting aarch64 and the qemu-system-aarch64 emulator.
sudo apt update
sudo apt install gcc-aarch64-linux-gnu qemu-system-arm makebrew tap mac-ports/arm-none-eabi
brew install aarch64-elf-gcc qemu(Note: If utilizing a non-Linux target cross-compiler on macOS, update the compiler commands in the makefile to match your toolchain prefixes, e.g., aarch64-elf-gcc).
-
Clean previous builds:
make clean
-
Compile the kernel image:
make
This generates the raw binary image
build/kernel8.imgand ELF debugging symbol filebuild/kernel.elf. -
Launch the OS in QEMU:
make run
This executes the kernel on a simulated Raspberry Pi 3 Model B, establishing a direct interactive terminal connection via stdout/stdin.