Initial commit: GKERN glyph kernel

This commit is contained in:
gyt
2026-07-09 13:28:07 -04:00
commit 0807c58eae
43 changed files with 6006 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
#ifndef GLYPH_DECODE_H
#define GLYPH_DECODE_H
#include "glyph_types.h"
static inline GlyphInstr glyph_decode(uint32_t word) {
GlyphInstr ins;
ins.family_id = (word >> 26) & 0x3F;
ins.sub_id = (word >> 21) & 0x1F;
ins.mode = (word >> 19) & 0x03;
ins.opclass = (word >> 16) & 0x07;
ins.opcode_local = word & 0xFFFF;
return ins;
}
static inline uint32_t glyph_encode(uint8_t family_id, uint8_t sub_id, uint8_t mode, uint8_t opclass, uint16_t opcode_local) {
return ((uint32_t)(family_id & 0x3F) << 26) | ((uint32_t)(sub_id & 0x1F) << 21) | ((uint32_t)(mode & 0x03) << 19) | ((uint32_t)(opclass & 0x07) << 16) | (uint32_t)(opcode_local);
}
static inline void glyph_decode_ops(uint16_t opcode_local, uint8_t *op_a, uint8_t *op_b) {
*op_a = (opcode_local >> 8) & 0xFF;
*op_b = opcode_local & 0xFF;
}
static inline uint16_t glyph_encode_ops(uint8_t op_a, uint8_t op_b) { return ((uint16_t)op_a << 8) | (uint16_t)op_b; }
static inline const char *glyph_mode_str(uint8_t mode) {
switch (mode) { case MODE_USER: return "user"; case MODE_KERNEL: return "kernel"; case MODE_SYSTEM: return "system"; case MODE_RESERVED: return "reserved"; default: return "unknown"; }
}
static inline const char *glyph_opclass_str(uint8_t opclass) {
switch (opclass) { case OPCLASS_MEM: return "MEM"; case OPCLASS_CMP: return "CMP"; case OPCLASS_CTL: return "CTL"; case OPCLASS_IPC: return "IPC"; case OPCLASS_SYS: return "SYS"; case OPCLASS_APP: return "APP"; case OPCLASS_EXT: return "EXT"; case OPCLASS_EXT2: return "EXT2"; default: return "???"; }
}
static inline const char *glyph_lineage_str(uint8_t family_id) {
if (family_id <= FAMILY_MEM_END) return "MEM"; if (family_id <= FAMILY_CMP_END) return "CMP"; if (family_id <= FAMILY_CTL_END) return "CTL"; if (family_id <= FAMILY_IPC_END) return "IPC"; if (family_id <= FAMILY_SYS_END) return "SYS"; return "APP";
}
#endif
+48
View File
@@ -0,0 +1,48 @@
#ifndef GLYPH_TYPES_H
#define GLYPH_TYPES_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
typedef uint64_t TraitMask;
typedef uint32_t HandleId;
typedef enum { HANDLE_UNKNOWN = 0, HANDLE_MEMORY_REGION = 1, HANDLE_GVM = 2, HANDLE_CHANNEL = 3, HANDLE_FILE = 4 } HandleKind;
typedef struct { HandleKind kind; uint32_t payload; } Handle;
typedef struct { HandleId id; uint8_t *bytes; uint32_t size; TraitMask traits; float resonance; float stability; uint32_t lineage_id; bool sealed; uint32_t mutation_count; } MemoryRegion;
typedef struct { HandleId dst; HandleId src; uint32_t tag; uint8_t *data; uint32_t data_len; } Message;
typedef struct { uint8_t family_id; uint8_t sub_id; uint8_t mode; uint8_t opclass; uint16_t opcode_local; } GlyphInstr;
typedef enum { EXT_NONE = 0, EXT_STORE = 1, EXT_CMP_PROFILE = 2, EXT_TRAITS = 3, EXT_MISC = 4 } ExtKind;
typedef struct { ExtKind kind; union { struct { uint32_t size; uint32_t integrity; TraitMask traits; } store; struct { uint32_t profile_id; HandleId dst_handle; } cmp_profile; struct { TraitMask mask; } trait; struct { uint32_t a; uint32_t b; } misc; } data; } ExtSlot;
#define MODE_USER 0
#define MODE_KERNEL 1
#define MODE_SYSTEM 2
#define MODE_RESERVED 3
#define OPCLASS_MEM 0
#define OPCLASS_CMP 1
#define OPCLASS_CTL 2
#define OPCLASS_IPC 3
#define OPCLASS_SYS 4
#define OPCLASS_APP 5
#define OPCLASS_EXT 6
#define OPCLASS_EXT2 7
#define FAMILY_MEM_START 0
#define FAMILY_MEM_END 7
#define FAMILY_CMP_START 8
#define FAMILY_CMP_END 15
#define FAMILY_CTL_START 16
#define FAMILY_CTL_END 23
#define FAMILY_IPC_START 24
#define FAMILY_IPC_END 31
#define FAMILY_SYS_START 32
#define FAMILY_SYS_END 47
#define FAMILY_APP_START 48
#define FAMILY_APP_END 63
#define GOBJ_MAGIC "GLYPHOBJ"
#define GOBJ_VERSION 1
typedef struct { char magic[8]; uint32_t version; uint32_t code_len; uint32_t ext_len; } GobjHeader;
#define MAX_HANDLES 256
#define MAX_REGIONS 64
#define MAX_MAILBOX 128
#define MAX_EXT_SLOTS 1024
#define MAX_CODE_SIZE 65536
#define MAX_CALL_DEPTH 64
#endif