# Pinnacle An operating system written from scratch in Rust, for ARM64 devices of every kind: phones, tablets, laptops. Its interface is responsive from the start: it lays out from the screen it gets, held upright or wide, and the same apps run on all of them. It is developed on QEMU's `virt` machine first, then on real boards. Everything is Rust. The only assembly is what Rust cannot express: the boot entry in `kernel/src/boot.rs`, which runs before there is a stack, and the exception vectors' register save and restore in `kernel/src/exceptions.rs`. It is built to be fast on modest hardware from the start: the MMU and caches are on before the first Rust instruction, with translation tables computed at compile time; a task switch is one pointer swap, and switching between programs one register write (ASIDs, no TLB flush); the release build is whole-program optimised, and code is scheduled for the Cortex-A53. Every core runs (as many as the hardware has, up to 64, found from the GIC's redistributors rather than listed per board), each switching only among its own tasks, so a task's caches and TLB entries stay on one core. The timer is tickless: a core wakes only when something is due there (a slice ends while tasks share it, a sleeper's deadline, a network retry), and a core with nothing to do sleeps with its timer off; a task alone on its core runs undisturbed. | Crate | What it is | |---|---| | `kernel` | The kernel: boot, memory, interrupts, the scheduler on every core, programs, channels and shared memory, drivers (display, input, disks on virtio, NVMe, SATA and USB, USB keyboards and mice, network, sound with a mixer, the serial port to the Bluetooth controller) | | `abi` | What the kernel and its programs agree on: system calls, input events | | `rt` | What every program is built on: system calls, a heap, channels, memory, files | | `gfx` | Drawing: shapes, blending, text from the TrueType fonts on disk, in any script | | `ui` | Apps: the display protocol, a window, the theme, the on-screen keyboard | | `layout` | Where everything goes on a screen of any size: pure functions of the window's size, which the apps draw by and `xtask` taps by | | `pfs` | The file system, shared by the kernel and the tools that make disk images: files up to 4 TiB on disks up to 16 TiB, read and written whole or a range at a time, with holes and times of change; every change a transaction through a journal, so a power cut leaves it as before or after, a large file's space freed after its removal in transactions of their own, and a check that proves a disk whole | | `net` | The network stack: Ethernet, ARP, IPv4, IPv6 (addresses from the routers, neighbours by solicitation), ICMP, UDP, DHCP, DNS (A and AAAA), TCP over either, SNTP with Network Time Security (NTS), and HTTP/1.1 and HTTP/2 (HPACK) as the client speaks them, as pure state machines | | `crypto` | SHA-2 (SHA-256 on the core's instructions), HMAC, HKDF, PBKDF2, ChaCha20-Poly1305, AES with GCM, CCM, CMAC and SIV (on the core's AES instructions), X25519, Ed25519, P-256 key agreement, RSA and ECDSA checks, against the standards' vectors | | `contacts` | The address book: contacts with or without a Pinnacle device, read from and written as vCards (2.1 to 4.0), and which entry an edit or an import replaces | | `p2p` | Identities, a Kademlia DHT over UDP, end-to-end encrypted sessions that follow a device that moves and find it again through the DHT, and reliable streams over them: messaging with no server | | `tls` | TLS 1.3: certificates checked against Mozilla's roots (`certificates/`), the client as a state machine with no I/O of its own; a small server for tests and demos | | `tz` | Time zones: IANA's TZif files (`zoneinfo/`) read, local time and summer time from them, the civil calendar | | `media` | The call codecs: a block DCT video codec and IMA ADPCM audio | | `bt` | Bluetooth Low Energy, as pure state machines: HCI over H4, L2CAP, ATT, GATT as client and server, pairing by LE Secure Connections (numbers compared on both screens, or a passkey shown and typed on a keyboard) and the link encrypted, paired devices remembered, a paired keyboard read over HID over GATT; a simulated controller and the air between several, for tests and for QEMU | | `modem` | The cellular modem, for ordinary phone calls when a contact cannot be reached peer to peer: AT commands as a pure state machine (the SIM and its PIN, the network, dialling, answering, who calls); a simulated modem and the network between several, for tests and for QEMU | | `wifi` | Wi-Fi: the networks nearby and joining one, as a pure state machine over the AT commands of a radio on a UART (ESP-AT: scan, join with a password, leave, a network lost); a simulated radio and the access points around it, for tests and for QEMU | | `disk` | What a whole disk holds around the file system: a GPT partition table, and the FAT32 boot partition UEFI starts from; shared by the kernel's installer and `xtask` | | `boot` | Pinnacle's UEFI loader: the kernel from the boot partition, as a boot image on ARM and by Multiboot2 on a PC (not a workspace member: built for the UEFI targets only) | | `pkg` | Packages: archives signed by their publisher, which the Store opens only with a key the system trusts; the system's two slots and boot record for system updates (`docs/updates.md`) | | `ttf` | The TrueType reader: glyph outlines, traced into a pen, and the fonts' layout rules (`GSUB`, `GPOS`) | | `text` | Text beyond Latin: the bidirectional algorithm, a font for each character from the fallbacks (Arabic, Hebrew, CJK, emoji), Arabic joining, shaping by the font's rules | | `locale` | The person's language (Dutch beside English) and how it writes dates and numbers; the system's texts in Dutch | | `speech` | The system's voice, for the screen reader: English and Dutch read aloud by a formant synthesizer | | `vector` | The vector renderer: paths to bands of exact coverage, the bands in parallel on a device | | `programs` | The display server, the launcher, the p2p, Bluetooth, phone, time and speech services, the Store, Settings, Files, Fien (the code editor of `jeroen/fien`), the apps (Messages, Calls, Contacts, Notes, Bluetooth, Clock, About, Calculator, Paint), and the self-check's test program | | `std` | Rust's standard library for Pinnacle: the target, the patch that adds Pinnacle to Rust's std, and the programs built against it ([std/README.md](std/README.md)) | | `ports` | Crates from crates.io with a Pinnacle branch added, switched in when an app is built for Pinnacle ([ports/README.md](ports/README.md)) | | `xtask` | Building, booting, checking and demonstrating it | ```sh cargo xtask build [qemu-virt|rk3399] # the kernel ELF (the program first) cargo xtask image [qemu-virt|rk3399] # the same as a boot image for U-Boot cargo xtask sdcard # the files for an RK3399 board's SD card cargo xtask run # boot the system in QEMU (disks kept) cargo xtask bundle # the system to run on another machine, in a window cargo xtask bundle pc # the same for a PC (x86-64), on KVM on a Linux laptop cargo xtask pc-demo # the PC used: its apps, one from the Store, a screenshot each cargo xtask pc-efi # the PC's self-check as a real PC boots: UEFI (OVMF), Pinnacle's loader, Multiboot2 cargo xtask loader [pc] # Pinnacle's UEFI loader (boot/), for ARM or a PC cargo xtask installer [pc] # target/install-{arm,pc}.img: a USB stick that installs Pinnacle (docs/hardware.md) cargo xtask install-test [pc] # in QEMU under UEFI: the stick installs on an NVMe disk, which then starts alone cargo xtask install-demo [pc] # the same in Settings → Disks, with a USB tablet and keyboard, a screenshot each step cargo xtask laptop # an Intel laptop as QEMU makes one, no virtio: install from a stick behind a hub, PS/2, off by ACPI cargo xtask demo # drive it like a person, a screenshot a step cargo xtask pair # two devices messaging and calling, no server; then by phone and text, one offline cargo xtask contacts-demo # the address book: write, keep, export, remove, import, search cargo xtask files-demo # Files: notes found in Notes' folder, one opened and moved, one deleted; a picture shown, a file nothing opens; a folder made, renamed, deleted cargo xtask notices-demo # past notifications: two texts, their list, one opened from it, a restart, still listed, cleared cargo xtask network-demo # Settings' network page: online, switched off, on again cargo xtask bluetooth-demo # the devices around, one paired, found again after it moved its address; a keyboard paired by a code, typing in Notes cargo xtask pinebook-demo # a Pinebook Pro's input only: the password typed, Settings clicked open, on USB 1.1 (OHCI) cargo xtask access-demo # five scripts, Settings in Dutch, larger text, high contrast, the screen reader cargo xtask sound-demo # the volume kept at a restart, Settings' slider moved, its tone as loud as it says cargo xtask updates-demo # an app's new version: told, then installed by itself cargo xtask system-update-demo # a new system fetched and started at a restart; a broken one falls back cargo xtask system-update-demo pc # the same on a PC (x86-64) cargo xtask time-demo # the clock set by NTS, a forged answer refused, Amsterdam's summer time, dead keys cargo xtask wifi-demo # Wi-Fi in Settings: networks nearby, a wrong password, joined and kept, joined again cargo xtask fien-demo # Fien: two cursors, Frits checked and completed, a long line wrapped, Edit from Files cargo xtask kees-demo # Kees: signed in, the inbox, an invite accepted, the week, a message written and sent cargo xtask fien-pair-demo # two devices writing in one file at once, each seeing the other's cursor cargo xtask remote # one device's terminal running commands on the other's cargo xtask sync-demo # two devices of one person linked by a code, their notes in step cargo xtask backup-demo # a backup to a stick, restored onto a new phone cargo xtask pipeline-demo # the terminal: a table sorted, filtered, cut to two columns cargo xtask admin-demo # the terminal for looking after a device: ps, kill, log, disks, network, > and && cargo xtask https [url] # fetch an https page from the internet in QEMU, TLS 1.3 cargo xtask test # boot five ways, check the self-check (PINNACLE_CORES=n: n cores, 6 if unset) cargo xtask gate # what a landing must pass PINNACLE_SCREEN=1280x800 cargo xtask demo # any of them on a screen of that size ``` Needs `qemu-system-aarch64` to boot; `rust-toolchain.toml` brings the `aarch64-unknown-none` targets (programs, and the kernel's soft-float one: the kernel never touches FP/SIMD registers, which programs get lazily). Programs written against Rust's std also need the nightly `STD_TOOLCHAIN` names (`xtask`) with its `rust-src`, which `cargo xtask` installs through rustup when it is missing. Build through `cargo xtask`: it builds the programs and the disks (the system font, `fonts/`, among them) the kernel and QEMU need before the kernel. To try it on another machine with nothing but QEMU, `cargo xtask bundle` makes `target/pinnacle.tar.gz`: the boot image, the disks, the Store's packages and a `start` script. Unpack it there and run `./start`; Pinnacle opens in a window of its own (on a Mac: `brew install qemu`, and on Apple silicon it runs on the processor itself rather than emulated). The person's data is kept beside it in `data.img` between runs. Sound goes to the host's speakers and comes from its microphone (Core Audio on a Mac; PipeWire, PulseAudio or ALSA on Linux), or nowhere on a machine without any. `cargo xtask bundle pc` makes `target/pinnacle-pc.tar.gz`, the same for a PC: on a Linux laptop with an Intel or AMD processor it runs on KVM, at the processor's own speed (`qemu-system-x86` needed). Every boot runs a self-check, and `cargo xtask test` requires each part's "ok": | Check | What it proves | |---|---| | memory | Page blocks of every size come back aligned and merge on free; `Vec`, `Box`, `BTreeMap` work | | scheduler | Two tasks on one core: one that never yields is preempted when its slice ends, one that yields gives way; both end | | smp | Every core the hardware has is found and starts (the test checks the count QEMU was given); tasks run on every one; 120 000 increments of one counter from all cores at once, under one lock, lose none | | programs | Two programs at the same addresses each keep their own memory; one that reads the kernel's is killed; every page comes back | | ipc | A service, 100 messages, shared memory seen by both programs, a timeout | | kill | A program ends another it started (the handle SPAWN gave it), its busy and sleeping threads with it | | fp | Twelve programs compute with FP/SIMD registers while switching, each keeping its own | | std | A program built against Rust's std: eight threads sharing a mutex, a condition variable, a channel, a reader-writer lock, thread-locals dropped as their threads end, a sleep and the clocks | | ports | When `cargo xtask test` put it on the disk: a program on tokio over the ported mio, on three workers, with timers, tasks and a TCP connection; and, with a 3D GPU, Vulkan through ash (from crates.io, unchanged) on Pinnacle's driver (`vulkan/`): an instance, the GPU named, a device and its queue, a buffer in mapped memory filled by a command buffer and its fence waited for; and wgpu on it (a WGSL compute shader doubling 1024 numbers) | | display | A framebuffer the size of the screen (720×1440 unless `PINNACLE_SCREEN` says otherwise), shown: behind a virtio-gpu (what changed is sent across a rectangle at a time), else a ramfb | | gpu3d | Where QEMU has the 3D virtio-gpu (Linux with a render node; a Mac with `tools/macos-venus` built): its capsets, a Venus context made and destroyed, and its host-visible memory found | | venus | Beside it, from a program (`hello`) on a GPU channel of its own (`pinnacle_abi::gpu`, Vulkan from `pinnacle-venus`, its encoding generated by `cargo xtask venus-gen`): command streams to the host's Vulkan, their replies read from memory the host shares — its version asked, an instance made, its GPUs listed and each one's name, vendor and type read (on a Mac node: "Apple Paravirtual device", through MoltenVK); then on the first, a logical device and queue, a 64 KiB buffer in memory the host shares into the window, a command buffer filling it with "Pinn", submitted with a fence that is asked until signalled, and every byte read back | | files | Every disk checked whole at mount (a change a power cut interrupted finished first); a file written, a range written into it, read back and removed on the system disk, and the disk whole after | | io | Disk requests complete by interrupt, in batches, while the program that waits for them sleeps: a 2 MiB file written a range at a time and read back, and every wait slept, none spun | | audio | A program plays 300 ms of a 440 Hz tone through the kernel's mixer to the virtio-sound device; `cargo xtask test` hears a tone of 440 Hz in the WAV QEMU wrote | | bluetooth | A program runs the Bluetooth host over the kernel's port to the controller (a simulated air `cargo xtask` holds the other end of): finds the three devices in it, connects to "Pinnacle Test", reads its name and battery level | | modem | A program runs the modem driver over the kernel's second port (a simulated cell network `cargo xtask` holds the other end of): the SIM opened, on the network, a call to a number that answers, hung up | | net | A program gets an address by DHCP and fetches the package source's catalog over TCP (HTTP) | | listen | A program listens on a TCP port; the host connects through QEMU's forwarded port, sends a line and gets it back: connections come in as well as go out | | idle | Cores with nothing to do sleep: their timers off, under one timer interrupt each in half a second (a periodic tick: 50) | | Board | State | |---|---| | `qemu-virt` | Boots, passes the self-check, runs the graphical shell; apps install from the package source | | `rk3399` | Builds as a boot image for U-Boot (`cargo xtask sdcard`, [docs/hardware.md](docs/hardware.md)); draws on a screen the bootloader left lit (a `simple-framebuffer`, or the VOP's first window); not yet run on hardware | Licensed under the GNU General Public License, version 3 or later (`LICENSE`). ## The system On QEMU the kernel starts the display server, which starts the launcher: the home screen, with the Store and the installed apps (`/apps` on the system disk). The Store installs apps from package sources over HTTP: the one `cargo xtask` serves beside QEMU, and the hosted one at pinnacle-os.eu/store, where Cartopolis is published ([docs/store.md](docs/store.md)). The display server is not X: apps draw into their own window (shared memory) and send only "this rectangle changed"; it copies just that to the screen and waits while nothing changes. [docs/architecture.md](docs/architecture.md) has how the parts fit.