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