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>
18 Make a printable character.
20 If Char is printable then return it, otherwise return a question mark.
22 @param[in] Char The character to make printable.
24 @return A printable character representing Char.
31 if ((Char
< 0x20 && Char
> 0)||(Char
> 126)) {
38 Display some Memory-Mapped-IO memory.
40 @param[in] Address The starting address to display.
41 @param[in] Size The length of memory to display.
45 IN CONST VOID
*Address
,
49 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRbIo
;
52 SHELL_STATUS ShellStatus
;
54 ShellStatus
= SHELL_SUCCESS
;
56 Status
= gBS
->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid
, NULL
, (VOID
**)&PciRbIo
);
57 if (EFI_ERROR(Status
)) {
58 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_NF
), gShellDebug1HiiHandle
, L
"dmem");
59 return (SHELL_NOT_FOUND
);
61 Buffer
= AllocateZeroPool(Size
);
63 return SHELL_OUT_OF_RESOURCES
;
66 Status
= PciRbIo
->Mem
.Read(PciRbIo
, EfiPciWidthUint8
, (UINT64
)(UINTN
)Address
, Size
, Buffer
);
67 if (EFI_ERROR(Status
)) {
68 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_ER
), gShellDebug1HiiHandle
, L
"dmem");
69 ShellStatus
= SHELL_NOT_FOUND
;
71 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
72 DumpHex(2, (UINTN
)Address
, Size
, Buffer
);
79 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
85 Function for 'dmem' command.
87 @param[in] ImageHandle Handle to the Image (NULL if Internal).
88 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
93 IN EFI_HANDLE ImageHandle
,
94 IN EFI_SYSTEM_TABLE
*SystemTable
100 SHELL_STATUS ShellStatus
;
104 UINT64 AcpiTableAddress
;
105 UINT64 Acpi20TableAddress
;
106 UINT64 SalTableAddress
;
107 UINT64 SmbiosTableAddress
;
108 UINT64 MpsTableAddress
;
111 ShellStatus
= SHELL_SUCCESS
;
112 Status
= EFI_SUCCESS
;
117 // initialize the shell lib (we must be in non-auto-init...)
119 Status
= ShellInitialize();
120 ASSERT_EFI_ERROR(Status
);
122 Status
= CommandInit();
123 ASSERT_EFI_ERROR(Status
);
126 // parse the command line
128 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
129 if (EFI_ERROR(Status
)) {
130 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
131 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"dmem", ProblemParam
);
132 FreePool(ProblemParam
);
133 ShellStatus
= SHELL_INVALID_PARAMETER
;
138 if (ShellCommandLineGetCount(Package
) > 3) {
139 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmem");
140 ShellStatus
= SHELL_INVALID_PARAMETER
;
142 Temp1
= ShellCommandLineGetRawValue(Package
, 1);
145 Size
= sizeof (*gST
);
147 if (!ShellIsHexOrDecimalNumber(Temp1
, TRUE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, (UINT64
*)&Address
, TRUE
, FALSE
))) {
148 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
149 ShellStatus
= SHELL_INVALID_PARAMETER
;
151 Temp1
= ShellCommandLineGetRawValue(Package
, 2);
155 if (!ShellIsHexOrDecimalNumber(Temp1
, FALSE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, &Size
, TRUE
, FALSE
))) {
156 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
157 ShellStatus
= SHELL_INVALID_PARAMETER
;
163 if (ShellStatus
== SHELL_SUCCESS
) {
164 if (!ShellCommandLineGetFlag(Package
, L
"-mmio")) {
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
166 DumpHex(2, (UINTN
)Address
, (UINTN
)Size
, Address
);
167 if (Address
== (VOID
*)gST
) {
168 Acpi20TableAddress
= 0;
169 AcpiTableAddress
= 0;
171 SmbiosTableAddress
= 0;
173 for (TableWalker
= 0 ; TableWalker
< gST
->NumberOfTableEntries
; TableWalker
++) {
174 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi20TableGuid
)) {
175 Acpi20TableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
178 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
179 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
182 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
183 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
186 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbios3TableGuid
)) {
187 SmbiosTableAddress
= (UINT64
) (UINTN
) gST
->ConfigurationTable
[TableWalker
].VendorTable
;
190 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiMpsTableGuid
)) {
191 MpsTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
196 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE
), gShellDebug1HiiHandle
,
197 (UINT64
)(UINTN
)Address
,
200 (UINT64
)(UINTN
)gST
->ConIn
,
201 (UINT64
)(UINTN
)gST
->ConOut
,
202 (UINT64
)(UINTN
)gST
->StdErr
,
203 (UINT64
)(UINTN
)gST
->RuntimeServices
,
204 (UINT64
)(UINTN
)gST
->BootServices
,
213 ShellStatus
= DisplayMmioMemory(Address
, (UINTN
)Size
);
218 ShellCommandLineFreeVarList (Package
);
221 return (ShellStatus
);