blob: af6455e3fcc9b9e6f7f1d75b6ee5ce112a689590 [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 *
62 * Test for the divl bug..
63 */
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
Krzysztof Helte0d22d02008-07-31 23:43:44 +020078 boot_cpu_data.fdiv_bug = fdiv_bug;
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020079 if (boot_cpu_data.fdiv_bug)
Joe Perchesc767a542012-05-21 19:50:07 -070080 pr_warn("Hmm, FPU with FDIV bug\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020081}
82
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020083/*
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020084 * Check whether we are able to run this kernel safely on SMP.
85 *
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -080086 * - i386 is no longer supported.
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020087 * - In order to run on anything without a TSC, we need to be
88 * compiled for a i486.
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010089 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020090
91static void __init check_config(void)
92{
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -080093 if (boot_cpu_data.x86 < 4)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020094 panic("Kernel requires i486+ for 'invlpg' and other features");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020095}
96
97
98void __init check_bugs(void)
99{
100 identify_boot_cpu();
101#ifndef CONFIG_SMP
Joe Perchesc767a542012-05-21 19:50:07 -0700102 pr_info("CPU: ");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200103 print_cpu_info(&boot_cpu_data);
104#endif
105 check_config();
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200106 init_utsname()->machine[1] =
107 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200108 alternative_instructions();
Suresh Siddha304bced2012-08-24 14:13:02 -0700109
110 /*
111 * kernel_fpu_begin/end() in check_fpu() relies on the patched
112 * alternative instructions.
113 */
114 check_fpu();
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200115}