traps.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * linux/arch/powerpc/kernel/traps.c
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Modified by Cort Dougan (cort@cs.nmt.edu)
  8. * and Paul Mackerras (paulus@cs.anu.edu.au)
  9. *
  10. * (C) Copyright 2000
  11. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  12. */
  13. /*
  14. * This file handles the architecture-dependent parts of hardware exceptions
  15. */
  16. #include <common.h>
  17. #include <asm/ptrace.h>
  18. #include <command.h>
  19. #include <asm/processor.h>
  20. /* Returns 0 if exception not found and fixup otherwise. */
  21. extern unsigned long search_exception_table(unsigned long);
  22. /* THIS NEEDS CHANGING to use the board info structure.
  23. */
  24. #define END_OF_MEM 0x02000000
  25. /*
  26. * Trap & Exception support
  27. */
  28. static void print_backtrace(unsigned long *sp)
  29. {
  30. int cnt = 0;
  31. unsigned long i;
  32. printf("Call backtrace: ");
  33. while (sp) {
  34. if ((uint)sp > END_OF_MEM)
  35. break;
  36. i = sp[1];
  37. if (cnt++ % 7 == 0)
  38. printf("\n");
  39. printf("%08lX ", i);
  40. if (cnt > 32)
  41. break;
  42. sp = (unsigned long *)*sp;
  43. }
  44. printf("\n");
  45. }
  46. void show_regs(struct pt_regs *regs)
  47. {
  48. int i;
  49. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  50. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  51. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  52. regs->msr, regs->msr & MSR_EE ? 1 : 0,
  53. regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
  54. regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
  55. regs->msr & MSR_DR ? 1 : 0);
  56. printf("\n");
  57. for (i = 0; i < 32; i++) {
  58. if ((i % 8) == 0)
  59. printf("GPR%02d: ", i);
  60. printf("%08lX ", regs->gpr[i]);
  61. if ((i % 8) == 7)
  62. printf("\n");
  63. }
  64. }
  65. static void _exception(int signr, struct pt_regs *regs)
  66. {
  67. show_regs(regs);
  68. print_backtrace((unsigned long *)regs->gpr[1]);
  69. panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
  70. }
  71. void MachineCheckException(struct pt_regs *regs)
  72. {
  73. unsigned long fixup = search_exception_table(regs->nip);
  74. /* Probing PCI using config cycles cause this exception
  75. * when a device is not present. Catch it and return to
  76. * the PCI exception handler.
  77. */
  78. if (fixup != 0) {
  79. regs->nip = fixup;
  80. return;
  81. }
  82. printf("Machine check in kernel mode.\n");
  83. printf("Caused by (from msr): ");
  84. printf("regs %p ", regs);
  85. switch (regs->msr & 0x000F0000) {
  86. case (0x80000000 >> 12):
  87. printf("Machine check signal - probably due to mm fault\n"
  88. "with mmu off\n");
  89. break;
  90. case (0x80000000 >> 13):
  91. printf("Transfer error ack signal\n");
  92. break;
  93. case (0x80000000 >> 14):
  94. printf("Data parity signal\n");
  95. break;
  96. case (0x80000000 >> 15):
  97. printf("Address parity signal\n");
  98. break;
  99. default:
  100. printf("Unknown values in msr\n");
  101. }
  102. show_regs(regs);
  103. print_backtrace((unsigned long *)regs->gpr[1]);
  104. panic("machine check");
  105. }
  106. void AlignmentException(struct pt_regs *regs)
  107. {
  108. show_regs(regs);
  109. print_backtrace((unsigned long *)regs->gpr[1]);
  110. panic("Alignment Exception");
  111. }
  112. void ProgramCheckException(struct pt_regs *regs)
  113. {
  114. show_regs(regs);
  115. print_backtrace((unsigned long *)regs->gpr[1]);
  116. panic("Program Check Exception");
  117. }
  118. void SoftEmuException(struct pt_regs *regs)
  119. {
  120. show_regs(regs);
  121. print_backtrace((unsigned long *)regs->gpr[1]);
  122. panic("Software Emulation Exception");
  123. }
  124. void UnknownException(struct pt_regs *regs)
  125. {
  126. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  127. regs->nip, regs->msr, regs->trap);
  128. _exception(0, regs);
  129. }
  130. void DebugException(struct pt_regs *regs)
  131. {
  132. printf("Debugger trap at @ %lx\n", regs->nip);
  133. show_regs(regs);
  134. }