]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerUefi.c
UefiCpuPkg/UefiCpuPkg.uni: Add PcdCpuNumberOfReservedVariableMtrrs
[mirror_edk2.git] / ArmPkg / Library / DefaultExceptionHandlerLib / DefaultExceptionHandlerUefi.c
CommitLineData
619b3998 1/** @file\r
2\r
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
4\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16#include <Library/PeCoffGetEntryPointLib.h>\r
17#include <Library/UefiLib.h>\r
18\r
19#include <Guid/DebugImageInfoTable.h>\r
20\r
21extern EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader;\r
22\r
23/**\r
24 The constructor function caches EFI Debug table information for use in the exception handler.\r
25\r
26\r
27 @param ImageHandle The firmware allocated handle for the EFI image.\r
28 @param SystemTable A pointer to the EFI System Table.\r
29\r
30 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
31\r
32**/\r
33EFI_STATUS\r
34EFIAPI\r
35DefaultExceptionHandlerConstructor (\r
36 IN EFI_HANDLE ImageHandle,\r
37 IN EFI_SYSTEM_TABLE *SystemTable\r
38 )\r
39{\r
40 EFI_STATUS Status;\r
41\r
42 Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader);\r
43 if (EFI_ERROR (Status)) {\r
44 gDebugImageTableHeader = NULL;\r
45 }\r
46 return Status;\r
47}\r
48\r
49/**\r
50 Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image\r
51 it came from. As long as the PE/COFF image contains a debug directory entry a\r
52 string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF\r
53 image. Microsoft tools contain a pointer to the PDB file that contains the debug information.\r
54\r
55 @param FaultAddress Address to find PE/COFF image for.\r
56 @param ImageBase Return load address of found image\r
57 @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found\r
58\r
59 @retval NULL FaultAddress not in a loaded PE/COFF image.\r
60 @retval Path and file name of PE/COFF image.\r
61\r
62**/\r
63CHAR8 *\r
64GetImageName (\r
c63626b7 65 IN UINTN FaultAddress,\r
66 OUT UINTN *ImageBase,\r
67 OUT UINTN *PeCoffSizeOfHeaders\r
619b3998 68 )\r
69{\r
70 EFI_DEBUG_IMAGE_INFO *DebugTable;\r
71 UINTN Entry;\r
72 CHAR8 *Address;\r
73\r
74 DebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;\r
75 if (DebugTable == NULL) {\r
76 return NULL;\r
77 }\r
78\r
79 Address = (CHAR8 *)(UINTN)FaultAddress;\r
80 for (Entry = 0; Entry < gDebugImageTableHeader->TableSize; Entry++, DebugTable++) {\r
81 if (DebugTable->NormalImage != NULL) {\r
82 if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&\r
83 (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r
84 if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&\r
85 (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize))) {\r
c63626b7 86 *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;\r
619b3998 87 *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);\r
88 return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);\r
89 }\r
90 }\r
91 }\r
92 }\r
93\r
94 return NULL;\r
95}\r
c63626b7 96\r