Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.h

    rdeca0f5 r212c2187  
    6262        #endif
    6363
    64         struct __stack_context_t {
    65                 void * SP;
    66                 void * FP;
    67         };
    68 
    69         // low adresses  :           +----------------------+ <- start of allocation
    70         //                           |  optional guard page |
    71         //                           +----------------------+ <- __stack_t.limit
    72         //                           |                      |
    73         //                           |       /\ /\ /\       |
    74         //                           |       || || ||       |
    75         //                           |                      |
    76         //                           |    program  stack    |
    77         //                           |                      |
    78         // __stack_info_t.storage -> +----------------------+ <- __stack_t.base
    79         //                           |      __stack_t       |
    80         // high adresses :           +----------------------+ <- end of allocation
    81 
    82         struct __stack_t {
    83                 // stack grows towards stack limit
    84                 void * limit;
    85 
    86                 // base of stack
    87                 void * base;
    88         };
    89 
    90         struct __stack_info_t {
    91                 // pointer to stack
    92                 struct __stack_t * storage;
     64        struct coStack_t {
     65                size_t size;                                                                    // size of stack
     66                void * storage;                                                                 // pointer to stack
     67                void * limit;                                                                   // stack grows towards stack limit
     68                void * base;                                                                    // base of stack
     69                void * context;                                                                 // address of cfa_context_t
     70                void * top;                                                                             // address of top of storage
     71                bool userStack;                                                                 // whether or not the user allocated the stack
    9372        };
    9473
     
    9675
    9776        struct coroutine_desc {
    98                 // context that is switch during a CtxSwitch
    99                 struct __stack_context_t context;
    100 
    10177                // stack information of the coroutine
    102                 struct __stack_info_t stack;
    103 
    104                 // textual name for coroutine/task
     78                struct coStack_t stack;
     79
     80                // textual name for coroutine/task, initialized by uC++ generated code
    10581                const char * name;
     82
     83                // copy of global UNIX variable errno
     84                int errno_;
    10685
    10786                // current execution status for coroutine
    10887                enum coroutine_state state;
    109 
    11088                // first coroutine to resume this one
    11189                struct coroutine_desc * starter;
     
    161139        struct thread_desc {
    162140                // Core threading fields
    163                 // context that is switch during a CtxSwitch
    164                 struct __stack_context_t context;
    165 
    166                 // current execution status for coroutine
    167                 enum coroutine_state state;
    168 
    169                 //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
    170 
    171141                // coroutine body used to store context
    172142                struct coroutine_desc  self_cor;
     
    260230        // assembler routines that performs the context switch
    261231        extern void CtxInvokeStub( void );
    262         extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     232        void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    263233        // void CtxStore ( void * this ) asm ("CtxStore");
    264234        // void CtxRet   ( void * dst  ) asm ("CtxRet");
     235
     236        #if   defined( __i386 )
     237        #define CtxGet( ctx ) __asm__ ( \
     238                        "movl %%esp,%0\n"   \
     239                        "movl %%ebp,%1\n"   \
     240                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     241        #elif defined( __x86_64 )
     242        #define CtxGet( ctx ) __asm__ ( \
     243                        "movq %%rsp,%0\n"   \
     244                        "movq %%rbp,%1\n"   \
     245                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     246        #elif defined( __ARM_ARCH )
     247        #define CtxGet( ctx ) __asm__ ( \
     248                        "mov %0,%%sp\n"   \
     249                        "mov %1,%%r11\n"   \
     250                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     251        #else
     252                #error unknown hardware architecture
     253        #endif
    265254
    266255#endif //_INVOKE_PRIVATE_H_
Note: See TracChangeset for help on using the changeset viewer.