traps.c 5.5 KB

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