Operating System written for me
Go to file
Daniel Samson 452080e997
Add runtime.time, drop demo drivers, harden TSC timekeeping
Time is a kernel concern in danos: the kernel owns the scheduling timer and
already exposes monotonic time via the clock/sleep/timer_bind syscalls, so a
userspace time service would be a redundant, slower path. This adds the generic
runtime.time module over those syscalls, retires the two demonstration drivers,
reorganizes the milestone docs, and makes the monotonic clock correct on Intel,
AMD, and inside any VM.

runtime.time (library/runtime/time.zig)
- Instant/Duration interface: now, sleep, spin, after, monotonicNanos, available
- a thin layer over system.clock/sleep/timerOnce; unit-tested arithmetic

Remove the demo drivers hpet and bus (a teaching example belongs in the docs,
not shipped in the tree)
- system/drivers/ now holds only real drivers: pci-bus, ps2-bus, usb-xhci-bus
- device-manager end-to-end test repointed to pci-bus (asserts on kernel state:
  the process table and the device tree, not a racy serial marker)
- device_register containment moved to a new in-kernel `containment` test
- the driver-model worked example moved inline into docs/drivers.md

Reorganize milestone docs into topic docs
- m17-m18 / m19-m20 / m21 plans dissolved into process-lifecycle, device-manager,
  discovery, and acpi docs; new docs/power.md and docs/timers.md; ~20 citations
  repointed; plan docs deleted

TSC reliability (apic.zig, smp.zig, cpu.zig, kernel.zig)
- check the invariant-TSC bit (CPUID 0x80000007 EDX[8]) on Intel and AMD
- cross-core "warp" check at SMP bring-up, pairwise BSP<->AP as each core comes up
- fall back to the HPET clocksource when the TSC is not invariant (a bare VM) or
  not synchronized (a warp), switched continuously so time never jumps
- boot log reports the outcome; new tsc-sync test exercises the TSC + warp path

Verified: zig build; zig build test; 60/60 QEMU cases (incl. new containment and
tsc-sync).
2026-07-13 11:56:43 +01:00
boot fix efi: debug prefix 2026-07-13 05:30:56 +01:00
docs Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
library Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
system Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
test Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +01:00
tools Make sort-lines-group-by-start.sh a runnable script 2026-07-13 05:15:56 +01:00
.editorconfig editorconfig 2026-07-12 16:09:11 +01:00
.gitattributes gitattributes 2026-07-12 16:09:18 +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 Docs: link README to system-requirements.md 2026-07-13 11:10:24 +01:00
build.zig Add runtime.time, drop demo drivers, harden TSC timekeeping 2026-07-13 11:56:43 +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 resilient operating system, written from scratch in Zig.

Zen of DanOS:

  • Resilient Micro-Kernel Architecture.
    • Every process run in an isolated user space not kernel space.
    • Processes cannot take down the entire OS with it when they die or is killed
  • Stable public runtime library, private OS ABI.
    • Keeps a stable runtime for user space processes between OS versions (great for backwards compatibility)
    • Allows the underlying OS to be changed without effecting applications
    • Provides a boundary to enable compatibility between OS's e.g. POSIX, MUSL etc
  • Drivers are just isolated processes in user space.
    • Thin binaries that can be restarted like applications.
    • Useful during driver development.
    • Drivers can claim MMIO / ports
    • Driver resources (e.g. IRQ/Port/MMIO) claims are automatically cleaned up if the driver dies or is killed
    • Drivers can also hook into the process lifecyle to clean up or reset hardware
  • No legacy to deal with
    • Zig code uses a clean coding style (Zen of Zig)
    • Favor reading code over writing code.
    • No magic numbers.
    • No shortend names unless its for ABI compatibility or acronyms
  • Inter-Process Communication (IPC)
    • Publish and subscribe to Asynchronous Messages
    • Talk to services and processes synchronously

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 why behind the code live in docs/ — start with docs/README.md.

For the hardware needed to run DanOS — minimum specs plus a plain-language guide matching Intel/AMD CPU generations by name — see docs/system-requirements.md.

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