- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.c
rdeca0f5 r212c2187 29 29 extern void __suspend_internal(void); 30 30 extern void __leave_coroutine( struct coroutine_desc * ); 31 extern void __finish_creation( struct thread_desc * );31 extern void __finish_creation( struct coroutine_desc * ); 32 32 extern void __leave_thread_monitor( struct thread_desc * this ); 33 33 extern void disable_interrupts(); … … 46 46 47 47 cor->state = Active; 48 49 enable_interrupts( __cfaabi_dbg_ctx ); 48 50 49 51 main( this ); … … 91 93 // First suspend, once the thread arrives here, 92 94 // 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; 94 99 95 100 // Officially start the thread by enabling preemption … … 117 122 void (*invoke)(void *) 118 123 ) { 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; 121 125 122 126 #if defined( __i386 ) … … 124 128 struct FakeStack { 125 129 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) 126 132 void *rturn; // where to go on return from uSwitch 127 133 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke … … 130 136 }; 131 137 132 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );133 cor->context.FP = NULL; // terminate stack with NULL fp138 ((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 134 140 135 struct FakeStack *fs = (struct FakeStack *)cor->context.SP;136 137 fs->dummyReturn = NULL;138 fs->argument[0] = this; // argument to invoke139 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 140 146 141 147 #elif defined( __x86_64 ) … … 143 149 struct FakeStack { 144 150 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) 145 153 void *rturn; // where to go on return from uSwitch 146 154 void *dummyReturn; // NULL return address to provide proper alignment 147 155 }; 148 156 149 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );150 cor->context.FP = NULL; // terminate stack with NULL fp157 ((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 151 159 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 158 166 159 167 #elif defined( __ARM_ARCH ) … … 165 173 }; 166 174 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; 169 177 170 struct FakeStack *fs = (struct FakeStack *) cor->context.SP;178 struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP; 171 179 172 180 fs->intRegs[8] = CtxInvokeStub;
Note: See TracChangeset
for help on using the changeset viewer.