From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.71]) by mx.groups.io with SMTP id smtpd.web11.2024.1594748784525228791 for ; Tue, 14 Jul 2020 10:46:25 -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=VRKBG9O2; spf=pass (domain: arm.com, ip: 40.107.1.71, 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=XJtSnwquktw77Zp0fUF34OChJaNWFpWkZF+iTBLlbSA=; b=VRKBG9O2WW9q0M0Da+eXNxg2VRVeuL6lPQYUu0xMg0/iLHQDRogc6sDYq1RvhuZTDEfAqQf+HYzshTM898CeaOr99Al8Kz4pCCwF5ndjye54fLXm0HPYlpTb59ILIfhMWzbOBZSiUsVu2pPvRh0J4kl+iMZ+0WK+CeD79EfLDSM= Received: from AM6P195CA0027.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::40) by AM0PR08MB5444.eurprd08.prod.outlook.com (2603:10a6:208:185::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.20; Tue, 14 Jul 2020 17:46:21 +0000 Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:81:cafe::da) by AM6P195CA0027.outlook.office365.com (2603:10a6:209:81::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 17:46:21 +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 AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 17:46:21 +0000 Received: ("Tessian outbound c83312565ef4:v62"); Tue, 14 Jul 2020 17:46:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 74b4fc60d212fb9f X-CR-MTA-TID: 64aa7808 Received: from cdeadd215a5b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3C52B95F-1DB8-4315-ABF9-C9768E64A1EB.1; Tue, 14 Jul 2020 17:46:15 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cdeadd215a5b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 14 Jul 2020 17:46:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fgiTBxuvh/30O5SbO0Cm42k1gEGrfYaf8TDF8GP+woIp2OpSV3fuV8TwYUcUp+Y6pAJGlH93gjkkefKWsCcd6tjiJ73KeL4rdKBzr66iGrDQvvJActwOhHhAzseBGnbtyixCAE972UGD1pRtLBZJvJCYHWz6GaubU6TJE1TaaqezPLhyVktw07PwBvjpewsj2rLL128TKvOJF0hjoVRddvyq7bBgF3lMYRxyuK3iCexNT+oz64+jyh1D9f94R/0paVSmbMWrS2paWXwAIN0pgt8YE2oRA3NGJqQVaMfVSgrciUAG5kjpL02c412mv/T1VTugo8oZed0SdXyJR8cF0w== 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=XJtSnwquktw77Zp0fUF34OChJaNWFpWkZF+iTBLlbSA=; b=EBjiLnPH4xbhamfy0WxPp2y2Wn41sDKgPnb3LuuULOBLP822tjxn1q2stb6AmsgL2nYzQRGbPj6dWIsYXs3S04PfDXjpubOSu58Lqe02R7OLuQj3iTEFW00l2prdavRrXoVWIWLRCZTJvl9CgYNmLOGmyLLK11mgXQX6tAAZ7aovSJhM4LkDmVMtoGVqFFD/0Ffr9//+GAxLkpzqHcB1hLVWsj8J4ecQ+nk8l3ZKRbGRGWDcD84YPYEojiDVl1l6+lFP1WhCekjVqAXA/IXV6NykyddiBlz7r6I/jlnwI0LrwGJNdcKtSbTKCd71k+dpVnzd+xJMIUVbo9JURoxPYQ== 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=XJtSnwquktw77Zp0fUF34OChJaNWFpWkZF+iTBLlbSA=; b=VRKBG9O2WW9q0M0Da+eXNxg2VRVeuL6lPQYUu0xMg0/iLHQDRogc6sDYq1RvhuZTDEfAqQf+HYzshTM898CeaOr99Al8Kz4pCCwF5ndjye54fLXm0HPYlpTb59ILIfhMWzbOBZSiUsVu2pPvRh0J4kl+iMZ+0WK+CeD79EfLDSM= Received: from MRXP264CA0023.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:15::35) by DB7PR08MB3452.eurprd08.prod.outlook.com (2603:10a6:10:48::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Tue, 14 Jul 2020 17:46:13 +0000 Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:15:cafe::47) by MRXP264CA0023.outlook.office365.com (2603:10a6:500:15::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 17:46:12 +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 VE1EUR03FT009.mail.protection.outlook.com (10.152.18.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 17:46:12 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Tue, 14 Jul 2020 17:46:03 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Tue, 14 Jul 2020 17:46:03 +0000 Received: from localhost.localdomain (10.57.32.194) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Tue, 14 Jul 2020 17:46:02 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [PATCH v3 7/8] ShellPkg/AcpiView: Refactor AcpiView Date: Tue, 14 Jul 2020 18:45:45 +0100 Message-ID: <20200714174546.560-8-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200714174546.560-1-Tomas.Pilar@arm.com> References: <20200714174546.560-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)(136003)(346002)(396003)(376002)(39860400002)(46966005)(30864003)(478600001)(2616005)(5660300002)(83380400001)(8676002)(26005)(70586007)(70206006)(47076004)(82740400003)(186003)(82310400002)(336012)(6916009)(426003)(8936002)(6666004)(81166007)(356005)(1076003)(2906002)(316002)(36756003)(4326008)(86362001)(54906003);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 259b7255-9588-48cf-ed85-08d8281dd1db X-MS-TrafficTypeDiagnostic: DB7PR08MB3452:|AM0PR08MB5444: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 7kxzZJFu4aSkMJ/qc2DXyX5qE0ydpXPArA+NYLSGdA4uquT/Ri1NGrNBFVUpzHoNhyloFzUpQ1BE6SCDB8lv79yzsbr7F8v7247OXqVBUNmXFQeRgYAlf+WBKwBbP4s8UmL1pnT/mcpVpJPe3Mv8l0mSlZmrojv3DDs/NvLqEQcMMCvNKg/wg2RgUk2o0I4sD10YxP2TlJW72Aaic0orboBGS9PnUimNUKJWSWfATUYv9mC96xdWfrYrD91Q7lHj9xHN/lQHKKeAPmCRDnHmVXikWBlFDlFYHDp2k92bBBHS5wUUgslcD3l4d6/r1R02hlyMIr2LBDekmSANllKGrUaYr0sYnBZGs41YvDfoMAcCK2TEApqVJ4/ul50aED05lFBbL38yKh8kh04FQ5Yo9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3452 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT015.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)(346002)(136003)(376002)(396003)(39860400002)(46966005)(336012)(82310400002)(478600001)(83380400001)(2906002)(82740400003)(107886003)(4326008)(47076004)(8936002)(6666004)(8676002)(81166007)(30864003)(6916009)(5660300002)(2616005)(1076003)(26005)(426003)(36756003)(36906005)(186003)(70206006)(70586007)(54906003)(86362001)(316002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 0857e68c-a2ee-4f0e-d20f-08d8281dccc1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J29/mMVBkOa2Z4rwfZNP8XWwcJa+q6I+ZaO9+3lbeIgUcBT0h095pk+5Q47OqHdK4fh7g7kDwU8+a2QKaUIOcVZ9C2iWBBIa2YmNecAVleOkIndPPCa83EUEtKJhOzC8BY9ioyGMNiBM6SLbHjl4+ufVVmkj0Hsat3YD4mhq7uQN1ZlpdDu/8DRcreuX4W6kHuzimWzLgwJdZCKv1zLm+aj7mnEpGcoITIWd4XFL03TtG+jc55+Fvl8iNaohOb2eYqQYmQHl5kkhCriZt9VIXLYDaA34XbKcymQnKKoF0GgMTCaGLwxknSHCa1AmsKcyFAW5ybXjbGdm4ovWiocv0MHDS7JAKptn1jHPCx2YuSv47Lw6uFK72DtrQ4VBAv29nRM3c5Q5J2nWUMDCg6pwUw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 17:46:21.2229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 259b7255-9588-48cf-ed85-08d8281dd1db 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: AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5444 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 | 225 ++++++++---------- .../UefiShellAcpiViewCommandLib/AcpiParser.h | 6 +- .../AcpiTableParser.c | 52 ++-- .../AcpiTableParser.h | 2 +- .../UefiShellAcpiViewCommandLib/AcpiView.c | 187 +++++---------- .../FieldFormatHelper.h | 106 +-------- 6 files changed, 188 insertions(+), 390 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 65108e25ff96..16b8d1f80bc2 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "AcpiParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" @@ -46,6 +49,7 @@ IncrementWarningCount ( mTableWarningCount++; } =20 + /** This function verifies the ACPI table checksum. =20 @@ -69,12 +73,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 +83,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 +107,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 +244,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 +277,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 +287,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 +332,7 @@ DumpGasStruct ( IN UINT32 Length ) { - Print (L"\n"); + AcpiInfo(L""); return ParseAcpi ( TRUE, Indent, @@ -421,7 +398,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 16f498b8c328..a34af68f7c23 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" @@ -57,7 +60,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); @@ -79,15 +82,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) { @@ -102,27 +97,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) { @@ -137,31 +114,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. @@ -181,17 +143,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; @@ -201,107 +158,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