30#define MAX_PRINT_CHARS 100
36#define CPSR_STRING_SIZE 32
87 for (Index = 0; mCpsrChar[Index].BIT != 0; Index++, Str++) {
88 *Str = mCpsrChar[Index].Char;
89 if ((Cpsr & (1 << mCpsrChar[Index].BIT)) != 0) {
98 switch (Cpsr & 0x1f) {
132 AsciiStrCatS (Str, CPSR_STRING_SIZE - (Str - ReturnStr), ModeStr);
143 case 0x01: FaultSource =
"Alignment fault";
145 case 0x02: FaultSource =
"Debug event fault";
147 case 0x03: FaultSource =
"Access Flag fault on Section";
149 case 0x04: FaultSource =
"Cache maintenance operation fault[2]";
151 case 0x05: FaultSource =
"Translation fault on Section";
153 case 0x06: FaultSource =
"Access Flag fault on Page";
155 case 0x07: FaultSource =
"Translation fault on Page";
157 case 0x08: FaultSource =
"Precise External Abort";
159 case 0x09: FaultSource =
"Domain fault on Section";
161 case 0x0b: FaultSource =
"Domain fault on Page";
163 case 0x0c: FaultSource =
"External abort on translation, first level";
165 case 0x0d: FaultSource =
"Permission fault on Section";
167 case 0x0e: FaultSource =
"External abort on translation, second level";
169 case 0x0f: FaultSource =
"Permission fault on Page";
171 case 0x16: FaultSource =
"Imprecise External Abort";
173 default: FaultSource =
"No function";
180STATIC CHAR8 *gExceptionTypeString[] = {
207 CHAR8 Buffer[MAX_PRINT_CHARS];
208 CHAR16 UnicodeBuffer[MAX_PRINT_CHARS];
220 "\n%a Exception PC at 0x%08x CPSR 0x%08x ",
221 gExceptionTypeString[ExceptionType],
222 SystemContext.SystemContextArm->PC,
223 SystemContext.SystemContextArm->CPSR
234 UINT32 PeCoffSizeOfHeader;
236 CHAR8 CpsrStr[CPSR_STRING_SIZE];
242 CpsrString (SystemContext.SystemContextArm->CPSR, CpsrStr);
243 DEBUG ((DEBUG_ERROR,
"%a\n", CpsrStr));
245 Pdb =
GetImageName (SystemContext.SystemContextArm->PC, &ImageBase, &PeCoffSizeOfHeader);
246 Offset = SystemContext.SystemContextArm->PC - ImageBase;
248 DEBUG ((DEBUG_ERROR,
"%a\n", Pdb));
258 DEBUG ((DEBUG_ERROR,
"loaded at 0x%08x (PE/COFF offset) 0x%x (ELF or Mach-O offset) 0x%x", ImageBase, Offset, Offset - PeCoffSizeOfHeader));
261 DisAsm = (UINT8 *)(
UINTN)SystemContext.SystemContextArm->PC;
263 DisassembleInstruction (&DisAsm, (SystemContext.SystemContextArm->CPSR & BIT5) == BIT5,
TRUE, &ItBlock, Buffer, sizeof (Buffer));
264 DEBUG ((DEBUG_ERROR,
"\n%a", Buffer));
266 switch (ExceptionType) {
267 case EXCEPT_ARM_UNDEFINED_INSTRUCTION:
268 case EXCEPT_ARM_SOFTWARE_INTERRUPT:
269 case EXCEPT_ARM_PREFETCH_ABORT:
270 case EXCEPT_ARM_DATA_ABORT:
272 PcAdjust = (
UINTN)DisAsm - SystemContext.SystemContextArm->PC;
281 DEBUG ((DEBUG_ERROR,
"\n R0 0x%08x R1 0x%08x R2 0x%08x R3 0x%08x\n", SystemContext.SystemContextArm->R0, SystemContext.SystemContextArm->R1, SystemContext.SystemContextArm->R2, SystemContext.SystemContextArm->R3));
282 DEBUG ((DEBUG_ERROR,
" R4 0x%08x R5 0x%08x R6 0x%08x R7 0x%08x\n", SystemContext.SystemContextArm->R4, SystemContext.SystemContextArm->R5, SystemContext.SystemContextArm->R6, SystemContext.SystemContextArm->R7));
283 DEBUG ((DEBUG_ERROR,
" R8 0x%08x R9 0x%08x R10 0x%08x R11 0x%08x\n", SystemContext.SystemContextArm->R8, SystemContext.SystemContextArm->R9, SystemContext.SystemContextArm->R10, SystemContext.SystemContextArm->R11));
284 DEBUG ((DEBUG_ERROR,
" R12 0x%08x SP 0x%08x LR 0x%08x PC 0x%08x\n", SystemContext.SystemContextArm->R12, SystemContext.SystemContextArm->SP, SystemContext.SystemContextArm->LR, SystemContext.SystemContextArm->PC));
285 DEBUG ((DEBUG_ERROR,
"DFSR 0x%08x DFAR 0x%08x IFSR 0x%08x IFAR 0x%08x\n", SystemContext.SystemContextArm->DFSR, SystemContext.SystemContextArm->DFAR, SystemContext.SystemContextArm->IFSR, SystemContext.SystemContextArm->IFAR));
288 DfsrStatus = (SystemContext.SystemContextArm->DFSR & 0xf) | ((SystemContext.SystemContextArm->DFSR >> 6) & 0x10);
289 DfsrWrite = (SystemContext.SystemContextArm->DFSR & BIT11) != 0;
290 if (DfsrStatus != 0x00) {
291 DEBUG ((DEBUG_ERROR,
" %a: %a 0x%08x\n", FaultStatusToString (DfsrStatus), DfsrWrite ?
"write to" :
"read from", SystemContext.SystemContextArm->DFAR));
294 IfsrStatus = (SystemContext.SystemContextArm->IFSR & 0xf) | ((SystemContext.SystemContextArm->IFSR >> 6) & 0x10);
295 if (IfsrStatus != 0) {
296 DEBUG ((DEBUG_ERROR,
" Instruction %a at 0x%08x\n", FaultStatusToString (SystemContext.SystemContextArm->IFSR & 0xf), SystemContext.SystemContextArm->IFAR));
299 DEBUG ((DEBUG_ERROR,
"\n"));
313 SystemContext.SystemContextArm->DFSR = 0;
314 SystemContext.SystemContextArm->IFSR = 0;
317 SystemContext.SystemContextArm->PC += PcAdjust;
CHAR8 * GetImageName(IN UINTN FaultAddress, OUT UINTN *ImageBase, OUT UINTN *PeCoffSizeOfHeaders)
VOID DefaultExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
VOID CpsrString(IN UINT32 Cpsr, OUT CHAR8 *ReturnStr)
VOID DisassembleInstruction(IN UINT8 **OpCodePtr, IN BOOLEAN Thumb, IN BOOLEAN Extended, IN OUT UINT32 *ItBlock, OUT CHAR8 *Buf, OUT UINTN Size)
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI AsciiStrCatS(IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
VOID EFIAPI CpuDeadLoop(VOID)
UINTN EFIAPI UnicodeSPrintAsciiFormat(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut