// SPDX-License-Identifier: GPL-2.01/*2* x86 FPU bug checks:3*/4#include <linux/printk.h>56#include <asm/cpufeature.h>7#include <asm/fpu/api.h>89/*10* Boot time CPU/FPU FDIV bug detection code:11*/1213static double __initdata x = 4195835.0;14static double __initdata y = 3145727.0;1516/*17* This used to check for exceptions..18* However, it turns out that to support that,19* the XMM trap handlers basically had to20* be buggy. So let's have a correct XMM trap21* handler, and forget about printing out22* some status at boot.23*24* We should really only care about bugs here25* anyway. Not features.26*/27void __init fpu__init_check_bugs(void)28{29s32 fdiv_bug;3031/* kernel_fpu_begin/end() relies on patched alternative instructions. */32if (!boot_cpu_has(X86_FEATURE_FPU))33return;3435kernel_fpu_begin();3637/*38* trap_init() enabled FXSR and company _before_ testing for FP39* problems here.40*41* Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug42*/43__asm__("fninit\n\t"44"fldl %1\n\t"45"fdivl %2\n\t"46"fmull %2\n\t"47"fldl %1\n\t"48"fsubp %%st,%%st(1)\n\t"49"fistpl %0\n\t"50"fwait\n\t"51"fninit"52: "=m" (*&fdiv_bug)53: "m" (*&x), "m" (*&y));5455kernel_fpu_end();5657if (fdiv_bug) {58set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);59pr_warn("Hmm, FPU with FDIV bug\n");60}61}626364