1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2008 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2001-2009 Marc Alexander Lehmann <schmorp@schmorp.de> |
3 | * |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
5 | * tion, are permitted provided that the following conditions are met: |
5 | * tion, are permitted provided that the following conditions are met: |
6 | * |
6 | * |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
… | |
… | |
223 | sigprocmask (SIG_SETMASK, &osig, 0); |
223 | sigprocmask (SIG_SETMASK, &osig, 0); |
224 | |
224 | |
225 | # elif CORO_LOSER |
225 | # elif CORO_LOSER |
226 | |
226 | |
227 | coro_setjmp (ctx->env); |
227 | coro_setjmp (ctx->env); |
228 | #if __CYGWIN__ |
228 | #if __CYGWIN__ && __i386 |
|
|
229 | ctx->env[8] = (long) coro_init; |
229 | ctx->env[7] = (long)((char *)sptr + ssize) - sizeof (long); |
230 | ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long); |
230 | ctx->env[8] = (long)coro_init; |
231 | #elif __CYGWIN__ && __x86_64 |
|
|
232 | ctx->env[7] = (long) coro_init; |
|
|
233 | ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long); |
231 | #elif defined(__MINGW32__) |
234 | #elif defined(__MINGW32__) |
|
|
235 | ctx->env[5] = (long) coro_init; |
232 | ctx->env[4] = (long)((char *)sptr + ssize) - sizeof (long); |
236 | ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long); |
233 | ctx->env[5] = (long)coro_init; |
|
|
234 | #elif defined(_M_IX86) |
237 | #elif defined(_M_IX86) |
235 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; |
238 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long) coro_init; |
236 | ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
239 | ((_JUMP_BUFFER *)&ctx->env)->Esp = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
237 | #elif defined(_M_AMD64) |
240 | #elif defined(_M_AMD64) |
238 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; |
241 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64) coro_init; |
239 | ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
242 | ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64); |
240 | #elif defined(_M_IA64) |
243 | #elif defined(_M_IA64) |
241 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; |
244 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64) coro_init; |
242 | ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
245 | ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64); |
243 | #else |
246 | #else |
244 | #error "microsoft libc or architecture not supported" |
247 | #error "microsoft libc or architecture not supported" |
245 | #endif |
248 | #endif |
246 | |
249 | |
247 | # elif CORO_LINUX |
250 | # elif CORO_LINUX |
248 | |
251 | |
249 | coro_setjmp (ctx->env); |
252 | coro_setjmp (ctx->env); |
250 | #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) |
253 | #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) |
251 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
254 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
252 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
255 | ctx->env[0].__jmpbuf[JB_SP] = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
253 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
256 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
254 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
257 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
255 | ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize) - sizeof (long); |
258 | ctx->env[0].__jmpbuf[0].__sp = (int *) ((char *)sptr + ssize) - sizeof (long); |
256 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
259 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
257 | ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; |
260 | ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; |
258 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); |
261 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
259 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
262 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
260 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
263 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
261 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); |
264 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
262 | #else |
265 | #else |
263 | #error "linux libc or architecture not supported" |
266 | #error "linux libc or architecture not supported" |
264 | #endif |
267 | #endif |
265 | |
268 | |
266 | # elif CORO_IRIX |
269 | # elif CORO_IRIX |
267 | |
270 | |
268 | coro_setjmp (ctx->env, 0); |
271 | coro_setjmp (ctx->env, 0); |
269 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
272 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
270 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
273 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
271 | |
274 | |
272 | # elif CORO_ASM |
275 | # elif CORO_ASM |
273 | |
276 | |
274 | ctx->sp = (void **)(ssize + (char *)sptr); |
277 | ctx->sp = (void **)(ssize + (char *)sptr); |
275 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
278 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |