bugs.h 4.9 KB

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