bugs.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * arch/i386/cpu/bugs.c
  3. *
  4. * Copyright (C) 1994 Linus Torvalds
  5. *
  6. * Cyrix stuff, June 1998 by:
  7. * - Rafael R. Reilova (moved everything from head.S),
  8. * <rreilova@ececs.uc.edu>
  9. * - Channing Corn (tests & fixes),
  10. * - Andrew D. Balsa (code cleanup).
  11. */
  12. #include <linux/init.h>
  13. #include <linux/utsname.h>
  14. #include <asm/bugs.h>
  15. #include <asm/processor.h>
  16. #include <asm/i387.h>
  17. #include <asm/msr.h>
  18. #include <asm/paravirt.h>
  19. #include <asm/alternative.h>
  20. static int __init no_halt(char *s)
  21. {
  22. boot_cpu_data.hlt_works_ok = 0;
  23. return 1;
  24. }
  25. __setup("no-hlt", no_halt);
  26. static int __init mca_pentium(char *s)
  27. {
  28. mca_pentium_flag = 1;
  29. return 1;
  30. }
  31. __setup("mca-pentium", mca_pentium);
  32. static int __init no_387(char *s)
  33. {
  34. boot_cpu_data.hard_math = 0;
  35. write_cr0(0xE | read_cr0());
  36. return 1;
  37. }
  38. __setup("no387", no_387);
  39. static double __initdata x = 4195835.0;
  40. static double __initdata y = 3145727.0;
  41. /*
  42. * This used to check for exceptions..
  43. * However, it turns out that to support that,
  44. * the XMM trap handlers basically had to
  45. * be buggy. So let's have a correct XMM trap
  46. * handler, and forget about printing out
  47. * some status at boot.
  48. *
  49. * We should really only care about bugs here
  50. * anyway. Not features.
  51. */
  52. static void __init check_fpu(void)
  53. {
  54. if (!boot_cpu_data.hard_math) {
  55. #ifndef CONFIG_MATH_EMULATION
  56. printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
  57. printk(KERN_EMERG "Giving up.\n");
  58. for (;;) ;
  59. #endif
  60. return;
  61. }
  62. /* trap_init() enabled FXSR and company _before_ testing for FP problems here. */
  63. /* Test for the divl bug.. */
  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" (*&boot_cpu_data.fdiv_bug)
  74. : "m" (*&x), "m" (*&y));
  75. if (boot_cpu_data.fdiv_bug)
  76. printk("Hmm, FPU with FDIV bug.\n");
  77. }
  78. static void __init check_hlt(void)
  79. {
  80. if (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("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. /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
  108. if (res != 12345678) printk( "Buggy.\n" );
  109. else printk( "OK.\n" );
  110. #endif
  111. }
  112. /*
  113. * Check whether we are able to run this kernel safely on SMP.
  114. *
  115. * - In order to run on a i386, we need to be compiled for i386
  116. * (for due to lack of "invlpg" and working WP on a i386)
  117. * - In order to run on anything without a TSC, we need to be
  118. * compiled for a i486.
  119. * - In order to support the local APIC on a buggy Pentium machine,
  120. * we need to be compiled with CONFIG_X86_GOOD_APIC disabled,
  121. * which happens implicitly if compiled for a Pentium or lower
  122. * (unless an advanced selection of CPU features is used) as an
  123. * otherwise config implies a properly working local APIC without
  124. * the need to do extra reads from the APIC.
  125. */
  126. static void __init check_config(void)
  127. {
  128. /*
  129. * We'd better not be a i386 if we're configured to use some
  130. * i486+ only features! (WP works in supervisor mode and the
  131. * new "invlpg" and "bswap" instructions)
  132. */
  133. #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || 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. * If we configured ourselves for a TSC, we'd better have one!
  139. */
  140. #ifdef CONFIG_X86_TSC
  141. if (!cpu_has_tsc && !tsc_disable)
  142. panic("Kernel compiled for Pentium+, requires TSC feature!");
  143. #endif
  144. /*
  145. * If we were told we had a good local APIC, check for buggy Pentia,
  146. * i.e. all B steppings and the C2 stepping of P54C when using their
  147. * integrated APIC (see 11AP erratum in "Pentium Processor
  148. * Specification Update").
  149. */
  150. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_GOOD_APIC)
  151. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL
  152. && cpu_has_apic
  153. && boot_cpu_data.x86 == 5
  154. && boot_cpu_data.x86_model == 2
  155. && (boot_cpu_data.x86_mask < 6 || boot_cpu_data.x86_mask == 11))
  156. panic("Kernel compiled for PMMX+, assumes a local APIC without the read-before-write bug!");
  157. #endif
  158. }
  159. void __init check_bugs(void)
  160. {
  161. identify_boot_cpu();
  162. #ifndef CONFIG_SMP
  163. printk("CPU: ");
  164. print_cpu_info(&boot_cpu_data);
  165. #endif
  166. check_config();
  167. check_fpu();
  168. check_hlt();
  169. check_popad();
  170. init_utsname()->machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  171. alternative_instructions();
  172. }