… | |
… | |
88 | volatile void *arg = coro_init_arg; |
88 | volatile void *arg = coro_init_arg; |
89 | |
89 | |
90 | coro_transfer (new_coro, create_coro); |
90 | coro_transfer (new_coro, create_coro); |
91 | |
91 | |
92 | #if __GCC_HAVE_DWARF2_CFI_ASM && __amd64 |
92 | #if __GCC_HAVE_DWARF2_CFI_ASM && __amd64 |
|
|
93 | /*asm (".cfi_startproc");*/ |
93 | asm (".cfi_undefined rip"); |
94 | /*asm (".cfi_undefined rip");*/ |
94 | #endif |
95 | #endif |
95 | |
96 | |
96 | func ((void *)arg); |
97 | func ((void *)arg); |
|
|
98 | |
|
|
99 | #if __GCC_HAVE_DWARF2_CFI_ASM && __amd64 |
|
|
100 | /*asm (".cfi_endproc");*/ |
|
|
101 | #endif |
97 | |
102 | |
98 | /* the new coro returned. bad. just abort() for now */ |
103 | /* the new coro returned. bad. just abort() for now */ |
99 | abort (); |
104 | abort (); |
100 | } |
105 | } |
101 | |
106 | |
… | |
… | |
114 | } |
119 | } |
115 | |
120 | |
116 | # endif |
121 | # endif |
117 | |
122 | |
118 | # if CORO_ASM |
123 | # if CORO_ASM |
|
|
124 | |
|
|
125 | #if __arm__ && \ |
|
|
126 | (defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
|
|
127 | || defined __ARM_ARCH_7R__ || defined __ARM_ARCH_7M__ \ |
|
|
128 | || __ARM_ARCH == 7) |
|
|
129 | #define CORO_ARM 1 |
|
|
130 | #endif |
119 | |
131 | |
120 | #if _WIN32 || __CYGWIN__ |
132 | #if _WIN32 || __CYGWIN__ |
121 | #define CORO_WIN_TIB 1 |
133 | #define CORO_WIN_TIB 1 |
122 | #endif |
134 | #endif |
123 | |
135 | |
… | |
… | |
204 | "\tpopq %rbp\n" |
216 | "\tpopq %rbp\n" |
205 | #endif |
217 | #endif |
206 | "\tpopq %rcx\n" |
218 | "\tpopq %rcx\n" |
207 | "\tjmpq *%rcx\n" |
219 | "\tjmpq *%rcx\n" |
208 | |
220 | |
209 | #elif __i386 |
221 | #elif __i386__ |
210 | |
222 | |
211 | #define NUM_SAVED 4 |
223 | #define NUM_SAVED 4 |
212 | "\tpushl %ebp\n" |
224 | "\tpushl %ebp\n" |
213 | "\tpushl %ebx\n" |
225 | "\tpushl %ebx\n" |
214 | "\tpushl %esi\n" |
226 | "\tpushl %esi\n" |
… | |
… | |
232 | "\tpopl %ebx\n" |
244 | "\tpopl %ebx\n" |
233 | "\tpopl %ebp\n" |
245 | "\tpopl %ebp\n" |
234 | "\tpopl %ecx\n" |
246 | "\tpopl %ecx\n" |
235 | "\tjmpl *%ecx\n" |
247 | "\tjmpl *%ecx\n" |
236 | |
248 | |
|
|
249 | #elif CORO_ARM /* untested, what about thumb, neon, iwmmxt? */ |
|
|
250 | |
|
|
251 | #if __ARM_PCS_VFP |
|
|
252 | "\tvpush {d8-d15}\n" |
|
|
253 | #define NUM_SAVED (9 + 8 * 2) |
|
|
254 | #else |
|
|
255 | #define NUM_SAVED 9 |
|
|
256 | #endif |
|
|
257 | "\tpush {r4-r11,lr}\n" |
|
|
258 | "\tstr sp, [r0]\n" |
|
|
259 | "\tldr sp, [r1]\n" |
|
|
260 | "\tpop {r4-r11,lr}\n" |
|
|
261 | #if __ARM_PCS_VFP |
|
|
262 | "\tvpop {d8-d15}\n" |
|
|
263 | #endif |
|
|
264 | "\tmov r15, lr\n" |
|
|
265 | |
|
|
266 | #elif __mips__ && 0 /* untested, 32 bit only */ |
|
|
267 | |
|
|
268 | #define NUM_SAVED (12 + 8 * 2) |
|
|
269 | /* TODO: n64/o64, lw=>ld */ |
|
|
270 | |
|
|
271 | "\t.set nomips16\n" |
|
|
272 | "\t.frame $sp,112,$31\n" |
|
|
273 | #if __mips_soft_float |
|
|
274 | "\taddiu $sp,$sp,-44\n" |
|
|
275 | #else |
|
|
276 | "\taddiu $sp,$sp,-112\n" |
|
|
277 | "\ts.d $f30,88($sp)\n" |
|
|
278 | "\ts.d $f28,80($sp)\n" |
|
|
279 | "\ts.d $f26,72($sp)\n" |
|
|
280 | "\ts.d $f24,64($sp)\n" |
|
|
281 | "\ts.d $f22,56($sp)\n" |
|
|
282 | "\ts.d $f20,48($sp)\n" |
|
|
283 | #endif |
|
|
284 | "\tsw $28,40($sp)\n" |
|
|
285 | "\tsw $31,36($sp)\n" |
|
|
286 | "\tsw $fp,32($sp)\n" |
|
|
287 | "\tsw $23,28($sp)\n" |
|
|
288 | "\tsw $22,24($sp)\n" |
|
|
289 | "\tsw $21,20($sp)\n" |
|
|
290 | "\tsw $20,16($sp)\n" |
|
|
291 | "\tsw $19,12($sp)\n" |
|
|
292 | "\tsw $18,8($sp)\n" |
|
|
293 | "\tsw $17,4($sp)\n" |
|
|
294 | "\tsw $16,0($sp)\n" |
|
|
295 | "\tsw $sp,0($4)\n" |
|
|
296 | "\tlw $sp,0($5)\n" |
|
|
297 | #if !__mips_soft_float |
|
|
298 | "\tl.d $f30,88($sp)\n" |
|
|
299 | "\tl.d $f28,80($sp)\n" |
|
|
300 | "\tl.d $f26,72($sp)\n" |
|
|
301 | "\tl.d $f24,64($sp)\n" |
|
|
302 | "\tl.d $f22,56($sp)\n" |
|
|
303 | "\tl.d $f20,48($sp)\n" |
|
|
304 | #endif |
|
|
305 | "\tlw $28,40($sp)\n" |
|
|
306 | "\tlw $31,36($sp)\n" |
|
|
307 | "\tlw $fp,32($sp)\n" |
|
|
308 | "\tlw $23,28($sp)\n" |
|
|
309 | "\tlw $22,24($sp)\n" |
|
|
310 | "\tlw $21,20($sp)\n" |
|
|
311 | "\tlw $20,16($sp)\n" |
|
|
312 | "\tlw $19,12($sp)\n" |
|
|
313 | "\tlw $18,8($sp)\n" |
|
|
314 | "\tlw $17,4($sp)\n" |
|
|
315 | "\tlw $16,0($sp)\n" |
|
|
316 | "\tj $31\n" |
|
|
317 | #if __mips_soft_float |
|
|
318 | "\taddiu $sp,$sp,44\n" |
|
|
319 | #else |
|
|
320 | "\taddiu $sp,$sp,112\n" |
|
|
321 | #endif |
|
|
322 | |
237 | #else |
323 | #else |
238 | #error unsupported architecture |
324 | #error unsupported architecture |
239 | #endif |
325 | #endif |
240 | ); |
326 | ); |
241 | |
327 | |
… | |
… | |
311 | sigprocmask (SIG_SETMASK, &osig, 0); |
397 | sigprocmask (SIG_SETMASK, &osig, 0); |
312 | |
398 | |
313 | # elif CORO_LOSER |
399 | # elif CORO_LOSER |
314 | |
400 | |
315 | coro_setjmp (ctx->env); |
401 | coro_setjmp (ctx->env); |
316 | #if __CYGWIN__ && __i386 |
402 | #if __CYGWIN__ && __i386__ |
317 | ctx->env[8] = (long) coro_init; |
403 | ctx->env[8] = (long) coro_init; |
318 | ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long); |
404 | ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long); |
319 | #elif __CYGWIN__ && __x86_64 |
405 | #elif __CYGWIN__ && __x86_64__ |
320 | ctx->env[7] = (long) coro_init; |
406 | ctx->env[7] = (long) coro_init; |
321 | ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long); |
407 | ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long); |
322 | #elif defined __MINGW32__ |
408 | #elif defined __MINGW32__ |
323 | ctx->env[5] = (long) coro_init; |
409 | ctx->env[5] = (long) coro_init; |
324 | ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long); |
410 | ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long); |
… | |
… | |
345 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
431 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
346 | ctx->env[0].__jmpbuf[0].__sp = (int *) ((char *)sptr + ssize) - sizeof (long); |
432 | ctx->env[0].__jmpbuf[0].__sp = (int *) ((char *)sptr + ssize) - sizeof (long); |
347 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
433 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
348 | ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; |
434 | ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; |
349 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
435 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
350 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
436 | #elif defined (__GNU_LIBRARY__) && defined (__x86_64__) |
351 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
437 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
352 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
438 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
353 | #else |
439 | #else |
354 | #error "linux libc or architecture not supported" |
440 | #error "linux libc or architecture not supported" |
355 | #endif |
441 | #endif |
… | |
… | |
360 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
446 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
361 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
447 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
362 | |
448 | |
363 | # elif CORO_ASM |
449 | # elif CORO_ASM |
364 | |
450 | |
|
|
451 | #if __i386__ || __x86_64__ |
365 | ctx->sp = (void **)(ssize + (char *)sptr); |
452 | ctx->sp = (void **)(ssize + (char *)sptr); |
366 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
453 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
367 | *--ctx->sp = (void *)coro_init; |
454 | *--ctx->sp = (void *)coro_init; |
368 | |
|
|
369 | #if CORO_WIN_TIB |
455 | #if CORO_WIN_TIB |
370 | *--ctx->sp = 0; /* ExceptionList */ |
456 | *--ctx->sp = 0; /* ExceptionList */ |
371 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
457 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
372 | *--ctx->sp = sptr; /* StackLimit */ |
458 | *--ctx->sp = sptr; /* StackLimit */ |
|
|
459 | #endif |
|
|
460 | #elif CORO_ARM |
|
|
461 | /* return address stored in lr register, don't push anything */ |
|
|
462 | #else |
|
|
463 | #error unsupported architecture |
373 | #endif |
464 | #endif |
374 | |
465 | |
375 | ctx->sp -= NUM_SAVED; |
466 | ctx->sp -= NUM_SAVED; |
376 | memset (ctx->sp, 0, sizeof (*ctx->sp) * NUM_SAVED); |
467 | memset (ctx->sp, 0, sizeof (*ctx->sp) * NUM_SAVED); |
|
|
468 | |
|
|
469 | #if __i386__ || __x86_64__ |
|
|
470 | /* done already */ |
|
|
471 | #elif CORO_ARM |
|
|
472 | ctx->sp[0] = coro; /* r4 */ |
|
|
473 | ctx->sp[1] = arg; /* r5 */ |
|
|
474 | ctx->sp[8] = (char *)coro_init; /* lr */ |
|
|
475 | #else |
|
|
476 | #error unsupported architecture |
|
|
477 | #endif |
377 | |
478 | |
378 | # elif CORO_UCONTEXT |
479 | # elif CORO_UCONTEXT |
379 | |
480 | |
380 | getcontext (&(ctx->uc)); |
481 | getcontext (&(ctx->uc)); |
381 | |
482 | |
… | |
… | |
600 | |
701 | |
601 | #if !CORO_MMAP |
702 | #if !CORO_MMAP |
602 | # undef CORO_GUARDPAGES |
703 | # undef CORO_GUARDPAGES |
603 | #endif |
704 | #endif |
604 | |
705 | |
605 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
706 | #if !__i386__ && !__x86_64__ && !__powerpc__ && !__arm__ && !__aarch64__ && !__m68k__ && !__alpha__ && !__mips__ && !__sparc64__ |
606 | # undef CORO_GUARDPAGES |
707 | # undef CORO_GUARDPAGES |
607 | #endif |
708 | #endif |
608 | |
709 | |
609 | #ifndef CORO_GUARDPAGES |
710 | #ifndef CORO_GUARDPAGES |
610 | # define CORO_GUARDPAGES 0 |
711 | # define CORO_GUARDPAGES 0 |