Module Name:    src
Committed By:   dsl
Date:           Sun Feb  2 22:41:20 UTC 2014

Modified Files:
        src/sys/arch/i386/acpi: acpi_wakecode.S
        src/sys/arch/i386/i386: i386_trap.S locore.S machdep.c mptramp.S
        src/sys/arch/i386/isa: npx.c
        src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Minor fpu initialisation cleanups:
Set default CR) so that the FPU is enabled (unset CR0_EM) and initialise
  i386_fpu_present to 1.
No need to call the npx trap indirectly, rename to fpunda() to match amd64.
Remove the i386_fpu_exception variable and sysctl (It used to indicate
  which irq was used for fpu exceptions, but we only support 'internal'
  now).  Hopefully no one cares.
fpuinit() now only needs to clear TS before the fninit(). Apart from the
  checks for 486SX and the 'fdiv bug' this matches the amd64 version.
Exclude fpuinit() from XEN kernels, they don't call it - which rather begs
  the question as to whether it is needed at all!


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/i386/acpi/acpi_wakecode.S
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.744 -r1.745 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/i386/i386/mptramp.S
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/i386/isa/npx.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/procfs_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/sys/arch/i386/acpi/acpi_wakecode.S
diff -u src/sys/arch/i386/acpi/acpi_wakecode.S:1.15 src/sys/arch/i386/acpi/acpi_wakecode.S:1.16
--- src/sys/arch/i386/acpi/acpi_wakecode.S:1.15	Thu Apr 19 18:00:34 2012
+++ src/sys/arch/i386/acpi/acpi_wakecode.S	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakecode.S,v 1.15 2012/04/19 18:00:34 jym Exp $	*/
+/*	$NetBSD: acpi_wakecode.S,v 1.16 2014/02/02 22:41:20 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -165,7 +165,7 @@ wakeup_32:
 	movl	WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
 	movl	%eax,%cr3
 	movl	%cr0,%eax
-	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP|CR0_AM),%eax
+	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
 	movl	%eax,%cr0
 
 	/* Flush the prefetch queue */

Index: src/sys/arch/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.2 src/sys/arch/i386/i386/i386_trap.S:1.3
--- src/sys/arch/i386/i386/i386_trap.S:1.2	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/i386/i386_trap.S	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.2 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.3 2014/02/02 22:41:20 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.2 2014/01/26 19:16:17 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.3 2014/02/02 22:41:20 dsl Exp $");
 #endif
 
 /*
@@ -163,7 +163,7 @@ IDTVEC(trap07)
 	movl	CPUVAR(ILEVEL),%ebx
 #endif
 	pushl	CPUVAR(SELF)
-	call	*_C_LABEL(npxdna_func)
+	call	_C_LABEL(fpudna)
 	addl	$4,%esp
 	testl	%eax,%eax
 	jz	calltrap

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.110 src/sys/arch/i386/i386/locore.S:1.111
--- src/sys/arch/i386/i386/locore.S:1.110	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/i386/locore.S	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.110 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: locore.S,v 1.111 2014/02/02 22:41:20 dsl Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.110 2014/01/26 19:16:17 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.111 2014/02/02 22:41:20 dsl Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_ddb.h"
@@ -697,8 +697,8 @@ try586:	/* Use the `cpuid' instruction. 
 	 * 2. Enable paging and the rest of it.
 	 */
 	movl	%cr0,%eax		# get control word
-					# enable paging & NPX emulation
-	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP|CR0_AM),%eax
+					# enable paging & NPX
+	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
 	movl	%eax,%cr0		# and page NOW!
 
 	pushl	$begin			# jump to high mem

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.744 src/sys/arch/i386/i386/machdep.c:1.745
--- src/sys/arch/i386/i386/machdep.c:1.744	Sat Feb  1 18:57:38 2014
+++ src/sys/arch/i386/i386/machdep.c	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.744 2014/02/01 18:57:38 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl 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.744 2014/02/01 18:57:38 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -229,12 +229,7 @@ struct mtrr_funcs *mtrr_funcs;
 
 int	cpu_class;
 int	use_pae;
-#ifdef XEN
 int	i386_fpu_present = 1;
-#else
-int	i386_fpu_present;
-#endif
-int	i386_fpu_exception;
 int	i386_fpu_fdivbug;
 
 int	i386_use_fxsave;

Index: src/sys/arch/i386/i386/mptramp.S
diff -u src/sys/arch/i386/i386/mptramp.S:1.26 src/sys/arch/i386/i386/mptramp.S:1.27
--- src/sys/arch/i386/i386/mptramp.S:1.26	Wed Jan 15 22:24:41 2014
+++ src/sys/arch/i386/i386/mptramp.S	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mptramp.S,v 1.26 2014/01/15 22:24:41 joerg Exp $	*/
+/*	$NetBSD: mptramp.S,v 1.27 2014/02/02 22:41:20 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.26 2014/01/15 22:24:41 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.27 2014/02/02 22:41:20 dsl Exp $");
 	
 #include "opt_mpbios.h"		/* for MPDEBUG */
 		
@@ -178,8 +178,8 @@ _TRMP_LABEL(mp_startup)
         /* Load base of page directory and enable mapping. */
         movl    %ecx,%cr3               # load ptd addr into mmu
         movl    %cr0,%eax               # get control word
