Module Name:    src
Committed By:   dsl
Date:           Sun Jan 19 14:30:38 UTC 2014

Modified Files:
        src/sys/arch/i386/i386: freebsd_machdep.c ibcs2_machdep.c machdep.c
            process_machdep.c svr4_machdep.c trap.c
        src/sys/arch/i386/include: npx.h
        src/sys/arch/i386/isa: npx.c
        src/sys/compat/linux/arch/i386: linux_machdep.c

Log Message:
Flatten the floating point register structures bu moving the
  'environment' registers into the main strcuture.
There are x87 instructions that only affect the environment, but that
  is no real excuse for all the sub-structures.
Rename fields so that there are far fewer collisions between the two
  sets of field names.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/i386/i386/freebsd_machdep.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/i386/i386/ibcs2_machdep.c
cvs rdiff -u -r1.741 -r1.742 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/i386/i386/process_machdep.c
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/i386/i386/svr4_machdep.c
cvs rdiff -u -r1.267 -r1.268 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/include/npx.h
cvs rdiff -u -r1.147 -r1.148 src/sys/arch/i386/isa/npx.c
cvs rdiff -u -r1.154 -r1.155 src/sys/compat/linux/arch/i386/linux_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/i386/freebsd_machdep.c
diff -u src/sys/arch/i386/i386/freebsd_machdep.c:1.57 src/sys/arch/i386/i386/freebsd_machdep.c:1.58
--- src/sys/arch/i386/i386/freebsd_machdep.c:1.57	Sun Jan 19 13:35:58 2014
+++ src/sys/arch/i386/i386/freebsd_machdep.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_machdep.c,v 1.57 2014/01/19 13:35:58 dsl Exp $	*/
+/*	$NetBSD: freebsd_machdep.c,v 1.58 2014/01/19 14:30:37 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.57 2014/01/19 13:35:58 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: freebsd_machdep.c,v 1.58 2014/01/19 14:30:37 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vm86.h"
@@ -64,9 +64,9 @@ freebsd_setregs(struct lwp *l, struct ex
 
 	setregs(l, epp, stack);
 	if (i386_use_fxsave)
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw = __FreeBSD_NPXCW__;
+		pcb->pcb_savefpu.sv_xmm.fx_cw = __FreeBSD_NPXCW__;
 	else
-		pcb->pcb_savefpu.sv_87.sv_env.en_cw = __FreeBSD_NPXCW__;
+		pcb->pcb_savefpu.sv_87.s87_cw = __FreeBSD_NPXCW__;
 }
 
 /*

Index: src/sys/arch/i386/i386/ibcs2_machdep.c
diff -u src/sys/arch/i386/i386/ibcs2_machdep.c:1.41 src/sys/arch/i386/i386/ibcs2_machdep.c:1.42
--- src/sys/arch/i386/i386/ibcs2_machdep.c:1.41	Sun Dec  8 20:45:30 2013
+++ src/sys/arch/i386/i386/ibcs2_machdep.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_machdep.c,v 1.41 2013/12/08 20:45:30 dsl Exp $	*/
+/*	$NetBSD: ibcs2_machdep.c,v 1.42 2014/01/19 14:30:37 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.41 2013/12/08 20:45:30 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_machdep.c,v 1.42 2014/01/19 14:30:37 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vm86.h"
@@ -69,9 +69,9 @@ ibcs2_setregs(struct lwp *l, struct exec
 
 	setregs(l, epp, stack);
 	if (i386_use_fxsave)
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw = __iBCS2_NPXCW__;
+		pcb->pcb_savefpu.sv_xmm.fx_cw = __iBCS2_NPXCW__;
 	else
-		pcb->pcb_savefpu.sv_87.sv_env.en_cw = __iBCS2_NPXCW__;
+		pcb->pcb_savefpu.sv_87.s87_cw = __iBCS2_NPXCW__;
 	tf = l->l_md.md_regs;
 	tf->tf_eax = 0x2000000;		/* XXX base of heap */
 	tf->tf_cs = GSEL(GUCODEBIG_SEL, SEL_UPL);

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.741 src/sys/arch/i386/i386/machdep.c:1.742
--- src/sys/arch/i386/i386/machdep.c:1.741	Thu Jan  9 00:57:25 2014
+++ src/sys/arch/i386/i386/machdep.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.741 2014/01/09 00:57:25 dholland Exp $	*/
+/*	$NetBSD: machdep.c,v 1.742 2014/01/19 14:30:37 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.741 2014/01/09 00:57:25 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.742 2014/01/19 14:30:37 dsl Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -887,10 +887,10 @@ setregs(struct lwp *l, struct exec_packa
 
 	l->l_md.md_flags &= ~MDL_USEDFPU;
 	if (i386_use_fxsave) {
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw = control;
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_mxcsr = __INITIAL_MXCSR__;
+		pcb->pcb_savefpu.sv_xmm.fx_cw = control;
+		pcb->pcb_savefpu.sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
 	} else
-		pcb->pcb_savefpu.sv_87.sv_env.en_cw = control;
+		pcb->pcb_savefpu.sv_87.s87_cw = control;
 	memcpy(&pcb->pcb_fsd, &gdt[GUDATA_SEL], sizeof(pcb->pcb_fsd));
 	memcpy(&pcb->pcb_gsd, &gdt[GUDATA_SEL], sizeof(pcb->pcb_gsd));
 
@@ -1761,7 +1761,7 @@ cpu_setmcontext(struct lwp *l, const mco
 					sizeof (pcb->pcb_savefpu.sv_xmm));
 			} else {
 				/* This is a weird corner case */
