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 quoted 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 command 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 or gdb depending on toolchain used.
75 Format
= "add-symbol-file %a 0x%x";
78 Format
= "load /a /ni /np %a &0x%x";
81 Elf
= (Argc
> 2) ? FALSE
: TRUE
;
83 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugImageTableHeader
);
84 if (EFI_ERROR (Status
)) {
88 DebugTable
= DebugImageTableHeader
->EfiDebugImageInfoTable
;
89 if (DebugTable
== NULL
) {
93 for (Entry
= 0; Entry
< DebugImageTableHeader
->TableSize
; Entry
++, DebugTable
++) {
94 if (DebugTable
->NormalImage
!= NULL
) {
95 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) && (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
96 ImageBase
= (UINT32
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
97 PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageBase
);
98 Pdb
= PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);
101 // ELF and Mach-O images don't include the header so the linked address does not include header
102 ImageBase
+= PeCoffSizeOfHeaders
;
104 AsciiPrint (Format
, Pdb
, ImageBase
);
117 Simple arm disassembler via a library
120 Argv[1] - Address to start disassembling from
121 ARgv[2] - Number of instructions to disassembly (optional)
123 @param Argc Number of command arguments in Argv
124 @param Argv Array of strings that represent the parsed command line.
125 Argv[0] is the command name
136 UINT8
*Ptr
, *CurrentAddress
;
143 return EFI_INVALID_PARAMETER
;
146 Address
= AsciiStrHexToUintn (Argv
[1]);
147 Count
= (Argc
> 2) ? (UINT32
)AsciiStrHexToUintn (Argv
[2]) : 20;
149 Ptr
= (UINT8
*)(UINTN
)Address
;
152 CurrentAddress
= Ptr
;
153 DisassembleInstruction (&Ptr
, TRUE
, TRUE
, &ItBlock
, Buffer
, sizeof (Buffer
));
154 AsciiPrint ("0x%08x: %a\n", CurrentAddress
, Buffer
);
155 } while (Count
-- > 0);
163 ImageHandleToPdbFileName (
168 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
172 Status
= gBS
->HandleProtocol (Handle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&LoadedImage
);
173 if (EFI_ERROR (Status
)) {
177 Pdb
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
178 StripLeading
= AsciiStrStr (Pdb
, "\\ARM\\");
179 if (StripLeading
== NULL
) {
180 StripLeading
= AsciiStrStr (Pdb
, "/ARM/");
181 if (StripLeading
== NULL
) {
185 // Hopefully we hacked off the unneeded part
186 return (StripLeading
+ 5);
190 CHAR8
*mTokenList
[] = {
199 Simple arm disassembler via a library
202 Argv[1] - Address to start disassembling from
203 ARgv[2] - Number of instructions to disassembly (optional)
205 @param Argc Number of command arguments in Argv
206 @param Argv Array of strings that represent the parsed command line.
207 Argv[0] is the command name
220 CONST CHAR8
*Token
, *Module
;
221 UINT64 Start
, Stop
, TimeStamp
;
222 UINT64 Delta
, TicksPerSecond
, Milliseconds
, Microseconds
;
225 TicksPerSecond
= GetPerformanceCounterProperties (NULL
, NULL
);
229 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
231 if (AsciiStriCmp ("StartImage:", Token
) == 0) {
233 // The entry for EBL is still running so the stop time will be zero. Skip it
234 AsciiPrint (" running %a\n", ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
236 Delta
= Stop
- Start
;
237 Microseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000000), TicksPerSecond
, NULL
);
238 AsciiPrint ("%10ld us %a\n", Microseconds
, ImageHandleToPdbFileName ((EFI_HANDLE
)Handle
));
249 Key
= GetPerformanceMeasurement (Key
, (CONST VOID
**)&Handle
, &Token
, &Module
, &Start
, &Stop
);
251 for (Index
= 0; mTokenList
[Index
] != NULL
; Index
++) {
252 if (AsciiStriCmp (mTokenList
[Index
], Token
) == 0) {
253 Delta
= Stop
- Start
;
255 Milliseconds
= DivU64x64Remainder (MultU64x32 (Delta
, 1000), TicksPerSecond
, NULL
);
256 AsciiPrint ("%6a %6ld ms\n", Token
, Milliseconds
);
263 AsciiPrint ("Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp
, 1000), TicksPerSecond
, NULL
));
269 GLOBAL_REMOVE_IF_UNREFERENCED
const EBL_COMMAND_TABLE mLibCmdTemplate
[] =
272 "disasm address [count]",
273 " disassemble count instructions",
279 " Display boot performance info",
284 "symboltable [\"format string\"] [PECOFF]",
285 " show symbol table commands for debugger",
293 EblInitializeExternalCmd (
297 EblAddCommands (mLibCmdTemplate
, sizeof (mLibCmdTemplate
)/sizeof (EBL_COMMAND_TABLE
));