A user-space process can now touch real hardware directly, capability-gated by the device tree — the microkernel driver model. - src/kernel/devsvc.zig: flattens the discovered device tree into an id-indexed snapshot + a claim table at boot (devsvc.init from main.zig). - Syscalls 11-13: dev_enumerate (snapshot the table), dev_claim (take exclusive ownership), mmio_map (map a claimed device's MMIO window into the caller's AS and return the register base). The claim is the capability: mmio_map refuses any device the caller doesn't own. - paging.mapUserDeviceInto: maps device MMIO strong-uncacheable (PCD|PWT) and marks each leaf with a device_grant PTE bit; freeSubtree skips pmm.free on those leaves, so tearing down a driver never returns MMIO frames to the RAM pool (the teardown hazard). MMIO grants live in a distinct arena, PML4[226] (Task.dev_map_next), so device pages widen no kernel mapping. - lib/dev.zig: user enumerate/claim/mmioMap wrappers; shared DeviceDesc/ResDesc in danos (root.zig). sbin/hpetd.zig: finds the HPET, claims it, maps its registers, enables the counter (an MMIO write) and reads it (0xF0) — proving read+write passthrough to real hardware. - Tests: `hpet` (driver reads the counter advancing from ring 3) and `iopass` (device-granted frame survives address-space teardown). Suite 33/33. irq_bind/irq_ack (IRQ-as-message) are stubbed (-1) pending; notifyFromIsr (M7) is the hook they'll use.
31 lines
1.3 KiB
Zig
31 lines
1.3 KiB
Zig
//! danos user-space runtime library — a nascent libc. Every user binary (init,
|
|
//! and later the VFS server + device drivers) imports this as `@import("rt")`:
|
|
//! syscall wrappers, the C-convention heap, IPC helpers, and the process start
|
|
//! shim. It is compiled into each binary (inheriting its `.large` code model and
|
|
//! freestanding target), so all user programs share one implementation.
|
|
//!
|
|
//! A user binary needs three lines:
|
|
//! const rt = @import("rt");
|
|
//! pub const panic = rt.panic;
|
|
//! comptime { _ = &rt.start._start; } // pull the entry shim in
|
|
//! and a `pub fn main() void`.
|
|
|
|
pub const sys = @import("sys.zig");
|
|
pub const heap = @import("heap.zig");
|
|
pub const ipc = @import("ipc.zig");
|
|
pub const start = @import("start.zig");
|
|
/// The VFS wire protocol (shared with the VFS server).
|
|
pub const vfsproto = @import("vfs_proto.zig");
|
|
/// POSIX-style file API: open/read/write/lseek/stat/close.
|
|
pub const unistd = @import("unistd.zig");
|
|
/// C stdio: fopen/fread/fwrite/fseek/ftell/fclose over unistd.
|
|
pub const stdio = @import("stdio.zig");
|
|
/// Device access for drivers: enumerate/claim/mmioMap.
|
|
pub const dev = @import("dev.zig");
|
|
|
|
/// Re-exported so a user binary can `pub const panic = rt.panic;`.
|
|
pub const panic = start.panic;
|
|
|
|
/// The heap as a `std.mem.Allocator`, for Zig `std` containers in user code.
|
|
pub const allocator = heap.allocator;
|