-				process_xmm_to_s87((struct savexmm *)
+				process_xmm_to_s87((struct fxsave *)
 				    &mcp->__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
 				    &pcb->pcb_savefpu.sv_87);
 			}

Index: src/sys/arch/i386/i386/process_machdep.c
diff -u src/sys/arch/i386/i386/process_machdep.c:1.76 src/sys/arch/i386/i386/process_machdep.c:1.77
--- src/sys/arch/i386/i386/process_machdep.c:1.76	Sat Jan  4 00:10:02 2014
+++ src/sys/arch/i386/i386/process_machdep.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.76 2014/01/04 00:10:02 dsl Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.77 2014/01/19 14:30:37 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.76 2014/01/04 00:10:02 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.77 2014/01/19 14:30:37 dsl Exp $");
 
 #include "opt_vm86.h"
 #include "opt_ptrace.h"
@@ -127,69 +127,73 @@ xmm_to_s87_tag(const uint8_t *fpac, int 
 }
 
 void
-process_xmm_to_s87(const struct savexmm *sxmm, struct save87 *s87)
+process_xmm_to_s87(const struct fxsave *sxmm, struct save87 *s87)
 {
 	int i;
 
+	/* Convert context sent by userspace */
+
 	/* FPU control/status */
-	s87->sv_env.en_cw = sxmm->sv_env.fx_cw;
-	s87->sv_env.en_sw = sxmm->sv_env.fx_sw;
+	s87->s87_cw = sxmm->fx_cw;
+	s87->s87_sw = sxmm->fx_sw;
 	/* tag word handled below */
-	s87->sv_env.en_ip = sxmm->sv_env.fx_ip;
-	s87->sv_env.en_opcode = sxmm->sv_env.fx_opcode;
-	s87->sv_env.en_dp = sxmm->sv_env.fx_dp;
+	s87->s87_ip = sxmm->fx_ip;
+	s87->s87_opcode = sxmm->fx_opcode;
+	s87->s87_dp = sxmm->fx_dp;
 
 	/* Tag word and registers. */
-	s87->sv_env.en_tw = 0;
-	s87->sv_ex_tw = 0;
+	s87->s87_tw = 0;
+	s87->s87_ex_tw = 0;
 	for (i = 0; i < 8; i++) {
-		s87->sv_env.en_tw |=
+		s87->s87_tw |=
 		    (xmm_to_s87_tag(sxmm->sv_ac[i].fp_bytes, i,
-		     sxmm->sv_env.fx_tw) << (i * 2));
+		     sxmm->fx_tw) << (i * 2));
 
-		s87->sv_ex_tw |=
+		s87->s87_ex_tw |=
 		    (xmm_to_s87_tag(sxmm->sv_ac[i].fp_bytes, i,
 		     sxmm->sv_ex_tw) << (i * 2));
 
-		memcpy(&s87->sv_ac[i].fp_bytes, &sxmm->sv_ac[i].fp_bytes,
-		    sizeof(s87->sv_ac[i].fp_bytes));
+		memcpy(&s87->s87_ac[i].fp_bytes, &sxmm->sv_ac[i].fp_bytes,
+		    sizeof(s87->s87_ac[i].fp_bytes));
 	}
 
