bugs.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. boot_cpu_data.hlt_works_ok = 0;
  22. return 1;
  23. }
  24. __setup("no-hlt", no_halt);
  25. static int __init no_387(char *s)
  26. {
  27. boot_cpu_data.hard_math = 0;
  28. write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
  29. return 1;
  30. }
  31. __setup("no387", no_387);
  32. static double __initdata x = 4195835.0;
  33. static double __initdata y = 3145727.0;
  34. /*
  35. * This used to check for exceptions..
  36. * However, it turns out that to support that,
  37. * the XMM trap handlers basically had to
  38. * be buggy. So let's have a correct XMM trap
  39. * handler, and forget about printing out
  40. * some status at boot.
  41. *
  42. * We should really only care about bugs here
  43. * anyway. Not features.
  44. */
  45. static void __init check_fpu(void)
  46. {
  47. if (!boot_cpu_data.hard_math) {
  48. #ifndef CONFIG_MATH_EMULATION
  49. printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
  50. printk(KERN_EMERG "Giving up.\n");
  51. for (;;) ;
  52. #endif
  53. return;
  54. }
  55. /*
  56. * trap_init() enabled FXSR and company _before_ testing for FP
  57. * problems here.
  58. *
  59. * Test for the divl bug..
  60. */
  61. __asm__("fninit\n\t"
  62. "fldl %1\n\t"
  63. "fdivl %2\n\t"
  64. "fmull %2\n\t"
  65. "fldl %1\n\t"
  66. "fsubp %%st,%%st(1)\n\t"
  67. "fistpl %0\n\t"
  68. "fwait\n\t"
  69. "fninit"
  70. : "=m" (*&boot_cpu_data.fdiv_bug)
  71. : "m" (*&x), "m" (*&y));
  72. if (boot_cpu_data.fdiv_bug)
  73. printk("Hmm, FPU with FDIV bug.\n");
  74. }
  75. static void __init check_hlt(void)
  76. {
  77. if (paravirt_enabled())
  78. return;
  79. printk(KERN_INFO "Checking 'hlt' instruction... ");
  80. if (!boot_cpu_data.hlt_works_ok) {
  81. printk("disabled\n");
  82. return;
  83. }
  84. halt();
  85. halt();
  86. halt();
  87. halt();
  88. printk("OK.\n");
  89. }
  90. /*
  91. * Most 386 processors have a bug where a POPAD can lock the
  92. * machine even from user space.
  93. */
  94. static void __init check_popad(void)
  95. {
  96. #ifndef CONFIG_X86_POPAD_OK
  97. int res, inp = (int) &res;
  98. printk(KERN_INFO "Checking for popad bug... ");
  99. __asm__ __volatile__(
  100. "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
  101. : "=&a" (res)
  102. : "d" (inp)
  103. : "ecx", "edi");
  104. /*
  105. * If this fails, it means that any user program may lock the
  106. * CPU hard. Too bad.
  107. */
  108. if (res != 12345678)
  109. printk("Buggy.\n");
  110. else
  111. printk("OK.\n");
  112. #endif
  113. }
  114. /*
  115. * Check whether we are able to run this kernel safely on SMP.
  116. *
  117. * - In order to run on a i386, we need to be compiled for i386
  118. * (for due to lack of "invlpg" and working WP on a i386)
  119. * - In order to run on anything without a TSC, we need to be
  120. * compiled for a i486.
  121. * - In order to support the local APIC on a buggy Pentium machine,
  122. * we need to be compiled with CONFIG_X86_GOOD_APIC disabled,
  123. * which happens implicitly if compiled for a Pentium or lower
  124. * (unless an advanced selection of CPU features is used) as an
  125. * otherwise config implies a properly working local APIC without
  126. * the need to do extra reads from the APIC.
  127. */
  128. static void __init check_config(void)
  129. {
  130. /*
  131. * We'd better not be a i386 if we're configured to use some
  132. * i486+ only features! (WP works in supervisor mode and the
  133. * new "invlpg" and "bswap" instructions)
  134. */
  135. #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
  136. defined(CONFIG_X86_BSWAP)
  137. if (boot_cpu_data.x86 == 3)
  138. panic("Kernel requires i486+ for 'invlpg' and other features");
  139. #endif
  140. /*
  141. * If we were told we had a good local APIC, check for buggy Pentia,
  142. * i.e. all B steppings and the C2 stepping of P54C when using their
  143. * integrated APIC (see 11AP erratum in "Pentium Processor
  144. * Specification Update").
  145. */
  146. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_GOOD_APIC)
  147. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL
  148. && cpu_has_apic
  149. && boot_cpu_data.x86 == 5
  150. && boot_cpu_data.x86_model == 2
  151. && (boot_cpu_data.x86_mask < 6 || boot_cpu_data.x86_mask == 11))
  152. panic("Kernel compiled for PMMX+, assumes a local APIC without the read-before-write bug!");
  153. #endif
  154. }
  155. void __init check_bugs(void)
  156. {
  157. identify_boot_cpu();
  158. #ifndef CONFIG_SMP
  159. printk("CPU: ");
  160. print_cpu_info(&boot_cpu_data);
  161. #endif
  162. check_config();
  163. check_fpu();
  164. check_hlt();
  165. check_popad();
  166. init_utsname()->machine[1] =
  167. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  168. alternative_instructions();
  169. }