--- libcoro/coro.c 2008/04/04 20:07:35 1.30 +++ libcoro/coro.c 2008/11/03 16:05:38 1.35 @@ -45,10 +45,10 @@ # if __sgi # define STACK_ADJUST_PTR(sp,ss) ((char *)(sp) + (ss) - 8) # define STACK_ADJUST_SIZE(sp,ss) ((ss) - 8) -# elif __i386__ && CORO_LINUX +# elif (__i386__ && CORO_LINUX) || (_M_IX86 && CORO_LOSER) # define STACK_ADJUST_PTR(sp,ss) ((char *)(sp) + (ss)) # define STACK_ADJUST_SIZE(sp,ss) (ss) -# elif __amd64__ && CORO_LINUX +# elif (__amd64__ && CORO_LINUX) || ((_M_AMD64 || _M_IA64) && CORO_LOSER) # define STACK_ADJUST_PTR(sp,ss) ((char *)(sp) + (ss) - 8) # define STACK_ADJUST_SIZE(sp,ss) (ss) # else @@ -122,43 +122,42 @@ #endif #if CORO_ASM -void __attribute__((__noinline__, __fastcall__)) -coro_transfer (struct coro_context *prev, struct coro_context *next) -{ - asm volatile ( +asm ( + ".text\n" + ".globl coro_transfer\n" + ".type coro_transfer, @function\n" + "coro_transfer:\n" #if __amd64 -# define NUM_CLOBBERED 5 - "push %%rbx\n\t" - "push %%r12\n\t" - "push %%r13\n\t" - "push %%r14\n\t" - "push %%r15\n\t" - "mov %%rsp, %0\n\t" - "mov %1, %%rsp\n\t" - "pop %%r15\n\t" - "pop %%r14\n\t" - "pop %%r13\n\t" - "pop %%r12\n\t" - "pop %%rbx\n\t" +# define NUM_SAVED 5 + "\tpush %rbx\n" + "\tpush %r12\n" + "\tpush %r13\n" + "\tpush %r14\n" + "\tpush %r15\n" + "\tmov %rsp, (%rdi)\n" + "\tmov (%rsi), %rsp\n" + "\tpop %r15\n" + "\tpop %r14\n" + "\tpop %r13\n" + "\tpop %r12\n" + "\tpop %rbx\n" #elif __i386 -# define NUM_CLOBBERED 4 - "push %%ebx\n\t" - "push %%esi\n\t" - "push %%edi\n\t" - "push %%ebp\n\t" - "mov %%esp, %0\n\t" - "mov %1, %%esp\n\t" - "pop %%ebp\n\t" - "pop %%edi\n\t" - "pop %%esi\n\t" - "pop %%ebx\n\t" +# define NUM_SAVED 4 + "\tpush %ebx\n" + "\tpush %esi\n" + "\tpush %edi\n" + "\tpush %ebp\n" + "\tmov %esp, (%eax)\n" + "\tmov (%edx), %esp\n" + "\tpop %ebp\n" + "\tpop %edi\n" + "\tpop %esi\n" + "\tpop %ebx\n" #else # error unsupported architecture #endif - : "=m" (prev->sp) - : "m" (next->sp) - ); -} + "\tret\n" +); #endif #if CORO_PTHREAD @@ -187,6 +186,8 @@ return 0; } +asm(""); + void coro_transfer(coro_context *prev, coro_context *next) { pthread_cond_init (&prev->c, 0); @@ -287,13 +288,13 @@ ctx->env[8] = (long)coro_init; #elif defined(_M_IX86) ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; - ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr,ssize); + ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr, ssize); #elif defined(_M_AMD64) ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; - ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr,ssize); + ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr, ssize); #elif defined(_M_IA64) ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; - ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr,ssize); + ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr, ssize); #else # error "microsoft libc or architecture not supported" #endif @@ -326,9 +327,13 @@ # elif CORO_ASM ctx->sp = (volatile void **)(ssize + (char *)sptr); + /* we try to allow for both functions with and without frame pointers */ *--ctx->sp = (void *)coro_init; - *--ctx->sp = (void *)coro_init; // this is needed when the prologue saves ebp - ctx->sp -= NUM_CLOBBERED; + { + int i; + for (i = NUM_SAVED; i--; ) + *--ctx->sp = 0; + } # endif