DynamicTablesPkg: Add HexDump for CM Object parser

Add helper function HexDump for printing hex dump of CM Object fields.

Also merge multiple flavors of PrintCharX into one function PrintChars
by using the field length.

Signed-off-by: Dat Mach <dmach@nvidia.com>
This commit is contained in:
Dat Mach 2024-06-18 17:50:02 -07:00 committed by mergify[bot]
parent 75a9afa540
commit d24df10cee
2 changed files with 53 additions and 81 deletions

View File

@ -3,6 +3,7 @@
Copyright (c) 2021 - 2023, ARM Limited. All rights reserved.<BR> Copyright (c) 2021 - 2023, ARM Limited. All rights reserved.<BR>
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -17,7 +18,8 @@ VOID
EFIAPI EFIAPI
PrintString ( PrintString (
CONST CHAR8 *Format, CONST CHAR8 *Format,
UINT8 *Ptr UINT8 *Ptr,
UINT32 Length
); );
STATIC STATIC
@ -25,31 +27,26 @@ VOID
EFIAPI EFIAPI
PrintStringPtr ( PrintStringPtr (
CONST CHAR8 *Format, CONST CHAR8 *Format,
UINT8 *Ptr UINT8 *Ptr,
UINT32 Length
); );
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintChar4 ( PrintChars (
CONST CHAR8 *Format, CONST CHAR8 *Format,
UINT8 *Ptr UINT8 *Ptr,
UINT32 Length
); );
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintChar6 ( HexDump (
CONST CHAR8 *Format, CONST CHAR8 *Format,
UINT8 *Ptr UINT8 *Ptr,
); UINT32 Length
STATIC
VOID
EFIAPI
PrintChar8 (
CONST CHAR8 *Format,
UINT8 *Ptr
); );
/** A parser for EArmObjBootArchInfo. /** A parser for EArmObjBootArchInfo.
@ -859,20 +856,20 @@ STATIC CONST CM_OBJ_PARSER_ARRAY X64NamespaceObjectParser[] = {
/** A parser for EStdObjCfgMgrInfo. /** A parser for EStdObjCfgMgrInfo.
*/ */
STATIC CONST CM_OBJ_PARSER StdObjCfgMgrInfoParser[] = { STATIC CONST CM_OBJ_PARSER StdObjCfgMgrInfoParser[] = {
{ "Revision", 4, "0x%x", NULL }, { "Revision", 4, "0x%x", NULL },
{ "OemId[6]", 6, "%c%c%c%c%c%c", PrintChar6 } { "OemId[6]", 6, NULL, PrintChars }
}; };
/** A parser for EStdObjAcpiTableList. /** A parser for EStdObjAcpiTableList.
*/ */
STATIC CONST CM_OBJ_PARSER StdObjAcpiTableInfoParser[] = { STATIC CONST CM_OBJ_PARSER StdObjAcpiTableInfoParser[] = {
{ "AcpiTableSignature", 4, "%c%c%c%c", PrintChar4 }, { "AcpiTableSignature", 4, NULL, PrintChars },
{ "AcpiTableRevision", 1, "%d", NULL }, { "AcpiTableRevision", 1, "%d", NULL },
{ "TableGeneratorId", sizeof (ACPI_TABLE_GENERATOR_ID), "0x%x", NULL }, { "TableGeneratorId", sizeof (ACPI_TABLE_GENERATOR_ID), "0x%x", NULL },
{ "AcpiTableData", sizeof (EFI_ACPI_DESCRIPTION_HEADER *), "0x%p", NULL }, { "AcpiTableData", sizeof (EFI_ACPI_DESCRIPTION_HEADER *), "0x%p", NULL },
{ "OemTableId", 8, "%c%c%c%c%c%c%c%c", PrintChar8 }, { "OemTableId", 8, NULL, PrintChars },
{ "OemRevision", 4, "0x%x", NULL }, { "OemRevision", 4, "0x%x", NULL },
{ "MinorRevision", 1, "0x%x", NULL }, { "MinorRevision", 1, "0x%x", NULL },
}; };
/** A parser for EStdObjSmbiosTableList. /** A parser for EStdObjSmbiosTableList.
@ -897,13 +894,15 @@ STATIC CONST CM_OBJ_PARSER_ARRAY StdNamespaceObjectParser[] = {
@param [in] Format Format to print the Ptr. @param [in] Format Format to print the Ptr.
@param [in] Ptr Pointer to the string. @param [in] Ptr Pointer to the string.
@param [in] Length Length of the field
**/ **/
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintString ( PrintString (
IN CONST CHAR8 *Format, IN CONST CHAR8 *Format,
IN UINT8 *Ptr IN UINT8 *Ptr,
IN UINT32 Length
) )
{ {
if (Ptr == NULL) { if (Ptr == NULL) {
@ -911,7 +910,7 @@ PrintString (
return; return;
} }
DEBUG ((DEBUG_ERROR, "%a", Ptr)); DEBUG ((DEBUG_INFO, "%a", Ptr));
} }
/** Print string from pointer. /** Print string from pointer.
@ -920,13 +919,15 @@ PrintString (
@param [in] Format Format to print the string. @param [in] Format Format to print the string.
@param [in] Ptr Pointer to the string pointer. @param [in] Ptr Pointer to the string pointer.
@param [in] Length Length of the field
**/ **/
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintStringPtr ( PrintStringPtr (
IN CONST CHAR8 *Format, IN CONST CHAR8 *Format,
IN UINT8 *Ptr IN UINT8 *Ptr,
IN UINT32 Length
) )
{ {
UINT8 *String; UINT8 *String;
@ -942,82 +943,51 @@ PrintStringPtr (
String = (UINT8 *)"(NULLPTR)"; String = (UINT8 *)"(NULLPTR)";
} }
PrintString (Format, String); PrintString (Format, String, Length);
} }
/** Print 4 characters. /** Print characters.
@param [in] Format Format to print the Ptr. @param [in] Format Format to print the Ptr.
@param [in] Ptr Pointer to the characters. @param [in] Ptr Pointer to the characters.
@param [in] Length Length of the field
**/ **/
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintChar4 ( PrintChars (
IN CONST CHAR8 *Format, IN CONST CHAR8 *Format,
IN UINT8 *Ptr IN UINT8 *Ptr,
IN UINT32 Length
) )
{ {
DEBUG (( UINT32 Index;
DEBUG_ERROR,
(Format != NULL) ? Format : "%c%c%c%c", for (Index = 0; Index < Length; Index++) {
Ptr[0], DEBUG ((DEBUG_INFO, "%c", Ptr[Index]));
Ptr[1], }
Ptr[2],
Ptr[3]
));
} }
/** Print 6 characters. /** Dump data in Hex format
@param [in] Format Format to print the Ptr. @param [in] Format Format to print the Ptr.
@param [in] Ptr Pointer to the characters. @param [in] Ptr Pointer to the string.
@param [in] Length Length of the field
**/ **/
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
PrintChar6 ( HexDump (
IN CONST CHAR8 *Format, IN CONST CHAR8 *Format,
IN UINT8 *Ptr IN UINT8 *Ptr,
IN UINT32 Length
) )
{ {
DEBUG (( UINT32 Index;
DEBUG_ERROR,
(Format != NULL) ? Format : "%c%c%c%c%c%c",
Ptr[0],
Ptr[1],
Ptr[2],
Ptr[3],
Ptr[4],
Ptr[5]
));
}
/** Print 8 characters. for (Index = 0; Index < Length; Index++) {
DEBUG ((DEBUG_INFO, "0x%02x ", *Ptr++));
@param [in] Format Format to print the Ptr. }
@param [in] Ptr Pointer to the characters.
**/
STATIC
VOID
EFIAPI
PrintChar8 (
IN CONST CHAR8 *Format,
IN UINT8 *Ptr
)
{
DEBUG ((
DEBUG_ERROR,
(Format != NULL) ? Format : "%c%c%c%c%c%c%c%c",
Ptr[0],
Ptr[1],
Ptr[2],
Ptr[3],
Ptr[4],
Ptr[5],
Ptr[6],
Ptr[7]
));
} }
/** Print fields of the objects. /** Print fields of the objects.
@ -1079,7 +1049,7 @@ PrintCmObjDesc (
Parser[Index].NameStr Parser[Index].NameStr
)); ));
if (Parser[Index].PrintFormatter != NULL) { if (Parser[Index].PrintFormatter != NULL) {
Parser[Index].PrintFormatter (Parser[Index].Format, Data); Parser[Index].PrintFormatter (Parser[Index].Format, Data, Parser[Index].Length);
} else if (Parser[Index].Format != NULL) { } else if (Parser[Index].Format != NULL) {
switch (Parser[Index].Length) { switch (Parser[Index].Length) {
case 1: case 1:

View File

@ -2,6 +2,7 @@
Configuration Manager Object parser. Configuration Manager Object parser.
Copyright (c) 2021, ARM Limited. All rights reserved.<BR> Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -28,8 +29,9 @@
@param [in] Format Format string for tracing the data as specified by @param [in] Format Format string for tracing the data as specified by
the 'Format' member of ACPI_PARSER. the 'Format' member of ACPI_PARSER.
@param [in] Ptr Pointer to the start of the buffer. @param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the field
**/ **/
typedef VOID (EFIAPI *FNPTR_PRINT_FORMATTER)(CONST CHAR8 *Format, UINT8 *Ptr); typedef VOID (EFIAPI *FNPTR_PRINT_FORMATTER)(CONST CHAR8 *Format, UINT8 *Ptr, UINT32 Length);
/** /**
The CM_OBJ_PARSER structure describes the fields of an CmObject and The CM_OBJ_PARSER structure describes the fields of an CmObject and