2015-04-26 19:48:08 +07:00
|
|
|
/*
|
|
|
|
* x86 FPU bug checks:
|
|
|
|
*/
|
|
|
|
#include <asm/fpu/internal.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boot time CPU/FPU FDIV bug detection code:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static double __initdata x = 4195835.0;
|
|
|
|
static double __initdata y = 3145727.0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This used to check for exceptions..
|
|
|
|
* However, it turns out that to support that,
|
|
|
|
* the XMM trap handlers basically had to
|
|
|
|
* be buggy. So let's have a correct XMM trap
|
|
|
|
* handler, and forget about printing out
|
|
|
|
* some status at boot.
|
|
|
|
*
|
|
|
|
* We should really only care about bugs here
|
|
|
|
* anyway. Not features.
|
|
|
|
*/
|
|
|
|
static void __init check_fpu(void)
|
|
|
|
{
|
2015-05-05 15:54:04 +07:00
|
|
|
u32 cr0_saved;
|
2015-04-26 19:48:08 +07:00
|
|
|
s32 fdiv_bug;
|
|
|
|
|
2015-05-05 15:54:04 +07:00
|
|
|
/* We might have CR0::TS set already, clear it: */
|
|
|
|
cr0_saved = read_cr0();
|
|
|
|
write_cr0(cr0_saved & ~X86_CR0_TS);
|
|
|
|
|
2015-04-26 19:48:08 +07:00
|
|
|
kernel_fpu_begin();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trap_init() enabled FXSR and company _before_ testing for FP
|
|
|
|
* problems here.
|
|
|
|
*
|
|
|
|
* Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug
|
|
|
|
*/
|
|
|
|
__asm__("fninit\n\t"
|
|
|
|
"fldl %1\n\t"
|
|
|
|
"fdivl %2\n\t"
|
|
|
|
"fmull %2\n\t"
|
|
|
|
"fldl %1\n\t"
|
|
|
|
"fsubp %%st,%%st(1)\n\t"
|
|
|
|
"fistpl %0\n\t"
|
|
|
|
"fwait\n\t"
|
|
|
|
"fninit"
|
|
|
|
: "=m" (*&fdiv_bug)
|
|
|
|
: "m" (*&x), "m" (*&y));
|
|
|
|
|
|
|
|
kernel_fpu_end();
|
|
|
|
|
2015-05-05 15:54:04 +07:00
|
|
|
write_cr0(cr0_saved);
|
|
|
|
|
2015-04-26 19:48:08 +07:00
|
|
|
if (fdiv_bug) {
|
|
|
|
set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);
|
|
|
|
pr_warn("Hmm, FPU with FDIV bug\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 14:52:42 +07:00
|
|
|
void __init fpu__init_check_bugs(void)
|
2015-04-26 19:48:08 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* kernel_fpu_begin/end() in check_fpu() relies on the patched
|
|
|
|
* alternative instructions.
|
|
|
|
*/
|
|
|
|
if (cpu_has_fpu)
|
|
|
|
check_fpu();
|
|
|
|
}
|