-                                        # enable paging & NPX emulation
-        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP|CR0_AM),%eax
+                                        # enable paging & the fpu
+        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
         movl    %eax,%cr0               # and page NOW!
 
 #ifdef MPDEBUG

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.149 src/sys/arch/i386/isa/npx.c:1.150
--- src/sys/arch/i386/isa/npx.c:1.149	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/isa/npx.c	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.149 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: npx.c,v 1.150 2014/02/02 22:41:20 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.149 2014/01/26 19:16:17 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.150 2014/02/02 22:41:20 dsl Exp $");
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -145,7 +145,8 @@ __KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.14
  */
 
 static int	x86fpflags_to_ksiginfo(uint32_t flags);
-static int	npxdna(struct cpu_info *);
+/* Called directly from i386_trap.S */
+int	fpudna(struct cpu_info *);
 
 #ifdef XEN
 #define	clts() HYPERVISOR_fpu_taskswitch(0)
@@ -156,7 +157,6 @@ volatile u_int			npx_intrs_while_probing
 volatile u_int			npx_traps_while_probing;
 
 extern int i386_fpu_present;
-extern int i386_fpu_exception;
 extern int i386_fpu_fdivbug;
 
 struct npx_softc		*npx_softc;
@@ -174,33 +174,28 @@ fpu_save(union savefpu *addr)
 		fnsave(&addr->sv_87);
 }
 
-int    (*npxdna_func)(struct cpu_info *) = npxdna;
-
+#ifndef XEN
+/* Initialise fpu, might be boot cpu or a later cpu coming online */
 void
 fpuinit(struct cpu_info *ci)
 {
 	uint16_t control;
-	uint32_t cr0;
 
-	/* Assume we have an FPU */
-	cr0 = rcr0();
-	cr0 &= ~(CR0_EM | CR0_TS);
-	cr0 |= CR0_NE | CR0_MP;
-	lcr0(cr0);
-	/* Read back the default contol word */
+	/* The default cr0 has the fpu enabled */
+	clts();
 	fninit();
+
+	/* Read the default control word */
 	fnstcw(&control);
 
 	if (control != __INITIAL_NPXCW__) {
-		/* Must be a 486SX, emulate FP instructions */
-		lcr0((cr0 & ~CR0_MP) | CR0_EM);
-		aprint_normal_dev(ci->ci_dev, "no fpu\n");
+		/* 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;
 	}
 
-	/* We have a valid FPU */
-	i386_fpu_present = 1;
-
 	if (npx586bug1(4195835, 3145727) != 0) {
 		/* NB 120+MHz cpus are not affected */
 		i386_fpu_fdivbug = 1;
@@ -209,8 +204,9 @@ fpuinit(struct cpu_info *ci)
 	}
 
 	/* Set TS so first fp instruction faults */
-	lcr0(cr0 | CR0_TS);
+	stts();
 }
+#endif
 
 /*
  * Record the FPU state and reinitialize it all except for the control word.
@@ -384,8 +380,8 @@ x86fpflags_to_ksiginfo(uint32_t flags)
  * Otherwise, we save the previous state, if necessary, and restore
  * our last saved state.
  */
-static int
-npxdna(struct cpu_info *ci)
+int
+fpudna(struct cpu_info *ci)
 {
 	struct lwp *l, *fl;
 	struct pcb *pcb;

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.1 src/sys/arch/x86/x86/procfs_machdep.c:1.2
--- src/sys/arch/x86/x86/procfs_machdep.c:1.1	Thu Jul  8 11:25:00 2010
+++ src/sys/arch/x86/x86/procfs_machdep.c	Sun Feb  2 22:41:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.1 2010/07/08 11:25:00 rmind Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.2 2014/02/02 22:41:20 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.1 2010/07/08 11:25:00 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.2 2014/02/02 22:41:20 dsl Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,7 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: procfs_machd
 #include <machine/reg.h>
 #include <machine/specialreg.h>
 
-extern int	i386_fpu_present, i386_fpu_exception, i386_fpu_fdivbug;
+extern int	i386_fpu_present, i386_fpu_fdivbug;
 extern char	cpu_model[];
 
 static const char * const x86_features[] = {
@@ -210,18 +210,16 @@ procfs_getonecpu(int xcpu, struct cpu_in
 	l = snprintf(p, left,
 	    "fdiv_bug\t: %s\n"
 	    "fpu\t\t: %s\n"
-	    "fpu_exception\t: %s\n"
+	    "fpu_exception\t: yes\n"
 	    "cpuid level\t: %d\n"
 	    "wp\t\t: %s\n"
 	    "flags\t\t: %s\n",
 #ifdef __x86_64__
 	    "no",	/* XXX */
 	    "yes",	/* XXX */
-	    "yes",	/* XXX */
 #else
 	    i386_fpu_fdivbug ? "yes" : "no",
 	    i386_fpu_present ? "yes" : "no",
-	    i386_fpu_exception ? "yes" : "no",
 #endif
 	    cpuid_level,
 	    (rcr0() & CR0_WP) ? "yes" : "no",

Reply via email to