Thu Dec 8 21:00:50 2011 UTC ()
Track if we saved l_private in the mcontext and don't blindly restore it.

This fixes the tests in /usr/tests/lib/libc/setjmp/t_threadjmp


(skrll)
diff -r1.25 -r1.26 src/sys/arch/hppa/hppa/hppa_machdep.c
diff -r1.6 -r1.7 src/sys/arch/hppa/include/mcontext.h

cvs diff -r1.25 -r1.26 src/sys/arch/hppa/hppa/hppa_machdep.c (expand / switch to unified diff)

--- src/sys/arch/hppa/hppa/hppa_machdep.c 2011/02/24 08:59:22 1.25
+++ src/sys/arch/hppa/hppa/hppa_machdep.c 2011/12/08 21:00:49 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hppa_machdep.c,v 1.25 2011/02/24 08:59:22 skrll Exp $ */ 1/* $NetBSD: hppa_machdep.c,v 1.26 2011/12/08 21:00:49 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: hppa_machdep.c,v 1.25 2011/02/24 08:59:22 skrll Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: hppa_machdep.c,v 1.26 2011/12/08 21:00:49 skrll Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/sa.h> 34#include <sys/sa.h>
35#include <sys/lwp.h> 35#include <sys/lwp.h>
36#include <sys/savar.h> 36#include <sys/savar.h>
37#include <sys/proc.h> 37#include <sys/proc.h>
38#include <sys/ras.h> 38#include <sys/ras.h>
39#include <sys/cpu.h> 39#include <sys/cpu.h>
40 40
41#include <sys/kernel.h> 41#include <sys/kernel.h>
42 42
43#include <uvm/uvm_extern.h> 43#include <uvm/uvm_extern.h>
@@ -191,27 +191,27 @@ cpu_getmcontext(struct lwp *l, mcontext_ @@ -191,27 +191,27 @@ cpu_getmcontext(struct lwp *l, mcontext_
191 gr[_REG_CR27] = tf->tf_cr27; 191 gr[_REG_CR27] = tf->tf_cr27;
192#if 0 192#if 0
193 gr[_REG_CR26] = tf->tf_cr26; 193 gr[_REG_CR26] = tf->tf_cr26;
194#endif 194#endif
195 195
196 ras_pc = (__greg_t)ras_lookup(l->l_proc, 196 ras_pc = (__greg_t)ras_lookup(l->l_proc,
197 (void *)(gr[_REG_PCOQH] & ~HPPA_PC_PRIV_MASK)); 197 (void *)(gr[_REG_PCOQH] & ~HPPA_PC_PRIV_MASK));
198 if (ras_pc != -1) { 198 if (ras_pc != -1) {
199 ras_pc |= HPPA_PC_PRIV_USER; 199 ras_pc |= HPPA_PC_PRIV_USER;
200 gr[_REG_PCOQH] = ras_pc; 200 gr[_REG_PCOQH] = ras_pc;
201 gr[_REG_PCOQT] = ras_pc + 4; 201 gr[_REG_PCOQT] = ras_pc + 4;
202 } 202 }
203 203
204 *flags |= _UC_CPU; 204 *flags |= _UC_CPU | _UC_TLSBASE;
205 205
206 if (l->l_md.md_flags & 0) { 206 if (l->l_md.md_flags & 0) {
207 return; 207 return;
208 } 208 }
209 209
210 hppa_fpu_flush(l); 210 hppa_fpu_flush(l);
211 memcpy(&mcp->__fpregs, pcb->pcb_fpregs, sizeof(mcp->__fpregs)); 211 memcpy(&mcp->__fpregs, pcb->pcb_fpregs, sizeof(mcp->__fpregs));
212 *flags |= _UC_FPU; 212 *flags |= _UC_FPU;
213} 213}
214 214
215int 215int
216cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags) 216cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags)
217{ 217{
@@ -293,39 +293,43 @@ cpu_setmcontext(struct lwp *l, const mco @@ -293,39 +293,43 @@ cpu_setmcontext(struct lwp *l, const mco
293 tf->tf_iioq_tail = gr[_REG_PCOQT]; 293 tf->tf_iioq_tail = gr[_REG_PCOQT];
294 294
295 if (tf->tf_iioq_head >= 0xc0000020) { 295 if (tf->tf_iioq_head >= 0xc0000020) {
296 tf->tf_iioq_head &= ~HPPA_PC_PRIV_MASK; 296 tf->tf_iioq_head &= ~HPPA_PC_PRIV_MASK;
297 } else { 297 } else {
298 tf->tf_iioq_head |= HPPA_PC_PRIV_USER; 298 tf->tf_iioq_head |= HPPA_PC_PRIV_USER;
299 } 299 }
300 if (tf->tf_iioq_tail >= 0xc0000020) { 300 if (tf->tf_iioq_tail >= 0xc0000020) {
301 tf->tf_iioq_tail &= ~HPPA_PC_PRIV_MASK; 301 tf->tf_iioq_tail &= ~HPPA_PC_PRIV_MASK;
302 } else { 302 } else {
303 tf->tf_iioq_tail |= HPPA_PC_PRIV_USER; 303 tf->tf_iioq_tail |= HPPA_PC_PRIV_USER;
304 } 304 }
305 305
306 lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_CR27]); 
307 tf->tf_cr27 = gr[_REG_CR27]; 
308 
309#if 0 306#if 0
310 tf->tf_sr0 = gr[_REG_SR0]; 307 tf->tf_sr0 = gr[_REG_SR0];
311 tf->tf_sr1 = gr[_REG_SR1]; 308 tf->tf_sr1 = gr[_REG_SR1];
312 tf->tf_sr2 = gr[_REG_SR2]; 309 tf->tf_sr2 = gr[_REG_SR2];
313 tf->tf_sr3 = gr[_REG_SR3]; 310 tf->tf_sr3 = gr[_REG_SR3];
314 tf->tf_sr4 = gr[_REG_SR4]; 311 tf->tf_sr4 = gr[_REG_SR4];
315 tf->tf_cr26 = gr[_REG_CR26]; 312 tf->tf_cr26 = gr[_REG_CR26];
316#endif 313#endif
317 } 314 }
318 315
 316 /* Restore the private thread context */
 317 if (flags & _UC_TLSBASE) {
 318 lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_CR27]);
 319 tf->tf_cr27 = gr[_REG_CR27];
 320 }
 321
 322 /* Restore the floating point registers */
