Module Name:    src
Committed By:   dsl
Date:           Mon Dec 31 16:20:18 UTC 2012

Modified Files:
        src/sys/arch/amd64/amd64: fpu.c netbsd32_machdep.c
        src/sys/arch/amd64/include: fpu.h pcb.h

Log Message:
Move the two fields used to save some i387 state on the last fpu trap
  into their own sub-structure of the pcb (from 'struct savefpu').
They only (seem) to be used in some code that generates core dumps
  for 32bit processes (code that might be broken as well!).
'struct safefpu' is now identical to 'struct fxsave64'. One (or both)
  needs extending to support AVX - might need to be dynamically sized.
Removed all the __aligned(16) except for the one in struct pcb itself.
  Only the copy used for the fsave instruction need be aligned.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/amd64/amd64/fpu.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/include/fpu.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/include/pcb.h

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/amd64/amd64/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.39 src/sys/arch/amd64/amd64/fpu.c:1.40
--- src/sys/arch/amd64/amd64/fpu.c:1.39	Sun Jul  8 20:14:11 2012
+++ src/sys/arch/amd64/amd64/fpu.c	Mon Dec 31 16:20:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.39 2012/07/08 20:14:11 dsl Exp $	*/
+/*	$NetBSD: fpu.c,v 1.40 2012/12/31 16:20:17 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.39 2012/07/08 20:14:11 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.40 2012/12/31 16:20:17 dsl Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -194,6 +194,9 @@ fputrap(struct trapframe *frame)
 	 */
 	KASSERT(l == curlwp);
 	fxsave(sfp);
+	pcb->pcb_savefpu_i387.fp_ex_tw = sfp->fp_fxsave.fx_ftw;
+	pcb->pcb_savefpu_i387.fp_ex_sw = sfp->fp_fxsave.fx_fsw;
+
 	if (frame->tf_trapno == T_XMM) {
 		mxcsr = sfp->fp_fxsave.fx_mxcsr;
 		statbits = mxcsr;
@@ -209,8 +212,6 @@ fputrap(struct trapframe *frame)
 	}
 	KPREEMPT_ENABLE(l);
 
-	sfp->fp_ex_tw = sfp->fp_fxsave.fx_ftw;
-	sfp->fp_ex_sw = sfp->fp_fxsave.fx_fsw;
 	KSI_INIT_TRAP(&ksi);
 	ksi.ksi_signo = SIGFPE;
 	ksi.ksi_addr = (void *)frame->tf_rip;

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.79 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.80
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.79	Sun Jul 15 15:17:56 2012
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Mon Dec 31 16:20:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.79 2012/07/15 15:17:56 dsl Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.80 2012/12/31 16:20:17 dsl Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.79 2012/07/15 15:17:56 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.80 2012/12/31 16:20:17 dsl Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -568,7 +568,6 @@ int
 netbsd32_process_read_fpregs(struct lwp *l, struct fpreg32 *regs)
 {
 	struct pcb *pcb = lwp_getpcb(l);
-	struct savefpu *sf = &pcb->pcb_savefpu;
 	struct fpreg regs64;
 	struct save87 *s87 = (struct save87 *)regs;
 	int error, i;
@@ -598,13 +597,13 @@ netbsd32_process_read_fpregs(struct lwp 
 
 		s87->sv_ex_tw |=
 		    (xmm_to_s87_tag((uint8_t *)&regs64.fxstate.fx_st[i][0], i,
-		     sf->fp_ex_tw) << (i * 2));
+		     pcb->pcb_savefpu_i387.fp_ex_tw) << (i * 2));
 
 		memcpy(&s87->sv_ac[i].fp_bytes, &regs64.fxstate.fx_st[i][0],
 		    sizeof(s87->sv_ac[i].fp_bytes));
 	}
 
-	s87->sv_ex_sw = sf->fp_ex_sw;
+	s87->sv_ex_sw = pcb->pcb_savefpu_i387.fp_ex_sw;
 
 	return (0);
 }

Index: src/sys/arch/amd64/include/fpu.h
diff -u src/sys/arch/amd64/include/fpu.h:1.6 src/sys/arch/amd64/include/fpu.h:1.7
--- src/sys/arch/amd64/include/fpu.h:1.6	Sat Dec 15 21:50:43 2012
+++ src/sys/arch/amd64/include/fpu.h	Mon Dec 31 16:20:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.h,v 1.6 2012/12/15 21:50:43 dsl Exp $	*/
+/*	$NetBSD: fpu.h,v 1.7 2012/12/31 16:20:17 dsl Exp $	*/
 
 #ifndef	_AMD64_FPU_H_
 #define	_AMD64_FPU_H_
@@ -7,7 +7,9 @@
  * NetBSD/amd64 only uses the extended save/restore format used
  * by fxsave/fsrestore, to always deal with the SSE registers,
  * which are part of the ABI to pass floating point values.
- * Must be stored in memory on a 16-byte boundary.
+ *
+ * The memory used for the 'fsave' instruction must be 16 byte aligned,
+ * but the definition here isn't aligned to avoid padding elsewhere.
  */
 
 struct fxsave64 {
@@ -30,10 +32,12 @@ __CTASSERT(sizeof (struct fxsave64) == 5
 
 struct savefpu {
 	struct fxsave64 fp_fxsave;	/* see above */
+};
+
+struct savefpu_i387 {
 	uint16_t fp_ex_sw;		/* saved status from last exception */
 	uint16_t fp_ex_tw;		/* saved tag from last exception */
-} __aligned(16);
-
+};
 
 /*
  * The i387 defaults to Intel extended precision mode and round to nearest,

Index: src/sys/arch/amd64/include/pcb.h
diff -u src/sys/arch/amd64/include/pcb.h:1.17 src/sys/arch/amd64/include/pcb.h:1.18
--- src/sys/arch/amd64/include/pcb.h:1.17	Wed Jul  7 01:14:52 2010
+++ src/sys/arch/amd64/include/pcb.h	Mon Dec 31 16:20:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcb.h,v 1.17 2010/07/07 01:14:52 chs Exp $	*/
+/*	$NetBSD: pcb.h,v 1.18 2012/12/31 16:20:17 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -81,10 +81,6 @@
 
 #define	NIOPORTS	1024		/* # of ports we allow to be mapped */
 
-/*
- * Please note that the pcb_savefpu field in struct below must be
- * on a 16-byte boundary.
- */
 struct pcb {
 	int	  pcb_flags;
 #define	PCB_USER_LDT	0x01		/* has user-set LDT */
@@ -96,8 +92,10 @@ struct pcb {
 	uint64_t pcb_rsp;
 	uint64_t pcb_rbp;
 	uint64_t pcb_usersp;
-	uint64_t pcb_unused;		/* unused */
+	uint32_t pcb_unused;		/* unused */
+	struct	savefpu_i387 pcb_savefpu_i387; /* i387 status on last exception */
 	struct	savefpu pcb_savefpu __aligned(16); /* floating point state */
+	uint32_t pcb_unused_1[4];	/* unused */
 	void     *pcb_onfault;		/* copyin/out fault recovery */
 	struct cpu_info *pcb_fpcpu;	/* cpu holding our fp state. */
 	uint64_t  pcb_fs;

Reply via email to