traps.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * (C) Copyright 2000 - 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. * Derived from the MPC83xx code.
  10. */
  11. /*
  12. * This file handles the architecture-dependent parts of hardware
  13. * exceptions
  14. */
  15. #include <common.h>
  16. #include <kgdb.h>
  17. #include <asm/processor.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. extern unsigned long search_exception_table(unsigned long);
  20. /*
  21. * End of addressable memory. This may be less than the actual
  22. * amount of memory on the system if we're unable to keep all
  23. * the memory mapped in.
  24. */
  25. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  26. /*
  27. * Trap & Exception support
  28. */
  29. static void print_backtrace(unsigned long *sp)
  30. {
  31. int cnt = 0;
  32. unsigned long i;
  33. puts("Call backtrace: ");
  34. while (sp) {
  35. if ((uint)sp > END_OF_MEM)
  36. break;
  37. i = sp[1];
  38. if (cnt++ % 7 == 0)
  39. putc('\n');
  40. printf("%08lX ", i);
  41. if (cnt > 32) break;
  42. sp = (unsigned long *) *sp;
  43. }
  44. putc('\n');
  45. }
  46. void show_regs(struct pt_regs *regs)
  47. {
  48. int i;
  49. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  50. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  51. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  52. regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0,
  53. regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0,
  54. regs->msr & MSR_IR ? 1 : 0,
  55. regs->msr & MSR_DR ? 1 : 0);
  56. putc('\n');
  57. for (i = 0; i < 32; i++) {
  58. if ((i % 8) == 0) {
  59. printf("GPR%02d: ", i);
  60. }
  61. printf("%08lX ", regs->gpr[i]);
  62. if ((i % 8) == 7) {
  63. putc('\n');
  64. }
  65. }
  66. }
  67. static void _exception(int signr, struct pt_regs *regs)
  68. {
  69. show_regs(regs);
  70. print_backtrace((unsigned long *)regs->gpr[1]);
  71. panic("Exception at pc %lx signal %d", regs->nip, signr);
  72. }
  73. void MachineCheckException(struct pt_regs *regs)
  74. {
  75. unsigned long fixup = search_exception_table(regs->nip);
  76. if (fixup) {
  77. regs->nip = fixup;
  78. return;
  79. }
  80. #ifdef CONFIG_CMD_KGDB
  81. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  82. return;
  83. #endif
  84. puts("Machine check.\nCaused by (from msr): ");
  85. printf("regs %p ", regs);
  86. switch (regs->msr & 0x00FF0000) {
  87. case (0x80000000 >> 10):
  88. puts("Instruction cache parity signal\n");
  89. break;
  90. case (0x80000000 >> 11):
  91. puts("Data cache parity signal\n");
  92. break;
  93. case (0x80000000 >> 12):
  94. puts("Machine check signal\n");
  95. break;
  96. case (0x80000000 >> 13):
  97. puts("Transfer error ack signal\n");
  98. break;
  99. case (0x80000000 >> 14):
  100. puts("Data parity signal\n");
  101. break;
  102. case (0x80000000 >> 15):
  103. puts("Address parity signal\n");
  104. break;
  105. default:
  106. puts("Unknown values in msr\n");
  107. }
  108. show_regs(regs);
  109. print_backtrace((unsigned long *)regs->gpr[1]);
  110. panic("machine check");
  111. }
  112. void AlignmentException(struct pt_regs *regs)
  113. {
  114. #ifdef CONFIG_CMD_KGDB
  115. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  116. return;
  117. #endif
  118. show_regs(regs);
  119. print_backtrace((unsigned long *)regs->gpr[1]);
  120. panic("Alignment Exception");
  121. }
  122. void ProgramCheckException(struct pt_regs *regs)
  123. {
  124. #ifdef CONFIG_CMD_KGDB
  125. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  126. return;
  127. #endif
  128. show_regs(regs);
  129. print_backtrace((unsigned long *)regs->gpr[1]);
  130. panic("Program Check Exception");
  131. }
  132. void SoftEmuException(struct pt_regs *regs)
  133. {
  134. #ifdef CONFIG_CMD_KGDB
  135. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  136. return;
  137. #endif
  138. show_regs(regs);
  139. print_backtrace((unsigned long *)regs->gpr[1]);
  140. panic("Software Emulation Exception");
  141. }
  142. void UnknownException(struct pt_regs *regs)
  143. {
  144. #ifdef CONFIG_CMD_KGDB
  145. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  146. return;
  147. #endif
  148. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  149. regs->nip, regs->msr, regs->trap);
  150. _exception(0, regs);
  151. }
  152. #ifdef CONFIG_CMD_BEDBUG
  153. extern void do_bedbug_breakpoint(struct pt_regs *);
  154. #endif
  155. void DebugException(struct pt_regs *regs)
  156. {
  157. printf("Debugger trap at @ %lx\n", regs->nip);
  158. show_regs(regs);
  159. #ifdef CONFIG_CMD_BEDBUG
  160. do_bedbug_breakpoint(regs);
  161. #endif
  162. }