traps.c 5.7 KB

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