bugs.c 4.8 KB

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