]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.c
BaseTools/FMMT: Add a tool FMMT
[mirror_edk2.git] / ArmPkg / Library / RvdPeCoffExtraActionLib / RvdPeCoffExtraActionLib.c
CommitLineData
62e797a4
A
1/**@file\r
2\r
d6ebcab7
HT
3Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
4Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
96a8bc11 5Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
6\r
4059386c 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
62e797a4 8\r
62e797a4
A
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
225290eb 18#include <Library/SemihostLib.h>\r
62e797a4
A
19#include <Library/PrintLib.h>\r
20\r
225290eb 21/**\r
3402aac7 22 Append string to debugger script file, create file if needed.\r
225290eb
A
23\r
24 This library can show up in mulitple places so we need to append the file every time we write to it.\r
25 For example Sec can use this to load the DXE core, and the DXE core would use this to load all the\r
26 other modules. So we have two instances of the library in the system.\r
62e797a4 27\r
225290eb
A
28 @param Buffer Buffer to write to file.\r
29 @param Length Length of Buffer in bytes.\r
30**/\r
62e797a4 31VOID\r
225290eb
A
32WriteStringToFile (\r
33 IN VOID *Buffer,\r
34 IN UINT32 Length\r
35 )\r
36{\r
37 // Working around and issue with the code that is commented out. For now send it to the console.\r
3402aac7
RC
38 // You can copy the console into a file and source the file as a script and you get symbols.\r
39 // This gets you all the symbols except for SEC. To get SEC symbols you need to copy the\r
225290eb
A
40 // debug print in the SEC into the debugger manually\r
41 SemihostWriteString (Buffer);\r
42/*\r
43 I'm currently having issues with this code crashing the debugger. Seems like it should work.\r
44\r
45 UINT32 SemihostHandle;\r
c20f8ec6 46 UINT32 SemihostMode = SEMIHOST_FILE_MODE_WRITE | SEMIHOST_FILE_MODE_BINARY | SEMIHOST_FILE_MODE_UPDATE;\r
225290eb
A
47\r
48 SemihostFileOpen ("c:\rvi_symbols.inc", SemihostMode, &SemihostHandle);\r
49 SemihostFileWrite (SemihostHandle, &Length, Buffer);\r
50 SemihostFileClose (SemihostHandle);\r
51 */\r
52}\r
53\r
54\r
55/**\r
3402aac7 56 If the build is done on cygwin the paths are cygpaths.\r
225290eb
A
57 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert\r
58 them to work with RVD commands\r
59\r
60 @param Name Path to convert if needed\r
61\r
62**/\r
63CHAR8 *\r
64DeCygwinPathIfNeeded (\r
62e797a4
A
65 IN CHAR8 *Name\r
66 )\r
67{\r
68 CHAR8 *Ptr;\r
69 UINTN Index;\r
70 UINTN Len;\r
3402aac7 71\r
62e797a4
A
72 Ptr = AsciiStrStr (Name, "/cygdrive/");\r
73 if (Ptr == NULL) {\r
225290eb 74 return Name;\r
62e797a4 75 }\r
3402aac7 76\r
62e797a4 77 Len = AsciiStrLen (Ptr);\r
3402aac7 78\r
62e797a4
A
79 // convert "/cygdrive" to spaces\r
80 for (Index = 0; Index < 9; Index++) {\r
81 Ptr[Index] = ' ';\r
82 }\r
83\r
84 // convert /c to c:\r
85 Ptr[9] = Ptr[10];\r
86 Ptr[10] = ':';\r
3402aac7 87\r
11c20f4e 88 // switch path separators\r
62e797a4
A
89 for (Index = 11; Index < Len; Index++) {\r
90 if (Ptr[Index] == '/') {\r
91 Ptr[Index] = '\\' ;\r
92 }\r
93 }\r
225290eb
A
94\r
95 return Name;\r
62e797a4
A
96}\r
97\r
98\r
99/**\r
100 Performs additional actions after a PE/COFF image has been loaded and relocated.\r
101\r
102 If ImageContext is NULL, then ASSERT().\r
103\r
104 @param ImageContext Pointer to the image context structure that describes the\r
105 PE/COFF image that has already been loaded and relocated.\r
106\r
107**/\r
108VOID\r
109EFIAPI\r
110PeCoffLoaderRelocateImageExtraAction (\r
111 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
112 )\r
113{\r
114 CHAR8 Buffer[256];\r
3402aac7 115\r
96a8bc11 116#if (__ARMCC_VERSION < 500000)\r
3d4c7abc 117 AsciiSPrint (Buffer, sizeof(Buffer), "load /a /ni /np \"%a\" &0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r
96a8bc11 118#else\r
119 AsciiSPrint (Buffer, sizeof(Buffer), "add-symbol-file %a 0x%08x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));\r
120#endif\r
225290eb 121 DeCygwinPathIfNeeded (&Buffer[16]);\r
3402aac7 122\r
225290eb 123 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
62e797a4
A
124}\r
125\r
126\r
127\r
128/**\r
129 Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
130 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
3402aac7 131\r
62e797a4 132 If ImageContext is NULL, then ASSERT().\r
3402aac7 133\r
62e797a4
A
134 @param ImageContext Pointer to the image context structure that describes the\r
135 PE/COFF image that is being unloaded.\r
136\r
137**/\r
138VOID\r
139EFIAPI\r
140PeCoffLoaderUnloadImageExtraAction (\r
141 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
142 )\r
143{\r
144 CHAR8 Buffer[256];\r
3402aac7 145\r
3d4c7abc 146 AsciiSPrint (Buffer, sizeof(Buffer), "unload symbols_only \"%a\"\n", ImageContext->PdbPointer);\r
225290eb 147 DeCygwinPathIfNeeded (Buffer);\r
3402aac7 148\r
225290eb 149 WriteStringToFile (Buffer, AsciiStrSize (Buffer));\r
62e797a4 150}\r