Operating System written for me
Go to file
Daniel Samson 5bba5d3363
Wire real PS/2 scancodes through to input events and characters
Replace the keyboard driver's synthetic stream with the real path:

- ps2-bus binds IRQ1 (interrupt bits set only after the bind), drains
  port 0x60 on each interrupt, and forwards every byte to the attached
  child driver over async ipc_send, routed by the status register's
  auxiliary-output bit. Children attach via the new well-known ps2_bus
  service, handing over their endpoint as a capability.
- scancode.zig (new, pure, host-tested): scancode set 2 -> USB HID
  usage decoding (F0/E0/E1 prefix state machine) plus keyboard state —
  pressed-key bitmap, typematic-repeat classification, modifier and
  caps-lock tracking.
- keyboard.zig decodes the forwarded stream and publishes real
  key_down/key_press/key_up events, filling key_press characters via
  xkeyboard-config (layout from argv[2], default us) and synthesizing
  ASCII control characters for Enter/Tab/Backspace/Escape.
- protocol.zig names the full HID usage set in Keycode; build.zig
  threads the xkeyboard-config module into user binaries.

Verified end to end in QEMU via monitor sendkey: shift, caps lock,
and control-character synthesis all decode correctly. The mouse
driver still publishes its synthetic stream; attaching it to the
bus the same way is the follow-up.
2026-07-11 22:48:59 +01:00
boot Update stale /sbin/ references to real FHS paths 2026-07-10 18:13:24 +01:00
docs Wire real PS/2 scancodes through to input events and characters 2026-07-11 22:48:59 +01:00
library Merge branch 'main' into claude/input-module-keyboard-events-379361 2026-07-11 20:28:21 +00:00
system Wire real PS/2 scancodes through to input events and characters 2026-07-11 22:48:59 +01:00
test Add input module: broadcast keyboard events over IPC 2026-07-11 15:03:24 +01:00
tools Add xkeyboard-config: X11 keyboard layouts compiled to Zig 2026-07-11 15:57:09 +01:00
.gitignore gitignore: ignore .claude/ and .github/ 2026-07-10 14:09:38 +01:00
.zig-version Pin zig version to 0.16 LTS 2026-07-03 13:49:47 +01:00
README.md Split the `system` contract into boot-handoff / abi / device-abi 2026-07-10 18:08:51 +01:00
build.zig Wire real PS/2 scancodes through to input events and characters 2026-07-11 22:48:59 +01:00
build.zig.zon started project with basic efi setup 2026-07-01 18:32:56 +01:00

README.md

DanOS

Codename: Shodan Version: 1

A small operating system, written from scratch in Zig — a bootloader (boot/) and a microkernel (system/kernel/), sharing a neutral handoff contract (system/boot-handoff.zig). It boots x86-64 via UEFI, and so far has a framebuffer console, a physical frame allocator, its own paging with W^X permissions, interrupt/exception handling, a LAPIC timer, a kernel heap, a fixed-priority preemptive scheduler, and in-kernel IPC channels. See docs/ for how each piece works.

Prerequisites

  • Zig 0.16.x — the build is pinned to this line (.zig-version); other minor versions are rejected, because Zig makes breaking changes between releases pre-1.0. A toolchain manager such as zvm or zigup will pick up .zig-version automatically.
  • QEMU (qemu-system-x86_64) — to run and test the kernel. On macOS, brew install qemu also bundles the OVMF firmware below.
  • OVMF UEFI firmware — the edk2-ovmf package (Arch), ovmf (Debian/Ubuntu), or edk2-ovmf (Fedora); on macOS it ships inside the Homebrew qemu formula. Both the build and the test harness probe the known Arch/Debian/Fedora/macOS layouts and use the first that exists, so no configuration is normally needed. Override with -Dovmf-code= / -Dovmf-vars= (build) if yours lives elsewhere.
  • Python 3 — for the QEMU integration test harness.

Build

zig build

Produces a FHS-shaped zig-out/ that is the danos filesystem and the boot volume: the UEFI bootloader at zig-out/EFI/BOOT/BOOTX64.efi, the kernel at zig-out/system/kernel, init at zig-out/system/services/init, drivers under zig-out/system/drivers/, and the initial-ramdisk at zig-out/boot/.

Run

Boot it in QEMU with OVMF (opens a display window):

zig build run-x86-64
# distro with OVMF elsewhere:
zig build run-x86-64 -Dovmf-code=/path/OVMF_CODE.fd -Dovmf-vars=/path/OVMF_VARS.fd

Test

zig build test            # host unit tests (the platform-independent shared code)
python3 test/qemu_test.py  # QEMU integration tests: boots the kernel and asserts
                           # on its serial output (see docs/testing.md)

The integration harness builds and boots the kernel once per test case, checking memory, the frame allocator, paging (incl. NX and the null guard), the heap, interrupts, and exception handling. It exits non-zero on any failure, so it drops straight into CI.

Documentation

Design notes explaining the why behind the code live in docs/ — start with docs/README.md.

San Serif Text "Dan OS" with a black karate belt around it.