Module Name:    src
Committed By:   matt
Date:           Tue Sep 11 00:15:19 UTC 2012

Modified Files:
        src/sys/arch/powerpc/include: mcontext.h
        src/sys/arch/powerpc/powerpc: sig_machdep.c

Log Message:
Add support for _UC_TLSBASE.  Make sure to preserve backwards compat for
programs built before TLS support was added.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/powerpc/include/mcontext.h
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/powerpc/powerpc/sig_machdep.c

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

Modified files:

Index: src/sys/arch/powerpc/include/mcontext.h
diff -u src/sys/arch/powerpc/include/mcontext.h:1.13 src/sys/arch/powerpc/include/mcontext.h:1.14
--- src/sys/arch/powerpc/include/mcontext.h:1.13	Sat Mar 12 07:38:16 2011
+++ src/sys/arch/powerpc/include/mcontext.h	Tue Sep 11 00:15:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.13 2011/03/12 07:38:16 matt Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.14 2012/09/11 00:15:19 matt Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -115,6 +115,7 @@ typedef struct {
 /* Machine-dependent uc_flags */
 #define	_UC_POWERPC_VEC	0x00010000	/* Vector Register File valid */
 #define	_UC_POWERPC_SPE	0x00020000	/* Vector Register File valid */
+#define	_UC_TLSBASE	0x00080000	/* thread context valid in R2 */
 
 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_R1])
 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_PC])

Index: src/sys/arch/powerpc/powerpc/sig_machdep.c
diff -u src/sys/arch/powerpc/powerpc/sig_machdep.c:1.42 src/sys/arch/powerpc/powerpc/sig_machdep.c:1.43
--- src/sys/arch/powerpc/powerpc/sig_machdep.c:1.42	Mon May 21 14:15:18 2012
+++ src/sys/arch/powerpc/powerpc/sig_machdep.c	Tue Sep 11 00:15:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sig_machdep.c,v 1.42 2012/05/21 14:15:18 martin Exp $	*/
+/*	$NetBSD: sig_machdep.c,v 1.43 2012/09/11 00:15:19 matt Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.42 2012/05/21 14:15:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.43 2012/09/11 00:15:19 matt Exp $");
 
 #include "opt_ppcarch.h"
 #include "opt_altivec.h"
@@ -172,6 +172,8 @@ cpu_getmcontext(struct lwp *l, mcontext_
 #endif
 
 	*flagp |= _UC_CPU;
+	if (gr[_REG_R2] == (uintptr_t)l->l_private)
+		*flagp |= _UC_TLSBASE;
 
 #ifdef PPC_HAVE_FPU
 	/* Save FPU context, if any. */
@@ -229,6 +231,17 @@ cpu_setmcontext(struct lwp *l, const mco
 #ifdef PPC_OEA
 		tf->tf_mq = gr[_REG_MQ];
 #endif
+		/*
+		 * If R2 contains the TLS base, make sure to update l->l_private.
+		 * If not, restore R2 from l->l_private if not null.  Since setcontext
+		 * existed before the TCB code, a static program could expect R2 to
+		 * the small data pointer.
+		 */
+		if (flags & _UC_TLSBASE) {
+			l->l_private = (void *) tf->tf_fixreg[_REG_R2];
+		} else if (l->l_private) {
+			tf->tf_fixreg[_REG_R2] = (uintptr_t)l->l_private;
+		}
 	}
 
 #ifdef PPC_HAVE_FPU

Reply via email to