2 Main file for Dmem shell Debug1 function.
4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellDebug1CommandsLib.h"
16 #include <Protocol/PciRootBridgeIo.h>
17 #include <Guid/Acpi.h>
19 #include <Guid/SmBios.h>
20 #include <Guid/SalSystemTable.h>
23 Make a printable character.
25 If Char is printable then return it, otherwise return a question mark.
27 @param[in] Char The character to make printable.
29 @return A printable character representing Char.
37 if ((Char
< 0x20 && Char
> 0)||(Char
> 126)) {
44 Display some Memory-Mapped-IO memory.
46 @param[in] Address The starting address to display.
47 @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
);
66 return (SHELL_NOT_FOUND
);
68 Buffer
= AllocateZeroPool(Size
);
69 ASSERT(Buffer
!= NULL
);
71 Status
= PciRbIo
->Mem
.Read(PciRbIo
, EfiPciWidthUint8
, (UINT64
)(UINTN
)Address
, Size
, Buffer
);
72 if (EFI_ERROR(Status
)) {
73 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PCIRBIO_ER
), gShellDebug1HiiHandle
, Status
);
74 ShellStatus
= SHELL_NOT_FOUND
;
76 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
77 DumpHex(2, (UINTN
)Address
, Size
, Buffer
);
84 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
90 Function for 'dmem' command.
92 @param[in] ImageHandle Handle to the Image (NULL if Internal).
93 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
98 IN EFI_HANDLE ImageHandle
,
99 IN EFI_SYSTEM_TABLE
*SystemTable
104 CHAR16
*ProblemParam
;
105 SHELL_STATUS ShellStatus
;
109 UINT64 AcpiTableAddress
;
110 UINT64 Acpi20TableAddress
;
111 UINT64 SalTableAddress
;
112 UINT64 SmbiosTableAddress
;
113 UINT64 MpsTableAddress
;
116 ShellStatus
= SHELL_SUCCESS
;
117 Status
= EFI_SUCCESS
;
122 // initialize the shell lib (we must be in non-auto-init...)
124 Status
= ShellInitialize();
125 ASSERT_EFI_ERROR(Status
);
127 Status
= CommandInit();
128 ASSERT_EFI_ERROR(Status
);
131 // parse the command line
133 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
134 if (EFI_ERROR(Status
)) {
135 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
136 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
137 FreePool(ProblemParam
);
138 ShellStatus
= SHELL_INVALID_PARAMETER
;
143 if (ShellCommandLineGetCount(Package
) > 3) {
144 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
145 ShellStatus
= SHELL_INVALID_PARAMETER
;
147 Temp1
= ShellCommandLineGetRawValue(Package
, 1);
152 if (!ShellIsHexOrDecimalNumber(Temp1
, TRUE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, (UINT64
*)&Address
, TRUE
, FALSE
))) {
153 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp1
);
154 ShellStatus
= SHELL_INVALID_PARAMETER
;
156 Temp1
= ShellCommandLineGetRawValue(Package
, 2);
160 if (!ShellIsHexOrDecimalNumber(Temp1
, FALSE
, FALSE
) || EFI_ERROR(ShellConvertStringToUint64(Temp1
, &Size
, TRUE
, FALSE
))) {
161 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp1
);
162 ShellStatus
= SHELL_INVALID_PARAMETER
;
168 if (ShellStatus
== SHELL_SUCCESS
) {
169 if (!ShellCommandLineGetFlag(Package
, L
"-mmio")) {
170 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMEM_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
171 DumpHex(2, (UINTN
)Address
, (UINTN
)Size
, Address
);
172 if (Address
== (VOID
*)gST
) {
173 Acpi20TableAddress
= 0;
174 AcpiTableAddress
= 0;
176 SmbiosTableAddress
= 0;
178 for (TableWalker
= 0 ; TableWalker
< gST
->NumberOfTableEntries
; TableWalker
++) {
179 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi20TableGuid
)) {
180 Acpi20TableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
183 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
184 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
187 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSalSystemTableGuid
)) {
188 SalTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
191 if (CompareGuid(&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
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
);