traps.c 6.3 KB

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