traps.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. /* THIS NEEDS CHANGING to use the board info structure.
  45. */
  46. #define END_OF_MEM (CFG_SDRAM_SIZE * 1024 * 1024)
  47. static __inline__ void set_tsr(unsigned long val)
  48. {
  49. asm volatile("mtspr 0x150, %0" : : "r" (val));
  50. }
  51. static __inline__ unsigned long get_esr(void)
  52. {
  53. unsigned long val;
  54. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  55. return val;
  56. }
  57. #define ESR_MCI 0x80000000
  58. #define ESR_PIL 0x08000000
  59. #define ESR_PPR 0x04000000
  60. #define ESR_PTR 0x02000000
  61. #define ESR_DST 0x00800000
  62. #define ESR_DIZ 0x00400000
  63. #define ESR_U0F 0x00008000
  64. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  65. extern void do_bedbug_breakpoint(struct pt_regs *);
  66. #endif
  67. /*
  68. * Trap & Exception support
  69. */
  70. void
  71. print_backtrace(unsigned long *sp)
  72. {
  73. int cnt = 0;
  74. unsigned long i;
  75. printf("Call backtrace: ");
  76. while (sp) {
  77. if ((uint)sp > END_OF_MEM)
  78. break;
  79. i = sp[1];
  80. if (cnt++ % 7 == 0)
  81. printf("\n");
  82. printf("%08lX ", i);
  83. if (cnt > 32) break;
  84. sp = (unsigned long *)*sp;
  85. }
  86. printf("\n");
  87. }
  88. void show_regs(struct pt_regs * regs)
  89. {
  90. int i;
  91. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  92. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  93. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  94. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  95. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  96. regs->msr&MSR_IR ? 1 : 0,
  97. regs->msr&MSR_DR ? 1 : 0);
  98. printf("\n");
  99. for (i = 0; i < 32; i++) {
  100. if ((i % 8) == 0)
  101. {
  102. printf("GPR%02d: ", i);
  103. }
  104. printf("%08lX ", regs->gpr[i]);
  105. if ((i % 8) == 7)
  106. {
  107. printf("\n");
  108. }
  109. }
  110. }
  111. void
  112. _exception(int signr, struct pt_regs *regs)
  113. {
  114. show_regs(regs);
  115. print_backtrace((unsigned long *)regs->gpr[1]);
  116. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  117. }
  118. void
  119. CritcalInputException(struct pt_regs *regs)
  120. {
  121. panic("Critical Input Exception");
  122. }
  123. void
  124. MachineCheckException(struct pt_regs *regs)
  125. {
  126. unsigned long fixup;
  127. /* Probing PCI using config cycles cause this exception
  128. * when a device is not present. Catch it and return to
  129. * the PCI exception handler.
  130. */
  131. if ((fixup = search_exception_table(regs->nip)) != 0) {
  132. regs->nip = fixup;
  133. return;
  134. }
  135. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  136. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  137. return;
  138. #endif
  139. printf("Machine check in kernel mode.\n");
  140. printf("Caused by (from msr): ");
  141. printf("regs %p ",regs);
  142. switch( regs->msr & 0x0000F000)
  143. {
  144. case (1<<12) :
  145. printf("Machine check signal - probably due to mm fault\n"
  146. "with mmu off\n");
  147. break;
  148. case (1<<13) :
  149. printf("Transfer error ack signal\n");
  150. break;
  151. case (1<<14) :
  152. printf("Data parity signal\n");
  153. break;
  154. case (1<<15) :
  155. printf("Address parity signal\n");
  156. break;
  157. default:
  158. printf("Unknown values in msr\n");
  159. }
  160. show_regs(regs);
  161. print_backtrace((unsigned long *)regs->gpr[1]);
  162. panic("machine check");
  163. }
  164. void
  165. AlignmentException(struct pt_regs *regs)
  166. {
  167. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  168. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  169. return;
  170. #endif
  171. show_regs(regs);
  172. print_backtrace((unsigned long *)regs->gpr[1]);
  173. panic("Alignment Exception");
  174. }
  175. void
  176. ProgramCheckException(struct pt_regs *regs)
  177. {
  178. long esr_val;
  179. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  180. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  181. return;
  182. #endif
  183. show_regs(regs);
  184. esr_val = get_esr();
  185. if( esr_val & ESR_PIL )
  186. printf( "** Illegal Instruction **\n" );
  187. else if( esr_val & ESR_PPR )
  188. printf( "** Privileged Instruction **\n" );
  189. else if( esr_val & ESR_PTR )
  190. printf( "** Trap Instruction **\n" );
  191. print_backtrace((unsigned long *)regs->gpr[1]);
  192. panic("Program Check Exception");
  193. }
  194. void
  195. PITException(struct pt_regs *regs)
  196. {
  197. /*
  198. * Reset PIT interrupt
  199. */
  200. set_tsr(0x0c000000);
  201. /*
  202. * Call timer_interrupt routine in interrupts.c
  203. */
  204. timer_interrupt(NULL);
  205. }
  206. void
  207. UnknownException(struct pt_regs *regs)
  208. {
  209. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  210. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  211. return;
  212. #endif
  213. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  214. regs->nip, regs->msr, regs->trap);
  215. _exception(0, regs);
  216. }
  217. void
  218. DebugException(struct pt_regs *regs)
  219. {
  220. printf("Debugger trap at @ %lx\n", regs->nip );
  221. show_regs(regs);
  222. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  223. do_bedbug_breakpoint( regs );
  224. #endif
  225. }
  226. /* Probe an address by reading. If not present, return -1, otherwise
  227. * return 0.
  228. */
  229. int
  230. addr_probe(uint *addr)
  231. {
  232. return 0;
  233. }