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