Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/arch/mips/gen Fix for [on]{32,64}



details:   https://anonhg.NetBSD.org/src/rev/8a376e7e7fac
branches:  trunk
changeset: 347883:8a376e7e7fac
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Sep 21 06:49:39 2016 +0000

description:
Fix for [on]{32,64}

/usr/tests/lib/libc/sys/t_getcontext
/usr/tests/lib/libc/sys/t_swapcontext
/usr/tests/lib/libc/sys/t_ucontext
/usr/tests/lib/libpthread/t_swapcontext

All pass now.

Changes amount to

- saving GP from caller in context for n{32,64}
- performing (the equivalient of) PIC_PROLOGUE for swapcontext and
  __resumecontext
- Call setcontext via the PLT in __resumecontext

diffstat:

 lib/libc/arch/mips/gen/_resumecontext.S |  27 +++++++++++++++++++++++----
 lib/libc/arch/mips/gen/swapcontext.S    |   9 +++++++--
 2 files changed, 30 insertions(+), 6 deletions(-)

diffs (93 lines):

diff -r 75f6090daff0 -r 8a376e7e7fac lib/libc/arch/mips/gen/_resumecontext.S
--- a/lib/libc/arch/mips/gen/_resumecontext.S   Wed Sep 21 06:41:42 2016 +0000
+++ b/lib/libc/arch/mips/gen/_resumecontext.S   Wed Sep 21 06:49:39 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: _resumecontext.S,v 1.10 2016/08/13 08:09:17 skrll Exp $        */
+/*     $NetBSD: _resumecontext.S,v 1.11 2016/09/21 06:49:39 skrll Exp $        */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include "assym.h"
 
 #if defined(SYSLIBC_SCCS) && !defined(lint)
-       RCSID("$NetBSD: _resumecontext.S,v 1.10 2016/08/13 08:09:17 skrll Exp $")
+       RCSID("$NetBSD: _resumecontext.S,v 1.11 2016/09/21 06:49:39 skrll Exp $")
 #endif /* SYSLIBC_SCCS && !lint */
 
        .set    reorder
@@ -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:
diff -r 75f6090daff0 -r 8a376e7e7fac lib/libc/arch/mips/gen/swapcontext.S
--- a/lib/libc/arch/mips/gen/swapcontext.S      Wed Sep 21 06:41:42 2016 +0000
+++ b/lib/libc/arch/mips/gen/swapcontext.S      Wed Sep 21 06:49:39 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: swapcontext.S,v 1.6 2016/09/21 06:41:42 skrll Exp $    */
+/*     $NetBSD: swapcontext.S,v 1.7 2016/09/21 06:49:39 skrll Exp $    */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -33,13 +33,14 @@
 #include "assym.h"
 
 #if defined(SYSLIBC_SCCS) && !defined(lint)
-       RCSID("$NetBSD: swapcontext.S,v 1.6 2016/09/21 06:41:42 skrll Exp $")
+       RCSID("$NetBSD: swapcontext.S,v 1.7 2016/09/21 06:49:39 skrll Exp $")
 #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 @@
        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



Home | Main Index | Thread Index | Old Index