From: "Tomas Pilar (tpilar)" <Tomas.Pilar@arm.com>
To: <devel@edk2.groups.io>
Cc: <Sami.Mujawar@arm.com>, <nd@arm.com>, Ray Ni <ray.ni@intel.com>,
"Zhichao Gao" <zhichao.gao@intel.com>
Subject: [PATCH v2 6/8] ShellPkg/AcpiView: Refactor dump helpers
Date: Sun, 12 Jul 2020 11:32:13 +0100 [thread overview]
Message-ID: <20200712103215.855-7-Tomas.Pilar@arm.com> (raw)
In-Reply-To: <20200712103215.855-1-Tomas.Pilar@arm.com>
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@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Tomas Pilar <tomas.pilar@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
next prev parent reply other threads:[~2020-07-12 10:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-12 10:32 [PATCH v2 0/8] ShellPkg/AcpiView: Refactor Error Logging Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 1/8] ShellPkg/AcpiView: Extract configuration struct Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 2/8] ShellPkg/AcpiView: Declutter error counters Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 3/8] ShellPkg/AcpiView: Modify error message Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 4/8] ShellPkg/AcpiView: Create a logging facility Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 5/8] ShellPkg/AcpiView: Refactor PrintFieldName Tomas Pilar (tpilar)
2020-07-12 10:32 ` Tomas Pilar (tpilar) [this message]
2020-07-12 10:32 ` [PATCH v2 7/8] ShellPkg/AcpiView: Refactor AcpiView Tomas Pilar (tpilar)
2020-07-12 10:32 ` [PATCH v2 8/8] ShellPkg/AcpiView: Refactor table parsers Tomas Pilar (tpilar)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200712103215.855-7-Tomas.Pilar@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox