traps.c 4.1 KB

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