ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/coro.c
(Generate patch)

Comparing libcoro/coro.c (file contents):
Revision 1.44 by root, Wed Nov 19 02:56:16 2008 UTC vs.
Revision 1.49 by root, Fri Apr 2 19:04:04 2010 UTC

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,
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 #if __amd64 120 #if __amd64
121 #if CORO_WIN_TIB
122 #define NUM_SAVED 6+3
123 "\tpush %fs:0x0\n"
124 "\tpush %fs:0x8\n"
125 "\tpush %fs:0xc\n"
126 #else
121 #define NUM_SAVED 6 127 #define NUM_SAVED 6
128 #endif
122 "\tpush %rbp\n" 129 "\tpush %rbp\n"
123 "\tpush %rbx\n" 130 "\tpush %rbx\n"
124 "\tpush %r12\n" 131 "\tpush %r12\n"
125 "\tpush %r13\n" 132 "\tpush %r13\n"
126 "\tpush %r14\n" 133 "\tpush %r14\n"
131 "\tpop %r14\n" 138 "\tpop %r14\n"
132 "\tpop %r13\n" 139 "\tpop %r13\n"
133 "\tpop %r12\n" 140 "\tpop %r12\n"
134 "\tpop %rbx\n" 141 "\tpop %rbx\n"
135 "\tpop %rbp\n" 142 "\tpop %rbp\n"
143 #if CORO_WIN_TIB
144 "\tpop %fs:0xc\n"
145 "\tpop %fs:0x8\n"
146 "\tpop %fs:0x0\n"
147 #endif
136 #elif __i386 148 #elif __i386
149 #if CORO_WIN_TIB
150 #define NUM_SAVED 4+3
151 "\tpush %fs:0x0\n"
152 "\tpush %fs:0x4\n"
153 "\tpush %fs:0x8\n"
154 #else
137 #define NUM_SAVED 4 155 #define NUM_SAVED 4
156 #endif
138 "\tpush %ebp\n" 157 "\tpush %ebp\n"
139 "\tpush %ebx\n" 158 "\tpush %ebx\n"
140 "\tpush %esi\n" 159 "\tpush %esi\n"
141 "\tpush %edi\n" 160 "\tpush %edi\n"
142 "\tmov %esp, (%eax)\n" 161 "\tmov %esp, (%eax)\n"
143 "\tmov (%edx), %esp\n" 162 "\tmov (%edx), %esp\n"
144 "\tpop %edi\n" 163 "\tpop %edi\n"
145 "\tpop %esi\n" 164 "\tpop %esi\n"
146 "\tpop %ebx\n" 165 "\tpop %ebx\n"
147 "\tpop %ebp\n" 166 "\tpop %ebp\n"
167 #if CORO_WIN_TIB
168 "\tpop %fs:0x8\n"
169 "\tpop %fs:0x4\n"
170 "\tpop %fs:0x0\n"
171 #endif
148 #else 172 #else
149 #error unsupported architecture 173 #error unsupported architecture
150 #endif 174 #endif
151 "\tret\n" 175 "\tret\n"
152 ); 176 );
223 sigprocmask (SIG_SETMASK, &osig, 0); 247 sigprocmask (SIG_SETMASK, &osig, 0);
224 248
225# elif CORO_LOSER 249# elif CORO_LOSER
226 250
227 coro_setjmp (ctx->env); 251 coro_setjmp (ctx->env);
228 #if __CYGWIN__ 252 #if __CYGWIN__ && __i386
253 ctx->env[8] = (long) coro_init;
229 ctx->env[7] = (long)((char *)sptr + ssize) - sizeof (long); 254 ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long);
230 ctx->env[8] = (long)coro_init; 255 #elif __CYGWIN__ && __x86_64
256 ctx->env[7] = (long) coro_init;
257 ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long);
258 #elif defined(__MINGW32__)
259 ctx->env[5] = (long) coro_init;
260 ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long);
231 #elif defined(_M_IX86) 261 #elif defined(_M_IX86)
232 ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; 262 ((_JUMP_BUFFER *)&ctx->env)->Eip = (long) coro_init;
233 ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 263 ((_JUMP_BUFFER *)&ctx->env)->Esp = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long);
234 #elif defined(_M_AMD64) 264 #elif defined(_M_AMD64)
235 ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; 265 ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64) coro_init;
236 ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 266 ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64);
237 #elif defined(_M_IA64) 267 #elif defined(_M_IA64)
238 ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; 268 ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64) coro_init;
239 ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 269 ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64);
240 #else 270 #else
241 #error "microsoft libc or architecture not supported" 271 #error "microsoft libc or architecture not supported"
242 #endif 272 #endif
243 273
244# elif CORO_LINUX 274# elif CORO_LINUX
245 275
246 coro_setjmp (ctx->env); 276 coro_setjmp (ctx->env);
247 #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) 277 #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP)
248 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; 278 ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init;
249 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 279 ctx->env[0].__jmpbuf[JB_SP] = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long);
250 #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) 280 #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__)
251 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; 281 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init;
252 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize) - sizeof (long); 282 ctx->env[0].__jmpbuf[0].__sp = (int *) ((char *)sptr + ssize) - sizeof (long);
253 #elif defined (__GNU_LIBRARY__) && defined (__i386__) 283 #elif defined (__GNU_LIBRARY__) && defined (__i386__)
254 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; 284 ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init;
255 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); 285 ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long);
256 #elif defined (__GNU_LIBRARY__) && defined (__amd64__) 286 #elif defined (__GNU_LIBRARY__) && defined (__amd64__)
257 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; 287 ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init;
258 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); 288 ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long);
259 #else 289 #else
260 #error "linux libc or architecture not supported" 290 #error "linux libc or architecture not supported"
261 #endif 291 #endif
262 292
263# elif CORO_IRIX 293# elif CORO_IRIX
264 294
265 coro_setjmp (ctx->env, 0); 295 coro_setjmp (ctx->env, 0);
266 ctx->env[JB_PC] = (__uint64_t)coro_init; 296 ctx->env[JB_PC] = (__uint64_t)coro_init;
267 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); 297 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long);
268 298
269# elif CORO_ASM 299# elif CORO_ASM
270 300
271 ctx->sp = (void **)(ssize + (char *)sptr); 301 ctx->sp = (void **)(ssize + (char *)sptr);
272 *--ctx->sp = (void *)abort; /* needed for alignment only */ 302 *--ctx->sp = (void *)abort; /* needed for alignment only */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines