Module Name:    src
Committed By:   skrll
Date:           Wed Sep 21 06:49:40 UTC 2016

Modified Files:
        src/lib/libc/arch/mips/gen: _resumecontext.S swapcontext.S

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/arch/mips/gen/_resumecontext.S
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/mips/gen/swapcontext.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/arch/mips/gen/_resumecontext.S
diff -u src/lib/libc/arch/mips/gen/_resumecontext.S:1.10 src/lib/libc/arch/mips/gen/_resumecontext.S:1.11
--- src/lib/libc/arch/mips/gen/_resumecontext.S:1.10	Sat Aug 13 08:09:17 2016
+++ src/lib/libc/arch/mips/gen/_resumecontext.S	Wed Sep 21 06:49:39 2016
@@ -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:

Index: src/lib/libc/arch/mips/gen/swapcontext.S
diff -u src/lib/libc/arch/mips/gen/swapcontext.S:1.6 src/lib/libc/arch/mips/gen/swapcontext.S:1.7
--- src/lib/libc/arch/mips/gen/swapcontext.S:1.6	Wed Sep 21 06:41:42 2016
+++ src/lib/libc/arch/mips/gen/swapcontext.S	Wed Sep 21 06:49:39 2016
@@ -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 @@ 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

Reply via email to