Index: lib/libc/arch/mips/gen/Makefile.inc =================================================================== RCS file: /cvsroot/src/lib/libc/arch/mips/gen/Makefile.inc,v retrieving revision 1.34 diff -u -p -r1.34 Makefile.inc --- lib/libc/arch/mips/gen/Makefile.inc 24 Jan 2016 16:01:56 -0000 1.34 +++ lib/libc/arch/mips/gen/Makefile.inc 21 Sep 2016 06:33:34 -0000 @@ -27,7 +27,8 @@ SRCS+= _setjmp.S SRCS+= sigsetjmp.S SRCS+= byte_swap_2.S byte_swap_4.S byte_swap_8.S -SRCS+= makecontext.c resumecontext.c _resumecontext.S swapcontext.S _lwp.c +# resumecontext.c +SRCS+= makecontext.c _resumecontext.S swapcontext.S _lwp.c # mips abi builtin extensions (used by GCC for lexical-closure trampoline) SRCS+= cacheflush.c Index: lib/libc/arch/mips/gen/_resumecontext.S =================================================================== RCS file: /cvsroot/src/lib/libc/arch/mips/gen/_resumecontext.S,v retrieving revision 1.10 diff -u -p -r1.10 _resumecontext.S --- lib/libc/arch/mips/gen/_resumecontext.S 13 Aug 2016 08:09:17 -0000 1.10 +++ lib/libc/arch/mips/gen/_resumecontext.S 21 Sep 2016 06:33:34 -0000 @@ -44,17 +44,36 @@ LEAF_NOPROFILE(__resumecontext) /* * We get here not by a call through $t9 but thru $ra after the - * function passed to makecontext returns. + * function passed to makecontext returns. Therefore, we need + * to recover gp from ra */ +#if defined(__mips_o32) || defined(__mips_o64) + .set push + .set noreorder + .cpload ra + .set pop +#endif +#if defined(__mips_n32) || defined(__mips_n64) + .cpsetup ra, t3, __resumecontext +#endif + PTR_SUBU sp, sp, UCONTEXT_SIZE # get space for ucontext move a0, sp # arg0 for getcontext PTR_S zero, _OFFSETOF_UC_LINK(a0) # make sure uc_link is 0 SYSTRAP(getcontext) # get context + +#if defined(__mips_n32) || defined(__mips_n64) + REG_PROLOGUE + /* We saved gp in t2 above */ + REG_S t3, _OFFSETOF_UC_GREGS_GP(a0) + REG_EPILOGUE +#endif + PTR_L a0, _OFFSETOF_UC_LINK(a0) # linked context? NOP_L beq a0, zero, 1f # nope, exit process nop - SYSTRAP(setcontext) # yes, become it. + PIC_TAILCALL(setcontext) # yes, become it. /* NOTREACHED (in theory) */ li a0, -1 # failure, 1: Index: lib/libc/arch/mips/gen/swapcontext.S =================================================================== RCS file: /cvsroot/src/lib/libc/arch/mips/gen/swapcontext.S,v retrieving revision 1.5 diff -u -p -r1.5 swapcontext.S --- lib/libc/arch/mips/gen/swapcontext.S 12 Sep 2012 02:00:52 -0000 1.5 +++ lib/libc/arch/mips/gen/swapcontext.S 21 Sep 2016 06:33:34 -0000 @@ -37,9 +37,10 @@ #endif /* SYSLIBC_SCCS && !lint */ .set reorder - + NESTED(swapcontext, CALLFRAME_SIZ, ra) .mask 0x80000030, (CALLFRAME_RA - CALLFRAME_SIZ) + PIC_PROLOGUE(swapcontext) PTR_SUBU sp, sp, CALLFRAME_SIZ PTR_S ra, CALLFRAME_RA(sp) # save ra PTR_S a0, 0(sp) # stash away oucp @@ -53,6 +54,10 @@ NESTED(swapcontext, CALLFRAME_SIZ, ra) PTR_ADDIU v0, sp, CALLFRAME_SIZ REG_PROLOGUE REG_S zero, _OFFSETOF_UC_GREGS_V0(v1) +#if defined(__mips_n32) || defined(__mips_n64) + /* PIC_PROLOGUE saved gp in t3 */ + REG_S t3, _OFFSETOF_UC_GREGS_GP(v1) +#endif REG_S ra, _OFFSETOF_UC_GREGS_EPC(v1) REG_S v0, _OFFSETOF_UC_GREGS_SP(v1) REG_EPILOGUE