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 // Default string is for RealView debugger
67 Format
= (Argc
> 1) ? Argv
[1] : "load /a /ni /np %a &0x%x";
68 Elf
= (Argc
> 2) ? FALSE
: TRUE
;
70 Status
= EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid
, (VOID
**)&DebugImageTableHeader
);
71 if (EFI_ERROR (Status
)) {
75 DebugTable
= DebugImageTableHeader
->EfiDebugImageInfoTable
;
76 if (DebugTable
== NULL
) {
80 for (Entry
= 0; Entry
< DebugImageTableHeader
->TableSize
; Entry
++, DebugTable
++) {
81 if (DebugTable
->NormalImage
!= NULL
) {
82 if ((DebugTable
->NormalImage
->ImageInfoType
== EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
) && (DebugTable
->NormalImage
->LoadedImageProtocolInstance
!= NULL
)) {
83 ImageBase
= (UINT32
)DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
;
84 PeCoffSizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageBase
);
85 Pdb
= PeCoffLoaderGetPdbPointer (DebugTable
->NormalImage
->LoadedImageProtocolInstance
->ImageBase
);
88 // ELF and Mach-O images don't include the header so the linked address does not include header
89 ImageBase
+= PeCoffSizeOfHeaders
;
91 AsciiPrint (Format
, Pdb
, ImageBase
);
104 Simple arm disassembler via a library
107 Argv[1] - Address to start disassembling from
108 ARgv[2] - Number of instructions to disassembly (optional)
110 @param Argc Number of command arguments in Argv
111 @param Argv Array of strings that represent the parsed command line.
112 Argv[0] is the comamnd name
123 UINT8
*Ptr
, *CurrentAddress
;
130 return EFI_INVALID_PARAMETER
;
133 Address
= AsciiStrHexToUintn (Argv
[1]);
134 Count
= (Argc
> 2) ? (UINT32
)AsciiStrHexToUintn (Argv
[2]) : 20;
136 Ptr
= (UINT8
*)(UINTN
)Address
;
139 CurrentAddress
= Ptr
;
140 DisassembleInstruction (&Ptr
, TRUE
, TRUE
, &ItBlock
, Buffer
, sizeof (Buffer
));
141 AsciiPrint ("0x%08x: %a\n", CurrentAddress
, Buffer
);
142 } while (Count
-- > 0);
149 GLOBAL_REMOVE_IF_UNREFERENCED
const EBL_COMMAND_TABLE mLibCmdTemplate
[] =
152 "disasm address [count]",
153 " disassemble count instructions",
158 "symboltable [\"format string\"] [PECOFF]",
159 " show symbol table commands for debugger",
167 EblInitializeExternalCmd (
171 EblAddCommands (mLibCmdTemplate
, sizeof (mLibCmdTemplate
)/sizeof (EBL_COMMAND_TABLE
));