25 lines
1.9 KiB
C
25 lines
1.9 KiB
C
#ifndef GLYPH_KERNEL_H
|
|
#define GLYPH_KERNEL_H
|
|
#include "../common/glyph_types.h"
|
|
#include "../common/glyph_decode.h"
|
|
#include "../hal/hal.h"
|
|
#define KERNEL_MAX_GVMS 64
|
|
#define KERNEL_TIMESLICE 100
|
|
#define KERNEL_IPC_QUEUE_SIZE 256
|
|
typedef enum { GVM_STATE_EMPTY = 0, GVM_STATE_READY = 1, GVM_STATE_RUNNING = 2, GVM_STATE_BLOCKED = 3, GVM_STATE_DEAD = 4 } GVM_State;
|
|
typedef enum { SCHED_ROUND_ROBIN = 0, SCHED_PRIORITY = 1, SCHED_RESONANCE = 2 } SchedPolicy;
|
|
typedef struct { uint32_t id; GVM_State state; int32_t priority; float resonance_score; uint32_t parent_id; TraitMask personality; uint32_t lineage_id; uint32_t pc; uint32_t *code; uint32_t code_len; int32_t regs[256]; uint32_t call_stack[MAX_CALL_DEPTH]; uint32_t call_depth; int32_t cmp_flag; uint8_t current_mode; bool trace_enabled; uint64_t tick; Handle handles[MAX_HANDLES]; uint32_t handle_count; MemoryRegion regions[MAX_REGIONS]; uint32_t region_count; ExtSlot *ext_ops; uint32_t ext_ops_count; uint64_t total_instructions; uint64_t total_ticks; } GVM;
|
|
typedef struct { uint32_t src_gvm; uint32_t dst_gvm; uint32_t tag; int32_t payload[4]; } KernelMessage;
|
|
typedef struct { GVM gvms[KERNEL_MAX_GVMS]; uint32_t gvm_count; uint32_t next_gvm_id; SchedPolicy sched_policy; uint32_t current_gvm; uint32_t timeslice; KernelMessage ipc_queue[KERNEL_IPC_QUEUE_SIZE]; uint32_t ipc_head; uint32_t ipc_tail; HAL_Context hal; uint64_t total_ticks; bool running; bool trace_enabled; } Kernel;
|
|
void kernel_init(Kernel *k);
|
|
void kernel_shutdown(Kernel *k);
|
|
int kernel_gvm_create(Kernel *k, uint32_t *code, uint32_t code_len, ExtSlot *ext_ops, uint32_t ext_ops_count);
|
|
GVM *kernel_gvm_get(Kernel *k, uint32_t gvm_id);
|
|
int kernel_load_gobj(Kernel *k, const char *path);
|
|
void kernel_set_policy(Kernel *k, SchedPolicy policy);
|
|
void kernel_set_timeslice(Kernel *k, uint32_t instructions);
|
|
uint32_t kernel_schedule_next(Kernel *k);
|
|
void kernel_run(Kernel *k);
|
|
uint32_t kernel_exec_timeslice(Kernel *k, uint32_t gvm_idx);
|
|
#endif
|