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