Module Name:    src
Committed By:   msaitoh
Date:           Sun Apr 19 07:43:02 UTC 2015

Modified Files:
        src/lib/libc/arch/sh3/gen [netbsd-5]: swapcontext.S

Log Message:
Pull up following revision(s) (requested by uwe in ticket #1960):

lib/libc/arch/sh3/gen/swapcontext.S             1.11-1.12 via patch

        Correctly preserve old sate in swapcontext(3).
        Fixes PR port-sh3/49597 reported by Yasushi Oshima.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.6.1 src/lib/libc/arch/sh3/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/sh3/gen/swapcontext.S
diff -u src/lib/libc/arch/sh3/gen/swapcontext.S:1.9 src/lib/libc/arch/sh3/gen/swapcontext.S:1.9.6.1
--- src/lib/libc/arch/sh3/gen/swapcontext.S:1.9	Mon Apr 28 20:22:57 2008
+++ src/lib/libc/arch/sh3/gen/swapcontext.S	Sun Apr 19 07:43:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: swapcontext.S,v 1.9 2008/04/28 20:22:57 martin Exp $	*/
+/*	$NetBSD: swapcontext.S,v 1.9.6.1 2015/04/19 07:43:02 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <machine/asm.h>
 #if defined(SYSLIBC_SCCS) && !defined(lint)
-	RCSID("$NetBSD: swapcontext.S,v 1.9 2008/04/28 20:22:57 martin Exp $")
+	RCSID("$NetBSD: swapcontext.S,v 1.9.6.1 2015/04/19 07:43:02 msaitoh Exp $")
 #endif /* SYSLIBC_SCCS and not lint */
 
 /*
@@ -40,33 +40,33 @@
  */
 ENTRY(swapcontext)
 	PIC_PROLOGUE(.L_got)
-	mov.l	r5, @-sp
 	sts.l	pr, @-sp
 
 	mov.l	.L__getcontext, r0
-1:	CALL	r0			/* _getcontext(oucp) */
+	mov.l	r5, @-sp
+1:	CALL	r0			! _getcontext(oucp)
 	 mov.l	r4, @-sp
-	mov.l	@sp+, r1
+	!! getcontext captures oucp resuming here with r12 (when PIC),
+	!! pr, r5 and r4 pushed onto the stack
+
 	tst	r0, r0
-	bf	3f			/* return error from getcontext */
+	bf.s	3f			! return error from getcontext
+	 mov.l	@sp, r1			! saved oucp
+
+	!! adjust oucp to resume after setcontext below
+	mova	3f, r0
+	mov.l	r0, @(36 + 1 * 4, r1)	! _UC_MACHINE_SET_PC(oucp, pr)
 
-	/* Note: getcontext does _UC_MACHINE_INTRV(oucp) = 0 for us */
-	mov.l	@sp, r0
-	mov.l	r0, @(36 + 1 * 4, r1)	/* _UC_MACHINE_SET_PC(oucp, pr) */
 	mov.l	.L_setcontext, r2
-2:	CALL	r2			/* setcontext(ucp) */
-	 mov.l	@(4, sp), r4
-	/* if we get here, return error from setcontext */
-3:
+2:	CALL	r2			! setcontext(ucp)
+	 mov.l	@(4, sp), r4		! saved ucp
+
+	.align	2
+3:	!! we get here on errors and when resuming oucp
+	add	#8, sp			! skip r4 and r5
 	lds.l	@sp+, pr
-#ifdef PIC
-	add	#4, sp
-	rts
-	 PIC_EPILOGUE
-#else
 	rts
-	 add	#4, sp
-#endif
+	 PIC_EPILOGUE_SLOT
 
 	.align	2
 .L_got:			PIC_GOT_DATUM

Reply via email to