From 9fec172b3af8d13ceda608dfe2bdd5bcb94af604 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 16 Mar 2026 11:10:01 +0100 Subject: [PATCH] Mon 16 Mar 11:09:06 CET 2026 --- src/mem.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/mem.h diff --git a/src/mem.h b/src/mem.h new file mode 100644 index 0000000..66736de --- /dev/null +++ b/src/mem.h @@ -0,0 +1,55 @@ +#ifndef _MEM_H +#define _MEM_H + +/* + Code segment occupied by a task, required for cleanup on task end and code memory partitioning. + Forked tasks inherit segment from parent task. + A task can use more than one segment, e.g., there is only one context (task) + which handles the main programm and single line statements modifying the state of the task (and heap). +*/ +typedef struct { + int8_t used; + address_t bottom; // start + address_t top; // end + index_t refcount; // contains function and procedures referenced by heap; + // no disposal of segment allowed if > 0 +#if PROFILE>0 + index_t ntoken; + unsigned long micros; +#endif +} segment_t; + + +/* + Shared data and code memory + ------- + heap | + v + + ^ + code | + -----. +*/ + +typedef struct { + unsigned char *data; // entire heap + int size; + int top; // top of heap, growing down + int bottom; // top of code, growing up + segment_t segments[MAXTASKS]; // parts of the heap + segment_t *segment; // current segment (used by code compiler) +} mem_t; + + +#define ADDRESS(M,addr) *(address_t*)(&M->data[addr]) +#define CHAR(M,addr) M->data[addr] +#define INDEX(M,addr) *(index_t*)(&M->data[addr]) +#define NUMBER(M,addr) *(number_t*)(&M->data[addr]) +#define CHECKHEAP(M,addr) (addr>M->top && addrsize) + +void MemInit(mem_t *M,int size,unsigned char *data); +void MemReset(mem_t *M); +segment_t *AllocSegment(mem_t *M); +int ReleaseSegment(mem_t *M, segment_t *S); + +#endif