Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 1 | /* |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 2 | * 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 Triplett | 91eb1b7 | 2007-07-31 00:39:20 -0700 | [diff] [blame] | 12 | #include <asm/bugs.h> |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
Dave Jones | 7ebad70 | 2008-01-30 13:30:39 +0100 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 15 | #include <asm/i387.h> |
| 16 | #include <asm/msr.h> |
| 17 | #include <asm/paravirt.h> |
| 18 | #include <asm/alternative.h> |
| 19 | |
| 20 | static 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 Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 28 | static int __init no_387(char *s) |
| 29 | { |
| 30 | boot_cpu_data.hard_math = 0; |
Dave Jones | 7ebad70 | 2008-01-30 13:30:39 +0100 | [diff] [blame] | 31 | write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0()); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | __setup("no387", no_387); |
| 36 | |
| 37 | static double __initdata x = 4195835.0; |
| 38 | static 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 | */ |
| 51 | static void __init check_fpu(void) |
| 52 | { |
| 53 | if (!boot_cpu_data.hard_math) { |
| 54 | #ifndef CONFIG_MATH_EMULATION |
| 55 | printk(KERN_EMERG "No coprocessor found and no math emulation present.\n"); |
| 56 | printk(KERN_EMERG "Giving up.\n"); |
| 57 | for (;;) ; |
| 58 | #endif |
| 59 | return; |
| 60 | } |
| 61 | |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 62 | /* |
| 63 | * trap_init() enabled FXSR and company _before_ testing for FP |
| 64 | * problems here. |
| 65 | * |
| 66 | * Test for the divl bug.. |
| 67 | */ |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 68 | __asm__("fninit\n\t" |
| 69 | "fldl %1\n\t" |
| 70 | "fdivl %2\n\t" |
| 71 | "fmull %2\n\t" |
| 72 | "fldl %1\n\t" |
| 73 | "fsubp %%st,%%st(1)\n\t" |
| 74 | "fistpl %0\n\t" |
| 75 | "fwait\n\t" |
| 76 | "fninit" |
| 77 | : "=m" (*&boot_cpu_data.fdiv_bug) |
| 78 | : "m" (*&x), "m" (*&y)); |
| 79 | if (boot_cpu_data.fdiv_bug) |
| 80 | printk("Hmm, FPU with FDIV bug.\n"); |
| 81 | } |
| 82 | |
| 83 | static void __init check_hlt(void) |
| 84 | { |
| 85 | if (paravirt_enabled()) |
| 86 | return; |
| 87 | |
| 88 | printk(KERN_INFO "Checking 'hlt' instruction... "); |
| 89 | if (!boot_cpu_data.hlt_works_ok) { |
| 90 | printk("disabled\n"); |
| 91 | return; |
| 92 | } |
| 93 | halt(); |
| 94 | halt(); |
| 95 | halt(); |
| 96 | halt(); |
| 97 | printk("OK.\n"); |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Most 386 processors have a bug where a POPAD can lock the |
| 102 | * machine even from user space. |
| 103 | */ |
| 104 | |
| 105 | static void __init check_popad(void) |
| 106 | { |
| 107 | #ifndef CONFIG_X86_POPAD_OK |
| 108 | int res, inp = (int) &res; |
| 109 | |
| 110 | printk(KERN_INFO "Checking for popad bug... "); |
| 111 | __asm__ __volatile__( |
| 112 | "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx " |
| 113 | : "=&a" (res) |
| 114 | : "d" (inp) |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 115 | : "ecx", "edi"); |
| 116 | /* |
| 117 | * If this fails, it means that any user program may lock the |
| 118 | * CPU hard. Too bad. |
| 119 | */ |
| 120 | if (res != 12345678) |
| 121 | printk("Buggy.\n"); |
| 122 | else |
| 123 | printk("OK.\n"); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 124 | #endif |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Check whether we are able to run this kernel safely on SMP. |
| 129 | * |
| 130 | * - In order to run on a i386, we need to be compiled for i386 |
| 131 | * (for due to lack of "invlpg" and working WP on a i386) |
| 132 | * - In order to run on anything without a TSC, we need to be |
| 133 | * compiled for a i486. |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame^] | 134 | */ |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 135 | |
| 136 | static void __init check_config(void) |
| 137 | { |
| 138 | /* |
| 139 | * We'd better not be a i386 if we're configured to use some |
| 140 | * i486+ only features! (WP works in supervisor mode and the |
| 141 | * new "invlpg" and "bswap" instructions) |
| 142 | */ |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 143 | #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \ |
| 144 | defined(CONFIG_X86_BSWAP) |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 145 | if (boot_cpu_data.x86 == 3) |
| 146 | panic("Kernel requires i486+ for 'invlpg' and other features"); |
| 147 | #endif |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | void __init check_bugs(void) |
| 152 | { |
| 153 | identify_boot_cpu(); |
| 154 | #ifndef CONFIG_SMP |
| 155 | printk("CPU: "); |
| 156 | print_cpu_info(&boot_cpu_data); |
| 157 | #endif |
| 158 | check_config(); |
| 159 | check_fpu(); |
| 160 | check_hlt(); |
| 161 | check_popad(); |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 162 | init_utsname()->machine[1] = |
| 163 | '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 164 | alternative_instructions(); |
| 165 | } |