2 Main file for Dmem shell Debug1 function.
4 Copyright (c) 2010 - 2018, 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 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "UefiShellDebug1CommandsLib.h"
12 #include <Protocol/PciRootBridgeIo.h>
13 #include <Guid/Acpi.h>
15 #include <Guid/SmBios.h>
16 #include <Guid/SalSystemTable.h>
19 Make a printable character.
21 If Char is printable then return it, otherwise return a question mark.
23 @param[in] Char The character to make printable.
25 @return A printable character representing Char.
32 if ((Char
< 0x20 && Char
> 0)||(Char
> 126)) {
39 Display some Memory-Mapped-IO memory.
41 @param[in] Address The starting address to display.
42 @param[in] Size The length of memory to display.
46 IN CONST VOID
*Address
,
50 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRbIo
;
53 SHELL_STATUS ShellStatus
;
55 ShellStatus
= SHELL_SUCCESS
;
57 Status
= gBS
->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid
, NULL
, (VOID
**)&PciRbIo
);
58 if (EFI_ERROR(Status
)) {
59 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_NF
), gShellDebug1HiiHandle
, L
"dmem");
60 return (SHELL_NOT_FOUND
);
62 Buffer
= AllocateZeroPool(Size
);
64 return SHELL_OUT_OF_RESOURCES
;
67 Status
= PciRbIo
->Mem
.Read(PciRbIo
, EfiPciWidthUint8
, (UINT64
)(UINTN
)Address
, Size
, Buffer
);
68 if (EFI_ERROR(Status
)) {
69 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_ER
), gShellDebug1HiiHandle
, L
"dmem");
70 ShellStatus
= SHELL_NOT_FOUND
;
72 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
73 DumpHex(2, (UINTN
)Address
, Size
, Buffer
);
80 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
86 Function for 'dmem' command.
88 @param[in] ImageHandle Handle to the Image (NULL if Internal).
89 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
94 IN EFI_HANDLE ImageHandle
,
95 IN EFI_SYSTEM_TABLE
*SystemTable
100 CHAR16
*ProblemParam
;
101 SHELL_STATUS ShellStatus
;
105 UINT64 AcpiTableAddress
;
106 UINT64 Acpi20TableAddress
;
107 UINT64 SalTableAddress
;
108 UINT64 SmbiosTableAddress
;
109 UINT64 MpsTableAddress
;
112 ShellStatus
= SHELL_SUCCESS
;
113 Status
= EFI_SUCCESS
;
118 // initialize the shell lib (we must be in non-auto-init...)
120 Status
= ShellInitialize();
121 ASSERT_EFI_ERROR(Status
);
123 Status
= CommandInit();
124 ASSERT_EFI_ERROR(Status
);
127 // parse the command line
129 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
130 if (EFI_ERROR(Status
)) {
131 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
132 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"dmem", ProblemParam
);
133 FreePool(ProblemParam
);
134 ShellStatus
= SHELL_INVALID_PARAMETER
;
139 if (ShellCommandLineGetCount(Package
) > 3) {
140 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmem");
141 ShellStatus
= SHELL_INVALID_PARAMETER
;
143 Temp1
= ShellCommandLineGetRawValue(Package
, 1);
146 Size
= sizeof (*gST
);
148 if (!ShellIsHexOrDecimalNumber(Temp1
, TRUE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, (UINT64
*)&Address
, TRUE
, FALSE
))) {
149 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
150 ShellStatus
= SHELL_INVALID_PARAMETER
;
152 Temp1
= ShellCommandLineGetRawValue(Package
, 2);
156 if (!ShellIsHexOrDecimalNumber(Temp1
, FALSE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, &Size
, TRUE
, FALSE
))) {
157 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
158 ShellStatus
= SHELL_INVALID_PARAMETER
;
164 if (ShellStatus
== SHELL_SUCCESS
) {
165 if (!ShellCommandLineGetFlag(Package
, L
"-mmio")) {
166 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
167 DumpHex(2, (UINTN
)Address
, (UINTN
)Size
, Address
);
168 if (Address
== (VOID
*)gST
) {
169 Acpi20TableAddress
= 0;
170 AcpiTableAddress
= 0;
172 SmbiosTableAddress
= 0;
174 for (TableWalker
= 0 ; TableWalker
< gST
->NumberOfTableEntries
; TableWalker
++) {
175 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi20TableGuid
)) {
176 Acpi20TableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
179 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
180 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
183 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSalSystemTableGuid
)) {
184 SalTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
187 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
188 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
191 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbios3TableGuid
)) {
192 SmbiosTableAddress
= (UINT64
) (UINTN
) gST
->ConfigurationTable
[TableWalker
].VendorTable
;
195 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiMpsTableGuid
)) {
196 MpsTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
201 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE
), gShellDebug1HiiHandle
,
202 (UINT64
)(UINTN
)Address
,
205 (UINT64
)(UINTN
)gST
->ConIn
,
206 (UINT64
)(UINTN
)gST
->ConOut
,
207 (UINT64
)(UINTN
)gST
->StdErr
,
208 (UINT64
)(UINTN
)gST
->RuntimeServices
,
209 (UINT64
)(UINTN
)gST
->BootServices
,
218 ShellStatus
= DisplayMmioMemory(Address
, (UINTN
)Size
);
223 ShellCommandLineFreeVarList (Package
);
226 return (ShellStatus
);