3 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/ArmLib.h>
17 #include <Library/CacheMaintenanceLib.h>
18 #include <Library/EblCmdLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DxeServicesTableLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/UefiRuntimeServicesTableLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/EfiFileLib.h>
28 #include <Library/ArmDisassemblerLib.h>
29 #include <Library/PeCoffGetEntryPointLib.h>
30 #include <Library/PerformanceLib.h>
31 #include <Library/TimerLib.h>
33 #include <Guid/DebugImageInfoTable.h>
35 #include <Protocol/DebugSupport.h>
36 #include <Protocol/LoadedImage.h>
45 Simple arm disassembler via a library
48 Argv[1] - Optional qoted format string
49 Argv[2] - Optional flag
51 @param Argc Number of command arguments in Argv
52 @param Argv Array of strings that represent the parsed command line.
53 Argv[0] is the comamnd name
65 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
*DebugImageTableHeader
= NULL
;
66 EFI_DEBUG_IMAGE_INFO
*DebugTable
;
70 UINT32 PeCoffSizeOfHeaders
;
74 // Need to add lots of error checking on the passed in string
75 // Default string is for RealView debugger
76 Format
= (Argc
> 1) ? Argv
[1] : "load /a /ni /np %a &0x%x";
77 Elf
= (Argc
> 2) ? FALSE
: TRUE
;
79 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugImageTableHeader
);
80 if (EFI_ERROR (Status
)) {
84 DebugTable
= DebugImageTableHeader
->EfiDebugImageInfoTable
;
85 if (DebugTable
== NULL
) {
89 for (Entry
= 0; Entry
< DebugImageTableHeader
->TableSize
; Entry
++, DebugTable
++) {
90 if (DebugTable
->NormalImage
!= NULL
) {
91 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) && (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
92 ImageBase
= (UINT32
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
93 PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageBase
);
94 Pdb
= PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);
97 // ELF and Mach-O images don't include the header so the linked address does not include header
98 ImageBase
+= PeCoffSizeOfHeaders
;
100 AsciiPrint (Format
, Pdb
, ImageBase
);
113 Simple arm disassembler via a library
116 Argv[1] - Address to start disassembling from
117 ARgv[2] - Number of instructions to disassembly (optional)
119 @param Argc Number of command arguments in Argv
120 @param Argv Array of strings that represent the parsed command line.
121 Argv[0] is the comamnd name
132 UINT8
*Ptr
, *CurrentAddress
;
139 return EFI_INVALID_PARAMETER
;
142 Address
= AsciiStrHexToUintn (Argv
[1]);
143 Count
= (Argc
> 2) ? (UINT32
)AsciiStrHexToUintn (Argv
[2]) : 20;
145 Ptr
= (UINT8
*)(UINTN
)Address
;
148 CurrentAddress
= Ptr
;
149 DisassembleInstruction (&Ptr
, TRUE
, TRUE
, &ItBlock
, Buffer
, sizeof (Buffer
));
150 AsciiPrint ("0x%08x: %a\n", CurrentAddress
, Buffer
);
151 } while (Count
-- > 0);
159 ImageHandleToPdbFileName (
164 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
168 Status
= gBS
->HandleProtocol (Handle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&LoadedImage
);
169 if (EFI_ERROR (Status
)) {
173 Pdb
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
174 StripLeading
= AsciiStrStr (Pdb
, "\\ARM\\");
175 if (StripLeading
== NULL
) {
176 StripLeading
= AsciiStrStr (Pdb
, "/ARM/");
177 if (StripLeading
== NULL
) {
181 // Hopefully we hacked off the unneeded part
182 return (StripLeading
+ 5);
186 CHAR8
*mTokenList
[] = {
195 Simple arm disassembler via a library
198 Argv[1] - Address to start disassembling from
199 ARgv[2] - Number of instructions to disassembly (optional)
201 @param Argc Number of command arguments in Argv
202 @param Argv Array of strings that represent the parsed command line.
203 Argv[0] is the comamnd name
216 CONST CHAR8
*Token
, *Module
;
217 UINT64 Start
, Stop
, TimeStamp
;
218 UINT64 Delta
, TicksPerSecond
, Milliseconds
, Microseconds
;
221 TicksPerSecond
= GetPerformanceCounterProperties (NULL
, NULL
);
225 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
227 if (AsciiStriCmp ("StartImage:", Token
) == 0) {
229 // The entry for EBL is still running so the stop time will be zero. Skip it
230 AsciiPrint (" running %a\n", ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
232 Delta
= Start
- Stop
;
233 Microseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000000), TicksPerSecond
, NULL
);
234 AsciiPrint ("%10ld us %a\n", Microseconds
, ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
245 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
247 for (Index
= 0; mTokenList
[Index
] != NULL
; Index
++) {
248 if (AsciiStriCmp (mTokenList
[Index
], Token
) == 0) {
249 Delta
= Start
- Stop
;
251 Milliseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000), TicksPerSecond
, NULL
);
252 AsciiPrint ("%6a %6ld ms\n", Token
, Milliseconds
);
259 AsciiPrint ("Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp
, 1000), TicksPerSecond
, NULL
));
264 #define EFI_MEMORY_PORT_IO 0x4000000000000000ULL
273 UINTN NumberOfDescriptors
;
275 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
276 EFI_GCD_IO_SPACE_DESCRIPTOR
*IoSpaceMap
;
278 Status
= gDS
->GetMemorySpaceMap(&NumberOfDescriptors
,&MemorySpaceMap
);
279 if (EFI_ERROR (Status
)) {
282 AsciiPrint (" Address Range Image Device Attributes\n");
283 AsciiPrint ("__________________________________________________________\n");
284 for (i
=0; i
< NumberOfDescriptors
; i
++) {
285 //AsciiPrint ("%016lx - %016lx",MemorySpaceMap[i].BaseAddress,MemorySpaceMap[i].BaseAddress+MemorySpaceMap[i].Length);
286 AsciiPrint ("MEM %08lx - %08lx",(UINT64
)MemorySpaceMap
[i
].BaseAddress
,MemorySpaceMap
[i
].BaseAddress
+MemorySpaceMap
[i
].Length
-1);
287 AsciiPrint (" %08x %08x",MemorySpaceMap
[i
].ImageHandle
,MemorySpaceMap
[i
].DeviceHandle
);
289 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_RUNTIME
)
290 AsciiPrint (" RUNTIME");
291 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_PORT_IO
)
292 AsciiPrint (" PORT_IO");
294 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_UC
)
295 AsciiPrint (" MEM_UC");
296 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_WC
)
297 AsciiPrint (" MEM_WC");
298 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_WT
)
299 AsciiPrint (" MEM_WT");
300 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_WB
)
301 AsciiPrint (" MEM_WB");
302 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_UCE
)
303 AsciiPrint (" MEM_UCE");
304 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_WP
)
305 AsciiPrint (" MEM_WP");
306 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_RP
)
307 AsciiPrint (" MEM_RP");
308 if (MemorySpaceMap
[i
].Attributes
& EFI_MEMORY_XP
)
309 AsciiPrint (" MEM_XP");
311 if (MemorySpaceMap
[i
].GcdMemoryType
& EfiGcdMemoryTypeNonExistent
)
312 AsciiPrint (" TYPE_NONEXISTENT");
313 if (MemorySpaceMap
[i
].GcdMemoryType
& EfiGcdMemoryTypeReserved
)
314 AsciiPrint (" TYPE_RESERVED");
315 if (MemorySpaceMap
[i
].GcdMemoryType
& EfiGcdMemoryTypeSystemMemory
)
316 AsciiPrint (" TYPE_SYSMEM");
317 if (MemorySpaceMap
[i
].GcdMemoryType
& EfiGcdMemoryTypeMemoryMappedIo
)
318 AsciiPrint (" TYPE_MEMMAP");
323 Status
= gDS
->GetIoSpaceMap(&NumberOfDescriptors
,&IoSpaceMap
);
324 if (EFI_ERROR (Status
)) {
327 for (i
=0; i
< NumberOfDescriptors
; i
++) {
328 AsciiPrint ("IO %08lx - %08lx",IoSpaceMap
[i
].BaseAddress
,IoSpaceMap
[i
].BaseAddress
+IoSpaceMap
[i
].Length
);
329 AsciiPrint ("\t%08x %08x",IoSpaceMap
[i
].ImageHandle
,IoSpaceMap
[i
].DeviceHandle
);
331 if (IoSpaceMap
[i
].GcdIoType
& EfiGcdMemoryTypeNonExistent
)
332 AsciiPrint (" TYPE_NONEXISTENT");
333 if (IoSpaceMap
[i
].GcdIoType
& EfiGcdMemoryTypeReserved
)
334 AsciiPrint (" TYPE_RESERVED");
335 if (IoSpaceMap
[i
].GcdIoType
& EfiGcdIoTypeIo
)
336 AsciiPrint (" TYPE_IO");
344 GLOBAL_REMOVE_IF_UNREFERENCED
const EBL_COMMAND_TABLE mLibCmdTemplate
[] =
347 "disasm address [count]",
348 " disassemble count instructions",
354 " Display boot performance info",
359 "symboltable [\"format string\"] [PECOFF]",
360 " show symbol table commands for debugger",
366 " dump Global Coherency Domain",
380 EblInitializeExternalCmd (
384 EblAddCommands (mLibCmdTemplate
, sizeof (mLibCmdTemplate
)/sizeof (EBL_COMMAND_TABLE
));