traps.c 4.4 KB

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