traps.c 6.2 KB

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