blob: 4112be9a46591209aae8169506f11e4eaf28fe7a [file] [log] [blame]
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +02001/*
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +02002 * Copyright (C) 1994 Linus Torvalds
3 *
4 * Cyrix stuff, June 1998 by:
5 * - Rafael R. Reilova (moved everything from head.S),
6 * <rreilova@ececs.uc.edu>
7 * - Channing Corn (tests & fixes),
8 * - Andrew D. Balsa (code cleanup).
9 */
10#include <linux/init.h>
11#include <linux/utsname.h>
Josh Triplett91eb1b72007-07-31 00:39:20 -070012#include <asm/bugs.h>
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020013#include <asm/processor.h>
Dave Jones7ebad702008-01-30 13:30:39 +010014#include <asm/processor-flags.h>
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020015#include <asm/i387.h>
16#include <asm/msr.h>
17#include <asm/paravirt.h>
18#include <asm/alternative.h>
19
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020020static int __init no_387(char *s)
21{
22 boot_cpu_data.hard_math = 0;
Dave Jones7ebad702008-01-30 13:30:39 +010023 write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020024 return 1;
25}
26
27__setup("no387", no_387);
28
29static double __initdata x = 4195835.0;
30static double __initdata y = 3145727.0;
31
32/*
33 * This used to check for exceptions..
34 * However, it turns out that to support that,
35 * the XMM trap handlers basically had to
36 * be buggy. So let's have a correct XMM trap
37 * handler, and forget about printing out
38 * some status at boot.
39 *
40 * We should really only care about bugs here
41 * anyway. Not features.
42 */
43static void __init check_fpu(void)
44{
Krzysztof Helte0d22d02008-07-31 23:43:44 +020045 s32 fdiv_bug;
46
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020047 if (!boot_cpu_data.hard_math) {
48#ifndef CONFIG_MATH_EMULATION
Joe Perchesc767a542012-05-21 19:50:07 -070049 pr_emerg("No coprocessor found and no math emulation present\n");
50 pr_emerg("Giving up\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020051 for (;;) ;
52#endif
53 return;
54 }
55
Suresh Siddha3e7cf5b2011-06-30 17:19:32 -070056 kernel_fpu_begin();
57
Miklos Vajnabfe4bb12008-05-17 22:48:13 +020058 /*
59 * trap_init() enabled FXSR and company _before_ testing for FP
60 * problems here.
61 *
Borislav Petkov93a829e2013-03-20 15:07:25 +010062 * Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug
Miklos Vajnabfe4bb12008-05-17 22:48:13 +020063 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020064 __asm__("fninit\n\t"
65 "fldl %1\n\t"
66 "fdivl %2\n\t"
67 "fmull %2\n\t"
68 "fldl %1\n\t"
69 "fsubp %%st,%%st(1)\n\t"
70 "fistpl %0\n\t"
71 "fwait\n\t"
72 "fninit"
Krzysztof Helte0d22d02008-07-31 23:43:44 +020073 : "=m" (*&fdiv_bug)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020074 : "m" (*&x), "m" (*&y));
Krzysztof Helte0d22d02008-07-31 23:43:44 +020075
Suresh Siddha3e7cf5b2011-06-30 17:19:32 -070076 kernel_fpu_end();
77
Borislav Petkov93a829e2013-03-20 15:07:25 +010078 if (fdiv_bug) {
79 set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV);
Joe Perchesc767a542012-05-21 19:50:07 -070080 pr_warn("Hmm, FPU with FDIV bug\n");
Borislav Petkov93a829e2013-03-20 15:07:25 +010081 }
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020082}
83
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020084void __init check_bugs(void)
85{
86 identify_boot_cpu();
87#ifndef CONFIG_SMP
Joe Perchesc767a542012-05-21 19:50:07 -070088 pr_info("CPU: ");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020089 print_cpu_info(&boot_cpu_data);
90#endif
Borislav Petkov55a36b62013-04-08 17:57:44 +020091
92 /*
93 * Check whether we are able to run this kernel safely on SMP.
94 *
95 * - i386 is no longer supported.
96 * - In order to run on anything without a TSC, we need to be
97 * compiled for a i486.
98 */
99 if (boot_cpu_data.x86 < 4)
100 panic("Kernel requires i486+ for 'invlpg' and other features");
101
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200102 init_utsname()->machine[1] =
103 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200104 alternative_instructions();
Suresh Siddha304bced2012-08-24 14:13:02 -0700105
106 /*
107 * kernel_fpu_begin/end() in check_fpu() relies on the patched
108 * alternative instructions.
109 */
110 check_fpu();
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200111}