From 619b3998880e3c28c46d3a20bbbfa879e08b3579 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Fri, 28 Sep 2012 09:55:48 +0000 Subject: [PATCH] ArmPkg/DefaultExceptionHandlerLib: Added support to the BASE-type library This library could be used before the UEFI phases to expose the CPU state when an unexpected exception interrupt the firmware. Signed-off-by: Olivier Martin git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13767 6f19259b-4bc3-4df7-8a09-765794883524 --- .../ArmDisassemblerLib/ArmDisassemblerLib.inf | 1 - .../DebugAgentSymbolsBaseLib.c | 3 +- .../DefaultExceptionHandler.c | 84 +--------------- .../DefaultExceptionHandlerBase.c | 35 +++++++ .../DefaultExceptionHandlerLib.inf | 2 +- .../DefaultExceptionHandlerLibBase.inf | 37 ++++++++ .../DefaultExceptionHandlerUefi.c | 95 +++++++++++++++++++ .../ArmRealViewEbPkg/ArmRealViewEb.dsc.inc | 1 + .../ArmVExpressPkg/ArmVExpress.dsc.inc | 1 + 9 files changed, 176 insertions(+), 83 deletions(-) create mode 100644 ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerBase.c create mode 100644 ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf create mode 100644 ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c diff --git a/ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf b/ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf index c63a4dfe2e..56ba2d2f39 100644 --- a/ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf +++ b/ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf @@ -31,7 +31,6 @@ ArmPkg/ArmPkg.dec [LibraryClasses] - UefiLib BaseLib PrintLib DebugLib diff --git a/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c b/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c index 5d986779ee..c27d8e7dd3 100644 --- a/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c +++ b/ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.c @@ -285,9 +285,8 @@ InitializeDebugAgent ( // Now we've got UART, make the check: // - The Vector table must be 32-byte aligned - //TODO: Define a macro for the ARM Exception Table ASSERT(((UINT32)DebugAgentVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0); - ArmWriteVBar (DebugAgentVectorTable); + ArmWriteVBar ((UINT32)DebugAgentVectorTable); // We use InitFlag to know if DebugAgent has been intialized from // Sec (DEBUG_AGENT_INIT_PREMEM_SEC) or PrePi (DEBUG_AGENT_INIT_POSTMEM_SEC) diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandler.c index 94aacf83a4..bb29b95da2 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandler.c @@ -2,6 +2,7 @@ Default exception handler Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -14,7 +15,6 @@ **/ #include -#include #include #include #include @@ -23,67 +23,23 @@ #include #include -#include -#include +#include +#include EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL; - typedef struct { UINT32 BIT; CHAR8 Char; } CPSR_CHAR; - -/** - Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image - it came from. As long as the PE/COFF image contains a debug directory entry a - string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF - image. Microsoft tools contain a pointer to the PDB file that contains the debug information. - - @param FaultAddress Address to find PE/COFF image for. - @param ImageBase Return load address of found image - @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found - - @retval NULL FaultAddress not in a loaded PE/COFF image. - @retval Path and file name of PE/COFF image. - -**/ CHAR8 * GetImageName ( IN UINT32 FaultAddress, OUT UINT32 *ImageBase, OUT UINT32 *PeCoffSizeOfHeaders - ) -{ - EFI_DEBUG_IMAGE_INFO *DebugTable; - UINTN Entry; - CHAR8 *Address; - - DebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable; - if (DebugTable == NULL) { - return NULL; - } - - Address = (CHAR8 *)(UINTN)FaultAddress; - for (Entry = 0; Entry < gDebugImageTableHeader->TableSize; Entry++, DebugTable++) { - if (DebugTable->NormalImage != NULL) { - if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && - (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) { - if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) && - (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize))) { - *ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase; - *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase); - return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase); - } - } - } - } - - return NULL; -} - + ); /** Convert the Current Program Status Register (CPSR) to a string. The string is @@ -198,7 +154,7 @@ FaultStatusToString ( STATIC CHAR8 *gExceptionTypeString[] = { "Reset", "Undefined OpCode", - "SWI", + "SVC", "Prefetch Abort", "Data Abort", "Undefined", @@ -310,33 +266,3 @@ DefaultExceptionHandler ( // If some one is stepping past the exception handler adjust the PC to point to the next instruction SystemContext.SystemContextArm->PC += PcAdjust; } - - - - -/** - The constructor function caches EFI Debug table information for use in the exception handler. - - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -DefaultExceptionHandlerConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - - - Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader); - if (EFI_ERROR (Status)) { - gDebugImageTableHeader = NULL; - } - return Status; -} diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerBase.c b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerBase.c new file mode 100644 index 0000000000..e68617e1e7 --- /dev/null +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerBase.c @@ -0,0 +1,35 @@ +/** @file + + Copyright (c) 2012, ARM Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +/** + + @param FaultAddress Address to find PE/COFF image for. + @param ImageBase Return load address of found image + @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found + + @retval NULL FaultAddress not in a loaded PE/COFF image. + @retval Path and file name of PE/COFF image. + +**/ +CHAR8 * +GetImageName ( + IN UINT32 FaultAddress, + OUT UINT32 *ImageBase, + OUT UINT32 *PeCoffSizeOfHeaders + ) +{ + return NULL; +} diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf index 2388c5c015..120e2de217 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf @@ -1,5 +1,4 @@ #/** @file -# Semihosting serail port lib # # Copyright (c) 2008, Apple Inc. All rights reserved.
# @@ -25,6 +24,7 @@ [Sources.common] DefaultExceptionHandler.c + DefaultExceptionHandlerUefi.c [Packages] MdePkg/MdePkg.dec diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf new file mode 100644 index 0000000000..f51d3a0ef5 --- /dev/null +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf @@ -0,0 +1,37 @@ +#/** @file +# +# Copyright (c) 2012, ARM Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DefaultExceptionHandlerBaseLib + FILE_GUID = 3d5261d5-5eb7-4559-98e7-475aa9d0dc42 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = DefaultExceptionHandlerLib + +[Sources.common] + DefaultExceptionHandler.c + DefaultExceptionHandlerBase.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + BaseLib + PrintLib + DebugLib + PeCoffGetEntryPointLib + ArmDisassemblerLib + SerialPortLib diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c new file mode 100644 index 0000000000..8543ade99c --- /dev/null +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c @@ -0,0 +1,95 @@ +/** @file + + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include + +#include + +extern EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader; + +/** + The constructor function caches EFI Debug table information for use in the exception handler. + + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +DefaultExceptionHandlerConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader); + if (EFI_ERROR (Status)) { + gDebugImageTableHeader = NULL; + } + return Status; +} + +/** + Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image + it came from. As long as the PE/COFF image contains a debug directory entry a + string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF + image. Microsoft tools contain a pointer to the PDB file that contains the debug information. + + @param FaultAddress Address to find PE/COFF image for. + @param ImageBase Return load address of found image + @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found + + @retval NULL FaultAddress not in a loaded PE/COFF image. + @retval Path and file name of PE/COFF image. + +**/ +CHAR8 * +GetImageName ( + IN UINT32 FaultAddress, + OUT UINT32 *ImageBase, + OUT UINT32 *PeCoffSizeOfHeaders + ) +{ + EFI_DEBUG_IMAGE_INFO *DebugTable; + UINTN Entry; + CHAR8 *Address; + + DebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable; + if (DebugTable == NULL) { + return NULL; + } + + Address = (CHAR8 *)(UINTN)FaultAddress; + for (Entry = 0; Entry < gDebugImageTableHeader->TableSize; Entry++, DebugTable++) { + if (DebugTable->NormalImage != NULL) { + if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && + (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) { + if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) && + (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize))) { + *ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase; + *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase); + return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase); + } + } + } + } + + return NULL; +} diff --git a/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc b/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc index 9d35b6fc6a..27413fe5a3 100644 --- a/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc +++ b/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc @@ -106,6 +106,7 @@ ArmTrustedMonitorLib|ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf + DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf # Uncomment to turn on GDB stub in SEC. #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf diff --git a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc index 59c821a2f0..fdff40da63 100644 --- a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc +++ b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc @@ -107,6 +107,7 @@ ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf + DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf !ifdef $(EDK2_SKIP_PEICORE) PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf -- 2.39.2