From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.82]) by mx.groups.io with SMTP id smtpd.web12.21086.1593444049218695736 for ; Mon, 29 Jun 2020 08:20:49 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=hq9nAASS; spf=pass (domain: arm.com, ip: 40.107.7.82, mailfrom: tomas.pilar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olEpI91Uh6WIjeGwzlRuxAy1zfVIHq3sd46vmdvhgFA=; b=hq9nAASSqCorHgZYMdIM0i2tXhoGjc2FKUiGl+g0WHzwZ8+s9FUULQlX1oOZTNqIrbca4liG5QFy2GOsdPCyqmMHI8pn7rrABJ6s9IkPHOCObGrNk3pJs1Z/1Qj8qab13wCZ/NWbfCI6LTOsJKLXzvC2u4Mp2Dg3HfyFPwl5rQU= Received: from AM5PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:206:1::18) by AM6PR08MB3125.eurprd08.prod.outlook.com (2603:10a6:209:46::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Mon, 29 Jun 2020 15:20:45 +0000 Received: from VE1EUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::e9) by AM5PR04CA0005.outlook.office365.com (2603:10a6:206:1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21 via Frontend Transport; Mon, 29 Jun 2020 15:20:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT056.mail.protection.outlook.com (10.152.19.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Mon, 29 Jun 2020 15:20:45 +0000 Received: ("Tessian outbound fcb8da16d5bd:v60"); Mon, 29 Jun 2020 15:20:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0ec8cf6a0ce0c287 X-CR-MTA-TID: 64aa7808 Received: from b3c057d5a931.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9F9A15F9-B1D9-498E-A033-14FE564086CC.1; Mon, 29 Jun 2020 15:20:39 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b3c057d5a931.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 29 Jun 2020 15:20:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m20KtdLpsOmoGiC30fUGGjAeIgD14/vq+GhpAVdt6ppn7peHVVaB6BI2thhfKb6BcEB2Ib9AEpVOBSJB6arkGqwwdKCuUEWFXd2sPh9EtwsnBH2bPk225vEI/EDR+7SW6Qv0bGyrZRPwHz4BQRUFdPGF5gmD5bRt0OJ1HtmjgL/a8/835sNl4LkH3WdxjGhBhaBoGgA7VX8pCCnKz4oH0dQwRROdT+nkpbUI6nGTAP1oGPqsPGCoWdtWhSO97PulRizLZTmPvoeqQ8pNSI+G5zynm3YOeimN4fGYZbn5psoDhwMS7u4abXET8kpVuTLeSZaSNdMd+/WZmJHVmgOo7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olEpI91Uh6WIjeGwzlRuxAy1zfVIHq3sd46vmdvhgFA=; b=hh8FWerxGf2wiiTwAu7HMUwwQLLvW0s4A09/hvBGfqwviida07XEn+GWK+LxgUiKrFDyJeVxVa/vlglUOsEWnogVrk5eEzfVbvQEbTxXnqrJePc3E+C5YI94sqvNjNxNCxc79KM4ttcQ1k3sr4X56Hz+xKK8TrTo6YioAom1JyIflk6HnFw6ydZem8PgUnRZK993oWxaMAxTSDASMKCHuRoOEb+r5sFe2LNTUGjNAb5chABq6MaYE+SrJ4DUQd5Gii3m5XuPRPm1jeRRvCu7aKUR1UGMvTJdEyU01XGDaEaLeAIxVE4wXHkRvghWtylq0SgfAzN/l//RhIL4SJ2uDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olEpI91Uh6WIjeGwzlRuxAy1zfVIHq3sd46vmdvhgFA=; b=hq9nAASSqCorHgZYMdIM0i2tXhoGjc2FKUiGl+g0WHzwZ8+s9FUULQlX1oOZTNqIrbca4liG5QFy2GOsdPCyqmMHI8pn7rrABJ6s9IkPHOCObGrNk3pJs1Z/1Qj8qab13wCZ/NWbfCI6LTOsJKLXzvC2u4Mp2Dg3HfyFPwl5rQU= Received: from AM6P194CA0037.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::14) by VI1PR08MB5488.eurprd08.prod.outlook.com (2603:10a6:803:137::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Mon, 29 Jun 2020 15:20:38 +0000 Received: from VE1EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::ef) by AM6P194CA0037.outlook.office365.com (2603:10a6:209:84::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Mon, 29 Jun 2020 15:20:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT064.mail.protection.outlook.com (10.152.19.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3131.20 via Frontend Transport; Mon, 29 Jun 2020 15:20:37 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Mon, 29 Jun 2020 15:20:29 +0000 Received: from localhost.localdomain (10.57.4.19) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Mon, 29 Jun 2020 15:20:29 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [PATCH 7/8] ShellPkg/AcpiView: Refactor AcpiView Date: Mon, 29 Jun 2020 16:20:07 +0100 Message-ID: <20200629152008.685-8-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200629152008.685-1-Tomas.Pilar@arm.com> References: <20200629152008.685-1-Tomas.Pilar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(346002)(376002)(136003)(396003)(39860400002)(46966005)(86362001)(426003)(478600001)(47076004)(1076003)(8936002)(356005)(36756003)(6666004)(8676002)(82310400002)(5660300002)(2616005)(83380400001)(316002)(2906002)(81166007)(70206006)(70586007)(30864003)(54906003)(82740400003)(186003)(336012)(26005)(4326008)(6916009);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89a1d1a6-f3a6-4e0b-f5fc-08d81c3ffe97 X-MS-TrafficTypeDiagnostic: VI1PR08MB5488:|AM6PR08MB3125: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-Forefront-PRVS: 044968D9E1 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Sv5kEx/gtjD2hPaYQQOwLHS0eCP8ytObTtqYramyMk9MNza8xsjZJazXTr79I+eA3Uyg6Jv3Do92CIsvueF0Jiuug4EbnCoo391LclIcE6irzOEvIDv5XuTgTYjtft5XGGP+wqTyjkR2RrASqCyfS0nVGkF7Vevpzs9uL9eCqyYGB6M0fnwmdwMIEpzsTc/tBZPmvPsUnwV4uUb5qpeswVzU5yhS+6Xse4YQbsP3mqgoxM79U8ugGEwULvqVy0e1fo4j9aSnZ5Y375+cNLX+ziEHrcXa45q4NqOo2f3u80Zs9wnap4vy6oS07/Nu329yyOtP3nSMl0PJzDbgMjCKNe8nXZcKgLnzBCIN8Bmhxz0cWaxR3haeyV1YERT+0qq78peHfCZWZNLUhZB62XSwGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5488 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT056.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(376002)(346002)(396003)(39860400002)(136003)(46966005)(8676002)(4326008)(8936002)(107886003)(6666004)(478600001)(82740400003)(36756003)(2616005)(316002)(47076004)(82310400002)(6916009)(54906003)(36906005)(81166007)(83380400001)(86362001)(426003)(2906002)(1076003)(5660300002)(336012)(30864003)(186003)(26005)(70586007)(70206006);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: ee6ec07e-942d-4b86-84e2-08d81c3ffa21 X-Forefront-PRVS: 044968D9E1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rnmk/LA8Iq7E2QedSIH6FnUUw8JR9Y3aKApuvHgDDNgPf2/sD0qFhFkKGTDO3fasJo3ByXnMVI0hEy5vwM1sAOvJTQxkR+oEhELuSwG08Lxg3bwh4kgDKM24qVnSiiEuifZk/Uo+MVSDFL72ah2dMAqSRk4VSF7IZhiIHejNs12TPPEsA9XVO59tESlRy7Njrf+4FSr0/I9/zRq97Qaox7yZW0Az2YIvGgOxufD+NdRUmXdIeRky6VhWh2cR9pWoJXQd6BbzyzOK0X4z/c1UrQxc9gMoAf4TG4G8EBPVoM6Ab1hjEzNmcjQSM73iVCIguldjEaoKBkDS3ZyZqqvO486CiufUui1a9GovglIAShDTyHiZhp98mG2UlIm6l1TOBfR+uQ9mhFd7xZAWTF9uHw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2020 15:20:45.1255 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89a1d1a6-f3a6-4e0b-f5fc-08d81c3ffe97 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3125 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Refactor logging using the AcpiViewLog facility. Trim some of the source to more elegant state. Cc: Ray Ni Cc: Zhichao Gao Signed-off-by: Tomas Pilar --- .../UefiShellAcpiViewCommandLib/AcpiParser.c | 224 ++++++++---------- .../UefiShellAcpiViewCommandLib/AcpiParser.h | 6 +- .../AcpiTableParser.c | 52 ++-- .../AcpiTableParser.h | 2 +- .../UefiShellAcpiViewCommandLib/AcpiView.c | 187 +++++---------- .../FieldFormatHelper.h | 106 +-------- 6 files changed, 187 insertions(+), 390 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 65108e25ff96..9bbf724dfdfe 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "AcpiParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" @@ -46,6 +48,7 @@ IncrementWarningCount ( mTableWarningCount++; } =20 + /** This function verifies the ACPI table checksum. =20 @@ -69,12 +72,7 @@ VerifyChecksum ( { UINTN ByteCount; UINT8 Checksum; - UINTN OriginalAttribute; =20 - // - // set local variables to suppress incorrect compiler/analyzer warnings - // - OriginalAttribute =3D 0; ByteCount =3D 0; Checksum =3D 0; =20 @@ -84,29 +82,10 @@ VerifyChecksum ( } =20 if (Log) { - OriginalAttribute =3D gST->ConOut->Mode->Attribute; if (Checksum =3D=3D 0) { - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute ( - gST->ConOut, - EFI_TEXT_ATTR (EFI_GREEN, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)) - ); - } - Print (L"Table Checksum : OK\n\n"); + AcpiLog (ACPI_GOOD, L"Table Checksum : OK\n"); } else { - IncrementErrorCount (); - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute ( - gST->ConOut, - EFI_TEXT_ATTR (EFI_RED, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)) - ); - } - Print (L"Table Checksum : FAILED (0x%X)\n\n", Checksum); - } - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); + AcpiError (ACPI_ERROR_CSUM, L"Table Checksum (0x%X !=3D 0)\n", Check= sum); } } =20 @@ -127,53 +106,101 @@ DumpRaw ( ) { UINTN ByteCount; - UINTN PartLineChars; - UINTN AsciiBufferIndex; CHAR8 AsciiBuffer[17]; + CHAR8 HexBuffer[128]; + CHAR8 *HexCursor; =20 ByteCount =3D 0; - AsciiBufferIndex =3D 0; =20 - Print (L"Address : 0x%p\n", Ptr); - Print (L"Length : %d\n", Length); + AcpiInfo (L"Address : 0x%p", Ptr); + AcpiInfo (L"Length : %d\n", Length); =20 while (ByteCount < Length) { - if ((ByteCount & 0x0F) =3D=3D 0) { - AsciiBuffer[AsciiBufferIndex] =3D '\0'; - Print (L" %a\n%08X : ", AsciiBuffer, ByteCount); - AsciiBufferIndex =3D 0; - } else if ((ByteCount & 0x07) =3D=3D 0) { - Print (L"- "); + + // Reset ascii and hex strings + if (ByteCount % 16 =3D=3D 0) { + HexCursor =3D HexBuffer; + ZeroMem (AsciiBuffer, sizeof(AsciiBuffer)); + ZeroMem (HexBuffer, sizeof(HexBuffer)); + } else if (ByteCount % 8 =3D=3D 0) { + HexCursor +=3D AsciiSPrint (HexCursor, sizeof(HexBuffer), "- "); } =20 + // Add hex couplet to hex buffer + HexCursor +=3D AsciiSPrint (HexCursor, sizeof(HexBuffer), "%02X ", *Pt= r); + + // Add ascii letter to the ascii buffer + AsciiBuffer[ByteCount & 0xF] =3D '.'; if ((*Ptr >=3D ' ') && (*Ptr < 0x7F)) { - AsciiBuffer[AsciiBufferIndex++] =3D *Ptr; - } else { - AsciiBuffer[AsciiBufferIndex++] =3D '.'; + AsciiBuffer[ByteCount & 0xF] =3D *Ptr; } =20 - Print (L"%02X ", *Ptr++); + // Print line with fixed width hex part + if (ByteCount % 16 =3D=3D 15) { + AcpiInfo (L"%08X : %-.*a %a", ByteCount + 1, 46, HexBuffer, AsciiBuf= fer); + } =20 ByteCount++; + Ptr++; } =20 - // Justify the final line using spaces before printing - // the ASCII data. - PartLineChars =3D (Length & 0x0F); - if (PartLineChars !=3D 0) { - PartLineChars =3D 48 - (PartLineChars * 3); - if ((Length & 0x0F) <=3D 8) { - PartLineChars +=3D 2; - } - while (PartLineChars > 0) { - Print (L" "); - PartLineChars--; + // Print the last line + if (ByteCount % 16 !=3D 15) { + AcpiInfo ( + L"%08X : %-*a %.*a", + (ByteCount + 16) & ~0xF, + 46, + HexBuffer, + ByteCount & 0xF, + AsciiBuffer); } +} + +/** + Prints an arbitrary variable to screen using a given parser. + Also calls the internal validator if it exists. + + @param[in] Parser The parser to use to print to screen + @param[in] Prt Pointer to variable that should be printed +**/ +STATIC +VOID +EFIAPI +DumpAndValidate( + IN CONST ACPI_PARSER* Parser, + IN VOID* Ptr + ) +{ + // if there is a Formatter function let the function handle + // the printing else if a Format is specified in the table use + // the Format for printing + PrintFieldName (2, Parser->NameStr); + if (Parser->PrintFormatter !=3D NULL) { + Parser->PrintFormatter(Parser->Format, Ptr); + } else if (Parser->Format !=3D NULL) { + switch (Parser->Length) { + case 1: + AcpiInfo (Parser->Format, *(UINT8 *)Ptr); + break; + case 2: + AcpiInfo (Parser->Format, ReadUnaligned16 ((CONST UINT16 *)Ptr)); + break; + case 4: + AcpiInfo (Parser->Format, ReadUnaligned32 ((CONST UINT32 *)Ptr)); + break; + case 8: + AcpiInfo (Parser->Format, ReadUnaligned64 ((CONST UINT64 *)Ptr)); + break; + default: + AcpiLog (ACPI_BAD, L""); + } // switch } =20 - // Print ASCII data for the final line. - AsciiBuffer[AsciiBufferIndex] =3D '\0'; - Print (L" %a\n\n", AsciiBuffer); + // Validating only makes sense if we are tracing + // the parsed table entries, to report by table name. + if (mConfig.ConsistencyCheck && (Parser->FieldValidator !=3D NULL)) { + Parser->FieldValidator(Ptr, Parser->Context); + } } =20 /** @@ -216,39 +243,25 @@ ParseAcpi ( { UINT32 Index; UINT32 Offset; - UINTN OriginalAttribute; =20 - // - // set local variables to suppress incorrect compiler/analyzer warnings - // - OriginalAttribute =3D 0; - Offset =3D 0; + if (Length =3D=3D 0) { + AcpiLog ( + ACPI_WARN, + L"Will not parse zero-length buffer <%a>=3D%p", + AsciiName ? AsciiName : "Unknown Item", + Ptr); + return 0; + } =20 // Increment the Indent gIndent +=3D Indent; =20 if (Trace && (AsciiName !=3D NULL)){ - - if (mConfig.ColourHighlighting) { - OriginalAttribute =3D gST->ConOut->Mode->Attribute; - gST->ConOut->SetAttribute ( - gST->ConOut, - EFI_TEXT_ATTR(EFI_YELLOW, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)) - ); - } - Print ( - L"%*a%-*a :\n", - gIndent, - "", - (OUTPUT_FIELD_COLUMN_WIDTH - gIndent), - AsciiName - ); - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); - } + AcpiLog ( + ACPI_ITEM, L"%*.a%a", gIndent, "", AsciiName); } =20 + Offset =3D 0; for (Index =3D 0; Index < ParserItems; Index++) { if ((Offset + Parser[Index].Length) > Length) { =20 @@ -263,10 +276,8 @@ ParseAcpi ( } =20 if (mConfig.ConsistencyCheck && (Offset !=3D Parser[Index].Offset)) { - IncrementErrorCount (); - Print ( - L"\nERROR: %a: Offset Mismatch for %s\n" - L"CurrentOffset =3D %d FieldOffset =3D %d\n", + AcpiError (ACPI_ERROR_PARSE, + L"%a: Offset Mismatch for %s (%d !=3D %d)", AsciiName, Parser[Index].NameStr, Offset, @@ -275,48 +286,13 @@ ParseAcpi ( } =20 if (Trace) { - // if there is a Formatter function let the function handle - // the printing else if a Format is specified in the table use - // the Format for printing - PrintFieldName (2, Parser[Index].NameStr); - if (Parser[Index].PrintFormatter !=3D NULL) { - Parser[Index].PrintFormatter (Parser[Index].Format, Ptr); - } else if (Parser[Index].Format !=3D NULL) { - switch (Parser[Index].Length) { - case 1: - DumpUint8 (Parser[Index].Format, Ptr); - break; - case 2: - DumpUint16 (Parser[Index].Format, Ptr); - break; - case 4: - DumpUint32 (Parser[Index].Format, Ptr); - break; - case 8: - DumpUint64 (Parser[Index].Format, Ptr); - break; - default: - Print ( - L"\nERROR: %a: CANNOT PARSE THIS FIELD, Field Length =3D %d\= n", - AsciiName, - Parser[Index].Length - ); - } // switch - - // Validating only makes sense if we are tracing - // the parsed table entries, to report by table name. - if (mConfig.ConsistencyCheck && (Parser[Index].FieldValidator !=3D= NULL)) { - Parser[Index].FieldValidator (Ptr, Parser[Index].Context); - } - } - Print (L"\n"); - } // if (Trace) + DumpAndValidate (&Parser[Index], &Ptr[Offset]); + } =20 if (Parser[Index].ItemPtr !=3D NULL) { - *Parser[Index].ItemPtr =3D (VOID*)Ptr; + *Parser[Index].ItemPtr =3D Ptr + Offset; } =20 - Ptr +=3D Parser[Index].Length; Offset +=3D Parser[Index].Length; } // for =20 @@ -355,7 +331,7 @@ DumpGasStruct ( IN UINT32 Length ) { - Print (L"\n"); + AcpiInfo(L""); return ParseAcpi ( TRUE, Indent, @@ -421,7 +397,7 @@ DumpAcpiHeader ( UINT32 EFIAPI ParseAcpiHeader ( - IN UINT8* Ptr, + IN VOID* Ptr, OUT CONST UINT32** Signature, OUT CONST UINT32** Length, OUT CONST UINT8** Revision diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 54ce44132055..bd3cdb774fb5 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -18,10 +18,6 @@ /// that allows us to process the log options. #define RSDP_TABLE_INFO SIGNATURE_32('R', 'S', 'D', 'P') =20 -// Publicly accessible error and warning counters. -extern UINT32 mTableErrorCount; -extern UINT32 mTableWarningCount; - /** This function increments the ACPI table error counter. **/ @@ -310,7 +306,7 @@ DumpAcpiHeader ( UINT32 EFIAPI ParseAcpiHeader ( - IN UINT8* Ptr, + IN VOID* Ptr, OUT CONST UINT32** Signature, OUT CONST UINT32** Length, OUT CONST UINT8** Revision diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c= b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c index 526cb8cb7cad..49acb3d03da1 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c @@ -18,6 +18,7 @@ #include "AcpiTableParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" +#include "AcpiViewLog.h" =20 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) #include "Arm/SbbrValidator.h" @@ -179,61 +180,43 @@ GetParser ( VOID EFIAPI ProcessAcpiTable ( - IN UINT8* Ptr + IN VOID* Ptr ) { EFI_STATUS Status; BOOLEAN Trace; - CONST UINT32* AcpiTableSignature; - CONST UINT32* AcpiTableLength; - CONST UINT8* AcpiTableRevision; - CONST UINT8* SignaturePtr; + CONST UINT32* Signature; + CONST UINT32* Length; + CONST UINT8* Revision; PARSE_ACPI_TABLE_PROC ParserProc; =20 - ParseAcpiHeader ( - Ptr, - &AcpiTableSignature, - &AcpiTableLength, - &AcpiTableRevision - ); + ParseAcpiHeader (Ptr, &Signature, &Length, &Revision); =20 - Trace =3D ProcessTableReportOptions ( - *AcpiTableSignature, - Ptr, - *AcpiTableLength - ); + Trace =3D ProcessTableReportOptions (*Signature, Ptr, *Length); =20 if (Trace) { - DumpRaw (Ptr, *AcpiTableLength); + DumpRaw (Ptr, *Length); =20 // Do not process the ACPI table any further if the table length read // is invalid. The ACPI table should at least contain the table header= . - if (*AcpiTableLength < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) { - SignaturePtr =3D (CONST UINT8*)AcpiTableSignature; - IncrementErrorCount (); - Print ( - L"ERROR: Invalid %c%c%c%c table length. Length =3D %d\n", - SignaturePtr[0], - SignaturePtr[1], - SignaturePtr[2], - SignaturePtr[3], - *AcpiTableLength - ); + if (*Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) { + AcpiError ( + ACPI_ERROR_LENGTH, L"Table %4a invalid length %d", Signature, *Len= gth); return; } =20 if (mConfig.ConsistencyCheck) { - VerifyChecksum (TRUE, Ptr, *AcpiTableLength); + VerifyChecksum (TRUE, Ptr, *Length); } } =20 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) if (mConfig.MandatoryTableValidate) { - ArmSbbrIncrementTableCount (*AcpiTableSignature); + ArmSbbrIncrementTableCount (*Signature); } #endif =20 - Status =3D GetParser (*AcpiTableSignature, &ParserProc); + Status =3D GetParser (*Signature, &ParserProc); if (EFI_ERROR (Status)) { // No registered parser found, do default handling. if (Trace) { @@ -242,10 +225,5 @@ ProcessAcpiTable ( return; } =20 - ParserProc ( - Trace, - Ptr, - *AcpiTableLength, - *AcpiTableRevision - ); + ParserProc (Trace, Ptr, *Length, *Revision); } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h= b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h index 4f92596b90a6..e2afeda2379c 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h @@ -101,7 +101,7 @@ DeregisterParser ( VOID EFIAPI ProcessAcpiTable ( - IN UINT8* Ptr + IN VOID* Ptr ); =20 /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/Shel= lPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c index e25e0712948b..64caff6ab0fe 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c @@ -10,6 +10,8 @@ - Arm Server Base Boot Requirements 1.2, September 2019 **/ =20 +#include + #include #include #include @@ -22,6 +24,7 @@ #include "AcpiTableParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" +#include "AcpiViewLog.h" =20 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) #include "Arm/SbbrValidator.h" @@ -59,7 +62,7 @@ DumpAcpiTableToFile ( mBinTableCount++ ); =20 - Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer); + AcpiInfo (L"Dumping ACPI table to : %s ... ", FileNameBuffer); =20 TransferBytes =3D ShellDumpBufferToFile (FileNameBuffer, Ptr, Length); return (Length =3D=3D TransferBytes); @@ -81,15 +84,7 @@ ProcessTableReportOptions ( IN CONST UINT32 Length ) { - UINTN OriginalAttribute; - UINT8 *SignaturePtr; BOOLEAN Log; - - // - // set local variables to suppress incorrect compiler/analyzer warnings - // - OriginalAttribute =3D 0; - SignaturePtr =3D (UINT8*)(UINTN)&Signature; Log =3D FALSE; =20 switch (mConfig.ReportType) { @@ -104,27 +99,9 @@ ProcessTableReportOptions ( break; case ReportTableList: if (mTableCount =3D=3D 0) { - if (mConfig.ColourHighlighting) { - OriginalAttribute =3D gST->ConOut->Mode->Attribute; - gST->ConOut->SetAttribute ( - gST->ConOut, - EFI_TEXT_ATTR(EFI_CYAN, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)) - ); - } - Print (L"\nInstalled Table(s):\n"); - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); - } + AcpiLog (ACPI_HIGHLIGHT, L"\nInstalled Table(s):"); } - Print ( - L"\t%4d. %c%c%c%c\n", - ++mTableCount, - SignaturePtr[0], - SignaturePtr[1], - SignaturePtr[2], - SignaturePtr[3] - ); + AcpiInfo (L"\t%4d. %.*a", ++mTableCount, 4, &Signature); break; case ReportDumpBinFile: if (Signature =3D=3D mSelectedAcpiTable.Type) { @@ -139,31 +116,16 @@ ProcessTableReportOptions ( } // switch =20 if (Log) { - if (mConfig.ColourHighlighting) { - OriginalAttribute =3D gST->ConOut->Mode->Attribute; - gST->ConOut->SetAttribute ( - gST->ConOut, - EFI_TEXT_ATTR(EFI_LIGHTBLUE, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)) - ); - } - Print ( - L"\n\n --------------- %c%c%c%c Table --------------- \n\n", - SignaturePtr[0], - SignaturePtr[1], - SignaturePtr[2], - SignaturePtr[3] - ); - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); - } + AcpiLog ( + ACPI_HIGHLIGHT, + L"\n --------------- %.*a Table --------------- \n", + 4, + &Signature); } =20 return Log; } =20 - - /** This function iterates the configuration table entries in the system table, retrieves the RSDP pointer and starts parsing the ACPI tab= les. @@ -183,17 +145,12 @@ AcpiView ( EFI_STATUS Status; UINTN Index; EFI_CONFIGURATION_TABLE* EfiConfigurationTable; - BOOLEAN FoundAcpiTable; - UINTN OriginalAttribute; - UINTN PrintAttribute; UINT8* RsdpPtr; UINT32 RsdpLength; UINT8 RsdpRevision; PARSE_ACPI_TABLE_PROC RsdpParserProc; BOOLEAN Trace; =20 - OriginalAttribute =3D 0; - // Reset Table counts mTableCount =3D 0; mBinTableCount =3D 0; @@ -203,107 +160,77 @@ AcpiView ( mTableWarningCount =3D 0; =20 // Search the table for an entry that matches the ACPI Table Guid - FoundAcpiTable =3D FALSE; + EfiConfigurationTable =3D NULL; for (Index =3D 0; Index < SystemTable->NumberOfTableEntries; Index++) { if (CompareGuid (&gEfiAcpiTableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) { EfiConfigurationTable =3D &SystemTable->ConfigurationTable[Index]; - FoundAcpiTable =3D TRUE; break; } } =20 - if (FoundAcpiTable) { - RsdpPtr =3D (UINT8*)EfiConfigurationTable->VendorTable; + if (!EfiConfigurationTable) { + AcpiFatal (L"No ACPI Table Guid in System Configuration Table."); + return EFI_NOT_FOUND; + } =20 - // The RSDP revision is 1 byte starting at offset 15 - RsdpRevision =3D *(RsdpPtr + RSDP_REVISION_OFFSET); + RsdpPtr =3D (UINT8 *)EfiConfigurationTable->VendorTable; =20 - if (RsdpRevision < 2) { - Print ( - L"ERROR: RSDP version less than 2 is not supported.\n" - ); - return EFI_UNSUPPORTED; - } + // The RSDP revision is 1 byte starting at offset 15 + RsdpRevision =3D *(RsdpPtr + RSDP_REVISION_OFFSET); =20 -#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) - if (mConfig.MandatoryTableValidate) { - ArmSbbrResetTableCounts (); - } -#endif + if (RsdpRevision < 2) { + AcpiFatal (L"RSDP version less than 2 is not supported."); + return EFI_UNSUPPORTED; + } =20 - // The RSDP length is 4 bytes starting at offset 20 - RsdpLength =3D *(UINT32*)(RsdpPtr + RSDP_LENGTH_OFFSET); +#if defined(MDE_CPU_ARM) || defined(MDE_CPU_AARCH64) + if (mConfig.MandatoryTableValidate) { + ArmSbbrResetTableCounts(); + } +#endif =20 - Trace =3D ProcessTableReportOptions (RSDP_TABLE_INFO, RsdpPtr, RsdpLen= gth); + // The RSDP length is 4 bytes starting at offset 20 + RsdpLength =3D *(UINT32 *)(RsdpPtr + RSDP_LENGTH_OFFSET); =20 - Status =3D GetParser (RSDP_TABLE_INFO, &RsdpParserProc); - if (EFI_ERROR (Status)) { - Print ( - L"ERROR: No registered parser found for RSDP.\n" - ); - return Status; - } + Trace =3D ProcessTableReportOptions(RSDP_TABLE_INFO, RsdpPtr, RsdpLength= ); =20 - RsdpParserProc ( - Trace, - RsdpPtr, - RsdpLength, - RsdpRevision - ); - - } else { - IncrementErrorCount (); - Print ( - L"ERROR: Failed to find ACPI Table Guid in System Configuration Tabl= e.\n" - ); - return EFI_NOT_FOUND; + Status =3D GetParser(RSDP_TABLE_INFO, &RsdpParserProc); + if (EFI_ERROR(Status)) { + AcpiFatal (L"No registered parser found for RSDP."); + return Status; } =20 + RsdpParserProc(Trace, RsdpPtr, RsdpLength, RsdpRevision); + #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) if (mConfig.MandatoryTableValidate) { ArmSbbrReqsValidate ((ARM_SBBR_VERSION) mConfig.MandatoryTableSpec); } #endif =20 - if (ReportTableList !=3D mConfig.ReportType) { - if (((ReportSelected =3D=3D mConfig.ReportType) || - (ReportDumpBinFile =3D=3D mConfig.ReportType)) && - (!mSelectedAcpiTable.Found)) { - Print (L"\nRequested ACPI Table not found.\n"); - } else if (mConfig.ConsistencyCheck && - (ReportDumpBinFile !=3D mConfig.ReportType)) { - OriginalAttribute =3D gST->ConOut->Mode->Attribute; - - Print (L"\nTable Statistics:\n"); - - if (mConfig.ColourHighlighting) { - PrintAttribute =3D ((mTableErrorCount) > 0) ? - EFI_TEXT_ATTR ( - EFI_RED, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4) - ) : - OriginalAttribute; - gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute); - } - Print (L"\t%d Error(s)\n", mTableErrorCount); - - if (mConfig.ColourHighlighting) { - PrintAttribute =3D (mTableWarningCount > 0) ? - EFI_TEXT_ATTR ( - EFI_RED, - ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4) - ) : - OriginalAttribute; - - gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute); - } - Print (L"\t%d Warning(s)\n", mTableWarningCount); + if (mConfig.ReportType =3D=3D ReportSelected || + mConfig.ReportType =3D=3D ReportDumpBinFile) { + if (!mSelectedAcpiTable.Found) { + AcpiFatal (L"Requested ACPI Table not found."); + return EFI_SUCCESS; + } + } =20 - if (mConfig.ColourHighlighting) { - gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); - } + if (mConfig.ConsistencyCheck) { + if (mConfig.ReportType =3D=3D ReportSelected || + mConfig.ReportType =3D=3D ReportAll) { + AcpiInfo (L"Table Statistics:"); + AcpiLog ( + mTableErrorCount ? ACPI_BAD : ACPI_GOOD, + L"\t%d Error(s)", + mTableErrorCount); + AcpiLog ( + mTableWarningCount ? ACPI_BAD : ACPI_GOOD, + L"\t%d Warning(s)\n", + mTableWarningCount); } } + return EFI_SUCCESS; } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper= .h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h index 25c70652806c..b0072b68844c 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h @@ -8,90 +8,10 @@ #ifndef FIELD_FORMAT_HELPER_H_ #define FIELD_FORMAT_HELPER_H_ =20 -#include -#include - -/** - 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. +#define INLINE inline =20 - @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 =3D *(UINT32*)(Ptr + sizeof (UINT32)); - - Val =3D LShiftU64(Val,32); - Val |=3D (UINT64)*(UINT32*)Ptr; - - Print (Format, Val); -} +#include +#include "AcpiViewLog.h" =20 /** This function traces 3 characters which can be optionally @@ -111,8 +31,8 @@ Dump3Chars ( IN UINT8* Ptr ) { - Print ( - (Format !=3D NULL) ? Format : (CONST CHAR16*) L"%c%c%c", + AcpiInfo ( + (Format !=3D NULL) ? Format : L"%c%c%c", Ptr[0], Ptr[1], Ptr[2] @@ -137,8 +57,8 @@ Dump4Chars ( IN UINT8* Ptr ) { - Print ( - (Format !=3D NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c", + AcpiInfo( + (Format !=3D NULL) ? Format : L"%c%c%c%c", Ptr[0], Ptr[1], Ptr[2], @@ -164,8 +84,8 @@ Dump6Chars ( IN UINT8* Ptr ) { - Print ( - (Format !=3D NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c", + AcpiInfo( + (Format !=3D NULL) ? Format : L"%c%c%c%c%c%c", Ptr[0], Ptr[1], Ptr[2], @@ -193,8 +113,8 @@ Dump8Chars ( IN UINT8* Ptr ) { - Print ( - (Format !=3D NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c%c%c", + AcpiInfo( + (Format !=3D NULL) ? Format : L"%c%c%c%c%c%c%c%c", Ptr[0], Ptr[1], Ptr[2], @@ -224,8 +144,8 @@ Dump12Chars ( IN UINT8* Ptr ) { - Print ( - (Format !=3D NULL) ? Format : (CONST CHAR16*) L"%c%c%c%c%c%c%c%c%c%c%c= %c", + AcpiInfo( + (Format !=3D NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c", Ptr[0], Ptr[1], Ptr[2], --=20 2.24.1.windows.2