bugs.c 4.5 KB

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