Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/x86/swap_proto.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / x86 / swap_proto.h` 57 lines · 2505 bytes Raw Blame History 1 /* swap_proto.h -- AIENOS live kernel swap wire protocol (port 47034). 2 * Shared between the running kernel (swap_x86.c) and the Spark push tool 3 * (tools/ck_imac_swap.c). No heap, no I/O; freestanding C. All integers 4 * big-endian in the wire format; host helpers below convert as needed. 5 * 6 * The payload is a signed slot object: CK_SLOT_UNIT bytes (manifest from 7 * native/boot/slot_format.h) followed by the raw kernel PE image bytes. 8 * The kernel verifies the manifest signature with the same Ed25519 check 9 * the netboot loader uses; only then does it quiesce and jump. */ 10 #ifndef AIENOS_CK_SWAP_PROTO_H 11 #define AIENOS_CK_SWAP_PROTO_H 12 #include 13 #include 14 15 #define CK_X86_SWAP_PORT 47034u 16 17 /* Header present in every swap packet (24 bytes). */ 18 #define SWAP_MAGIC "ASWP" 19 #define SWAP_MAGIC_ACK "ASWK" 20 #define SWAP_VERSION 1u 21 22 /* Types for PUSH packets (Spark → iMac). */ 23 #define SWAP_TYPE_DATA 1u /* data chunk */ 24 #define SWAP_TYPE_END 2u /* all chunks sent; ask for status */ 25 26 /* Status codes in ACK packets (iMac → Spark). */ 27 #define SWAP_ACK_WANT 0u /* more data wanted; want_offset = next expected */ 28 #define SWAP_ACK_DONE 1u /* verified, about to jump; done */ 29 #define SWAP_ACK_FAIL 2u /* rejected; see text */ 30 31 #define SWAP_CHUNK 1024u /* bytes per data chunk (NB_CHUNK) */ 32 #define SWAP_WINDOW 16u /* max outstanding chunks */ 33 #define SWAP_TEXT_MAX 80u /* max printable text in ACK */ 34 #define SWAP_HDR_BYTES 24u /* fixed header, before data */ 35 36 /* Wire layout of a PUSH packet (all integers big-endian): 37 * 0 magic[4] 4 version u8 5 type u8 6 pad[2] 8 nonce[8] 38 * 16 offset u32 20 total u32 24 len u16 26 pad[6] 32 data[len] */ 39 #define SWAP_PUSH_MIN 32u 40 41 /* Wire layout of an ACK packet: 42 * 0 magic[4] 4 version u8 5 status u8 6 pad[2] 8 nonce[8] 43 * 16 want u32 20 total u32 24 text[n] (n <= SWAP_TEXT_MAX) */ 44 #define SWAP_ACK_MIN 24u 45 #define SWAP_MSG_MAX (SWAP_PUSH_MIN + SWAP_CHUNK) 46 47 /* Decode helpers (big-endian). */ 48 static inline uint32_t swap_r32(const uint8_t *b) { 49 return (uint32_t)b[0] << 24 | (uint32_t)b[1] << 16 | (uint32_t)b[2] << 8 | b[3]; } 50 static inline uint16_t swap_r16(const uint8_t *b) { 51 return (uint16_t)((uint16_t)b[0] << 8 | b[1]); } 52 static inline void swap_w32(uint8_t *b, uint32_t v) { 53 b[0]=(uint8_t)(v>>24); b[1]=(uint8_t)(v>>16); b[2]=(uint8_t)(v>>8); b[3]=(uint8_t)v; } 54 static inline void swap_w16(uint8_t *b, uint16_t v) { 55 b[0]=(uint8_t)(v>>8); b[1]=(uint8_t)v; } 56 57 #endif /* AIENOS_CK_SWAP_PROTO_H */