2 Add custom commands for BeagleBoard development.
4 Copyright (c) 2008-2010, Apple Inc. All rights reserved.
6 All rights reserved. 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>
31 #include <Guid/DebugImageInfoTable.h>
32 #include <Protocol/DebugSupport.h>
33 #include <Protocol/LoadedImage.h>
36 Simple arm disassembler via a library
39 Argv[1] - Optional qoted format string
40 Argv[2] - Optional flag
42 @param Argc Number of command arguments in Argv
43 @param Argv Array of strings that represent the parsed command line.
44 Argv[0] is the comamnd name
56 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
*DebugImageTableHeader
= NULL
;
57 EFI_DEBUG_IMAGE_INFO
*DebugTable
;
61 UINT32 PeCoffSizeOfHeaders
;
65 // Need to add lots of error checking on the passed in string
66 Format
= (Argc
> 1) ? Argv
[1] : "load /a /ni /np %a & 0x%x\n";
67 Elf
= (Argc
> 2) ? FALSE
: TRUE
;
69 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugImageTableHeader
);
70 if (EFI_ERROR (Status
)) {
74 DebugTable
= DebugImageTableHeader
->EfiDebugImageInfoTable
;
75 if (DebugTable
== NULL
) {
79 for (Entry
= 0; Entry
< DebugImageTableHeader
->TableSize
; Entry
++, DebugTable
++) {
80 if (DebugTable
->NormalImage
!= NULL
) {
81 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) && (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
82 ImageBase
= (UINT32
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
83 PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageBase
);
84 Pdb
= PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);
86 // ELF and Mach-O images don't include the header so the linked address does not include header
87 ImageBase
+= PeCoffSizeOfHeaders
;
89 AsciiPrint (Format
, Pdb
, ImageBase
);
99 Simple arm disassembler via a library
102 Argv[1] - Address to start disassembling from
103 ARgv[2] - Number of instructions to disassembly (optional)
105 @param Argc Number of command arguments in Argv
106 @param Argv Array of strings that represent the parsed command line.
107 Argv[0] is the comamnd name
118 UINT8
*Ptr
, *CurrentAddress
;
125 return EFI_INVALID_PARAMETER
;
128 Address
= AsciiStrHexToUintn (Argv
[1]);
129 Count
= (Argc
> 2) ? (UINT32
)AsciiStrHexToUintn (Argv
[2]) : 20;
131 Ptr
= (UINT8
*)(UINTN
)Address
;
134 CurrentAddress
= Ptr
;
135 DisassembleInstruction (&Ptr
, TRUE
, TRUE
, &ItBlock
, Buffer
, sizeof (Buffer
));
136 AsciiPrint ("0x%08x: %a\n", CurrentAddress
, Buffer
);
137 } while (Count
-- > 0);
144 GLOBAL_REMOVE_IF_UNREFERENCED
const EBL_COMMAND_TABLE mLibCmdTemplate
[] =
147 "disasm address [count]",
148 " disassemble count instructions",
153 "symboltable [\"format string\"] [TRUE]",
154 " show symbol table commands for debugger",
162 EblInitializeExternalCmd (
166 EblAddCommands (mLibCmdTemplate
, sizeof (mLibCmdTemplate
)/sizeof (EBL_COMMAND_TABLE
));