traps.c 6.2 KB

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