]> git.proxmox.com Git - mirror_edk2.git/blame - BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.c
Change to a NEON compatible CPU Arch (ARMv7 is NEON optional) and add performance...
[mirror_edk2.git] / BeagleBoardPkg / Library / EblCmdLib / EblCmdLib.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Add custom commands for BeagleBoard development.\r
3\r
b2a73e21 4 Copyright (c) 2008-2010, Apple Inc. All rights reserved.\r
2ef2b01e
A
5 \r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <PiDxe.h>\r
17#include <Library/ArmLib.h>\r
18#include <Library/CacheMaintenanceLib.h>\r
19#include <Library/EblCmdLib.h>\r
20#include <Library/BaseLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/UefiRuntimeServicesTableLib.h>\r
24#include <Library/MemoryAllocationLib.h>\r
25#include <Library/UefiLib.h>\r
26#include <Library/PcdLib.h>\r
27#include <Library/EfiFileLib.h>\r
f9f937d2 28#include <Library/ArmDisassemblerLib.h>\r
b2a73e21 29#include <Library/PeCoffGetEntryPointLib.h>\r
d02b28d7 30#include <Library/PerformanceLib.h>\r
31#include <Library/TimerLib.h>\r
2ef2b01e 32\r
b2a73e21 33#include <Guid/DebugImageInfoTable.h>\r
d02b28d7 34\r
b2a73e21 35#include <Protocol/DebugSupport.h>\r
36#include <Protocol/LoadedImage.h>\r
6f72e28d 37\r
38/**\r
b2a73e21 39 Simple arm disassembler via a library\r
6f72e28d 40\r
b2a73e21 41 Argv[0] - symboltable\r
42 Argv[1] - Optional qoted format string \r
43 Argv[2] - Optional flag\r
44\r
45 @param Argc Number of command arguments in Argv\r
46 @param Argv Array of strings that represent the parsed command line. \r
47 Argv[0] is the comamnd name\r
48\r
49 @return EFI_SUCCESS\r
50\r
51**/\r
52EFI_STATUS\r
53EblSymbolTable (\r
54 IN UINTN Argc,\r
55 IN CHAR8 **Argv\r
56 )\r
57{\r
58 EFI_STATUS Status;\r
59 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugImageTableHeader = NULL;\r
60 EFI_DEBUG_IMAGE_INFO *DebugTable;\r
61 UINTN Entry;\r
62 CHAR8 *Format;\r
63 CHAR8 *Pdb;\r
64 UINT32 PeCoffSizeOfHeaders;\r
65 UINT32 ImageBase;\r
66 BOOLEAN Elf;\r
67 \r
68 // Need to add lots of error checking on the passed in string\r
b8758b6e 69 // Default string is for RealView debugger\r
70 Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a &0x%x";\r
b2a73e21 71 Elf = (Argc > 2) ? FALSE : TRUE;\r
72 \r
73 Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader);\r
74 if (EFI_ERROR (Status)) {\r
75 return Status;\r
76 }\r
77 \r
78 DebugTable = DebugImageTableHeader->EfiDebugImageInfoTable;\r
79 if (DebugTable == NULL) {\r
80 return EFI_SUCCESS;\r
81 }\r
82\r
83 for (Entry = 0; Entry < DebugImageTableHeader->TableSize; Entry++, DebugTable++) {\r
84 if (DebugTable->NormalImage != NULL) {\r
85 if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r
86 ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;\r
87 PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageBase);\r
88 Pdb = PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);\r
b8758b6e 89 if (Pdb != NULL) {\r
90 if (Elf) {\r
91 // ELF and Mach-O images don't include the header so the linked address does not include header\r
92 ImageBase += PeCoffSizeOfHeaders;\r
93 } \r
94 AsciiPrint (Format, Pdb, ImageBase);\r
95 AsciiPrint ("\n");\r
96 } else {\r
97 }\r
b2a73e21 98 }\r
99 } \r
100 }\r
101\r
102 return EFI_SUCCESS;\r
103}\r
104\r
105\r
106/**\r
107 Simple arm disassembler via a library\r
108\r
109 Argv[0] - disasm\r
110 Argv[1] - Address to start disassembling from\r
111 ARgv[2] - Number of instructions to disassembly (optional)\r
6f72e28d 112\r
113 @param Argc Number of command arguments in Argv\r
114 @param Argv Array of strings that represent the parsed command line. \r
115 Argv[0] is the comamnd name\r
116\r
117 @return EFI_SUCCESS\r
118\r
119**/\r
120EFI_STATUS\r
f9f937d2 121EblDisassembler (\r
6f72e28d 122 IN UINTN Argc,\r
123 IN CHAR8 **Argv\r
124 )\r
125{\r
77844905 126 UINT8 *Ptr, *CurrentAddress;\r
f9f937d2 127 UINT32 Address;\r
128 UINT32 Count;\r
129 CHAR8 Buffer[80];\r
f3198cba 130 UINT32 ItBlock;\r
f9f937d2 131 \r
132 if (Argc < 2) {\r
133 return EFI_INVALID_PARAMETER;\r
134 }\r
135 \r
136 Address = AsciiStrHexToUintn (Argv[1]);\r
77844905 137 Count = (Argc > 2) ? (UINT32)AsciiStrHexToUintn (Argv[2]) : 20;\r
f9f937d2 138\r
139 Ptr = (UINT8 *)(UINTN)Address; \r
f3198cba 140 ItBlock = 0;\r
77844905 141 do {\r
142 CurrentAddress = Ptr;\r
f3198cba 143 DisassembleInstruction (&Ptr, TRUE, TRUE, &ItBlock, Buffer, sizeof (Buffer));\r
77844905 144 AsciiPrint ("0x%08x: %a\n", CurrentAddress, Buffer);\r
145 } while (Count-- > 0);\r
146 \r
f9f937d2 147\r
6f72e28d 148 return EFI_SUCCESS;\r
149}\r
150\r
151\r
d02b28d7 152CHAR8 *\r
153ImageHandleToPdbFileName (\r
154 IN EFI_HANDLE Handle\r
155 )\r
156{\r
157 EFI_STATUS Status;\r
158 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
159\r
160 Status = gBS->HandleProtocol (Handle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);\r
161 if (EFI_ERROR (Status)) {\r
162 return "";\r
163 }\r
164\r
165 return PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);\r
166}\r
167\r
168CHAR8 *mTokenList[] = {\r
169 "SEC",\r
170 "PEI",\r
171 "DXE",\r
172 "BDS",\r
173 NULL\r
174};\r
175\r
176/**\r
177 Simple arm disassembler via a library\r
178\r
179 Argv[0] - disasm\r
180 Argv[1] - Address to start disassembling from\r
181 ARgv[2] - Number of instructions to disassembly (optional)\r
182\r
183 @param Argc Number of command arguments in Argv\r
184 @param Argv Array of strings that represent the parsed command line. \r
185 Argv[0] is the comamnd name\r
186\r
187 @return EFI_SUCCESS\r
188\r
189**/\r
190EFI_STATUS\r
191EblPerformance (\r
192 IN UINTN Argc,\r
193 IN CHAR8 **Argv\r
194 )\r
195{\r
196 UINTN Key;\r
197 CONST VOID *Handle;\r
198 CONST CHAR8 *Token, *Module;\r
199 UINT64 Start, Stop, TimeStamp;\r
200 UINT64 Delta, TicksPerSecond, Milliseconds, Microseconds;\r
201 UINTN Index;\r
202\r
203 TicksPerSecond = GetPerformanceCounterProperties (NULL, NULL);\r
204\r
205 Key = 0;\r
206 do {\r
207 Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);\r
208 if (Key != 0) {\r
209 if (AsciiStriCmp ("StartImage:", Token) == 0) {\r
210 if (Stop == 0) {\r
211 // The entry for EBL is still running so the stop time will be zero. Skip it\r
212 AsciiPrint (" running %a\n", ImageHandleToPdbFileName ((EFI_HANDLE)Handle));\r
213 } else {\r
214 Delta = Stop - Start;\r
215 Microseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000000), TicksPerSecond, NULL);\r
216 AsciiPrint ("%10ld us %a\n", Microseconds, ImageHandleToPdbFileName ((EFI_HANDLE)Handle));\r
217 }\r
218 }\r
219 }\r
220 } while (Key != 0);\r
221\r
222 AsciiPrint ("\n");\r
223\r
224 TimeStamp = 0;\r
225 Key = 0;\r
226 do {\r
227 Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);\r
228 if (Key != 0) {\r
229 for (Index = 0; mTokenList[Index] != NULL; Index++) {\r
230 if (AsciiStriCmp (mTokenList[Index], Token) == 0) {\r
231 Delta = Stop - Start;\r
232 TimeStamp += Delta;\r
233 Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);\r
234 AsciiPrint ("%6a %6ld ms\n", Token, Milliseconds);\r
235 break;\r
236 }\r
237 } \r
238 }\r
239 } while (Key != 0);\r
240\r
241 AsciiPrint ("Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));\r
242\r
243 return EFI_SUCCESS;\r
244}\r
245\r
246\r
2ef2b01e
A
247GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =\r
248{\r
6f72e28d 249 {\r
f9f937d2 250 "disasm address [count]",\r
251 " disassemble count instructions",\r
6f72e28d 252 NULL,\r
f9f937d2 253 EblDisassembler\r
b2a73e21 254 },\r
d02b28d7 255 {\r
256 "performance",\r
257 " Display boot performance info",\r
258 NULL,\r
259 EblPerformance\r
260 },\r
b2a73e21 261 {\r
b8758b6e 262 "symboltable [\"format string\"] [PECOFF]",\r
b2a73e21 263 " show symbol table commands for debugger",\r
264 NULL,\r
265 EblSymbolTable\r
6f72e28d 266 }\r
2ef2b01e
A
267};\r
268\r
269\r
270VOID\r
271EblInitializeExternalCmd (\r
272 VOID\r
273 )\r
274{\r
275 EblAddCommands (mLibCmdTemplate, sizeof (mLibCmdTemplate)/sizeof (EBL_COMMAND_TABLE));\r
276 return;\r
277}\r