bugs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
  22. boot_cpu_data.hlt_works_ok = 0;
  23. return 1;
  24. }
  25. __setup("no-hlt", no_halt);
  26. static int __init no_387(char *s)
  27. {
  28. boot_cpu_data.hard_math = 0;
  29. write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
  30. return 1;
  31. }
  32. __setup("no387", no_387);
  33. static double __initdata x = 4195835.0;
  34. static double __initdata y = 3145727.0;
  35. /*
  36. * This used to check for exceptions..
  37. * However, it turns out that to support that,
  38. * the XMM trap handlers basically had to
  39. * be buggy. So let's have a correct XMM trap
  40. * handler, and forget about printing out
  41. * some status at boot.
  42. *
  43. * We should really only care about bugs here
  44. * anyway. Not features.
  45. */
  46. static void __init check_fpu(void)
  47. {
  48. s32 fdiv_bug;
  49. if (!boot_cpu_data.hard_math) {
  50. #ifndef CONFIG_MATH_EMULATION
  51. pr_emerg("No coprocessor found and no math emulation present\n");
  52. pr_emerg("Giving up\n");
  53. for (;;) ;
  54. #endif
  55. return;
  56. }
  57. kernel_fpu_begin();
  58. /*
  59. * trap_init() enabled FXSR and company _before_ testing for FP
  60. * problems here.
  61. *
  62. * Test for the divl bug..
  63. */
  64. __asm__("fninit\n\t"
  65. "fldl %1\n\t"
  66. "fdivl %2\n\t"
  67. "fmull %2\n\t"
  68. "fldl %1\n\t"
  69. "fsubp %%st,%%st(1)\n\t"
  70. "fistpl %0\n\t"
  71. "fwait\n\t"
  72. "fninit"
  73. : "=m" (*&fdiv_bug)
  74. : "m" (*&x), "m" (*&y));
  75. kernel_fpu_end();
  76. boot_cpu_data.fdiv_bug = fdiv_bug;
  77. if (boot_cpu_data.fdiv_bug)
  78. pr_warn("Hmm, FPU with FDIV bug\n");
  79. }
  80. static void __init check_hlt(void)
  81. {
  82. if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
  83. return;
  84. pr_info("Checking 'hlt' instruction... ");
  85. if (!boot_cpu_data.hlt_works_ok) {
  86. pr_cont("disabled\n");
  87. return;
  88. }
  89. halt();
  90. halt();
  91. halt();
  92. halt();
  93. pr_cont("OK\n");
  94. }
  95. /*
  96. * Check whether we are able to run this kernel safely on SMP.
  97. *
  98. * - i386 is no longer supported.
  99. * - In order to run on anything without a TSC, we need to be
  100. * compiled for a i486.
  101. */
  102. static void __init check_config(void)
  103. {
  104. if (boot_cpu_data.x86 < 4)
  105. panic("Kernel requires i486+ for 'invlpg' and other features");
  106. }
  107. void __init check_bugs(void)
  108. {
  109. identify_boot_cpu();
  110. #ifndef CONFIG_SMP
  111. pr_info("CPU: ");
  112. print_cpu_info(&boot_cpu_data);
  113. #endif
  114. check_config();
  115. check_hlt();
  116. init_utsname()->machine[1] =
  117. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  118. alternative_instructions();
  119. /*
  120. * kernel_fpu_begin/end() in check_fpu() relies on the patched
  121. * alternative instructions.
  122. */
  123. check_fpu();
  124. }