/** * Declaration of the entry point functions used by a new context */ typedef void (CtxFunc)(void *ptr); /** * CPU Context declaration */ enum CtxState {CtxInit, CtxOpen, CtxRunning, CtxClose} ; struct CPUCtx { unsigned int magic; /* Magic word allowing struct init check */ enum CtxState status; /* is the context ready to use ? */ CtxFunc *entryFunc; /* address of the first called function */ void *entryArgs; /* address of the associated arguments */ unsigned char *savedESP; /* current intel x86 stack pointer */ unsigned char *savedEBP; /* current intel x86 base pointer */ unsigned char *stack; /* address for the linked stack */ struct CPUCtx *next; /* next Context */ } ; int yield(); /** * */ void initMainCtx( struct CPUCtx *theCtx /* the "main" context */) ; /** * */ void openCtx( struct CPUCtx *theCtx, /* the context */ int stackSize, /* size (in byte) of the associated stack */ CtxFunc *fct, /* entry point for this context */ void *arg) ; /* starting arguments */ /** * switch from oldCtx context to newCtx context */ volatile int switchToCtx(struct CPUCtx *newCtx) ;