diff options
-rw-r--r-- | sys/arch/hppa/conf/files.hppa | 3 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/fpu.c | 53 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/hpux_machdep.c | 13 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/machdep.c | 35 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/process_machdep.c | 15 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/vm_machdep.c | 17 | ||||
-rw-r--r-- | sys/arch/hppa/include/fpu.h | 25 |
7 files changed, 104 insertions, 57 deletions
diff --git a/sys/arch/hppa/conf/files.hppa b/sys/arch/hppa/conf/files.hppa index e1e35c1d3d8..ec867b7af24 100644 --- a/sys/arch/hppa/conf/files.hppa +++ b/sys/arch/hppa/conf/files.hppa @@ -1,4 +1,4 @@ -# $OpenBSD: files.hppa,v 1.82 2010/05/21 15:24:29 jsing Exp $ +# $OpenBSD: files.hppa,v 1.83 2010/06/29 04:03:21 jsing Exp $ # # hppa-specific configuration info @@ -307,6 +307,7 @@ file arch/hppa/hppa/conf.c file arch/hppa/hppa/db_interface.c ddb file arch/hppa/hppa/db_disasm.c ddb file arch/hppa/hppa/disksubr.c disk +file arch/hppa/hppa/fpu.c file arch/hppa/hppa/ipi.c multiprocessor file arch/hppa/hppa/lock_machdep.c multiprocessor file arch/hppa/hppa/machdep.c diff --git a/sys/arch/hppa/hppa/fpu.c b/sys/arch/hppa/hppa/fpu.c new file mode 100644 index 00000000000..2661ea92551 --- /dev/null +++ b/sys/arch/hppa/hppa/fpu.c @@ -0,0 +1,53 @@ +/* $OpenBSD: fpu.c,v 1.1 2010/06/29 04:03:21 jsing Exp $ */ + +/* + * Copyright (c) 2010 Joel Sing <jsing@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> + +#include <machine/cpu.h> +#include <machine/cpufunc.h> +#include <machine/fpu.h> +#include <machine/pcb.h> +#include <machine/reg.h> + +void +fpu_proc_flush(struct proc *p) +{ + struct cpu_info *ci = curcpu(); + + /* Flush process FPU state from CPU. */ + if (p->p_md.md_regs->tf_cr30 == ci->ci_fpu_state) { + fpu_exit(); + ci->ci_fpu_state = 0; + } +} + +void +fpu_proc_save(struct proc *p) +{ + struct cpu_info *ci = curcpu(); + extern u_int fpu_enable; + + /* Save process FPU state. */ + if (p->p_md.md_regs->tf_cr30 == ci->ci_fpu_state) { + mtctl(fpu_enable, CR_CCR); + fpu_save(ci->ci_fpu_state); + mtctl(0, CR_CCR); + } +} diff --git a/sys/arch/hppa/hppa/hpux_machdep.c b/sys/arch/hppa/hppa/hpux_machdep.c index 6483ea25c02..fdfbe0b17ef 100644 --- a/sys/arch/hppa/hppa/hpux_machdep.c +++ b/sys/arch/hppa/hppa/hpux_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hpux_machdep.c,v 1.5 2010/06/29 00:50:40 jsing Exp $ */ +/* $OpenBSD: hpux_machdep.c,v 1.6 2010/06/29 04:03:21 jsing Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -37,9 +37,10 @@ #include <compat/hpux/hpux_util.h> #include <compat/hpux/hpux_syscallargs.h> -#include <machine/hpux_machdep.h> #include <machine/cpufunc.h> +#include <machine/fpu.h> #include <machine/frame.h> +#include <machine/hpux_machdep.h> int hpux_cpu_sysconf_arch(void) @@ -119,11 +120,9 @@ hpux_setregs(struct proc *p, struct exec_package *pack, u_long stack, pcb->pcb_fpregs->fpr_regs[1] = 0; pcb->pcb_fpregs->fpr_regs[2] = 0; pcb->pcb_fpregs->fpr_regs[3] = 0; - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - curcpu()->ci_fpu_state = 0; - /* force an fpu ctxsw, we won't be hugged by the cpu_switch */ - mtctl(0, CR_CCR); - } + + fpu_proc_flush(p); + retval[1] = 0; } diff --git a/sys/arch/hppa/hppa/machdep.c b/sys/arch/hppa/hppa/machdep.c index 57b2a26de6c..628b605adff 100644 --- a/sys/arch/hppa/hppa/machdep.c +++ b/sys/arch/hppa/hppa/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.190 2010/06/29 00:50:40 jsing Exp $ */ +/* $OpenBSD: machdep.c,v 1.191 2010/06/29 04:03:21 jsing Exp $ */ /* * Copyright (c) 1999-2003 Michael Shalayeff @@ -65,6 +65,7 @@ #include <machine/cpufunc.h> #include <machine/autoconf.h> #include <machine/kcore.h> +#include <machine/fpu.h> #ifdef COMPAT_HPUX #include <compat/hpux/hpux.h> @@ -1220,10 +1221,7 @@ setregs(p, pack, stack, retval) copyout(&zero, (caddr_t)(stack + HPPA_FRAME_CRP), sizeof(register_t)); /* reset any of the pending FPU exceptions */ - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - fpu_exit(); - curcpu()->ci_fpu_state = 0; - } + fpu_proc_flush(p); pcb->pcb_fpregs->fpr_regs[0] = ((u_int64_t)HPPA_FPU_INIT) << 32; pcb->pcb_fpregs->fpr_regs[1] = 0; pcb->pcb_fpregs->fpr_regs[2] = 0; @@ -1245,7 +1243,6 @@ sendsig(catcher, sig, mask, code, type, val) int type; union sigval val; { - extern u_int fpu_enable; struct proc *p = curproc; struct trapframe *tf = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; @@ -1261,13 +1258,8 @@ sendsig(catcher, sig, mask, code, type, val) p->p_comm, p->p_pid, sig, catcher); #endif - /* flush the FPU ctx first */ - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - mtctl(fpu_enable, CR_CCR); - fpu_save(curcpu()->ci_fpu_state); - /* fpu_curpcb = 0; only needed if fpregs are preset */ - mtctl(0, CR_CCR); - } + /* Save the FPU context first. */ + fpu_proc_save(p); ksc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; @@ -1392,11 +1384,8 @@ sys_sigreturn(p, v, retval) printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp); #endif - /* flush the FPU ctx first */ - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - fpu_exit(); - curcpu()->ci_fpu_state = 0; - } + /* Flush the FPU context first. */ + fpu_proc_flush(p); if ((error = copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))) return (error); @@ -1471,7 +1460,6 @@ void hpux_sendsig(sig_t catcher, int sig, int mask, u_long code, int type, union sigval val) { - extern u_int fpu_enable; struct proc *p = curproc; struct pcb *pcb = &p->p_addr->u_pcb; struct trapframe *tf = p->p_md.md_regs; @@ -1485,13 +1473,8 @@ hpux_sendsig(sig_t catcher, int sig, int mask, u_long code, int type, printf("hpux_sendsig: %s[%d] sig %d catcher %p\n", p->p_comm, p->p_pid, sig, catcher); #endif - /* flush the FPU ctx first */ - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - mtctl(fpu_enable, CR_CCR); - fpu_save(curcpu()->ci_fpu_state); - curcpu()->ci_fpu_state = 0; - mtctl(0, CR_CCR); - } + /* Save the FPU context first. */ + fpu_proc_save(p); bzero(&hsc, sizeof hsc); hsc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; diff --git a/sys/arch/hppa/hppa/process_machdep.c b/sys/arch/hppa/hppa/process_machdep.c index 7d9cadc7a6f..6276978e595 100644 --- a/sys/arch/hppa/hppa/process_machdep.c +++ b/sys/arch/hppa/hppa/process_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process_machdep.c,v 1.17 2010/06/29 00:50:40 jsing Exp $ */ +/* $OpenBSD: process_machdep.c,v 1.18 2010/06/29 04:03:21 jsing Exp $ */ /* * Copyright (c) 1999-2004 Michael Shalayeff @@ -34,6 +34,7 @@ #include <sys/user.h> #include <machine/cpufunc.h> +#include <machine/fpu.h> #include <machine/frame.h> int @@ -86,13 +87,8 @@ process_read_fpregs(p, fpregs) struct proc *p; struct fpreg *fpregs; { - extern u_int fpu_enable; + fpu_proc_save(p); - if (p->p_md.md_regs->tf_cr30 == curcpu()->ci_fpu_state) { - mtctl(fpu_enable, CR_CCR); - fpu_save(curcpu()->ci_fpu_state); - mtctl(0, CR_CCR); - } bcopy(p->p_addr->u_pcb.pcb_fpregs, fpregs, 32 * 8); return (0); @@ -150,10 +146,7 @@ process_write_fpregs(p, fpregs) struct proc *p; struct fpreg *fpregs; { - if (p->p_md.md_regs->tf_cr30 == curcpu()->ci_fpu_state) { - fpu_exit(); - curcpu()->ci_fpu_state = 0; - } + fpu_proc_flush(p); bcopy(fpregs, p->p_addr->u_pcb.pcb_fpregs, 32 * 8); diff --git a/sys/arch/hppa/hppa/vm_machdep.c b/sys/arch/hppa/hppa/vm_machdep.c index a3dbef8b224..9f6ab53994f 100644 --- a/sys/arch/hppa/hppa/vm_machdep.c +++ b/sys/arch/hppa/hppa/vm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_machdep.c,v 1.71 2010/06/29 00:50:40 jsing Exp $ */ +/* $OpenBSD: vm_machdep.c,v 1.72 2010/06/29 04:03:22 jsing Exp $ */ /* * Copyright (c) 1999-2004 Michael Shalayeff @@ -41,6 +41,7 @@ #include <sys/pool.h> #include <machine/cpufunc.h> +#include <machine/fpu.h> #include <machine/pmap.h> #include <machine/pcb.h> @@ -100,7 +101,6 @@ cpu_fork(p1, p2, stack, stacksize, func, arg) void (*func)(void *); void *arg; { - extern u_int fpu_enable; struct pcb *pcbp; struct trapframe *tf; register_t sp, osp; @@ -109,11 +109,7 @@ cpu_fork(p1, p2, stack, stacksize, func, arg) if (round_page(sizeof(struct user)) > NBPG) panic("USPACE too small for user"); #endif - if (p1->p_md.md_regs->tf_cr30 == curcpu()->ci_fpu_state) { - mtctl(fpu_enable, CR_CCR); - fpu_save(curcpu()->ci_fpu_state); - mtctl(0, CR_CCR); - } + fpu_proc_save(p1); pcbp = &p2->p_addr->u_pcb; bcopy(&p1->p_addr->u_pcb, pcbp, sizeof(*pcbp)); @@ -178,13 +174,10 @@ void cpu_exit(p) struct proc *p; { - struct trapframe *tf = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; - if (tf->tf_cr30 == curcpu()->ci_fpu_state) { - fpu_exit(); - curcpu()->ci_fpu_state = 0; - } + fpu_proc_flush(p); + pool_put(&hppa_fppl, pcb->pcb_fpregs); pmap_deactivate(p); diff --git a/sys/arch/hppa/include/fpu.h b/sys/arch/hppa/include/fpu.h new file mode 100644 index 00000000000..65b3e519c69 --- /dev/null +++ b/sys/arch/hppa/include/fpu.h @@ -0,0 +1,25 @@ +/* $OpenBSD: fpu.h,v 1.1 2010/06/29 04:03:22 jsing Exp $ */ + +/* + * Copyright (c) 2010 Joel Sing <jsing@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_FPU_H_ +#define _MACHINE_FPU_H_ + +void fpu_proc_save(struct proc *); +void fpu_proc_flush(struct proc *); + +#endif /* _MACHINE_FPU_H_ */ |