2 Main file for Dmem shell Debug1 function.
4 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "UefiShellDebug1CommandsLib.h"
18 #include <Protocol/PciRootBridgeIo.h>
19 #include <Guid/Acpi.h>
21 #include <Guid/SmBios.h>
22 #include <Guid/SalSystemTable.h>
25 Make a printable character.
27 If Char is printable then return it, otherwise return a question mark.
29 @param[in] Char The character to make printable.
31 @return A printable character representing Char.
39 if ((Char
< 0x20 && Char
> 0)||(Char
> 126)) {
46 Display some Memory-Mapped-IO memory.
48 @param[in] Address The starting address to display.
49 @param[in] Size The length of memory to display.
54 IN CONST VOID
*Address
,
58 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRbIo
;
61 SHELL_STATUS ShellStatus
;
63 ShellStatus
= SHELL_SUCCESS
;
65 Status
= gBS
->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid
, NULL
, (VOID
**)&PciRbIo
);
66 if (EFI_ERROR(Status
)) {
67 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_NF
), gShellDebug1HiiHandle
, L
"dmem");
68 return (SHELL_NOT_FOUND
);
70 Buffer
= AllocateZeroPool(Size
);
72 return SHELL_OUT_OF_RESOURCES
;
75 Status
= PciRbIo
->Mem
.Read(PciRbIo
, EfiPciWidthUint8
, (UINT64
)(UINTN
)Address
, Size
, Buffer
);
76 if (EFI_ERROR(Status
)) {
77 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_ER
), gShellDebug1HiiHandle
, L
"dmem");
78 ShellStatus
= SHELL_NOT_FOUND
;
80 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
81 DumpHex(2, (UINTN
)Address
, Size
, Buffer
);
88 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
94 Function for 'dmem' command.
96 @param[in] ImageHandle Handle to the Image (NULL if Internal).
97 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
101 ShellCommandRunDmem (
102 IN EFI_HANDLE ImageHandle
,
103 IN EFI_SYSTEM_TABLE
*SystemTable
108 CHAR16
*ProblemParam
;
109 SHELL_STATUS ShellStatus
;
113 UINT64 AcpiTableAddress
;
114 UINT64 Acpi20TableAddress
;
115 UINT64 SalTableAddress
;
116 UINT64 SmbiosTableAddress
;
117 UINT64 MpsTableAddress
;
120 ShellStatus
= SHELL_SUCCESS
;
121 Status
= EFI_SUCCESS
;
126 // initialize the shell lib (we must be in non-auto-init...)
128 Status
= ShellInitialize();
129 ASSERT_EFI_ERROR(Status
);
131 Status
= CommandInit();
132 ASSERT_EFI_ERROR(Status
);
135 // parse the command line
137 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
138 if (EFI_ERROR(Status
)) {
139 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
140 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"dmem", ProblemParam
);
141 FreePool(ProblemParam
);
142 ShellStatus
= SHELL_INVALID_PARAMETER
;
147 if (ShellCommandLineGetCount(Package
) > 3) {
148 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmem");
149 ShellStatus
= SHELL_INVALID_PARAMETER
;
151 Temp1
= ShellCommandLineGetRawValue(Package
, 1);
156 if (!ShellIsHexOrDecimalNumber(Temp1
, TRUE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, (UINT64
*)&Address
, TRUE
, FALSE
))) {
157 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
158 ShellStatus
= SHELL_INVALID_PARAMETER
;
160 Temp1
= ShellCommandLineGetRawValue(Package
, 2);
164 if (!ShellIsHexOrDecimalNumber(Temp1
, FALSE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, &Size
, TRUE
, FALSE
))) {
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
166 ShellStatus
= SHELL_INVALID_PARAMETER
;
172 if (ShellStatus
== SHELL_SUCCESS
) {
173 if (!ShellCommandLineGetFlag(Package
, L
"-mmio")) {
174 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
175 DumpHex(2, (UINTN
)Address
, (UINTN
)Size
, Address
);
176 if (Address
== (VOID
*)gST
) {
177 Acpi20TableAddress
= 0;
178 AcpiTableAddress
= 0;
180 SmbiosTableAddress
= 0;
182 for (TableWalker
= 0 ; TableWalker
< gST
->NumberOfTableEntries
; TableWalker
++) {
183 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi20TableGuid
)) {
184 Acpi20TableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
187 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
188 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
191 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSalSystemTableGuid
)) {
192 SalTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
195 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
196 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
199 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbios3TableGuid
)) {
200 SmbiosTableAddress
= (UINT64
) (UINTN
) gST
->ConfigurationTable
[TableWalker
].VendorTable
;
203 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiMpsTableGuid
)) {
204 MpsTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
209 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE
), gShellDebug1HiiHandle
,
210 (UINT64
)(UINTN
)Address
,
213 (UINT64
)(UINTN
)gST
->ConIn
,
214 (UINT64
)(UINTN
)gST
->ConOut
,
215 (UINT64
)(UINTN
)gST
->StdErr
,
216 (UINT64
)(UINTN
)gST
->RuntimeServices
,
217 (UINT64
)(UINTN
)gST
->BootServices
,
226 ShellStatus
= DisplayMmioMemory(Address
, (UINTN
)Size
);
231 ShellCommandLineFreeVarList (Package
);
234 return (ShellStatus
);