blob: c39576cb3018507f2d359521741c1764778b68f7 [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
20static int __init no_halt(char *s)
21{
22 boot_cpu_data.hlt_works_ok = 0;
23 return 1;
24}
25
26__setup("no-hlt", no_halt);
27
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020028static int __init no_387(char *s)
29{
30 boot_cpu_data.hard_math = 0;
Dave Jones7ebad702008-01-30 13:30:39 +010031 write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020032 return 1;
33}
34
35__setup("no387", no_387);
36
37static double __initdata x = 4195835.0;
38static double __initdata y = 3145727.0;
39
40/*
41 * This used to check for exceptions..
42 * However, it turns out that to support that,
43 * the XMM trap handlers basically had to
44 * be buggy. So let's have a correct XMM trap
45 * handler, and forget about printing out
46 * some status at boot.
47 *
48 * We should really only care about bugs here
49 * anyway. Not features.
50 */
51static void __init check_fpu(void)
52{
Krzysztof Helte0d22d02008-07-31 23:43:44 +020053 s32 fdiv_bug;
54
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020055 if (!boot_cpu_data.hard_math) {
56#ifndef CONFIG_MATH_EMULATION
57 printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
58 printk(KERN_EMERG "Giving up.\n");
59 for (;;) ;
60#endif
61 return;
62 }
63
Miklos Vajnabfe4bb12008-05-17 22:48:13 +020064 /*
65 * trap_init() enabled FXSR and company _before_ testing for FP
66 * problems here.
67 *
68 * Test for the divl bug..
69 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020070 __asm__("fninit\n\t"
71 "fldl %1\n\t"
72 "fdivl %2\n\t"
73 "fmull %2\n\t"
74 "fldl %1\n\t"
75 "fsubp %%st,%%st(1)\n\t"
76 "fistpl %0\n\t"
77 "fwait\n\t"
78 "fninit"
Krzysztof Helte0d22d02008-07-31 23:43:44 +020079 : "=m" (*&fdiv_bug)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020080 : "m" (*&x), "m" (*&y));
Krzysztof Helte0d22d02008-07-31 23:43:44 +020081
82 boot_cpu_data.fdiv_bug = fdiv_bug;
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020083 if (boot_cpu_data.fdiv_bug)
Alan Cox8bdbd962009-07-04 00:35:45 +010084 printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020085}
86
87static void __init check_hlt(void)
88{
Jacob Pan2b107d92010-05-07 14:59:45 -070089 if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020090 return;
91
92 printk(KERN_INFO "Checking 'hlt' instruction... ");
93 if (!boot_cpu_data.hlt_works_ok) {
94 printk("disabled\n");
95 return;
96 }
97 halt();
98 halt();
99 halt();
100 halt();
Alan Cox8bdbd962009-07-04 00:35:45 +0100101 printk(KERN_CONT "OK.\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200102}
103
104/*
105 * Most 386 processors have a bug where a POPAD can lock the
106 * machine even from user space.
107 */
108
109static void __init check_popad(void)
110{
111#ifndef CONFIG_X86_POPAD_OK
112 int res, inp = (int) &res;
113
114 printk(KERN_INFO "Checking for popad bug... ");
115 __asm__ __volatile__(
116 "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
117 : "=&a" (res)
118 : "d" (inp)
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200119 : "ecx", "edi");
120 /*
121 * If this fails, it means that any user program may lock the
122 * CPU hard. Too bad.
123 */
124 if (res != 12345678)
Alan Cox8bdbd962009-07-04 00:35:45 +0100125 printk(KERN_CONT "Buggy.\n");
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200126 else
Alan Cox8bdbd962009-07-04 00:35:45 +0100127 printk(KERN_CONT "OK.\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200128#endif
129}
130
131/*
132 * Check whether we are able to run this kernel safely on SMP.
133 *
134 * - In order to run on a i386, we need to be compiled for i386
135 * (for due to lack of "invlpg" and working WP on a i386)
136 * - In order to run on anything without a TSC, we need to be
137 * compiled for a i486.
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +0100138 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200139
140static void __init check_config(void)
141{
142/*
143 * We'd better not be a i386 if we're configured to use some
144 * i486+ only features! (WP works in supervisor mode and the
145 * new "invlpg" and "bswap" instructions)
146 */
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200147#if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
148 defined(CONFIG_X86_BSWAP)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200149 if (boot_cpu_data.x86 == 3)
150 panic("Kernel requires i486+ for 'invlpg' and other features");
151#endif
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200152}
153
154
155void __init check_bugs(void)
156{
157 identify_boot_cpu();
158#ifndef CONFIG_SMP
Alan Cox8bdbd962009-07-04 00:35:45 +0100159 printk(KERN_INFO "CPU: ");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200160 print_cpu_info(&boot_cpu_data);
161#endif
162 check_config();
163 check_fpu();
164 check_hlt();
165 check_popad();
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200166 init_utsname()->machine[1] =
167 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200168 alternative_instructions();
169}