diff --git a/sys/arch/sparc/include/proc.h b/sys/arch/sparc/include/proc.h index 4e0b7696258b..446b13e61f9c 100644 --- a/sys/arch/sparc/include/proc.h +++ b/sys/arch/sparc/include/proc.h @@ -1,4 +1,4 @@ -/* $NetBSD: proc.h,v 1.9 2003/01/06 18:32:32 pk Exp $ */ +/* $NetBSD: proc.h,v 1.10 2003/01/12 16:29:01 pk Exp $ */ /* * Copyright (c) 1992, 1993 @@ -57,7 +57,16 @@ struct mdproc { /* md_flags */ #define MDP_FIXALIGN 0x1 /* Fix unaligned memory accesses */ -/* FPU context switch lock */ +/* + * FPU context switch lock + * Prevent interrupts that grab the kernel lock + */ extern struct simplelock fpulock; -#define FPU_LOCK() simple_lock(&fpulock) -#define FPU_UNLOCK() simple_unlock(&fpulock) +#define FPU_LOCK(s) do { \ + s = splclock(); \ + simple_lock(&fpulock); \ +} while (/* CONSTCOND */ 0) +#define FPU_UNLOCK(s) do { \ + simple_unlock(&fpulock); \ + splx(s); \ +} while (/* CONSTCOND */ 0) diff --git a/sys/arch/sparc/sparc/machdep.c b/sys/arch/sparc/sparc/machdep.c index 6129e37c7de9..364c18381ecb 100644 --- a/sys/arch/sparc/sparc/machdep.c +++ b/sys/arch/sparc/sparc/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.215 2003/01/09 04:58:58 mrg Exp $ */ +/* $NetBSD: machdep.c,v 1.216 2003/01/12 16:29:01 pk Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -396,7 +396,6 @@ setregs(p, pack, stack) struct trapframe *tf = p->p_md.md_tf; struct fpstate *fs; int psr; - int s; /* Don't allow misaligned code by default */ p->p_md.md_flags &= ~MDP_FIXALIGN; @@ -411,13 +410,13 @@ setregs(p, pack, stack) psr = tf->tf_psr & (PSR_S | PSR_CWP); if ((fs = p->p_md.md_fpstate) != NULL) { struct cpu_info *cpi; + int s; /* * We hold an FPU state. If we own *some* FPU chip state * we must get rid of it, and the only way to do that is * to save it. In any case, get rid of our FPU state. */ - s = splclock(); - FPU_LOCK(); + FPU_LOCK(s); if ((cpi = p->p_md.md_fpu) != NULL) { if (cpi->fpproc != p) panic("FPU(%d): fpproc %p", @@ -431,8 +430,7 @@ setregs(p, pack, stack) cpi->fpproc = NULL; } p->p_md.md_fpu = NULL; - FPU_UNLOCK(); - splx(s); + FPU_UNLOCK(s); free((void *)fs, M_SUBPROC); p->p_md.md_fpstate = NULL; } diff --git a/sys/arch/sparc/sparc/trap.c b/sys/arch/sparc/sparc/trap.c index 7fbadcd62fb6..80ca0a8be3de 100644 --- a/sys/arch/sparc/sparc/trap.c +++ b/sys/arch/sparc/sparc/trap.c @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.127 2003/01/10 16:34:15 pk Exp $ */ +/* $NetBSD: trap.c,v 1.128 2003/01/12 16:29:00 pk Exp $ */ /* * Copyright (c) 1996 @@ -470,10 +470,8 @@ badtrap: if (cpuinfo.fpproc != p) { /* we do not have it */ struct cpu_info *cpi; - int s; - s = splclock(); - FPU_LOCK(); + FPU_LOCK(s); if (cpuinfo.fpproc != NULL) { /* someone else had it*/ savefpstate(cpuinfo.fpproc->p_md.md_fpstate); cpuinfo.fpproc->p_md.md_fpu = NULL; @@ -495,8 +493,7 @@ badtrap: loadfpstate(fs); cpuinfo.fpproc = p; /* now we do have it */ p->p_md.md_fpu = curcpu(); - FPU_UNLOCK(); - splx(s); + FPU_UNLOCK(s); } tf->tf_psr |= PSR_EF; break; @@ -597,13 +594,11 @@ badtrap: */ if (p != cpuinfo.fpproc) panic("fpe without being the FP user"); - s = splclock(); - FPU_LOCK(); + FPU_LOCK(s); savefpstate(p->p_md.md_fpstate); cpuinfo.fpproc = NULL; p->p_md.md_fpu = NULL; - FPU_UNLOCK(); - splx(s); + FPU_UNLOCK(s); /* tf->tf_psr &= ~PSR_EF; */ /* share_fpu will do this */ fpu_cleanup(p, p->p_md.md_fpstate); /* fpu_cleanup posts signals if needed */ diff --git a/sys/arch/sparc/sparc/vm_machdep.c b/sys/arch/sparc/sparc/vm_machdep.c index 450837b61c50..9f2c923ffe2c 100644 --- a/sys/arch/sparc/sparc/vm_machdep.c +++ b/sys/arch/sparc/sparc/vm_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.69 2003/01/09 05:27:09 mrg Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.70 2003/01/12 16:29:01 pk Exp $ */ /* * Copyright (c) 1996 @@ -238,8 +238,7 @@ cpu_fork(p1, p2, stack, stacksize, func, arg) p2->p_md.md_fpstate = malloc(sizeof(struct fpstate), M_SUBPROC, M_WAITOK); - s = splclock(); - FPU_LOCK(); + FPU_LOCK(s); if ((cpi = p1->p_md.md_fpu) != NULL) { if (cpi->fpproc != p1) panic("FPU(%d): fpproc %p", @@ -254,8 +253,7 @@ cpu_fork(p1, p2, stack, stacksize, func, arg) } bcopy(p1->p_md.md_fpstate, p2->p_md.md_fpstate, sizeof(struct fpstate)); - FPU_UNLOCK(); - splx(s); + FPU_UNLOCK(s); } else p2->p_md.md_fpstate = NULL; @@ -322,8 +320,7 @@ cpu_exit(p) struct cpu_info *cpi; int s; - s = splclock(); - FPU_LOCK(); + FPU_LOCK(s); if ((cpi = p->p_md.md_fpu) != NULL) { if (cpi->fpproc != p) panic("FPU(%d): fpproc %p", @@ -336,8 +333,7 @@ cpu_exit(p) #endif cpi->fpproc = NULL; } - FPU_UNLOCK(); - splx(s); + FPU_UNLOCK(s); free((void *)fs, M_SUBPROC); } switchexit(p);