Initialize the mxcsr properly, so the initial value in a process isn't

just the value that was left over from some other application.
This commit is contained in:
David Schultz 2005-03-17 22:21:36 +00:00
parent 738473e4ff
commit c513b0c567
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143768
2 changed files with 11 additions and 0 deletions

View File

@ -134,6 +134,7 @@ union savefpu {
* intermediate values are stored in memory or in FPU registers. * intermediate values are stored in memory or in FPU registers.
*/ */
#define __INITIAL_NPXCW__ 0x127F #define __INITIAL_NPXCW__ 0x127F
#define __INITIAL_MXCSR__ 0x1F80
#ifdef _KERNEL #ifdef _KERNEL
int npxdna(void); int npxdna(void);

View File

@ -108,6 +108,7 @@ __FBSDID("$FreeBSD$");
#ifdef CPU_ENABLE_SSE #ifdef CPU_ENABLE_SSE
#define fxrstor(addr) __asm("fxrstor %0" : : "m" (*(addr))) #define fxrstor(addr) __asm("fxrstor %0" : : "m" (*(addr)))
#define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr)))
#define ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr))
#endif #endif
#define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \ #define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \
: : "n" (CR0_TS) : "ax") : : "n" (CR0_TS) : "ax")
@ -754,6 +755,9 @@ npxdna()
{ {
struct pcb *pcb; struct pcb *pcb;
register_t s; register_t s;
#ifdef CPU_ENABLE_SSE
int mxcsr;
#endif
u_short control; u_short control;
if (!npx_exists) if (!npx_exists)
@ -788,6 +792,12 @@ npxdna()
fninit(); fninit();
control = __INITIAL_NPXCW__; control = __INITIAL_NPXCW__;
fldcw(&control); fldcw(&control);
#ifdef CPU_ENABLE_SSE
if (cpu_fxsr) {
mxcsr = __INITIAL_MXCSR__;
ldmxcsr(mxcsr);
}
#endif
pcb->pcb_flags |= PCB_NPXINITDONE; pcb->pcb_flags |= PCB_NPXINITDONE;
} else { } else {
/* /*