Ignore:
File:
1 edited

Legend:

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

    rdeca0f5 r212c2187  
    2929extern void __suspend_internal(void);
    3030extern void __leave_coroutine( struct coroutine_desc * );
    31 extern void __finish_creation( struct thread_desc * );
     31extern void __finish_creation( struct coroutine_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 );
    4850
    4951        main( this );
     
    9193        // First suspend, once the thread arrives here,
    9294        // the function pointer to main can be invalidated without risk
    93         __finish_creation( thrd );
     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;
    9499
    95100        // Officially start the thread by enabling preemption
     
    117122        void (*invoke)(void *)
    118123) {
    119         struct coroutine_desc * cor = get_coroutine( this );
    120         struct __stack_t * stack = cor->stack.storage;
     124        struct coStack_t* stack = &get_coroutine( this )->stack;
    121125
    122126#if defined( __i386 )
     
    124128        struct FakeStack {
    125129            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)
    126132            void *rturn;                          // where to go on return from uSwitch
    127133            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     
    130136        };
    131137
    132         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    133         cor->context.FP = NULL;         // terminate stack with NULL fp
     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
    134140
    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;
     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
    140146
    141147#elif defined( __x86_64 )
     
    143149        struct FakeStack {
    144150                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)
    145153                void *rturn;                        // where to go on return from uSwitch
    146154                void *dummyReturn;                  // NULL return address to provide proper alignment
    147155        };
    148156
    149         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    150         cor->context.FP = NULL;         // terminate stack with NULL fp
     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
    151159
    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;
     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
    158166
    159167#elif defined( __ARM_ARCH )
     
    165173        };
    166174
    167         cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
    168         cor->context.FP = NULL;
     175        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     176        ((struct machine_context_t *)stack->context)->FP = NULL;
    169177
    170         struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
     178        struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP;
    171179
    172180        fs->intRegs[8] = CtxInvokeStub;
Note: See TracChangeset for help on using the changeset viewer.