Module Name:    src
Committed By:   rin
Date:           Mon Jun 22 05:34:57 UTC 2020

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/powerpc/include/mcontext.h
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/powerpc/include/types.h
cvs rdiff -u -r1.50 -r1.51 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.20 src/sys/arch/powerpc/include/mcontext.h:1.21
--- src/sys/arch/powerpc/include/mcontext.h:1.20	Sun Jun 21 00:39:59 2020
+++ src/sys/arch/powerpc/include/mcontext.h	Mon Jun 22 05:34:57 2020
@@ -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 @@ typedef struct {
 
 #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 @@ defined(_RTLD_SOURCE) || defined(_LIBC_S
 #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 @@ __lwp_gettcb_fast(void)
 
 	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_ */

Index: src/sys/arch/powerpc/include/types.h
diff -u src/sys/arch/powerpc/include/types.h:1.63 src/sys/arch/powerpc/include/types.h:1.64
--- src/sys/arch/powerpc/include/types.h:1.63	Sun Jun 21 00:39:59 2020
+++ src/sys/arch/powerpc/include/types.h	Mon Jun 22 05:34:57 2020
@@ -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 @@ typedef __uint32_t tlb_asid_t;		/* for b
 #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)

Index: src/sys/arch/powerpc/powerpc/sig_machdep.c
diff -u src/sys/arch/powerpc/powerpc/sig_machdep.c:1.50 src/sys/arch/powerpc/powerpc/sig_machdep.c:1.51
--- src/sys/arch/powerpc/powerpc/sig_machdep.c:1.50	Sun Jun 21 00:40:00 2020
+++ src/sys/arch/powerpc/powerpc/sig_machdep.c	Mon Jun 22 05:34:57 2020
@@ -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 @@ cpu_setmcontext(struct lwp *l, const mco
 #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 @@ cpu_lwp_setprivate(lwp_t *l, void *addr)
 {
 	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;
 }

Reply via email to