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 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.
38 if ((Char
< 0x20 && Char
> 0)||(Char
> 126)) {
45 Display some Memory-Mapped-IO memory.
47 @param[in] Address The starting address to display.
48 @param[in] Size The length of memory to display.
52 IN CONST VOID
*Address
,
56 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRbIo
;
59 SHELL_STATUS ShellStatus
;
61 ShellStatus
= SHELL_SUCCESS
;
63 Status
= gBS
->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid
, NULL
, (VOID
**)&PciRbIo
);
64 if (EFI_ERROR(Status
)) {
65 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_NF
), gShellDebug1HiiHandle
, L
"dmem");
66 return (SHELL_NOT_FOUND
);
68 Buffer
= AllocateZeroPool(Size
);
70 return SHELL_OUT_OF_RESOURCES
;
73 Status
= PciRbIo
->Mem
.Read(PciRbIo
, EfiPciWidthUint8
, (UINT64
)(UINTN
)Address
, Size
, Buffer
);
74 if (EFI_ERROR(Status
)) {
75 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_ER
), gShellDebug1HiiHandle
, L
"dmem");
76 ShellStatus
= SHELL_NOT_FOUND
;
78 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
79 DumpHex(2, (UINTN
)Address
, Size
, Buffer
);
86 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
92 Function for 'dmem' command.
94 @param[in] ImageHandle Handle to the Image (NULL if Internal).
95 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
100 IN EFI_HANDLE ImageHandle
,
101 IN EFI_SYSTEM_TABLE
*SystemTable
106 CHAR16
*ProblemParam
;
107 SHELL_STATUS ShellStatus
;
111 UINT64 AcpiTableAddress
;
112 UINT64 Acpi20TableAddress
;
113 UINT64 SalTableAddress
;
114 UINT64 SmbiosTableAddress
;
115 UINT64 MpsTableAddress
;
118 ShellStatus
= SHELL_SUCCESS
;
119 Status
= EFI_SUCCESS
;
124 // initialize the shell lib (we must be in non-auto-init...)
126 Status
= ShellInitialize();
127 ASSERT_EFI_ERROR(Status
);
129 Status
= CommandInit();
130 ASSERT_EFI_ERROR(Status
);
133 // parse the command line
135 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
136 if (EFI_ERROR(Status
)) {
137 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
138 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"dmem", ProblemParam
);
139 FreePool(ProblemParam
);
140 ShellStatus
= SHELL_INVALID_PARAMETER
;
145 if (ShellCommandLineGetCount(Package
) > 3) {
146 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmem");
147 ShellStatus
= SHELL_INVALID_PARAMETER
;
149 Temp1
= ShellCommandLineGetRawValue(Package
, 1);
152 Size
= sizeof (*gST
);
154 if (!ShellIsHexOrDecimalNumber(Temp1
, TRUE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, (UINT64
*)&Address
, TRUE
, FALSE
))) {
155 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
156 ShellStatus
= SHELL_INVALID_PARAMETER
;
158 Temp1
= ShellCommandLineGetRawValue(Package
, 2);
162 if (!ShellIsHexOrDecimalNumber(Temp1
, FALSE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, &Size
, TRUE
, FALSE
))) {
163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmem", Temp1
);
164 ShellStatus
= SHELL_INVALID_PARAMETER
;
170 if (ShellStatus
== SHELL_SUCCESS
) {
171 if (!ShellCommandLineGetFlag(Package
, L
"-mmio")) {
172 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
173 DumpHex(2, (UINTN
)Address
, (UINTN
)Size
, Address
);
174 if (Address
== (VOID
*)gST
) {
175 Acpi20TableAddress
= 0;
176 AcpiTableAddress
= 0;
178 SmbiosTableAddress
= 0;
180 for (TableWalker
= 0 ; TableWalker
< gST
->NumberOfTableEntries
; TableWalker
++) {
181 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi20TableGuid
)) {
182 Acpi20TableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
185 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
186 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
189 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSalSystemTableGuid
)) {
190 SalTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
193 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
194 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
197 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbios3TableGuid
)) {
198 SmbiosTableAddress
= (UINT64
) (UINTN
) gST
->ConfigurationTable
[TableWalker
].VendorTable
;
201 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiMpsTableGuid
)) {
202 MpsTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
207 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE
), gShellDebug1HiiHandle
,
208 (UINT64
)(UINTN
)Address
,
211 (UINT64
)(UINTN
)gST
->ConIn
,
212 (UINT64
)(UINTN
)gST
->ConOut
,
213 (UINT64
)(UINTN
)gST
->StdErr
,
214 (UINT64
)(UINTN
)gST
->RuntimeServices
,
215 (UINT64
)(UINTN
)gST
->BootServices
,
224 ShellStatus
= DisplayMmioMemory(Address
, (UINTN
)Size
);
229 ShellCommandLineFreeVarList (Package
);
232 return (ShellStatus
);