bugs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  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>
  12. #include <asm/bugs.h>
  13. #include <asm/processor.h>
  14. #include <asm/processor-flags.h>
  15. #include <asm/i387.h>
  16. #include <asm/msr.h>
  17. #include <asm/paravirt.h>
  18. #include <asm/alternative.h>
  19. static int __init no_halt(char *s)
  20. {
  21. WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
  22. boot_cpu_data.hlt_works_ok = 0;
  23. return 1;
  24. }
  25. __setup("no-hlt", no_halt);
  26. static int __init no_387(char *s)
  27. {
  28. boot_cpu_data.hard_math = 0;
  29. write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
  30. return 1;
  31. }
  32. __setup("no387", no_387);
  33. static double __initdata x = 4195835.0;
  34. static double __initdata y = 3145727.0;
  35. /*
  36. * This used to check for exceptions..
  37. * However, it turns out that to support that,
  38. * the XMM trap handlers basically had to
  39. * be buggy. So let's have a correct XMM trap
  40. * handler, and forget about printing out
  41. * some status at boot.
  42. *
  43. * We should really only care about bugs here
  44. * anyway. Not features.
  45. */
  46. static void __init check_fpu(void)
  47. {
  48. s32 fdiv_bug;
  49. if (!boot_cpu_data.hard_math) {
  50. #ifndef CONFIG_MATH_EMULATION
  51. printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
  52. printk(KERN_EMERG "Giving up.\n");
  53. for (;;) ;
  54. #endif
  55. return;
  56. }
  57. kernel_fpu_begin();
  58. /*
  59. * trap_init() enabled FXSR and company _before_ testing for FP
  60. * problems here.
  61. *
  62. * Test for the divl bug..
  63. */
  64. __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"
  73. : "=m" (*&fdiv_bug)
  74. : "m" (*&x), "m" (*&y));
  75. kernel_fpu_end();
  76. boot_cpu_data.fdiv_bug = fdiv_bug;
  77. if (boot_cpu_data.fdiv_bug)
  78. printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n");
  79. }
  80. static void __init check_hlt(void)
  81. {
  82. if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
  83. return;
  84. printk(KERN_INFO "Checking 'hlt' instruction... ");
  85. if (!boot_cpu_data.hlt_works_ok) {
  86. printk("disabled\n");
  87. return;
  88. }
  89. halt();
  90. halt();
  91. halt();
  92. halt();
  93. printk(KERN_CONT "OK.\n");
  94. }
  95. /*
  96. * Most 386 processors have a bug where a POPAD can lock the
  97. * machine even from user space.
  98. */
  99. static void __init check_popad(void)
  100. {
  101. #ifndef CONFIG_X86_POPAD_OK
  102. int res, inp = (int) &res;
  103. printk(KERN_INFO "Checking for popad bug... ");
  104. __asm__ __volatile__(
  105. "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
  106. : "=&a" (res)
  107. : "d" (inp)
  108. : "ecx", "edi");
  109. /*
  110. * If this fails, it means that any user program may lock the
  111. * CPU hard. Too bad.
  112. */
  113. if (res != 12345678)
  114. printk(KERN_CONT "Buggy.\n");
  115. else
  116. printk(KERN_CONT "OK.\n");
  117. #endif
  118. }
  119. /*
  120. * Check whether we are able to run this kernel safely on SMP.
  121. *
  122. * - In order to run on a i386, we need to be compiled for i386
  123. * (for due to lack of "invlpg" and working WP on a i386)
  124. * - In order to run on anything without a TSC, we need to be
  125. * compiled for a i486.
  126. */
  127. static void __init check_config(void)
  128. {
  129. /*
  130. * We'd better not be a i386 if we're configured to use some
  131. * i486+ only features! (WP works in supervisor mode and the
  132. * new "invlpg" and "bswap" instructions)
  133. */
  134. #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
  135. defined(CONFIG_X86_BSWAP)
  136. if (boot_cpu_data.x86 == 3)
  137. panic("Kernel requires i486+ for 'invlpg' and other features");
  138. #endif
  139. }
  140. void __init check_bugs(void)
  141. {
  142. identify_boot_cpu();
  143. #ifndef CONFIG_SMP
  144. printk(KERN_INFO "CPU: ");
  145. print_cpu_info(&boot_cpu_data);
  146. #endif
  147. check_config();
  148. check_fpu();
  149. check_hlt();
  150. check_popad();
  151. init_utsname()->machine[1] =
  152. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  153. alternative_instructions();
  154. }