]>
Commit | Line | Data |
---|---|---|
25402f5d HL |
1 | /** @file\r |
2 | Default exception handler\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
451b6658 | 5 | Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r |
25402f5d HL |
6 | \r |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
18 | #include <Library/UefiLib.h>\r | |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
22 | #include <Library/PrintLib.h>\r | |
23 | #include <Library/ArmDisassemblerLib.h>\r | |
24 | #include <Library/SerialPortLib.h>\r | |
25 | \r | |
26 | #include <Guid/DebugImageInfoTable.h>\r | |
27 | #include <Protocol/DebugSupport.h>\r | |
28 | #include <Protocol/LoadedImage.h>\r | |
29 | \r | |
25402f5d HL |
30 | STATIC CHAR8 *gExceptionTypeString[] = {\r |
31 | "Synchronous",\r | |
32 | "IRQ",\r | |
33 | "FIQ",\r | |
34 | "SError"\r | |
35 | };\r | |
36 | \r | |
cd82e330 AB |
37 | STATIC BOOLEAN mRecursiveException;\r |
38 | \r | |
25402f5d HL |
39 | CHAR8 *\r |
40 | GetImageName (\r | |
41 | IN UINTN FaultAddress,\r | |
42 | OUT UINTN *ImageBase,\r | |
43 | OUT UINTN *PeCoffSizeOfHeaders\r | |
44 | );\r | |
45 | \r | |
451b6658 OM |
46 | STATIC\r |
47 | VOID\r | |
48 | DescribeInstructionOrDataAbort (\r | |
49 | IN CHAR8 *AbortType,\r | |
50 | IN UINTN Iss\r | |
51 | )\r | |
52 | {\r | |
53 | CHAR8 *AbortCause;\r | |
54 | \r | |
55 | switch (Iss & 0x3f) {\r | |
56 | case 0x0: AbortCause = "Address size fault, zeroth level of translation or translation table base register"; break;\r | |
57 | case 0x1: AbortCause = "Address size fault, first level"; break;\r | |
58 | case 0x2: AbortCause = "Address size fault, second level"; break;\r | |
59 | case 0x3: AbortCause = "Address size fault, third level"; break;\r | |
60 | case 0x4: AbortCause = "Translation fault, zeroth level"; break;\r | |
61 | case 0x5: AbortCause = "Translation fault, first level"; break;\r | |
62 | case 0x6: AbortCause = "Translation fault, second level"; break;\r | |
63 | case 0x7: AbortCause = "Translation fault, third level"; break;\r | |
64 | case 0x9: AbortCause = "Access flag fault, first level"; break;\r | |
65 | case 0xa: AbortCause = "Access flag fault, second level"; break;\r | |
66 | case 0xb: AbortCause = "Access flag fault, third level"; break;\r | |
67 | case 0xd: AbortCause = "Permission fault, first level"; break;\r | |
68 | case 0xe: AbortCause = "Permission fault, second level"; break;\r | |
69 | case 0xf: AbortCause = "Permission fault, third level"; break;\r | |
70 | case 0x10: AbortCause = "Synchronous external abort"; break;\r | |
71 | case 0x18: AbortCause = "Synchronous parity error on memory access"; break;\r | |
72 | case 0x11: AbortCause = "Asynchronous external abort"; break;\r | |
73 | case 0x19: AbortCause = "Asynchronous parity error on memory access"; break;\r | |
74 | case 0x14: AbortCause = "Synchronous external abort on translation table walk, zeroth level"; break;\r | |
75 | case 0x15: AbortCause = "Synchronous external abort on translation table walk, first level"; break;\r | |
76 | case 0x16: AbortCause = "Synchronous external abort on translation table walk, second level"; break;\r | |
77 | case 0x17: AbortCause = "Synchronous external abort on translation table walk, third level"; break;\r | |
78 | case 0x1c: AbortCause = "Synchronous parity error on memory access on translation table walk, zeroth level"; break;\r | |
79 | case 0x1d: AbortCause = "Synchronous parity error on memory access on translation table walk, first level"; break;\r | |
80 | case 0x1e: AbortCause = "Synchronous parity error on memory access on translation table walk, second level"; break;\r | |
81 | case 0x1f: AbortCause = "Synchronous parity error on memory access on translation table walk, third level"; break;\r | |
82 | case 0x21: AbortCause = "Alignment fault"; break;\r | |
83 | case 0x22: AbortCause = "Debug event"; break;\r | |
84 | case 0x30: AbortCause = "TLB conflict abort"; break;\r | |
85 | case 0x33:\r | |
86 | case 0x34: AbortCause = "IMPLEMENTATION DEFINED"; break;\r | |
87 | case 0x35:\r | |
88 | case 0x36: AbortCause = "Domain fault"; break;\r | |
89 | default: AbortCause = ""; break;\r | |
90 | }\r | |
91 | \r | |
92 | DEBUG ((EFI_D_ERROR, "\n%a: %a\n", AbortType, AbortCause));\r | |
93 | }\r | |
94 | \r | |
95 | STATIC\r | |
96 | VOID\r | |
97 | DescribeExceptionSyndrome (\r | |
98 | IN UINT32 Esr\r | |
99 | )\r | |
100 | {\r | |
101 | CHAR8 *Message;\r | |
102 | UINTN Ec;\r | |
103 | UINTN Iss;\r | |
104 | \r | |
105 | Ec = Esr >> 26;\r | |
106 | Iss = Esr & 0x00ffffff;\r | |
107 | \r | |
108 | switch (Ec) {\r | |
109 | case 0x15: Message = "SVC executed in AArch64"; break;\r | |
110 | case 0x20:\r | |
111 | case 0x21: DescribeInstructionOrDataAbort ("Instruction abort", Iss); return;\r | |
112 | case 0x22: Message = "PC alignment fault"; break;\r | |
113 | case 0x23: Message = "SP alignment fault"; break;\r | |
114 | case 0x24:\r | |
115 | case 0x25: DescribeInstructionOrDataAbort ("Data abort", Iss); return;\r | |
116 | default: return;\r | |
117 | }\r | |
118 | \r | |
119 | DEBUG ((EFI_D_ERROR, "\n %a \n", Message));\r | |
120 | }\r | |
121 | \r | |
1f8f4e33 AB |
122 | #ifndef MDEPKG_NDEBUG\r |
123 | STATIC\r | |
124 | CONST CHAR8 *\r | |
125 | BaseName (\r | |
126 | IN CONST CHAR8 *FullName\r | |
127 | )\r | |
128 | {\r | |
129 | CONST CHAR8 *Str;\r | |
130 | \r | |
131 | Str = FullName + AsciiStrLen (FullName);\r | |
132 | \r | |
133 | while (--Str > FullName) {\r | |
134 | if (*Str == '/' || *Str == '\\') {\r | |
135 | return Str + 1;\r | |
136 | }\r | |
137 | }\r | |
138 | return Str;\r | |
139 | }\r | |
140 | #endif\r | |
141 | \r | |
25402f5d HL |
142 | /**\r |
143 | This is the default action to take on an unexpected exception\r | |
144 | \r | |
145 | Since this is exception context don't do anything crazy like try to allcoate memory.\r | |
146 | \r | |
147 | @param ExceptionType Type of the exception\r | |
148 | @param SystemContext Register state at the time of the Exception\r | |
149 | \r | |
150 | **/\r | |
151 | VOID\r | |
152 | DefaultExceptionHandler (\r | |
153 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
154 | IN OUT EFI_SYSTEM_CONTEXT SystemContext\r | |
155 | )\r | |
156 | {\r | |
157 | CHAR8 Buffer[100];\r | |
158 | UINTN CharCount;\r | |
cd82e330 AB |
159 | INT32 Offset;\r |
160 | \r | |
161 | if (mRecursiveException) {\r | |
162 | CharCount = AsciiSPrint (Buffer, sizeof (Buffer),"\nRecursive exception occurred while dumping the CPU state\n");\r | |
163 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
164 | CpuDeadLoop ();\r | |
165 | }\r | |
166 | mRecursiveException = TRUE;\r | |
25402f5d | 167 | \r |
451b6658 | 168 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"\n\n%a Exception at 0x%016lx\n", gExceptionTypeString[ExceptionType], SystemContext.SystemContextAArch64->ELR);\r |
25402f5d HL |
169 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r |
170 | \r | |
171 | DEBUG_CODE_BEGIN ();\r | |
062f9fd2 | 172 | CHAR8 *Pdb, *PrevPdb;\r |
25402f5d HL |
173 | UINTN ImageBase;\r |
174 | UINTN PeCoffSizeOfHeader;\r | |
960d0de8 | 175 | UINT64 *Fp;\r |
062f9fd2 AB |
176 | UINT64 RootFp[2];\r |
177 | UINTN Idx;\r | |
960d0de8 | 178 | \r |
062f9fd2 | 179 | PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);\r |
25402f5d | 180 | if (Pdb != NULL) {\r |
062f9fd2 AB |
181 | DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",\r |
182 | SystemContext.SystemContextAArch64->ELR, ImageBase,\r | |
183 | SystemContext.SystemContextAArch64->ELR - ImageBase, BaseName (Pdb)));\r | |
184 | \r | |
185 | if ((UINT64 *)SystemContext.SystemContextAArch64->FP != 0) {\r | |
186 | Idx = 0;\r | |
187 | \r | |
188 | RootFp[0] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[0];\r | |
189 | RootFp[1] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[1];\r | |
190 | if (RootFp[1] != SystemContext.SystemContextAArch64->LR) {\r | |
191 | RootFp[0] = SystemContext.SystemContextAArch64->FP;\r | |
192 | RootFp[1] = SystemContext.SystemContextAArch64->LR;\r | |
193 | }\r | |
194 | for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {\r | |
195 | Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);\r | |
196 | if (Pdb != NULL) {\r | |
197 | if (Pdb != PrevPdb) {\r | |
198 | Idx++;\r | |
199 | PrevPdb = Pdb;\r | |
200 | }\r | |
201 | DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",\r | |
202 | Fp[1], ImageBase, Fp[1] - ImageBase, Idx, BaseName (Pdb)));\r | |
203 | }\r | |
960d0de8 | 204 | }\r |
062f9fd2 AB |
205 | PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);\r |
206 | DEBUG ((EFI_D_ERROR, "\n[ 0] %a\n", Pdb));\r | |
207 | \r | |
208 | Idx = 0;\r | |
209 | for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {\r | |
210 | Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);\r | |
211 | if (Pdb != NULL && Pdb != PrevPdb) {\r | |
212 | DEBUG ((EFI_D_ERROR, "[% 2d] %a\n", ++Idx, Pdb));\r | |
213 | PrevPdb = Pdb;\r | |
214 | }\r | |
960d0de8 AB |
215 | }\r |
216 | }\r | |
25402f5d HL |
217 | }\r |
218 | DEBUG_CODE_END ();\r | |
219 | \r | |
220 | DEBUG ((EFI_D_ERROR, "\n X0 0x%016lx X1 0x%016lx X2 0x%016lx X3 0x%016lx\n", SystemContext.SystemContextAArch64->X0, SystemContext.SystemContextAArch64->X1, SystemContext.SystemContextAArch64->X2, SystemContext.SystemContextAArch64->X3));\r | |
221 | DEBUG ((EFI_D_ERROR, " X4 0x%016lx X5 0x%016lx X6 0x%016lx X7 0x%016lx\n", SystemContext.SystemContextAArch64->X4, SystemContext.SystemContextAArch64->X5, SystemContext.SystemContextAArch64->X6, SystemContext.SystemContextAArch64->X7));\r | |
222 | DEBUG ((EFI_D_ERROR, " X8 0x%016lx X9 0x%016lx X10 0x%016lx X11 0x%016lx\n", SystemContext.SystemContextAArch64->X8, SystemContext.SystemContextAArch64->X9, SystemContext.SystemContextAArch64->X10, SystemContext.SystemContextAArch64->X11));\r | |
223 | DEBUG ((EFI_D_ERROR, " X12 0x%016lx X13 0x%016lx X14 0x%016lx X15 0x%016lx\n", SystemContext.SystemContextAArch64->X12, SystemContext.SystemContextAArch64->X13, SystemContext.SystemContextAArch64->X14, SystemContext.SystemContextAArch64->X15));\r | |
224 | DEBUG ((EFI_D_ERROR, " X16 0x%016lx X17 0x%016lx X18 0x%016lx X19 0x%016lx\n", SystemContext.SystemContextAArch64->X16, SystemContext.SystemContextAArch64->X17, SystemContext.SystemContextAArch64->X18, SystemContext.SystemContextAArch64->X19));\r | |
225 | DEBUG ((EFI_D_ERROR, " X20 0x%016lx X21 0x%016lx X22 0x%016lx X23 0x%016lx\n", SystemContext.SystemContextAArch64->X20, SystemContext.SystemContextAArch64->X21, SystemContext.SystemContextAArch64->X22, SystemContext.SystemContextAArch64->X23));\r | |
226 | DEBUG ((EFI_D_ERROR, " X24 0x%016lx X25 0x%016lx X26 0x%016lx X27 0x%016lx\n", SystemContext.SystemContextAArch64->X24, SystemContext.SystemContextAArch64->X25, SystemContext.SystemContextAArch64->X26, SystemContext.SystemContextAArch64->X27));\r | |
227 | DEBUG ((EFI_D_ERROR, " X28 0x%016lx FP 0x%016lx LR 0x%016lx \n", SystemContext.SystemContextAArch64->X28, SystemContext.SystemContextAArch64->FP, SystemContext.SystemContextAArch64->LR));\r | |
228 | \r | |
229 | /* We save these as 128bit numbers, but have to print them as two 64bit numbers,\r | |
230 | so swap the 64bit words to correctly represent a 128bit number. */\r | |
231 | DEBUG ((EFI_D_ERROR, "\n V0 0x%016lx %016lx V1 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V0[1], SystemContext.SystemContextAArch64->V0[0], SystemContext.SystemContextAArch64->V1[1], SystemContext.SystemContextAArch64->V1[0]));\r | |
232 | DEBUG ((EFI_D_ERROR, " V2 0x%016lx %016lx V3 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V2[1], SystemContext.SystemContextAArch64->V2[0], SystemContext.SystemContextAArch64->V3[1], SystemContext.SystemContextAArch64->V3[0]));\r | |
233 | DEBUG ((EFI_D_ERROR, " V4 0x%016lx %016lx V5 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V4[1], SystemContext.SystemContextAArch64->V4[0], SystemContext.SystemContextAArch64->V5[1], SystemContext.SystemContextAArch64->V5[0]));\r | |
234 | DEBUG ((EFI_D_ERROR, " V6 0x%016lx %016lx V7 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V6[1], SystemContext.SystemContextAArch64->V6[0], SystemContext.SystemContextAArch64->V7[1], SystemContext.SystemContextAArch64->V7[0]));\r | |
235 | DEBUG ((EFI_D_ERROR, " V8 0x%016lx %016lx V9 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V8[1], SystemContext.SystemContextAArch64->V8[0], SystemContext.SystemContextAArch64->V9[1], SystemContext.SystemContextAArch64->V9[0]));\r | |
236 | DEBUG ((EFI_D_ERROR, " V10 0x%016lx %016lx V11 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V10[1], SystemContext.SystemContextAArch64->V10[0], SystemContext.SystemContextAArch64->V11[1], SystemContext.SystemContextAArch64->V11[0]));\r | |
237 | DEBUG ((EFI_D_ERROR, " V12 0x%016lx %016lx V13 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V12[1], SystemContext.SystemContextAArch64->V12[0], SystemContext.SystemContextAArch64->V13[1], SystemContext.SystemContextAArch64->V13[0]));\r | |
238 | DEBUG ((EFI_D_ERROR, " V14 0x%016lx %016lx V15 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V14[1], SystemContext.SystemContextAArch64->V14[0], SystemContext.SystemContextAArch64->V15[1], SystemContext.SystemContextAArch64->V15[0]));\r | |
239 | DEBUG ((EFI_D_ERROR, " V16 0x%016lx %016lx V17 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V16[1], SystemContext.SystemContextAArch64->V16[0], SystemContext.SystemContextAArch64->V17[1], SystemContext.SystemContextAArch64->V17[0]));\r | |
240 | DEBUG ((EFI_D_ERROR, " V18 0x%016lx %016lx V19 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V18[1], SystemContext.SystemContextAArch64->V18[0], SystemContext.SystemContextAArch64->V19[1], SystemContext.SystemContextAArch64->V19[0]));\r | |
241 | DEBUG ((EFI_D_ERROR, " V20 0x%016lx %016lx V21 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V20[1], SystemContext.SystemContextAArch64->V20[0], SystemContext.SystemContextAArch64->V21[1], SystemContext.SystemContextAArch64->V21[0]));\r | |
242 | DEBUG ((EFI_D_ERROR, " V22 0x%016lx %016lx V23 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V22[1], SystemContext.SystemContextAArch64->V22[0], SystemContext.SystemContextAArch64->V23[1], SystemContext.SystemContextAArch64->V23[0]));\r | |
243 | DEBUG ((EFI_D_ERROR, " V24 0x%016lx %016lx V25 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V24[1], SystemContext.SystemContextAArch64->V24[0], SystemContext.SystemContextAArch64->V25[1], SystemContext.SystemContextAArch64->V25[0]));\r | |
244 | DEBUG ((EFI_D_ERROR, " V26 0x%016lx %016lx V27 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V26[1], SystemContext.SystemContextAArch64->V26[0], SystemContext.SystemContextAArch64->V27[1], SystemContext.SystemContextAArch64->V27[0]));\r | |
245 | DEBUG ((EFI_D_ERROR, " V28 0x%016lx %016lx V29 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V28[1], SystemContext.SystemContextAArch64->V28[0], SystemContext.SystemContextAArch64->V29[1], SystemContext.SystemContextAArch64->V29[0]));\r | |
246 | DEBUG ((EFI_D_ERROR, " V30 0x%016lx %016lx V31 0x%016lx %016lx\n", SystemContext.SystemContextAArch64->V30[1], SystemContext.SystemContextAArch64->V30[0], SystemContext.SystemContextAArch64->V31[1], SystemContext.SystemContextAArch64->V31[0]));\r | |
247 | \r | |
248 | DEBUG ((EFI_D_ERROR, "\n SP 0x%016lx ELR 0x%016lx SPSR 0x%08lx FPSR 0x%08lx\n ESR 0x%08lx FAR 0x%016lx\n", SystemContext.SystemContextAArch64->SP, SystemContext.SystemContextAArch64->ELR, SystemContext.SystemContextAArch64->SPSR, SystemContext.SystemContextAArch64->FPSR, SystemContext.SystemContextAArch64->ESR, SystemContext.SystemContextAArch64->FAR));\r | |
249 | \r | |
250 | DEBUG ((EFI_D_ERROR, "\n ESR : EC 0x%02x IL 0x%x ISS 0x%08x\n", (SystemContext.SystemContextAArch64->ESR & 0xFC000000) >> 26, (SystemContext.SystemContextAArch64->ESR >> 25) & 0x1, SystemContext.SystemContextAArch64->ESR & 0x1FFFFFF ));\r | |
251 | \r | |
451b6658 | 252 | DescribeExceptionSyndrome (SystemContext.SystemContextAArch64->ESR);\r |
1549fb60 | 253 | \r |
cd82e330 AB |
254 | DEBUG ((EFI_D_ERROR, "\nStack dump:\n"));\r |
255 | for (Offset = -256; Offset < 256; Offset += 32) {\r | |
256 | DEBUG ((EFI_D_ERROR, "%c %013lx: %016lx %016lx %016lx %016lx\n",\r | |
257 | Offset == 0 ? '>' : ' ',\r | |
258 | SystemContext.SystemContextAArch64->SP + Offset,\r | |
259 | *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset),\r | |
260 | *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 8),\r | |
261 | *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 16),\r | |
262 | *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 24)));\r | |
263 | }\r | |
264 | \r | |
f9ebccec | 265 | ASSERT (FALSE);\r |
1549fb60 | 266 | CpuDeadLoop ();\r |
25402f5d | 267 | }\r |