traps.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 <asm/processor.h>
  29. #include <asm/mpc8349_pci.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* Returns 0 if exception not found and fixup otherwise. */
  32. extern unsigned long search_exception_table(unsigned long);
  33. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  34. /*
  35. * Trap & Exception support
  36. */
  37. void
  38. print_backtrace(unsigned long *sp)
  39. {
  40. int cnt = 0;
  41. unsigned long i;
  42. puts ("Call backtrace: ");
  43. while (sp) {
  44. if ((uint)sp > END_OF_MEM)
  45. break;
  46. i = sp[1];
  47. if (cnt++ % 7 == 0)
  48. putc ('\n');
  49. printf("%08lX ", i);
  50. if (cnt > 32) break;
  51. sp = (unsigned long *)*sp;
  52. }
  53. putc ('\n');
  54. }
  55. void show_regs(struct pt_regs * regs)
  56. {
  57. int i;
  58. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  59. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  60. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  61. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  62. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  63. regs->msr&MSR_IR ? 1 : 0,
  64. regs->msr&MSR_DR ? 1 : 0);
  65. putc ('\n');
  66. for (i = 0; i < 32; i++) {
  67. if ((i % 8) == 0) {
  68. printf("GPR%02d: ", i);
  69. }
  70. printf("%08lX ", regs->gpr[i]);
  71. if ((i % 8) == 7) {
  72. putc ('\n');
  73. }
  74. }
  75. }
  76. void
  77. _exception(int signr, struct pt_regs *regs)
  78. {
  79. show_regs(regs);
  80. print_backtrace((unsigned long *)regs->gpr[1]);
  81. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  82. }
  83. #ifdef CONFIG_PCI
  84. void dump_pci (void)
  85. {
  86. /*
  87. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  88. printf ("PCI: err status %x err mask %x err ctrl %x\n",
  89. le32_to_cpu (immap->im_pci.pci_esr),
  90. le32_to_cpu (immap->im_pci.pci_emr),
  91. le32_to_cpu (immap->im_pci.pci_ecr));
  92. printf (" error address %x error data %x ctrl %x\n",
  93. le32_to_cpu (immap->im_pci.pci_eacr),
  94. le32_to_cpu (immap->im_pci.pci_edcr),
  95. le32_to_cpu (immap->im_pci.pci_eccr));
  96. */
  97. }
  98. #endif
  99. void
  100. MachineCheckException(struct pt_regs *regs)
  101. {
  102. unsigned long fixup;
  103. /* Probing PCI using config cycles cause this exception
  104. * when a device is not present. Catch it and return to
  105. * the PCI exception handler.
  106. */
  107. #ifdef CONFIG_PCI
  108. #if 0
  109. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  110. #ifdef DEBUG
  111. dump_pci();
  112. #endif
  113. /* clear the error in the error status register */
  114. if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
  115. immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
  116. return;
  117. }
  118. #endif
  119. #endif /* CONFIG_PCI */
  120. if ((fixup = search_exception_table(regs->nip)) != 0) {
  121. regs->nip = fixup;
  122. return;
  123. }
  124. #if defined(CONFIG_CMD_KGDB)
  125. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  126. return;
  127. #endif
  128. puts ("Machine check in kernel mode.\n"
  129. "Caused by (from msr): ");
  130. printf("regs %p ",regs);
  131. switch( regs->msr & 0x000F0000) {
  132. case (0x80000000>>12):
  133. puts ("Machine check signal - probably due to mm fault\n"
  134. "with mmu off\n");
  135. break;
  136. case (0x80000000>>13):
  137. puts ("Transfer error ack signal\n");
  138. break;
  139. case (0x80000000>>14):
  140. puts ("Data parity signal\n");
  141. break;
  142. case (0x80000000>>15):
  143. puts ("Address parity signal\n");
  144. break;
  145. default:
  146. puts ("Unknown values in msr\n");
  147. }
  148. show_regs(regs);
  149. print_backtrace((unsigned long *)regs->gpr[1]);
  150. #ifdef CONFIG_PCI
  151. dump_pci();
  152. #endif
  153. panic("machine check");
  154. }
  155. void
  156. AlignmentException(struct pt_regs *regs)
  157. {
  158. #if defined(CONFIG_CMD_KGDB)
  159. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  160. return;
  161. #endif
  162. show_regs(regs);
  163. print_backtrace((unsigned long *)regs->gpr[1]);
  164. panic("Alignment Exception");
  165. }
  166. void
  167. ProgramCheckException(struct pt_regs *regs)
  168. {
  169. #if defined(CONFIG_CMD_KGDB)
  170. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  171. return;
  172. #endif
  173. show_regs(regs);
  174. print_backtrace((unsigned long *)regs->gpr[1]);
  175. panic("Program Check Exception");
  176. }
  177. void
  178. SoftEmuException(struct pt_regs *regs)
  179. {
  180. #if defined(CONFIG_CMD_KGDB)
  181. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  182. return;
  183. #endif
  184. show_regs(regs);
  185. print_backtrace((unsigned long *)regs->gpr[1]);
  186. panic("Software Emulation Exception");
  187. }
  188. void
  189. UnknownException(struct pt_regs *regs)
  190. {
  191. #if defined(CONFIG_CMD_KGDB)
  192. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  193. return;
  194. #endif
  195. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  196. regs->nip, regs->msr, regs->trap);
  197. _exception(0, regs);
  198. }
  199. #if defined(CONFIG_CMD_BEDBUG)
  200. extern void do_bedbug_breakpoint(struct pt_regs *);
  201. #endif
  202. void
  203. DebugException(struct pt_regs *regs)
  204. {
  205. printf("Debugger trap at @ %lx\n", regs->nip );
  206. show_regs(regs);
  207. #if defined(CONFIG_CMD_BEDBUG)
  208. do_bedbug_breakpoint( regs );
  209. #endif
  210. }
  211. /* Probe an address by reading. If not present, return -1, otherwise
  212. * return 0.
  213. */
  214. int
  215. addr_probe(uint *addr)
  216. {
  217. #if 0
  218. int retval;
  219. __asm__ __volatile__( \
  220. "1: lwz %0,0(%1)\n" \
  221. " eieio\n" \
  222. " li %0,0\n" \
  223. "2:\n" \
  224. ".section .fixup,\"ax\"\n" \
  225. "3: li %0,-1\n" \
  226. " b 2b\n" \
  227. ".section __ex_table,\"a\"\n" \
  228. " .align 2\n" \
  229. " .long 1b,3b\n" \
  230. ".text" \
  231. : "=r" (retval) : "r"(addr));
  232. return (retval);
  233. #endif
  234. return 0;
  235. }