2.6 KiB
2.6 KiB
Sovereign Ledger: VirtIO Block Driver
Overview
Phase 10 "The Sovereign Ledger" introduces persistent storage capabilities to Rumpk via a custom VirtIO Block Driver. This allows the NipBox userland to perform direct sector-level I/O operations on a raw disk image (storage.img), establishing the foundation for a future Sovereign Filesystem.
Architecture
1. Hardware Abstraction (L0 HAL)
- Driver:
hal/virtio_block.zig - Device ID:
0x1001(Legacy Block) or0x1042(Modern). - Transport: Leverages
hal/virtio_pci.zigfor universal PCI resource discovery and I/O port allocation. - Mechanism: Synchronous Polling (Busy Wait).
- Uses a 3-Descriptor Chain per request:
- Header:
VirtioBlkReq(Type, Priority, Sector). - Buffer: Data payload (512 bytes).
- Status: Completion byte (0 = OK).
- Header:
- Uses a 3-Descriptor Chain per request:
- Orchestration: Initialized in
hal/entry_riscv.zigviahal_io_init.
2. Kernel Core (L1 Logic)
- Command Ring: Adds
CMD_BLK_READ(0x600) andCMD_BLK_WRITE(0x601) toion.nim. - Arguments:
BlkArgsstructure marshalssector,buffer_ptr, andlenacross the User/Kernel boundary. - Dispatch:
kernel.nimroutes these commands from thechan_cmdring directly to the HAL functionsvirtio_blk_read/write.
3. Userland Shim (Membrane)
- Syscalls:
libc_shim.zigexposesnexus_blk_readandnexus_blk_write. - Packaging: These wrappers construct the
BlkArgsstruct and invokenexus_syscall.
4. Userland Application (NipBox)
- Command:
dd - Syntax:
dd read <sector>: Dumps the first 16 bytes of the sector in Hex.dd write <sector> <string>: Writes the string (UTF-8) to the sector, zero-padded.
- Protocol: Uses the new IO syscalls to interact with the Ledger.
Deployment & Verification
- Disk Image:
build/storage.img(Raw, 32MB). - QEMU: Attached via
-drive if=none,format=raw,file=build/storage.img,id=hd0 -device virtio-blk-pci,drive=hd0,disable-modern=on. - Status:
- Write: Confirmed successful (Hexdump valid on host).
- Read: Driver operation successful, data verification ongoing.
- Boot: Stable initialization of both Network and Block devices simultaneously (via fixed PCI I/O allocation).
Next Steps
- Data Integrity: Investigate zero-readback issue (likely buffer address mapping or flag polarity).
- Filesystem: Implement a minimalist inode-based FS (SovFS) on top of the raw ledger.
- Async I/O: Move from busy-polling to Interrupt-driven (Virtqueue Notification) for high throughput.