traps.c 3.3 KB

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