svn commit: r238678 - in head/sys/i386: i386 include isa

Konstantin Belousov kib at FreeBSD.org
Sat Jul 21 21:52:49 UTC 2012


Author: kib
Date: Sat Jul 21 21:52:48 2012
New Revision: 238678
URL: http://svn.freebsd.org/changeset/base/238678

Log:
  MFCamd64 r238598:
  Provide siginfo.si_code for floating point errors when error occurs
  using the SSE math processor.
  
  MFC after:    3 weeks

Modified:
  head/sys/i386/i386/trap.c
  head/sys/i386/include/npx.h
  head/sys/i386/isa/npx.c

Modified: head/sys/i386/i386/trap.c
==============================================================================
--- head/sys/i386/i386/trap.c	Sat Jul 21 21:49:05 2012	(r238677)
+++ head/sys/i386/i386/trap.c	Sat Jul 21 21:52:48 2012	(r238678)
@@ -369,7 +369,7 @@ trap(struct trapframe *frame)
 
 		case T_ARITHTRAP:	/* arithmetic trap */
 #ifdef DEV_NPX
-			ucode = npxtrap();
+			ucode = npxtrap_x87();
 			if (ucode == -1)
 				goto userout;
 #else
@@ -532,7 +532,13 @@ trap(struct trapframe *frame)
 			break;
 
 		case T_XMMFLT:		/* SIMD floating-point exception */
-			ucode = 0; /* XXX */
+#if defined(DEV_NPX) && !defined(CPU_DISABLE_SSE) && defined(I686_CPU)
+			ucode = npxtrap_sse();
+			if (ucode == -1)
+				goto userout;
+#else
+			ucode = 0;
+#endif
 			i = SIGFPE;
 			break;
 		}

Modified: head/sys/i386/include/npx.h
==============================================================================
--- head/sys/i386/include/npx.h	Sat Jul 21 21:49:05 2012	(r238677)
+++ head/sys/i386/include/npx.h	Sat Jul 21 21:52:48 2012	(r238678)
@@ -55,7 +55,8 @@ int	npxgetregs(struct thread *td);
 void	npxinit(void);
 void	npxsave(union savefpu *addr);
 void	npxsetregs(struct thread *td, union savefpu *addr);
-int	npxtrap(void);
+int	npxtrap_x87(void);
+int	npxtrap_sse(void);
 void	npxuserinited(struct thread *);
 struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags);
 void	fpu_kern_free_ctx(struct fpu_kern_ctx *ctx);

Modified: head/sys/i386/isa/npx.c
==============================================================================
--- head/sys/i386/isa/npx.c	Sat Jul 21 21:49:05 2012	(r238677)
+++ head/sys/i386/isa/npx.c	Sat Jul 21 21:52:48 2012	(r238678)
@@ -600,12 +600,13 @@ static char fpetable[128] = {
  * For XMM traps, the exceptions were never cleared.
  */
 int
-npxtrap()
+npxtrap_x87(void)
 {
 	u_short control, status;
 
 	if (!hw_float) {
-		printf("npxtrap: fpcurthread = %p, curthread = %p, hw_float = %d\n",
+		printf(
+	"npxtrap_x87: fpcurthread = %p, curthread = %p, hw_float = %d\n",
 		       PCPU_GET(fpcurthread), curthread, hw_float);
 		panic("npxtrap from nowhere");
 	}
@@ -627,6 +628,28 @@ npxtrap()
 	return (fpetable[status & ((~control & 0x3f) | 0x40)]);
 }
 
+#ifdef CPU_ENABLE_SSE
+int
+npxtrap_sse(void)
+{
+	u_int mxcsr;
+
+	if (!hw_float) {
+		printf(
+	"npxtrap_sse: fpcurthread = %p, curthread = %p, hw_float = %d\n",
+		       PCPU_GET(fpcurthread), curthread, hw_float);
+		panic("npxtrap from nowhere");
+	}
+	critical_enter();
+	if (PCPU_GET(fpcurthread) != curthread)
+		mxcsr = curthread->td_pcb->pcb_save->sv_xmm.sv_env.en_mxcsr;
+	else
+		stmxcsr(&mxcsr);
+	critical_exit();
+	return (fpetable[(mxcsr & (~mxcsr >> 7)) & 0x3f]);
+}
+#endif
+
 /*
  * Implement device not available (DNA) exception
  *


More information about the svn-src-all mailing list