Repository navigation
Home
Language: English | 中文
This is a tutorial written for readers with absolutely no operating-system background. We start from "what an OS actually is" and, step by step, read and build every part of EwokOS with our own hands — ending with a system you helped build, running on a real Raspberry Pi.
EwokOS is a real, runnable microkernel operating system written entirely from scratch — not a fork or modification of Linux or any other existing OS — and built for edge computing in the AI era. It is adapted to a wide range of platforms (ARM32 / AArch64 / RISC-V / x86: QEMU, Raspberry Pi families, Qualcomm 8gen3, NVIDIA Jetson Orin Nano, handhelds, and more), with a modest, clearly structured codebase — an ideal learning vehicle. Every code walkthrough in this tutorial maps directly onto real source files in this repository; there are no toy examples.
Many people say OS development is hard. What is actually hard is the span: between "can write hello world" and "can read a real kernel" there is a huge gap. This tutorial slices that gap into small steps, each with a visible result: first print, first interrupt, first crossing into userland, first two processes taking turns... You will gradually realize that an interrupt is just a table of function pointers, virtual memory is just a translation table, a system call is just a controlled jump, and fork is just copying a data structure.
The tutorial has a hands-on main line: eight milestones ("eight code sets"), evolving from bare-metal UART printing all the way to a mini microkernel with multi-processing, communication, and reproduction — each one mapping to the real EwokOS implementation:
| Set | Milestone | Chapters |
|---|---|---|
| #1 | Bare-metal UART printing: nothing beats seeing it run the first time | 03 |
| — (deep dive) | First contact with ARM instructions and the Pi; don't hesitate, assembly is really simple; mixing C and asm, argument passing; first reading of a device interface (UART) and its registers | 03 |
| #2 | Interrupts and clocks: the heartbeat that brings an OS to life | 06 |
| #3 | Memory and addresses: the meaning and implementation of virtual addresses; ARM execution states and privileges | 05, 04 |
| — (the crossing) | A magical journey through space-time: from kernel mode into userland, and what happens on the way | 04 (§4.6) |
| #4 | The OS's first child: the three essentials of a process and its creation | 07 (§7.1–7.2) |
| #5 | The wormhole through space-time: system calls; interrupts vs system calls | 08 |
| #6 | The hand of God: process run states, timer interrupts, and scheduling | 07 (§7.3–7.5), 06 |
| #7 | The essence of a microkernel: how IPC works, data-exchange efficiency, communication as service | 09 |
| #8 | Life multiplies: fork fission, the parent/child parting of ways, copy-on-write | 07 (§7.6) |
Part 1 Getting started (concepts + environment + first bare-metal program + assembly primer)
│
Part 2 The kernel (exceptions → memory → interrupts → processes → system calls → IPC → Capability)
│
Part 3 Userland (filesystem → init/shell → writing your own apps)
│
Part 4 The full system (graphics → building images → flashing a real Pi)
│
Part 5 The ewokos library series (ecosystem overview → libc → common libs → extra libs → dlopen)
│
Part 6 GPU & compute (platform GPU support → the KUDA CUDA-compatible layer)
| Chapter | Contents | You will gain |
|---|---|---|
| 01 Meet the Operating System | What/why an OS, microkernel vs monolithic, why write a microkernel, the EwokOS source map | A mental model of the whole system |
| 02 Setting Up the Environment | Cross toolchain, QEMU, hardware prep (Pi / SD card / USB-TTL wiring), first build and run | Seeing EwokOS boot for the first time |
| 03 The First Bare-Metal Program | Pi boot process, MMIO, a hand-written UART program; ARM instructions and registers, mixing C and assembly | Code set #1: your very first line of kernel code |
| Chapter | Contents | Source |
|---|---|---|
| 04 CPU Privilege Levels & Exceptions | EL0–EL3, the exception vector table, context saving, crossing from kernel mode to userland |
kernel/platform/aarch64/arch/v8/boot.S, interrupt.S
|
| 05 Memory Management & the MMU | The meaning of virtual memory, page tables, the kernel memory layout, physical page allocation | kernel/kernel/src/mm/ |
| 23 Cache Maintenance | Why caches break coherence; clean/invalidate/flush, PoC/PoU, by-set-way vs by-VA; the portable cache API and its AArch64/ARMv7/x86 implementations; TLB/ASID, code-load and DMA handoff; SMP broadcast |
kernel/platform/<arch>/arch/<ver>/system_arch.c, system.S
|
| 06 Interrupts & Timers | Pi interrupt sources, the four-step interrupt handling, the clock heartbeat |
kernel/kernel/src/irq.c, interrupt.c, kernel/platform/<arch>/arch/common/src/irq.c
|
| 07 Processes & the Scheduler | The three essentials of a process, creating the first process, context switch, scheduling, fork and copy-on-write |
kernel/kernel/src/proc.c, schedule.c
|
| 08 System Calls | Why system calls exist, svc #0, dispatching, syscalls vs interrupts |
kernel/kernel/src/svc.c |
| 09 IPC: Inter-Process Communication | How IPC works, data-exchange efficiency, synchronous RPC, communication as service | kernel/kernel/src/ipc.c |
| 21 The Capability Permission Model | Capability tickets, the cnode, kernel checkpoints, mint/grant delegation, the declarative /
8000
etc/cap.json policy |
kernel/kernel/src/cap.c, system/basic/sys/init/cap_policy.c
|
| Chapter | Contents | Source |
|---|---|---|
| 10 Filesystems & Storage | SD card driver, ext2, the VFS daemon |
kernel/lib/ext2/, system/basic/sys/vfsd/
|
| 11 Boot Flow: init and the shell | The init process, .rd boot scripts, terminal sessions |
system/basic/sys/init/init.c |
| 12 Writing Your Own Apps | The userland build system; write a command of your own and run it | system/basic/bin/ |
| Chapter | Contents | Source |
|---|---|---|
| 13 Graphics & the Window System | Framebuffer, the graphics library, an X-style window system |
system/gui/, system/xwin/
|
| 20 The xwm Window Manager | Mechanism/policy separation, the xwm↔xserverd IPC protocol, shared-memory decoration rendering, writing your own WM |
system/xwin/xwm/, system/xwin/libs/x/src/xwm.c
|
| 22 The xserverd Compositor: Rendering Flow & Dirty Regions | The shared-memory UPDATE handshake, two-level dirty flags, x_repaint step by step, draw_win composite paths, dirty-rect packing and flush, cursor/drag fast paths |
system/xwin/drivers/xserverd/ |
| 14 Images & Flashing to a Pi | SD card images, partitioning, flashing, booting real hardware |
tools/makesd.sh, tools/bootfs/
|
| 15 Debugging & the Road Ahead | GDB debugging, the logging stack, what to do next | — |
A standalone "series" dedicated to the EwokOS libraries: from libc (the C runtime) to the assorted common libraries. When you want to write a real application, or wonder "which library do I use for X", look here.
| Chapter | Contents | Source |
|---|---|---|
| 16 Library Ecosystem Overview | Why the libraries are self-built, the five-layer map, the directory layout, EWOK_LIBC/EWOK_LIB_GRAPH/EWOK_LIB_X linking, the build & install flow |
system/platform/*/make.rule |
| 17 The EwokOS libc | The C-runtime puzzle: newlib + libgloss + libewoksys + openlibm + softfloat; the full call chain of printf; errno |
system/basic/libc/ |
| 18 Common Libraries | Quick reference for base/graphics/window/network libraries; an "I want to do X → use library Y" table | system/*/libs/ |
| 19 Extra Libraries | Optional libraries in projects (SDL2/litehtml/cglm/ferox/portablegl/imgui/ffmpeg/widget++ extended widgets); the former sw.extra is gone — curses is now a core gui library |
projects/ |
| 25 Runtime Dynamic Loading (dlopen) | Why a static OS has no ld.so; the three-piece design — kernel anonymous window with real W^X + cache-sync syscall, the libdl ELF loader, and the build-time host ABI table; object graph, scope & search path; building a plugin; the dltest self-test |
system/basic/libs/dl/, kernel/kernel/src/mm/mmu.c
|
The graphics stack of 13 goes deeper here: how one user-space stack drives four real GPU families, and how a CUDA-compatible compute layer runs LLM inference on a phone-class GPU.
| Chapter | Contents | Source |
|---|---|---|
| 27 GPU Support Across the Mainstream Platforms | One daemon/IPC shape for VideoCore IV/VI/VII, Adreno 690 and GA10B; zero copy, sticky honest CPU fallback, cache discipline; per-machine shader compilers and PGL_G3D; what is board-verified on each platform |
system/gui/drivers/g2dd/, hardwares/*/system/libs/{videocore,adreno,ga10b,*compiler}
|
| 28 KUDA: a CUDA-Compatible Compute Layer | The ku*/KU_* driver-API subset (M0); core/BSP split and link contract; module/launch walkthrough; the built-in CPU simulator; the Adreno 690 ops.q8b backend with deferred batching and LLM operator set; measured decode throughput |
projects/kuda/libs/kuda/, hardwares/qcom/8gen3/system/libs/kuda/
|
| Chapter | Contents |
|---|---|
| 99 Glossary: A Quick Terminology Reference | Every abbreviation and term: full English name, meaning, first-appearance chapter |
- Any Raspberry Pi 2B / 3B / 3B+ / Zero 2W / 4B (supported by
hardwares/raspixin this repository) - An SD card of at least 4 GB
- A USB-to-TTL serial cable (for watching boot logs — highly recommended)
- No Pi? The entire tutorial can be done in the QEMU emulator.
- Read in order. Each chapter assumes you have understood all previous ones.
- Do every "follow along". All code can be compiled and verified directly.
- Read against the source. Every file link points at a real file in this repository — open it side by side.
- When you hit an unfamiliar abbreviation or term, consult the 99 Glossary first — it collects the full English names and one-line explanations of every term; key terms are also annotated where they first appear in the text.
- Don't look up every ARM instruction in the manual; the tutorial explains the important ones in place.
- Lines starting with
>are commands typed into a terminal - Comments inside code blocks are part of the tutorial — read them carefully
- The main line is AArch64 (64-bit Raspberry Pi); 32-bit differences are called out separately
Happy learning. By the time you finish every chapter, your understanding of "how computers actually work" will never be the same.
EwokOS OS Tutorial / EwokOS 操作系统教学
Part 1: Getting Started / 第 1 部分:起步
Part 2: The Kernel / 第 2 部分:内核
Part 3: Userland / 第 3 部分:用户态
Part 4: The Full System / 第 4 部分:完整系统
Part 5: The ewokos Series (Libraries) / 第 5 部分:ewokos 系列(库生态)
Part 6: GPU & Compute / 第 6 部分:GPU 与计算
Appendix / 附录