#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