bugs.c 1.8 KB

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