traps.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  3. *
  4. * Modified by Cort Dougan (cort@cs.nmt.edu)
  5. * and Paul Mackerras (paulus@cs.anu.edu.au)
  6. *
  7. * (C) Copyright 2000
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of hardware exceptions
  14. */
  15. #include <common.h>
  16. #include <command.h>
  17. #include <kgdb.h>
  18. #include <asm/processor.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /* Returns 0 if exception not found and fixup otherwise. */
  21. extern unsigned long search_exception_table(unsigned long);
  22. /*
  23. * End of addressable memory. This may be less than the actual
  24. * amount of memory on the system if we're unable to keep all
  25. * the memory mapped in.
  26. */
  27. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  28. /*
  29. * Trap & Exception support
  30. */
  31. static void print_backtrace(unsigned long *sp)
  32. {
  33. int cnt = 0;
  34. unsigned long i;
  35. printf("Call backtrace: ");
  36. while (sp) {
  37. if ((uint) sp > END_OF_MEM)
  38. break;
  39. i = sp[1];
  40. if (cnt++ % 7 == 0)
  41. printf("\n");
  42. printf("%08lX ", i);
  43. if (cnt > 32)
  44. break;
  45. sp = (unsigned long *)*sp;
  46. }
  47. printf("\n");
  48. }
  49. void show_regs(struct pt_regs *regs)
  50. {
  51. int i;
  52. printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
  53. " %p TRAP: %04lx DAR: %08lX\n",
  54. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  55. printf("MSR: %08lx EE: %01x PR: %01x FP:"
  56. " %01x ME: %01x IR/DR: %01x%01x\n",
  57. regs->msr, regs->msr & MSR_EE ? 1 : 0,
  58. regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
  59. regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
  60. regs->msr & MSR_DR ? 1 : 0);
  61. printf("\n");
  62. for (i = 0; i < 32; i++) {
  63. if ((i % 8) == 0) {
  64. printf("GPR%02d: ", i);
  65. }
  66. printf("%08lX ", regs->gpr[i]);
  67. if ((i % 8) == 7) {
  68. printf("\n");
  69. }
  70. }
  71. }
  72. static void _exception(int signr, struct pt_regs *regs)
  73. {
  74. show_regs(regs);
  75. print_backtrace((unsigned long *)regs->gpr[1]);
  76. panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
  77. }
  78. void MachineCheckException(struct pt_regs *regs)
  79. {
  80. unsigned long fixup;
  81. /* Probing PCI using config cycles cause this exception
  82. * when a device is not present. Catch it and return to
  83. * the PCI exception handler.
  84. */
  85. if ((fixup = search_exception_table(regs->nip)) != 0) {
  86. regs->nip = fixup;
  87. return;
  88. }
  89. #if defined(CONFIG_CMD_KGDB)
  90. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  91. return;
  92. #endif
  93. printf("Machine check in kernel mode.\n");
  94. printf("Caused by (from msr): ");
  95. printf("regs %p ", regs);
  96. switch ( regs->msr & 0x001F0000) {
  97. case (0x80000000>>11):
  98. printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
  99. break;
  100. case (0x80000000>>12):
  101. printf("Machine check signal - probably due to mm fault\n"
  102. "with mmu off\n");
  103. break;
  104. case (0x80000000 >> 13):
  105. printf("Transfer error ack signal\n");
  106. break;
  107. case (0x80000000 >> 14):
  108. printf("Data parity signal\n");
  109. break;
  110. case (0x80000000 >> 15):
  111. printf("Address parity signal\n");
  112. break;
  113. default:
  114. printf("Unknown values in msr\n");
  115. }
  116. show_regs(regs);
  117. print_backtrace((unsigned long *)regs->gpr[1]);
  118. panic("machine check");
  119. }
  120. void AlignmentException(struct pt_regs *regs)
  121. {
  122. #if defined(CONFIG_CMD_KGDB)
  123. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  124. return;
  125. #endif
  126. show_regs(regs);
  127. print_backtrace((unsigned long *)regs->gpr[1]);
  128. panic("Alignment Exception");
  129. }
  130. void ProgramCheckException(struct pt_regs *regs)
  131. {
  132. unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
  133. int i, j;
  134. #if defined(CONFIG_CMD_KGDB)
  135. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  136. return;
  137. #endif
  138. show_regs(regs);
  139. p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
  140. p -= 32;
  141. for (i = 0; i < 256; i += 16) {
  142. printf("%08x: ", (unsigned int)p + i);
  143. for (j = 0; j < 16; j++) {
  144. printf("%02x ", p[i + j]);
  145. }
  146. printf("\n");
  147. }
  148. print_backtrace((unsigned long *)regs->gpr[1]);
  149. panic("Program Check Exception");
  150. }
  151. void SoftEmuException(struct pt_regs *regs)
  152. {
  153. #if defined(CONFIG_CMD_KGDB)
  154. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  155. return;
  156. #endif
  157. show_regs(regs);
  158. print_backtrace((unsigned long *)regs->gpr[1]);
  159. panic("Software Emulation Exception");
  160. }
  161. void UnknownException(struct pt_regs *regs)
  162. {
  163. #if defined(CONFIG_CMD_KGDB)
  164. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  165. return;
  166. #endif
  167. printf("UnknownException regs@%lx\n", (ulong)regs);
  168. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  169. regs->nip, regs->msr, regs->trap);
  170. _exception(0, regs);
  171. }
  172. /*
  173. * Probe an address by reading.
  174. * If not present, return -1,
  175. * otherwise return 0.
  176. */
  177. int addr_probe(uint *addr)
  178. {
  179. return 0;
  180. }