… | |
… | |
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" |
128 | #if CORO_WIN_TIB |
130 | #if CORO_WIN_TIB |
129 | "\tpush %fs:0xc\n" |
|
|
130 | "\tpush %fs:0x8\n" |
|
|
131 | "\tpush %fs:0x0\n" |
131 | "\tpush %gs:0x0\n" |
|
|
132 | "\tpush %gs:0x8\n" |
|
|
133 | "\tpush %gs:0xc\n" |
132 | #endif |
134 | #endif |
133 | "\tmov %rsp, (%rdi)\n" |
135 | "\tmov %rsp, (%rdi)\n" |
134 | "\tmov (%rsi), %rsp\n" |
136 | "\tmov (%rsi), %rsp\n" |
135 | #if CORO_WIN_TIB |
137 | #if CORO_WIN_TIB |
136 | "\tpop %fs:0x0\n" |
|
|
137 | "\tpop %fs:0x8\n" |
|
|
138 | "\tpop %fs:0xc\n" |
138 | "\tpop %gs:0xc\n" |
|
|
139 | "\tpop %gs:0x8\n" |
|
|
140 | "\tpop %gs:0x0\n" |
139 | #endif |
141 | #endif |
140 | "\tpop %r15\n" |
142 | "\tpop %r15\n" |
141 | "\tpop %r14\n" |
143 | "\tpop %r14\n" |
142 | "\tpop %r13\n" |
144 | "\tpop %r13\n" |
143 | "\tpop %r12\n" |
145 | "\tpop %r12\n" |
… | |
… | |
148 | "\tpush %ebp\n" |
150 | "\tpush %ebp\n" |
149 | "\tpush %ebx\n" |
151 | "\tpush %ebx\n" |
150 | "\tpush %esi\n" |
152 | "\tpush %esi\n" |
151 | "\tpush %edi\n" |
153 | "\tpush %edi\n" |
152 | #if CORO_WIN_TIB |
154 | #if CORO_WIN_TIB |
|
|
155 | "\tpush %fs:0\n" |
|
|
156 | "\tpush %fs:4\n" |
153 | "\tpush %fs:8\n" |
157 | "\tpush %fs:8\n" |
154 | "\tpush %fs:4\n" |
|
|
155 | "\tpush %fs:0\n" |
|
|
156 | #endif |
158 | #endif |
157 | "\tmov %esp, (%eax)\n" |
159 | "\tmov %esp, (%eax)\n" |
158 | "\tmov (%edx), %esp\n" |
160 | "\tmov (%edx), %esp\n" |
159 | #if CORO_WIN_TIB |
161 | #if CORO_WIN_TIB |
|
|
162 | "\tpop %fs:8\n" |
|
|
163 | "\tpop %fs:4\n" |
160 | "\tpop %fs:0\n" |
164 | "\tpop %fs:0\n" |
161 | "\tpop %fs:4\n" |
|
|
162 | "\tpop %fs:8\n" |
|
|
163 | #endif |
165 | #endif |
164 | "\tpop %edi\n" |
166 | "\tpop %edi\n" |
165 | "\tpop %esi\n" |
167 | "\tpop %esi\n" |
166 | "\tpop %ebx\n" |
168 | "\tpop %ebx\n" |
167 | "\tpop %ebp\n" |
169 | "\tpop %ebp\n" |
… | |
… | |
295 | # elif CORO_ASM |
297 | # elif CORO_ASM |
296 | |
298 | |
297 | ctx->sp = (void **)(ssize + (char *)sptr); |
299 | ctx->sp = (void **)(ssize + (char *)sptr); |
298 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
300 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
299 | *--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 | |
300 | ctx->sp -= NUM_SAVED; |
309 | ctx->sp -= NUM_SAVED; |
301 | |
|
|
302 | #if CORO_WIN_TIB |
|
|
303 | *--ctx->sp = sptr; /* StackLimit */ |
|
|
304 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
|
|
305 | *--ctx->sp = 0; /* ExceptionList */ |
|
|
306 | #endif |
|
|
307 | |
310 | |
308 | # elif CORO_UCONTEXT |
311 | # elif CORO_UCONTEXT |
309 | |
312 | |
310 | getcontext (&(ctx->uc)); |
313 | getcontext (&(ctx->uc)); |
311 | |
314 | |
… | |
… | |
399 | args.arg = arg; |
402 | args.arg = arg; |
400 | args.self = ctx; |
403 | args.self = ctx; |
401 | args.main = &nctx; |
404 | args.main = &nctx; |
402 | |
405 | |
403 | pthread_attr_init (&attr); |
406 | pthread_attr_init (&attr); |
|
|
407 | #if __UCLIBC__ |
|
|
408 | pthread_attr_setstacksize (&attr, (size_t)ssize); |
|
|
409 | #else |
404 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
410 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
|
|
411 | #endif |
405 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
412 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
406 | pthread_create (&ctx->id, &attr, coro_init, &args); |
413 | pthread_create (&ctx->id, &attr, coro_init, &args); |
407 | |
414 | |
408 | coro_transfer (args.main, args.self); |
415 | coro_transfer (args.main, args.self); |
409 | } |
416 | } |