bugs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /*
  58. * trap_init() enabled FXSR and company _before_ testing for FP
  59. * problems here.
  60. *
  61. * Test for the divl bug..
  62. */
  63. __asm__("fninit\n\t"
  64. "fldl %1\n\t"
  65. "fdivl %2\n\t"
  66. "fmull %2\n\t"
  67. "fldl %1\n\t"
  68. "fsubp %%st,%%st(1)\n\t"
  69. "fistpl %0\n\t"
  70. "fwait\n\t"
  71. "fninit"
  72. : "=m" (*&fdiv_bug)
  73. : "m" (*&x), "m" (*&y));
  74. boot_cpu_data.fdiv_bug = fdiv_bug;
  75. if (boot_cpu_data.fdiv_bug)
  76. printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n");
  77. }
  78. static void __init check_hlt(void)
  79. {
  80. if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
  81. return;
  82. printk(KERN_INFO "Checking 'hlt' instruction... ");
  83. if (!boot_cpu_data.hlt_works_ok) {
  84. printk("disabled\n");
  85. return;
  86. }
  87. halt();
  88. halt();
  89. halt();
  90. halt();
  91. printk(KERN_CONT "OK.\n");
  92. }
  93. /*
  94. * Most 386 processors have a bug where a POPAD can lock the
  95. * machine even from user space.
  96. */
  97. static void __init check_popad(void)
  98. {
  99. #ifndef CONFIG_X86_POPAD_OK
  100. int res, inp = (int) &res;
  101. printk(KERN_INFO "Checking for popad bug... ");
  102. __asm__ __volatile__(
  103. "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
  104. : "=&a" (res)
  105. : "d" (inp)
  106. : "ecx", "edi");
  107. /*
  108. * If this fails, it means that any user program may lock the
  109. * CPU hard. Too bad.
  110. */
  111. if (res != 12345678)
  112. printk(KERN_CONT "Buggy.\n");
  113. else
  114. printk(KERN_CONT "OK.\n");
  115. #endif
  116. }
  117. /*
  118. * Check whether we are able to run this kernel safely on SMP.
  119. *
  120. * - In order to run on a i386, we need to be compiled for i386
  121. * (for due to lack of "invlpg" and working WP on a i386)
  122. * - In order to run on anything without a TSC, we need to be
  123. * compiled for a i486.
  124. */
  125. static void __init check_config(void)
  126. {
  127. /*
  128. * We'd better not be a i386 if we're configured to use some
  129. * i486+ only features! (WP works in supervisor mode and the
  130. * new "invlpg" and "bswap" instructions)
  131. */
  132. #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
  133. defined(CONFIG_X86_BSWAP)
  134. if (boot_cpu_data.x86 == 3)
  135. panic("Kernel requires i486+ for 'invlpg' and other features");
  136. #endif
  137. }
  138. void __init check_bugs(void)
  139. {
  140. identify_boot_cpu();
  141. #ifndef CONFIG_SMP
  142. printk(KERN_INFO "CPU: ");
  143. print_cpu_info(&boot_cpu_data);
  144. #endif
  145. check_config();
  146. check_fpu();
  147. check_hlt();
  148. check_popad();
  149. init_utsname()->machine[1] =
  150. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  151. alternative_instructions();
  152. }