bugs_32.c 1.8 KB

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