traps.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 <asm/processor.h>
  35. /* Returns 0 if exception not found and fixup otherwise. */
  36. extern unsigned long search_exception_table(unsigned long);
  37. /* THIS NEEDS CHANGING to use the board info structure.
  38. */
  39. #define END_OF_MEM 0x00400000
  40. /*
  41. * Trap & Exception support
  42. */
  43. void
  44. print_backtrace(unsigned long *sp)
  45. {
  46. int cnt = 0;
  47. unsigned long i;
  48. printf("Call backtrace: ");
  49. while (sp) {
  50. if ((uint)sp > END_OF_MEM)
  51. break;
  52. i = sp[1];
  53. if (cnt++ % 7 == 0)
  54. printf("\n");
  55. printf("%08lX ", i);
  56. if (cnt > 32) break;
  57. sp = (unsigned long *)*sp;
  58. }
  59. printf("\n");
  60. }
  61. void show_regs(struct pt_regs * regs)
  62. {
  63. int i;
  64. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  65. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  66. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  67. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  68. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  69. regs->msr&MSR_IR ? 1 : 0,
  70. regs->msr&MSR_DR ? 1 : 0);
  71. printf("\n");
  72. for (i = 0; i < 32; i++) {
  73. if ((i % 8) == 0)
  74. {
  75. printf("GPR%02d: ", i);
  76. }
  77. printf("%08lX ", regs->gpr[i]);
  78. if ((i % 8) == 7)
  79. {
  80. printf("\n");
  81. }
  82. }
  83. }
  84. void
  85. _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
  92. MachineCheckException(struct pt_regs *regs)
  93. {
  94. unsigned long fixup;
  95. /* Probing PCI using config cycles cause this exception
  96. * when a device is not present. Catch it and return to
  97. * the PCI exception handler.
  98. */
  99. if ((fixup = search_exception_table(regs->nip)) != 0) {
  100. regs->nip = fixup;
  101. return;
  102. }
  103. printf("Machine check in kernel mode.\n");
  104. printf("Caused by (from msr): ");
  105. printf("regs %p ",regs);
  106. switch( regs->msr & 0x000F0000) {
  107. case (0x80000000>>12):
  108. printf("Machine check signal - probably due to mm fault\n"
  109. "with mmu off\n");
  110. break;
  111. case (0x80000000>>13):
  112. printf("Transfer error ack signal\n");
  113. break;
  114. case (0x80000000>>14):
  115. printf("Data parity signal\n");
  116. break;
  117. case (0x80000000>>15):
  118. printf("Address parity signal\n");
  119. break;
  120. default:
  121. printf("Unknown values in msr\n");
  122. }
  123. show_regs(regs);
  124. print_backtrace((unsigned long *)regs->gpr[1]);
  125. panic("machine check");
  126. }
  127. void
  128. AlignmentException(struct pt_regs *regs)
  129. {
  130. show_regs(regs);
  131. print_backtrace((unsigned long *)regs->gpr[1]);
  132. panic("Alignment Exception");
  133. }
  134. void
  135. ProgramCheckException(struct pt_regs *regs)
  136. {
  137. show_regs(regs);
  138. print_backtrace((unsigned long *)regs->gpr[1]);
  139. panic("Program Check Exception");
  140. }
  141. void
  142. SoftEmuException(struct pt_regs *regs)
  143. {
  144. show_regs(regs);
  145. print_backtrace((unsigned long *)regs->gpr[1]);
  146. panic("Software Emulation Exception");
  147. }
  148. void
  149. UnknownException(struct pt_regs *regs)
  150. {
  151. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  152. regs->nip, regs->msr, regs->trap);
  153. _exception(0, regs);
  154. }
  155. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  156. extern void do_bedbug_breakpoint(struct pt_regs *);
  157. #endif
  158. void
  159. DebugException(struct pt_regs *regs)
  160. {
  161. printf("Debugger trap at @ %lx\n", regs->nip );
  162. show_regs(regs);
  163. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  164. do_bedbug_breakpoint( regs );
  165. #endif
  166. }
  167. /* Probe an address by reading. If not present, return -1, otherwise
  168. * return 0.
  169. */
  170. int
  171. addr_probe(uint *addr)
  172. {
  173. #if 0
  174. int retval;
  175. __asm__ __volatile__( \
  176. "1: lwz %0,0(%1)\n" \
  177. " eieio\n" \
  178. " li %0,0\n" \
  179. "2:\n" \
  180. ".section .fixup,\"ax\"\n" \
  181. "3: li %0,-1\n" \
  182. " b 2b\n" \
  183. ".section __ex_table,\"a\"\n" \
  184. " .align 2\n" \
  185. " .long 1b,3b\n" \
  186. ".text" \
  187. : "=r" (retval) : "r"(addr));
  188. return (retval);
  189. #endif
  190. return 0;
  191. }