#pragma once #include "stdint.h" #define OPC_MAGIC 0x0143504F /* 'O', 'P', 'C', 0x01 */ #define OPC_ARCH_X86_64 0x8664 #define OPC_VERSION_1 1 /* Capability flags for OPC binaries */ #define OPC_CAP_KERNEL_CTRL (1 << 0) #define OPC_CAP_UART (1 << 1) #define OPC_CAP_NET (1 << 2) #define OPC_CAP_FB (1 << 3) #define OPC_CAP_NOTIFY (1 << 4) #define OPC_CAP_ALL 0xFFFFFFFF /* Segment flags */ #define OPC_SEG_X (1 << 0) /* Executable */ #define OPC_SEG_W (1 << 1) /* Writable */ #define OPC_SEG_R (1 << 2) /* Readable */ #define OPC_SEG_TYPE_LOAD 1 #ifdef __cplusplus extern "C" { #endif typedef struct opc_header { uint32_t magic; /* OPC_MAGIC ("OPC\x01") */ uint16_t version; /* OPC_VERSION_1 */ uint16_t arch; /* OPC_ARCH_X86_64 */ uint64_t entry_rip; /* Virtual address of entry point */ uint64_t stack_size; /* Required user stack size (bytes, e.g. 65536) */ uint32_t caps_mask; /* Required capability bitmask */ uint8_t preferred_core; /* Preferred CPU core (0..3, or 0xFF = any) */ uint8_t num_segments; /* Number of opc_segment_t headers following */ uint16_t reserved; /* Alignment padding */ } __attribute__((packed)) opc_header_t; typedef struct opc_segment { uint32_t seg_type; /* OPC_SEG_TYPE_LOAD */ uint32_t flags; /* OPC_SEG_R | OPC_SEG_W | OPC_SEG_X */ uint64_t file_offset; /* Offset within the .opc file */ uint64_t vaddr; /* Target virtual address */ uint64_t filesz; /* Size in file (bytes) */ uint64_t memsz; /* Size in memory (bytes, memsz >= filesz, rest is BSS) */ uint64_t align; /* Alignment requirement (usually 4096) */ } __attribute__((packed)) opc_segment_t; #ifdef __cplusplus } #endif