]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c
Clarify that the shared variables of the shell protocols are properly named.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Dmem.c
index b8ab9c69e60954955f0ca705721f87a94ca42b22..dfee96bb295d17811c2b23a460e8bd7111ae9e28 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Dmem shell Debug1 function.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 #include "UefiShellDebug1CommandsLib.h"\r
 #include <Protocol/PciRootBridgeIo.h>\r
+#include <Guid/Acpi.h>\r
+#include <Guid/Mps.h>\r
+#include <Guid/SmBios.h>\r
+#include <Guid/SalSystemTable.h>\r
 \r
+/**\r
+  Make a printable character.\r
+\r
+  If Char is printable then return it, otherwise return a question mark.\r
+\r
+  @param[in] Char     The character to make printable.\r
+\r
+  @return A printable character representing Char.\r
+**/\r
 CHAR16\r
+EFIAPI\r
 MakePrintable(\r
   IN CONST CHAR16 Char\r
   )\r
@@ -26,6 +40,12 @@ MakePrintable(
   return (Char);\r
 }\r
 \r
+/**\r
+  Display some Memory-Mapped-IO memory.\r
+\r
+  @param[in] Address    The starting address to display.\r
+  @param[in] Size       The length of memory to display.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 DisplayMmioMemory(\r
@@ -48,12 +68,12 @@ DisplayMmioMemory(
   Buffer = AllocateZeroPool(Size);\r
   ASSERT(Buffer != NULL);\r
 \r
-  Status = PciRbIo->Mem.Read(PciRbIo, EfiPciWidthUint8, (UINT64)Address, Size, Buffer);\r
+  Status = PciRbIo->Mem.Read(PciRbIo, EfiPciWidthUint8, (UINT64)(UINTN)Address, Size, Buffer);\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_ER), gShellDebug1HiiHandle, Status);\r
     ShellStatus = SHELL_NOT_FOUND;\r
   } else {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)Address, Size);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);\r
     DumpHex(2,0,Size,Buffer);\r
   }\r
 \r
@@ -66,6 +86,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {NULL, TypeMax}\r
   };\r
 \r
+/**\r
+  Function for 'dmem' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ShellCommandRunDmem (\r
@@ -78,8 +104,14 @@ ShellCommandRunDmem (
   CHAR16              *ProblemParam;\r
   SHELL_STATUS        ShellStatus;\r
   VOID                *Address;\r
-  UINT              Size;\r
+  UINT64              Size;\r
   CONST CHAR16        *Temp1;\r
+  UINT64              AcpiTableAddress;\r
+  UINT64              Acpi20TableAddress;\r
+  UINT64              SalTableAddress;\r
+  UINT64              SmbiosTableAddress;\r
+  UINT64              MpsTableAddress;\r
+  UINTN               TableWalker;\r
 \r
   ShellStatus         = SHELL_SUCCESS;\r
   Status              = EFI_SUCCESS;\r
@@ -108,36 +140,82 @@ ShellCommandRunDmem (
       ASSERT(FALSE);\r
     }\r
   } else {\r
-    Temp1 = ShellCommandLineGetRawValue(Package, 1);\r
-    if (Temp1 == NULL) {\r
-      Address = gST;\r
-      Size = 512;\r
+    if (ShellCommandLineGetCount(Package) > 3) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
-      if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE)) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);\r
-        ShellStatus = SHELL_INVALID_PARAMETER;\r
-      } else {\r
-        Address = (VOID*)StrHexToUintn(Temp1);\r
-      }\r
-      Temp1 = ShellCommandLineGetRawValue(Package, 2);\r
+      Temp1 = ShellCommandLineGetRawValue(Package, 1);\r
       if (Temp1 == NULL) {\r
+        Address = gST;\r
         Size = 512;\r
       } else {\r
-        if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {\r
+        if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, (UINT64*)&Address, TRUE, FALSE))) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
+        } \r
+        Temp1 = ShellCommandLineGetRawValue(Package, 2);\r
+        if (Temp1 == NULL) {\r
+          Size = 512;\r
         } else {\r
-          Size = ShellStrToUintn(Temp1);\r
+          if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, &Size, TRUE, FALSE))) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
+          }\r
         }\r
       }\r
     }\r
 \r
     if (ShellStatus == SHELL_SUCCESS) {\r
       if (!ShellCommandLineGetFlag(Package, L"-mmio")) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)Address, Size);\r
-        DumpHex(2,0,Size,Address);\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);\r
+        DumpHex(2,0,(UINTN)Size,Address);\r
+        if (Address == (VOID*)gST) {\r
+          Acpi20TableAddress  = 0;\r
+          AcpiTableAddress    = 0;\r
+          SalTableAddress     = 0;\r
+          SmbiosTableAddress  = 0;\r
+          MpsTableAddress     = 0;\r
+          for (TableWalker = 0 ; TableWalker < gST->NumberOfTableEntries ; TableWalker++) {\r
+            if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi20TableGuid)) {\r
+              Acpi20TableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;\r
+              continue;\r
+            }\r
+            if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi10TableGuid)) {\r
+              AcpiTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;\r
+              continue;\r
+            }\r
+            if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSalSystemTableGuid)) {\r
+              SalTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;\r
+              continue;\r
+            }\r
+            if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbiosTableGuid)) {\r
+              SmbiosTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;\r
+              continue;\r
+            }\r
+            if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMpsTableGuid)) {\r
+              MpsTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;\r
+              continue;\r
+            }\r
+          }\r
+\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE), gShellDebug1HiiHandle, \r
+            (UINT64)(UINTN)Address,\r
+            gST->Hdr.HeaderSize,\r
+            gST->Hdr.Revision,\r
+            (UINT64)(UINTN)gST->ConIn,\r
+            (UINT64)(UINTN)gST->ConOut,\r
+            (UINT64)(UINTN)gST->StdErr,\r
+            (UINT64)(UINTN)gST->RuntimeServices,\r
+            (UINT64)(UINTN)gST->BootServices,\r
+            SalTableAddress,\r
+            AcpiTableAddress,\r
+            Acpi20TableAddress,\r
+            MpsTableAddress,\r
+            SmbiosTableAddress\r
+            );\r
+        }\r
       } else {\r
-        ShellStatus = DisplayMmioMemory(Address, Size);\r
+        ShellStatus = DisplayMmioMemory(Address, (UINTN)Size);\r
       }\r
     }\r
 \r