bugs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. s32 fdiv_bug;
  48. if (!boot_cpu_data.hard_math) {
  49. #ifndef CONFIG_MATH_EMULATION
  50. printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
  51. printk(KERN_EMERG "Giving up.\n");
  52. for (;;) ;
  53. #endif
  54. return;
  55. }
  56. /*
  57. * trap_init() enabled FXSR and company _before_ testing for FP
  58. * problems here.
  59. *
  60. * Test for the divl bug..
  61. */
  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" (*&fdiv_bug)
  72. : "m" (*&x), "m" (*&y));
  73. boot_cpu_data.fdiv_bug = fdiv_bug;
  74. if (boot_cpu_data.fdiv_bug)
  75. printk("Hmm, FPU with FDIV bug.\n");
  76. }
  77. static void __init check_hlt(void)
  78. {
  79. if (paravirt_enabled())
  80. return;
  81. printk(KERN_INFO "Checking 'hlt' instruction... ");
  82. if (!boot_cpu_data.hlt_works_ok) {
  83. printk("disabled\n");
  84. return;
  85. }
  86. halt();
  87. halt();
  88. halt();
  89. halt();
  90. printk("OK.\n");
  91. }
  92. /*
  93. * Most 386 processors have a bug where a POPAD can lock the
  94. * machine even from user space.
  95. */
  96. static void __init check_popad(void)
  97. {
  98. #ifndef CONFIG_X86_POPAD_OK
  99. int res, inp = (int) &res;
  100. printk(KERN_INFO "Checking for popad bug... ");
  101. __asm__ __volatile__(
  102. "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
  103. : "=&a" (res)
  104. : "d" (inp)
  105. : "ecx", "edi");
  106. /*
  107. * If this fails, it means that any user program may lock the
  108. * CPU hard. Too bad.
  109. */
  110. if (res != 12345678)
  111. printk("Buggy.\n");
  112. else
  113. printk("OK.\n");
  114. #endif
  115. }
  116. /*
  117. * Check whether we are able to run this kernel safely on SMP.
  118. *
  119. * - In order to run on a i386, we need to be compiled for i386
  120. * (for due to lack of "invlpg" and working WP on a i386)
  121. * - In order to run on anything without a TSC, we need to be
  122. * compiled for a i486.
  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) || \
  132. defined(CONFIG_X86_BSWAP)
  133. if (boot_cpu_data.x86 == 3)
  134. panic("Kernel requires i486+ for 'invlpg' and other features");
  135. #endif
  136. }
  137. void __init check_bugs(void)
  138. {
  139. identify_boot_cpu();
  140. #ifndef CONFIG_SMP
  141. printk("CPU: ");
  142. print_cpu_info(&boot_cpu_data);
  143. #endif
  144. check_config();
  145. check_fpu();
  146. check_hlt();
  147. check_popad();
  148. init_utsname()->machine[1] =
  149. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  150. alternative_instructions();
  151. }