bugs.c 4.8 KB

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