… | |
… | |
115 | asm ( |
115 | asm ( |
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 | /* windows, of course, gives a shit on the amd64 ABI and uses different registers */ |
|
|
121 | /* http://blogs.msdn.com/freik/archive/2005/03/17/398200.aspx */ |
120 | #if __amd64 |
122 | #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 |
|
|
127 | #define NUM_SAVED 6 |
123 | #define NUM_SAVED 6 |
128 | #endif |
|
|
129 | "\tpush %rbp\n" |
124 | "\tpush %rbp\n" |
130 | "\tpush %rbx\n" |
125 | "\tpush %rbx\n" |
131 | "\tpush %r12\n" |
126 | "\tpush %r12\n" |
132 | "\tpush %r13\n" |
127 | "\tpush %r13\n" |
133 | "\tpush %r14\n" |
128 | "\tpush %r14\n" |
134 | "\tpush %r15\n" |
129 | "\tpush %r15\n" |
|
|
130 | #if CORO_WIN_TIB |
|
|
131 | "\tpush %gs:0x0\n" |
|
|
132 | "\tpush %gs:0x8\n" |
|
|
133 | "\tpush %gs:0xc\n" |
|
|
134 | #endif |
135 | "\tmov %rsp, (%rdi)\n" |
135 | "\tmov %rsp, (%rdi)\n" |
136 | "\tmov (%rsi), %rsp\n" |
136 | "\tmov (%rsi), %rsp\n" |
|
|
137 | #if CORO_WIN_TIB |
|
|
138 | "\tpop %gs:0xc\n" |
|
|
139 | "\tpop %gs:0x8\n" |
|
|
140 | "\tpop %gs:0x0\n" |
|
|
141 | #endif |
137 | "\tpop %r15\n" |
142 | "\tpop %r15\n" |
138 | "\tpop %r14\n" |
143 | "\tpop %r14\n" |
139 | "\tpop %r13\n" |
144 | "\tpop %r13\n" |
140 | "\tpop %r12\n" |
145 | "\tpop %r12\n" |
141 | "\tpop %rbx\n" |
146 | "\tpop %rbx\n" |
142 | "\tpop %rbp\n" |
147 | "\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 |
|
|
148 | #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 |
|
|
155 | #define NUM_SAVED 4 |
149 | #define NUM_SAVED 4 |
156 | #endif |
|
|
157 | "\tpush %ebp\n" |
150 | "\tpush %ebp\n" |
158 | "\tpush %ebx\n" |
151 | "\tpush %ebx\n" |
159 | "\tpush %esi\n" |
152 | "\tpush %esi\n" |
160 | "\tpush %edi\n" |
153 | "\tpush %edi\n" |
|
|
154 | #if CORO_WIN_TIB |
|
|
155 | "\tpush %fs:0\n" |
|
|
156 | "\tpush %fs:4\n" |
|
|
157 | "\tpush %fs:8\n" |
|
|
158 | #endif |
161 | "\tmov %esp, (%eax)\n" |
159 | "\tmov %esp, (%eax)\n" |
162 | "\tmov (%edx), %esp\n" |
160 | "\tmov (%edx), %esp\n" |
|
|
161 | #if CORO_WIN_TIB |
|
|
162 | "\tpop %fs:8\n" |
|
|
163 | "\tpop %fs:4\n" |
|
|
164 | "\tpop %fs:0\n" |
|
|
165 | #endif |
163 | "\tpop %edi\n" |
166 | "\tpop %edi\n" |
164 | "\tpop %esi\n" |
167 | "\tpop %esi\n" |
165 | "\tpop %ebx\n" |
168 | "\tpop %ebx\n" |
166 | "\tpop %ebp\n" |
169 | "\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 |
|
|
172 | #else |
170 | #else |
173 | #error unsupported architecture |
171 | #error unsupported architecture |
174 | #endif |
172 | #endif |
175 | "\tret\n" |
173 | "\tret\n" |
176 | ); |
174 | ); |
… | |
… | |
299 | # elif CORO_ASM |
297 | # elif CORO_ASM |
300 | |
298 | |
301 | ctx->sp = (void **)(ssize + (char *)sptr); |
299 | ctx->sp = (void **)(ssize + (char *)sptr); |
302 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
300 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
303 | *--ctx->sp = (void *)coro_init; |
301 | *--ctx->sp = (void *)coro_init; |
|
|
302 | |
|
|
303 | #if CORO_WIN_TIB |
|
|
304 | *--ctx->sp = 0; /* ExceptionList */ |
|
|
305 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
|
|
306 | *--ctx->sp = sptr; /* StackLimit */ |
|
|
307 | #endif |
|
|
308 | |
304 | ctx->sp -= NUM_SAVED; |
309 | ctx->sp -= NUM_SAVED; |
305 | |
310 | |
306 | # elif CORO_UCONTEXT |
311 | # elif CORO_UCONTEXT |
307 | |
312 | |
308 | getcontext (&(ctx->uc)); |
313 | getcontext (&(ctx->uc)); |