]>
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 | |
b8758b6e | 66 | // Default string is for RealView debugger\r |
67 | Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a &0x%x";\r | |
b2a73e21 | 68 | Elf = (Argc > 2) ? FALSE : TRUE;\r |
69 | \r | |
70 | Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader);\r | |
71 | if (EFI_ERROR (Status)) {\r | |
72 | return Status;\r | |
73 | }\r | |
74 | \r | |
75 | DebugTable = DebugImageTableHeader->EfiDebugImageInfoTable;\r | |
76 | if (DebugTable == NULL) {\r | |
77 | return EFI_SUCCESS;\r | |
78 | }\r | |
79 | \r | |
80 | for (Entry = 0; Entry < DebugImageTableHeader->TableSize; Entry++, DebugTable++) {\r | |
81 | if (DebugTable->NormalImage != NULL) {\r | |
82 | if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r | |
83 | ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;\r | |
84 | PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageBase);\r | |
85 | Pdb = PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);\r | |
b8758b6e | 86 | if (Pdb != NULL) {\r |
87 | if (Elf) {\r | |
88 | // ELF and Mach-O images don't include the header so the linked address does not include header\r | |
89 | ImageBase += PeCoffSizeOfHeaders;\r | |
90 | } \r | |
91 | AsciiPrint (Format, Pdb, ImageBase);\r | |
92 | AsciiPrint ("\n");\r | |
93 | } else {\r | |
94 | }\r | |
b2a73e21 | 95 | }\r |
96 | } \r | |
97 | }\r | |
98 | \r | |
99 | return EFI_SUCCESS;\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | /**\r | |
104 | Simple arm disassembler via a library\r | |
105 | \r | |
106 | Argv[0] - disasm\r | |
107 | Argv[1] - Address to start disassembling from\r | |
108 | ARgv[2] - Number of instructions to disassembly (optional)\r | |
6f72e28d | 109 | \r |
110 | @param Argc Number of command arguments in Argv\r | |
111 | @param Argv Array of strings that represent the parsed command line. \r | |
112 | Argv[0] is the comamnd name\r | |
113 | \r | |
114 | @return EFI_SUCCESS\r | |
115 | \r | |
116 | **/\r | |
117 | EFI_STATUS\r | |
f9f937d2 | 118 | EblDisassembler (\r |
6f72e28d | 119 | IN UINTN Argc,\r |
120 | IN CHAR8 **Argv\r | |
121 | )\r | |
122 | {\r | |
77844905 | 123 | UINT8 *Ptr, *CurrentAddress;\r |
f9f937d2 | 124 | UINT32 Address;\r |
125 | UINT32 Count;\r | |
126 | CHAR8 Buffer[80];\r | |
f3198cba | 127 | UINT32 ItBlock;\r |
f9f937d2 | 128 | \r |
129 | if (Argc < 2) {\r | |
130 | return EFI_INVALID_PARAMETER;\r | |
131 | }\r | |
132 | \r | |
133 | Address = AsciiStrHexToUintn (Argv[1]);\r | |
77844905 | 134 | Count = (Argc > 2) ? (UINT32)AsciiStrHexToUintn (Argv[2]) : 20;\r |
f9f937d2 | 135 | \r |
136 | Ptr = (UINT8 *)(UINTN)Address; \r | |
f3198cba | 137 | ItBlock = 0;\r |
77844905 | 138 | do {\r |
139 | CurrentAddress = Ptr;\r | |
f3198cba | 140 | DisassembleInstruction (&Ptr, TRUE, TRUE, &ItBlock, Buffer, sizeof (Buffer));\r |
77844905 | 141 | AsciiPrint ("0x%08x: %a\n", CurrentAddress, Buffer);\r |
142 | } while (Count-- > 0);\r | |
143 | \r | |
f9f937d2 | 144 | \r |
6f72e28d | 145 | return EFI_SUCCESS;\r |
146 | }\r | |
147 | \r | |
148 | \r | |
2ef2b01e A |
149 | GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =\r |
150 | {\r | |
6f72e28d | 151 | {\r |
f9f937d2 | 152 | "disasm address [count]",\r |
153 | " disassemble count instructions",\r | |
6f72e28d | 154 | NULL,\r |
f9f937d2 | 155 | EblDisassembler\r |
b2a73e21 | 156 | },\r |
157 | {\r | |
b8758b6e | 158 | "symboltable [\"format string\"] [PECOFF]",\r |
b2a73e21 | 159 | " show symbol table commands for debugger",\r |
160 | NULL,\r | |
161 | EblSymbolTable\r | |
6f72e28d | 162 | }\r |
2ef2b01e A |
163 | };\r |
164 | \r | |
165 | \r | |
166 | VOID\r | |
167 | EblInitializeExternalCmd (\r | |
168 | VOID\r | |
169 | )\r | |
170 | {\r | |
171 | EblAddCommands (mLibCmdTemplate, sizeof (mLibCmdTemplate)/sizeof (EBL_COMMAND_TABLE));\r | |
172 | return;\r | |
173 | }\r |