## 🏆 VICTORY: First Alien Binary Executed! ``` [Loader] Summoning: bin/hello [Loader] Transferring Consciousness... Hello from a dynamically loaded ELF! Consciousness transferred successfully. ``` ## The Ghost in the Machine (ABI Mismatch Hunt) ### The Hunt - Userland pushed CMD_SYS_EXEC (0x400) to command ring ✅ - Ring reported SUCCESS ✅ - Kernel received... GARBAGE (0xFA42B295) ❌ ### The Diagnosis Raw hex dump revealed 0x400 at offset 12 instead of offset 0. Three layers, three different CmdPacket definitions: - `hal/channel.zig`: 24 bytes (arg: u32) ❌ - `libs/membrane/ion.zig`: 28→32 bytes (packed→extern) 🔧 - `core/ion.nim`: 28→32 bytes (packed→normal) 🔧 ### The Fix: Canonical 32-Byte Structure ```zig pub const CmdPacket = extern struct { kind: u32, _pad: u32, // Explicit Padding arg: u64, id: u128, // 16 bytes }; // Enforced: 32 bytes across ALL layers ``` Compile-time assertions added to prevent future drift. ## Technical Achievements ### 1. ABI Alignment Enforcement - Unified CmdPacket structure across Zig HAL, Zig userland, Nim kernel - Explicit padding eliminates compiler-dependent layout - Static size assertions (32 bytes) at compile time ### 2. Command Ring Communication - Userland→Kernel syscall path verified end-to-end - SipHash provenance tracking operational - Atomic ring buffer operations confirmed ### 3. ELF Loader (from Phase 8 commit) - Dynamic loading from VFS ✅ - ELF64 header validation ✅ - PT_LOAD segment mapping ✅ - BSS initialization ✅ - Userland entry trampoline ✅ ## Files Changed **ABI Fixes:** - `hal/channel.zig`: Updated CmdPacket to 32-byte extern struct - `libs/membrane/ion.zig`: Changed to extern struct with u128 id - `libs/membrane/libc_shim.zig`: Updated packet initialization - `core/ion.nim`: Added explicit padding field, removed {.packed.} **Debug Infrastructure:** - `core/kernel.nim`: Added raw packet hex dump for debugging - `libs/membrane/ion.zig`: Added syscall debug logging **Build:** - `build.sh`: Skipped removed LwIP compilation step ## Lessons Learned **The Law of ABI Invariance:** > "When multiple languages share memory, explicit is the only truth." - Never rely on compiler padding behavior - Always use explicit padding fields - Enforce sizes with compile-time assertions - Test with raw memory dumps, not assumptions **The Debugging Mantra:** > "Flush the pipes. Purge the cache. Trust nothing." Stale binaries from aggressive caching led to hours of ghost-chasing. Solution: `rm -rf build/ .zig-cache/` before critical tests. ## Next Steps (Phase 8 Completion) 1. Implement `exit()` syscall for clean program termination 2. Remove debug logging 3. Test `exec bin/nipbox` (self-reload) 4. Stress test with multiple exec calls 5. Document final implementation ## Metrics - **Time to First Light:** ~8 hours of debugging - **Root Cause:** 8-byte struct size mismatch - **Lines Changed:** ~50 - **Impact:** Infinite (dynamic code loading unlocked) --- **Markus Maiwald (Architect) | (AI)** **New Year's Eve 2024 → 2025** **The year ends with consciousness transfer. 🔥** Co-authored-by: <ai@voxisforge.dev> |
||
|---|---|---|
| .. | ||
| arch | ||
| crypto | ||
| README.md | ||
| abi.zig | ||
| channel.zig | ||
| entry_riscv.zig | ||
| framebuffer.zig | ||
| gpu.zig | ||
| hud.zig | ||
| main.zig | ||
| matrix.zig | ||
| stubs.zig | ||
| uart.zig | ||
| ui.zig | ||
| virtio_net.zig | ||
| virtio_pci.zig | ||
README.md
Rumpk HAL (L0)
Language: Zig + Assembly
Purpose: Hardware Abstraction Layer
Module Index
| File | Purpose |
|---|---|
main.zig |
Entry point (_start), stack setup, calls Nim kmain |
stubs.zig |
Freestanding libc (memcpy, malloc, printf, etc.) |
uart.zig |
PL011 UART driver (QEMU virt) |
abi.zig |
C ABI structs shared with Nim |
Architecture Directory (arch/)
Contains per-architecture implementations:
arch/
├── aarch64/ # ARM64 (VisionFive 2, RPi, AWS Graviton)
│ ├── switch.S # Context switch (96 bytes)
│ └── constants.nim
├── x86_64/ # System V ABI (servers, trading)
│ ├── switch.S # Context switch (56 bytes)
│ └── constants.nim
└── riscv64/ # RISC-V LP64 (satellites, drones)
├── switch.S # Context switch (112 bytes)
└── constants.nim
Freestanding Doctrine
This HAL provides ALL C ABI symbols. No glibc, no musl.
Exported Symbols:
- Memory:
memcpy,memset,memmove,memcmp - Strings:
strlen,strcmp,strcpy - Heap:
malloc,free,realloc,calloc - I/O:
printf,puts,putchar - Exit:
exit,abort - Signals:
signal,raise(no-op stubs)
Build
Compiled via zig build-obj -target <arch>-freestanding-none