Commit Graph

4 Commits

Author SHA1 Message Date
Markus Maiwald 73620c43b1 Phase 37: The Glass Cage - Memory Isolation Complete
VICTORY: All page faults (Code 12, 13, 15) eliminated. NipBox runs in isolated userspace.

Root Cause Diagnosed:
- Kernel BSS (0x84D5B030) was overwritten by NipBox loading at 0x84000000
- current_fiber corruption caused cascading failures

Strategic Fixes:
1. Relocated NipBox to 0x86000000 (eliminating BSS collision)
2. Expanded DRAM to 256MB, User region to 64MB (accommodating NipBox BSS)
3. Restored Kernel GP register in trap handler (fixing global access)
4. Conditionally excluded ion/memory from userspace builds (removing 2MB pool)
5. Enabled release build optimizations (reducing BSS bloat)

Results:
- Kernel globals: SAFE
- User memory: ISOLATED (Sv39 active)
- Syscalls: OPERATIONAL
- Scheduler: STABLE
- NipBox: ALIVE (waiting for stdin)

Files Modified:
- core/rumpk/apps/linker_user.ld: User region 0x86000000-0x89FFFFFF (64MB)
- core/rumpk/hal/mm.zig: DRAM 256MB, User map 32-256MB
- core/rumpk/hal/entry_riscv.zig: GP reload in trap handler
- core/rumpk/core/ion.nim: Conditional memory export
- core/rumpk/libs/membrane/ion_client.nim: Local type declarations
- core/rumpk/libs/membrane/net_glue.nim: Removed ion import
- core/rumpk/libs/membrane/compositor.nim: Stubbed unused functions
- src/nexus/builder/nipbox.nim: Release build flags

Next: Fix stdin delivery to enable interactive shell.
2026-01-04 02:03:01 +01:00
Markus Maiwald 5416c8cd93 🎊 PHASE 8 COMPLETE: The Summoning - Dynamic ELF Loader OPERATIONAL
## 🏆 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) | Forge (AI)**
**New Year's Eve 2024 → 2025**
**The year ends with consciousness transfer. 🔥**

Co-authored-by: Forge <ai@voxisforge.dev>
2025-12-31 21:08:25 +01:00
Markus Maiwald 30fa024367 feat(rumpk): Sovereign Core Stabilization & Membrane IPC Hardening
- NexShell: Hardened command transmission via atomic ION packets, fixed fragmentation issues.
- NipBox: Expanded 'Sovereign Coreutils' with 'ls' and enhanced 'matrix' control.
- GPU/Retina: Optimized VirtIO-GPU driver, improved polling and framebuffer synchronization.
- Membrane: Stabilized libc shims (clib.c, libc.nim) and ION client logic.
- Kernel: Refined fiber scheduler and watchdog metrics.
- Forge: Cleanup and optimization of build scripts and manifests.
2025-12-31 20:18:49 +01:00
Markus Maiwald 061a2ff56b feat(rumpk): implement Invariant Shield and Blink Recovery
- Implement Design by Contract in HAL and Kernel (Phase 2 Task 1)
- Add invariant checks to Sovereign Channels (pointer validation, bounds)
- Create invariant.nim for secure Logic-to-HAL transitions
- Codify Silence Doctrine in DOCTRINE.md and SPEC files
- Finalize Blink Recovery confirmation via Saboteur test
- Update SPEC-008, SPEC-009, SPEC-010, SPEC-011 with architectural refinements
- Sync Website vision with new technical milestones
2025-12-31 20:18:48 +01:00