Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Fix previous; hide userland ABI details for...



details:   https://anonhg.NetBSD.org/src/rev/6c985ec93519
branches:  trunk
changeset: 935002:6c985ec93519
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Jun 22 05:34:57 2020 +0000

description:
Fix previous; hide userland ABI details for kernel as suggested by joerg:

http://mail-index.netbsd.org/source-changes-d/2020/06/21/msg012745.html

- Revive __lwp_settcb(), and call _lwp_setprivate(2) from it.

- Keep l_private opaque pointer for kernel; store raw value of %r2 in it.
  In the previous commit message, I wrote,

http://mail-index.netbsd.org/source-changes/2020/06/21/msg118524.html

> - Make sure that, like other ports, l_private represents address of tcb,
>   not biased one as in %r2.

  but, it turned out to be wrong. mips stores a biased address, at least.
  It is userland responsibility to interpret returned values from
  lwp_getprivate(2).

diffstat:

 sys/arch/powerpc/include/mcontext.h    |  24 ++++++++++++++++++------
 sys/arch/powerpc/include/types.h       |   3 ++-
 sys/arch/powerpc/powerpc/sig_machdep.c |  10 ++++------
 3 files changed, 24 insertions(+), 13 deletions(-)

diffs (107 lines):

diff -r ef49c9ad5174 -r 6c985ec93519 sys/arch/powerpc/include/mcontext.h
--- a/sys/arch/powerpc/include/mcontext.h       Mon Jun 22 03:16:29 2020 +0000
+++ b/sys/arch/powerpc/include/mcontext.h       Mon Jun 22 05:34:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mcontext.h,v 1.20 2020/06/21 00:39:59 rin Exp $        */
+/*     $NetBSD: mcontext.h,v 1.21 2020/06/22 05:34:57 rin Exp $        */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -141,8 +141,7 @@
 
 #define        _UC_MACHINE_SET_PC(uc, pc)      _UC_MACHINE_PC(uc) = (pc)
 
-#if defined(_KERNEL) || \
-defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
+#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
 #include <sys/tls.h>
 
 /*
@@ -154,7 +153,6 @@
 #define        TLS_DTV_OFFSET  0x8000
 __CTASSERT(TLS_TP_OFFSET + sizeof(struct tls_tcb) < 0x8000);
 
-#ifndef _KERNEL
 static __inline void *
 __lwp_gettcb_fast(void)
 {
@@ -167,7 +165,21 @@
 
        return __tcb;
 }
-#endif /* !_KERNEL */
-#endif /* _KERNEL || _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */
+
+void _lwp_setprivate(void *);
+
+static __inline void
+__lwp_settcb(void *__tcb)
+{
+       __tcb = (uint8_t *)__tcb + TLS_TP_OFFSET + sizeof(struct tls_tcb);
+
+       __asm __volatile(
+               "mr %%r2,%[__tcb]"
+           :
+           :   [__tcb] "r" (__tcb));
+
+       _lwp_setprivate(__tcb);
+}
+#endif /* _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */
 
 #endif /* !_POWERPC_MCONTEXT_H_ */
diff -r ef49c9ad5174 -r 6c985ec93519 sys/arch/powerpc/include/types.h
--- a/sys/arch/powerpc/include/types.h  Mon Jun 22 03:16:29 2020 +0000
+++ b/sys/arch/powerpc/include/types.h  Mon Jun 22 05:34:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.63 2020/06/21 00:39:59 rin Exp $   */
+/*     $NetBSD: types.h,v 1.64 2020/06/22 05:34:57 rin Exp $   */
 
 /*-
  * Copyright (C) 1995 Wolfgang Solfrank.
@@ -89,6 +89,7 @@
 #define        __HAVE_CPU_LWP_SETPRIVATE
 #define        __HAVE_COMMON___TLS_GET_ADDR
 #define        __HAVE___LWP_GETTCB_FAST
+#define        __HAVE___LWP_SETTCB
 #define        __HAVE_TLS_VARIANT_I
 
 #if defined(_KERNEL) || defined(_KMEMUSER)
diff -r ef49c9ad5174 -r 6c985ec93519 sys/arch/powerpc/powerpc/sig_machdep.c
--- a/sys/arch/powerpc/powerpc/sig_machdep.c    Mon Jun 22 03:16:29 2020 +0000
+++ b/sys/arch/powerpc/powerpc/sig_machdep.c    Mon Jun 22 05:34:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sig_machdep.c,v 1.50 2020/06/21 00:40:00 rin Exp $     */
+/*     $NetBSD: sig_machdep.c,v 1.51 2020/06/22 05:34:57 rin Exp $     */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.50 2020/06/21 00:40:00 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.51 2020/06/22 05:34:57 rin Exp $");
 
 #include "opt_ppcarch.h"
 #include "opt_altivec.h"
@@ -243,9 +243,8 @@
 #endif
        }
 
-#define TLS_BIAS (TLS_TP_OFFSET + sizeof(struct tls_tcb))
        if (flags & _UC_TLSBASE)
-               lwp_setprivate(l, (void *)((uintptr_t)gr[_REG_R2] - TLS_BIAS));
+               lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_R2]);
 
 #ifdef PPC_HAVE_FPU
        /* Restore FPU context, if any. */
@@ -280,8 +279,7 @@
 {
        struct trapframe * const tf = l->l_md.md_utf;
 
-       tf->tf_fixreg[_REG_R2] = (register_t)addr + TLS_BIAS;
-#undef TLS_BIAS
+       tf->tf_fixreg[_REG_R2] = (register_t)addr;
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index