[Midnightbsd-cvs] src [7962] trunk/sys/amd64: On amd64, provide siginfo.si_code for floating point errors when the error occurs using SSE
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Sep 14 19:03:00 EDT 2016
Revision: 7962
http://svnweb.midnightbsd.org/src/?rev=7962
Author: laffer1
Date: 2016-09-14 19:03:00 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
On amd64, provide siginfo.si_code for floating point errors when the error occurs using SSE
Modified Paths:
--------------
trunk/sys/amd64/amd64/fpu.c
trunk/sys/amd64/amd64/trap.c
trunk/sys/amd64/include/fpu.h
Modified: trunk/sys/amd64/amd64/fpu.c
===================================================================
--- trunk/sys/amd64/amd64/fpu.c 2016-09-14 23:00:42 UTC (rev 7961)
+++ trunk/sys/amd64/amd64/fpu.c 2016-09-14 23:03:00 UTC (rev 7962)
@@ -115,9 +115,6 @@
#define start_emulating() load_cr0(rcr0() | CR0_TS)
#define stop_emulating() clts()
-#define GET_FPU_CW(thread) ((thread)->td_pcb->pcb_save->sv_env.en_cw)
-#define GET_FPU_SW(thread) ((thread)->td_pcb->pcb_save->sv_env.en_sw)
-
CTASSERT(sizeof(struct savefpu) == 512);
CTASSERT(sizeof(struct xstate_hdr) == 64);
CTASSERT(sizeof(struct savefpu_ymm) == 832);
@@ -516,12 +513,16 @@
};
/*
- * Preserve the FP status word, clear FP exceptions, then generate a SIGFPE.
+ * Preserve the FP status word, clear FP exceptions for x87, then
+ * generate a SIGFPE.
*
- * Clearing exceptions is necessary mainly to avoid IRQ13 bugs. We now
- * depend on longjmp() restoring a usable state. Restoring the state
- * or examining it might fail if we didn't clear exceptions.
+ * Clearing exceptions was necessary mainly to avoid IRQ13 bugs and is
+ * engraved in our i386 ABI. We now depend on longjmp() restoring a
+ * usable state. Restoring the state or examining it might fail if we
+ * didn't clear exceptions.
*
+ * For SSE exceptions, the exceptions are not cleared.
+ *
* The error code chosen will be one of the FPE_... macros. It will be
* sent as the second argument to old BSD-style signal handlers and as
* "siginfo_t->si_code" (second argument) to SA_SIGINFO signal handlers.
@@ -533,8 +534,9 @@
* solution for signals other than SIGFPE.
*/
int
-fputrap()
+fputrap_x87(void)
{
+ struct savefpu *pcb_save;
u_short control, status;
critical_enter();
@@ -545,19 +547,33 @@
* wherever they are.
*/
if (PCPU_GET(fpcurthread) != curthread) {
- control = GET_FPU_CW(curthread);
- status = GET_FPU_SW(curthread);
+ pcb_save = PCPU_GET(curpcb)->pcb_save;
+ control = pcb_save->sv_env.en_cw;
+ status = pcb_save->sv_env.en_sw;
} else {
fnstcw(&control);
fnstsw(&status);
+ fnclex();
}
- if (PCPU_GET(fpcurthread) == curthread)
- fnclex();
critical_exit();
return (fpetable[status & ((~control & 0x3f) | 0x40)]);
}
+int
+fputrap_sse(void)
+{
+ u_int mxcsr;
+
+ critical_enter();
+ if (PCPU_GET(fpcurthread) != curthread)
+ mxcsr = PCPU_GET(curpcb)->pcb_save->sv_env.en_mxcsr;
+ else
+ stmxcsr(&mxcsr);
+ critical_exit();
+ return (fpetable[(mxcsr & (~mxcsr >> 7)) & 0x3f]);
+}
+
/*
* Implement device not available (DNA) exception
*
Modified: trunk/sys/amd64/amd64/trap.c
===================================================================
--- trunk/sys/amd64/amd64/trap.c 2016-09-14 23:00:42 UTC (rev 7961)
+++ trunk/sys/amd64/amd64/trap.c 2016-09-14 23:03:00 UTC (rev 7962)
@@ -333,7 +333,7 @@
break;
case T_ARITHTRAP: /* arithmetic trap */
- ucode = fputrap();
+ ucode = fputrap_x87();
if (ucode == -1)
goto userout;
i = SIGFPE;
@@ -447,7 +447,9 @@
break;
case T_XMMFLT: /* SIMD floating-point exception */
- ucode = 0; /* XXX */
+ ucode = fputrap_sse();
+ if (ucode == -1)
+ goto userout;
i = SIGFPE;
break;
}
Modified: trunk/sys/amd64/include/fpu.h
===================================================================
--- trunk/sys/amd64/include/fpu.h 2016-09-14 23:00:42 UTC (rev 7961)
+++ trunk/sys/amd64/include/fpu.h 2016-09-14 23:03:00 UTC (rev 7962)
@@ -145,7 +145,8 @@
char *xfpustate, size_t xfpustate_size);
int fpusetxstate(struct thread *td, char *xfpustate,
size_t xfpustate_size);
-int fputrap(void);
+int fputrap_sse(void);
+int fputrap_x87(void);
void fpuuserinited(struct thread *td);
struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags);
void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx);
More information about the Midnightbsd-cvs
mailing list