319 if ((flags & _UC_FPU) != 0) { 323 if ((flags & _UC_FPU) != 0) {
320 struct pcb *pcb = lwp_getpcb(l); 324 struct pcb *pcb = lwp_getpcb(l);
321 325
322 hppa_fpu_flush(l); 326 hppa_fpu_flush(l);
323 memcpy(pcb->pcb_fpregs, &mcp->__fpregs, sizeof(mcp->__fpregs)); 327 memcpy(pcb->pcb_fpregs, &mcp->__fpregs, sizeof(mcp->__fpregs));
324 } 328 }
325 329
326 mutex_enter(p->p_lock); 330 mutex_enter(p->p_lock);
327 if (flags & _UC_SETSTACK) 331 if (flags & _UC_SETSTACK)
328 l->l_sigstk.ss_flags |= SS_ONSTACK; 332 l->l_sigstk.ss_flags |= SS_ONSTACK;
329 if (flags & _UC_CLRSTACK) 333 if (flags & _UC_CLRSTACK)
330 l->l_sigstk.ss_flags &= ~SS_ONSTACK; 334 l->l_sigstk.ss_flags &= ~SS_ONSTACK;
331 mutex_exit(p->p_lock); 335 mutex_exit(p->p_lock);

cvs diff -r1.6 -r1.7 src/sys/arch/hppa/include/mcontext.h (expand / switch to unified diff)

--- src/sys/arch/hppa/include/mcontext.h 2011/02/25 14:07:12 1.6
+++ src/sys/arch/hppa/include/mcontext.h 2011/12/08 21:00:50 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mcontext.h,v 1.6 2011/02/25 14:07:12 joerg Exp $ */ 1/* $NetBSD: mcontext.h,v 1.7 2011/12/08 21:00:50 skrll Exp $ */
2 2
3#ifndef _HPPA_MCONTEXT_H_ 3#ifndef _HPPA_MCONTEXT_H_
4#define _HPPA_MCONTEXT_H_ 4#define _HPPA_MCONTEXT_H_
5 5
6/* 6/*
7 * General register state 7 * General register state
8 */ 8 */
9#define _NGREG 44 9#define _NGREG 44
10 10
11#define _REG_PSW 0 11#define _REG_PSW 0
12#define _REG_RP 2 12#define _REG_RP 2
13#define _REG_R19 19 13#define _REG_R19 19
14#define _REG_ARG0 26 14#define _REG_ARG0 26
@@ -63,15 +63,16 @@ __lwp_getprivate_fast(void) @@ -63,15 +63,16 @@ __lwp_getprivate_fast(void)
63 register void *__tmp; 63 register void *__tmp;
64 64
65 __asm volatile("mfctl\t27 /* CR_TLS */, %0" : "=r" (__tmp)); 65 __asm volatile("mfctl\t27 /* CR_TLS */, %0" : "=r" (__tmp));
66 66
67 return __tmp; 67 return __tmp;
68} 68}
69 69
70#endif /* !__ASSEMBLER__ */ 70#endif /* !__ASSEMBLER__ */
71 71
72#define _OFFSETOF_UC_GREGS 40 72#define _OFFSETOF_UC_GREGS 40
73 73
74#define _UC_SETSTACK 0x00010000 74#define _UC_SETSTACK 0x00010000
75#define _UC_CLRSTACK 0x00020000 75#define _UC_CLRSTACK 0x00020000
 76#define _UC_TLSBASE 0x00040000
76 77
77#endif /* _HPPA_MCONTEXT_H_ */ 78#endif /* _HPPA_MCONTEXT_H_ */