bugs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/config.h>
  19. #include <linux/init.h>
  20. #include <asm/processor.h>
  21. #include <asm/i387.h>
  22. #include <asm/msr.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. printk(KERN_INFO "Checking 'hlt' instruction... ");
  84. if (!boot_cpu_data.hlt_works_ok) {
  85. printk("disabled\n");
  86. return;
  87. }
  88. halt();
  89. halt();
  90. halt();
  91. halt();
  92. printk("OK.\n");
  93. }
  94. /*
  95. * Most 386 processors have a bug where a POPAD can lock the
  96. * machine even from user space.
  97. */
  98. static void __init check_popad(void)
  99. {
  100. #ifndef CONFIG_X86_POPAD_OK
  101. int res, inp = (int) &res;
  102. printk(KERN_INFO "Checking for popad bug... ");
  103. __asm__ __volatile__(
  104. "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
  105. : "=&a" (res)
  106. : "d" (inp)
  107. : "ecx", "edi" );
  108. /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
  109. if (res != 12345678) printk( "Buggy.\n" );
  110. else printk( "OK.\n" );
  111. #endif
  112. }
  113. /*
  114. * Check whether we are able to run this kernel safely on SMP.
  115. *
  116. * - In order to run on a i386, we need to be compiled for i386
  117. * (for due to lack of "invlpg" and working WP on a i386)
  118. * - In order to run on anything without a TSC, we need to be
  119. * compiled for a i486.
  120. * - In order to support the local APIC on a buggy Pentium machine,
  121. * we need to be compiled with CONFIG_X86_GOOD_APIC disabled,
  122. * which happens implicitly if compiled for a Pentium or lower
  123. * (unless an advanced selection of CPU features is used) as an
  124. * otherwise config implies a properly working local APIC without
  125. * the need to do extra reads from the APIC.
  126. */
  127. static void __init check_config(void)
  128. {
  129. /*
  130. * We'd better not be a i386 if we're configured to use some
  131. * i486+ only features! (WP works in supervisor mode and the
  132. * new "invlpg" and "bswap" instructions)
  133. */
  134. #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || defined(CONFIG_X86_BSWAP)
  135. if (boot_cpu_data.x86 == 3)
  136. panic("Kernel requires i486+ for 'invlpg' and other features");
  137. #endif
  138. /*
  139. * If we configured ourselves for a TSC, we'd better have one!
  140. */
  141. #ifdef CONFIG_X86_TSC
  142. if (!cpu_has_tsc)
  143. panic("Kernel compiled for Pentium+, requires TSC feature!");
  144. #endif
  145. /*
  146. * If we were told we had a good local APIC, check for buggy Pentia,
  147. * i.e. all B steppings and the C2 stepping of P54C when using their
  148. * integrated APIC (see 11AP erratum in "Pentium Processor
  149. * Specification Update").
  150. */
  151. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_GOOD_APIC)
  152. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL
  153. && cpu_has_apic
  154. && boot_cpu_data.x86 == 5
  155. && boot_cpu_data.x86_model == 2
  156. && (boot_cpu_data.x86_mask < 6 || boot_cpu_data.x86_mask == 11))
  157. panic("Kernel compiled for PMMX+, assumes a local APIC without the read-before-write bug!");
  158. #endif
  159. }
  160. extern void alternative_instructions(void);
  161. static void __init check_bugs(void)
  162. {
  163. identify_cpu(&boot_cpu_data);
  164. #ifndef CONFIG_SMP
  165. printk("CPU: ");
  166. print_cpu_info(&boot_cpu_data);
  167. #endif
  168. check_config();
  169. check_fpu();
  170. check_hlt();
  171. check_popad();
  172. system_utsname.machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  173. alternative_instructions();
  174. }