]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
Add "Debug1" profile (all but Edit and HexEdit commands)
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / UefiShellDebug1CommandsLib.c
1 /** @file
2 Main file for NULL named library for debug1 profile shell command functions.
3
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellDebug1CommandsLib.h"
16
17 STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";
18 EFI_HANDLE gShellDebug1HiiHandle = NULL;
19 CONST EFI_GUID gShellDebug1HiiGuid = \
20 { \
21 0x25f200aa, 0xd3cb, 0x470a, { 0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f } \
22 };
23
24 CONST CHAR16*
25 EFIAPI
26 ShellCommandGetManFileNameDebug1 (
27 VOID
28 )
29 {
30 return (mFileName);
31 }
32
33 /**
34 Constructor for the Shell Debug1 Commands library.
35
36 @param ImageHandle the image handle of the process
37 @param SystemTable the EFI System Table pointer
38
39 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
40 @retval EFI_UNSUPPORTED the shell level required was not found.
41 **/
42 EFI_STATUS
43 EFIAPI
44 UefiShellDebug1CommandsLibConstructor (
45 IN EFI_HANDLE ImageHandle,
46 IN EFI_SYSTEM_TABLE *SystemTable
47 )
48 {
49 //
50 // check our bit of the profiles mask
51 //
52 if ((PcdGet8(PcdShellProfileMask) & BIT1) == 0) {
53 return (EFI_UNSUPPORTED);
54 }
55
56 //
57 // install the HII stuff.
58 //
59 gShellDebug1HiiHandle = HiiAddPackages (&gShellDebug1HiiGuid, gImageHandle, UefiShellDebug1CommandsLibStrings, NULL);
60 if (gShellDebug1HiiHandle == NULL) {
61 return (EFI_DEVICE_ERROR);
62 }
63
64 //
65 // install our shell command handlers that are always installed
66 //
67 ShellCommandRegisterCommandName(L"SetSize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
68 ShellCommandRegisterCommandName(L"comp", ShellCommandRunComp , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_COMP) );
69 ShellCommandRegisterCommandName(L"mode", ShellCommandRunMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MODE) );
70 ShellCommandRegisterCommandName(L"memmap", ShellCommandRunMemMap , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MEMMAP) );
71 ShellCommandRegisterCommandName(L"eficompress", ShellCommandRunEfiCompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFICOMPRESS) );
72 ShellCommandRegisterCommandName(L"efidecompress", ShellCommandRunEfiDecompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFIDCOMPRESS) );
73 ShellCommandRegisterCommandName(L"dmem", ShellCommandRunDmem , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMEM) );
74 ShellCommandRegisterCommandName(L"LoadPciRom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
75 ShellCommandRegisterCommandName(L"mm", ShellCommandRunMm , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MM) );
76 ShellCommandRegisterCommandName(L"SetVar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
77 ShellCommandRegisterCommandName(L"SerMode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
78 ShellCommandRegisterCommandName(L"Pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
79 ShellCommandRegisterCommandName(L"smbiosview", ShellCommandRunSmbiosView , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SMBIOSVIEW) );
80 ShellCommandRegisterCommandName(L"dmpstore", ShellCommandRunDmpStore , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMPSTORE) );
81 ShellCommandRegisterCommandName(L"dblk", ShellCommandRunDblk , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DBLK) );
82
83 //
84 // check install profile bit of the profiles mask is set
85 //
86 if ((PcdGet8(PcdShellProfileMask) & BIT2) == 0) {
87 ShellCommandRegisterCommandName(L"bcfg", ShellCommandRunBcfg , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG) );
88 }
89
90 /*
91 ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT );
92 ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
93 */
94
95 ShellCommandRegisterAlias(L"dmem", L"mem");
96
97 return (EFI_SUCCESS);
98 }
99
100 /**
101 Destructor for the library. free any resources.
102 **/
103 EFI_STATUS
104 EFIAPI
105 UefiShellDebug1CommandsLibDestructor (
106 IN EFI_HANDLE ImageHandle,
107 IN EFI_SYSTEM_TABLE *SystemTable
108 )
109 {
110 if (gShellDebug1HiiHandle != NULL) {
111 HiiRemovePackages(gShellDebug1HiiHandle);
112 }
113 return (EFI_SUCCESS);
114 }
115
116 STATIC CONST CHAR8 Hex[] = {
117 '0',
118 '1',
119 '2',
120 '3',
121 '4',
122 '5',
123 '6',
124 '7',
125 '8',
126 '9',
127 'A',
128 'B',
129 'C',
130 'D',
131 'E',
132 'F'
133 };
134
135 VOID
136 EFIAPI
137 DumpHex (
138 IN UINTN Indent,
139 IN UINTN Offset,
140 IN UINTN DataSize,
141 IN VOID *UserData
142 )
143 {
144 UINT8 *Data;
145
146 CHAR8 Val[50];
147
148 CHAR8 Str[20];
149
150 UINT8 c;
151 UINTN Size;
152 UINTN Index;
153
154 ASSERT (UserData != NULL);
155
156 Data = UserData;
157 while (DataSize != 0) {
158 Size = 16;
159 if (Size > DataSize) {
160 Size = DataSize;
161 }
162
163 for (Index = 0; Index < Size; Index += 1) {
164 c = Data[Index];
165 Val[Index * 3 + 0] = Hex[c >> 4];
166 Val[Index * 3 + 1] = Hex[c & 0xF];
167 Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');
168 Str[Index] = (CHAR8) ((c < ' ' || c > 'z') ? '.' : c);
169 }
170
171 Val[Index * 3] = 0;
172 Str[Index] = 0;
173 ShellPrintEx(-1, -1, L"%*a%02X: %-.48a *%a*\r\n", Indent, "", Offset, Val, Str);
174
175 Data += Size;
176 Offset += Size;
177 DataSize -= Size;
178 }
179 }
180
181 /**
182 Convert a Unicode character to upper case only if
183 it maps to a valid small-case ASCII character.
184
185 This internal function only deal with Unicode character
186 which maps to a valid small-case ASCII character, i.e.
187 L'a' to L'z'. For other Unicode character, the input character
188 is returned directly.
189
190 @param Char The character to convert.
191
192 @retval LowerCharacter If the Char is with range L'a' to L'z'.
193 @retval Unchanged Otherwise.
194
195
196 //Stolen from MdePkg Baselib
197 **/
198 CHAR16
199 EFIAPI
200 CharToUpper (
201 IN CHAR16 Char
202 )
203 {
204 if (Char >= L'a' && Char <= L'z') {
205 return (CHAR16) (Char - (L'a' - L'A'));
206 }
207
208 return Char;
209 }
210
211 /**
212 Function returns a system configuration table that is stored in the
213 EFI System Table based on the provided GUID.
214
215 @param[in] TableGuid A pointer to the table's GUID type.
216 @param[out] Table On exit, a pointer to a system configuration table.
217
218 @retval EFI_SUCCESS A configuration table matching TableGuid was found.
219 @retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.
220 **/
221 EFI_STATUS
222 EFIAPI
223 GetSystemConfigurationTable (
224 IN EFI_GUID *TableGuid,
225 IN OUT VOID **Table
226 )
227 {
228 UINTN Index;
229 ASSERT (Table != NULL);
230
231 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
232 if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid)) == 0) {
233 *Table = gST->ConfigurationTable[Index].VendorTable;
234 return EFI_SUCCESS;
235 }
236 }
237
238 return EFI_NOT_FOUND;
239 }
240
241 /**
242 Convert a Unicode character to numerical value.
243
244 This internal function only deal with Unicode character
245 which maps to a valid hexadecimal ASII character, i.e.
246 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
247 Unicode character, the value returned does not make sense.
248
249 @param Char The character to convert.
250
251 @return The numerical value converted.
252
253 **/
254 UINTN
255 EFIAPI
256 HexCharToUintn (
257 IN CHAR16 Char
258 )
259 {
260 if (Char >= L'0' && Char <= L'9') {
261 return Char - L'0';
262 }
263
264 return (UINTN) (10 + CharToUpper (Char) - L'A');
265 }
266
267 EFI_STATUS
268 EFIAPI
269 ConvertStringToGuid (
270 IN CONST CHAR16 *StringGuid,
271 IN OUT EFI_GUID *Guid
272 )
273 {
274 if (StrLen(StringGuid) != 35) {
275 return (EFI_INVALID_PARAMETER);
276 } else {
277 Guid->Data1 = (UINT32)StrHexToUintn(StringGuid);
278 StringGuid += 9;
279 Guid->Data2 = (UINT16)StrHexToUintn(StringGuid);
280 StringGuid += 5;
281 Guid->Data3 = (UINT16)StrHexToUintn(StringGuid);
282 StringGuid += 5;
283 Guid->Data4[0] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
284 Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(StringGuid[1]));
285 StringGuid += 2;
286 Guid->Data4[1] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
287 Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(StringGuid[1]));
288 StringGuid += 2;
289 Guid->Data4[2] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
290 Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(StringGuid[1]));
291 StringGuid += 2;
292 Guid->Data4[3] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
293 Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(StringGuid[1]));
294 StringGuid += 2;
295 Guid->Data4[4] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
296 Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(StringGuid[1]));
297 StringGuid += 2;
298 Guid->Data4[5] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
299 Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(StringGuid[1]));
300 StringGuid += 2;
301 Guid->Data4[6] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
302 Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(StringGuid[1]));
303 StringGuid += 2;
304 Guid->Data4[7] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
305 Guid->Data4[7] = (UINT8)(Guid->Data4[7] = (UINT8)HexCharToUintn(StringGuid[1]));
306 return (EFI_SUCCESS);
307 }
308 }
309