Ignore:
File:
1 edited

Legend:

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

    rb78129a r76e069f  
    2828
    2929extern void __suspend_internal(void);
    30 extern void __leave_coroutine( struct coroutine_desc * );
    31 extern void __finish_creation( struct thread_desc * );
     30extern void __leave_coroutine(void);
     31extern void __finish_creation(void);
    3232extern void __leave_thread_monitor( struct thread_desc * this );
    3333extern void disable_interrupts();
     
    4747        cor->state = Active;
    4848
     49        enable_interrupts( __cfaabi_dbg_ctx );
     50
    4951        main( this );
    5052
    5153        //Final suspend, should never return
    52         __leave_coroutine( cor );
     54        __leave_coroutine();
    5355        __cabi_abort( "Resumed dead coroutine" );
    5456}
     
    6062        __attribute((__unused__)) struct _Unwind_Exception * unwind_exception,
    6163        __attribute((__unused__)) struct _Unwind_Context * context,
    62         void * param
     64        __attribute((__unused__)) void * param
    6365) {
    6466        if( actions & _UA_END_OF_STACK  ) {
    6567                // We finished unwinding the coroutine,
    6668                // leave it
    67                 __leave_coroutine( param );
     69                __leave_coroutine();
    6870                __cabi_abort( "Resumed dead coroutine" );
    6971        }
     
    7375}
    7476
    75 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) __attribute__ ((__noreturn__));
    76 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) {
    77         _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, cor );
     77void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage) __attribute__ ((__noreturn__));
     78void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage) {
     79        _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, NULL );
    7880        printf("UNWIND ERROR %d after force unwind\n", ret);
    7981        abort();
     
    8688        void *this
    8789) {
     90        // First suspend, once the thread arrives here,
     91        // the function pointer to main can be invalidated without risk
     92        __finish_creation();
     93
    8894        // Fetch the thread handle from the user defined thread structure
    8995        struct thread_desc* thrd = get_thread( this );
    90 
    91         // First suspend, once the thread arrives here,
    92         // the function pointer to main can be invalidated without risk
    93         __finish_creation( thrd );
     96        thrd->self_cor.last = NULL;
    9497
    9598        // Officially start the thread by enabling preemption
     
    117120        void (*invoke)(void *)
    118121) {
    119         struct coroutine_desc * cor = get_coroutine( this );
    120         struct __stack_t * stack = cor->stack.storage;
     122        struct coStack_t* stack = &get_coroutine( this )->stack;
    121123
    122124#if defined( __i386 )
    123125
    124126        struct FakeStack {
    125             void *fixedRegisters[3];              // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
     127            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
     128            uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
     129            uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
    126130            void *rturn;                          // where to go on return from uSwitch
    127             void *dummyReturn;                    // fake return compiler would have pushed on call to uInvoke
    128             void *argument[3];                    // for 16-byte ABI, 16-byte alignment starts here
    129             void *padding;                        // padding to force 16-byte alignment, as "base" is 16-byte aligned
     131            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     132            void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
     133            void *padding;                              // padding to force 16-byte alignment, as "base" is 16-byte aligned
    130134        };
    131135
    132         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    133         cor->context.FP = NULL;         // terminate stack with NULL fp
     136        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     137        ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
    134138
    135         struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
    136 
    137         fs->dummyReturn = NULL;
    138         fs->argument[0] = this;     // argument to invoke
    139         fs->rturn = invoke;
     139        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
     140        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
     141        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
     142        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     143        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    140144
    141145#elif defined( __x86_64 )
     
    143147        struct FakeStack {
    144148                void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
     149                uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
     150                uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
    145151                void *rturn;                        // where to go on return from uSwitch
    146152                void *dummyReturn;                  // NULL return address to provide proper alignment
    147153        };
    148154
    149         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    150         cor->context.FP = NULL;         // terminate stack with NULL fp
     155        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     156        ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
    151157
    152         struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
    153 
    154         fs->dummyReturn = NULL;
    155         fs->rturn = CtxInvokeStub;
    156         fs->fixedRegisters[0] = this;
    157         fs->fixedRegisters[1] = invoke;
     158        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
     159        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub;
     160        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;
     161        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
     162        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     163        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    158164
    159165#elif defined( __ARM_ARCH )
     
    165171        };
    166172
    167         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    168         cor->context.FP = NULL;
     173        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     174        ((struct machine_context_t *)stack->context)->FP = NULL;
    169175
    170         struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
     176        struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP;
    171177
    172178        fs->intRegs[8] = CtxInvokeStub;
Note: See TracChangeset for help on using the changeset viewer.