bugs.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <errno.h>
  6. #include <signal.h>
  7. #include <string.h>
  8. #include "kern_constants.h"
  9. #include "os.h"
  10. #include "task.h"
  11. #include "user.h"
  12. #include "sysdep/archsetjmp.h"
  13. /* Set during early boot */
  14. int host_has_cmov = 1;
  15. static jmp_buf cmov_test_return;
  16. static void cmov_sigill_test_handler(int sig)
  17. {
  18. host_has_cmov = 0;
  19. longjmp(cmov_test_return, 1);
  20. }
  21. static void test_for_host_cmov(void)
  22. {
  23. struct sigaction old, new;
  24. printk(UM_KERN_INFO "Checking for host processor cmov support...");
  25. new.sa_handler = cmov_sigill_test_handler;
  26. /* Make sure that SIGILL is enabled after the handler longjmps back */
  27. new.sa_flags = SA_NODEFER;
  28. sigemptyset(&new.sa_mask);
  29. sigaction(SIGILL, &new, &old);
  30. if (setjmp(cmov_test_return) == 0) {
  31. unsigned long foo = 0;
  32. __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo));
  33. printk(UM_KERN_CONT "Yes\n");
  34. } else
  35. printk(UM_KERN_CONT "No\n");
  36. sigaction(SIGILL, &old, &new);
  37. }
  38. void arch_init_thread(void)
  39. {
  40. }
  41. void arch_check_bugs(void)
  42. {
  43. test_for_host_cmov();
  44. }
  45. int arch_handle_signal(int sig, struct uml_pt_regs *regs)
  46. {
  47. unsigned char tmp[2];
  48. /*
  49. * This is testing for a cmov (0x0f 0x4x) instruction causing a
  50. * SIGILL in init.
  51. */
  52. if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
  53. return 0;
  54. if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
  55. panic("SIGILL in init, could not read instructions!\n");
  56. if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
  57. return 0;
  58. if (host_has_cmov == 0)
  59. panic("SIGILL caused by cmov, which this processor doesn't "
  60. "implement, boot a filesystem compiled for older "
  61. "processors");
  62. else if (host_has_cmov == 1)
  63. panic("SIGILL caused by cmov, which this processor claims to "
  64. "implement");
  65. else panic("Bad value for host_has_cmov (%d)", host_has_cmov);
  66. return 0;
  67. }