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