-	s87->sv_ex_sw = sxmm->sv_ex_sw;
+	s87->s87_ex_sw = sxmm->sv_ex_sw;
 }
 
 void
-process_s87_to_xmm(const struct save87 *s87, struct savexmm *sxmm)
+process_s87_to_xmm(const struct save87 *s87, struct fxsave *sxmm)
 {
 	int i;
 
+	/* Convert context sent by userspace */
+
 	/* FPU control/status */
-	sxmm->sv_env.fx_cw = s87->sv_env.en_cw;
-	sxmm->sv_env.fx_sw = s87->sv_env.en_sw;
+	sxmm->fx_cw = s87->s87_cw;
+	sxmm->fx_sw = s87->s87_sw;
 	/* tag word handled below */
-	sxmm->sv_env.fx_ip = s87->sv_env.en_ip;
-	sxmm->sv_env.fx_opcode = s87->sv_env.en_opcode;
-	sxmm->sv_env.fx_dp = s87->sv_env.en_dp;
+	sxmm->fx_ip = s87->s87_ip;
+	sxmm->fx_opcode = s87->s87_opcode;
+	sxmm->fx_dp = s87->s87_dp;
 
 	/* Tag word and registers. */
 	for (i = 0; i < 8; i++) {
-		if (((s87->sv_env.en_tw >> (i * 2)) & 3) == 3)
-			sxmm->sv_env.fx_tw &= ~(1U << i);
+		if (((s87->s87_tw >> (i * 2)) & 3) == 3)
+			sxmm->fx_tw &= ~(1U << i);
 		else
-			sxmm->sv_env.fx_tw |= (1U << i);
+			sxmm->fx_tw |= (1U << i);
 
 #if 0
 		/*
 		 * Software-only word not provided by the userland fpreg
 		 * structure.
 		 */
-		if (((s87->sv_ex_tw >> (i * 2)) & 3) == 3)
+		if (((s87->s87_ex_tw >> (i * 2)) & 3) == 3)
 			sxmm->sv_ex_tw &= ~(1U << i);
 		else
 			sxmm->sv_ex_tw |= (1U << i);
 #endif
 
-		memcpy(&sxmm->sv_ac[i].fp_bytes, &s87->sv_ac[i].fp_bytes,
+		memcpy(&sxmm->sv_ac[i].fp_bytes, &s87->s87_ac[i].fp_bytes,
 		    sizeof(sxmm->sv_ac[i].fp_bytes));
 	}
 #if 0
@@ -197,7 +201,7 @@ process_s87_to_xmm(const struct save87 *
 	 * Software-only word not provided by the userland fpreg
 	 * structure.
 	 */
-	sxmm->sv_ex_sw = s87->sv_ex_sw;
+	sxmm->sv_ex_sw = s87->s87_ex_sw;
 #endif
 }
 
@@ -253,22 +257,22 @@ process_read_fpregs(struct lwp *l, struc
 		 * save it temporarily.
 		 */
 		if (i386_use_fxsave) {
-			uint32_t mxcsr = frame->sv_xmm.sv_env.fx_mxcsr;
-			uint16_t cw = frame->sv_xmm.sv_env.fx_cw;
+			uint32_t mxcsr = frame->sv_xmm.fx_mxcsr;
+			uint16_t cw = frame->sv_xmm.fx_cw;
 
 			/* XXX Don't zero XMM regs? */
 			memset(&frame->sv_xmm, 0, sizeof(frame->sv_xmm));
-			frame->sv_xmm.sv_env.fx_cw = cw;
-			frame->sv_xmm.sv_env.fx_mxcsr = mxcsr;
-			frame->sv_xmm.sv_env.fx_sw = 0x0000;
-			frame->sv_xmm.sv_env.fx_tw = 0x00;
+			frame->sv_xmm.fx_cw = cw;
+			frame->sv_xmm.fx_mxcsr = mxcsr;
+			frame->sv_xmm.fx_sw = 0x0000;
+			frame->sv_xmm.fx_tw = 0x00;
 		} else {
-			uint16_t cw = frame->sv_87.sv_env.en_cw;
+			uint16_t cw = frame->sv_87.s87_cw;
 
 			memset(&frame->sv_87, 0, sizeof(frame->sv_87));
-			frame->sv_87.sv_env.en_cw = cw;
-			frame->sv_87.sv_env.en_sw = 0x0000;
-			frame->sv_87.sv_env.en_tw = 0xffff;
+			frame->sv_87.s87_cw = cw;
+			frame->sv_87.s87_sw = 0x0000;
+			frame->sv_87.s87_tw = 0xffff;
 		}
 		l->l_md.md_flags |= MDL_USEDFPU;
 	}
@@ -410,15 +414,15 @@ process_machdep_read_xmmregs(struct lwp 
 		 * The initial control word was already set by setregs(),
 		 * so save it temporarily.
 		 */
-		uint32_t mxcsr = frame->sv_xmm.sv_env.fx_mxcsr;
-		uint16_t cw = frame->sv_xmm.sv_env.fx_cw;
+		uint32_t mxcsr = frame->sv_xmm.fx_mxcsr;
+		uint16_t cw = frame->sv_xmm.fx_cw;
 
 		/* XXX Don't zero XMM regs? */
 		memset(&frame->sv_xmm, 0, sizeof(frame->sv_xmm));
-		frame->sv_xmm.sv_env.fx_cw = cw;
-		frame->sv_xmm.sv_env.fx_mxcsr = mxcsr;
-		frame->sv_xmm.sv_env.fx_sw = 0x0000;
-		frame->sv_xmm.sv_env.fx_tw = 0x00;
+		frame->sv_xmm.fx_cw = cw;
+		frame->sv_xmm.fx_mxcsr = mxcsr;
+		frame->sv_xmm.fx_sw = 0x0000;
+		frame->sv_xmm.fx_tw = 0x00;
 
 		l->l_md.md_flags |= MDL_USEDFPU;  
 	}

Index: src/sys/arch/i386/i386/svr4_machdep.c
diff -u src/sys/arch/i386/i386/svr4_machdep.c:1.97 src/sys/arch/i386/i386/svr4_machdep.c:1.98
--- src/sys/arch/i386/i386/svr4_machdep.c:1.97	Sun Dec  8 20:45:30 2013
+++ src/sys/arch/i386/i386/svr4_machdep.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.97 2013/12/08 20:45:30 dsl Exp $	 */
+/*	$NetBSD: svr4_machdep.c,v 1.98 2014/01/19 14:30:37 dsl Exp $	 */
 
 /*-
  * Copyright (c) 1994, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.97 2013/12/08 20:45:30 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.98 2014/01/19 14:30:37 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vm86.h"
@@ -116,9 +116,9 @@ svr4_setregs(struct lwp *l, struct exec_
 
 	setregs(l, epp, stack);
 	if (i386_use_fxsave)
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw = __SVR4_NPXCW__;
+		pcb->pcb_savefpu.sv_xmm.fx_cw = __SVR4_NPXCW__;
 	else
-		pcb->pcb_savefpu.sv_87.sv_env.en_cw = __SVR4_NPXCW__;
+		pcb->pcb_savefpu.sv_87.s87_cw = __SVR4_NPXCW__;
 	tf->tf_cs = GSEL(GUCODEBIG_SEL, SEL_UPL);
 }
 

Index: src/sys/arch/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.267 src/sys/arch/i386/i386/trap.c:1.268
--- src/sys/arch/i386/i386/trap.c:1.267	Sun Dec  8 20:45:30 2013
+++ src/sys/arch/i386/i386/trap.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.267 2013/12/08 20:45:30 dsl Exp $	*/
+/*	$NetBSD: trap.c,v 1.268 2014/01/19 14:30:37 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.267 2013/12/08 20:45:30 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.268 2014/01/19 14:30:37 dsl Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -203,7 +203,7 @@ xmm_si_code(struct lwp *l)
 		return 0;
 	}
 	pcb = lwp_getpcb(l);
-	mxcsr = pcb->pcb_savefpu.sv_xmm.sv_env.fx_mxcsr;
+	mxcsr = pcb->pcb_savefpu.sv_xmm.fx_mxcsr;
 
 	/*
          * Since we only have a single status and control register,

Index: src/sys/arch/i386/include/npx.h
diff -u src/sys/arch/i386/include/npx.h:1.27 src/sys/arch/i386/include/npx.h:1.28
--- src/sys/arch/i386/include/npx.h:1.27	Sun Dec  8 20:45:30 2013
+++ src/sys/arch/i386/include/npx.h	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.h,v 1.27 2013/12/08 20:45:30 dsl Exp $	*/
+/*	$NetBSD: npx.h,v 1.28 2014/01/19 14:30:37 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -42,30 +42,21 @@
 #ifndef	_I386_NPX_H_
 #define	_I386_NPX_H_
 
+/*
+ * Layout for code/data pointers relating to FP exceptions.
+ * Marked 'packed' because they aren't always 64bit aligned.
+ * Since the x86 cpu supports misaligned accesses it isn't
+ * worth avoiding the 'packed' attribute.
+ */
 union fp_addr {
 	uint64_t fa_64;	/* Linear address for 64bit systems */
 	struct {
-		uint32_t fa_off;	/* Linear address for 32 bit */
-		uint16_t fa_seg;	/* Code/data (etc) segment */
-		uint16_t fa_pad;
+		uint32_t fa_off;	/* linear address for 32 bit */
+		uint16_t fa_seg;	/* code/data (etc) segment */
+		uint16_t fa_opcode;	/* last opcode (sometimes) */
 	} fa_32;
 } __packed;
 
-/*
- * Environment information of floating point unit (fsave instruction).
- * Note that the 'tag word' contains 2 bits per register and is relative
- * to the stack top.
- * The fxsave version is 1 bit per register indexed by register number.
- */
-struct env87 {
-	long	 en_cw;		/* control word (16bits) */
-	long	 en_sw;		/* status word (16bits) */
-	long	 en_tw;		/* tag word (16bits) */
-	union fp_addr en_ip;	/* floating point instruction pointer */
-#define en_opcode en_ip.fa_32.fa_pad	/* opcode last executed (11bits) */
-	union fp_addr en_dp;	/* floating operand offset */
-};
-
 /* Contents of each floating point accumulator */
 struct fpacc87 {
 #ifdef dontdef	/* too unportable */
@@ -78,30 +69,29 @@ struct fpacc87 {
 #endif
 };
 
-/* Floating point context */
+/*
+ * floating point unit registers (fsave instruction).
+ * Note that the 'tag word' contains 2 bits per register and is relative
+ * to the stack top.
+ * The fxsave version is 1 bit per register indexed by register number.
+ */
 struct save87 {
-	struct	env87 sv_env;		/* floating point control/status */
-	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
+	uint32_t	s87_cw;		/* control word (16bits) */
+	uint32_t	s87_sw;		/* status word (16bits) */
+	uint32_t	s87_tw;		/* tag word (16bits) */
+	union fp_addr	s87_ip;		/* floating point instruction pointer */
+#define s87_opcode s87_ip.fa_32.fa_opcode	/* opcode last executed (11bits) */
+	union fp_addr	s87_dp;		/* floating operand offset */
+	struct fpacc87	s87_ac[8];	/* accumulator contents, 0-7 */
+
+	/* Additional fields that are not part of the hardware definition */
 #ifndef dontdef
-	uint32_t sv_ex_sw;	/* status word for last exception (was pad) */
-	uint32_t sv_ex_tw;	/* tag word for last exception (was pad) */
-	uint8_t	 sv_pad[8 * 2 - 2 * 4];	/* bogus historical padding */
+	uint32_t	s87_ex_sw;	/* status word for last exception */
+	uint32_t	s87_ex_tw;	/* tag word for last exception */
+	uint8_t		s87_pad[8 * 2 - 2 * 4];	/* bogus historical padding */
 #endif
 };
 
-/* Environment of FPU/MMX/SSE/SSE2 (fxsave instruction). */
-struct envxmm {
-/*0*/	uint16_t fx_cw;		/* FPU Control Word */
-	uint16_t fx_sw;		/* FPU Status Word */
-	uint8_t  fx_tw;		/* FPU Tag Word (abridged) */
-	uint8_t  fx_reserved1;
-	uint16_t fx_opcode;	/* FPU Opcode */
-	union fp_addr fx_ip;	/* FPU Instruction Pointer */
-/*16*/	union fp_addr fx_dp;	/* FPU Data pointer */
-	uint32_t fx_mxcsr;	/* MXCSR Register State */
-	uint32_t fx_mxcsr_mask;
-};
-
 /* FPU regsters in the extended save format. */
 struct fpaccxmm {
 	uint8_t fp_bytes[10];
@@ -114,8 +104,16 @@ struct xmmreg {
 };
 
 /* FPU/MMX/SSE/SSE2 context */
-struct savexmm {
-	struct envxmm sv_env;		/* control/status context */
+struct fxsave {
+/*0*/	uint16_t fx_cw;		/* FPU Control Word */
+	uint16_t fx_sw;		/* FPU Status Word */
+	uint8_t  fx_tw;		/* FPU Tag Word (abridged) */
+	uint8_t  fx_reserved1;
+	uint16_t fx_opcode;	/* FPU Opcode */
+	union fp_addr fx_ip;	/* FPU Instruction Pointer */
+/*16*/	union fp_addr fx_dp;	/* FPU Data pointer */
+	uint32_t fx_mxcsr;	/* MXCSR Register State */
+	uint32_t fx_mxcsr_mask;
 	struct fpaccxmm sv_ac[8];	/* ST/MM regs */
 	struct xmmreg sv_xmmregs[8];	/* XMM regs */
 	uint8_t sv_rsvd[16 * 14];
@@ -126,7 +124,7 @@ struct savexmm {
 
 union savefpu {
 	struct save87 sv_87;
-	struct savexmm sv_xmm;
+	struct fxsave sv_xmm;
 };
 
 /*
@@ -197,8 +195,8 @@ void	probeintr(void);
 void	probetrap(void);
 int	npx586bug1(int, int);
 void 	npxinit(struct cpu_info *);
-void	process_xmm_to_s87(const struct savexmm *, struct save87 *);
-void	process_s87_to_xmm(const struct save87 *, struct savexmm *);
+void	process_xmm_to_s87(const struct fxsave *, struct save87 *);
+void	process_s87_to_xmm(const struct save87 *, struct fxsave *);
 struct lwp;
 int	npxtrap(struct lwp *);
 

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.147 src/sys/arch/i386/isa/npx.c:1.148
--- src/sys/arch/i386/isa/npx.c:1.147	Sun Dec  8 20:45:30 2013
+++ src/sys/arch/i386/isa/npx.c	Sun Jan 19 14:30:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.147 2013/12/08 20:45:30 dsl Exp $	*/
+/*	$NetBSD: npx.c,v 1.148 2014/01/19 14:30:37 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.147 2013/12/08 20:45:30 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.148 2014/01/19 14:30:37 dsl Exp $");
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -435,13 +435,13 @@ npxintr(void *arg, struct intrframe *fra
 	fpu_save(addr);
 	fwait();
         if (i386_use_fxsave) {
-		fldcw(&addr->sv_xmm.sv_env.fx_cw);
+		fldcw(&addr->sv_xmm.fx_cw);
 		/*
 		 * FNINIT doesn't affect MXCSR or the XMM registers;
 		 * no need to re-load MXCSR here.
 		 */
         } else
-                fldcw(&addr->sv_87.sv_env.en_cw);
+                fldcw(&addr->sv_87.s87_cw);
 	fwait();
 	/*
 	 * Remember the exception status word and tag word.  The current
@@ -452,11 +452,11 @@ npxintr(void *arg, struct intrframe *fra
 	 * words, so the complete exception state can be recovered.
 	 */
         if (i386_use_fxsave) {
-		addr->sv_xmm.sv_ex_sw = addr->sv_xmm.sv_env.fx_sw;
-		addr->sv_xmm.sv_ex_tw = addr->sv_xmm.sv_env.fx_tw;
+		addr->sv_xmm.sv_ex_sw = addr->sv_xmm.fx_sw;
+		addr->sv_xmm.sv_ex_tw = addr->sv_xmm.fx_tw;
 	} else {
-		addr->sv_87.sv_ex_sw = addr->sv_87.sv_env.en_sw;
-		addr->sv_87.sv_ex_tw = addr->sv_87.sv_env.en_tw;
+		addr->sv_87.s87_ex_sw = addr->sv_87.s87_sw;
+		addr->sv_87.s87_ex_tw = addr->sv_87.s87_tw;
 	}
 	/*
 	 * Pass exception to process.
@@ -490,8 +490,8 @@ npxintr(void *arg, struct intrframe *fra
 			ksi.ksi_trap = (int)addr->sv_xmm.sv_ex_sw;
 		} else {
 			ksi.ksi_code =
-				x86fpflags_to_ksiginfo(addr->sv_87.sv_ex_sw);
-			ksi.ksi_trap = (int)addr->sv_87.sv_ex_sw;
+				x86fpflags_to_ksiginfo(addr->sv_87.s87_ex_sw);
+			ksi.ksi_trap = (int)addr->sv_87.s87_ex_sw;
 		}
 
 		trapsignal(l, &ksi);
@@ -609,11 +609,9 @@ npxdna(struct cpu_info *ci)
 	if ((l->l_md.md_flags & MDL_USEDFPU) == 0) {
 		fninit();
 		if (i386_use_fxsave) {
-			fldcw(&pcb->pcb_savefpu.
-			    sv_xmm.sv_env.fx_cw);
+			fldcw(&pcb->pcb_savefpu.sv_xmm.fx_cw);
 		} else {
-			fldcw(&pcb->pcb_savefpu.
-			    sv_87.sv_env.en_cw);
+			fldcw(&pcb->pcb_savefpu.sv_87.s87_cw);
 		}
 		l->l_md.md_flags |= MDL_USEDFPU;
 	} else if (i386_use_fxsave) {
@@ -914,15 +912,6 @@ static const uint8_t fpetable[128] = {
 	FPE_FLTSUB,	/* 7F - INV | DNML | DZ | OFL | UFL | IMP | STK */
 };
 
-#define GET_FPU_CW(pcb) \
-    (i386_use_fxsave ? \
-	pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw : \
-	pcb->pcb_savefpu.sv_87.sv_env.en_cw)
-#define GET_FPU_SW(pcb) \
-    (i386_use_fxsave ? \
-	pcb->pcb_savefpu.sv_xmm.sv_env.fx_sw : \
-	pcb->pcb_savefpu.sv_87.sv_env.en_sw)
-
 /*
  * Preserve the FP status word, clear FP exceptions, then generate a SIGFPE.
  *
@@ -961,8 +950,13 @@ npxtrap(struct lwp *l)
 	 */
 	if (fl != l) {
 		struct pcb *pcb = lwp_getpcb(l);
-		control = GET_FPU_CW(pcb);
-		status = GET_FPU_SW(pcb);
+		if (i386_use_fxsave) {
+			control = pcb->pcb_savefpu.sv_xmm.fx_cw;
+			status = pcb->pcb_savefpu.sv_xmm.fx_sw;
+		} else {
+			control = pcb->pcb_savefpu.sv_87.s87_cw;
+			status = pcb->pcb_savefpu.sv_87.s87_sw;
+		}
 	} else {
 		fnstcw(&control);
 		fnstsw(&status);

Index: src/sys/compat/linux/arch/i386/linux_machdep.c
diff -u src/sys/compat/linux/arch/i386/linux_machdep.c:1.154 src/sys/compat/linux/arch/i386/linux_machdep.c:1.155
--- src/sys/compat/linux/arch/i386/linux_machdep.c:1.154	Mon Dec  9 08:33:48 2013
+++ src/sys/compat/linux/arch/i386/linux_machdep.c	Sun Jan 19 14:30:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_machdep.c,v 1.154 2013/12/09 08:33:48 dsl Exp $	*/
+/*	$NetBSD: linux_machdep.c,v 1.155 2014/01/19 14:30:38 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1995, 2000, 2008, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.154 2013/12/09 08:33:48 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.155 2014/01/19 14:30:38 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vm86.h"
@@ -142,10 +142,10 @@ linux_setregs(struct lwp *l, struct exec
 	l->l_md.md_flags &= ~MDL_USEDFPU;
 
 	if (i386_use_fxsave) {
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_cw = __Linux_NPXCW__;
-		pcb->pcb_savefpu.sv_xmm.sv_env.fx_mxcsr = __INITIAL_MXCSR__;
+		pcb->pcb_savefpu.sv_xmm.fx_cw = __Linux_NPXCW__;
+		pcb->pcb_savefpu.sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
 	} else
-		pcb->pcb_savefpu.sv_87.sv_env.en_cw = __Linux_NPXCW__;
+		pcb->pcb_savefpu.sv_87.s87_cw = __Linux_NPXCW__;
 
 	tf = l->l_md.md_regs;
 	tf->tf_gs = 0;

Reply via email to