traps.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Helper functions for trap handlers
  3. *
  4. * Copyright (C) 2000-2007, Axis Communications AB.
  5. *
  6. * Authors: Bjorn Wesen
  7. * Hans-Peter Nilsson
  8. *
  9. */
  10. #include <linux/ptrace.h>
  11. #include <asm/uaccess.h>
  12. #include <arch/sv_addr_ag.h>
  13. void
  14. show_registers(struct pt_regs *regs)
  15. {
  16. /*
  17. * It's possible to use either the USP register or current->thread.usp.
  18. * USP might not correspond to the current process for all cases this
  19. * function is called, and current->thread.usp isn't up to date for the
  20. * current process. Experience shows that using USP is the way to go.
  21. */
  22. unsigned long usp = rdusp();
  23. printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
  24. regs->irp, regs->srp, regs->dccr, usp, regs->mof);
  25. printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
  26. regs->r0, regs->r1, regs->r2, regs->r3);
  27. printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
  28. regs->r4, regs->r5, regs->r6, regs->r7);
  29. printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
  30. regs->r8, regs->r9, regs->r10, regs->r11);
  31. printk("r12: %08lx r13: %08lx oR10: %08lx sp: %08lx\n",
  32. regs->r12, regs->r13, regs->orig_r10, (long unsigned)regs);
  33. printk("R_MMU_CAUSE: %08lx\n", (unsigned long)*R_MMU_CAUSE);
  34. printk("Process %s (pid: %d, stackpage=%08lx)\n",
  35. current->comm, current->pid, (unsigned long)current);
  36. /*
  37. * When in-kernel, we also print out the stack and code at the
  38. * time of the fault..
  39. */
  40. if (!user_mode(regs)) {
  41. int i;
  42. show_stack(NULL, (unsigned long *)usp);
  43. /*
  44. * If the previous stack-dump wasn't a kernel one, dump the
  45. * kernel stack now.
  46. */
  47. if (usp != 0)
  48. show_stack(NULL, NULL);
  49. printk("\nCode: ");
  50. if (regs->irp < PAGE_OFFSET)
  51. goto bad_value;
  52. /*
  53. * Quite often the value at regs->irp doesn't point to the
  54. * interesting instruction, which often is the previous
  55. * instruction. So dump at an offset large enough that the
  56. * instruction decoding should be in sync at the interesting
  57. * point, but small enough to fit on a row. The regs->irp
  58. * location is pointed out in a ksymoops-friendly way by
  59. * wrapping the byte for that address in parenthesises.
  60. */
  61. for (i = -12; i < 12; i++) {
  62. unsigned char c;
  63. if (__get_user(c, &((unsigned char *)regs->irp)[i])) {
  64. bad_value:
  65. printk(" Bad IP value.");
  66. break;
  67. }
  68. if (i == 0)
  69. printk("(%02x) ", c);
  70. else
  71. printk("%02x ", c);
  72. }
  73. printk("\n");
  74. }
  75. }
  76. void
  77. arch_enable_nmi(void)
  78. {
  79. asm volatile ("setf m");
  80. }
  81. extern void (*nmi_handler)(struct pt_regs *);
  82. void handle_nmi(struct pt_regs *regs)
  83. {
  84. if (nmi_handler)
  85. nmi_handler(regs);
  86. /* Wait until nmi is no longer active. (We enable NMI immediately after
  87. returning from this function, and we don't want it happening while
  88. exiting from the NMI interrupt handler.) */
  89. while (*R_IRQ_MASK0_RD & IO_STATE(R_IRQ_MASK0_RD, nmi_pin, active))
  90. ;
  91. }
  92. #ifdef CONFIG_DEBUG_BUGVERBOSE
  93. void
  94. handle_BUG(struct pt_regs *regs)
  95. {
  96. struct bug_frame f;
  97. unsigned char c;
  98. unsigned long irp = regs->irp;
  99. if (__copy_from_user(&f, (const void __user *)(irp - 8), sizeof f))
  100. return;
  101. if (f.prefix != BUG_PREFIX || f.magic != BUG_MAGIC)
  102. return;
  103. if (__get_user(c, f.filename))
  104. f.filename = "<bad filename>";
  105. printk("kernel BUG at %s:%d!\n", f.filename, f.line);
  106. }
  107. #endif