#include #include #ifdef __CFORALL__ extern "C" { #endif #if ! defined(__CFA_INVOKE_PRIVATE__) #ifndef _INVOKE_H_ #define _INVOKE_H_ #define OFFSET_OF(type, field) ((intptr_t)( &((type*)0)->field)) #define VPTR_OFFSET(type, vptr, field) (OFFSET_OF(type, field) - OFFSET_OF(type, vptr)) struct coVtable_t { void (*main)(void*); intptr_t offset_coroutine; intptr_t offset_object; }; typedef struct coVtable_t* covptr_t; static inline struct coroutine* get_coroutine(covptr_t* vthis) { return (struct coroutine*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_coroutine) ); } static inline void* get_object(covptr_t* vthis) { return (void*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_object) ); } struct coStack_t { unsigned int size; // size of stack void *storage; // pointer to stack void *limit; // stack grows towards stack limit void *base; // base of stack void *context; // address of cfa_context_t void *top; // address of top of storage bool userStack; }; enum coroutine_state { Start, Inactive, Active, Halt }; struct coroutine { struct coStack_t stack; const char *name; // textual name for coroutine/task, initialized by uC++ generated code int errno_; // copy of global UNIX variable errno enum coroutine_state state; // current execution status for coroutine bool notHalted; // indicate if execuation state is not halted struct coroutine *starter; // first coroutine to resume this one struct coroutine *last; // last coroutine to resume this one }; void invokeCoroutine(covptr_t* this); void startCoroutine(covptr_t* this, void (*invoke)(covptr_t*)); #endif //_INVOKE_H_ #else //! defined(__CFA_INVOKE_PRIVATE__) #ifndef _INVOKE_PRIVATE_H_ #define _INVOKE_PRIVATE_H_ struct machine_context_t { void *SP; void *FP; void *PC; }; // assembler routines that performs the context switch extern void coInvokeStub( void ); void CtxSwitch( void *from, void *to ) asm ("CtxSwitch"); #endif //_INVOKE_PRIVATE_H_ #endif //! defined(__CFA_INVOKE_PRIVATE__) #ifdef __CFORALL__ } #endif