Mon 16 Mar 11:09:06 CET 2026
This commit is contained in:
parent
a21c6e22eb
commit
215017e547
99
src/context.c
Normal file
99
src/context.c
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include "config.h"
|
||||
#include "types.h"
|
||||
#include "error.h"
|
||||
#include "lexer.h"
|
||||
#include "ops.h"
|
||||
#include "mem.h"
|
||||
#include "stack.h"
|
||||
#include "reg.h"
|
||||
#include "utils.h"
|
||||
#include "vm.h"
|
||||
#include "printf.h"
|
||||
#include "ccall.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
#include "debug.h"
|
||||
#include "log.h"
|
||||
|
||||
context_t *Context[MAXTASKS];
|
||||
int ContextTop=0;
|
||||
|
||||
context_t *ContextAllocate() {
|
||||
context_t *c = (context_t *)MEMALLOC(sizeof(context_t));
|
||||
MEMSET(c,0,sizeof(context_t));
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
Initialize one context
|
||||
*/
|
||||
context_t *ContextInit(context_t* C, mem_t *M,stack_t *DS, stack_t *FS, reg_t *R) {
|
||||
int index=ContextTop;
|
||||
#if DEBUG > 0
|
||||
log(LOGDEBUG1,"ContextInit(%d)\n",index);
|
||||
#endif
|
||||
if (!C) C=(context_t*)ContextAllocate();
|
||||
Context[index]=C;
|
||||
C->index=index;
|
||||
if (M) {
|
||||
C->M=M;
|
||||
} else {
|
||||
|
||||
}
|
||||
if (DS) {
|
||||
C->DS=DS;
|
||||
} else if (!C->DS) {
|
||||
C->DS=StackAllocate(DEFSTACKSIZE);
|
||||
}
|
||||
if (FS) {
|
||||
C->FS=FS;
|
||||
} else if (!C->FS) {
|
||||
C->FS=StackAllocate(DEFSTACKSIZE);
|
||||
}
|
||||
if (R) {
|
||||
C->R=R;
|
||||
} else if (!C->R) {
|
||||
C->R=RegAllocate();
|
||||
}
|
||||
RegInit(C->R);
|
||||
R->context=index; // assign context id to register set
|
||||
C->next=NULL;
|
||||
if (index>0) {
|
||||
Context[index-1]->next=C;
|
||||
}
|
||||
ContextTop++;
|
||||
return C;
|
||||
}
|
||||
|
||||
/*
|
||||
Reset entire context (Stack, Code segment, release events, ...)
|
||||
*/
|
||||
int ContextReset(context_t *c) {
|
||||
#if DEBUG > 0
|
||||
log(LOGDEBUG1,"ContextReset(%d)\n",CONTEXTID(c));
|
||||
#endif
|
||||
if (c->S) ReleaseSegment(c->M,c->S);
|
||||
c->S=NULL;
|
||||
StackReset(c->DS);
|
||||
StackReset(c->FS);
|
||||
RegInit(c->R);
|
||||
c->R->context=CONTEXTID(c);
|
||||
c->R->state=PIDLE;
|
||||
c->evmask=0;
|
||||
}
|
||||
|
||||
/*
|
||||
new
|
||||
*/
|
||||
void ContextResetAll(context_t *c0) {
|
||||
if (c0==NULL) c0=Context[0];
|
||||
if (!ContextTop) return;
|
||||
context_t *c=c0;
|
||||
mem_t *M=c->M;
|
||||
while(c) {
|
||||
ContextReset(c);
|
||||
c=c->next;
|
||||
}
|
||||
MemReset(M);
|
||||
EventInit(1);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user