]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file\r |
2 | Add custom commands for BeagleBoard development.\r | |
3 | \r | |
b2a73e21 | 4 | Copyright (c) 2008-2010, Apple Inc. All rights reserved.\r |
2ef2b01e A |
5 | \r |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiDxe.h>\r | |
17 | #include <Library/ArmLib.h>\r | |
18 | #include <Library/CacheMaintenanceLib.h>\r | |
19 | #include <Library/EblCmdLib.h>\r | |
20 | #include <Library/BaseLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Library/UefiBootServicesTableLib.h>\r | |
23 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
24 | #include <Library/MemoryAllocationLib.h>\r | |
25 | #include <Library/UefiLib.h>\r | |
26 | #include <Library/PcdLib.h>\r | |
27 | #include <Library/EfiFileLib.h>\r | |
f9f937d2 | 28 | #include <Library/ArmDisassemblerLib.h>\r |
b2a73e21 | 29 | #include <Library/PeCoffGetEntryPointLib.h>\r |
2ef2b01e | 30 | \r |
b2a73e21 | 31 | #include <Guid/DebugImageInfoTable.h>\r |
32 | #include <Protocol/DebugSupport.h>\r | |
33 | #include <Protocol/LoadedImage.h>\r | |
6f72e28d | 34 | \r |
35 | /**\r | |
b2a73e21 | 36 | Simple arm disassembler via a library\r |
6f72e28d | 37 | \r |
b2a73e21 | 38 | Argv[0] - symboltable\r |
39 | Argv[1] - Optional qoted format string \r | |
40 | Argv[2] - Optional flag\r | |
41 | \r | |
42 | @param Argc Number of command arguments in Argv\r | |
43 | @param Argv Array of strings that represent the parsed command line. \r | |
44 | Argv[0] is the comamnd name\r | |
45 | \r | |
46 | @return EFI_SUCCESS\r | |
47 | \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EblSymbolTable (\r | |
51 | IN UINTN Argc,\r | |
52 | IN CHAR8 **Argv\r | |
53 | )\r | |
54 | {\r | |
55 | EFI_STATUS Status;\r | |
56 | EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugImageTableHeader = NULL;\r | |
57 | EFI_DEBUG_IMAGE_INFO *DebugTable;\r | |
58 | UINTN Entry;\r | |
59 | CHAR8 *Format;\r | |
60 | CHAR8 *Pdb;\r | |
61 | UINT32 PeCoffSizeOfHeaders;\r | |
62 | UINT32 ImageBase;\r | |
63 | BOOLEAN Elf;\r | |
64 | \r | |
65 | // Need to add lots of error checking on the passed in string\r | |
d5505a2a | 66 | Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a & 0x%x";\r |
b2a73e21 | 67 | Elf = (Argc > 2) ? FALSE : TRUE;\r |
68 | \r | |
69 | Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader);\r | |
70 | if (EFI_ERROR (Status)) {\r | |
71 | return Status;\r | |
72 | }\r | |
73 | \r | |
74 | DebugTable = DebugImageTableHeader->EfiDebugImageInfoTable;\r | |
75 | if (DebugTable == NULL) {\r | |
76 | return EFI_SUCCESS;\r | |
77 | }\r | |
78 | \r | |
79 | for (Entry = 0; Entry < DebugImageTableHeader->TableSize; Entry++, DebugTable++) {\r | |
80 | if (DebugTable->NormalImage != NULL) {\r | |
81 | if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r | |
82 | ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;\r | |
83 | PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageBase);\r | |
84 | Pdb = PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);\r | |
85 | if (Elf) {\r | |
86 | // ELF and Mach-O images don't include the header so the linked address does not include header\r | |
87 | ImageBase += PeCoffSizeOfHeaders;\r | |
88 | } \r | |
89 | AsciiPrint (Format, Pdb, ImageBase);\r | |
d5505a2a | 90 | AsciiPrint ("\n");\r |
b2a73e21 | 91 | }\r |
92 | } \r | |
93 | }\r | |
94 | \r | |
95 | return EFI_SUCCESS;\r | |
96 | }\r | |
97 | \r | |
98 | \r | |
99 | /**\r | |
100 | Simple arm disassembler via a library\r | |
101 | \r | |
102 | Argv[0] - disasm\r | |
103 | Argv[1] - Address to start disassembling from\r | |
104 | ARgv[2] - Number of instructions to disassembly (optional)\r | |
6f72e28d | 105 | \r |
106 | @param Argc Number of command arguments in Argv\r | |
107 | @param Argv Array of strings that represent the parsed command line. \r | |
108 | Argv[0] is the comamnd name\r | |
109 | \r | |
110 | @return EFI_SUCCESS\r | |
111 | \r | |
112 | **/\r | |
113 | EFI_STATUS\r | |
f9f937d2 | 114 | EblDisassembler (\r |
6f72e28d | 115 | IN UINTN Argc,\r |
116 | IN CHAR8 **Argv\r | |
117 | )\r | |
118 | {\r | |
77844905 | 119 | UINT8 *Ptr, *CurrentAddress;\r |
f9f937d2 | 120 | UINT32 Address;\r |
121 | UINT32 Count;\r | |
122 | CHAR8 Buffer[80];\r | |
f3198cba | 123 | UINT32 ItBlock;\r |
f9f937d2 | 124 | \r |
125 | if (Argc < 2) {\r | |
126 | return EFI_INVALID_PARAMETER;\r | |
127 | }\r | |
128 | \r | |
129 | Address = AsciiStrHexToUintn (Argv[1]);\r | |
77844905 | 130 | Count = (Argc > 2) ? (UINT32)AsciiStrHexToUintn (Argv[2]) : 20;\r |
f9f937d2 | 131 | \r |
132 | Ptr = (UINT8 *)(UINTN)Address; \r | |
f3198cba | 133 | ItBlock = 0;\r |
77844905 | 134 | do {\r |
135 | CurrentAddress = Ptr;\r | |
f3198cba | 136 | DisassembleInstruction (&Ptr, TRUE, TRUE, &ItBlock, Buffer, sizeof (Buffer));\r |
77844905 | 137 | AsciiPrint ("0x%08x: %a\n", CurrentAddress, Buffer);\r |
138 | } while (Count-- > 0);\r | |
139 | \r | |
f9f937d2 | 140 | \r |
6f72e28d | 141 | return EFI_SUCCESS;\r |
142 | }\r | |
143 | \r | |
144 | \r | |
2ef2b01e A |
145 | GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =\r |
146 | {\r | |
6f72e28d | 147 | {\r |
f9f937d2 | 148 | "disasm address [count]",\r |
149 | " disassemble count instructions",\r | |
6f72e28d | 150 | NULL,\r |
f9f937d2 | 151 | EblDisassembler\r |
b2a73e21 | 152 | },\r |
153 | {\r | |
154 | "symboltable [\"format string\"] [TRUE]",\r | |
155 | " show symbol table commands for debugger",\r | |
156 | NULL,\r | |
157 | EblSymbolTable\r | |
6f72e28d | 158 | }\r |
2ef2b01e A |
159 | };\r |
160 | \r | |
161 | \r | |
162 | VOID\r | |
163 | EblInitializeExternalCmd (\r | |
164 | VOID\r | |
165 | )\r | |
166 | {\r | |
167 | EblAddCommands (mLibCmdTemplate, sizeof (mLibCmdTemplate)/sizeof (EBL_COMMAND_TABLE));\r | |
168 | return;\r | |
169 | }\r |