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); |
|
|
234 | #elif defined(__MINGW32__) |
|
|
235 | ctx->env[5] = (long) coro_init; |
|
|
236 | ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long); |
231 | #elif defined(_M_IX86) |
237 | #elif defined(_M_IX86) |
232 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; |
238 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long) coro_init; |
233 | ((_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); |
234 | #elif defined(_M_AMD64) |
240 | #elif defined(_M_AMD64) |
235 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; |
241 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64) coro_init; |
236 | ((_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); |
237 | #elif defined(_M_IA64) |
243 | #elif defined(_M_IA64) |
238 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; |
244 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64) coro_init; |
239 | ((_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); |
240 | #else |
246 | #else |
241 | #error "microsoft libc or architecture not supported" |
247 | #error "microsoft libc or architecture not supported" |
242 | #endif |
248 | #endif |
243 | |
249 | |
244 | # elif CORO_LINUX |
250 | # elif CORO_LINUX |
245 | |
251 | |
246 | coro_setjmp (ctx->env); |
252 | coro_setjmp (ctx->env); |
247 | #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) |
248 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
254 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
249 | 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); |
250 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
256 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
251 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
257 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
252 | 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); |
253 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
259 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
254 | ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; |
260 | ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; |
255 | 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); |
256 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
262 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
257 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
263 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
258 | 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); |
259 | #else |
265 | #else |
260 | #error "linux libc or architecture not supported" |
266 | #error "linux libc or architecture not supported" |
261 | #endif |
267 | #endif |
262 | |
268 | |
263 | # elif CORO_IRIX |
269 | # elif CORO_IRIX |
264 | |
270 | |
265 | coro_setjmp (ctx->env, 0); |
271 | coro_setjmp (ctx->env, 0); |
266 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
272 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
267 | 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); |
268 | |
274 | |
269 | # elif CORO_ASM |
275 | # elif CORO_ASM |
270 | |
276 | |
271 | ctx->sp = (void **)(ssize + (char *)sptr); |
277 | ctx->sp = (void **)(ssize + (char *)sptr); |
272 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
278 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |