traps.c 4.6 KB

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