]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
Fixed issue that addition LEFT CTRL key was detected when press PAUSE key. PS2 keybo...
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Mm.c
CommitLineData
5d73d92f 1/** @file\r
2 Main file for Mm shell Debug1 function.\r
3\r
3737ac2b 4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
5d73d92f 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellDebug1CommandsLib.h"\r
16#include <Library/ShellLib.h>\r
17#include <Protocol/PciRootBridgeIo.h>\r
18#include <Protocol/DeviceIo.h>\r
19\r
20typedef enum {\r
21 EfiMemory,\r
22 EFIMemoryMappedIo,\r
23 EfiIo,\r
24 EfiPciConfig,\r
25 EfiPciEConfig\r
26} EFI_ACCESS_TYPE;\r
27\r
3737ac2b 28STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
29 {L"-mmio", TypeFlag},\r
30 {L"-mem", TypeFlag},\r
31 {L"-io", TypeFlag},\r
32 {L"-pci", TypeFlag},\r
33 {L"-pcie", TypeFlag},\r
34 {L"-n", TypeFlag},\r
35 {L"-w", TypeValue},\r
36 {NULL, TypeMax}\r
37 };\r
38\r
e0c2cc6f 39STATIC CONST UINT64 MaxNum[9] = { 0xff, 0xffff, 0xffffffff, 0xffffffffffffffffULL };\r
3737ac2b 40\r
41/**\r
42 Read some data into a buffer from memory.\r
5d73d92f 43\r
3737ac2b 44 @param[in] Width The width of each read.\r
45 @param[in] Addresss The memory location to start reading at.\r
46 @param[in] Size The size of Buffer in Width sized units.\r
47 @param[out] Buffer The buffer to read into.\r
48**/\r
5d73d92f 49VOID\r
50EFIAPI\r
51ReadMem (\r
52 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
53 IN UINT64 Address,\r
54 IN UINTN Size,\r
3737ac2b 55 OUT VOID *Buffer\r
56 )\r
57{\r
58 //\r
59 // This function is defective. This ASSERT prevents the defect from affecting anything.\r
60 //\r
61 ASSERT(Size == 1);\r
62 do {\r
63 if (Width == EfiPciWidthUint8) {\r
64 *(UINT8 *) Buffer = *(UINT8 *) (UINTN) Address;\r
65 Address -= 1;\r
66 } else if (Width == EfiPciWidthUint16) {\r
67 *(UINT16 *) Buffer = *(UINT16 *) (UINTN) Address;\r
68 Address -= 2;\r
69 } else if (Width == EfiPciWidthUint32) {\r
70 *(UINT32 *) Buffer = *(UINT32 *) (UINTN) Address;\r
71 Address -= 4;\r
72 } else if (Width == EfiPciWidthUint64) {\r
73 *(UINT64 *) Buffer = *(UINT64 *) (UINTN) Address;\r
74 Address -= 8;\r
75 } else {\r
76 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_READ_ERROR), gShellDebug1HiiHandle);\r
77 break;\r
78 }\r
79 Size--;\r
80 } while (Size > 0);\r
81}\r
82\r
83/**\r
84 Write some data to memory.\r
5d73d92f 85\r
3737ac2b 86 @param[in] Width The width of each write.\r
87 @param[in] Addresss The memory location to start writing at.\r
88 @param[in] Size The size of Buffer in Width sized units.\r
89 @param[in] Buffer The buffer to write from.\r
90**/\r
5d73d92f 91VOID\r
92EFIAPI\r
93WriteMem (\r
94 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
95 IN UINT64 Address,\r
96 IN UINTN Size,\r
97 IN VOID *Buffer\r
3737ac2b 98 )\r
99{\r
100 //\r
101 // This function is defective. This ASSERT prevents the defect from affecting anything.\r
102 //\r
103 ASSERT(Size == 1);\r
104 do {\r
105 if (Width == EfiPciWidthUint8) {\r
106 *(UINT8 *) (UINTN) Address = *(UINT8 *) Buffer;\r
107 Address += 1;\r
108 } else if (Width == EfiPciWidthUint16) {\r
109 *(UINT16 *) (UINTN) Address = *(UINT16 *) Buffer;\r
110 Address += 2;\r
111 } else if (Width == EfiPciWidthUint32) {\r
112 *(UINT32 *) (UINTN) Address = *(UINT32 *) Buffer;\r
113 Address += 4;\r
114 } else if (Width == EfiPciWidthUint64) {\r
115 *(UINT64 *) (UINTN) Address = *(UINT64 *) Buffer;\r
116 Address += 8;\r
117 } else {\r
118 ASSERT (FALSE);\r
119 }\r
120 //\r
121 //\r
122 //\r
123 Size--;\r
124 } while (Size > 0);\r
125}\r
5d73d92f 126\r
3737ac2b 127/**\r
128 Convert a string to it's hex data.\r
129\r
130 @param[in] str The pointer to the string of hex data.\r
131 @param[out] data The pointer to the buffer to fill. Valid upon a TRUE return.\r
132\r
133 @retval TRUE The conversion was successful.\r
134 @retval FALSE The conversion failed.\r
135**/\r
5d73d92f 136BOOLEAN\r
137EFIAPI\r
138GetHex (\r
139 IN UINT16 *str,\r
140 OUT UINT64 *data\r
3737ac2b 141 )\r
142{\r
143 UINTN TempUint;\r
144 CHAR16 TempChar;\r
145 BOOLEAN Find;\r
5d73d92f 146\r
3737ac2b 147 Find = FALSE;\r
148 //\r
149 // convert hex digits\r
150 //\r
151 TempUint = 0;\r
152 TempChar = *(str++);\r
153 while (TempChar != CHAR_NULL) {\r
154 if (TempChar >= 'a' && TempChar <= 'f') {\r
155 TempChar -= 'a' - 'A';\r
156 }\r
5d73d92f 157\r
3737ac2b 158 if (TempChar == ' ') {\r
159 break;\r
160 }\r
161\r
162 if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r
f3c59716 163 TempUint = (TempUint << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r
3737ac2b 164\r
165 Find = TRUE;\r
166 } else {\r
167 return FALSE;\r
168 }\r
169\r
170 TempChar = *(str++);\r
171 }\r
172\r
173 *data = TempUint;\r
174 return Find;\r
175}\r
5d73d92f 176\r
177/**\r
178 Get the PCI-E Address from a PCI address format 0x0000ssbbddffrrr\r
179 where ss is SEGMENT, bb is BUS, dd is DEVICE, ff is FUNCTION\r
180 and rrr is REGISTER (extension format for PCI-E).\r
181\r
182 @param[in] InputAddress PCI address format on input.\r
183 @param[out]PciEAddress PCI-E address extention format.\r
184**/\r
185VOID\r
186EFIAPI\r
187GetPciEAddressFromInputAddress (\r
188 IN UINT64 InputAddress,\r
189 OUT UINT64 *PciEAddress\r
190 )\r
191{\r
192 *PciEAddress = RShiftU64(InputAddress & ~(UINT64) 0xFFF, 4);\r
193 *PciEAddress += LShiftU64((UINT16) InputAddress & 0x0FFF, 32);\r
194}\r
195\r
196/**\r
197 Function for 'mm' command.\r
198\r
199 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
200 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
201**/\r
202SHELL_STATUS\r
203EFIAPI\r
204ShellCommandRunMm (\r
205 IN EFI_HANDLE ImageHandle,\r
206 IN EFI_SYSTEM_TABLE *SystemTable\r
207 )\r
208{\r
209 EFI_STATUS Status;\r
210 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev;\r
211 UINT64 Address;\r
212 UINT64 PciEAddress;\r
213 UINT64 Value;\r
214 UINT32 SegmentNumber;\r
215 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width;\r
216 EFI_ACCESS_TYPE AccessType;\r
217 UINT64 Buffer;\r
218 UINTN Index;\r
219 UINTN Size;\r
220 CHAR16 *AddressStr;\r
221// CHAR16 *ValueStr;\r
222 BOOLEAN Complete;\r
223 CHAR16 *InputStr;\r
224 BOOLEAN Interactive;\r
225 EFI_HANDLE *HandleBuffer;\r
226 UINTN BufferSize;\r
227 UINTN ItemValue;\r
228 LIST_ENTRY *Package;\r
229 CHAR16 *ProblemParam;\r
230 SHELL_STATUS ShellStatus;\r
231 CONST CHAR16 *Temp;\r
232\r
233 Address = 0;\r
234 PciEAddress = 0;\r
235 IoDev = NULL;\r
236 HandleBuffer = NULL;\r
237 BufferSize = 0;\r
238 SegmentNumber = 0;\r
239 ShellStatus = SHELL_SUCCESS;\r
240 InputStr = NULL;\r
241\r
242 //\r
243 // Parse arguments\r
244 //\r
245 Width = EfiPciWidthUint8;\r
246 Size = 1;\r
247 AccessType = EfiMemory;\r
248 AddressStr = NULL;\r
249// ValueStr = NULL;\r
250 Interactive = TRUE;\r
251 Package = NULL;\r
252\r
253 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
254 if (EFI_ERROR(Status)) {\r
255 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
256 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
257 FreePool(ProblemParam);\r
258 ShellStatus = SHELL_INVALID_PARAMETER;\r
259 goto Done;\r
260 } else {\r
261 ASSERT(FALSE);\r
262 }\r
263 } else {\r
3737ac2b 264 if (ShellCommandLineGetCount(Package) < 2) {\r
5d73d92f 265 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
266 ShellStatus = SHELL_INVALID_PARAMETER;\r
267 goto Done;\r
268 } else if (ShellCommandLineGetCount(Package) > 3) {\r
269 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
270 ShellStatus = SHELL_INVALID_PARAMETER;\r
271 goto Done;\r
3737ac2b 272 } else if (ShellCommandLineGetFlag(Package, L"-w") && ShellCommandLineGetValue(Package, L"-w") == NULL) {\r
273 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-w");\r
274 ShellStatus = SHELL_INVALID_PARAMETER;\r
275 goto Done;\r
5d73d92f 276 } else {\r
277 if (ShellCommandLineGetFlag(Package, L"-mmio")) {\r
278 AccessType = EFIMemoryMappedIo;\r
3737ac2b 279 if (ShellCommandLineGetFlag(Package, L"-mem")\r
280 ||ShellCommandLineGetFlag(Package, L"-io")\r
281 ||ShellCommandLineGetFlag(Package, L"-pci")\r
282 ||ShellCommandLineGetFlag(Package, L"-pcie")\r
283 ){\r
284 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
285 ShellStatus = SHELL_INVALID_PARAMETER;\r
286 goto Done;\r
287 }\r
5d73d92f 288 } else if (ShellCommandLineGetFlag(Package, L"-mem")) {\r
289 AccessType = EfiMemory;\r
3737ac2b 290 if (ShellCommandLineGetFlag(Package, L"-io")\r
291 ||ShellCommandLineGetFlag(Package, L"-pci")\r
292 ||ShellCommandLineGetFlag(Package, L"-pcie")\r
293 ){\r
294 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
295 ShellStatus = SHELL_INVALID_PARAMETER;\r
296 goto Done;\r
297 }\r
5d73d92f 298 } else if (ShellCommandLineGetFlag(Package, L"-io")) {\r
299 AccessType = EfiIo;\r
3737ac2b 300 if (ShellCommandLineGetFlag(Package, L"-pci")\r
301 ||ShellCommandLineGetFlag(Package, L"-pcie")\r
302 ){\r
303 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
304 ShellStatus = SHELL_INVALID_PARAMETER;\r
305 goto Done;\r
306 }\r
5d73d92f 307 } else if (ShellCommandLineGetFlag(Package, L"-pci")) {\r
308 AccessType = EfiPciConfig;\r
3737ac2b 309 if (ShellCommandLineGetFlag(Package, L"-pcie")\r
310 ){\r
311 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
312 ShellStatus = SHELL_INVALID_PARAMETER;\r
313 goto Done;\r
314 }\r
5d73d92f 315 } else if (ShellCommandLineGetFlag(Package, L"-pcie")) {\r
316 AccessType = EfiPciEConfig;\r
317 }\r
318 }\r
319\r
320 if (ShellCommandLineGetFlag (Package, L"-n")) {\r
321 Interactive = FALSE;\r
322 }\r
323\r
324 Temp = ShellCommandLineGetValue(Package, L"-w");\r
325 if (Temp != NULL) {\r
3737ac2b 326 ItemValue = ShellStrToUintn (Temp);\r
5d73d92f 327\r
328 switch (ItemValue) {\r
329 case 1:\r
330 Width = EfiPciWidthUint8;\r
331 Size = 1;\r
332 break;\r
333\r
334 case 2:\r
335 Width = EfiPciWidthUint16;\r
336 Size = 2;\r
337 break;\r
338\r
339 case 4:\r
340 Width = EfiPciWidthUint32;\r
341 Size = 4;\r
342 break;\r
343\r
344 case 8:\r
345 Width = EfiPciWidthUint64;\r
346 Size = 8;\r
347 break;\r
348\r
349 default:\r
3737ac2b 350 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-w");\r
5d73d92f 351 ShellStatus = SHELL_INVALID_PARAMETER;\r
352 goto Done;\r
353 }\r
354 }\r
355\r
356 Temp = ShellCommandLineGetRawValue(Package, 1);\r
3737ac2b 357 if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, (UINT64*)&Address, TRUE, FALSE))) {\r
358 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
359 ShellStatus = SHELL_INVALID_PARAMETER;\r
360 goto Done;\r
5d73d92f 361 }\r
362\r
363 Temp = ShellCommandLineGetRawValue(Package, 2);\r
364 if (Temp != NULL) {\r
3737ac2b 365 if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, &Value, TRUE, FALSE))) {\r
366 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
367 ShellStatus = SHELL_INVALID_PARAMETER;\r
368 goto Done;\r
369 }\r
5d73d92f 370 switch (Size) {\r
371 case 1:\r
372 if (Value > 0xFF) {\r
373 ShellStatus = SHELL_INVALID_PARAMETER;\r
374 }\r
375 break;\r
376\r
377 case 2:\r
378 if (Value > 0xFFFF) {\r
379 ShellStatus = SHELL_INVALID_PARAMETER;\r
380 }\r
381 break;\r
382\r
383 case 4:\r
384 if (Value > 0xFFFFFFFF) {\r
385 ShellStatus = SHELL_INVALID_PARAMETER;\r
386 }\r
387 break;\r
388\r
389 default:\r
390 break;\r
391 }\r
392\r
393 if (ShellStatus != SHELL_SUCCESS) {\r
394 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
395 ShellStatus = SHELL_INVALID_PARAMETER;\r
396 goto Done;\r
397 }\r
398 }\r
399\r
400 if ((Address & (Size - 1)) != 0) {\r
401 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, Address);\r
402 ShellStatus = SHELL_INVALID_PARAMETER;\r
403 goto Done;\r
404 }\r
405 //\r
406 // locate DeviceIO protocol interface\r
407 //\r
408 if (AccessType != EfiMemory) {\r
409 Status = gBS->LocateHandleBuffer (\r
410 ByProtocol,\r
411 &gEfiPciRootBridgeIoProtocolGuid,\r
412 NULL,\r
413 &BufferSize,\r
414 &HandleBuffer\r
415 );\r
416 if (EFI_ERROR (Status)) {\r
417 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle);\r
418 ShellStatus = SHELL_NOT_FOUND;\r
419 goto Done;\r
420 }\r
421 //\r
422 // In the case of PCI or PCIE\r
423 // Get segment number and mask the segment bits in Address\r
424 //\r
425 if (AccessType == EfiPciEConfig) {\r
426 SegmentNumber = (UINT32) RShiftU64 (Address, 36) & 0xff;\r
e0c2cc6f 427 Address &= 0xfffffffffULL;\r
5d73d92f 428 } else {\r
429 if (AccessType == EfiPciConfig) {\r
430 SegmentNumber = (UINT32) RShiftU64 (Address, 32) & 0xff;\r
431 Address &= 0xffffffff;\r
432 }\r
433 }\r
434 //\r
435 // Find the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL of the specified segment number\r
436 //\r
437 for (Index = 0; Index < BufferSize; Index++) {\r
438 Status = gBS->HandleProtocol (\r
439 HandleBuffer[Index],\r
440 &gEfiPciRootBridgeIoProtocolGuid,\r
441 (VOID *) &IoDev\r
442 );\r
443 if (EFI_ERROR (Status)) {\r
444 continue;\r
445 }\r
446 if (IoDev->SegmentNumber != SegmentNumber) {\r
447 IoDev = NULL;\r
448 }\r
449 }\r
450 if (IoDev == NULL) {\r
5d73d92f 451 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_SEGMENT_NOT_FOUND), gShellDebug1HiiHandle, SegmentNumber);\r
452 ShellStatus = SHELL_INVALID_PARAMETER;\r
453 goto Done;\r
454 }\r
455 }\r
456\r
457 if (AccessType == EfiIo && Address + Size > 0x10000) {\r
458 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE), gShellDebug1HiiHandle);\r
459 ShellStatus = SHELL_INVALID_PARAMETER;\r
460 goto Done;\r
461 }\r
462\r
463 if (AccessType == EfiPciEConfig) {\r
464 GetPciEAddressFromInputAddress (Address, &PciEAddress);\r
465 }\r
466\r
467// //\r
468// // Set value\r
469// //\r
470// if (ValueStr != NULL) {\r
471// if (AccessType == EFIMemoryMappedIo) {\r
472// IoDev->Mem.Write (IoDev, Width, Address, 1, &Value);\r
473// } else if (AccessType == EfiIo) {\r
474// IoDev->Io.Write (IoDev, Width, Address, 1, &Value);\r
475// } else if (AccessType == EfiPciConfig) {\r
476// IoDev->Pci.Write (IoDev, Width, Address, 1, &Value);\r
477// } else if (AccessType == EfiPciEConfig) {\r
478// IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Buffer);\r
479// } else {\r
480// WriteMem (Width, Address, 1, &Value);\r
481// }\r
482//\r
483// ASSERT(ShellStatus == SHELL_SUCCESS);\r
484// goto Done;\r
485// }\r
486\r
487\r
488 //\r
489 // non-interactive mode\r
490 //\r
491 if (!Interactive) {\r
492 Buffer = 0;\r
493 if (AccessType == EFIMemoryMappedIo) {\r
494 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);\r
495 IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);\r
496 } else if (AccessType == EfiIo) {\r
497 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);\r
498 IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);\r
499 } else if (AccessType == EfiPciConfig) {\r
500 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);\r
501 IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);\r
502 } else if (AccessType == EfiPciEConfig) {\r
3737ac2b 503 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);\r
5d73d92f 504 IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);\r
505 } else {\r
3737ac2b 506 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);\r
5d73d92f 507 ReadMem (Width, Address, 1, &Buffer);\r
508 }\r
509\r
510 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);\r
511 if (Size == 1) {\r
512 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, Buffer);\r
513 } else if (Size == 2) {\r
514 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, Buffer);\r
515 } else if (Size == 4) {\r
516 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, Buffer);\r
517 } else if (Size == 8) {\r
518 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);\r
519 }\r
520\r
521 ShellPrintEx(-1, -1, L"\r\n");\r
522\r
523 ASSERT(ShellStatus == SHELL_SUCCESS);\r
524 goto Done;\r
525 }\r
526 //\r
527 // interactive mode\r
528 //\r
529 Complete = FALSE;\r
530 do {\r
531 if (AccessType == EfiIo && Address + Size > 0x10000) {\r
532 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle);\r
5d73d92f 533 break;\r
534 }\r
535\r
536 Buffer = 0;\r
537 if (AccessType == EFIMemoryMappedIo) {\r
538 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);\r
5d73d92f 539 IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);\r
540 } else if (AccessType == EfiIo) {\r
541 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);\r
5d73d92f 542 IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);\r
543 } else if (AccessType == EfiPciConfig) {\r
544 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);\r
5d73d92f 545 IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);\r
546 } else if (AccessType == EfiPciEConfig) {\r
547 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);\r
5d73d92f 548 IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);\r
549 } else {\r
550 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);\r
5d73d92f 551 ReadMem (Width, Address, 1, &Buffer);\r
552 }\r
553\r
554 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);\r
5d73d92f 555\r
556 if (Size == 1) {\r
557 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, Buffer);\r
5d73d92f 558 } else if (Size == 2) {\r
559 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, Buffer);\r
5d73d92f 560 } else if (Size == 4) {\r
561 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, Buffer);\r
5d73d92f 562 } else if (Size == 8) {\r
563 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);\r
5d73d92f 564 }\r
3737ac2b 565 ShellPrintEx(-1, -1, L" > ");\r
5d73d92f 566 //\r
567 // wait user input to modify\r
568 //\r
569 if (InputStr != NULL) {\r
570 FreePool(InputStr);\r
3737ac2b 571 InputStr = NULL;\r
5d73d92f 572 }\r
573 ShellPromptForResponse(ShellPromptResponseTypeFreeform, NULL, (VOID**)&InputStr);\r
574\r
575 //\r
576 // skip space characters\r
577 //\r
3737ac2b 578 for (Index = 0; InputStr != NULL && InputStr[Index] == ' '; Index++);\r
5d73d92f 579\r
580 //\r
581 // parse input string\r
582 //\r
3737ac2b 583 if (InputStr != NULL && (InputStr[Index] == '.' || InputStr[Index] == 'q' || InputStr[Index] == 'Q')) {\r
5d73d92f 584 Complete = TRUE;\r
3737ac2b 585 } else if (InputStr == NULL || InputStr[Index] == CHAR_NULL) {\r
5d73d92f 586 //\r
587 // Continue to next address\r
588 //\r
589 } else if (GetHex (InputStr + Index, &Buffer) && Buffer <= MaxNum[Width]) {\r
590 if (AccessType == EFIMemoryMappedIo) {\r
591 IoDev->Mem.Write (IoDev, Width, Address, 1, &Buffer);\r
592 } else if (AccessType == EfiIo) {\r
593 IoDev->Io.Write (IoDev, Width, Address, 1, &Buffer);\r
594 } else if (AccessType == EfiPciConfig) {\r
595 IoDev->Pci.Write (IoDev, Width, Address, 1, &Buffer);\r
596 } else if (AccessType == EfiPciEConfig) {\r
597 IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Buffer);\r
598 } else {\r
599 WriteMem (Width, Address, 1, &Buffer);\r
600 }\r
601 } else {\r
602 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle);\r
5d73d92f 603 continue;\r
3737ac2b 604 // PrintToken (STRING_TOKEN (STR_IOMOD_ERROR), HiiHandle);\r
5d73d92f 605 }\r
606\r
607 Address += Size;\r
608 if (AccessType == EfiPciEConfig) {\r
609 GetPciEAddressFromInputAddress (Address, &PciEAddress);\r
610 }\r
611 ShellPrintEx(-1, -1, L"\r\n");\r
612 // Print (L"\n");\r
613 } while (!Complete);\r
614 }\r
615 ASSERT(ShellStatus == SHELL_SUCCESS);\r
616Done:\r
617\r
618 if (InputStr != NULL) {\r
619 FreePool(InputStr);\r
620 }\r
621 if (HandleBuffer != NULL) {\r
622 FreePool (HandleBuffer);\r
623 }\r
624 if (Package != NULL) {\r
625 ShellCommandLineFreeVarList (Package);\r
626 }\r
627 return ShellStatus;\r
628}\r