bugs_32.c 1.9 KB

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