traps.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * This file handles the architecture-dependent parts of hardware
  24. * exceptions
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <kgdb.h>
  29. #include <asm/processor.h>
  30. #include <asm/mpc8349_pci.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* Returns 0 if exception not found and fixup otherwise. */
  33. extern unsigned long search_exception_table(unsigned long);
  34. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  35. /*
  36. * Trap & Exception support
  37. */
  38. void
  39. print_backtrace(unsigned long *sp)
  40. {
  41. int cnt = 0;
  42. unsigned long i;
  43. puts ("Call backtrace: ");
  44. while (sp) {
  45. if ((uint)sp > END_OF_MEM)
  46. break;
  47. i = sp[1];
  48. if (cnt++ % 7 == 0)
  49. putc ('\n');
  50. printf("%08lX ", i);
  51. if (cnt > 32) break;
  52. sp = (unsigned long *)*sp;
  53. }
  54. putc ('\n');
  55. }
  56. void show_regs(struct pt_regs * regs)
  57. {
  58. int i;
  59. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  60. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  61. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  62. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  63. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  64. regs->msr&MSR_IR ? 1 : 0,
  65. regs->msr&MSR_DR ? 1 : 0);
  66. putc ('\n');
  67. for (i = 0; i < 32; i++) {
  68. if ((i % 8) == 0) {
  69. printf("GPR%02d: ", i);
  70. }
  71. printf("%08lX ", regs->gpr[i]);
  72. if ((i % 8) == 7) {
  73. putc ('\n');
  74. }
  75. }
  76. }
  77. void
  78. _exception(int signr, struct pt_regs *regs)
  79. {
  80. show_regs(regs);
  81. print_backtrace((unsigned long *)regs->gpr[1]);
  82. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  83. }
  84. #ifdef CONFIG_PCI
  85. void dump_pci (void)
  86. {
  87. /*
  88. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  89. printf ("PCI: err status %x err mask %x err ctrl %x\n",
  90. le32_to_cpu (immap->im_pci.pci_esr),
  91. le32_to_cpu (immap->im_pci.pci_emr),
  92. le32_to_cpu (immap->im_pci.pci_ecr));
  93. printf (" error address %x error data %x ctrl %x\n",
  94. le32_to_cpu (immap->im_pci.pci_eacr),
  95. le32_to_cpu (immap->im_pci.pci_edcr),
  96. le32_to_cpu (immap->im_pci.pci_eccr));
  97. */
  98. }
  99. #endif
  100. void
  101. MachineCheckException(struct pt_regs *regs)
  102. {
  103. unsigned long fixup;
  104. /* Probing PCI using config cycles cause this exception
  105. * when a device is not present. Catch it and return to
  106. * the PCI exception handler.
  107. */
  108. #ifdef CONFIG_PCI
  109. #if 0
  110. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  111. #ifdef DEBUG
  112. dump_pci();
  113. #endif
  114. /* clear the error in the error status register */
  115. if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
  116. immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
  117. return;
  118. }
  119. #endif
  120. #endif /* CONFIG_PCI */
  121. if ((fixup = search_exception_table(regs->nip)) != 0) {
  122. regs->nip = fixup;
  123. return;
  124. }
  125. #if defined(CONFIG_CMD_KGDB)
  126. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  127. return;
  128. #endif
  129. puts ("Machine check in kernel mode.\n"
  130. "Caused by (from msr): ");
  131. printf("regs %p ",regs);
  132. switch( regs->msr & 0x000F0000) {
  133. case (0x80000000>>12):
  134. puts ("Machine check signal - probably due to mm fault\n"
  135. "with mmu off\n");
  136. break;
  137. case (0x80000000>>13):
  138. puts ("Transfer error ack signal\n");
  139. break;
  140. case (0x80000000>>14):
  141. puts ("Data parity signal\n");
  142. break;
  143. case (0x80000000>>15):
  144. puts ("Address parity signal\n");
  145. break;
  146. default:
  147. puts ("Unknown values in msr\n");
  148. }
  149. show_regs(regs);
  150. print_backtrace((unsigned long *)regs->gpr[1]);
  151. #ifdef CONFIG_PCI
  152. dump_pci();
  153. #endif
  154. panic("machine check");
  155. }
  156. void
  157. AlignmentException(struct pt_regs *regs)
  158. {
  159. #if defined(CONFIG_CMD_KGDB)
  160. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  161. return;
  162. #endif
  163. show_regs(regs);
  164. print_backtrace((unsigned long *)regs->gpr[1]);
  165. panic("Alignment Exception");
  166. }
  167. void
  168. ProgramCheckException(struct pt_regs *regs)
  169. {
  170. #if defined(CONFIG_CMD_KGDB)
  171. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  172. return;
  173. #endif
  174. show_regs(regs);
  175. print_backtrace((unsigned long *)regs->gpr[1]);
  176. panic("Program Check Exception");
  177. }
  178. void
  179. SoftEmuException(struct pt_regs *regs)
  180. {
  181. #if defined(CONFIG_CMD_KGDB)
  182. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  183. return;
  184. #endif
  185. show_regs(regs);
  186. print_backtrace((unsigned long *)regs->gpr[1]);
  187. panic("Software Emulation Exception");
  188. }
  189. void
  190. UnknownException(struct pt_regs *regs)
  191. {
  192. #if defined(CONFIG_CMD_KGDB)
  193. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  194. return;
  195. #endif
  196. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  197. regs->nip, regs->msr, regs->trap);
  198. _exception(0, regs);
  199. }
  200. #if defined(CONFIG_CMD_BEDBUG)
  201. extern void do_bedbug_breakpoint(struct pt_regs *);
  202. #endif
  203. void
  204. DebugException(struct pt_regs *regs)
  205. {
  206. printf("Debugger trap at @ %lx\n", regs->nip );
  207. show_regs(regs);
  208. #if defined(CONFIG_CMD_BEDBUG)
  209. do_bedbug_breakpoint( regs );
  210. #endif
  211. }
  212. /* Probe an address by reading. If not present, return -1, otherwise
  213. * return 0.
  214. */
  215. int
  216. addr_probe(uint *addr)
  217. {
  218. #if 0
  219. int retval;
  220. __asm__ __volatile__( \
  221. "1: lwz %0,0(%1)\n" \
  222. " eieio\n" \
  223. " li %0,0\n" \
  224. "2:\n" \
  225. ".section .fixup,\"ax\"\n" \
  226. "3: li %0,-1\n" \
  227. " b 2b\n" \
  228. ".section __ex_table,\"a\"\n" \
  229. " .align 2\n" \
  230. " .long 1b,3b\n" \
  231. ".text" \
  232. : "=r" (retval) : "r"(addr));
  233. return (retval);
  234. #endif
  235. return 0;
  236. }