traps.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  7. */
  8. /*
  9. * This file handles the architecture-dependent parts of hardware
  10. * exceptions
  11. */
  12. #include <common.h>
  13. #include <asm/ptrace.h>
  14. #include <command.h>
  15. #include <kgdb.h>
  16. #include <asm/processor.h>
  17. #include <asm/mpc8349_pci.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. #define END_OF_MEM (gd->ram_base + gd->ram_size)
  22. /*
  23. * Trap & Exception support
  24. */
  25. static void print_backtrace(unsigned long *sp)
  26. {
  27. int cnt = 0;
  28. unsigned long i;
  29. puts ("Call backtrace: ");
  30. while (sp) {
  31. if ((uint)sp > END_OF_MEM)
  32. break;
  33. i = sp[1];
  34. if (cnt++ % 7 == 0)
  35. putc ('\n');
  36. printf("%08lX ", i);
  37. if (cnt > 32) break;
  38. sp = (unsigned long *)*sp;
  39. }
  40. putc ('\n');
  41. }
  42. void show_regs(struct pt_regs *regs)
  43. {
  44. int i;
  45. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  46. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  47. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  48. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  49. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  50. regs->msr&MSR_IR ? 1 : 0,
  51. regs->msr&MSR_DR ? 1 : 0);
  52. putc ('\n');
  53. for (i = 0; i < 32; i++) {
  54. if ((i % 8) == 0) {
  55. printf("GPR%02d: ", i);
  56. }
  57. printf("%08lX ", regs->gpr[i]);
  58. if ((i % 8) == 7) {
  59. putc ('\n');
  60. }
  61. }
  62. }
  63. static void _exception(int signr, struct pt_regs *regs)
  64. {
  65. show_regs(regs);
  66. print_backtrace((unsigned long *)regs->gpr[1]);
  67. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  68. }
  69. #ifdef CONFIG_PCI
  70. void dump_pci (void)
  71. {
  72. /*
  73. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  74. printf ("PCI: err status %x err mask %x err ctrl %x\n",
  75. le32_to_cpu (immap->im_pci.pci_esr),
  76. le32_to_cpu (immap->im_pci.pci_emr),
  77. le32_to_cpu (immap->im_pci.pci_ecr));
  78. printf (" error address %x error data %x ctrl %x\n",
  79. le32_to_cpu (immap->im_pci.pci_eacr),
  80. le32_to_cpu (immap->im_pci.pci_edcr),
  81. le32_to_cpu (immap->im_pci.pci_eccr));
  82. */
  83. }
  84. #endif
  85. void MachineCheckException(struct pt_regs *regs)
  86. {
  87. unsigned long fixup;
  88. /* Probing PCI using config cycles cause this exception
  89. * when a device is not present. Catch it and return to
  90. * the PCI exception handler.
  91. */
  92. #ifdef CONFIG_PCI
  93. #if 0
  94. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  95. #ifdef DEBUG
  96. dump_pci();
  97. #endif
  98. /* clear the error in the error status register */
  99. if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
  100. immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
  101. return;
  102. }
  103. #endif
  104. #endif /* CONFIG_PCI */
  105. if ((fixup = search_exception_table(regs->nip)) != 0) {
  106. regs->nip = fixup;
  107. return;
  108. }
  109. #if defined(CONFIG_CMD_KGDB)
  110. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  111. return;
  112. #endif
  113. puts ("Machine check in kernel mode.\n"
  114. "Caused by (from msr): ");
  115. printf("regs %p ",regs);
  116. switch( regs->msr & 0x000F0000) {
  117. case (0x80000000>>12):
  118. puts ("Machine check signal - probably due to mm fault\n"
  119. "with mmu off\n");
  120. break;
  121. case (0x80000000>>13):
  122. puts ("Transfer error ack signal\n");
  123. break;
  124. case (0x80000000>>14):
  125. puts ("Data parity signal\n");
  126. break;
  127. case (0x80000000>>15):
  128. puts ("Address parity signal\n");
  129. break;
  130. default:
  131. puts ("Unknown values in msr\n");
  132. }
  133. show_regs(regs);
  134. print_backtrace((unsigned long *)regs->gpr[1]);
  135. #ifdef CONFIG_PCI
  136. dump_pci();
  137. #endif
  138. panic("machine check");
  139. }
  140. void AlignmentException(struct pt_regs *regs)
  141. {
  142. #if defined(CONFIG_CMD_KGDB)
  143. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  144. return;
  145. #endif
  146. show_regs(regs);
  147. print_backtrace((unsigned long *)regs->gpr[1]);
  148. panic("Alignment Exception");
  149. }
  150. void ProgramCheckException(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("Program Check Exception");
  159. }
  160. void SoftEmuException(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. show_regs(regs);
  167. print_backtrace((unsigned long *)regs->gpr[1]);
  168. panic("Software Emulation Exception");
  169. }
  170. void UnknownException(struct pt_regs *regs)
  171. {
  172. #if defined(CONFIG_CMD_KGDB)
  173. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  174. return;
  175. #endif
  176. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  177. regs->nip, regs->msr, regs->trap);
  178. _exception(0, regs);
  179. }
  180. #if defined(CONFIG_CMD_BEDBUG)
  181. extern void do_bedbug_breakpoint(struct pt_regs *);
  182. #endif
  183. void DebugException(struct pt_regs *regs)
  184. {
  185. printf("Debugger trap at @ %lx\n", regs->nip );
  186. show_regs(regs);
  187. #if defined(CONFIG_CMD_BEDBUG)
  188. do_bedbug_breakpoint( regs );
  189. #endif
  190. }