traps.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  3. *
  4. * Modified by Cort Dougan (cort@cs.nmt.edu)
  5. * and Paul Mackerras (paulus@cs.anu.edu.au)
  6. *
  7. * (C) Copyright 2000
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. /*
  29. * This file handles the architecture-dependent parts of hardware exceptions
  30. */
  31. #include <common.h>
  32. #include <command.h>
  33. #include <asm/processor.h>
  34. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  35. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  36. #endif
  37. /* Returns 0 if exception not found and fixup otherwise. */
  38. extern unsigned long search_exception_table(unsigned long);
  39. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  40. /*
  41. * Trap & Exception support
  42. */
  43. void
  44. print_backtrace(unsigned long *sp)
  45. {
  46. DECLARE_GLOBAL_DATA_PTR;
  47. int cnt = 0;
  48. unsigned long i;
  49. printf("Call backtrace: ");
  50. while (sp) {
  51. if ((uint)sp > END_OF_MEM)
  52. break;
  53. i = sp[1];
  54. if (cnt++ % 7 == 0)
  55. printf("\n");
  56. printf("%08lX ", i);
  57. if (cnt > 32) break;
  58. sp = (unsigned long *)*sp;
  59. }
  60. printf("\n");
  61. }
  62. void
  63. show_regs(struct pt_regs * regs)
  64. {
  65. int i;
  66. printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
  67. " %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:"
  70. " %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. printf("\n");
  76. for (i = 0; i < 32; i++) {
  77. if ((i % 8) == 0)
  78. {
  79. printf("GPR%02d: ", i);
  80. }
  81. printf("%08lX ", regs->gpr[i]);
  82. if ((i % 8) == 7)
  83. {
  84. printf("\n");
  85. }
  86. }
  87. }
  88. void
  89. _exception(int signr, struct pt_regs *regs)
  90. {
  91. show_regs(regs);
  92. print_backtrace((unsigned long *)regs->gpr[1]);
  93. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  94. }
  95. void
  96. MachineCheckException(struct pt_regs *regs)
  97. {
  98. unsigned long fixup;
  99. /* Probing PCI using config cycles cause this exception
  100. * when a device is not present. Catch it and return to
  101. * the PCI exception handler.
  102. */
  103. if ((fixup = search_exception_table(regs->nip)) != 0) {
  104. regs->nip = fixup;
  105. return;
  106. }
  107. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  108. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  109. return;
  110. #endif
  111. printf("Machine check in kernel mode.\n");
  112. printf("Caused by (from msr): ");
  113. printf("regs %p ",regs);
  114. switch( regs->msr & 0x000F0000) {
  115. case (0x80000000>>12):
  116. printf("Machine check signal - probably due to mm fault\n"
  117. "with mmu off\n");
  118. break;
  119. case (0x80000000>>13):
  120. printf("Transfer error ack signal\n");
  121. break;
  122. case (0x80000000>>14):
  123. printf("Data parity signal\n");
  124. break;
  125. case (0x80000000>>15):
  126. printf("Address parity signal\n");
  127. break;
  128. default:
  129. printf("Unknown values in msr\n");
  130. }
  131. show_regs(regs);
  132. print_backtrace((unsigned long *)regs->gpr[1]);
  133. panic("machine check");
  134. }
  135. void
  136. AlignmentException(struct pt_regs *regs)
  137. {
  138. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  139. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  140. return;
  141. #endif
  142. show_regs(regs);
  143. print_backtrace((unsigned long *)regs->gpr[1]);
  144. panic("Alignment Exception");
  145. }
  146. void
  147. ProgramCheckException(struct pt_regs *regs)
  148. {
  149. unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
  150. int i, j;
  151. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  152. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  153. return;
  154. #endif
  155. show_regs(regs);
  156. p = (unsigned char *) ((unsigned long)p & 0xFFFFFFE0);
  157. p -= 32;
  158. for (i = 0; i < 256; i+=16) {
  159. printf("%08x: ", (unsigned int)p+i);
  160. for (j = 0; j < 16; j++) {
  161. printf("%02x ", p[i+j]);
  162. }
  163. printf("\n");
  164. }
  165. print_backtrace((unsigned long *)regs->gpr[1]);
  166. panic("Program Check Exception");
  167. }
  168. void
  169. SoftEmuException(struct pt_regs *regs)
  170. {
  171. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  172. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  173. return;
  174. #endif
  175. show_regs(regs);
  176. print_backtrace((unsigned long *)regs->gpr[1]);
  177. panic("Software Emulation Exception");
  178. }
  179. void
  180. UnknownException(struct pt_regs *regs)
  181. {
  182. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  183. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  184. return;
  185. #endif
  186. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  187. regs->nip, regs->msr, regs->trap);
  188. _exception(0, regs);
  189. }
  190. /* Probe an address by reading. If not present, return -1, otherwise
  191. * return 0.
  192. */
  193. int
  194. addr_probe(uint *addr)
  195. {
  196. #if 0
  197. int retval;
  198. __asm__ __volatile__( \
  199. "1: lwz %0,0(%1)\n" \
  200. " eieio\n" \
  201. " li %0,0\n" \
  202. "2:\n" \
  203. ".section .fixup,\"ax\"\n" \
  204. "3: li %0,-1\n" \
  205. " b 2b\n" \
  206. ".section __ex_table,\"a\"\n" \
  207. " .align 2\n" \
  208. " .long 1b,3b\n" \
  209. ".text" \
  210. : "=r" (retval) : "r"(addr));
  211. return (retval);
  212. #endif
  213. return 0;
  214. }