X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmPkg%2FLibrary%2FDefaultExceptionHandlerLib%2FAArch64%2FDefaultExceptionHandler.c;h=2f9c2ede37c1d149dfceb3b3e85f477665f7f1fa;hp=49d36ed69329878ecffb6d1f9cdbf2b455fd8d10;hb=062f9fd2cfaad09f6dd0e302094bc030827eb706;hpb=451b665890f69244f213d7aba4450394a21bc60c diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c index 49d36ed693..2f9c2ede37 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c @@ -27,8 +27,6 @@ #include #include -EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL; - STATIC CHAR8 *gExceptionTypeString[] = { "Synchronous", "IRQ", @@ -36,6 +34,8 @@ STATIC CHAR8 *gExceptionTypeString[] = { "SError" }; +STATIC BOOLEAN mRecursiveException; + CHAR8 * GetImageName ( IN UINTN FaultAddress, @@ -119,6 +119,26 @@ DescribeExceptionSyndrome ( DEBUG ((EFI_D_ERROR, "\n %a \n", Message)); } +#ifndef MDEPKG_NDEBUG +STATIC +CONST CHAR8 * +BaseName ( + IN CONST CHAR8 *FullName + ) +{ + CONST CHAR8 *Str; + + Str = FullName + AsciiStrLen (FullName); + + while (--Str > FullName) { + if (*Str == '/' || *Str == '\\') { + return Str + 1; + } + } + return Str; +} +#endif + /** This is the default action to take on an unexpected exception @@ -136,17 +156,64 @@ DefaultExceptionHandler ( { CHAR8 Buffer[100]; UINTN CharCount; + INT32 Offset; + + if (mRecursiveException) { + CharCount = AsciiSPrint (Buffer, sizeof (Buffer),"\nRecursive exception occurred while dumping the CPU state\n"); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + CpuDeadLoop (); + } + mRecursiveException = TRUE; CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"\n\n%a Exception at 0x%016lx\n", gExceptionTypeString[ExceptionType], SystemContext.SystemContextAArch64->ELR); SerialPortWrite ((UINT8 *) Buffer, CharCount); DEBUG_CODE_BEGIN (); - CHAR8 *Pdb; + CHAR8 *Pdb, *PrevPdb; UINTN ImageBase; UINTN PeCoffSizeOfHeader; - Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader); + UINT64 *Fp; + UINT64 RootFp[2]; + UINTN Idx; + + PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader); if (Pdb != NULL) { - DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb, ImageBase)); + DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n", + SystemContext.SystemContextAArch64->ELR, ImageBase, + SystemContext.SystemContextAArch64->ELR - ImageBase, BaseName (Pdb))); + + if ((UINT64 *)SystemContext.SystemContextAArch64->FP != 0) { + Idx = 0; + + RootFp[0] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[0]; + RootFp[1] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[1]; + if (RootFp[1] != SystemContext.SystemContextAArch64->LR) { + RootFp[0] = SystemContext.SystemContextAArch64->FP; + RootFp[1] = SystemContext.SystemContextAArch64->LR; + } + for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) { + Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader); + if (Pdb != NULL) { + if (Pdb != PrevPdb) { + Idx++; + PrevPdb = Pdb; + } + DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n", + Fp[1], ImageBase, Fp[1] - ImageBase, Idx, BaseName (Pdb))); + } + } + PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader); + DEBUG ((EFI_D_ERROR, "\n[ 0] %a\n", Pdb)); + + Idx = 0; + for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) { + Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader); + if (Pdb != NULL && Pdb != PrevPdb) { + DEBUG ((EFI_D_ERROR, "[% 2d] %a\n", ++Idx, Pdb)); + PrevPdb = Pdb; + } + } + } } DEBUG_CODE_END (); @@ -183,5 +250,18 @@ DefaultExceptionHandler ( 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 )); DescribeExceptionSyndrome (SystemContext.SystemContextAArch64->ESR); + + DEBUG ((EFI_D_ERROR, "\nStack dump:\n")); + for (Offset = -256; Offset < 256; Offset += 32) { + DEBUG ((EFI_D_ERROR, "%c %013lx: %016lx %016lx %016lx %016lx\n", + Offset == 0 ? '>' : ' ', + SystemContext.SystemContextAArch64->SP + Offset, + *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset), + *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 8), + *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 16), + *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 24))); + } + ASSERT (FALSE); + CpuDeadLoop (); }