]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c
Add "Debug1" profile (all but Edit and HexEdit commands)
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Dmem.c
1 /** @file
2 Main file for Dmem shell Debug1 function.
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 #include <Protocol/PciRootBridgeIo.h>
17
18 CHAR16
19 MakePrintable(
20 IN CONST CHAR16 Char
21 )
22 {
23 if ((Char < 0x20 && Char > 0)||(Char > 126)) {
24 return (L'?');
25 }
26 return (Char);
27 }
28
29 SHELL_STATUS
30 EFIAPI
31 DisplayMmioMemory(
32 IN CONST VOID *Address,
33 IN CONST UINTN Size
34 )
35 {
36 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRbIo;
37 EFI_STATUS Status;
38 VOID *Buffer;
39 SHELL_STATUS ShellStatus;
40
41 ShellStatus = SHELL_SUCCESS;
42
43 Status = gBS->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid, NULL, (VOID**)&PciRbIo);
44 if (EFI_ERROR(Status)) {
45 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle);
46 return (SHELL_NOT_FOUND);
47 }
48 Buffer = AllocateZeroPool(Size);
49 ASSERT(Buffer != NULL);
50
51 Status = PciRbIo->Mem.Read(PciRbIo, EfiPciWidthUint8, (UINT64)Address, Size, Buffer);
52 if (EFI_ERROR(Status)) {
53 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_ER), gShellDebug1HiiHandle, Status);
54 ShellStatus = SHELL_NOT_FOUND;
55 } else {
56 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)Address, Size);
57 DumpHex(2,0,Size,Buffer);
58 }
59
60 FreePool(Buffer);
61 return (ShellStatus);
62 }
63
64 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
65 {L"-mmio", TypeFlag},
66 {NULL, TypeMax}
67 };
68
69 SHELL_STATUS
70 EFIAPI
71 ShellCommandRunDmem (
72 IN EFI_HANDLE ImageHandle,
73 IN EFI_SYSTEM_TABLE *SystemTable
74 )
75 {
76 EFI_STATUS Status;
77 LIST_ENTRY *Package;
78 CHAR16 *ProblemParam;
79 SHELL_STATUS ShellStatus;
80 VOID *Address;
81 UINTN Size;
82 CONST CHAR16 *Temp1;
83
84 ShellStatus = SHELL_SUCCESS;
85 Status = EFI_SUCCESS;
86 Address = NULL;
87 Size = 0;
88
89 //
90 // initialize the shell lib (we must be in non-auto-init...)
91 //
92 Status = ShellInitialize();
93 ASSERT_EFI_ERROR(Status);
94
95 Status = CommandInit();
96 ASSERT_EFI_ERROR(Status);
97
98 //
99 // parse the command line
100 //
101 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
102 if (EFI_ERROR(Status)) {
103 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
104 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
105 FreePool(ProblemParam);
106 ShellStatus = SHELL_INVALID_PARAMETER;
107 } else {
108 ASSERT(FALSE);
109 }
110 } else {
111 Temp1 = ShellCommandLineGetRawValue(Package, 1);
112 if (Temp1 == NULL) {
113 Address = gST;
114 Size = 512;
115 } else {
116 if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE)) {
117 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);
118 ShellStatus = SHELL_INVALID_PARAMETER;
119 } else {
120 Address = (VOID*)StrHexToUintn(Temp1);
121 }
122 Temp1 = ShellCommandLineGetRawValue(Package, 2);
123 if (Temp1 == NULL) {
124 Size = 512;
125 } else {
126 if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {
127 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);
128 ShellStatus = SHELL_INVALID_PARAMETER;
129 } else {
130 Size = ShellStrToUintn(Temp1);
131 }
132 }
133 }
134
135 if (ShellStatus == SHELL_SUCCESS) {
136 if (!ShellCommandLineGetFlag(Package, L"-mmio")) {
137 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)Address, Size);
138 DumpHex(2,0,Size,Address);
139 } else {
140 ShellStatus = DisplayMmioMemory(Address, Size);
141 }
142 }
143
144
145 ShellCommandLineFreeVarList (Package);
146 }
147
148 return (ShellStatus);
149 }