#ifndef CODE_WINDOW_H #define CODE_WINDOW_H #include #include #define CW_SLOTS 4u #define CW_CAPACITY 12u #define CW_OK 0 #define CW_CONFLICT (-1) #define CW_INACTIVE (-2) #define CW_PROGRAM (-3) #define CW_SYNTAX (-4) #define CW_EXECUTION (-5) #define CW_ADAPTER (-6) typedef struct { uint16_t data[CW_CAPACITY]; uint16_t execution[CW_CAPACITY]; unsigned active; unsigned length; uint64_t generation; } CodeSlot; typedef struct { uint64_t serial; uint64_t installs; uint64_t patches; uint64_t drops; uint64_t executions; uint64_t writes; uint64_t sync_calls; uint64_t sync_words; uint64_t rejected; } CodeCounters; typedef struct { CodeSlot slots[CW_SLOTS]; CodeCounters counts; } CodeWorkbench; typedef struct { int rc; uint32_t value; unsigned retired; } CodeResult; typedef enum { CW_INSTALL = 0, CW_PATCH = 1, CW_DROP = 2 } Publication; void store_reset(CodeWorkbench *work); int store_write(CodeWorkbench *work, unsigned slot, unsigned first, const uint16_t *words, unsigned count); int store_sync(CodeWorkbench *work, unsigned slot, unsigned first, unsigned end); int store_publish(CodeWorkbench *work, unsigned slot, unsigned length, Publication kind); int instruction_valid(uint16_t word, int last); int program_valid(const uint16_t *words, unsigned count); CodeResult interpret(const uint16_t *words, unsigned count, uint32_t input); CodeResult window_install(CodeWorkbench *work, unsigned slot, const uint16_t *words, unsigned count); CodeResult window_patch(CodeWorkbench *work, unsigned slot, uint64_t expected, unsigned first, const uint16_t *words, unsigned count); CodeResult window_drop(CodeWorkbench *work, unsigned slot, uint64_t expected); CodeResult window_execute(CodeWorkbench *work, unsigned slot, uint32_t input); void observe_result(uint64_t sequence, CodeResult result); void observe_state(uint64_t sequence, const CodeWorkbench *work); #endif