--- libcoro/coro.c 2012/12/07 14:21:09 1.66 +++ libcoro/coro.c 2016/03/06 06:26:21 1.68 @@ -117,6 +117,13 @@ # if CORO_ASM + #if __arm__ && \ + (defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ + || defined __ARM_ARCH_7R__ || defined __ARM_ARCH_7M__ \ + || __ARCH_ARCH == 7) + #define CORO_ARM 1 + #endif + #if _WIN32 || __CYGWIN__ #define CORO_WIN_TIB 1 #endif @@ -206,7 +213,7 @@ "\tpopq %rcx\n" "\tjmpq *%rcx\n" - #elif __i386 + #elif __i386__ #define NUM_SAVED 4 "\tpushl %ebp\n" @@ -234,6 +241,80 @@ "\tpopl %ecx\n" "\tjmpl *%ecx\n" + #elif CORO_ARM /* untested, what about thumb, neon, iwmmxt? */ + + #if __ARM_PCS_VFP + "\tvpush {d8-d15}\n" + #define NUM_SAVED (9 + 8 * 2) + #else + #define NUM_SAVED 9 + #endif + "\tpush {r4-r11,lr}\n" + "\tstr sp, [r0]\n" + "\tldr sp, [r1]\n" + "\tpop {r4-r11,lr}\n" + #if __ARM_PCS_VFP + "\tvpop {d8-d15}\n" + #endif + "\tmov r15, lr\n" + + #elif __mips__ && 0 /* untested, 32 bit only */ + + #define NUM_SAVED (12 + 8 * 2) + /* TODO: n64/o64, lw=>ld */ + + "\t.set nomips16\n" + "\t.frame $sp,112,$31\n" + #if __mips_soft_float + "\taddiu $sp,$sp,-44\n" + #else + "\taddiu $sp,$sp,-112\n" + "\ts.d $f30,88($sp)\n" + "\ts.d $f28,80($sp)\n" + "\ts.d $f26,72($sp)\n" + "\ts.d $f24,64($sp)\n" + "\ts.d $f22,56($sp)\n" + "\ts.d $f20,48($sp)\n" + #endif + "\tsw $28,40($sp)\n" + "\tsw $31,36($sp)\n" + "\tsw $fp,32($sp)\n" + "\tsw $23,28($sp)\n" + "\tsw $22,24($sp)\n" + "\tsw $21,20($sp)\n" + "\tsw $20,16($sp)\n" + "\tsw $19,12($sp)\n" + "\tsw $18,8($sp)\n" + "\tsw $17,4($sp)\n" + "\tsw $16,0($sp)\n" + "\tsw $sp,0($4)\n" + "\tlw $sp,0($5)\n" + #if !__mips_soft_float + "\tl.d $f30,88($sp)\n" + "\tl.d $f28,80($sp)\n" + "\tl.d $f26,72($sp)\n" + "\tl.d $f24,64($sp)\n" + "\tl.d $f22,56($sp)\n" + "\tl.d $f20,48($sp)\n" + #endif + "\tlw $28,40($sp)\n" + "\tlw $31,36($sp)\n" + "\tlw $fp,32($sp)\n" + "\tlw $23,28($sp)\n" + "\tlw $22,24($sp)\n" + "\tlw $21,20($sp)\n" + "\tlw $20,16($sp)\n" + "\tlw $19,12($sp)\n" + "\tlw $18,8($sp)\n" + "\tlw $17,4($sp)\n" + "\tlw $16,0($sp)\n" + "\tj $31\n" + #if __mips_soft_float + "\taddiu $sp,$sp,44\n" + #else + "\taddiu $sp,$sp,112\n" + #endif + #else #error unsupported architecture #endif @@ -313,10 +394,10 @@ # elif CORO_LOSER coro_setjmp (ctx->env); - #if __CYGWIN__ && __i386 + #if __CYGWIN__ && __i386__ ctx->env[8] = (long) coro_init; ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long); - #elif __CYGWIN__ && __x86_64 + #elif __CYGWIN__ && __x86_64__ ctx->env[7] = (long) coro_init; ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long); #elif defined __MINGW32__ @@ -347,7 +428,7 @@ #elif defined (__GNU_LIBRARY__) && defined (__i386__) ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); - #elif defined (__GNU_LIBRARY__) && defined (__amd64__) + #elif defined (__GNU_LIBRARY__) && defined (__x86_64__) ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); #else @@ -362,19 +443,34 @@ # elif CORO_ASM - ctx->sp = (void **)(ssize + (char *)sptr); - *--ctx->sp = (void *)abort; /* needed for alignment only */ - *--ctx->sp = (void *)coro_init; - - #if CORO_WIN_TIB - *--ctx->sp = 0; /* ExceptionList */ - *--ctx->sp = (char *)sptr + ssize; /* StackBase */ - *--ctx->sp = sptr; /* StackLimit */ + #if __i386__ || __x86_64__ + ctx->sp = (void **)(ssize + (char *)sptr); + *--ctx->sp = (void *)abort; /* needed for alignment only */ + *--ctx->sp = (void *)coro_init; + #if CORO_WIN_TIB + *--ctx->sp = 0; /* ExceptionList */ + *--ctx->sp = (char *)sptr + ssize; /* StackBase */ + *--ctx->sp = sptr; /* StackLimit */ + #endif + #elif CORO_ARM + /* return address stored in lr register, don't push anything */ + #else + #error unsupported architecture #endif ctx->sp -= NUM_SAVED; memset (ctx->sp, 0, sizeof (*ctx->sp) * NUM_SAVED); + #if __i386__ || __x86_64__ + /* done already */ + #elif CORO_ARM + ctx->sp[0] = coro; /* r4 */ + ctx->sp[1] = arg; /* r5 */ + ctx->sp[8] = (char *)coro_init; /* lr */ + #else + #error unsupported architecture + #endif + # elif CORO_UCONTEXT getcontext (&(ctx->uc)); @@ -602,7 +698,7 @@ # undef CORO_GUARDPAGES #endif -#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 +#if !__i386__ && !__x86_64__ && !__powerpc__ && !__arm__ && !__aarch64__ && !__m68k__ && !__alpha__ && !__mips__ && !__sparc64__ # undef CORO_GUARDPAGES #endif @@ -674,7 +770,7 @@ #endif #if CORO_USE_VALGRIND - stack->valgrind_id = VALGRIND_STACK_REGISTER ((char *)base, (char *)ssze - CORO_GUARDPAGES * PAGESIZE); + stack->valgrind_id = VALGRIND_STACK_REGISTER ((char *)base, ((char *)base) + ssze - CORO_GUARDPAGES * PAGESIZE); #endif stack->sptr = base;