traps.c 4.6 KB

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