traps.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (C) 2003-2006, Axis Communications AB.
  3. */
  4. #include <linux/ptrace.h>
  5. #include <linux/module.h>
  6. #include <asm/uaccess.h>
  7. #include <hwregs/supp_reg.h>
  8. #include <hwregs/intr_vect_defs.h>
  9. #include <asm/irq.h>
  10. void
  11. show_registers(struct pt_regs *regs)
  12. {
  13. /*
  14. * It's possible to use either the USP register or current->thread.usp.
  15. * USP might not correspond to the current process for all cases this
  16. * function is called, and current->thread.usp isn't up to date for the
  17. * current process. Experience shows that using USP is the way to go.
  18. */
  19. unsigned long usp = rdusp();
  20. unsigned long d_mmu_cause;
  21. unsigned long i_mmu_cause;
  22. printk("CPU: %d\n", smp_processor_id());
  23. printk("ERP: %08lx SRP: %08lx CCS: %08lx USP: %08lx MOF: %08lx\n",
  24. regs->erp, regs->srp, regs->ccs, 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 acr: %08lx\n",
  32. regs->r12, regs->r13, regs->orig_r10, regs->acr);
  33. printk(" sp: %08lx\n", (unsigned long)regs);
  34. SUPP_BANK_SEL(BANK_IM);
  35. SUPP_REG_RD(RW_MM_CAUSE, i_mmu_cause);
  36. SUPP_BANK_SEL(BANK_DM);
  37. SUPP_REG_RD(RW_MM_CAUSE, d_mmu_cause);
  38. printk(" Data MMU Cause: %08lx\n", d_mmu_cause);
  39. printk("Instruction MMU Cause: %08lx\n", i_mmu_cause);
  40. printk("Process %s (pid: %d, stackpage=%08lx)\n",
  41. current->comm, current->pid, (unsigned long)current);
  42. /*
  43. * When in-kernel, we also print out the stack and code at the
  44. * time of the fault..
  45. */
  46. if (!user_mode(regs)) {
  47. int i;
  48. show_stack(NULL, (unsigned long *)usp);
  49. /*
  50. * If the previous stack-dump wasn't a kernel one, dump the
  51. * kernel stack now.
  52. */
  53. if (usp != 0)
  54. show_stack(NULL, NULL);
  55. printk("\nCode: ");
  56. if (regs->erp < PAGE_OFFSET)
  57. goto bad_value;
  58. /*
  59. * Quite often the value at regs->erp doesn't point to the
  60. * interesting instruction, which often is the previous
  61. * instruction. So dump at an offset large enough that the
  62. * instruction decoding should be in sync at the interesting
  63. * point, but small enough to fit on a row. The regs->erp
  64. * location is pointed out in a ksymoops-friendly way by
  65. * wrapping the byte for that address in parenthesises.
  66. */
  67. for (i = -12; i < 12; i++) {
  68. unsigned char c;
  69. if (__get_user(c, &((unsigned char *)regs->erp)[i])) {
  70. bad_value:
  71. printk(" Bad IP value.");
  72. break;
  73. }
  74. if (i == 0)
  75. printk("(%02x) ", c);
  76. else
  77. printk("%02x ", c);
  78. }
  79. printk("\n");
  80. }
  81. }
  82. void
  83. arch_enable_nmi(void)
  84. {
  85. unsigned long flags;
  86. local_save_flags(flags);
  87. flags |= (1 << 30); /* NMI M flag is at bit 30 */
  88. local_irq_restore(flags);
  89. }
  90. extern void (*nmi_handler)(struct pt_regs *);
  91. void handle_nmi(struct pt_regs *regs)
  92. {
  93. #ifdef CONFIG_ETRAXFS
  94. reg_intr_vect_r_nmi r;
  95. #endif
  96. if (nmi_handler)
  97. nmi_handler(regs);
  98. #ifdef CONFIG_ETRAXFS
  99. /* Wait until nmi is no longer active. */
  100. do {
  101. r = REG_RD(intr_vect, regi_irq, r_nmi);
  102. } while (r.ext == regk_intr_vect_on);
  103. #endif
  104. }
  105. #ifdef CONFIG_BUG
  106. extern void die_if_kernel(const char *str, struct pt_regs *regs, long err);
  107. /* Copy of the regs at BUG() time. */
  108. struct pt_regs BUG_regs;
  109. void do_BUG(char *file, unsigned int line)
  110. {
  111. printk("kernel BUG at %s:%d!\n", file, line);
  112. die_if_kernel("Oops", &BUG_regs, 0);
  113. }
  114. EXPORT_SYMBOL(do_BUG);
  115. void fixup_BUG(struct pt_regs *regs)
  116. {
  117. BUG_regs = *regs;
  118. #ifdef CONFIG_DEBUG_BUGVERBOSE
  119. /*
  120. * Fixup the BUG arguments through exception handlers.
  121. */
  122. {
  123. const struct exception_table_entry *fixup;
  124. /*
  125. * ERP points at the "break 14" + 2, compensate for the 2
  126. * bytes.
  127. */
  128. fixup = search_exception_tables(instruction_pointer(regs) - 2);
  129. if (fixup) {
  130. /* Adjust the instruction pointer in the stackframe. */
  131. instruction_pointer(regs) = fixup->fixup;
  132. arch_fixup(regs);
  133. }
  134. }
  135. #else
  136. /* Dont try to lookup the filename + line, just dump regs. */
  137. do_BUG("unknown", 0);
  138. #endif
  139. }
  140. /*
  141. * Break 14 handler. Save regs and jump into the fixup_BUG.
  142. */
  143. __asm__ ( ".text\n\t"
  144. ".global breakh_BUG\n\t"
  145. "breakh_BUG:\n\t"
  146. SAVE_ALL
  147. KGDB_FIXUP
  148. "move.d $sp, $r10\n\t"
  149. "jsr fixup_BUG\n\t"
  150. "nop\n\t"
  151. "jump ret_from_intr\n\t"
  152. "nop\n\t");
  153. #ifdef CONFIG_DEBUG_BUGVERBOSE
  154. void
  155. handle_BUG(struct pt_regs *regs)
  156. {
  157. }
  158. #endif
  159. #endif