traps.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * linux/arch/ppc/kernel/traps.c
  3. *
  4. * Copyright (C) 2003 Motorola
  5. * Modified by Xianghua Xiao(x.xiao@motorola.com)
  6. *
  7. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  8. *
  9. * Modified by Cort Dougan (cort@cs.nmt.edu)
  10. * and Paul Mackerras (paulus@cs.anu.edu.au)
  11. *
  12. * (C) Copyright 2000
  13. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  14. *
  15. * See file CREDITS for list of people who contributed to this
  16. * project.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License as
  20. * published by the Free Software Foundation; either version 2 of
  21. * the License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  31. * MA 02111-1307 USA
  32. */
  33. /*
  34. * This file handles the architecture-dependent parts of hardware exceptions
  35. */
  36. #include <common.h>
  37. #include <command.h>
  38. #include <asm/processor.h>
  39. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  40. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  41. #endif
  42. /* Returns 0 if exception not found and fixup otherwise. */
  43. extern unsigned long search_exception_table(unsigned long);
  44. /*
  45. * End of memory as shown by board info and determined by DDR setup.
  46. */
  47. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  48. static __inline__ void set_tsr(unsigned long val)
  49. {
  50. asm volatile("mtspr 0x150, %0" : : "r" (val));
  51. }
  52. static __inline__ unsigned long get_esr(void)
  53. {
  54. unsigned long val;
  55. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  56. return val;
  57. }
  58. #define ESR_MCI 0x80000000
  59. #define ESR_PIL 0x08000000
  60. #define ESR_PPR 0x04000000
  61. #define ESR_PTR 0x02000000
  62. #define ESR_DST 0x00800000
  63. #define ESR_DIZ 0x00400000
  64. #define ESR_U0F 0x00008000
  65. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  66. extern void do_bedbug_breakpoint(struct pt_regs *);
  67. #endif
  68. /*
  69. * Trap & Exception support
  70. */
  71. void
  72. print_backtrace(unsigned long *sp)
  73. {
  74. DECLARE_GLOBAL_DATA_PTR;
  75. int cnt = 0;
  76. unsigned long i;
  77. printf("Call backtrace: ");
  78. while (sp) {
  79. if ((uint)sp > END_OF_MEM)
  80. break;
  81. i = sp[1];
  82. if (cnt++ % 7 == 0)
  83. printf("\n");
  84. printf("%08lX ", i);
  85. if (cnt > 32) break;
  86. sp = (unsigned long *)*sp;
  87. }
  88. printf("\n");
  89. }
  90. void show_regs(struct pt_regs * regs)
  91. {
  92. int i;
  93. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  94. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  95. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  96. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  97. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  98. regs->msr&MSR_IR ? 1 : 0,
  99. regs->msr&MSR_DR ? 1 : 0);
  100. printf("\n");
  101. for (i = 0; i < 32; i++) {
  102. if ((i % 8) == 0)
  103. {
  104. printf("GPR%02d: ", i);
  105. }
  106. printf("%08lX ", regs->gpr[i]);
  107. if ((i % 8) == 7)
  108. {
  109. printf("\n");
  110. }
  111. }
  112. }
  113. void
  114. _exception(int signr, struct pt_regs *regs)
  115. {
  116. show_regs(regs);
  117. print_backtrace((unsigned long *)regs->gpr[1]);
  118. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  119. }
  120. void
  121. CritcalInputException(struct pt_regs *regs)
  122. {
  123. panic("Critical Input Exception");
  124. }
  125. void
  126. MachineCheckException(struct pt_regs *regs)
  127. {
  128. unsigned long fixup;
  129. /* Probing PCI using config cycles cause this exception
  130. * when a device is not present. Catch it and return to
  131. * the PCI exception handler.
  132. */
  133. if ((fixup = search_exception_table(regs->nip)) != 0) {
  134. regs->nip = fixup;
  135. return;
  136. }
  137. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  138. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  139. return;
  140. #endif
  141. printf("Machine check in kernel mode.\n");
  142. printf("Caused by (from msr): ");
  143. printf("regs %p ",regs);
  144. switch( regs->msr & 0x000F0000) {
  145. case (0x80000000>>12):
  146. printf("Machine check signal - probably due to mm fault\n"
  147. "with mmu off\n");
  148. break;
  149. case (0x80000000>>13):
  150. printf("Transfer error ack signal\n");
  151. break;
  152. case (0x80000000>>14):
  153. printf("Data parity signal\n");
  154. break;
  155. case (0x80000000>>15):
  156. printf("Address parity signal\n");
  157. break;
  158. default:
  159. printf("Unknown values in msr\n");
  160. }
  161. show_regs(regs);
  162. print_backtrace((unsigned long *)regs->gpr[1]);
  163. panic("machine check");
  164. }
  165. void
  166. AlignmentException(struct pt_regs *regs)
  167. {
  168. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  169. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  170. return;
  171. #endif
  172. show_regs(regs);
  173. print_backtrace((unsigned long *)regs->gpr[1]);
  174. panic("Alignment Exception");
  175. }
  176. void
  177. ProgramCheckException(struct pt_regs *regs)
  178. {
  179. long esr_val;
  180. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  181. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  182. return;
  183. #endif
  184. show_regs(regs);
  185. esr_val = get_esr();
  186. if( esr_val & ESR_PIL )
  187. printf( "** Illegal Instruction **\n" );
  188. else if( esr_val & ESR_PPR )
  189. printf( "** Privileged Instruction **\n" );
  190. else if( esr_val & ESR_PTR )
  191. printf( "** Trap Instruction **\n" );
  192. print_backtrace((unsigned long *)regs->gpr[1]);
  193. panic("Program Check Exception");
  194. }
  195. void
  196. PITException(struct pt_regs *regs)
  197. {
  198. /*
  199. * Reset PIT interrupt
  200. */
  201. set_tsr(0x0c000000);
  202. /*
  203. * Call timer_interrupt routine in interrupts.c
  204. */
  205. timer_interrupt(NULL);
  206. }
  207. void
  208. UnknownException(struct pt_regs *regs)
  209. {
  210. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  211. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  212. return;
  213. #endif
  214. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  215. regs->nip, regs->msr, regs->trap);
  216. _exception(0, regs);
  217. }
  218. void
  219. DebugException(struct pt_regs *regs)
  220. {
  221. printf("Debugger trap at @ %lx\n", regs->nip );
  222. show_regs(regs);
  223. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  224. do_bedbug_breakpoint( regs );
  225. #endif
  226. }
  227. /* Probe an address by reading. If not present, return -1, otherwise
  228. * return 0.
  229. */
  230. int
  231. addr_probe(uint *addr)
  232. {
  233. return 0;
  234. }