… | |
… | |
115 | asm ( |
115 | asm ( |
116 | ".text\n" |
116 | ".text\n" |
117 | ".globl coro_transfer\n" |
117 | ".globl coro_transfer\n" |
118 | ".type coro_transfer, @function\n" |
118 | ".type coro_transfer, @function\n" |
119 | "coro_transfer:\n" |
119 | "coro_transfer:\n" |
|
|
120 | /* windows, of course, gives a shit on the amd64 ABI and uses different registers */ |
|
|
121 | /* http://blogs.msdn.com/freik/archive/2005/03/17/398200.aspx */ |
120 | #if __amd64 |
122 | #if __amd64 |
121 | #define NUM_SAVED 6 |
123 | #define NUM_SAVED 6 |
122 | "\tpush %rbp\n" |
124 | "\tpush %rbp\n" |
123 | "\tpush %rbx\n" |
125 | "\tpush %rbx\n" |
124 | "\tpush %r12\n" |
126 | "\tpush %r12\n" |
125 | "\tpush %r13\n" |
127 | "\tpush %r13\n" |
126 | "\tpush %r14\n" |
128 | "\tpush %r14\n" |
127 | "\tpush %r15\n" |
129 | "\tpush %r15\n" |
|
|
130 | #if CORO_WIN_TIB |
|
|
131 | "\tpush %gs:0x0\n" |
|
|
132 | "\tpush %gs:0x8\n" |
|
|
133 | "\tpush %gs:0xc\n" |
|
|
134 | #endif |
128 | "\tmov %rsp, (%rdi)\n" |
135 | "\tmov %rsp, (%rdi)\n" |
129 | "\tmov (%rsi), %rsp\n" |
136 | "\tmov (%rsi), %rsp\n" |
|
|
137 | #if CORO_WIN_TIB |
|
|
138 | "\tpop %gs:0xc\n" |
|
|
139 | "\tpop %gs:0x8\n" |
|
|
140 | "\tpop %gs:0x0\n" |
|
|
141 | #endif |
130 | "\tpop %r15\n" |
142 | "\tpop %r15\n" |
131 | "\tpop %r14\n" |
143 | "\tpop %r14\n" |
132 | "\tpop %r13\n" |
144 | "\tpop %r13\n" |
133 | "\tpop %r12\n" |
145 | "\tpop %r12\n" |
134 | "\tpop %rbx\n" |
146 | "\tpop %rbx\n" |
… | |
… | |
137 | #define NUM_SAVED 4 |
149 | #define NUM_SAVED 4 |
138 | "\tpush %ebp\n" |
150 | "\tpush %ebp\n" |
139 | "\tpush %ebx\n" |
151 | "\tpush %ebx\n" |
140 | "\tpush %esi\n" |
152 | "\tpush %esi\n" |
141 | "\tpush %edi\n" |
153 | "\tpush %edi\n" |
|
|
154 | #if CORO_WIN_TIB |
|
|
155 | "\tpush %fs:0\n" |
|
|
156 | "\tpush %fs:4\n" |
|
|
157 | "\tpush %fs:8\n" |
|
|
158 | #endif |
142 | "\tmov %esp, (%eax)\n" |
159 | "\tmov %esp, (%eax)\n" |
143 | "\tmov (%edx), %esp\n" |
160 | "\tmov (%edx), %esp\n" |
|
|
161 | #if CORO_WIN_TIB |
|
|
162 | "\tpop %fs:8\n" |
|
|
163 | "\tpop %fs:4\n" |
|
|
164 | "\tpop %fs:0\n" |
|
|
165 | #endif |
144 | "\tpop %edi\n" |
166 | "\tpop %edi\n" |
145 | "\tpop %esi\n" |
167 | "\tpop %esi\n" |
146 | "\tpop %ebx\n" |
168 | "\tpop %ebx\n" |
147 | "\tpop %ebp\n" |
169 | "\tpop %ebp\n" |
148 | #else |
170 | #else |
… | |
… | |
275 | # elif CORO_ASM |
297 | # elif CORO_ASM |
276 | |
298 | |
277 | ctx->sp = (void **)(ssize + (char *)sptr); |
299 | ctx->sp = (void **)(ssize + (char *)sptr); |
278 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
300 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
279 | *--ctx->sp = (void *)coro_init; |
301 | *--ctx->sp = (void *)coro_init; |
|
|
302 | |
|
|
303 | #if CORO_WIN_TIB |
|
|
304 | *--ctx->sp = 0; /* ExceptionList */ |
|
|
305 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
|
|
306 | *--ctx->sp = sptr; /* StackLimit */ |
|
|
307 | #endif |
|
|
308 | |
280 | ctx->sp -= NUM_SAVED; |
309 | ctx->sp -= NUM_SAVED; |
281 | |
310 | |
282 | # elif CORO_UCONTEXT |
311 | # elif CORO_UCONTEXT |
283 | |
312 | |
284 | getcontext (&(ctx->uc)); |
313 | getcontext (&(ctx->uc)); |
… | |
… | |
373 | args.arg = arg; |
402 | args.arg = arg; |
374 | args.self = ctx; |
403 | args.self = ctx; |
375 | args.main = &nctx; |
404 | args.main = &nctx; |
376 | |
405 | |
377 | pthread_attr_init (&attr); |
406 | pthread_attr_init (&attr); |
|
|
407 | #if __UCLIBC__ |
|
|
408 | pthread_attr_setstacksize (&attr, (size_t)ssize); |
|
|
409 | #else |
378 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
410 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
|
|
411 | #endif |
379 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
412 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
380 | pthread_create (&ctx->id, &attr, coro_init, &args); |
413 | pthread_create (&ctx->id, &attr, coro_init, &args); |
381 | |
414 | |
382 | coro_transfer (args.main, args.self); |
415 | coro_transfer (args.main, args.self); |
383 | } |
416 | } |