From 5524f0b4e61d20dc53f24613a3ad8af532824573 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Tue, 1 Mar 2011 22:44:16 +0800 Subject: [PATCH] kernel: Don't store FPU status into the reserved area of fxsave Since each time before the old sv_ex_sw is accessed, fnstsw() is always called, it no longer makes any sense to save the temporary in the reserved area for fxsave. And more important: saving the FPU status into fxsave area overwrites saved xmm register value. --- sys/cpu/i386/include/npx.h | 4 ++-- sys/cpu/x86_64/include/npx.h | 4 ++-- sys/platform/pc32/i386/machdep.c | 4 ---- sys/platform/pc32/isa/npx.c | 20 +++----------------- sys/platform/pc64/x86_64/machdep.c | 4 ---- sys/platform/pc64/x86_64/npx.c | 13 ------------- sys/platform/vkernel/i386/cpu_regs.c | 4 ---- sys/platform/vkernel/i386/npx.c | 20 +++----------------- sys/platform/vkernel64/x86_64/cpu_regs.c | 4 ---- sys/platform/vkernel64/x86_64/npx.c | 13 ------------- 10 files changed, 10 insertions(+), 80 deletions(-) diff --git a/sys/cpu/i386/include/npx.h b/sys/cpu/i386/include/npx.h index afbff239bd..3096149252 100644 --- a/sys/cpu/i386/include/npx.h +++ b/sys/cpu/i386/include/npx.h @@ -78,7 +78,7 @@ struct fpacc87 { struct save87 { struct env87 sv_env; /* floating point control/status */ struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ - u_long sv_ex_sw; /* status word for last exception */ + u_long sv_unused001; /* * Bogus padding for emulators. Emulators should use their own * struct and arrange to store into this struct (ending here) @@ -120,7 +120,7 @@ struct savexmm { u_char fp_pad[6]; /* 6 (padding) */ } sv_fp[8]; struct xmmacc sv_xmm[8]; /* 128 */ - u_long sv_ex_sw; /* status word for last exception */ + u_long sv_unused001; u_char sv_pad[220]; } __attribute__((aligned(16))); diff --git a/sys/cpu/x86_64/include/npx.h b/sys/cpu/x86_64/include/npx.h index 186682cefd..35f8184ff6 100644 --- a/sys/cpu/x86_64/include/npx.h +++ b/sys/cpu/x86_64/include/npx.h @@ -78,7 +78,7 @@ struct fpacc87 { struct save87 { struct env87 sv_env; /* floating point control/status */ struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ - u_long sv_ex_sw; /* status word for last exception */ + u_long sv_unused001; /* * Bogus padding for emulators. Emulators should use their own * struct and arrange to store into this struct (ending here) @@ -120,7 +120,7 @@ struct savexmm { u_char fp_pad[6]; /* 6 (padding) */ } sv_fp[8]; struct xmmacc sv_xmm[8]; /* 128 */ - u_long sv_ex_sw; /* status word for last exception */ + u_long sv_unused001; u_char sv_pad[220]; } __attribute__((aligned(16))); diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index 8834b2ac80..6faa0cd07b 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -2326,8 +2326,6 @@ fill_fpregs_xmm(struct savexmm *sv_xmm, struct save87 *sv_87) /* FPU registers */ for (i = 0; i < 8; ++i) sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc; - - sv_87->sv_ex_sw = sv_xmm->sv_ex_sw; } static void @@ -2350,8 +2348,6 @@ set_fpregs_xmm(struct save87 *sv_87, struct savexmm *sv_xmm) /* FPU registers */ for (i = 0; i < 8; ++i) sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i]; - - sv_xmm->sv_ex_sw = sv_87->sv_ex_sw; } #endif /* CPU_DISABLE_SSE */ diff --git a/sys/platform/pc32/isa/npx.c b/sys/platform/pc32/isa/npx.c index 6cdedd51e0..47ac83ecad 100644 --- a/sys/platform/pc32/isa/npx.c +++ b/sys/platform/pc32/isa/npx.c @@ -128,16 +128,6 @@ void stop_emulating (void); #endif /* __GNUC__ */ -#ifndef CPU_DISABLE_SSE -#define GET_FPU_EXSW_PTR(td) \ - (cpu_fxsr ? \ - &(td)->td_savefpu->sv_xmm.sv_ex_sw : \ - &(td)->td_savefpu->sv_87.sv_ex_sw) -#else /* CPU_DISABLE_SSE */ -#define GET_FPU_EXSW_PTR(td) \ - (&(td)->td_savefpu->sv_87.sv_ex_sw) -#endif /* CPU_DISABLE_SSE */ - typedef u_char bool_t; #ifndef CPU_DISABLE_SSE static void fpu_clean_state(void); @@ -763,8 +753,8 @@ npx_intr(void *dummy) { int code; u_short control; + u_short status; struct intrframe *frame; - u_long *exstat; crit_enter(); @@ -794,9 +784,8 @@ npx_intr(void *dummy) panic("npxintr from non-current process"); } - exstat = GET_FPU_EXSW_PTR(curthread); outb(0xf0, 0); - fnstsw(exstat); + fnstsw(&status); fnstcw(&control); fnclex(); @@ -824,7 +813,7 @@ npx_intr(void *dummy) * this exception. */ code = - fpetable[(*exstat & ~control & 0x3f) | (*exstat & 0x40)]; + fpetable[(status & ~control & 0x3f) | (status & 0x40)]; trapsignal(curthread->td_lwp, SIGFPE, code); } else { /* @@ -859,7 +848,6 @@ int npxdna(void) { thread_t td = curthread; - u_long *exstat; int didinit = 0; if (!npx_exists) @@ -894,8 +882,6 @@ npxdna(void) * Record new context early in case frstor causes an IRQ13. */ mdcpu->gd_npxthread = td; - exstat = GET_FPU_EXSW_PTR(td); - *exstat = 0; /* * The following frstor may cause an IRQ13 when the state being * restored has a pending error. The error will appear to have been diff --git a/sys/platform/pc64/x86_64/machdep.c b/sys/platform/pc64/x86_64/machdep.c index bdd136f354..3fbae08f97 100644 --- a/sys/platform/pc64/x86_64/machdep.c +++ b/sys/platform/pc64/x86_64/machdep.c @@ -2083,8 +2083,6 @@ fill_fpregs_xmm(struct savexmm *sv_xmm, struct save87 *sv_87) /* FPU registers */ for (i = 0; i < 8; ++i) sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc; - - sv_87->sv_ex_sw = sv_xmm->sv_ex_sw; } static void @@ -2107,8 +2105,6 @@ set_fpregs_xmm(struct save87 *sv_87, struct savexmm *sv_xmm) /* FPU registers */ for (i = 0; i < 8; ++i) sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i]; - - sv_xmm->sv_ex_sw = sv_87->sv_ex_sw; } #endif /* CPU_DISABLE_SSE */ diff --git a/sys/platform/pc64/x86_64/npx.c b/sys/platform/pc64/x86_64/npx.c index d54f7a1ac4..fab71e4102 100644 --- a/sys/platform/pc64/x86_64/npx.c +++ b/sys/platform/pc64/x86_64/npx.c @@ -86,16 +86,6 @@ : : "n" (CR0_TS) : "ax") #define stop_emulating() __asm("clts") -#ifndef CPU_DISABLE_SSE -#define GET_FPU_EXSW_PTR(td) \ - (cpu_fxsr ? \ - &(td)->td_savefpu->sv_xmm.sv_ex_sw : \ - &(td)->td_savefpu->sv_87.sv_ex_sw) -#else /* CPU_DISABLE_SSE */ -#define GET_FPU_EXSW_PTR(td) \ - (&(td)->td_savefpu->sv_87.sv_ex_sw) -#endif /* CPU_DISABLE_SSE */ - typedef u_char bool_t; #ifndef CPU_DISABLE_SSE static void fpu_clean_state(void); @@ -325,7 +315,6 @@ int npxdna(void) { thread_t td = curthread; - u_long *exstat; int didinit = 0; if (mdcpu->gd_npxthread != NULL) { @@ -358,8 +347,6 @@ npxdna(void) * Record new context early in case frstor causes an IRQ13. */ mdcpu->gd_npxthread = td; - exstat = GET_FPU_EXSW_PTR(td); - *exstat = 0; /* * The following frstor may cause an IRQ13 when the state being * restored has a pending error. The error will appear to have been diff --git a/sys/platform/vkernel/i386/cpu_regs.c b/sys/platform/vkernel/i386/cpu_regs.c index 35305fe9ba..0c2afd2ea9 100644 --- a/sys/platform/vkernel/i386/cpu_regs.c +++ b/sys/platform/vkernel/i386/cpu_regs.c @@ -1003,8 +1003,6 @@ fill_fpregs_xmm(struct savexmm *sv_xmm, struct save87 *sv_87) /* FPU registers */ for (i = 0; i < 8; ++i) sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc; - - sv_87->sv_ex_sw = sv_xmm->sv_ex_sw; } static void @@ -1027,8 +1025,6 @@ set_fpregs_xmm(struct save87 *sv_87, struct savexmm *sv_xmm) /* FPU registers */ for (i = 0; i < 8; ++i) sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i]; - - sv_xmm->sv_ex_sw = sv_87->sv_ex_sw; } #endif /* CPU_DISABLE_SSE */ diff --git a/sys/platform/vkernel/i386/npx.c b/sys/platform/vkernel/i386/npx.c index 2f1426723c..6d686d498c 100644 --- a/sys/platform/vkernel/i386/npx.c +++ b/sys/platform/vkernel/i386/npx.c @@ -86,16 +86,6 @@ #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) #endif -#ifndef CPU_DISABLE_SSE -#define GET_FPU_EXSW_PTR(td) \ - (cpu_fxsr ? \ - &(td)->td_savefpu->sv_xmm.sv_ex_sw : \ - &(td)->td_savefpu->sv_87.sv_ex_sw) -#else /* CPU_DISABLE_SSE */ -#define GET_FPU_EXSW_PTR(td) \ - (&(td)->td_savefpu->sv_87.sv_ex_sw) -#endif /* CPU_DISABLE_SSE */ - typedef u_char bool_t; #ifndef CPU_DISABLE_SSE static void fpu_clean_state(void); @@ -372,8 +362,8 @@ npx_intr(void *dummy) { int code; u_short control; + u_short status; struct intrframe *frame; - u_long *exstat; crit_enter(); @@ -407,9 +397,8 @@ npx_intr(void *dummy) panic("npxintr from non-current process"); } - exstat = GET_FPU_EXSW_PTR(curthread); outb(0xf0, 0); - fnstsw(exstat); + fnstsw(&status); fnstcw(&control); fnclex(); @@ -437,7 +426,7 @@ npx_intr(void *dummy) * this exception. */ code = - fpetable[(*exstat & ~control & 0x3f) | (*exstat & 0x40)]; + fpetable[(status & ~control & 0x3f) | (status & 0x40)]; trapsignal(curthread->td_lwp, SIGFPE, code); } else { /* @@ -474,7 +463,6 @@ int npxdna(struct trapframe *frame) { thread_t td = curthread; - u_long *exstat; int didinit = 0; if (mdcpu->gd_npxthread != NULL) { @@ -507,8 +495,6 @@ npxdna(struct trapframe *frame) * Record new context early in case frstor causes an IRQ13. */ mdcpu->gd_npxthread = td; - exstat = GET_FPU_EXSW_PTR(td); - *exstat = 0; /* * The following frstor may cause an IRQ13 when the state being * restored has a pending error. The error will appear to have been diff --git a/sys/platform/vkernel64/x86_64/cpu_regs.c b/sys/platform/vkernel64/x86_64/cpu_regs.c index 8745bdc32e..c396255267 100644 --- a/sys/platform/vkernel64/x86_64/cpu_regs.c +++ b/sys/platform/vkernel64/x86_64/cpu_regs.c @@ -972,8 +972,6 @@ fill_fpregs_xmm(struct savexmm *sv_xmm, struct save87 *sv_87) /* FPU registers */ for (i = 0; i < 8; ++i) sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc; - - sv_87->sv_ex_sw = sv_xmm->sv_ex_sw; } static void @@ -996,8 +994,6 @@ set_fpregs_xmm(struct save87 *sv_87, struct savexmm *sv_xmm) /* FPU registers */ for (i = 0; i < 8; ++i) sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i]; - - sv_xmm->sv_ex_sw = sv_87->sv_ex_sw; } #endif /* CPU_DISABLE_SSE */ diff --git a/sys/platform/vkernel64/x86_64/npx.c b/sys/platform/vkernel64/x86_64/npx.c index 5b3f637cc4..e2fbe7079c 100644 --- a/sys/platform/vkernel64/x86_64/npx.c +++ b/sys/platform/vkernel64/x86_64/npx.c @@ -84,16 +84,6 @@ #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) #endif -#ifndef CPU_DISABLE_SSE -#define GET_FPU_EXSW_PTR(td) \ - (cpu_fxsr ? \ - &(td)->td_savefpu->sv_xmm.sv_ex_sw : \ - &(td)->td_savefpu->sv_87.sv_ex_sw) -#else /* CPU_DISABLE_SSE */ -#define GET_FPU_EXSW_PTR(td) \ - (&(td)->td_savefpu->sv_87.sv_ex_sw) -#endif /* CPU_DISABLE_SSE */ - typedef u_char bool_t; #ifndef CPU_DISABLE_SSE static void fpu_clean_state(void); @@ -353,7 +343,6 @@ int npxdna(struct trapframe *frame) { thread_t td = curthread; - u_long *exstat; int didinit = 0; if (mdcpu->gd_npxthread != NULL) { @@ -386,8 +375,6 @@ npxdna(struct trapframe *frame) * Record new context early in case frstor causes an IRQ13. */ mdcpu->gd_npxthread = td; - exstat = GET_FPU_EXSW_PTR(td); - *exstat = 0; /* * The following frstor may cause an IRQ13 when the state being * restored has a pending error. The error will appear to have been -- 2.41.0