bugs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_387(char *s)
  20. {
  21. boot_cpu_data.hard_math = 0;
  22. write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
  23. return 1;
  24. }
  25. __setup("no387", no_387);
  26. static double __initdata x = 4195835.0;
  27. static double __initdata y = 3145727.0;
  28. /*
  29. * This used to check for exceptions..
  30. * However, it turns out that to support that,
  31. * the XMM trap handlers basically had to
  32. * be buggy. So let's have a correct XMM trap
  33. * handler, and forget about printing out
  34. * some status at boot.
  35. *
  36. * We should really only care about bugs here
  37. * anyway. Not features.
  38. */
  39. static void __init check_fpu(void)
  40. {
  41. s32 fdiv_bug;
  42. if (!boot_cpu_data.hard_math) {
  43. #ifndef CONFIG_MATH_EMULATION
  44. pr_emerg("No coprocessor found and no math emulation present\n");
  45. pr_emerg("Giving up\n");
  46. for (;;) ;
  47. #endif
  48. return;
  49. }
  50. kernel_fpu_begin();
  51. /*
  52. * trap_init() enabled FXSR and company _before_ testing for FP
  53. * problems here.
  54. *
  55. * Test for the divl bug..
  56. */
  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" (*&fdiv_bug)
  67. : "m" (*&x), "m" (*&y));
  68. kernel_fpu_end();
  69. boot_cpu_data.fdiv_bug = fdiv_bug;
  70. if (boot_cpu_data.fdiv_bug)
  71. pr_warn("Hmm, FPU with FDIV bug\n");
  72. }
  73. /*
  74. * Check whether we are able to run this kernel safely on SMP.
  75. *
  76. * - i386 is no longer supported.
  77. * - In order to run on anything without a TSC, we need to be
  78. * compiled for a i486.
  79. */
  80. static void __init check_config(void)
  81. {
  82. if (boot_cpu_data.x86 < 4)
  83. panic("Kernel requires i486+ for 'invlpg' and other features");
  84. }
  85. void __init check_bugs(void)
  86. {
  87. identify_boot_cpu();
  88. #ifndef CONFIG_SMP
  89. pr_info("CPU: ");
  90. print_cpu_info(&boot_cpu_data);
  91. #endif
  92. check_config();
  93. init_utsname()->machine[1] =
  94. '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
  95. alternative_instructions();
  96. /*
  97. * kernel_fpu_begin/end() in check_fpu() relies on the patched
  98. * alternative instructions.
  99. */
  100. check_fpu();
  101. }