Module Name: src Committed By: dsl Date: Wed Feb 12 23:24:09 UTC 2014
Modified Files: src/distrib/sets/lists/comp: md.i386 src/sys/arch/amd64/amd64: cpufunc.S src/sys/arch/i386/conf: files.i386 src/sys/arch/i386/i386: autoconf.c cpufunc.S freebsd_machdep.c i386_trap.S ibcs2_machdep.c trap.c src/sys/arch/i386/include: Makefile freebsd_machdep.h pcb.h src/sys/arch/x86/include: cpu.h cpu_extended_state.h cpufunc.h fpu.h src/sys/arch/x86/x86: convert_xmm_s87.c fpu.c procfs_machdep.c src/sys/arch/xen/conf: files.xen src/sys/arch/xen/x86: cpu.c xen_ipi.c Removed Files: src/sys/arch/i386/include: npx.h src/sys/arch/i386/isa: npx.c Log Message: Change i386 to use x86/fpu.c instead of i386/isa/npx.c This changes the trap10 and trap13 code to call directly into fpu.c, removing all the code for T_ARITHTRAP, T_XMM and T_FPUNDA from i386/trap.c Not all of the code thate appeared to handle fpu traps was ever called! Most of the changes just replace the include of machine/npx.h with x86/fpu.h (or remove it entirely). To generate a diff of this commit: cvs rdiff -u -r1.144 -r1.145 src/distrib/sets/lists/comp/md.i386 cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/amd64/cpufunc.S cvs rdiff -u -r1.373 -r1.374 src/sys/arch/i386/conf/files.i386 cvs rdiff -u -r1.99 -r1.100 src/sys/arch/i386/i386/autoconf.c cvs rdiff -u -r1.17 -r1.18 src/sys/arch/i386/i386/cpufunc.S cvs rdiff -u -r1.58 -r1.59 src/sys/arch/i386/i386/freebsd_machdep.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/i386/i386_trap.S cvs rdiff -u -r1.42 -r1.43 src/sys/arch/i386/i386/ibcs2_machdep.c cvs rdiff -u -r1.270 -r1.271 src/sys/arch/i386/i386/trap.c cvs rdiff -u -r1.41 -r1.42 src/sys/arch/i386/include/Makefile cvs rdiff -u -r1.12 -r1.13 src/sys/arch/i386/include/freebsd_machdep.h cvs rdiff -u -r1.35 -r0 src/sys/arch/i386/include/npx.h cvs rdiff -u -r1.51 -r1.52 src/sys/arch/i386/include/pcb.h cvs rdiff -u -r1.153 -r0 src/sys/arch/i386/isa/npx.c cvs rdiff -u -r1.60 -r1.61 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/include/cpu_extended_state.h cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/include/cpufunc.h cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/include/fpu.h cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/convert_xmm_s87.c cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/fpu.c \ src/sys/arch/x86/x86/procfs_machdep.c cvs rdiff -u -r1.132 -r1.133 src/sys/arch/xen/conf/files.xen cvs rdiff -u -r1.97 -r1.98 src/sys/arch/xen/x86/cpu.c cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/xen_ipi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/comp/md.i386 diff -u src/distrib/sets/lists/comp/md.i386:1.144 src/distrib/sets/lists/comp/md.i386:1.145 --- src/distrib/sets/lists/comp/md.i386:1.144 Tue Feb 11 22:48:25 2014 +++ src/distrib/sets/lists/comp/md.i386 Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -# $NetBSD: md.i386,v 1.144 2014/02/11 22:48:25 dsl Exp $ +# $NetBSD: md.i386,v 1.145 2014/02/12 23:24:09 dsl Exp $ ./usr/include/clang-3.0/avx2intrin.h comp-obsolete obsolete ./usr/include/clang-3.0/avxintrin.h comp-obsolete obsolete ./usr/include/clang-3.0/bmi2intrin.h comp-obsolete obsolete @@ -259,7 +259,7 @@ ./usr/include/i386/mtrr.h comp-c-include ./usr/include/i386/multiboot.h comp-c-include ./usr/include/i386/mutex.h comp-c-include -./usr/include/i386/npx.h comp-c-include +./usr/include/i386/npx.h comp-c-include obsolete ./usr/include/i386/param.h comp-c-include ./usr/include/i386/pcb.h comp-c-include ./usr/include/i386/pccons.h comp-obsolete obsolete Index: src/sys/arch/amd64/amd64/cpufunc.S diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.24 src/sys/arch/amd64/amd64/cpufunc.S:1.25 --- src/sys/arch/amd64/amd64/cpufunc.S:1.24 Sun Feb 9 19:42:04 2014 +++ src/sys/arch/amd64/amd64/cpufunc.S Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.S,v 1.24 2014/02/09 19:42:04 dsl Exp $ */ +/* $NetBSD: cpufunc.S,v 1.25 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. @@ -441,6 +441,10 @@ ENTRY(fnstcw) fnstcw (%rdi) ret +ENTRY(fngetsw) + fnstsw %ax + ret + ENTRY(fnstsw) fnstsw (%rdi) ret @@ -480,7 +484,7 @@ ENTRY(fxrstor) ENTRY(fldummy) ffree %st(7) - flds (%rdi) + fldz ret ENTRY(xsave) Index: src/sys/arch/i386/conf/files.i386 diff -u src/sys/arch/i386/conf/files.i386:1.373 src/sys/arch/i386/conf/files.i386:1.374 --- src/sys/arch/i386/conf/files.i386:1.373 Fri Feb 7 22:40:22 2014 +++ src/sys/arch/i386/conf/files.i386 Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -# $NetBSD: files.i386,v 1.373 2014/02/07 22:40:22 dsl Exp $ +# $NetBSD: files.i386,v 1.374 2014/02/12 23:24:09 dsl Exp $ # # new style config file for i386 architecture # @@ -82,7 +82,7 @@ file arch/i386/i386/process_machdep.c file arch/x86/x86/convert_xmm_s87.c file arch/i386/i386/trap.c file dev/cons.c -file arch/i386/isa/npx.c +file arch/x86/x86/fpu.c file arch/i386/i386/mptramp.S multiprocessor Index: src/sys/arch/i386/i386/autoconf.c diff -u src/sys/arch/i386/i386/autoconf.c:1.99 src/sys/arch/i386/i386/autoconf.c:1.100 --- src/sys/arch/i386/i386/autoconf.c:1.99 Sun Jan 26 19:16:17 2014 +++ src/sys/arch/i386/i386/autoconf.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.99 2014/01/26 19:16:17 dsl Exp $ */ +/* $NetBSD: autoconf.c,v 1.100 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -46,7 +46,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.99 2014/01/26 19:16:17 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.100 2014/02/12 23:24:09 dsl Exp $"); #include "opt_compat_oldboot.h" #include "opt_intrdebug.h" @@ -64,7 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v #include <machine/intr.h> #include <machine/pcb.h> #include <machine/cpufunc.h> -#include <machine/npx.h> +#include <x86/fpu.h> #include "ioapic.h" #include "lapic.h" Index: src/sys/arch/i386/i386/cpufunc.S diff -u src/sys/arch/i386/i386/cpufunc.S:1.17 src/sys/arch/i386/i386/cpufunc.S:1.18 --- src/sys/arch/i386/i386/cpufunc.S:1.17 Sat Sep 24 21:24:52 2011 +++ src/sys/arch/i386/i386/cpufunc.S Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.S,v 1.17 2011/09/24 21:24:52 jym Exp $ */ +/* $NetBSD: cpufunc.S,v 1.18 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include <sys/errno.h> #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.17 2011/09/24 21:24:52 jym Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.18 2014/02/12 23:24:09 dsl Exp $"); #include "opt_xen.h" @@ -332,6 +332,11 @@ ENTRY(fnstcw) ret END(fnstcw) +ENTRY(fngetsw) + fnstsw %ax + ret +END(fngetsw) + ENTRY(fnstsw) movl 4(%esp), %eax fnstsw (%eax) @@ -384,10 +389,19 @@ ENTRY(fxrstor) ret END(fxrstor) -ENTRY(fldummy) +ENTRY(x86_stmxcsr) + movl 4(%esp), %eax + stmxcsr (%eax) + ret + +ENTRY(x86_ldmxcsr) movl 4(%esp), %eax + ldmxcsr (%eax) + ret + +ENTRY(fldummy) ffree %st(7) - flds (%eax) + fldz ret END(fldummy) Index: src/sys/arch/i386/i386/freebsd_machdep.c diff -u src/sys/arch/i386/i386/freebsd_machdep.c:1.58 src/sys/arch/i386/i386/freebsd_machdep.c:1.59 --- src/sys/arch/i386/i386/freebsd_machdep.c:1.58 Sun Jan 19 14:30:37 2014 +++ src/sys/arch/i386/i386/freebsd_machdep.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: freebsd_machdep.c,v 1.58 2014/01/19 14:30:37 dsl Exp $ */ +/* $NetBSD: freebsd_machdep.c,v 1.59 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: freebsd_machdep.c,v 1.58 2014/01/19 14:30:37 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: freebsd_machdep.c,v 1.59 2014/02/12 23:24:09 dsl Exp $"); #if defined(_KERNEL_OPT) #include "opt_vm86.h" @@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: freebsd_mach #include <compat/sys/signal.h> #include <machine/cpufunc.h> -#include <machine/npx.h> +#include <x86/fpu.h> #include <machine/reg.h> #include <machine/vm86.h> #include <machine/vmparam.h> Index: src/sys/arch/i386/i386/i386_trap.S diff -u src/sys/arch/i386/i386/i386_trap.S:1.4 src/sys/arch/i386/i386/i386_trap.S:1.5 --- src/sys/arch/i386/i386/i386_trap.S:1.4 Tue Feb 4 21:09:23 2014 +++ src/sys/arch/i386/i386/i386_trap.S Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: i386_trap.S,v 1.4 2014/02/04 21:09:23 dsl Exp $ */ +/* $NetBSD: i386_trap.S,v 1.5 2014/02/12 23:24:09 dsl Exp $ */ /* * Copyright 2002 (c) Wasabi Systems, Inc. @@ -66,7 +66,7 @@ #if 0 #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.4 2014/02/04 21:09:23 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.5 2014/02/12 23:24:09 dsl Exp $"); #endif /* @@ -162,7 +162,7 @@ IDTVEC(trap07) #ifdef DIAGNOSTIC movl CPUVAR(ILEVEL),%ebx #endif - pushl CPUVAR(SELF) + pushl %esp call _C_LABEL(fpudna) addl $4,%esp jmp _C_LABEL(trapreturn) @@ -231,30 +231,30 @@ IDTVEC(trap10) * this is difficult for nested interrupts. */ pushl $0 # dummy error code - pushl $T_ASTFLT + pushl $T_ARITHTRAP +.Ldo_fputrap: INTRENTRY movl CPUVAR(ILEVEL),%ebx - pushl %ebx pushl %esp - pushl $0 # dummy arg addl $1,CPUVAR(NTRAP) # statistical info adcl $0,CPUVAR(NTRAP)+4 - call _C_LABEL(npxintr) - addl $12,%esp + call _C_LABEL(fputrap) + addl $4,%esp jmp _C_LABEL(trapreturn) IDTVEC_END(trap10) IDTVEC(trap11) TRAP(T_ALIGNFLT) IDTVEC_END(trap11) -#ifdef XEN -IDTVEC(trap12) -IDTVEC(trap13) -#else + IDTVEC(trap12) ZTRAP(T_MCA) +IDTVEC_END(trap12) IDTVEC(trap13) - ZTRAP(T_XMM) -#endif + pushl $0 # dummy error code + pushl $T_XMM + jmp .Ldo_fputrap +IDTVEC_END(trap13) + IDTVEC(trap14) IDTVEC(trap15) IDTVEC(trap16) Index: src/sys/arch/i386/i386/ibcs2_machdep.c diff -u src/sys/arch/i386/i386/ibcs2_machdep.c:1.42 src/sys/arch/i386/i386/ibcs2_machdep.c:1.43 --- src/sys/arch/i386/i386/ibcs2_machdep.c:1.42 Sun Jan 19 14:30:37 2014 +++ src/sys/arch/i386/i386/ibcs2_machdep.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ibcs2_machdep.c,v 1.42 2014/01/19 14:30:37 dsl Exp $ */ +/* $NetBSD: ibcs2_machdep.c,v 1.43 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1997, 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ibcs2_machdep.c,v 1.42 2014/01/19 14:30:37 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ibcs2_machdep.c,v 1.43 2014/02/12 23:24:09 dsl Exp $"); #if defined(_KERNEL_OPT) #include "opt_vm86.h" @@ -47,7 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: ibcs2_machde #include <machine/cpu.h> #include <machine/cpufunc.h> #include <machine/psl.h> -#include <machine/npx.h> +#include <x86/fpu.h> #include <machine/reg.h> #include <machine/vmparam.h> #include <machine/ibcs2_machdep.h> Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.270 src/sys/arch/i386/i386/trap.c:1.271 --- src/sys/arch/i386/i386/trap.c:1.270 Fri Feb 7 19:32:50 2014 +++ src/sys/arch/i386/i386/trap.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.270 2014/02/07 19:32:50 dsl Exp $ */ +/* $NetBSD: trap.c,v 1.271 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.270 2014/02/07 19:32:50 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.271 2014/02/12 23:24:09 dsl Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -126,7 +126,6 @@ dtrace_doubletrap_func_t dtrace_doubletr #endif -static inline int xmm_si_code(struct lwp *); void trap(struct trapframe *); void trap_tss(struct i386tss *, int, int); void trap_return_fault_return(struct trapframe *) __dead; @@ -188,44 +187,6 @@ trap_tss(struct i386tss *tss, int trapno trap(&tf); } -static inline int -xmm_si_code(struct lwp *l) -{ - struct pcb *pcb; - uint32_t mxcsr, mask; - - if (!i386_use_fxsave) { -#ifdef DIAGNOSTIC - panic("SSE FP Exception, but no SSE"); -#endif - return 0; - } - pcb = lwp_getpcb(l); - mxcsr = pcb->pcb_savefpu.sv_xmm.fx_mxcsr; - - /* - * Since we only have a single status and control register, - * we use the exception mask bits to mask disabled exceptions - */ - mask = ~((mxcsr & __INITIAL_MXCSR__) >> 7) & 0xff; - switch (mask & mxcsr) { - case EN_SW_INVOP: - return FPE_FLTINV; - case EN_SW_DENORM: - case EN_SW_PRECLOSS: - return FPE_FLTRES; - case EN_SW_ZERODIV: - return FPE_FLTDIV; - case EN_SW_OVERFLOW: - return FPE_FLTOVF; - case EN_SW_UNDERFLOW: - return FPE_FLTUND; - case 0: - default: - return 0; - } -} - static void * onfault_handler(const struct pcb *pcb, const struct trapframe *tf) { @@ -552,27 +513,13 @@ kernelfault: } goto out; - case T_DNA|T_USER: { - KSI_INIT_TRAP(&ksi); - ksi.ksi_signo = SIGKILL; - ksi.ksi_addr = (void *)frame->tf_eip; - printf("pid %d killed due to lack of floating point\n", - p->p_pid); - goto trapsignal; - } - - case T_XMM|T_USER: case T_BOUND|T_USER: case T_OFLOW|T_USER: case T_DIVIDE|T_USER: - case T_ARITHTRAP|T_USER: KSI_INIT_TRAP(&ksi); ksi.ksi_signo = SIGFPE; ksi.ksi_addr = (void *)frame->tf_eip; switch (type) { - case T_XMM|T_USER: - ksi.ksi_code = xmm_si_code(l); - break; case T_BOUND|T_USER: ksi.ksi_code = FPE_FLTSUB; break; @@ -582,9 +529,6 @@ kernelfault: case T_DIVIDE|T_USER: ksi.ksi_code = FPE_INTDIV; break; - case T_ARITHTRAP|T_USER: - ksi.ksi_code = npxtrap(l); - break; default: ksi.ksi_code = 0; break; Index: src/sys/arch/i386/include/Makefile diff -u src/sys/arch/i386/include/Makefile:1.41 src/sys/arch/i386/include/Makefile:1.42 --- src/sys/arch/i386/include/Makefile:1.41 Mon Nov 5 00:57:42 2012 +++ src/sys/arch/i386/include/Makefile Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.41 2012/11/05 00:57:42 alnsn Exp $ +# $NetBSD: Makefile,v 1.42 2014/02/12 23:24:09 dsl Exp $ INCSDIR= /usr/include/i386 @@ -16,7 +16,6 @@ INCS= ansi.h aout_machdep.h apmvar.h asm kcore.h \ limits.h lock.h \ math.h mcontext.h mutex.h mtrr.h multiboot.h \ - npx.h \ param.h pcb.h pio.h pmap.h pmc.h proc.h profile.h psl.h \ pte.h ptrace.h \ reg.h rwlock.h \ Index: src/sys/arch/i386/include/freebsd_machdep.h diff -u src/sys/arch/i386/include/freebsd_machdep.h:1.12 src/sys/arch/i386/include/freebsd_machdep.h:1.13 --- src/sys/arch/i386/include/freebsd_machdep.h:1.12 Sun Jan 19 13:35:58 2014 +++ src/sys/arch/i386/include/freebsd_machdep.h Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: freebsd_machdep.h,v 1.12 2014/01/19 13:35:58 dsl Exp $ */ +/* $NetBSD: freebsd_machdep.h,v 1.13 2014/02/12 23:24:09 dsl Exp $ */ /* * Copyright (c) 1986, 1989, 1991, 1993 @@ -41,7 +41,6 @@ #define _FREEBSD_MACHDEP_H #include <compat/sys/sigtypes.h> -#include <machine/npx.h> /* * signal support Index: src/sys/arch/i386/include/pcb.h diff -u src/sys/arch/i386/include/pcb.h:1.51 src/sys/arch/i386/include/pcb.h:1.52 --- src/sys/arch/i386/include/pcb.h:1.51 Sun Jan 19 10:30:19 2014 +++ src/sys/arch/i386/include/pcb.h Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: pcb.h,v 1.51 2014/01/19 10:30:19 dsl Exp $ */ +/* $NetBSD: pcb.h,v 1.52 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2009 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ #include <machine/segments.h> #include <machine/tss.h> -#include <i386/npx.h> +#include <x86/fpu.h> #include <i386/sysarch.h> struct pcb { Index: src/sys/arch/x86/include/cpu.h diff -u src/sys/arch/x86/include/cpu.h:1.60 src/sys/arch/x86/include/cpu.h:1.61 --- src/sys/arch/x86/include/cpu.h:1.60 Tue Feb 4 21:09:24 2014 +++ src/sys/arch/x86/include/cpu.h Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.60 2014/02/04 21:09:24 dsl Exp $ */ +/* $NetBSD: cpu.h,v 1.61 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -101,8 +101,7 @@ struct cpu_info { struct cpu_info *ci_next; /* next cpu */ struct lwp *ci_curlwp; /* current owner of the processor */ struct lwp *ci_fpcurlwp; /* current owner of the FPU */ - int _unused1; - int ci_fpused; /* XEN: FPU was used by curlwp */ + int _unused1[2]; cpuid_t ci_cpuid; /* our CPU ID */ int _unused; uint32_t ci_acpiid; /* our ACPI/MADT ID */ @@ -365,9 +364,20 @@ extern int cpu_class; extern char cpu_brand_string[]; extern int use_pae; +#ifdef __i386__ +extern int i386_fpu_present; +int npx586bug1(int, int); +extern int i386_fpu_fdivbug; extern int i386_use_fxsave; extern int i386_has_sse; extern int i386_has_sse2; +#else +#define i386_fpu_present 1 +#define i386_fpu_fdivbug 0 +#define i386_use_fxsave 1 +#define i386_has_sse 1 +#define i386_has_sse2 1 +#endif extern void (*x86_cpu_idle)(void); #define cpu_idle() (*x86_cpu_idle)() Index: src/sys/arch/x86/include/cpu_extended_state.h diff -u src/sys/arch/x86/include/cpu_extended_state.h:1.4 src/sys/arch/x86/include/cpu_extended_state.h:1.5 --- src/sys/arch/x86/include/cpu_extended_state.h:1.4 Sun Feb 9 14:44:42 2014 +++ src/sys/arch/x86/include/cpu_extended_state.h Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_extended_state.h,v 1.4 2014/02/09 14:44:42 dsl Exp $ */ +/* $NetBSD: cpu_extended_state.h,v 1.5 2014/02/12 23:24:09 dsl Exp $ */ #ifndef _X86_CPU_EXTENDED_STATE_H_ #define _X86_CPU_EXTENDED_STATE_H_ @@ -248,10 +248,4 @@ __CTASSERT(sizeof (struct xsave_ymm) == #define __INITIAL_MXCSR__ 0x1f80 #define __INITIAL_MXCSR_MASK__ 0xffbf -#ifdef _KERNEL -void process_xmm_to_s87(const struct fxsave *, struct save87 *); -void process_s87_to_xmm(const struct save87 *, struct fxsave *); -#endif - - #endif /* _X86_CPU_EXTENDED_STATE_H_ */ Index: src/sys/arch/x86/include/cpufunc.h diff -u src/sys/arch/x86/include/cpufunc.h:1.15 src/sys/arch/x86/include/cpufunc.h:1.16 --- src/sys/arch/x86/include/cpufunc.h:1.15 Sun Feb 9 17:07:41 2014 +++ src/sys/arch/x86/include/cpufunc.h Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.h,v 1.15 2014/02/09 17:07:41 dsl Exp $ */ +/* $NetBSD: cpufunc.h,v 1.16 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. @@ -81,13 +81,14 @@ void fnclex(void); void fninit(void); void fnsave(void *); void fnstcw(uint16_t *); -void fnstsw(void *); +uint16_t fngetsw(void); +void fnstsw(uint16_t *); void fp_divide_by_0(void); void frstor(void *); void fwait(void); void clts(void); void stts(void); -void fldummy(const double *); +void fldummy(void); void fxsave(void *); void fxrstor(void *); void x86_monitor(const void *, uint32_t, uint32_t); Index: src/sys/arch/x86/include/fpu.h diff -u src/sys/arch/x86/include/fpu.h:1.1 src/sys/arch/x86/include/fpu.h:1.2 --- src/sys/arch/x86/include/fpu.h:1.1 Tue Feb 11 20:17:16 2014 +++ src/sys/arch/x86/include/fpu.h Wed Feb 12 23:24:09 2014 @@ -1,25 +1,25 @@ -/* $NetBSD: fpu.h,v 1.1 2014/02/11 20:17:16 dsl Exp $ */ +/* $NetBSD: fpu.h,v 1.2 2014/02/12 23:24:09 dsl Exp $ */ -#ifndef _AMD64_FPU_H_ -#define _AMD64_FPU_H_ +#ifndef _X86_FPU_H_ +#define _X86_FPU_H_ #include <x86/cpu_extended_state.h> #ifdef _KERNEL -/* - * XXX - */ + struct trapframe; struct cpu_info; void fpuinit(struct cpu_info *); -void fpudrop(void); -void fpusave(struct lwp *); -void fpudiscard(struct lwp *); -void fputrap(struct trapframe *); void fpusave_lwp(struct lwp *, bool); void fpusave_cpu(bool); +void fputrap(struct trapframe *); +void fpudna(struct trapframe *); + +void process_xmm_to_s87(const struct fxsave *, struct save87 *); +void process_s87_to_xmm(const struct save87 *, struct fxsave *); + #endif -#endif /* _AMD64_FPU_H_ */ +#endif /* _X86_FPU_H_ */ Index: src/sys/arch/x86/x86/convert_xmm_s87.c diff -u src/sys/arch/x86/x86/convert_xmm_s87.c:1.1 src/sys/arch/x86/x86/convert_xmm_s87.c:1.2 --- src/sys/arch/x86/x86/convert_xmm_s87.c:1.1 Fri Feb 7 22:40:22 2014 +++ src/sys/arch/x86/x86/convert_xmm_s87.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: convert_xmm_s87.c,v 1.1 2014/02/07 22:40:22 dsl Exp $ */ +/* $NetBSD: convert_xmm_s87.c,v 1.2 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -30,12 +30,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: convert_xmm_s87.c,v 1.1 2014/02/07 22:40:22 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: convert_xmm_s87.c,v 1.2 2014/02/12 23:24:09 dsl Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <x86/cpu_extended_state.h> +#include <x86/fpu.h> void process_xmm_to_s87(const struct fxsave *sxmm, struct save87 *s87) Index: src/sys/arch/x86/x86/fpu.c diff -u src/sys/arch/x86/x86/fpu.c:1.2 src/sys/arch/x86/x86/fpu.c:1.3 --- src/sys/arch/x86/x86/fpu.c:1.2 Wed Feb 12 19:53:49 2014 +++ src/sys/arch/x86/x86/fpu.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fpu.c,v 1.2 2014/02/12 19:53:49 dsl Exp $ */ +/* $NetBSD: fpu.c,v 1.3 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. All @@ -100,7 +100,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.2 2014/02/12 19:53:49 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.3 2014/02/12 23:24:09 dsl Exp $"); #include "opt_multiprocessor.h" @@ -118,8 +118,12 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.2 #include <machine/pcb.h> #include <machine/trap.h> #include <machine/specialreg.h> +#include <x86/cpu.h> #include <x86/fpu.h> +/* Check some duplicate definitions match */ +#include <machine/fenv.h> + #ifdef XEN #define clts() HYPERVISOR_fpu_taskswitch(0) #define stts() HYPERVISOR_fpu_taskswitch(1) @@ -131,7 +135,7 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.2 * * DNA exceptions are handled like this: * - * 1) If there is no FPU, return and go to the emulator. + * 1) If there is no FPU, send SIGILL. * 2) If someone else has used the FPU, save its state into that lwp's PCB. * 3a) If MDL_USEDFPU is not set, set it and initialize the FPU. * 3b) Otherwise, reload the lwp's previous FPU state. @@ -143,8 +147,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.2 * state is saved. */ -void fpudna(struct trapframe *frame); - /* * The following table is used to ensure that the FPE_... value * that is passed as a trapcode to the signal handler of the user @@ -224,15 +226,58 @@ static const uint8_t fpetable[128] = { /* * Init the FPU. + * + * This might not be structly necessary since it will be initialised + * for each process. However it does no harm. */ void fpuinit(struct cpu_info *ci) { clts(); fninit(); + +#if defined(__i386__) && !defined(XEN) + { + uint16_t control; + + /* Read the default control word */ + fnstcw(&control); + + if (control != __INITIAL_NPXCW__) { + /* Must be a 486SX, trap FP instructions */ + lcr0((rcr0() & ~CR0_MP) | CR0_EM); + aprint_normal_dev(ci->ci_dev, "no fpu (control %x)\n", + control); + i386_fpu_present = 0; + return; + } + + if (npx586bug1(4195835, 3145727) != 0) { + /* NB 120+MHz cpus are not affected */ + i386_fpu_fdivbug = 1; + aprint_normal_dev(ci->ci_dev, + "WARNING: Pentium FDIV bug detected!\n"); + } + } +#endif + stts(); } +static void +send_sigill(void *rip) +{ + /* No fpu (486SX) - send SIGILL */ + ksiginfo_t ksi; + + x86_enable_intr(); + KSI_INIT_TRAP(&ksi); + ksi.ksi_signo = SIGILL; + ksi.ksi_addr = rip; + (*curlwp->l_proc->p_emul->e_trapsignal)(curlwp, &ksi); + return; +} + /* * This is a synchronous trap on either an x87 instruction (due to an * unmasked error on the previous x87 instruction) or on an SSE/SSE2 etc @@ -268,6 +313,11 @@ fputrap(struct trapframe *frame) if (!USERMODE(frame->tf_cs, frame->tf_eflags)) panic("fpu trap from kernel, trapframe %p\n", frame); + if (i386_fpu_present == 0) { + send_sigill((void *)X86_TF_RIP(frame)); + return; + } + /* * At this point, fpcurlwp should be curlwp. If it wasn't, the TS bit * should be set, and we should have gotten a DNA exception. @@ -303,7 +353,7 @@ fputrap(struct trapframe *frame) KSI_INIT_TRAP(&ksi); ksi.ksi_signo = SIGFPE; - ksi.ksi_addr = (void *)frame->tf_rip; + ksi.ksi_addr = (void *)X86_TF_RIP(frame); ksi.ksi_code = fpetable[statbits & 0x7f]; ksi.ksi_trap = statbits; (*curlwp->l_proc->p_emul->e_trapsignal)(curlwp, &ksi); @@ -322,14 +372,18 @@ void fpudna(struct trapframe *frame) { struct cpu_info *ci; - uint16_t cw; - uint32_t mxcsr; struct lwp *l, *fl; struct pcb *pcb; int s; if (!USERMODE(frame->tf_cs, frame->tf_eflags)) - panic("fpudna from kernel, trapframe %p\n", frame); + panic("fpudna from kernel, ip %p, trapframe %p\n", + (void *)X86_TF_RIP(frame), frame); + + if (i386_fpu_present == 0) { + send_sigill((void *)X86_TF_RIP(frame)); + return; + } ci = curcpu(); @@ -378,35 +432,35 @@ fpudna(struct trapframe *frame) pcb->pcb_fpcpu = ci; if ((l->l_md.md_flags & MDL_USEDFPU) == 0) { fninit(); - cw = pcb->pcb_savefpu.sv_xmm.fx_cw; - fldcw(&cw); - mxcsr = pcb->pcb_savefpu.sv_xmm.fx_mxcsr; - x86_ldmxcsr(&mxcsr); + if (i386_use_fxsave) { + fldcw(&pcb->pcb_savefpu.sv_xmm.fx_cw); + x86_ldmxcsr(&pcb->pcb_savefpu.sv_xmm.fx_mxcsr); + } else { + fldcw(&pcb->pcb_savefpu.sv_87.s87_cw); + } l->l_md.md_flags |= MDL_USEDFPU; - } else { + } else if (i386_use_fxsave) { /* * AMD FPU's do not restore FIP, FDP, and FOP on fxrstor, * leaking other process's execution history. Clear them * manually. */ - static const double zero = 0.0; - uint16_t status; /* * Clear the ES bit in the x87 status word if it is currently * set, in order to avoid causing a fault in the upcoming load. */ - fnstsw(&status); - if (status & 0x80) + if (fngetsw() & 0x80) fnclex(); /* - * Load the dummy variable into the x87 stack. This mangles - * the x87 stack, but we don't care since we're about to call - * fxrstor() anyway. + * Load a zero into the x87 stack. This mangles the x87 stack, + * but we don't care since we're about to call fxrstor() anyway. */ - fldummy(&zero); + fldummy(); fxrstor(&pcb->pcb_savefpu); + } else { + frstor(&pcb->pcb_savefpu.sv_87); } KASSERT(ci == curcpu()); @@ -434,7 +488,11 @@ fpusave_cpu(bool save) if (save) { clts(); - fxsave(&pcb->pcb_savefpu); + if (i386_use_fxsave) { + fxsave(&pcb->pcb_savefpu); + } else { + fnsave(&pcb->pcb_savefpu.sv_87); + } } stts(); Index: src/sys/arch/x86/x86/procfs_machdep.c diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.2 src/sys/arch/x86/x86/procfs_machdep.c:1.3 --- src/sys/arch/x86/x86/procfs_machdep.c:1.2 Sun Feb 2 22:41:20 2014 +++ src/sys/arch/x86/x86/procfs_machdep.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_machdep.c,v 1.2 2014/02/02 22:41:20 dsl Exp $ */ +/* $NetBSD: procfs_machdep.c,v 1.3 2014/02/12 23:24:09 dsl Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -42,7 +42,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.2 2014/02/02 22:41:20 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.3 2014/02/12 23:24:09 dsl Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -56,7 +56,6 @@ __KERNEL_RCSID(0, "$NetBSD: procfs_machd #include <machine/reg.h> #include <machine/specialreg.h> -extern int i386_fpu_present, i386_fpu_fdivbug; extern char cpu_model[]; static const char * const x86_features[] = { @@ -214,13 +213,8 @@ procfs_getonecpu(int xcpu, struct cpu_in "cpuid level\t: %d\n" "wp\t\t: %s\n" "flags\t\t: %s\n", -#ifdef __x86_64__ - "no", /* XXX */ - "yes", /* XXX */ -#else - i386_fpu_fdivbug ? "yes" : "no", - i386_fpu_present ? "yes" : "no", -#endif + i386_fpu_fdivbug ? "yes" : "no", /* an old pentium */ + i386_fpu_present ? "yes" : "no", /* not a 486SX */ cpuid_level, (rcr0() & CR0_WP) ? "yes" : "no", featurebuf Index: src/sys/arch/xen/conf/files.xen diff -u src/sys/arch/xen/conf/files.xen:1.132 src/sys/arch/xen/conf/files.xen:1.133 --- src/sys/arch/xen/conf/files.xen:1.132 Tue Feb 11 20:17:16 2014 +++ src/sys/arch/xen/conf/files.xen Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -# $NetBSD: files.xen,v 1.132 2014/02/11 20:17:16 dsl Exp $ +# $NetBSD: files.xen,v 1.133 2014/02/12 23:24:09 dsl Exp $ # NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp # NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp @@ -55,9 +55,6 @@ file arch/i386/i386/process_machdep.c file arch/i386/i386/trap.c file arch/i386/i386/lock_stubs.S -file arch/i386/isa/npx.c - - file arch/i386/i386/pmc.c perfctrs file crypto/des/arch/i386/des_enc.S des @@ -79,7 +76,6 @@ file arch/amd64/amd64/gdt.c file arch/amd64/amd64/machdep.c file arch/amd64/amd64/process_machdep.c file arch/amd64/amd64/trap.c -file arch/x86/x86/fpu.c file arch/amd64/amd64/lock_stubs.S endif @@ -87,6 +83,7 @@ file kern/subr_disk_mbr.c disk file arch/x86/x86/convert_xmm_s87.c file arch/x86/x86/db_memrw.c ddb | kgdb file arch/x86/x86/db_trace.c ddb +file arch/x86/x86/fpu.c file arch/xen/x86/hypervisor_machdep.c # file arch/x86/x86/mtrr_i686.c mtrr file arch/x86/x86/syscall.c Index: src/sys/arch/xen/x86/cpu.c diff -u src/sys/arch/xen/x86/cpu.c:1.97 src/sys/arch/xen/x86/cpu.c:1.98 --- src/sys/arch/xen/x86/cpu.c:1.97 Tue Feb 11 20:17:16 2014 +++ src/sys/arch/xen/x86/cpu.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.97 2014/02/11 20:17:16 dsl Exp $ */ +/* $NetBSD: cpu.c,v 1.98 2014/02/12 23:24:09 dsl Exp $ */ /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp */ /*- @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.97 2014/02/11 20:17:16 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.98 2014/02/12 23:24:09 dsl Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -102,11 +102,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.97 #include <machine/mtrr.h> #include <machine/pio.h> -#ifdef i386 -#include <machine/npx.h> -#else #include <x86/fpu.h> -#endif #include <xen/xen.h> #include <xen/xen-public/vcpu.h> Index: src/sys/arch/xen/x86/xen_ipi.c diff -u src/sys/arch/xen/x86/xen_ipi.c:1.16 src/sys/arch/xen/x86/xen_ipi.c:1.17 --- src/sys/arch/xen/x86/xen_ipi.c:1.16 Tue Feb 11 20:17:16 2014 +++ src/sys/arch/xen/x86/xen_ipi.c Wed Feb 12 23:24:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_ipi.c,v 1.16 2014/02/11 20:17:16 dsl Exp $ */ +/* $NetBSD: xen_ipi.c,v 1.17 2014/02/12 23:24:09 dsl Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -33,10 +33,10 @@ /* * Based on: x86/ipi.c - * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.16 2014/02/11 20:17:16 dsl Exp $"); + * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.17 2014/02/12 23:24:09 dsl Exp $"); */ -__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.16 2014/02/11 20:17:16 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.17 2014/02/12 23:24:09 dsl Exp $"); #include <sys/types.h> @@ -48,11 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v #include <sys/errno.h> #include <sys/systm.h> -#ifdef __x86_64__ #include <x86/fpu.h> -#else -#include <machine/npx.h> -#endif /* __x86_64__ */ #include <machine/frame.h> #include <machine/segments.h>