traps.c 5.6 KB

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