Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Add support for _UC_TLSBASE. Make sure to ...



details:   https://anonhg.NetBSD.org/src/rev/3a47c899132c
branches:  trunk
changeset: 781499:3a47c899132c
user:      matt <matt%NetBSD.org@localhost>
date:      Tue Sep 11 00:15:19 2012 +0000

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

diffstat:

 sys/arch/powerpc/include/mcontext.h    |   3 ++-
 sys/arch/powerpc/powerpc/sig_machdep.c |  17 +++++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diffs (62 lines):

diff -r 1363f041cef5 -r 3a47c899132c sys/arch/powerpc/include/mcontext.h
--- a/sys/arch/powerpc/include/mcontext.h       Mon Sep 10 21:42:53 2012 +0000
+++ b/sys/arch/powerpc/include/mcontext.h       Tue Sep 11 00:15:19 2012 +0000
@@ -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 @@
 /* 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])
diff -r 1363f041cef5 -r 3a47c899132c sys/arch/powerpc/powerpc/sig_machdep.c
--- a/sys/arch/powerpc/powerpc/sig_machdep.c    Mon Sep 10 21:42:53 2012 +0000
+++ b/sys/arch/powerpc/powerpc/sig_machdep.c    Tue Sep 11 00:15:19 2012 +0000
@@ -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 @@
 #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 @@
 #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



Home | Main Index | Thread Index | Old Index