Module Name: src Committed By: joerg Date: Thu Feb 24 04:28:49 UTC 2011
Modified Files: src/lib/libc/arch/alpha/gen: _lwp.c src/lib/libc/arch/arm/gen: _lwp.c src/lib/libc/arch/hppa/gen: _lwp.c src/lib/libc/arch/i386/gen: _lwp.c src/lib/libc/arch/m68k/gen: _lwp.c src/lib/libc/arch/mips/gen: _lwp.c src/lib/libc/arch/powerpc/gen: _lwp.c src/lib/libc/arch/sh3/gen: _lwp.c src/lib/libc/arch/sparc/gen: _lwp.c src/lib/libc/arch/sparc64/gen: _lwp.c src/lib/libc/arch/x86_64/gen: _lwp.c src/lib/libpthread: pthread_int.h src/lib/libpthread/arch/i386: pthread_md.h src/sys/arch/alpha/alpha: machdep.c sys_machdep.c src/sys/arch/alpha/include: mcontext.h types.h src/sys/arch/amd64/amd64: machdep.c netbsd32_machdep.c src/sys/arch/amd64/include: mcontext.h types.h src/sys/arch/arm/arm: sig_machdep.c src/sys/arch/arm/include: mcontext.h src/sys/arch/hppa/hppa: hppa_machdep.c trap.S vm_machdep.c src/sys/arch/hppa/include: mcontext.h types.h src/sys/arch/i386/i386: machdep.c src/sys/arch/i386/include: mcontext.h types.h src/sys/arch/m68k/include: mcontext.h src/sys/arch/m68k/m68k: sig_machdep.c src/sys/arch/mips/include: mcontext.h types.h src/sys/arch/mips/mips: cpu_subr.c netbsd32_machdep.c src/sys/arch/powerpc/include: mcontext.h types.h src/sys/arch/sh3/include: mcontext.h types.h src/sys/arch/sh3/sh3: sh3_machdep.c src/sys/arch/sparc/include: mcontext.h types.h src/sys/arch/sparc/sparc: machdep.c vm_machdep.c src/sys/arch/sparc64/sparc64: netbsd32_machdep.c vm_machdep.c Log Message: Allow storing and receiving the LWP private pointer via ucontext_t on all platforms except VAX and IA64. Add fast access via register for AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace the stack based pthread_self(). Implement skeleton support for Alpha, HPPA, PowerPC, SPARC and SPARC64, but leave it disabled. Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in machine/types.h and a corresponding __lwp_getprivate_fast in machine/mcontext.h. This material is based upon work partially supported by The NetBSD Foundation under a contract with Joerg Sonnenberger. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/alpha/gen/_lwp.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/arm/gen/_lwp.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/hppa/gen/_lwp.c cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/i386/gen/_lwp.c cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/m68k/gen/_lwp.c cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/mips/gen/_lwp.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/powerpc/gen/_lwp.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/sh3/gen/_lwp.c cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/sparc/gen/_lwp.c cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/sparc64/gen/_lwp.c cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/x86_64/gen/_lwp.c cvs rdiff -u -r1.73 -r1.74 src/lib/libpthread/pthread_int.h cvs rdiff -u -r1.18 -r1.19 src/lib/libpthread/arch/i386/pthread_md.h cvs rdiff -u -r1.328 -r1.329 src/sys/arch/alpha/alpha/machdep.c cvs rdiff -u -r1.19 -r1.20 src/sys/arch/alpha/alpha/sys_machdep.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/include/mcontext.h cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/include/types.h cvs rdiff -u -r1.158 -r1.159 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.72 -r1.73 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/include/mcontext.h cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/include/types.h cvs rdiff -u -r1.38 -r1.39 src/sys/arch/arm/arm/sig_machdep.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/include/mcontext.h cvs rdiff -u -r1.23 -r1.24 src/sys/arch/hppa/hppa/hppa_machdep.c cvs rdiff -u -r1.53 -r1.54 src/sys/arch/hppa/hppa/trap.S cvs rdiff -u -r1.48 -r1.49 src/sys/arch/hppa/hppa/vm_machdep.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hppa/include/mcontext.h cvs rdiff -u -r1.17 -r1.18 src/sys/arch/hppa/include/types.h cvs rdiff -u -r1.699 -r1.700 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.8 -r1.9 src/sys/arch/i386/include/mcontext.h cvs rdiff -u -r1.70 -r1.71 src/sys/arch/i386/include/types.h cvs rdiff -u -r1.7 -r1.8 src/sys/arch/m68k/include/mcontext.h cvs rdiff -u -r1.45 -r1.46 src/sys/arch/m68k/m68k/sig_machdep.c cvs rdiff -u -r1.14 -r1.15 src/sys/arch/mips/include/mcontext.h cvs rdiff -u -r1.48 -r1.49 src/sys/arch/mips/include/types.h cvs rdiff -u -r1.3 -r1.4 src/sys/arch/mips/mips/cpu_subr.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/mips/mips/netbsd32_machdep.c cvs rdiff -u -r1.10 -r1.11 src/sys/arch/powerpc/include/mcontext.h cvs rdiff -u -r1.36 -r1.37 src/sys/arch/powerpc/include/types.h cvs rdiff -u -r1.7 -r1.8 src/sys/arch/sh3/include/mcontext.h cvs rdiff -u -r1.30 -r1.31 src/sys/arch/sh3/include/types.h cvs rdiff -u -r1.90 -r1.91 src/sys/arch/sh3/sh3/sh3_machdep.c cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sparc/include/mcontext.h cvs rdiff -u -r1.55 -r1.56 src/sys/arch/sparc/include/types.h cvs rdiff -u -r1.305 -r1.306 src/sys/arch/sparc/sparc/machdep.c cvs rdiff -u -r1.104 -r1.105 src/sys/arch/sparc/sparc/vm_machdep.c cvs rdiff -u -r1.93 -r1.94 src/sys/arch/sparc64/sparc64/netbsd32_machdep.c cvs rdiff -u -r1.95 -r1.96 src/sys/arch/sparc64/sparc64/vm_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/lib/libc/arch/alpha/gen/_lwp.c diff -u src/lib/libc/arch/alpha/gen/_lwp.c:1.5 src/lib/libc/arch/alpha/gen/_lwp.c:1.6 --- src/lib/libc/arch/alpha/gen/_lwp.c:1.5 Mon Apr 28 20:22:55 2008 +++ src/lib/libc/arch/alpha/gen/_lwp.c Thu Feb 24 04:28:41 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:55 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:41 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:55 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:41 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -60,4 +60,7 @@ gr[_REG_A0] = (unsigned long) arg; gr[_REG_SP] = ((unsigned long) (stack_base + stack_size)) & ~0x7; gr[_REG_S6] = 0; + gr[_REG_UNIQUE] = (unsigned long)private; + + u->uc_flags |= _UC_UNIQUE; } Index: src/lib/libc/arch/arm/gen/_lwp.c diff -u src/lib/libc/arch/arm/gen/_lwp.c:1.4 src/lib/libc/arch/arm/gen/_lwp.c:1.5 --- src/lib/libc/arch/arm/gen/_lwp.c:1.4 Sun Jun 12 05:21:25 2005 +++ src/lib/libc/arch/arm/gen/_lwp.c Thu Feb 24 04:28:41 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $ */ +/* $NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:41 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:41 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -68,4 +68,6 @@ u->uc_mcontext.__gregs[_REG_SP] = ((__greg_t) sp) & ~7; u->uc_mcontext.__gregs[_REG_LR] = (__greg_t) _lwp_exit; u->uc_mcontext.__gregs[_REG_PC] = (__greg_t) start; + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } Index: src/lib/libc/arch/hppa/gen/_lwp.c diff -u src/lib/libc/arch/hppa/gen/_lwp.c:1.4 src/lib/libc/arch/hppa/gen/_lwp.c:1.5 --- src/lib/libc/arch/hppa/gen/_lwp.c:1.4 Thu Jan 7 12:31:10 2010 +++ src/lib/libc/arch/hppa/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.4 2010/01/07 12:31:10 skrll Exp $ */ +/* $NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.4 2010/01/07 12:31:10 skrll Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -69,4 +69,5 @@ gr[_REG_RP] = (__greg_t) _lwp_exit; gr[_REG_ARG0] = (__greg_t) arg; gr[_REG_SP] = (__greg_t) sp; + gr[_REG_CR27] = (__greg_t) private; } Index: src/lib/libc/arch/i386/gen/_lwp.c diff -u src/lib/libc/arch/i386/gen/_lwp.c:1.6 src/lib/libc/arch/i386/gen/_lwp.c:1.7 --- src/lib/libc/arch/i386/gen/_lwp.c:1.6 Mon Apr 28 20:22:56 2008 +++ src/lib/libc/arch/i386/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.6 2008/04/28 20:22:56 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:42 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.6 2008/04/28 20:22:56 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -66,5 +66,6 @@ /* LINTED uintptr_t is safe */ u->uc_mcontext.__gregs[_REG_UESP] = (uintptr_t) sp; - /* LINTED private is currently unused */ + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } Index: src/lib/libc/arch/m68k/gen/_lwp.c diff -u src/lib/libc/arch/m68k/gen/_lwp.c:1.5 src/lib/libc/arch/m68k/gen/_lwp.c:1.6 --- src/lib/libc/arch/m68k/gen/_lwp.c:1.5 Mon Apr 28 20:22:56 2008 +++ src/lib/libc/arch/m68k/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:56 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:56 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -60,4 +60,6 @@ *--sp = (void *) _lwp_exit; u->uc_mcontext.__gregs[_REG_A7] = (int) sp; + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } Index: src/lib/libc/arch/mips/gen/_lwp.c diff -u src/lib/libc/arch/mips/gen/_lwp.c:1.5 src/lib/libc/arch/mips/gen/_lwp.c:1.6 --- src/lib/libc/arch/mips/gen/_lwp.c:1.5 Mon Apr 28 20:22:56 2008 +++ src/lib/libc/arch/mips/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:56 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:56 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -61,4 +61,6 @@ gr[_REG_RA] = (unsigned long) _lwp_exit; gr[_REG_A0] = (unsigned long) arg; gr[_REG_SP] = (unsigned long) sp; + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } Index: src/lib/libc/arch/powerpc/gen/_lwp.c diff -u src/lib/libc/arch/powerpc/gen/_lwp.c:1.4 src/lib/libc/arch/powerpc/gen/_lwp.c:1.5 --- src/lib/libc/arch/powerpc/gen/_lwp.c:1.4 Sun Jun 12 05:21:26 2005 +++ src/lib/libc/arch/powerpc/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:26 lukem Exp $ */ +/* $NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:26 lukem Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -64,4 +64,5 @@ u->uc_mcontext.__gregs[1] = ((int) sp) - 12; /* stack */ u->uc_mcontext.__gregs[33] = (int) _lwp_exit; /* LR */ u->uc_mcontext.__gregs[34] = (int) start; /* PC */ + u->uc_mcontext.__gregs[_REG_R2] = (__greg_t) private; } Index: src/lib/libc/arch/sh3/gen/_lwp.c diff -u src/lib/libc/arch/sh3/gen/_lwp.c:1.4 src/lib/libc/arch/sh3/gen/_lwp.c:1.5 --- src/lib/libc/arch/sh3/gen/_lwp.c:1.4 Sun Jun 12 05:21:26 2005 +++ src/lib/libc/arch/sh3/gen/_lwp.c Thu Feb 24 04:28:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:26 lukem Exp $ */ +/* $NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $ */ /* * Copyright (c) 2002 Wasabi Systems, Inc. @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:26 lukem Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.5 2011/02/24 04:28:42 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -64,4 +64,5 @@ u->uc_mcontext.__gregs[_REG_SP] = ((__greg_t) sp) & ~3; u->uc_mcontext.__gregs[_REG_PR] = (__greg_t) _lwp_exit; u->uc_mcontext.__gregs[_REG_PC] = (__greg_t) start; + u->uc_mcontext.__gregs[_REG_GBR] = (__greg_t) private; } Index: src/lib/libc/arch/sparc/gen/_lwp.c diff -u src/lib/libc/arch/sparc/gen/_lwp.c:1.5 src/lib/libc/arch/sparc/gen/_lwp.c:1.6 --- src/lib/libc/arch/sparc/gen/_lwp.c:1.5 Mon Apr 28 20:22:57 2008 +++ src/lib/libc/arch/sparc/gen/_lwp.c Thu Feb 24 04:28:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:57 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:57 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:43 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -65,6 +65,7 @@ gr[_REG_O0] = (ulong)arg; gr[_REG_O6] = (ulong)sp; gr[_REG_O7] = (ulong)_lwp_exit - 8; + gr[_REG_G7] = (ulong)private; /* XXX: uwe: why do we need this? */ /* create loopback in the window save area on the stack? */ Index: src/lib/libc/arch/sparc64/gen/_lwp.c diff -u src/lib/libc/arch/sparc64/gen/_lwp.c:1.5 src/lib/libc/arch/sparc64/gen/_lwp.c:1.6 --- src/lib/libc/arch/sparc64/gen/_lwp.c:1.5 Mon Apr 28 20:22:57 2008 +++ src/lib/libc/arch/sparc64/gen/_lwp.c Thu Feb 24 04:28:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:57 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.5 2008/04/28 20:22:57 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:43 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -70,4 +70,5 @@ gr[_REG_O0] = (ulong) arg; gr[_REG_O6] = (ulong) sp; gr[_REG_O7] = (ulong)_lwp_exit - 8; + gr[_REG_G7] = (ulong)private; } Index: src/lib/libc/arch/x86_64/gen/_lwp.c diff -u src/lib/libc/arch/x86_64/gen/_lwp.c:1.6 src/lib/libc/arch/x86_64/gen/_lwp.c:1.7 --- src/lib/libc/arch/x86_64/gen/_lwp.c:1.6 Thu Jul 2 09:57:09 2009 +++ src/lib/libc/arch/x86_64/gen/_lwp.c Thu Feb 24 04:28:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.6 2009/07/02 09:57:09 joerg Exp $ */ +/* $NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.6 2009/07/02 09:57:09 joerg Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:43 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -66,5 +66,6 @@ /* LINTED uintptr_t is safe */ gr[_REG_URSP] = (uintptr_t) sp; - /* LINTED private is currently unused */ + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } Index: src/lib/libpthread/pthread_int.h diff -u src/lib/libpthread/pthread_int.h:1.73 src/lib/libpthread/pthread_int.h:1.74 --- src/lib/libpthread/pthread_int.h:1.73 Sat Dec 18 15:54:27 2010 +++ src/lib/libpthread/pthread_int.h Thu Feb 24 04:28:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_int.h,v 1.73 2010/12/18 15:54:27 christos Exp $ */ +/* $NetBSD: pthread_int.h,v 1.74 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -250,8 +250,12 @@ } while (/*CONSTCOND*/0) -#ifdef PTHREAD__HAVE_THREADREG -#define pthread__self() pthread__threadreg_get() +#ifdef __HAVE___LWP_GETPRIVATE_FAST +static inline pthread_t __constfunc +pthread__self(void) +{ + return (pthread_t)__lwp_getprivate_fast(); +} #else /* Stack location of pointer to a particular thread */ extern vaddr_t pthread__mainbase; Index: src/lib/libpthread/arch/i386/pthread_md.h diff -u src/lib/libpthread/arch/i386/pthread_md.h:1.18 src/lib/libpthread/arch/i386/pthread_md.h:1.19 --- src/lib/libpthread/arch/i386/pthread_md.h:1.18 Tue Jan 25 19:12:05 2011 +++ src/lib/libpthread/arch/i386/pthread_md.h Thu Feb 24 04:28:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_md.h,v 1.18 2011/01/25 19:12:05 christos Exp $ */ +/* $NetBSD: pthread_md.h,v 1.19 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2001, 2007, 2008 The NetBSD Foundation, Inc. @@ -75,26 +75,10 @@ } while (/*CONSTCOND*/0); #define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory") -/* #define PTHREAD__HAVE_THREADREG */ /* Don't need additional memory barriers. */ #define PTHREAD__ATOMIC_IS_MEMBAR -static inline pthread_t -#ifdef __GNUC__ -__attribute__ ((__const__)) -#endif -pthread__threadreg_get(void) -{ - pthread_t self; - - __asm volatile("movl %%gs:0, %0" - : "=r" (self) - :); - - return self; -} - static inline void * _atomic_cas_ptr(volatile void *ptr, void *old, void *new) { Index: src/sys/arch/alpha/alpha/machdep.c diff -u src/sys/arch/alpha/alpha/machdep.c:1.328 src/sys/arch/alpha/alpha/machdep.c:1.329 --- src/sys/arch/alpha/alpha/machdep.c:1.328 Wed Nov 10 09:27:21 2010 +++ src/sys/arch/alpha/alpha/machdep.c Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.328 2010/11/10 09:27:21 uebayasi Exp $ */ +/* $NetBSD: machdep.c,v 1.329 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.328 2010/11/10 09:27:21 uebayasi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.329 2011/02/24 04:28:44 joerg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1928,12 +1928,8 @@ frame->tf_regs[FRAME_PC] = gr[_REG_PC]; frame->tf_regs[FRAME_PS] = gr[_REG_PS]; } - if (flags & _UC_UNIQUE) { - if (l == curlwp) - alpha_pal_wrunique(gr[_REG_UNIQUE]); - else - pcb->pcb_hw.apcb_unique = gr[_REG_UNIQUE]; - } + if (flags & _UC_UNIQUE) + lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_UNIQUE]); /* Restore floating point register context, if any. */ if (flags & _UC_FPU) { /* If we have an FP register context, get rid of it. */ Index: src/sys/arch/alpha/alpha/sys_machdep.c diff -u src/sys/arch/alpha/alpha/sys_machdep.c:1.19 src/sys/arch/alpha/alpha/sys_machdep.c:1.20 --- src/sys/arch/alpha/alpha/sys_machdep.c:1.19 Wed Jul 7 01:20:49 2010 +++ src/sys/arch/alpha/alpha/sys_machdep.c Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_machdep.c,v 1.19 2010/07/07 01:20:49 chs Exp $ */ +/* $NetBSD: sys_machdep.c,v 1.20 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.19 2010/07/07 01:20:49 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.20 2011/02/24 04:28:44 joerg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -238,5 +238,7 @@ pcb = lwp_getpcb(l); pcb->pcb_hw.apcb_unique = (unsigned long)addr; + if (l == curlwp) + alpha_pal_wrunique(pcb->pcb_hw.apcb_unique); return 0; } Index: src/sys/arch/alpha/include/mcontext.h diff -u src/sys/arch/alpha/include/mcontext.h:1.5 src/sys/arch/alpha/include/mcontext.h:1.6 --- src/sys/arch/alpha/include/mcontext.h:1.5 Mon Apr 28 20:23:11 2008 +++ src/sys/arch/alpha/include/mcontext.h Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.5 2008/04/28 20:23:11 martin Exp $ */ +/* $NetBSD: mcontext.h,v 1.6 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -101,4 +101,16 @@ #define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc) +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__tmp __asm("$0"); + + __asm volatile("call_pal %1 # PAL_rdunique" + : "=r" (__tmp) + : "i" (0x009e /* PAL_rdunique */)); + + return __tmp; +} + #endif /* !_ALPHA_MCONTEXT_H_ */ Index: src/sys/arch/alpha/include/types.h diff -u src/sys/arch/alpha/include/types.h:1.43 src/sys/arch/alpha/include/types.h:1.44 --- src/sys/arch/alpha/include/types.h:1.43 Wed Jul 7 01:20:49 2010 +++ src/sys/arch/alpha/include/types.h Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.43 2010/07/07 01:20:49 chs Exp $ */ +/* $NetBSD: types.h,v 1.44 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -76,6 +76,9 @@ #define __HAVE_AST_PERPROC #define __HAVE_ATOMIC64_OPS #define __HAVE_CPU_LWP_SETPRIVATE +#if 0 +#define __HAVE___LWP_GETPRIVATE_FAST +#endif #if defined(_KERNEL) #define __HAVE_RAS Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.158 src/sys/arch/amd64/amd64/machdep.c:1.159 --- src/sys/arch/amd64/amd64/machdep.c:1.158 Tue Jan 11 21:10:17 2011 +++ src/sys/arch/amd64/amd64/machdep.c Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.158 2011/01/11 21:10:17 jruoho Exp $ */ +/* $NetBSD: machdep.c,v 1.159 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008 @@ -107,7 +107,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.158 2011/01/11 21:10:17 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.159 2011/02/24 04:28:44 joerg Exp $"); /* #define XENDEBUG_LOW */ @@ -1607,6 +1607,9 @@ *flags |= _UC_CPU; + mcp->_mc_tlsbase = (uintptr_t)l->l_private;; + *flags |= _UC_TLSBASE; + if ((l->l_md.md_flags & MDP_USEDFPU) != 0) { struct pcb *pcb = lwp_getpcb(l); @@ -1674,6 +1677,9 @@ l->l_md.md_flags |= MDP_USEDFPU; } + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + mutex_enter(p->p_lock); if (flags & _UC_SETSTACK) l->l_sigstk.ss_flags |= SS_ONSTACK; Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.72 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.73 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.72 Wed Feb 23 03:31:49 2011 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.72 2011/02/23 03:31:49 joerg Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.73 2011/02/24 04:28:44 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.72 2011/02/23 03:31:49 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.73 2011/02/24 04:28:44 joerg Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -157,7 +157,7 @@ tf->tf_ds = LSEL(LUDATA32_SEL, SEL_UPL); tf->tf_es = LSEL(LUDATA32_SEL, SEL_UPL); cpu_fsgs_zero(l); - cpu_fsgs_reload(l, tf->tf_ds, tf->tf_ds); + cpu_fsgs_reload(l, tf->tf_ds, tf->tf_es); tf->tf_rdi = 0; tf->tf_rsi = 0; tf->tf_rbp = 0; @@ -859,6 +859,9 @@ tf->tf_ss = gr[_REG32_SS]; } + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + /* Restore floating point register context, if any. */ if ((flags & _UC_FPU) != 0) { struct pcb *pcb = lwp_getpcb(l); @@ -919,6 +922,9 @@ *flags |= _UC_CPU; + mcp->_mc_tlsbase = (uint32_t)(uintptr_t)l->l_private; + *flags |= _UC_TLSBASE; + /* Save floating point register context, if any. */ if ((l->l_md.md_flags & MDP_USEDFPU) != 0) { struct pcb *pcb = lwp_getpcb(l); @@ -927,7 +933,7 @@ fpusave_lwp(l, true); } memcpy(&mcp->__fpregs, &pcb->pcb_savefpu.fp_fxsave, - sizeof (mcp->__fpregs)); + sizeof (pcb->pcb_savefpu.fp_fxsave)); *flags |= _UC_FPU; } } Index: src/sys/arch/amd64/include/mcontext.h diff -u src/sys/arch/amd64/include/mcontext.h:1.12 src/sys/arch/amd64/include/mcontext.h:1.13 --- src/sys/arch/amd64/include/mcontext.h:1.12 Wed Feb 23 02:58:39 2011 +++ src/sys/arch/amd64/include/mcontext.h Thu Feb 24 04:28:44 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.12 2011/02/23 02:58:39 joerg Exp $ */ +/* $NetBSD: mcontext.h,v 1.13 2011/02/24 04:28:44 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ typedef struct { __gregset_t __gregs; - long __pad; + __greg_t _mc_tlsbase; __fpregset_t __fpregs; } mcontext_t; @@ -74,6 +74,8 @@ #define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc) +#define _UC_TLSBASE 0x00080000 + /* * mcontext extensions to handle signal delivery. */ @@ -82,6 +84,16 @@ #define __UCONTEXT_SIZE 784 +static inline void * +__lwp_getprivate_fast(void) +{ + void *__tmp; + + __asm volatile("movq %%fs:0, %0" : "=r" (__tmp)); + + return __tmp; +} + #ifdef _KERNEL /* @@ -138,9 +150,10 @@ typedef struct { __gregset32_t __gregs; __fpregset32_t __fpregs; + uint32_t _mc_tlsbase; } mcontext32_t; -#define _UC_MACHINE32_PAD 5 +#define _UC_MACHINE32_PAD 4 #define __UCONTEXT32_SIZE 776 struct trapframe; Index: src/sys/arch/amd64/include/types.h diff -u src/sys/arch/amd64/include/types.h:1.35 src/sys/arch/amd64/include/types.h:1.36 --- src/sys/arch/amd64/include/types.h:1.35 Wed Dec 22 22:08:47 2010 +++ src/sys/arch/amd64/include/types.h Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.35 2010/12/22 22:08:47 njoly Exp $ */ +/* $NetBSD: types.h,v 1.36 2011/02/24 04:28:45 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -85,6 +85,7 @@ #define __HAVE_ATOMIC64_OPS #define __HAVE_ATOMIC_AS_MEMBAR #define __HAVE_CPU_LWP_SETPRIVATE +#define __HAVE___LWP_GETPRIVATE_FAST #define __HAVE_INTR_CONTROL #ifdef _KERNEL_OPT Index: src/sys/arch/arm/arm/sig_machdep.c diff -u src/sys/arch/arm/arm/sig_machdep.c:1.38 src/sys/arch/arm/arm/sig_machdep.c:1.39 --- src/sys/arch/arm/arm/sig_machdep.c:1.38 Sat Nov 21 20:32:17 2009 +++ src/sys/arch/arm/arm/sig_machdep.c Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sig_machdep.c,v 1.38 2009/11/21 20:32:17 rmind Exp $ */ +/* $NetBSD: sig_machdep.c,v 1.39 2011/02/24 04:28:45 joerg Exp $ */ /* * Copyright (c) 1994-1998 Mark Brinicombe. @@ -44,7 +44,7 @@ #include <sys/param.h> -__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.38 2009/11/21 20:32:17 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.39 2011/02/24 04:28:45 joerg Exp $"); #include <sys/mount.h> /* XXX only needed by syscallargs.h */ #include <sys/proc.h> @@ -199,6 +199,9 @@ arm_fpe_getcontext(p, (struct fpreg *)(void *)&mcp->fpregs); *flags |= _UC_FPU; #endif + + mcp->_mc_tlsbase = (uintptr_t)l->l_private; + *flags |= _UC_TLSBASE; } int @@ -240,6 +243,9 @@ } #endif + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + mutex_enter(p->p_lock); if (flags & _UC_SETSTACK) l->l_sigstk.ss_flags |= SS_ONSTACK; Index: src/sys/arch/arm/include/mcontext.h diff -u src/sys/arch/arm/include/mcontext.h:1.7 src/sys/arch/arm/include/mcontext.h:1.8 --- src/sys/arch/arm/include/mcontext.h:1.7 Wed Feb 23 02:58:39 2011 +++ src/sys/arch/arm/include/mcontext.h Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.7 2011/02/23 02:58:39 joerg Exp $ */ +/* $NetBSD: mcontext.h,v 1.8 2011/02/24 04:28:45 joerg Exp $ */ /*- * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. @@ -87,6 +87,7 @@ __fpregset_t __fpregs; __vfpregset_t __vfpregs; } __fpu; + __greg_t _mc_tlsbase; } mcontext_t; /* Machine-dependent uc_flags */ @@ -96,7 +97,9 @@ #define _UC_SETSTACK 0x00020000 #define _UC_CLRSTACK 0x00040000 -#define _UC_MACHINE_PAD 3 /* Padding appended to ucontext_t */ +#define _UC_TLSBASE 0x00080000 + +#define _UC_MACHINE_PAD 2 /* Padding appended to ucontext_t */ #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP]) #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC]) Index: src/sys/arch/hppa/hppa/hppa_machdep.c diff -u src/sys/arch/hppa/hppa/hppa_machdep.c:1.23 src/sys/arch/hppa/hppa/hppa_machdep.c:1.24 --- src/sys/arch/hppa/hppa/hppa_machdep.c:1.23 Fri Jan 14 02:06:26 2011 +++ src/sys/arch/hppa/hppa/hppa_machdep.c Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hppa_machdep.c,v 1.23 2011/01/14 02:06:26 rmind Exp $ */ +/* $NetBSD: hppa_machdep.c,v 1.24 2011/02/24 04:28:45 joerg Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: hppa_machdep.c,v 1.23 2011/01/14 02:06:26 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hppa_machdep.c,v 1.24 2011/02/24 04:28:45 joerg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -187,10 +187,10 @@ gr[_REG_SR1] = tf->tf_sr1; gr[_REG_SR2] = tf->tf_sr2; gr[_REG_SR3] = tf->tf_sr3; - gr[_REG_SR4] = tf->tf_sr4; + gr[_REG_CR27] = tf->tf_cr27; #if 0 gr[_REG_CR26] = tf->tf_cr26; - gr[_REG_CR27] = tf->tf_cr27; + gr[_REG_SR4] = tf->tf_sr4; #endif ras_pc = (__greg_t)ras_lookup(l->l_proc, @@ -303,6 +303,9 @@ tf->tf_iioq_tail |= HPPA_PC_PRIV_USER; } + lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_CR27]); + tf->tf_cr27 = gr[_REG_CR27]; + #if 0 tf->tf_sr0 = gr[_REG_SR0]; tf->tf_sr1 = gr[_REG_SR1]; @@ -310,7 +313,6 @@ tf->tf_sr3 = gr[_REG_SR3]; tf->tf_sr4 = gr[_REG_SR4]; tf->tf_cr26 = gr[_REG_CR26]; - tf->tf_cr27 = gr[_REG_CR27]; #endif } Index: src/sys/arch/hppa/hppa/trap.S diff -u src/sys/arch/hppa/hppa/trap.S:1.53 src/sys/arch/hppa/hppa/trap.S:1.54 --- src/sys/arch/hppa/hppa/trap.S:1.53 Sun Jan 23 09:44:59 2011 +++ src/sys/arch/hppa/hppa/trap.S Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.S,v 1.53 2011/01/23 09:44:59 skrll Exp $ */ +/* $NetBSD: trap.S,v 1.54 2011/02/24 04:28:45 joerg Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -366,6 +366,9 @@ stw %arg3, TF_CR13-TRAPFRAME_SIZEOF(%sr1, %t3) #endif + mfctl CR_TLS, %arg0 + stw %arg0, TF_CR27-TRAPFRAME_SIZEOF(%sr1, %t3) + #if defined(DDB) || defined(KGDB) /* * Save v2p translation table pointer @@ -507,6 +510,9 @@ mtctl %t1, %pidr3 mtctl %t2, %pidr4 #endif + ldw TF_CR27(%sr3, %t3), %t1 + mtctl %t1, CR_TLS + ldw TF_CR0(%sr3, %t3), %t1 mtctl %t1, %rctr @@ -2088,6 +2094,9 @@ stw %t1, TF_SR7(%sr3, %t3) stw %t2, TF_CR9(%sr3, %t3) + mfctl CR_TLS, %t1 + stw %t1, TF_CR27(%sr3, %t3) + mtsp %r0, %sr0 mtsp %r0, %sr1 mtsp %r0, %sr2 Index: src/sys/arch/hppa/hppa/vm_machdep.c diff -u src/sys/arch/hppa/hppa/vm_machdep.c:1.48 src/sys/arch/hppa/hppa/vm_machdep.c:1.49 --- src/sys/arch/hppa/hppa/vm_machdep.c:1.48 Thu Feb 10 14:46:46 2011 +++ src/sys/arch/hppa/hppa/vm_machdep.c Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.48 2011/02/10 14:46:46 pooka Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.49 2011/02/24 04:28:45 joerg Exp $ */ /* $OpenBSD: vm_machdep.c,v 1.64 2008/09/30 18:54:26 miod Exp $ */ @@ -29,7 +29,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.48 2011/02/10 14:46:46 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.49 2011/02/24 04:28:45 joerg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -42,6 +42,7 @@ #include <sys/exec.h> #include <sys/core.h> #include <sys/pool.h> +#include <sys/cpu.h> #include <machine/cpufunc.h> #include <machine/pmap.h> @@ -302,3 +303,13 @@ bp->b_data = bp->b_saveaddr; bp->b_saveaddr = NULL; } + +int +cpu_lwp_setprivate(lwp_t *l, void *addr) +{ + + l->l_md.md_regs->tf_cr27 = (u_int)addr; + if (l == curlwp) + mtctl(addr, CR_TLS); + return 0; +} Index: src/sys/arch/hppa/include/mcontext.h diff -u src/sys/arch/hppa/include/mcontext.h:1.4 src/sys/arch/hppa/include/mcontext.h:1.5 --- src/sys/arch/hppa/include/mcontext.h:1.4 Sun Dec 11 12:17:37 2005 +++ src/sys/arch/hppa/include/mcontext.h Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.4 2005/12/11 12:17:37 christos Exp $ */ +/* $NetBSD: mcontext.h,v 1.5 2011/02/24 04:28:45 joerg Exp $ */ #ifndef _HPPA_MCONTEXT_H_ #define _HPPA_MCONTEXT_H_ @@ -57,6 +57,16 @@ (uc)->uc_mcontext.__gregs[_REG_PCOQT] = (pc) + 4; \ } while (/*CONSTCOND*/0) +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__tmp; + + __asm volatile("mfctl\t27 /* CR_TLS */, %0" : "=r" (__tmp)); + + return __tmp; +} + #endif /* !__ASSEMBLER__ */ #define _OFFSETOF_UC_GREGS 40 Index: src/sys/arch/hppa/include/types.h diff -u src/sys/arch/hppa/include/types.h:1.17 src/sys/arch/hppa/include/types.h:1.18 --- src/sys/arch/hppa/include/types.h:1.17 Fri Dec 11 05:52:03 2009 +++ src/sys/arch/hppa/include/types.h Thu Feb 24 04:28:45 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.17 2009/12/11 05:52:03 matt Exp $ */ +/* $NetBSD: types.h,v 1.18 2011/02/24 04:28:45 joerg Exp $ */ /* $OpenBSD: types.h,v 1.6 2001/08/11 01:58:34 art Exp $ */ @@ -93,4 +93,9 @@ #define RAS_DECL(name) \ extern const char __CONCAT(name,_ras_start[]), __CONCAT(name,_ras_end[]) +#define __HAVE_CPU_LWP_SETPRIVATE +#if 0 +#define __HAVE___LWP_GETPRIVATE_FAST +#endif + #endif /* _HPPA_TYPES_H_ */ Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.699 src/sys/arch/i386/i386/machdep.c:1.700 --- src/sys/arch/i386/i386/machdep.c:1.699 Tue Jan 11 21:10:17 2011 +++ src/sys/arch/i386/i386/machdep.c Thu Feb 24 04:28:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.699 2011/01/11 21:10:17 jruoho Exp $ */ +/* $NetBSD: machdep.c,v 1.700 2011/02/24 04:28:46 joerg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.699 2011/01/11 21:10:17 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.700 2011/02/24 04:28:46 joerg Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -1755,6 +1755,9 @@ *flags |= _UC_CPU; + mcp->_mc_tlsbase = (uintptr_t)l->l_private; + *flags |= _UC_TLSBASE; + /* Save floating point register context, if any. */ if ((l->l_md.md_flags & MDL_USEDFPU) != 0) { struct pcb *pcb = lwp_getpcb(l); @@ -1845,6 +1848,9 @@ tf->tf_ss = gr[_REG_SS]; } + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + #if NNPX > 0 /* * If we were using the FPU, forget that we were. Index: src/sys/arch/i386/include/mcontext.h diff -u src/sys/arch/i386/include/mcontext.h:1.8 src/sys/arch/i386/include/mcontext.h:1.9 --- src/sys/arch/i386/include/mcontext.h:1.8 Wed Feb 23 02:58:39 2011 +++ src/sys/arch/i386/include/mcontext.h Thu Feb 24 04:28:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.8 2011/02/23 02:58:39 joerg Exp $ */ +/* $NetBSD: mcontext.h,v 1.9 2011/02/24 04:28:46 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -39,6 +39,7 @@ #define _UC_SETSTACK 0x00010000 #define _UC_CLRSTACK 0x00020000 #define _UC_VM 0x00040000 +#define _UC_TLSBASE 0x00080000 /* * Layout of mcontext_t according to the System V Application Binary Interface, @@ -96,11 +97,12 @@ typedef struct { __gregset_t __gregs; __fpregset_t __fpregs; + __greg_t _mc_tlsbase; } mcontext_t; #define _UC_FXSAVE 0x20 /* FP state is in FXSAVE format in XMM space */ -#define _UC_MACHINE_PAD 5 /* Padding appended to ucontext_t */ +#define _UC_MACHINE_PAD 4 /* Padding appended to ucontext_t */ #define _UC_UCONTEXT_ALIGN (~0xf) @@ -125,4 +127,14 @@ #define __UCONTEXT_SIZE 776 +static inline void * +__lwp_getprivate_fast(void) +{ + void *__tmp; + + __asm volatile("movl %%gs:0, %0" : "=r" (__tmp)); + + return __tmp; +} + #endif /* !_I386_MCONTEXT_H_ */ Index: src/sys/arch/i386/include/types.h diff -u src/sys/arch/i386/include/types.h:1.70 src/sys/arch/i386/include/types.h:1.71 --- src/sys/arch/i386/include/types.h:1.70 Wed Dec 22 04:15:02 2010 +++ src/sys/arch/i386/include/types.h Thu Feb 24 04:28:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.70 2010/12/22 04:15:02 christos Exp $ */ +/* $NetBSD: types.h,v 1.71 2011/02/24 04:28:46 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -112,6 +112,7 @@ #define __HAVE_ATOMIC_AS_MEMBAR #define __HAVE_CPU_LWP_SETPRIVATE #define __HAVE_INTR_CONTROL +#define __HAVE___LWP_GETPRIVATE_FAST #if defined(_KERNEL) #define __HAVE_RAS Index: src/sys/arch/m68k/include/mcontext.h diff -u src/sys/arch/m68k/include/mcontext.h:1.7 src/sys/arch/m68k/include/mcontext.h:1.8 --- src/sys/arch/m68k/include/mcontext.h:1.7 Wed Feb 23 02:58:39 2011 +++ src/sys/arch/m68k/include/mcontext.h Thu Feb 24 04:28:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.7 2011/02/23 02:58:39 joerg Exp $ */ +/* $NetBSD: mcontext.h,v 1.8 2011/02/24 04:28:46 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -79,7 +79,7 @@ __gregset_t __gregs; /* General Register set */ __fpregset_t __fpregs; /* Floating Point Register set */ union { - long __mc_state[202]; /* Only need 308 bytes... */ + long __mc_state[201]; /* Only need 308 bytes... */ #if defined(_KERNEL) || defined(__M68K_MCONTEXT_PRIVATE) struct { /* Rest of the frame. */ @@ -92,12 +92,14 @@ } __mc_frame; #endif /* _KERNEL || __M68K_MCONTEXT_PRIVATE */ } __mc_pad; + __greg_t _mc_tlsbase; } mcontext_t; /* Note: no additional padding is to be performed in ucontext_t. */ /* Machine-specific uc_flags value */ #define _UC_M68K_UC_USER 0x40000000 +#define _UC_TLSBASE 0x00080000 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_A7]) #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC]) Index: src/sys/arch/m68k/m68k/sig_machdep.c diff -u src/sys/arch/m68k/m68k/sig_machdep.c:1.45 src/sys/arch/m68k/m68k/sig_machdep.c:1.46 --- src/sys/arch/m68k/m68k/sig_machdep.c:1.45 Tue Feb 8 20:20:16 2011 +++ src/sys/arch/m68k/m68k/sig_machdep.c Thu Feb 24 04:28:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sig_machdep.c,v 1.45 2011/02/08 20:20:16 rmind Exp $ */ +/* $NetBSD: sig_machdep.c,v 1.46 2011/02/24 04:28:46 joerg Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -40,7 +40,7 @@ #include "opt_m68k_arch.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.45 2011/02/08 20:20:16 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.46 2011/02/24 04:28:46 joerg Exp $"); #define __M68K_SIGNAL_PRIVATE @@ -261,6 +261,9 @@ *flags |= _UC_CPU; + mcp->_mc_tlsbase = (uintptr_t)l->l_private; + *flags |= _UC_TLSBASE; + /* Save exception frame information. */ mcp->__mc_pad.__mc_frame.__mcf_format = format; if (format >= FMT4) { @@ -421,6 +424,9 @@ m68881_restore(fpf); } + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + mutex_enter(l->l_proc->p_lock); if (flags & _UC_SETSTACK) l->l_sigstk.ss_flags |= SS_ONSTACK; Index: src/sys/arch/mips/include/mcontext.h diff -u src/sys/arch/mips/include/mcontext.h:1.14 src/sys/arch/mips/include/mcontext.h:1.15 --- src/sys/arch/mips/include/mcontext.h:1.14 Thu Feb 24 00:40:09 2011 +++ src/sys/arch/mips/include/mcontext.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.14 2011/02/24 00:40:09 matt Exp $ */ +/* $NetBSD: mcontext.h,v 1.15 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc. @@ -125,6 +125,10 @@ typedef struct { __gregset_t __gregs; __fpregset_t __fpregs; + __greg_t _mc_tlsbase; +#if !__mips_n32 + __greg_t __mc_unused; +#endif } mcontext_t; #if defined(_KERNEL) && !defined(__mips_o32) @@ -134,22 +138,25 @@ typedef struct { __gregset32_t __gregs; struct __fpregset_oabi __fpregs; + __greg32_t _mc_tlsbase; + __greg32_t __mc_unused; } mcontext_o32_t; typedef struct { __gregset_t __gregs; struct __fpregset_nabi __fpregs; + __greg_t _mc_tlsbase; } mcontext32_t; #endif /* _KERNEL && _LP64 */ #endif /* !__ASSEMBLER__ */ -#define _UC_MACHINE_PAD 16 /* Padding appended to ucontext_t */ -#define _UC_MACHINE32_PAD 16 /* Padding appended to ucontext_t */ +#define _UC_MACHINE_PAD 14 /* Padding appended to ucontext_t */ #define _UC_SETSTACK 0x00010000 #define _UC_CLRSTACK 0x00020000 +#define _UC_TLSBASE 0x00040000 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP]) #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EPC]) @@ -160,12 +167,13 @@ #define _UC_MACHINE32_SP(uc) _UC_MACHINE_SP(uc) #define _UC_MACHINE32_PC(uc) _UC_MACHINE_PC(uc) #define _UC_MACHINE32_INTRV(uc) _UC_MACHINE_INTRV(uc) +#define _UC_MACHINE32_PAD 14 /* Padding appended to ucontext32_t */ #define _UC_MACHINE32_SET_PC(uc, pc) _UC_MACHINE_PC((uc), (pc)) -#define __UCONTEXT_SIZE_O32 (40 + 288 + 64) /* 392 */ -#define __UCONTEXT_SIZE_N32 (40 + 560 + 64) /* 664 */ -#define __UCONTEXT_SIZE_N64 (56 + 560 + 128) /* 774 */ +#define __UCONTEXT_SIZE_O32 (40 + 296 + 56) /* 392 */ +#define __UCONTEXT_SIZE_N32 (40 + 568 + 56) /* 664 */ +#define __UCONTEXT_SIZE_N64 (56 + 576 + 112) /* 774 */ #ifdef __mips_o32 #define __UCONTEXT_SIZE __UCONTEXT_SIZE_O32 @@ -178,4 +186,16 @@ #error O64 is not supported #endif +#ifndef __ASSEMBLER__ +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__tcb; + + __asm volatile(".set push; .set mips32r2; " + "rdhwr %0, $29; .set pop" : "=v"(__tcb)); + return __tcb; +} +#endif + #endif /* _MIPS_MCONTEXT_H_ */ Index: src/sys/arch/mips/include/types.h diff -u src/sys/arch/mips/include/types.h:1.48 src/sys/arch/mips/include/types.h:1.49 --- src/sys/arch/mips/include/types.h:1.48 Sun Feb 20 16:03:49 2011 +++ src/sys/arch/mips/include/types.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.48 2011/02/20 16:03:49 rmind Exp $ */ +/* $NetBSD: types.h,v 1.49 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -148,6 +148,9 @@ #define __HAVE_CPU_COUNTER #endif #define __HAVE_CPU_UAREA_ROUTINES +#if 0 +#define __HAVE___LWP_GETPRIVATE_FAST +#endif #if !defined(__mips_o32) #define __HAVE_ATOMIC64_OPS Index: src/sys/arch/mips/mips/cpu_subr.c diff -u src/sys/arch/mips/mips/cpu_subr.c:1.3 src/sys/arch/mips/mips/cpu_subr.c:1.4 --- src/sys/arch/mips/mips/cpu_subr.c:1.3 Sun Feb 20 16:38:13 2011 +++ src/sys/arch/mips/mips/cpu_subr.c Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_subr.c,v 1.3 2011/02/20 16:38:13 rmind Exp $ */ +/* $NetBSD: cpu_subr.c,v 1.4 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.3 2011/02/20 16:38:13 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.4 2011/02/24 04:28:47 joerg Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -367,6 +367,9 @@ *flags |= _UC_CPU; + mcp->_mc_tlsbase = (uintptr_t)l->l_private; + *flags |= _UC_TLSBASE; + /* Save floating point register context, if any. */ if (fpu_used_p(l)) { size_t fplen; @@ -450,6 +453,9 @@ memcpy(&pcb->pcb_fpregs, &mcp->__fpregs, fplen); } + if ((flags & _UC_TLSBASE) != 0) + lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase); + mutex_enter(p->p_lock); if (flags & _UC_SETSTACK) l->l_sigstk.ss_flags |= SS_ONSTACK; Index: src/sys/arch/mips/mips/netbsd32_machdep.c diff -u src/sys/arch/mips/mips/netbsd32_machdep.c:1.5 src/sys/arch/mips/mips/netbsd32_machdep.c:1.6 --- src/sys/arch/mips/mips/netbsd32_machdep.c:1.5 Sun Feb 20 07:45:48 2011 +++ src/sys/arch/mips/mips/netbsd32_machdep.c Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.5 2011/02/20 07:45:48 matt Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.6 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.5 2011/02/20 07:45:48 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.6 2011/02/24 04:28:47 joerg Exp $"); #include "opt_compat_netbsd.h" #include "opt_sa.h" @@ -262,6 +262,8 @@ if (*flagsp & _UC_FPU) memcpy(&mco32->__fpregs, &mc.__fpregs, sizeof(struct fpreg_oabi)); + mco32->_mc_tlsbase = mc._mc_tlsbase; + *flagsp |= _UC_TLSBASE; } int @@ -279,6 +281,7 @@ if (flags & _UC_FPU) memcpy(&mc.__fpregs, &mco32->__fpregs, sizeof(struct fpreg_oabi)); + mc._mc_tlsbase = mco32->_mc_tlsbase; return cpu_setmcontext(l, &mc, flags); } Index: src/sys/arch/powerpc/include/mcontext.h diff -u src/sys/arch/powerpc/include/mcontext.h:1.10 src/sys/arch/powerpc/include/mcontext.h:1.11 --- src/sys/arch/powerpc/include/mcontext.h:1.10 Tue Feb 1 01:21:29 2011 +++ src/sys/arch/powerpc/include/mcontext.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.10 2011/02/01 01:21:29 matt Exp $ */ +/* $NetBSD: mcontext.h,v 1.11 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -122,4 +122,13 @@ #define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc) +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__tcb; + __asm("mr %r2, %%0" : "=r"(__tcb)); + + return __tcb; +} + #endif /* !_POWERPC_MCONTEXT_H_ */ Index: src/sys/arch/powerpc/include/types.h diff -u src/sys/arch/powerpc/include/types.h:1.36 src/sys/arch/powerpc/include/types.h:1.37 --- src/sys/arch/powerpc/include/types.h:1.36 Wed Dec 22 01:03:03 2010 +++ src/sys/arch/powerpc/include/types.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.36 2010/12/22 01:03:03 matt Exp $ */ +/* $NetBSD: types.h,v 1.37 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (C) 1995 Wolfgang Solfrank. @@ -78,5 +78,8 @@ #ifdef _LP64 #define __HAVE_ATOMIC64_OPS #endif +#if 0 +#define __HAVE___LWP_GETPRIVATE_FAST +#endif #endif /* _MACHTYPES_H_ */ Index: src/sys/arch/sh3/include/mcontext.h diff -u src/sys/arch/sh3/include/mcontext.h:1.7 src/sys/arch/sh3/include/mcontext.h:1.8 --- src/sys/arch/sh3/include/mcontext.h:1.7 Sun Jun 1 23:07:20 2008 +++ src/sys/arch/sh3/include/mcontext.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.7 2008/06/01 23:07:20 uwe Exp $ */ +/* $NetBSD: mcontext.h,v 1.8 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -93,5 +93,14 @@ #define _UC_SETSTACK 0x10000 #define _UC_CLRSTACK 0x20000 +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__gbr; + + __asm volatile("stc gbr, %0" : "=r" (__gbr)); + + return __gbr; +} #endif /* !_SH3_MCONTEXT_H_ */ Index: src/sys/arch/sh3/include/types.h diff -u src/sys/arch/sh3/include/types.h:1.30 src/sys/arch/sh3/include/types.h:1.31 --- src/sys/arch/sh3/include/types.h:1.30 Wed Dec 22 02:41:12 2010 +++ src/sys/arch/sh3/include/types.h Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.30 2010/12/22 02:41:12 matt Exp $ */ +/* $NetBSD: types.h,v 1.31 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -77,4 +77,7 @@ #define __HAVE_RAS #endif +#define __HAVE_CPU_LWP_SETPRIVATE +#define __HAVE___LWP_GETPRIVATE_FAST + #endif /* !_SH3_TYPES_H_ */ Index: src/sys/arch/sh3/sh3/sh3_machdep.c diff -u src/sys/arch/sh3/sh3/sh3_machdep.c:1.90 src/sys/arch/sh3/sh3/sh3_machdep.c:1.91 --- src/sys/arch/sh3/sh3/sh3_machdep.c:1.90 Fri Jan 28 21:06:08 2011 +++ src/sys/arch/sh3/sh3/sh3_machdep.c Thu Feb 24 04:28:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sh3_machdep.c,v 1.90 2011/01/28 21:06:08 uwe Exp $ */ +/* $NetBSD: sh3_machdep.c,v 1.91 2011/02/24 04:28:47 joerg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2002 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.90 2011/01/28 21:06:08 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.91 2011/02/24 04:28:47 joerg Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -88,6 +88,7 @@ #include <sys/savar.h> #include <sys/syscallargs.h> #include <sys/ucontext.h> +#include <sys/cpu.h> #ifdef KGDB #include <sys/kgdb.h> @@ -514,6 +515,8 @@ tf->tf_r1 = gr[_REG_R1]; tf->tf_r0 = gr[_REG_R0]; tf->tf_r15 = gr[_REG_R15]; + + lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_GBR]); } #if 0 @@ -586,3 +589,11 @@ #endif /* NOTREACHED */ } + +int +cpu_lwp_setprivate(lwp_t *l, void *addr) +{ + + l->l_md.md_regs->tf_gbr = (int)addr; + return 0; +} Index: src/sys/arch/sparc/include/mcontext.h diff -u src/sys/arch/sparc/include/mcontext.h:1.10 src/sys/arch/sparc/include/mcontext.h:1.11 --- src/sys/arch/sparc/include/mcontext.h:1.10 Sun Oct 26 06:58:02 2008 +++ src/sys/arch/sparc/include/mcontext.h Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mcontext.h,v 1.10 2008/10/26 06:58:02 mrg Exp $ */ +/* $NetBSD: mcontext.h,v 1.11 2011/02/24 04:28:48 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -160,4 +160,14 @@ (uc)->uc_mcontext.__gregs[_REG_nPC] = (pc) + 4; \ } while (/*CONSTCOND*/0) +static inline void * +__lwp_getprivate_fast(void) +{ + register void *__tmp; + + __asm volatile("mov %%g7, %0" : "=r" (__tmp)); + + return __tmp; +} + #endif /* !_SPARC_MCONTEXT_H_ */ Index: src/sys/arch/sparc/include/types.h diff -u src/sys/arch/sparc/include/types.h:1.55 src/sys/arch/sparc/include/types.h:1.56 --- src/sys/arch/sparc/include/types.h:1.55 Sun Dec 26 12:06:56 2010 +++ src/sys/arch/sparc/include/types.h Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.55 2010/12/26 12:06:56 martin Exp $ */ +/* $NetBSD: types.h,v 1.56 2011/02/24 04:28:48 joerg Exp $ */ /* * Copyright (c) 1992, 1993 @@ -127,5 +127,9 @@ #endif #endif +#define __HAVE_CPU_LWP_SETPRIVATE +#if 0 +#define __HAVE___LWP_GETPRIVATE_FAST +#endif #endif /* _MACHTYPES_H_ */ Index: src/sys/arch/sparc/sparc/machdep.c diff -u src/sys/arch/sparc/sparc/machdep.c:1.305 src/sys/arch/sparc/sparc/machdep.c:1.306 --- src/sys/arch/sparc/sparc/machdep.c:1.305 Fri Jan 14 02:06:31 2011 +++ src/sys/arch/sparc/sparc/machdep.c Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.305 2011/01/14 02:06:31 rmind Exp $ */ +/* $NetBSD: machdep.c,v 1.306 2011/02/24 04:28:48 joerg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.305 2011/01/14 02:06:31 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.306 2011/02/24 04:28:48 joerg Exp $"); #include "opt_compat_netbsd.h" #include "opt_compat_sunos.h" @@ -777,6 +777,8 @@ tf->tf_out[5] = r[_REG_O5]; tf->tf_out[6] = r[_REG_O6]; tf->tf_out[7] = r[_REG_O7]; + + lwp_setprivate(l, (void *)(uintptr_t)r[_REG_G7]); } #ifdef FPU_CONTEXT Index: src/sys/arch/sparc/sparc/vm_machdep.c diff -u src/sys/arch/sparc/sparc/vm_machdep.c:1.104 src/sys/arch/sparc/sparc/vm_machdep.c:1.105 --- src/sys/arch/sparc/sparc/vm_machdep.c:1.104 Thu Feb 10 14:46:47 2011 +++ src/sys/arch/sparc/sparc/vm_machdep.c Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.104 2011/02/10 14:46:47 pooka Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.105 2011/02/24 04:28:48 joerg Exp $ */ /* * Copyright (c) 1996 @@ -49,7 +49,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.104 2011/02/10 14:46:47 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.105 2011/02/24 04:28:48 joerg Exp $"); #include "opt_multiprocessor.h" @@ -62,6 +62,7 @@ #include <sys/exec.h> #include <sys/vnode.h> #include <sys/simplelock.h> +#include <sys/cpu.h> #include <uvm/uvm_extern.h> @@ -344,3 +345,13 @@ pcb->pcb_psr &= ~PSR_CWP; /* Run in window #0 */ pcb->pcb_wim = 1; /* Fence at window #1 */ } + +int +cpu_lwp_setprivate(lwp_t *l, void *addr) +{ + struct trapframe *tf = l->l_md.md_tf; + + tf->tf_global[7] = (uintptr_t)addr; + + return 0; +} Index: src/sys/arch/sparc64/sparc64/netbsd32_machdep.c diff -u src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.93 src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.94 --- src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.93 Fri Jan 14 02:06:32 2011 +++ src/sys/arch/sparc64/sparc64/netbsd32_machdep.c Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.93 2011/01/14 02:06:32 rmind Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.94 2011/02/24 04:28:48 joerg Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.93 2011/01/14 02:06:32 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.94 2011/02/24 04:28:48 joerg Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -1228,6 +1228,8 @@ tf->tf_out[7] = (uint64_t)gr[_REG32_O7]; /* %asi restored above; %fprs not yet supported. */ + lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_G7]); + /* XXX mcp->__gwins */ } Index: src/sys/arch/sparc64/sparc64/vm_machdep.c diff -u src/sys/arch/sparc64/sparc64/vm_machdep.c:1.95 src/sys/arch/sparc64/sparc64/vm_machdep.c:1.96 --- src/sys/arch/sparc64/sparc64/vm_machdep.c:1.95 Thu Feb 10 14:46:47 2011 +++ src/sys/arch/sparc64/sparc64/vm_machdep.c Thu Feb 24 04:28:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.95 2011/02/10 14:46:47 pooka Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.96 2011/02/24 04:28:48 joerg Exp $ */ /* * Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved. @@ -50,7 +50,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.95 2011/02/10 14:46:47 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.96 2011/02/24 04:28:48 joerg Exp $"); #include "opt_multiprocessor.h" @@ -61,6 +61,7 @@ #include <sys/buf.h> #include <sys/exec.h> #include <sys/vnode.h> +#include <sys/cpu.h> #include <uvm/uvm_extern.h> @@ -354,3 +355,13 @@ if ((fs = l->l_md.md_fpstate) != NULL) pool_cache_put(fpstate_cache, fs); } + +int +cpu_lwp_setprivate(lwp_t *l, void *addr) +{ + struct trapframe *tf = l->l_md.md_tf; + + tf->tf_global[7] = (uintptr_t)addr; + + return 0; +}