Ignore:
File:
1 edited

Legend:

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

    r212c2187 rdeca0f5  
    2929extern void __suspend_internal(void);
    3030extern void __leave_coroutine( struct coroutine_desc * );
    31 extern void __finish_creation( struct coroutine_desc * );
     31extern void __finish_creation( struct thread_desc * );
    3232extern void __leave_thread_monitor( struct thread_desc * this );
    3333extern void disable_interrupts();
     
    4646
    4747        cor->state = Active;
    48 
    49         enable_interrupts( __cfaabi_dbg_ctx );
    5048
    5149        main( this );
     
    9391        // First suspend, once the thread arrives here,
    9492        // the function pointer to main can be invalidated without risk
    95         __finish_creation(&thrd->self_cor);
    96 
    97         // Restore the last to NULL, we clobbered because of the thunk problem
    98         thrd->self_cor.last = NULL;
     93        __finish_creation( thrd );
    9994
    10095        // Officially start the thread by enabling preemption
     
    122117        void (*invoke)(void *)
    123118) {
    124         struct coStack_t* stack = &get_coroutine( this )->stack;
     119        struct coroutine_desc * cor = get_coroutine( this );
     120        struct __stack_t * stack = cor->stack.storage;
    125121
    126122#if defined( __i386 )
     
    128124        struct FakeStack {
    129125            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    130             uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
    131             uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
    132126            void *rturn;                          // where to go on return from uSwitch
    133127            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     
    136130        };
    137131
    138         ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
    139         ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
     132        cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
     133        cor->context.FP = NULL;         // terminate stack with NULL fp
    140134
    141         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
    142         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    143         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
    144         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    145         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     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;
    146140
    147141#elif defined( __x86_64 )
     
    149143        struct FakeStack {
    150144                void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
    151                 uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
    152                 uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
    153145                void *rturn;                        // where to go on return from uSwitch
    154146                void *dummyReturn;                  // NULL return address to provide proper alignment
    155147        };
    156148
    157         ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
    158         ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
     149        cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
     150        cor->context.FP = NULL;         // terminate stack with NULL fp
    159151
    160         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
    161         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub;
    162         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;
    163         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
    164         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    165         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     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;
    166158
    167159#elif defined( __ARM_ARCH )
     
    173165        };
    174166
    175         ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
    176         ((struct machine_context_t *)stack->context)->FP = NULL;
     167        cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
     168        cor->context.FP = NULL;
    177169
    178         struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP;
     170        struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
    179171
    180172        fs->intRegs[8] = CtxInvokeStub;
Note: See TracChangeset for help on using the changeset viewer.