From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (EUR02-AM5-obe.outbound.protection.outlook.com [40.107.0.71]) by mx.groups.io with SMTP id smtpd.web11.21345.1593444049234200762 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=jIKIhMeK; spf=pass (domain: arm.com, ip: 40.107.0.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=Oi+wvNg7rczvBBScGNpqKfvu0lEyG2J71ee4F/Lkcyc=; b=jIKIhMeKtQtOVKd89NLT3RcZzui9ozPfI8LKnt+9L37yImi+qIZNoTMpqgfrF9WEGKvSsEHtOyIUJlVhTSvAZsIJ50vNGa3DHbsARJRJ4EoBhO47ndm+87OIJPm3wNVuyKheGE3CEyTxYVGN+OGKLLneIjWdBrtMA8/0L5X3rLs= Received: from MRXP264CA0043.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:14::31) by VI1PR08MB5519.eurprd08.prod.outlook.com (2603:10a6:803:133::9) 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:46 +0000 Received: from VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:14:cafe::4f) by MRXP264CA0043.outlook.office365.com (2603:10a6:500:14::31) 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:46 +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 VE1EUR03FT050.mail.protection.outlook.com (10.152.19.209) 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:46 +0000 Received: ("Tessian outbound cea5956745d7:v60"); Mon, 29 Jun 2020 15:20:46 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d16d5cf317258a94 X-CR-MTA-TID: 64aa7808 Received: from 113bdbaaeaeb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8928D47D-B918-4D57-BD59-A043943D2427.1; Mon, 29 Jun 2020 15:20:40 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 113bdbaaeaeb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 29 Jun 2020 15:20:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QD29ba7FipEy9OHYFmr2T1u8FHE7cVBOQjI2nZB7d01bKDw+HJWofmXQxuCKJk10u2QOPcx3iy0BsA96Dr7jGWEaXBbpTQHO4Bunz2ziBhbJZdB4cYFOi7FbCJ47fcL6aaIdsXAJT7Hk8LieqhG16Wo8qX2cSAY5y8ERYh4wQlJ7TrD0EHNlDR+Wc15Mn1p/BM4TdarEtTO0hZpqX27gTM3r0YNZS3y1fGET9vBbUMvTfdNjMtrRKKIW3L7G2u4femtMtN0u72nss9LqbdBC3ACa+fUMLfxRLsAGLB56P5vr98z6ocQADsATN+RHb3DnDsv8dixKO6oMceP3kKJHtg== 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=Oi+wvNg7rczvBBScGNpqKfvu0lEyG2J71ee4F/Lkcyc=; b=Xm45y+duxVbBuxoSeZwBtJc+V7wMALuutF1PEcP7Ic088e/IEb5tbL7G9NVgbIOFJaCik1eENhHNoIFekBuTyI2XY6eKHp38wi425IPkwlONcUA7Xf78wM3hHDJcsJeBRHNANDI6UMso/luKt3zcKZytyc5dq2OEUwIuT5OrzdUuiddiYZqfe0PfIRzlcou3rwRr6WkUrJ/rt7JcmCusWTW7eQnas1ILoR82BBcrsm64eekDts66jokJfxm1DO6bwsAvbcEMdeznscAwmDGL9uFj0zKfoGPlN2q2fV26b6zDZWmwI0KnJQGHfJ5GqhHE23807GbDTipSaLSVXr2gnw== 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=Oi+wvNg7rczvBBScGNpqKfvu0lEyG2J71ee4F/Lkcyc=; b=jIKIhMeKtQtOVKd89NLT3RcZzui9ozPfI8LKnt+9L37yImi+qIZNoTMpqgfrF9WEGKvSsEHtOyIUJlVhTSvAZsIJ50vNGa3DHbsARJRJ4EoBhO47ndm+87OIJPm3wNVuyKheGE3CEyTxYVGN+OGKLLneIjWdBrtMA8/0L5X3rLs= Received: from AM6P194CA0057.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::34) by VE1PR08MB4958.eurprd08.prod.outlook.com (2603:10a6:803:108::29) 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:36 +0000 Received: from VE1EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::32) by AM6P194CA0057.outlook.office365.com (2603:10a6:209:84::34) 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:36 +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:36 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Mon, 29 Jun 2020 15:20:28 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) 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; Mon, 29 Jun 2020 15:20:27 +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:27 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [PATCH 4/8] ShellPkg/AcpiView: Create a logging facility Date: Mon, 29 Jun 2020 16:20:04 +0100 Message-ID: <20200629152008.685-5-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)(136003)(39860400002)(376002)(346002)(396003)(46966005)(86362001)(316002)(478600001)(426003)(5660300002)(336012)(1076003)(19627235002)(2616005)(82740400003)(83380400001)(4326008)(47076004)(6916009)(81166007)(36756003)(8676002)(8936002)(6666004)(2906002)(30864003)(70586007)(356005)(26005)(82310400002)(54906003)(186003)(70206006)(403724002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b2a0c19-fe48-4889-dda0-08d81c3fff53 X-MS-TrafficTypeDiagnostic: VE1PR08MB4958:|VI1PR08MB5519: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 044968D9E1 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: RQluxEZiwCc3fkmnq+WI5OA/bbfY1/YcgND4IO1vruzhd3EjQzptH31yRUSp5g1lFgAduey8UMG2Ik/vBKONIpk2r0VAJtYZD9d7Xm+aU1jeBJOVFs/4t2p0RU7DzgtseI5hEux+wZJ3rJ4xm80xwIzixUd/LTeY/STbYgn8Nd6alRr/QSArh1J+uvMxw5Wg+NIJY/hdjHU9K3oGKbc8PI18vRYBgumXn5dqPIzFADUaBpwD9T/bBobFK19Nbd6kI/nNVlCTcjvQ8MzU2ZaADrvx5Z7rbBmRPe3RwCm9WbmPAe8evTQrcM4TUe+RH2MhYNtSCn/rRnEMToXrxRTiDjU/Pku5gSlbcKUc20vNRsOvVsDxn/mquXXfU6V5efUAVgSuL2N23McAfYxcZ/5Qt5a0vvDrj+MTXV0rasXGCx8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4958 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT050.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)(136003)(346002)(376002)(39860400002)(396003)(46966005)(426003)(2616005)(4326008)(6666004)(186003)(2906002)(1076003)(36906005)(19627235002)(5660300002)(336012)(316002)(54906003)(30864003)(36756003)(26005)(70586007)(8936002)(47076004)(82740400003)(82310400002)(81166007)(70206006)(6916009)(8676002)(86362001)(478600001)(107886003)(83380400001)(403724002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 980c8d00-72d6-4f78-9b05-08d81c3ff923 X-Forefront-PRVS: 044968D9E1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2n+MWEabN295z8yi0KvRmb6+k4FOuX4qjBQ3sNW3NFRFvTZI1P7LaWahaS832SqnPGh658kD3yA/yj4sIKL/cKpsIEKGd/gqXYs4Xk0YsSUoQtKdux+fcT3TuqfLHbFjVaQPSXz4rWRUIVHTW0jCaMVhnRigHOWq4PahvQegVrhczg03QSlRI6C9TUwpYoL6xmQ41Z8wdEFlwDMtMm1ympeF9yBVRS754jQzngfPIrxPcsoM8RLC2hKr4sHYozj6gbkPv4QLxtiYokJV2NH5Et7fI0STVJZv8VWdfCe2EMVgBdHE7fSRI6ZfffLwIMyUJYP+w9kk2wAmtubvOpVD/4x9WvUf1BU5ALsXMnPiqGMaLAZqG6l6+pFbBVzAyzdBQeJFFx2zcJ62OGpKp7Sa2xK1dyHGsr2L6h0CZHqJxsY= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2020 15:20:46.3609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b2a0c19-fe48-4889-dda0-08d81c3fff53 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: VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5519 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Extract error and warning logging into separate methods. Fold highlighting and other output properties into the logging methods. Cc: Ray Ni Cc: Zhichao Gao Signed-off-by: Tomas Pilar --- .../UefiShellAcpiViewCommandLib/AcpiParser.c | 5 +- .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 230 +++++++++++++++++ .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 233 ++++++++++++++++++ .../UefiShellAcpiViewCommandLib.inf | 2 + 4 files changed, 466 insertions(+), 4 deletions(-) create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLo= g.c create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLo= g.h diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 7017fa93efae..b88594cf3865 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -11,13 +11,10 @@ #include "AcpiParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" +#include "AcpiViewLog.h" =20 STATIC UINT32 gIndent; =20 -// Publicly accessible error and warning counters. -UINT32 mTableErrorCount; -UINT32 mTableWarningCount; - STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; =20 /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c b/S= hellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c new file mode 100644 index 000000000000..9b9aaa855fdc --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c @@ -0,0 +1,230 @@ +/** @file + 'acpiview' logging and output facility + + Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "AcpiViewLog.h" +#include "AcpiViewConfig.h" +#include "AcpiParser.h" +#include + +static CHAR16 mOutputBuffer [MAX_OUTPUT_SIZE] =3D { 0 }; + +// String descriptions of error types +static const CHAR16* mErrorTypeDesc [ACPI_ERROR_MAX] =3D { + L"Not an error", ///< ACPI_ERROR_NONE + L"Generic", ///< ACPI_ERROR_GENERIC + L"Checksum", ///< ACPI_ERROR_CSUM + L"Parsing", ///< ACPI_ERROR_PARSE + L"Length", ///< ACPI_ERROR_LENGTH + L"Value", ///< ACPI_ERROR_VALUE + L"Cross-check", ///< ACPI_ERROR_CROSS +}; + +// Publicly accessible error and warning counters. +UINT32 mTableErrorCount; +UINT32 mTableWarningCount; + +/** + Change the attributes of the standard output console + to change the colour of the text according to the given + severity of a log message. + + @param[in] Severity The severity of the log message that is bei= ng + annotated with changed colour text. + @param[in] OriginalAttribute The current attributes of ConOut that will = be modified. +**/ +static +VOID +EFIAPI +ApplyColor ( + IN ACPI_LOG_SEVERITY Severity, + IN UINTN OriginalAttribute + ) +{ + if (!mConfig.ColourHighlighting) { + return; + } + + // Strip the foreground colour + UINTN NewAttribute =3D OriginalAttribute & 0xF0; + + // Add specific foreground colour based on severity + switch (Severity) { + case ACPI_DEBUG: + NewAttribute |=3D EFI_DARKGRAY; + break; + case ACPI_HIGHLIGHT: + NewAttribute |=3D EFI_LIGHTBLUE; + break; + case ACPI_GOOD: + NewAttribute |=3D EFI_GREEN; + break; + case ACPI_ITEM: + case ACPI_WARN: + NewAttribute |=3D EFI_YELLOW; + break; + case ACPI_BAD: + case ACPI_ERROR: + case ACPI_FATAL: + NewAttribute |=3D EFI_RED; + break; + case ACPI_INFO: + default: + NewAttribute |=3D OriginalAttribute; + break; + } + + gST->ConOut->SetAttribute (gST->ConOut, NewAttribute); +} + +/** + Restore ConOut text attributes. + + @param[in] OriginalAttribute The attribute set that will be restored. +**/ +static +VOID +EFIAPI +RestoreColor( + IN UINTN OriginalAttribute + ) +{ + gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); +} + +/** + Formats and prints an ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] Marker The marker for variable parameters to be formatted. +**/ +static +VOID +EFIAPI +AcpiViewVSOutput ( + IN const CHAR16 *Format, + IN VA_LIST Marker + ) +{ + UnicodeVSPrint (mOutputBuffer, sizeof(mOutputBuffer), Format, Marker); + gST->ConOut->OutputString(gST->ConOut, mOutputBuffer); +} + +/** + Formats and prints and ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] ... A variable number of parameters that will be formatted= . +**/ +VOID +EFIAPI +AcpiViewOutput ( + IN const CHAR16 *Format, + IN ... +) +{ + VA_LIST Marker; + VA_START (Marker, Format); + + AcpiViewVSOutput (Format, Marker); + + VA_END (Marker); +} + + +/** + Prints the base file name given a full file path. + + @param[in] FullName Fully qualified file path +**/ +VOID +EFIAPI +PrintFileName ( + IN const CHAR8* FullName + ) +{ + const CHAR8* Cursor; + UINTN Size; + + Cursor =3D FullName; + Size =3D 0; + + // Find the end point of the string. + while (*Cursor && Cursor < FullName + MAX_OUTPUT_SIZE) + Cursor++; + + // Find the rightmost path separator. + while (*Cursor !=3D '\\' && *Cursor !=3D '/' && Cursor > FullName) { + Cursor--; + Size++; + } + + // Print base file name. + AcpiViewOutput (L"%.*a", Size - 1, Cursor + 1); +} + +/** + AcpiView output and logging function. Will log the event to + configured output (currently screen) and annotate with colour + and extra metadata. + + @param[in] FileName The full filename of the source file where this + event occured. + @param[in] FunctionName The name of the function where this event occur= ed. + @param[in] LineNumber The line number in the source code where this e= vent + occured. + @param[in] Severity The severity of the event that occured. + @param[in] Format The format of the string describing the event. + @param[in] ... The variable number of parameters that will for= mat the + string supplied in Format. +**/ +VOID +EFIAPI +AcpiViewLog ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN ACPI_ERROR_TYPE Error, + IN ACPI_LOG_SEVERITY Severity, + IN const CHAR16 *Format, + ...) +{ + VA_LIST Marker; + UINTN OriginalAttribute; + + OriginalAttribute =3D gST->ConOut->Mode->Attribute; + ApplyColor (Severity, OriginalAttribute); + VA_START (Marker, Format); + + switch (Severity) { + case ACPI_FATAL: + AcpiViewOutput (L"FATAL "); + break; + case ACPI_ERROR: + AcpiViewOutput (L"ERROR[%s] ", mErrorTypeDesc[Error]); + mTableErrorCount++; + break; + case ACPI_WARN: + AcpiViewOutput (L"WARN "); + mTableWarningCount++; + break; + default: + break; + } + + if (Severity >=3D ACPI_WARN) { + AcpiViewOutput (L"("); + PrintFileName (FileName); + AcpiViewOutput (L":%d) ", LineNumber); + } + + AcpiViewVSOutput (Format, Marker); + AcpiViewOutput (L"\n"); + + VA_END (Marker); + RestoreColor (OriginalAttribute); +} + diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h b/S= hellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h new file mode 100644 index 000000000000..77049cd8eec2 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h @@ -0,0 +1,233 @@ +/** @file + Header file for 'acpiview' logging and output facility + + Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef ACPI_VIEW_LOG_H_ +#define ACPI_VIEW_LOG_H_ + +#include + +/* + Categories of errors that can be logged by AcpiView. +*/ +typedef enum { + ACPI_ERROR_NONE, ///< Not an error + ACPI_ERROR_GENERIC, ///< An unspecified error + ACPI_ERROR_CSUM, ///< A checksum was invalid + ACPI_ERROR_PARSE, ///< Failed to parse item + ACPI_ERROR_LENGTH, ///< Size of a thing is incorrect + ACPI_ERROR_VALUE, ///< The value of a field was incorrect + ACPI_ERROR_CROSS, ///< A constraint on multiple items was violated + ACPI_ERROR_MAX +} ACPI_ERROR_TYPE; + +/* + Different severities of events that can be logged. +*/ +typedef enum { + ACPI_DEBUG, ///< Will not be shown unless specified on command lin= e + ACPI_INFO, ///< Standard output + ACPI_GOOD, ///< Unspecified good outcome, green colour + ACPI_BAD, ///< Unspecified bad outcome, red colour + ACPI_ITEM, ///< Used when describing multiple items + ACPI_HIGHLIGHT, ///< A new context or section has been entered + ACPI_WARN, ///< An unusual event happened + ACPI_ERROR, ///< Acpi table is not conformant + ACPI_FATAL ///< This will abort program execution. +} ACPI_LOG_SEVERITY; + +// Publicly accessible error and warning counters. +extern UINT32 mTableErrorCount; +extern UINT32 mTableWarningCount; + +/** + AcpiView output and logging function. Will log the event to + configured output (currently screen) and annotate with colour + and extra metadata. + + @param[in] FileName The full filename of the source file where this + event occured. + @param[in] FunctionName The name of the function where this event occur= ed. + @param[in] LineNumber The line number in the source code where this e= vent + occured. + @param[in] Severity The severity of the event that occured. + @param[in] Error The type of the erorr reported. May be ACPI_ERR= OR_NONE if the event + is not an error. + @param[in] Format The format of the string describing the event. + @param[in] ... The variable number of parameters that will for= mat the + string supplied in Format. +**/ +VOID +EFIAPI +AcpiViewLog ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN ACPI_ERROR_TYPE Error, + IN ACPI_LOG_SEVERITY Severity, + IN const CHAR16 *Format, + ... + ); + +/** + Formats and prints and ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] ... A variable number of parameters that will be formatted= . +**/ +VOID +EFIAPI +AcpiViewOutput ( + IN const CHAR16 *Format, + IN ... + ); + +/** + Check that a buffer has not been overrun by a member. Can be invoked + using the BufferOverrun macro that fills in local source metadata + (first three parameters) for logging purposes. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ItemDescription User friendly name for the member being check= ed + @param[in] Position Memory address of the member + @param[in] Length Length of the member + @param[in] Buffer Memory address of the buffer where member res= ides + @param[in] BufferSize Size of the buffer where member resides + + @retval TRUE Buffer was overrun + @retval FALSE Buffer is safe +**/ +static +inline +BOOLEAN +EFIAPI +MemberIntegrityInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ItemDescription, + IN UINTN Offset, + IN UINTN Length, + IN VOID *Buffer, + IN UINTN BufferSize) +{ + if (Length =3D=3D 0) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + ACPI_ERROR_LENGTH, + ACPI_ERROR, + L"%a at %p in buffer %p+%x has zero size!", + ItemDescription, + (UINT8 *)Buffer + Offset, + Buffer, + BufferSize); + return TRUE; + } + + if (Offset + Length > BufferSize) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + ACPI_ERROR_LENGTH, + ACPI_ERROR, + L"%a %p+%x overruns buffer %p+%x", + ItemDescription, + (UINT8 *) Buffer + Offset, + Length, + Buffer, + BufferSize); + } + + return (Offset + Length > BufferSize); +} + +// Determine if a member located at Offset into a Buffer lies entirely +// within the BufferSize given the member size is Length +// Evaluates to TRUE and logs error if buffer is overrun or if Length is z= ero +#define AssertMemberIntegrity(Offset, Length, Buffer, BufferSize) \ + MemberIntegrityInternal (__FILE__, __func__, __LINE__, #Length, Offset, = Length, Buffer, BufferSize) + + +/** + Checks that a boolean constraint evaluates correctly. Can be invoked + using the CheckConstraint macro that fills in the source code metadata. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ConstraintText The Source code of the constraint + @param[in] Specification The specification that imposes the constraint + @param[in] Constraint The actual constraint + @ + + @retval TRUE Constraint is violated + @retval FALSE Constraint is not violated +**/ +static +inline +BOOLEAN +EFIAPI +CheckConstraintInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ConstraintText, + IN const CHAR16 *Specification, + IN BOOLEAN Constraint, + IN ACPI_LOG_SEVERITY Severity +) +{ + if (!Constraint) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + Severity =3D=3D ACPI_ERROR ? ACPI_ERROR_VALUE : ACPI_ERROR_NONE, + Severity, + L"(%a) Constraint was violated: %a", + Specification, + ConstraintText); + } + + // Return TRUE if constraint was violated + return !Constraint; +} + +// Evaluates to TRUE and logs error if a constraint is violated +// Constraint internally cast to BOOLEAN using !!(Constraint) +#define AssertConstraint(Specification, Constraint) \ + CheckConstraintInternal ( \ + __FILE__, __func__, __LINE__, #Constraint, Specification, !!(Constrain= t), ACPI_ERROR) + +// Evaluates to TRUE and logs error if a constraint is violated +#define WarnConstraint(Specification, Constraint) \ + CheckConstraintInternal ( \ + __FILE__, __func__, __LINE__, #Constraint, Specification, Constraint, = ACPI_WARN) + + +// Maximum string size that can be printed +#define MAX_OUTPUT_SIZE 256 + +#define _AcpiLog(...) AcpiViewLog(__FILE__, __func__, __LINE__, __VA_ARGS_= _) + +// Generic Loging macro, needs severity and formatted string +#define AcpiLog(Severity, ...) _AcpiLog(ACPI_ERROR_NONE, Severity, __VA_AR= GS__) + +// Log undecorated text, needs formatted string +#define AcpiInfo(...) _AcpiLog(ACPI_ERROR_NONE, ACPI_INFO, __VA_ARGS__) + +// Log error and increment counter, needs error type and formatted string +#define AcpiError(Error, ...) _AcpiLog(Error, ACPI_ERROR, __VA_ARGS__) + +// Log a FATAL error, needs formatted string +#define AcpiFatal(...) _AcpiLog(ACPI_ERROR_GENERIC, ACPI_FATAL, __VA_ARGS_= _) + +#endif // ACPI_VIEW_LOG_H_ diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpi= ViewCommandLib.inf index 91459f9ec632..e0586cbccec2 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.inf @@ -27,6 +27,8 @@ [Sources.common] AcpiView.h AcpiViewConfig.c AcpiViewConfig.h + AcpiViewLog.h + AcpiViewLog.c Parsers/Bgrt/BgrtParser.c Parsers/Dbg2/Dbg2Parser.c Parsers/Dsdt/DsdtParser.c --=20 2.24.1.windows.2