2 Add custom commands for BeagleBoard development.
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/ArmLib.h>
18 #include <Library/CacheMaintenanceLib.h>
19 #include <Library/EblCmdLib.h>
20 #include <Library/BaseLib.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>
39 Simple arm disassembler via a library
42 Argv[1] - Optional qoted format string
43 Argv[2] - Optional flag
45 @param Argc Number of command arguments in Argv
46 @param Argv Array of strings that represent the parsed command line.
47 Argv[0] is the comamnd name
59 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
*DebugImageTableHeader
= NULL
;
60 EFI_DEBUG_IMAGE_INFO
*DebugTable
;
64 UINT32 PeCoffSizeOfHeaders
;
68 // Need to add lots of error checking on the passed in string
69 // Default string is for RealView debugger
70 Format
= (Argc
> 1) ? Argv
[1] : "load /a /ni /np %a &0x%x";
71 Elf
= (Argc
> 2) ? FALSE
: TRUE
;
73 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugImageTableHeader
);
74 if (EFI_ERROR (Status
)) {
78 DebugTable
= DebugImageTableHeader
->EfiDebugImageInfoTable
;
79 if (DebugTable
== NULL
) {
83 for (Entry
= 0; Entry
< DebugImageTableHeader
->TableSize
; Entry
++, DebugTable
++) {
84 if (DebugTable
->NormalImage
!= NULL
) {
85 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) && (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
86 ImageBase
= (UINT32
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
87 PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageBase
);
88 Pdb
= PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);
91 // ELF and Mach-O images don't include the header so the linked address does not include header
92 ImageBase
+= PeCoffSizeOfHeaders
;
94 AsciiPrint (Format
, Pdb
, ImageBase
);
107 Simple arm disassembler via a library
110 Argv[1] - Address to start disassembling from
111 ARgv[2] - Number of instructions to disassembly (optional)
113 @param Argc Number of command arguments in Argv
114 @param Argv Array of strings that represent the parsed command line.
115 Argv[0] is the comamnd name
126 UINT8
*Ptr
, *CurrentAddress
;
133 return EFI_INVALID_PARAMETER
;
136 Address
= AsciiStrHexToUintn (Argv
[1]);
137 Count
= (Argc
> 2) ? (UINT32
)AsciiStrHexToUintn (Argv
[2]) : 20;
139 Ptr
= (UINT8
*)(UINTN
)Address
;
142 CurrentAddress
= Ptr
;
143 DisassembleInstruction (&Ptr
, TRUE
, TRUE
, &ItBlock
, Buffer
, sizeof (Buffer
));
144 AsciiPrint ("0x%08x: %a\n", CurrentAddress
, Buffer
);
145 } while (Count
-- > 0);
153 ImageHandleToPdbFileName (
158 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
162 Status
= gBS
->HandleProtocol (Handle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&LoadedImage
);
163 if (EFI_ERROR (Status
)) {
167 Pdb
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
168 StripLeading
= AsciiStrStr (Pdb
, "\\ARM\\");
169 if (StripLeading
== NULL
) {
170 StripLeading
= AsciiStrStr (Pdb
, "/ARM/");
171 if (StripLeading
== NULL
) {
175 // Hopefully we hacked off the unneeded part
176 return (StripLeading
+ 5);
180 CHAR8
*mTokenList
[] = {
189 Simple arm disassembler via a library
192 Argv[1] - Address to start disassembling from
193 ARgv[2] - Number of instructions to disassembly (optional)
195 @param Argc Number of command arguments in Argv
196 @param Argv Array of strings that represent the parsed command line.
197 Argv[0] is the comamnd name
210 CONST CHAR8
*Token
, *Module
;
211 UINT64 Start
, Stop
, TimeStamp
;
212 UINT64 Delta
, TicksPerSecond
, Milliseconds
, Microseconds
;
215 TicksPerSecond
= GetPerformanceCounterProperties (NULL
, NULL
);
219 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
221 if (AsciiStriCmp ("StartImage:", Token
) == 0) {
223 // The entry for EBL is still running so the stop time will be zero. Skip it
224 AsciiPrint (" running %a\n", ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
226 Delta
= Stop
- Start
;
227 Microseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000000), TicksPerSecond
, NULL
);
228 AsciiPrint ("%10ld us %a\n", Microseconds
, ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
239 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
241 for (Index
= 0; mTokenList
[Index
] != NULL
; Index
++) {
242 if (AsciiStriCmp (mTokenList
[Index
], Token
) == 0) {
243 Delta
= Stop
- Start
;
245 Milliseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000), TicksPerSecond
, NULL
);
246 AsciiPrint ("%6a %6ld ms\n", Token
, Milliseconds
);
253 AsciiPrint ("Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp
, 1000), TicksPerSecond
, NULL
));
259 GLOBAL_REMOVE_IF_UNREFERENCED
const EBL_COMMAND_TABLE mLibCmdTemplate
[] =
262 "disasm address [count]",
263 " disassemble count instructions",
269 " Display boot performance info",
274 "symboltable [\"format string\"] [PECOFF]",
275 " show symbol table commands for debugger",
283 EblInitializeExternalCmd (
287 EblAddCommands (mLibCmdTemplate
, sizeof (mLibCmdTemplate
)/sizeof (EBL_COMMAND_TABLE
));