]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Library / DebugPeCoffExtraActionLib / DebugPeCoffExtraActionLib.c
1 /**@file
2
3 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <PiDxe.h>
12 #include <Library/PeCoffLib.h>
13
14 #include <Library/BaseLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/PeCoffExtraActionLib.h>
18 #include <Library/PrintLib.h>
19
20 /**
21 If the build is done on cygwin the paths are cygpaths.
22 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
23 them to work with RVD commands
24
25 @param Name Path to convert if needed
26
27 **/
28 CHAR8 *
29 DeCygwinPathIfNeeded (
30 IN CHAR8 *Name,
31 IN CHAR8 *Temp,
32 IN UINTN Size
33 )
34 {
35 CHAR8 *Ptr;
36 UINTN Index;
37 UINTN Index2;
38
39 Ptr = AsciiStrStr (Name, "/cygdrive/");
40 if (Ptr == NULL) {
41 return Name;
42 }
43
44 for (Index = 9, Index2 = 0; (Index < (Size + 9)) && (Ptr[Index] != '\0'); Index++, Index2++) {
45 Temp[Index2] = Ptr[Index];
46 if (Temp[Index2] == '/') {
47 Temp[Index2] = '\\';
48 }
49
50 if (Index2 == 1) {
51 Temp[Index2 - 1] = Ptr[Index];
52 Temp[Index2] = ':';
53 }
54 }
55
56 return Temp;
57 }
58
59 /**
60 Performs additional actions after a PE/COFF image has been loaded and relocated.
61
62 If ImageContext is NULL, then ASSERT().
63
64 @param ImageContext Pointer to the image context structure that describes the
65 PE/COFF image that has already been loaded and relocated.
66
67 **/
68 VOID
69 EFIAPI
70 PeCoffLoaderRelocateImageExtraAction (
71 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
72 )
73 {
74 #if !defined (MDEPKG_NDEBUG)
75 CHAR8 Temp[512];
76 #endif
77
78 if (ImageContext->PdbPointer) {
79 #ifdef __CC_ARM
80 #if (__ARMCC_VERSION < 500000)
81 // Print out the command for the RVD debugger to load symbols for this image
82 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
83 #else
84 // Print out the command for the DS-5 to load symbols for this image
85 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
86 #endif
87 #elif __GNUC__
88 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
89 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
90 #else
91 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
92 #endif
93 } else {
94 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
95 }
96 }
97
98 /**
99 Performs additional actions just before a PE/COFF image is unloaded. Any resources
100 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
101
102 If ImageContext is NULL, then ASSERT().
103
104 @param ImageContext Pointer to the image context structure that describes the
105 PE/COFF image that is being unloaded.
106
107 **/
108 VOID
109 EFIAPI
110 PeCoffLoaderUnloadImageExtraAction (
111 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
112 )
113 {
114 #if !defined (MDEPKG_NDEBUG)
115 CHAR8 Temp[512];
116 #endif
117
118 if (ImageContext->PdbPointer) {
119 #ifdef __CC_ARM
120 // Print out the command for the RVD debugger to load symbols for this image
121 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "unload symbols_only %a\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp))));
122 #elif __GNUC__
123 // This may not work correctly if you generate PE/COFF directly as then the Offset would not be required
124 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
125 #else
126 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading %a\n", ImageContext->PdbPointer));
127 #endif
128 } else {
129 DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Unloading driver at 0x%11p\n", (VOID *)(UINTN)ImageContext->ImageAddress));
130 }
131 }