Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * x86 FPU bug checks:
0004  */
0005 #include <asm/fpu/api.h>
0006 
0007 /*
0008  * Boot time CPU/FPU FDIV bug detection code:
0009  */
0010 
0011 static double __initdata x = 4195835.0;
0012 static double __initdata y = 3145727.0;
0013 
0014 /*
0015  * This used to check for exceptions..
0016  * However, it turns out that to support that,
0017  * the XMM trap handlers basically had to
0018  * be buggy. So let's have a correct XMM trap
0019  * handler, and forget about printing out
0020  * some status at boot.
0021  *
0022  * We should really only care about bugs here
0023  * anyway. Not features.
0024  */
0025 void __init fpu__init_check_bugs(void)
0026 {
0027     s32 fdiv_bug;
0028 
0029     /* kernel_fpu_begin/end() relies on patched alternative instructions. */
0030     if (!boot_cpu_has(X86_FEATURE_FPU))
0031         return;
0032 
0033     kernel_fpu_begin();
0034 
0035     /*
0036      * trap_init() enabled FXSR and company _before_ testing for FP
0037      * problems here.
0038      *
0039      * Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug
0040      */
0041     __asm__("fninit\n\t"
0042         "fldl %1\n\t"
0043         "fdivl %2\n\t"
0044         "fmull %2\n\t"
0045         "fldl %1\n\t"
0046         "fsubp %%st,%%st(1)\n\t"
0047         "fistpl %0\n\t"
0048         "fwait\n\t"
0049         "fninit"
0050         : "=m" (*&fdiv_bug)
0051         : "m" (*&x), "m" (*&y));
0052 
0053     kernel_fpu_end();
0054 
0055     if (fdiv_bug) {
0056         set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);
0057         pr_warn("Hmm, FPU with FDIV bug\n");
0058     }
0059 }