traps.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  37. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  38. #endif
  39. /* Returns 0 if exception not found and fixup otherwise. */
  40. extern unsigned long search_exception_table(unsigned long);
  41. /* THIS NEEDS CHANGING to use the board info structure.
  42. */
  43. #ifdef CONFIG_AMIGAONEG3SE
  44. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  45. #else
  46. #define END_OF_MEM 0x02000000
  47. #endif
  48. /*
  49. * Trap & Exception support
  50. */
  51. void
  52. print_backtrace(unsigned long *sp)
  53. {
  54. #ifdef CONFIG_AMIGAONEG3SE
  55. DECLARE_GLOBAL_DATA_PTR;
  56. #endif
  57. int cnt = 0;
  58. unsigned long i;
  59. printf("Call backtrace: ");
  60. while (sp) {
  61. if ((uint)sp > END_OF_MEM)
  62. break;
  63. i = sp[1];
  64. if (cnt++ % 7 == 0)
  65. printf("\n");
  66. printf("%08lX ", i);
  67. if (cnt > 32) break;
  68. sp = (unsigned long *)*sp;
  69. }
  70. printf("\n");
  71. }
  72. void
  73. show_regs(struct pt_regs * regs)
  74. {
  75. int i;
  76. printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
  77. " %p TRAP: %04lx DAR: %08lX\n",
  78. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  79. printf("MSR: %08lx EE: %01x PR: %01x FP:"
  80. " %01x ME: %01x IR/DR: %01x%01x\n",
  81. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  82. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  83. regs->msr&MSR_IR ? 1 : 0,
  84. regs->msr&MSR_DR ? 1 : 0);
  85. printf("\n");
  86. for (i = 0; i < 32; i++) {
  87. if ((i % 8) == 0)
  88. {
  89. printf("GPR%02d: ", i);
  90. }
  91. printf("%08lX ", regs->gpr[i]);
  92. if ((i % 8) == 7)
  93. {
  94. printf("\n");
  95. }
  96. }
  97. }
  98. void
  99. _exception(int signr, struct pt_regs *regs)
  100. {
  101. show_regs(regs);
  102. print_backtrace((unsigned long *)regs->gpr[1]);
  103. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  104. }
  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. if ((fixup = search_exception_table(regs->nip)) != 0) {
  114. regs->nip = fixup;
  115. return;
  116. }
  117. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  118. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  119. return;
  120. #endif
  121. printf("Machine check in kernel mode.\n");
  122. printf("Caused by (from msr): ");
  123. printf("regs %p ",regs);
  124. switch( regs->msr & 0x000F0000) {
  125. case (0x80000000>>12):
  126. printf("Machine check signal - probably due to mm fault\n"
  127. "with mmu off\n");
  128. break;
  129. case (0x80000000>>13):
  130. printf("Transfer error ack signal\n");
  131. break;
  132. case (0x80000000>>14):
  133. printf("Data parity signal\n");
  134. break;
  135. case (0x80000000>>15):
  136. printf("Address parity signal\n");
  137. break;
  138. default:
  139. printf("Unknown values in msr\n");
  140. }
  141. show_regs(regs);
  142. print_backtrace((unsigned long *)regs->gpr[1]);
  143. panic("machine check");
  144. }
  145. void
  146. AlignmentException(struct pt_regs *regs)
  147. {
  148. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  149. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  150. return;
  151. #endif
  152. show_regs(regs);
  153. print_backtrace((unsigned long *)regs->gpr[1]);
  154. panic("Alignment Exception");
  155. }
  156. void
  157. ProgramCheckException(struct pt_regs *regs)
  158. {
  159. unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
  160. int i, j;
  161. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  162. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  163. return;
  164. #endif
  165. show_regs(regs);
  166. p = (unsigned char *) ((unsigned long)p & 0xFFFFFFE0);
  167. p -= 32;
  168. for (i = 0; i < 256; i+=16) {
  169. printf("%08x: ", (unsigned int)p+i);
  170. for (j = 0; j < 16; j++) {
  171. printf("%02x ", p[i+j]);
  172. }
  173. printf("\n");
  174. }
  175. print_backtrace((unsigned long *)regs->gpr[1]);
  176. panic("Program Check Exception");
  177. }
  178. void
  179. SoftEmuException(struct pt_regs *regs)
  180. {
  181. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  182. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  183. return;
  184. #endif
  185. show_regs(regs);
  186. print_backtrace((unsigned long *)regs->gpr[1]);
  187. panic("Software Emulation Exception");
  188. }
  189. void
  190. UnknownException(struct pt_regs *regs)
  191. {
  192. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  193. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  194. return;
  195. #endif
  196. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  197. regs->nip, regs->msr, regs->trap);
  198. _exception(0, regs);
  199. }
  200. /* Probe an address by reading. If not present, return -1, otherwise
  201. * return 0.
  202. */
  203. int
  204. addr_probe(uint *addr)
  205. {
  206. #if 0
  207. int retval;
  208. __asm__ __volatile__( \
  209. "1: lwz %0,0(%1)\n" \
  210. " eieio\n" \
  211. " li %0,0\n" \
  212. "2:\n" \
  213. ".section .fixup,\"ax\"\n" \
  214. "3: li %0,-1\n" \
  215. " b 2b\n" \
  216. ".section __ex_table,\"a\"\n" \
  217. " .align 2\n" \
  218. " .long 1b,3b\n" \
  219. ".text" \
  220. : "=r" (retval) : "r"(addr));
  221. return (retval);
  222. #endif
  223. return 0;
  224. }