[edk2-devel] [PATCH v2 6/8] ShellPkg/AcpiView: Refactor dump helpers

Tomas Pilar (tpilar) Tomas.Pilar at arm.com
Sun Jul 12 10:32:13 UTC 2020


The dump variable helper functions are refactored into
a separate header file as inline functions to declutter code.

Change-Id: I9c43c9ce1e9809813949b4f45b1b19b6265e18c4
Cc: Ray Ni <ray.ni at intel.com>
Cc: Zhichao Gao <zhichao.gao at intel.com>
Signed-off-by: Tomas Pilar <tomas.pilar at arm.com>
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 212 ---------------
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  | 134 +---------
 .../FieldFormatHelper.h                       | 244 ++++++++++++++++++
 .../UefiShellAcpiViewCommandLib.inf           |   1 +
 4 files changed, 247 insertions(+), 344 deletions(-)
 create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 54d87e2768e1..65108e25ff96 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -176,218 +176,6 @@ DumpRaw (
   Print (L"  %a\n\n", AsciiBuffer);
 }
 
-/**
-  This function traces 1 byte of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint8 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  )
-{
-  Print (Format, *Ptr);
-}
-
-/**
-  This function traces 2 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint16 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  )
-{
-  Print (Format, *(UINT16*)Ptr);
-}
-
-/**
-  This function traces 4 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint32 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  )
-{
-  Print (Format, *(UINT32*)Ptr);
-}
-
-/**
-  This function traces 8 bytes of data as specified by the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint64 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  )
-{
-  // Some fields are not aligned and this causes alignment faults
-  // on ARM platforms if the compiler generates LDRD instructions.
-  // Perform word access so that LDRD instructions are not generated.
-  UINT64 Val;
-
-  Val = *(UINT32*)(Ptr + sizeof (UINT32));
-
-  Val = LShiftU64(Val,32);
-  Val |= (UINT64)*(UINT32*)Ptr;
-
-  Print (Format, Val);
-}
-
-/**
-  This function traces 3 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump3Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  )
-{
-  Print (
-    (Format != NULL) ? Format : L"%c%c%c",
-    Ptr[0],
-    Ptr[1],
-    Ptr[2]
-    );
-}
-
-/**
-  This function traces 4 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump4Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  )
-{
-  Print (
-    (Format != NULL) ? Format : L"%c%c%c%c",
-    Ptr[0],
-    Ptr[1],
-    Ptr[2],
-    Ptr[3]
-    );
-}
-
-/**
-  This function traces 6 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump6Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  )
-{
-  Print (
-    (Format != NULL) ? Format : L"%c%c%c%c%c%c",
-    Ptr[0],
-    Ptr[1],
-    Ptr[2],
-    Ptr[3],
-    Ptr[4],
-    Ptr[5]
-    );
-}
-
-/**
-  This function traces 8 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump8Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  )
-{
-  Print (
-    (Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c",
-    Ptr[0],
-    Ptr[1],
-    Ptr[2],
-    Ptr[3],
-    Ptr[4],
-    Ptr[5],
-    Ptr[6],
-    Ptr[7]
-    );
-}
-
-/**
-  This function traces 12 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump12Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN       UINT8*  Ptr
-  )
-{
-  Print (
-    (Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c",
-    Ptr[0],
-    Ptr[1],
-    Ptr[2],
-    Ptr[3],
-    Ptr[4],
-    Ptr[5],
-    Ptr[6],
-    Ptr[7],
-    Ptr[8],
-    Ptr[9],
-    Ptr[10],
-    Ptr[11]
-    );
-}
-
 /**
   This function is used to parse an ACPI table buffer.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index eb0c74eef144..54ce44132055 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -8,6 +8,8 @@
 #ifndef ACPIPARSER_H_
 #define ACPIPARSER_H_
 
+#include "FieldFormatHelper.h"
+
 #define OUTPUT_FIELD_COLUMN_WIDTH  36
 
 /// The RSDP table signature is "RSD PTR " (8 bytes)
@@ -72,138 +74,6 @@ DumpRaw (
   IN UINT32 Length
   );
 
-/**
-  This function traces 1 byte of datum as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint8 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 2 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint16 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 4 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint32 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 8 bytes of data as specified by the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint64 (
-  IN CONST CHAR16* Format,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 3 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump3Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 4 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump4Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 6 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump6Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 8 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump8Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*        Ptr
-  );
-
-/**
-  This function traces 12 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr     Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump12Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN       UINT8*  Ptr
-  );
-
 /**
   This function pointer is the template for customizing the trace output
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h
new file mode 100644
index 000000000000..25c70652806c
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h
@@ -0,0 +1,244 @@
+/** @file
+  Formatting functions used in parser definitions
+
+  Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FIELD_FORMAT_HELPER_H_
+#define FIELD_FORMAT_HELPER_H_
+
+#include <Library/UefiLib.h>
+#include <Uefi.h>
+
+/**
+  This function traces 1 byte of data as specified in the format string.
+
+  @param [in] Format  The format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+DumpUint8 (
+  IN CONST CHAR16* Format,
+  IN UINT8*        Ptr
+  )
+{
+  Print (Format, *Ptr);
+}
+
+/**
+  This function traces 2 bytes of data as specified in the format string.
+
+  @param [in] Format  The format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+DumpUint16 (
+  IN CONST CHAR16* Format,
+  IN UINT8*        Ptr
+  )
+{
+  Print (Format, *(UINT16*)Ptr);
+}
+
+/**
+  This function traces 4 bytes of data as specified in the format string.
+
+  @param [in] Format  The format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+DumpUint32 (
+  IN CONST CHAR16* Format,
+  IN UINT8*        Ptr
+  )
+{
+  Print (Format, *(UINT32*)Ptr);
+}
+
+/**
+  This function traces 8 bytes of data as specified by the format string.
+
+  @param [in] Format  The format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+DumpUint64 (
+  IN CONST CHAR16* Format,
+  IN UINT8*        Ptr
+  )
+{
+  // Some fields are not aligned and this causes alignment faults
+  // on ARM platforms if the compiler generates LDRD instructions.
+  // Perform word access so that LDRD instructions are not generated.
+  UINT64 Val;
+
+  Val = *(UINT32*)(Ptr + sizeof (UINT32));
+
+  Val = LShiftU64(Val,32);
+  Val |= (UINT64)*(UINT32*)Ptr;
+
+  Print (Format, Val);
+}
+
+/**
+  This function traces 3 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+Dump3Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN UINT8*        Ptr
+  )
+{
+  Print (
+    (Format != NULL) ? Format : (CONST CHAR16*) L"%c%c%c",
+    Ptr[0],
+    Ptr[1],
+    Ptr[2]
+    );
+}
+
+/**
+  This function traces 4 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+Dump4Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN UINT8*        Ptr
+  )
+{
+  Print (
+    (Format != NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c",
+    Ptr[0],
+    Ptr[1],
+    Ptr[2],
+    Ptr[3]
+    );
+}
+
+/**
+  This function traces 6 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+Dump6Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN UINT8*        Ptr
+  )
+{
+  Print (
+    (Format != NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c",
+    Ptr[0],
+    Ptr[1],
+    Ptr[2],
+    Ptr[3],
+    Ptr[4],
+    Ptr[5]
+    );
+}
+
+/**
+  This function traces 8 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+Dump8Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN UINT8*        Ptr
+  )
+{
+  Print (
+    (Format != NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c%c%c",
+    Ptr[0],
+    Ptr[1],
+    Ptr[2],
+    Ptr[3],
+    Ptr[4],
+    Ptr[5],
+    Ptr[6],
+    Ptr[7]
+    );
+}
+
+/**
+  This function traces 12 characters which can be optionally
+  formated using the format string if specified.
+
+  If no format string is specified the Format must be NULL.
+
+  @param [in] Format  Optional format string for tracing the data.
+  @param [in] Ptr     Pointer to the start of the buffer.
+**/
+static
+inline
+VOID
+EFIAPI
+Dump12Chars (
+  IN CONST CHAR16* Format OPTIONAL,
+  IN       UINT8*  Ptr
+  )
+{
+  Print (
+    (Format != NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c%c%c%c%c%c%c",
+    Ptr[0],
+    Ptr[1],
+    Ptr[2],
+    Ptr[3],
+    Ptr[4],
+    Ptr[5],
+    Ptr[6],
+    Ptr[7],
+    Ptr[8],
+    Ptr[9],
+    Ptr[10],
+    Ptr[11]
+    );
+}
+
+#endif
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
index e0586cbccec2..271d09a940ee 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
@@ -29,6 +29,7 @@ [Sources.common]
   AcpiViewConfig.h
   AcpiViewLog.h
   AcpiViewLog.c
+  FieldFormatHelper.h
   Parsers/Bgrt/BgrtParser.c
   Parsers/Dbg2/Dbg2Parser.c
   Parsers/Dsdt/DsdtParser.c
-- 
2.24.1.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62380): https://edk2.groups.io/g/devel/message/62380
Mute This Topic: https://groups.io/mt/75454453/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list