bugs.c 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 *  Copyright (C) 1994  Linus Torvalds
 *
 *  Cyrix stuff, June 1998 by:
 *	- Rafael R. Reilova (moved everything from head.S),
 *        <rreilova@ececs.uc.edu>
 *	- Channing Corn (tests & fixes),
 *	- Andrew D. Balsa (code cleanup).
 */
#include <linux/init.h>
#include <linux/utsname.h>
12
#include <asm/bugs.h>
13
#include <asm/processor.h>
D
Dave Jones 已提交
14
#include <asm/processor-flags.h>
15 16 17 18 19 20 21
#include <asm/i387.h>
#include <asm/msr.h>
#include <asm/paravirt.h>
#include <asm/alternative.h>

static int __init no_halt(char *s)
{
22
	WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
23 24 25 26 27 28 29 30 31
	boot_cpu_data.hlt_works_ok = 0;
	return 1;
}

__setup("no-hlt", no_halt);

static int __init no_387(char *s)
{
	boot_cpu_data.hard_math = 0;
D
Dave Jones 已提交
32
	write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	return 1;
}

__setup("no387", no_387);

static double __initdata x = 4195835.0;
static double __initdata y = 3145727.0;

/*
 * This used to check for exceptions..
 * However, it turns out that to support that,
 * the XMM trap handlers basically had to
 * be buggy. So let's have a correct XMM trap
 * handler, and forget about printing out
 * some status at boot.
 *
 * We should really only care about bugs here
 * anyway. Not features.
 */
static void __init check_fpu(void)
{
K
Krzysztof Helt 已提交
54 55
	s32 fdiv_bug;

56 57 58 59 60 61 62 63 64
	if (!boot_cpu_data.hard_math) {
#ifndef CONFIG_MATH_EMULATION
		printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
		printk(KERN_EMERG "Giving up.\n");
		for (;;) ;
#endif
		return;
	}

M
Miklos Vajna 已提交
65 66 67 68 69 70
	/*
	 * trap_init() enabled FXSR and company _before_ testing for FP
	 * problems here.
	 *
	 * Test for the divl bug..
	 */
71 72 73 74 75 76 77 78 79
	__asm__("fninit\n\t"
		"fldl %1\n\t"
		"fdivl %2\n\t"
		"fmull %2\n\t"
		"fldl %1\n\t"
		"fsubp %%st,%%st(1)\n\t"
		"fistpl %0\n\t"
		"fwait\n\t"
		"fninit"
K
Krzysztof Helt 已提交
80
		: "=m" (*&fdiv_bug)
81
		: "m" (*&x), "m" (*&y));
K
Krzysztof Helt 已提交
82 83

	boot_cpu_data.fdiv_bug = fdiv_bug;
84
	if (boot_cpu_data.fdiv_bug)
A
Alan Cox 已提交
85
		printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n");
86 87 88 89
}

static void __init check_hlt(void)
{
J
Jacob Pan 已提交
90
	if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
91 92 93 94 95 96 97 98 99 100 101
		return;

	printk(KERN_INFO "Checking 'hlt' instruction... ");
	if (!boot_cpu_data.hlt_works_ok) {
		printk("disabled\n");
		return;
	}
	halt();
	halt();
	halt();
	halt();
A
Alan Cox 已提交
102
	printk(KERN_CONT "OK.\n");
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}

/*
 *	Most 386 processors have a bug where a POPAD can lock the
 *	machine even from user space.
 */

static void __init check_popad(void)
{
#ifndef CONFIG_X86_POPAD_OK
	int res, inp = (int) &res;

	printk(KERN_INFO "Checking for popad bug... ");
	__asm__ __volatile__(
	  "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
	  : "=&a" (res)
	  : "d" (inp)
M
Miklos Vajna 已提交
120 121 122 123 124 125
	  : "ecx", "edi");
	/*
	 * If this fails, it means that any user program may lock the
	 * CPU hard. Too bad.
	 */
	if (res != 12345678)
A
Alan Cox 已提交
126
		printk(KERN_CONT "Buggy.\n");
M
Miklos Vajna 已提交
127
	else
A
Alan Cox 已提交
128
		printk(KERN_CONT "OK.\n");
129 130 131 132 133 134 135 136 137 138
#endif
}

/*
 * Check whether we are able to run this kernel safely on SMP.
 *
 * - In order to run on a i386, we need to be compiled for i386
 *   (for due to lack of "invlpg" and working WP on a i386)
 * - In order to run on anything without a TSC, we need to be
 *   compiled for a i486.
139
 */
140 141 142 143 144 145 146 147

static void __init check_config(void)
{
/*
 * We'd better not be a i386 if we're configured to use some
 * i486+ only features! (WP works in supervisor mode and the
 * new "invlpg" and "bswap" instructions)
 */
M
Miklos Vajna 已提交
148 149
#if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
	defined(CONFIG_X86_BSWAP)
150 151 152 153 154 155 156 157 158 159
	if (boot_cpu_data.x86 == 3)
		panic("Kernel requires i486+ for 'invlpg' and other features");
#endif
}


void __init check_bugs(void)
{
	identify_boot_cpu();
#ifndef CONFIG_SMP
A
Alan Cox 已提交
160
	printk(KERN_INFO "CPU: ");
161 162 163 164 165 166
	print_cpu_info(&boot_cpu_data);
#endif
	check_config();
	check_fpu();
	check_hlt();
	check_popad();
M
Miklos Vajna 已提交
167 168
	init_utsname()->machine[1] =
		'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
169 170
	alternative_instructions();
}