traps.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <command.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 0x02000000
  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)
  40. break;
  41. sp = (unsigned long *)*sp;
  42. }
  43. printf("\n");
  44. }
  45. void show_regs(struct pt_regs *regs)
  46. {
  47. int i;
  48. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  49. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  50. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  51. regs->msr, regs->msr & MSR_EE ? 1 : 0,
  52. regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
  53. regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
  54. regs->msr & MSR_DR ? 1 : 0);
  55. printf("\n");
  56. for (i = 0; i < 32; i++) {
  57. if ((i % 8) == 0)
  58. printf("GPR%02d: ", i);
  59. printf("%08lX ", regs->gpr[i]);
  60. if ((i % 8) == 7)
  61. printf("\n");
  62. }
  63. }
  64. static void _exception(int signr, struct pt_regs *regs)
  65. {
  66. show_regs(regs);
  67. print_backtrace((unsigned long *)regs->gpr[1]);
  68. panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
  69. }
  70. void MachineCheckException(struct pt_regs *regs)
  71. {
  72. unsigned long fixup = search_exception_table(regs->nip);
  73. /* Probing PCI using config cycles cause this exception
  74. * when a device is not present. Catch it and return to
  75. * the PCI exception handler.
  76. */
  77. if (fixup != 0) {
  78. regs->nip = fixup;
  79. return;
  80. }
  81. printf("Machine check in kernel mode.\n");
  82. printf("Caused by (from msr): ");
  83. printf("regs %p ", regs);
  84. switch (regs->msr & 0x000F0000) {
  85. case (0x80000000 >> 12):
  86. printf("Machine check signal - probably due to mm fault\n"
  87. "with mmu off\n");
  88. break;
  89. case (0x80000000 >> 13):
  90. printf("Transfer error ack signal\n");
  91. break;
  92. case (0x80000000 >> 14):
  93. printf("Data parity signal\n");
  94. break;
  95. case (0x80000000 >> 15):
  96. printf("Address parity signal\n");
  97. break;
  98. default:
  99. printf("Unknown values in msr\n");
  100. }
  101. show_regs(regs);
  102. print_backtrace((unsigned long *)regs->gpr[1]);
  103. panic("machine check");
  104. }
  105. void AlignmentException(struct pt_regs *regs)
  106. {
  107. show_regs(regs);
  108. print_backtrace((unsigned long *)regs->gpr[1]);
  109. panic("Alignment Exception");
  110. }
  111. void ProgramCheckException(struct pt_regs *regs)
  112. {
  113. show_regs(regs);
  114. print_backtrace((unsigned long *)regs->gpr[1]);
  115. panic("Program Check Exception");
  116. }
  117. void SoftEmuException(struct pt_regs *regs)
  118. {
  119. show_regs(regs);
  120. print_backtrace((unsigned long *)regs->gpr[1]);
  121. panic("Software Emulation Exception");
  122. }
  123. void UnknownException(struct pt_regs *regs)
  124. {
  125. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  126. regs->nip, regs->msr, regs->trap);
  127. _exception(0, regs);
  128. }
  129. void DebugException(struct pt_regs *regs)
  130. {
  131. printf("Debugger trap at @ %lx\n", regs->nip);
  132. show_regs(regs);
  133. }