bugs.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. static int __init no_halt(char *s)
  23. {
  24. boot_cpu_data.hlt_works_ok = 0;
  25. return 1;
  26. }
  27. __setup("no-hlt", no_halt);
  28. static int __init mca_pentium(char *s)
  29. {
  30. mca_pentium_flag = 1;
  31. return 1;
  32. }
  33. __setup("mca-pentium", mca_pentium);
  34. static int __init no_387(char *s)
  35. {
  36. boot_cpu_data.hard_math = 0;
  37. write_cr0(0xE | read_cr0());
  38. return 1;
  39. }
  40. __setup("no387", no_387);
  41. static double __initdata x = 4195835.0;
  42. static double __initdata y = 3145727.0;
  43. /*
  44. * This used to check for exceptions..
  45. * However, it turns out that to support that,
  46. * the XMM trap handlers basically had to
  47. * be buggy. So let's have a correct XMM trap
  48. * handler, and forget about printing out
  49. * some status at boot.
  50. *
  51. * We should really only care about bugs here
  52. * anyway. Not features.
  53. */
  54. static void __init check_fpu(void)
  55. {
  56. if (!boot_cpu_data.hard_math) {
  57. #ifndef CONFIG_MATH_EMULATION
  58. printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
  59. printk(KERN_EMERG "Giving up.\n");
  60. for (;;) ;
  61. #endif
  62. return;
  63. }
  64. /* trap_init() enabled FXSR and company _before_ testing for FP problems here. */
  65. /* Test for the divl bug.. */
  66. __asm__("fninit\n\t"
  67. "fldl %1\n\t"
  68. "fdivl %2\n\t"
  69. "fmull %2\n\t"
  70. "fldl %1\n\t"
  71. "fsubp %%st,%%st(1)\n\t"
  72. "fistpl %0\n\t"
  73. "fwait\n\t"
  74. "fninit"
  75. : "=m" (*&boot_cpu_data.fdiv_bug)
  76. : "m" (*&x), "m" (*&y));
  77. if (boot_cpu_data.fdiv_bug)
  78. printk("Hmm, FPU with FDIV bug.\n");
  79. }
  80. static void __init check_hlt(void)
  81. {
  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)
  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. extern void alternative_instructions(void);
  160. static void __init check_bugs(void)
  161. {
  162. identify_cpu(&boot_cpu_data);
  163. #ifndef CONFIG_SMP
  164. printk("CPU: ");
  165. print_cpu_info(&boot_cpu_data);
  166. #endif
  167. check_config();
  168. check_fpu();
  169. check_hlt();
  170. check_popad();
  171. system_utsname.machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  172. alternative_instructions();
  173. }