traps.c 6.3 KB

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