Commit Graph

84 Commits

Author SHA1 Message Date
a3b15e5264 feat: playable snake game via UART terminal rendering
Snake renders using ANSI escape codes via debug_putchar syscall,
bypassing the VirtIO GPU (which has a QEMU 11.x legacy MMIO bug
where transfer_to_host_2d succeeds but doesn't transfer data).

Full microkernel stack running end-to-end:
  adapter → init → storage-server IPC → load snake from disk →
  input-server IPC (UART keyboard) → snake game logic →
  debug_putchar syscall → UART → terminal display

Controls: WASD to steer, runs at 0.2s tick rate.
Green O=head, o=body, red @=food, #=border.
2026-10-18 22:08:52 +02:00
27be73f42d feat: wire display + input servers to snake, fix QEMU 11.x GPU bug
VirtIO GPU: QEMU 11.x has RESOURCE_ATTACH_BACKING (0x0104) and
RESOURCE_FLUSH (0x0106) command types swapped in its legacy MMIO
VirtIO GPU implementation. Workaround: send swapped type values.
Confirmed via QEMU monitor (xp shows correct bytes in memory)
and QEMU trace events (device dispatches to wrong handler).

Display pipeline now works end-to-end:
  adapter → GPU init → create_2d → attach_backing → set_scanout
  display-server → clear(blue) → flush → transfer + resource_flush
  snake → draw commands via IPC → display renders → flush to GPU

Input server:
  - New driver-input-uart crate (reads UART at mapped VA 0x20000)
  - New bins/input-qemu composition root
  - Adapter loads input-server, maps UART MMIO into its address space
  - Init delegates both display_ep (slot 0) and input_ep (slot 1) to snake
  - WASD keys → UART → input-server → IPC → snake direction change

Snake game runs with display and input, exits on wall collision.
2026-10-18 21:10:42 +02:00
7c7e3b8748 refactor: apply newtypes throughout userspace API and display types
Every syscall stub now uses proper types from types/ — CapSlot,
EntryPoint, StackPointer, VirtualAddress, PageCount, ProcessId,
PermissionSet, Ticks. The compiler prevents swapping entry/stack,
passing a ProcessId where a CapSlot is expected, or using an
address as a page count.

New display types in types/display.rs:
  - Color(u32) with rgb() constructor
  - ScreenCoord(u16) for x/y positions
  - Dimension(u16) for width/height

Updated throughout:
  - userspace/syscall.rs: all params typed, returns Option instead
    of sentinel usize::MAX
  - server-framework: endpoint param is CapSlot
  - port-framebuffer: trait uses Color, ScreenCoord, Dimension
  - hw-virtio: DmaAddrs uses PhysicalAddress/VirtualAddress,
    GPU commands use Dimension
  - All servers, drivers, bins, apps updated for new signatures
  - permission-manager: process field uses ProcessId
  - PermissionSet: added bits() accessor

89 tests pass, full QEMU boot verified.
2026-10-18 13:45:40 +02:00
3a0395453b refactor: extract shared hw-virtio crate, eliminate VirtIO protocol duplication
Two VirtIO block and two VirtIO GPU implementations (adapter + driver)
shared 90% of their protocol logic. Extracted the common code into
hw-virtio, parameterized by MmioAccess trait.

New crate: hw-virtio (no_std, zero deps)
  - mmio.rs: MmioAccess trait, DirectMmio, init_legacy_device(), scan
  - queue.rs: VirtioQueue with descriptor chain submit + poll
  - block.rs: block read protocol (3-descriptor chain)
  - gpu.rs: GPU commands (create_2d, attach_backing, set_scanout,
            transfer_to_host, resource_flush)

Adapter thin wrappers (identity-mapped, statics for DMA):
  - virtio_blk.rs: 220 → 53 lines
  - virtio_gpu.rs: 165 → 37 lines

Driver thin wrappers (mapped VAs, phys-info for DMA):
  - drivers/block/virtio: 139 → 70 lines
  - drivers/framebuffer/virtio: 146 → 95 lines

Also deleted input-server/input_device.rs (1-line re-export,
superseded by port-input-device).
2026-10-18 13:29:28 +02:00
8d53fa9ac5 refactor(adapter-riscv): split kmain into boot/, devices/ modules
kmain is now 20 lines — six function calls:

  hardware::init        → BSS, MMU, traps, timer, PLIC, kernel
  loader::load_init     → read init.elf, create process, map ELF
  loader::load_server   → read server ELF, create process, map ELF
  storage_setup         → VirtIO block re-init, shared buffer, phys-info
  gpu_setup             → VirtIO GPU init, framebuffer alloc, phys-info
  caps::grant_all       → endpoints, capability grants

New modules:
  boot/hardware.rs   — hardware init (BSS, MMU, traps, kernel)
  boot/loader.rs     — ELF loading, thread setup, enter_userspace
  boot/caps.rs       — endpoint creation, capability grants
  devices/storage_setup.rs — VirtIO block for storage server
  devices/gpu_setup.rs     — VirtIO GPU for display server

All unsafe contained in hw/, mmu/, trap/. Boot and device
modules call safe wrappers.
2026-10-18 13:19:16 +02:00
5766c6f7f7 refactor: extract ports/drivers/bins layers — clean dependency inversion
Separate abstractions from implementations following DIP:

  servers/              drivers/
      │                     │
      ▼                     ▼
    ports/  (trait-only crates, zero deps)

New crates:

ports/ (abstractions):
  - port-framebuffer: Framebuffer trait
  - port-block-device: BlockDevice trait + SectorId
  - port-input-device: InputDevice trait + InputEvent types

drivers/ (implementations depend on ports/):
  - driver-framebuffer-virtio: VirtIO GPU framebuffer
  - driver-framebuffer-mock: test double
  - driver-block-virtio: VirtIO block device

bins/ (composition roots wire server + driver):
  - display-qemu: DisplayServer<VirtioFramebuffer>
  - storage-qemu: storage server with VirtIO block

Servers no longer own their hardware traits or driver code.
Neither server nor driver depends on the other — both point
inward to the port abstraction.
2026-10-18 13:13:53 +02:00
38f20cc3c4 feat: proper IPC-based boot — init loads servers from storage via IPC, VirtIO GPU driver
Complete microkernel boot pipeline: adapter loads only init + storage + display
from disk. Init bootstraps all other servers by reading binaries from the
storage server via IPC, parsing ELF, creating processes, mapping pages, and
spawning threads.

New syscalls:
- CreateEndpoint: userspace endpoint creation with full capability grant
- DebugPutchar: debug output to UART from userspace
- MapPage: cross-process page mapping (init loads binaries into children)
- SpawnThreadIn: spawn thread in another process via capability

Key fixes:
- Per-process L1 page tables for VPN[2]=0 (prevents cross-process corruption)
- Separate kernel_pt from page_tables[0] (init pid=0 overwrote kernel PT ref)
- Thread Running state set in switch_to_next (syscalls rejected without it)
- Pending IPC results applied during context switch
- SIE disabled during boot (timer can't preempt into unready processes)
- User heap VA starts at 0x40000 (avoids shared buffer at 0x30000)
- RequestPages maps at user VAs via per-process heap allocator

VirtIO GPU:
- Adapter probes for GPU device, initializes resource/scanout/backing
- Display server writes to mapped framebuffer, flushes via GPU virtqueue
- 640x480 BGRA framebuffer with transfer-to-host and resource-flush

Storage server:
- Userspace VirtIO block driver using pre-mapped MMIO and DMA pages
- FAT16 filesystem reader serving file-read requests via IPC
- Shared buffer protocol: init writes filename, storage writes file data

Echo app for IPC testing (adapter-loaded echo proved the pipeline end-to-end).
2026-10-18 13:02:30 +02:00
ffde4065ba fix: full init boot logic works — CreateProcess no longer spawns threads, boot uses out-param to avoid sret bug
- CreateProcess only creates process + grants cap, no thread spawning
- boot::boot takes &mut BootResult instead of returning it (fixes -> ! sret convention issue)
- Init creates 6 server processes, sets up supervisor, enters receive loop
- No faults on QEMU with full boot sequence
2026-10-18 04:57:20 +02:00
29cd0e7dfe feat: userspace linker script at 0x10000, proper ELF segment loading, full disk boot pipeline working
- Userspace linker script: apps/servers link at 0x10000 (user VA)
- Adapter linker script: kernel links at 0x80200000 (S-mode)
- Each uses build.rs to emit its own -T flag, global config only sets panic=abort
- ELF loader: page-aligns segment mappings, handles non-aligned vaddrs
- Stack: 4 pages (16K) mapped below program
- SP set to top of stack (0x10000), not bottom
- FAT16 disk image forced (mformat was creating FAT32)
- End-to-end verified: VirtIO → FAT16 → ELF → userspace → ecall → exit
2026-10-18 04:51:07 +02:00
924baede9e fix(adapter-riscv): fix VirtIO block driver — scan all MMIO slots, handle legacy mode, fix virtqueue layout
VirtIO now properly scans 8 MMIO slots, detects legacy vs modern mode,
uses correct virtqueue page alignment for legacy, and reads sectors.
Fixed disk image script to force FAT16 (mformat was creating FAT32).
init.elf successfully loaded from FAT16 disk via VirtIO on QEMU.
2026-10-18 04:42:13 +02:00
7649cb0b18 feat: add run() and binary entry points for all servers and init
Every server now has lib.rs (testable) + main.rs (deployable binary).
Binary is 3 lines: extern crate userspace_rt + call run().
Hardware servers use feature flags for adapter selection.
9 RISC-V binaries ready for the disk image.
2026-10-18 04:26:42 +02:00
d43c6a7e74 feat(adapter-riscv): load init from VirtIO block device with FAT16 filesystem
Adapter probes for VirtIO block device, reads init.elf from FAT16 disk,
parses ELF, maps into userspace, and launches. Falls back to embedded
minimal init if no disk is present.

Also: VirtIO MMIO driver, boot FAT16 reader, disk image build script,
Makefile targets for build/run/run-disk.
2026-10-18 04:19:19 +02:00
a910c06cf7 refactor(adapter-riscv): replace hardcoded demo with proper init launch via ELF parsing
Adapter now: parses init binary (ELF or raw), allocates pages, creates
user page table, sets thread entry point in SavedContext, enters U-mode.
Init takes over from there — no more IPC demo hardcoded in the adapter.
2026-10-18 04:13:13 +02:00
41f7e7db10 feat(session-server): add session server for app launching, remove apps from init manifest
Init now only starts servers. The session server holds ProcessCreate cap
and launches apps on demand. Snake is no longer in the boot manifest.
2026-10-18 04:09:28 +02:00
29434805a6 feat(userspace-rt): add runtime crate with entry point, panic handler, and allocator re-export
Snake and hello apps now use extern crate userspace_rt — no more boilerplate assembly or panic handlers in app code.
2026-10-18 04:04:52 +02:00
e092fa4ae5 fix: disable test harness for no_std binaries, fix shutdown to best-effort notify-and-halt, use CapSlot newtypes 2026-10-18 04:01:39 +02:00
0389c85108 feat(snake): implement snake game with pure game logic, renderer, and IPC-based main loop 2026-10-18 04:00:09 +02:00
a7913ddeef feat(userspace): add KosAllocator — free-list allocator backed by RequestPages syscall 2026-10-18 03:55:58 +02:00
f72a434e1a refactor(init): replace raw usize with CapSlot, StorageHandle, PhysicalAddress newtypes throughout supervisor and boot 2026-10-18 03:54:07 +02:00
0a2e01bec9 feat(init): implement supervisor with storage-backed restart, binary source tracking, and back-off delays 2026-10-18 03:52:07 +02:00
29c3841679 feat(storage-server): implement ext4 read-only filesystem with superblock, inode, extent, and directory parsing 2026-10-18 03:49:24 +02:00
dd5c2c7268 feat(storage-server): implement FAT16 filesystem with read, write, create, delete, list, and cluster chain management 2026-10-18 03:45:30 +02:00
2dc503e07e refactor(storage-server): add SectorId, FileName, PackedPath newtypes, eliminate raw primitives and DRY violations 2026-10-18 03:41:14 +02:00
7a4600b3a2 feat(storage-server): add StorageServer<F: FileSystem> with BlockDevice trait, mock adapters, and tests 2026-10-18 03:37:40 +02:00
b7bc223a79 feat: add Halt syscall, fault notification to fault handler, supervisor with back-off, shutdown with timeout
- Halt syscall: only pid 0 (init) can halt, adapter uses SBI SRST
- Fault notification: kernel delivers fault info to process fault handler endpoint before killing
- Supervisor: tracks restart counts, back-off up to 5 restarts
- Shutdown: notifies servers, waits with timeout, calls halt
- Trap handler: faults now call kernel.handle_fault instead of halting
2026-10-18 03:29:05 +02:00
a83b53d962 feat(init): add init crate with declarative boot manifest, boot sequence, supervisor and shutdown stubs
Also: make types from_raw/raw const fn, add create_process/kill/delegate/revoke to userspace syscall stubs.
2026-10-18 03:21:17 +02:00
962df75f85 refactor(permission-manager): deduplicate kind mapping into CapabilityKind::index/from_index 2026-10-18 03:17:03 +02:00
36cab28506 feat: add log-server (ring buffer) and permission-manager (grant/revoke/check) system servers 2026-10-18 03:14:48 +02:00
919e918c0a feat(input-server): expand protocol with pointer, scroll, and gamepad events 2026-10-18 03:11:15 +02:00
c9bd1d2c35 feat(input-server): add InputServer<D: InputDevice> with protocol, mock + UART adapters, and tests 2026-10-18 03:08:36 +02:00
5600ce0260 feat(display-server): add VirtioFramebuffer adapter for QEMU 2026-10-18 03:05:27 +02:00
b6cfea814a feat(display-server): add DisplayServer<F: Framebuffer> with protocol, mock adapter, and tests 2026-10-18 03:03:58 +02:00
c14fe50c23 feat(server-framework): add Server trait, Encode/Decode, async executor, syscall wrappers, and mock arch for host testing 2026-10-18 02:55:22 +02:00
5c29c0845d refactor: move Mapping<F> to types crate with VirtualAddress/PhysicalAddress newtypes, rename MapFlags to Sv39Flags 2026-10-18 02:45:53 +02:00
7df3034fca refactor(mmu): replace bool-heavy map_range with Mapping struct and MapFlags builders 2026-10-18 02:41:27 +02:00
896c78088a feat: implement configure_protection and map_shared with real page mapping, remove dead context_switch from Platform trait 2026-10-18 02:39:36 +02:00
7724a5bd0a feat: implement context switching, SavedContext with pc/status fields, wire all syscall outcomes and timer preemption 2026-10-18 02:34:36 +02:00
5a45c14cf5 feat(adapter-riscv): replace static mut with KernelCell, complete all 17 syscall decoders, wire timer and PLIC interrupts to kernel 2026-10-18 02:29:46 +02:00
ededdb2ed9 refactor(userspace): split syscall stubs into arch-agnostic API + arch/riscv backend 2026-10-18 02:19:30 +02:00
570fe22bee feat: userspace round-trip — syscall stubs, ecall dispatch, U-mode entry and exit on QEMU 2026-10-18 02:15:35 +02:00
450d74d07f docs: add ADAPTERS.md with adapter structure, rules, and scaffolding guide 2026-10-18 02:09:56 +02:00
b742f92c0a feat: add scripts/new-adapter.sh to scaffold adapter crates with consistent structure 2026-10-18 02:08:32 +02:00
d327794d33 refactor(adapter-riscv): restructure into hw/, mmu/, trap/ modules with board constants
Add Priority::DEFAULT and TimeSlice::DEFAULT to types crate.
All QEMU virt addresses consolidated in board.rs.
Structure mirrors future adapter-arm/ layout.
2026-10-18 02:05:57 +02:00
66a730b2fe feat(adapter-riscv): IPC demo — two processes exchange a message on QEMU virt 2026-10-18 01:58:18 +02:00
2436061215 feat(adapter-riscv): add RiscVPlatform, PLIC driver, and kernel boot on QEMU 2026-10-18 01:56:18 +02:00
941704bbbc feat(adapter-riscv): add trap handling, timer via SBI, and S/U-mode trap vector 2026-10-18 01:53:37 +02:00
d9de828420 feat(adapter-riscv): add Sv39 page tables with identity mapping and MMU activation 2026-10-18 01:48:00 +02:00
44a0ead7f2 feat(adapter-riscv): boot on QEMU virt with UART hello world 2026-10-18 01:46:47 +02:00
dcadb83088 feat: add Platform::map_shared and wire memory delegation to page mapping 2026-10-18 01:30:23 +02:00
4844b6c2d2 feat(elf): add no_std ELF64 parser for loading process binaries 2026-10-18 01:26:18 +02:00