rumpk/core/ion.nim

70 lines
2.0 KiB
Nim

# Markus Maiwald (Architect) | Voxis Forge (AI)
# Nexus Rumpk: ION Control Plane
import ion/memory
export memory
type
CmdType* = enum
CMD_SYS_NOOP = 0
CMD_SYS_REBOOT = 1
CMD_ION_STOP = 2
CMD_ION_START = 3
CMD_GPU_MATRIX = 0x100
CMD_GPU_CLEAR = 0x101
CMD_GET_GPU_STATUS = 0x102
CmdPacket* = object
kind*: uint32
arg*: uint32
id*: array[16, byte] # u128 for SipHash Provenance
# Binary compatible with hal/channel.zig
HAL_Ring*[T] = object
head*: uint32
tail*: uint32
mask*: uint32
data*: array[256, T]
SovereignChannel*[T] = object
ring*: ptr HAL_Ring[T]
SysTable* = object
magic*: uint32 # 0x4E585553
s_rx*: ptr HAL_Ring[IonPacket] # Kernel -> App
s_tx*: ptr HAL_Ring[IonPacket] # App -> Kernel
s_event*: ptr HAL_Ring[IonPacket] # Telemetry
s_cmd*: ptr HAL_Ring[CmdPacket] # Command Ring (Control Plane)
s_input*: ptr HAL_Ring[IonPacket] # Input to Subject
include invariant
const SYSTABLE_BASE* = 0x83000000'u64
# HAL Imports (Hardened ABI - Handle Based)
proc hal_channel_push*(handle: uint64,
pkt: IonPacket): bool {.importc: "hal_channel_push", cdecl.}
proc hal_channel_pop*(handle: uint64,
out_pkt: ptr IonPacket): bool {.importc: "hal_channel_pop", cdecl.}
proc hal_cmd_push*(handle: uint64,
pkt: CmdPacket): bool {.importc: "hal_cmd_push", cdecl.}
proc hal_cmd_pop*(handle: uint64,
out_pkt: ptr CmdPacket): bool {.importc: "hal_cmd_pop", cdecl.}
proc send*(chan: var SovereignChannel[IonPacket], pkt: IonPacket) =
secure_push_packet(chan.ring, pkt)
proc recv*(chan: var SovereignChannel[IonPacket],
out_pkt: var IonPacket): bool =
if (cast[uint](chan.ring) and 0b11) != 0:
return false # Or panic
return hal_channel_pop(cast[uint64](chan.ring), addr out_pkt)
proc send*(chan: var SovereignChannel[CmdPacket], pkt: CmdPacket) =
secure_send(chan.ring, pkt)
proc recv*(chan: var SovereignChannel[CmdPacket],
out_pkt: var CmdPacket): bool =
return secure_recv_cmd(chan.ring, out_pkt)