traps.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. #define END_OF_MEM 0x00400000
  44. static __inline__ void set_tsr(unsigned long val)
  45. {
  46. #if defined(CONFIG_440)
  47. asm volatile("mtspr 0x150, %0" : : "r" (val));
  48. #else
  49. asm volatile("mttsr %0" : : "r" (val));
  50. #endif
  51. }
  52. static __inline__ unsigned long get_esr(void)
  53. {
  54. unsigned long val;
  55. #if defined(CONFIG_440)
  56. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  57. #else
  58. asm volatile("mfesr %0" : "=r" (val) :);
  59. #endif
  60. return val;
  61. }
  62. #define ESR_MCI 0x80000000
  63. #define ESR_PIL 0x08000000
  64. #define ESR_PPR 0x04000000
  65. #define ESR_PTR 0x02000000
  66. #define ESR_DST 0x00800000
  67. #define ESR_DIZ 0x00400000
  68. #define ESR_U0F 0x00008000
  69. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  70. extern void do_bedbug_breakpoint(struct pt_regs *);
  71. #endif
  72. /*
  73. * Trap & Exception support
  74. */
  75. void
  76. print_backtrace(unsigned long *sp)
  77. {
  78. int cnt = 0;
  79. unsigned long i;
  80. printf("Call backtrace: ");
  81. while (sp) {
  82. if ((uint)sp > END_OF_MEM)
  83. break;
  84. i = sp[1];
  85. if (cnt++ % 7 == 0)
  86. printf("\n");
  87. printf("%08lX ", i);
  88. if (cnt > 32) break;
  89. sp = (unsigned long *)*sp;
  90. }
  91. printf("\n");
  92. }
  93. void show_regs(struct pt_regs * regs)
  94. {
  95. int i;
  96. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  97. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  98. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  99. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  100. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  101. regs->msr&MSR_IR ? 1 : 0,
  102. regs->msr&MSR_DR ? 1 : 0);
  103. printf("\n");
  104. for (i = 0; i < 32; i++) {
  105. if ((i % 8) == 0)
  106. {
  107. printf("GPR%02d: ", i);
  108. }
  109. printf("%08lX ", regs->gpr[i]);
  110. if ((i % 8) == 7)
  111. {
  112. printf("\n");
  113. }
  114. }
  115. }
  116. void
  117. _exception(int signr, struct pt_regs *regs)
  118. {
  119. show_regs(regs);
  120. print_backtrace((unsigned long *)regs->gpr[1]);
  121. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  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 & 0x000F0000) {
  143. case (0x80000000>>12):
  144. printf("Machine check signal - probably due to mm fault\n"
  145. "with mmu off\n");
  146. break;
  147. case (0x80000000>>13):
  148. printf("Transfer error ack signal\n");
  149. break;
  150. case (0x80000000>>14):
  151. printf("Data parity signal\n");
  152. break;
  153. case (0x80000000>>15):
  154. printf("Address parity signal\n");
  155. break;
  156. default:
  157. printf("Unknown values in msr\n");
  158. }
  159. show_regs(regs);
  160. print_backtrace((unsigned long *)regs->gpr[1]);
  161. panic("machine check");
  162. }
  163. void
  164. AlignmentException(struct pt_regs *regs)
  165. {
  166. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  167. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  168. return;
  169. #endif
  170. show_regs(regs);
  171. print_backtrace((unsigned long *)regs->gpr[1]);
  172. panic("Alignment Exception");
  173. }
  174. void
  175. ProgramCheckException(struct pt_regs *regs)
  176. {
  177. long esr_val;
  178. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  179. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  180. return;
  181. #endif
  182. show_regs(regs);
  183. esr_val = get_esr();
  184. if( esr_val & ESR_PIL )
  185. printf( "** Illegal Instruction **\n" );
  186. else if( esr_val & ESR_PPR )
  187. printf( "** Privileged Instruction **\n" );
  188. else if( esr_val & ESR_PTR )
  189. printf( "** Trap Instruction **\n" );
  190. print_backtrace((unsigned long *)regs->gpr[1]);
  191. panic("Program Check Exception");
  192. }
  193. void
  194. PITException(struct pt_regs *regs)
  195. {
  196. /*
  197. * Reset PIT interrupt
  198. */
  199. set_tsr(0x08000000);
  200. /*
  201. * Call timer_interrupt routine in interrupts.c
  202. */
  203. timer_interrupt(NULL);
  204. }
  205. void
  206. UnknownException(struct pt_regs *regs)
  207. {
  208. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  209. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  210. return;
  211. #endif
  212. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  213. regs->nip, regs->msr, regs->trap);
  214. _exception(0, regs);
  215. }
  216. void
  217. DebugException(struct pt_regs *regs)
  218. {
  219. printf("Debugger trap at @ %lx\n", regs->nip );
  220. show_regs(regs);
  221. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  222. do_bedbug_breakpoint( regs );
  223. #endif
  224. }
  225. /* Probe an address by reading. If not present, return -1, otherwise
  226. * return 0.
  227. */
  228. int
  229. addr_probe(uint *addr)
  230. {
  231. #if 0
  232. int retval;
  233. __asm__ __volatile__( \
  234. "1: lwz %0,0(%1)\n" \
  235. " eieio\n" \
  236. " li %0,0\n" \
  237. "2:\n" \
  238. ".section .fixup,\"ax\"\n" \
  239. "3: li %0,-1\n" \
  240. " b 2b\n" \
  241. ".section __ex_table,\"a\"\n" \
  242. " .align 2\n" \
  243. " .long 1b,3b\n" \
  244. ".text" \
  245. : "=r" (retval) : "r"(addr));
  246. return (retval);
  247. #endif
  248. return 0;
  249. }