From nobody Mon Feb 9 20:58:59 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 149662882712549.884780168145085; Sun, 4 Jun 2017 19:13:47 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7BDAF21945DDD; Sun, 4 Jun 2017 19:12:40 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3B2E121A16E4A for ; Sun, 4 Jun 2017 19:12:39 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2017 19:13:44 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga002.fm.intel.com with ESMTP; 04 Jun 2017 19:13:43 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,298,1493708400"; d="scan'208";a="1178260082" From: Dandan Bi To: edk2-devel@lists.01.org Date: Mon, 5 Jun 2017 10:13:15 +0800 Message-Id: <1496628796-368572-2-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1496628796-368572-1-git-send-email-dandan.bi@intel.com> References: <1496628796-368572-1-git-send-email-dandan.bi@intel.com> Subject: [edk2] [RFC 1/2] BaseTool/VfrCompile: Support Union type in VFR X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Dong , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Eric Dong Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi --- BaseTools/Source/C/VfrCompile/VfrSyntax.g | 17 +++++++++++++++++ BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 13 ++++++++++++- BaseTools/Source/C/VfrCompile/VfrUtilityLib.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C= /VfrCompile/VfrSyntax.g index 406dbc5..bd8457d 100644 --- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g +++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g @@ -155,10 +155,11 @@ VfrParserStart ( #token Label("label") "label" #token Timeout("timeout") "timeout" #token Inventory("inventory") "inventory" #token NonNvDataMap("_NON_NV_DATA_MAP") "_NON_NV_DATA_MAP" #token Struct("struct") "struct" +#token Union("union") "union" #token Boolean("BOOLEAN") "BOOLEAN" #token Uint64("UINT64") "UINT64" #token Uint32("UINT32") "UINT32" #token Uint16("UINT16") "UINT16" #token Char16("CHAR16") "CHAR16" @@ -270,10 +271,11 @@ vfrProgram > [UINT8 Return] : mConstantOnlyInExpression =3D FALSE; >> ( vfrPragmaPackDefinition | vfrDataStructDefinition + | vfrDataUnionDefinition )* vfrFormSetDefinition << $Return =3D mParserStatus; >> ; =20 @@ -318,10 +320,25 @@ vfrPragmaPackDefinition : | pragmaPackNumber } "\)" ; =20 + vfrDataUnionDefinition : + { TypeDef } Union << gUnionTypeStructure = =3D TRUE; gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >> + { NonNvDataMap } + { + N1:StringIdentifier << _PCATCH(gCVfrVarDat= aTypeDB.SetNewTypeName (N1->getText()), N1); >> + } + OpenBrace + vfrDataStructFields + CloseBrace + { + N2:StringIdentifier << _PCATCH(gCVfrVarDat= aTypeDB.SetNewTypeName (N2->getText()), N2); >> + } + ";" << gCVfrVarDataTypeDB.= DeclareDataTypeEnd (); gUnionTypeStructure =3D FALSE;>> + ; + vfrDataStructDefinition : { TypeDef } Struct << gCVfrVarDataTypeDB.= DeclareDataTypeBegin (); >> { NonNvDataMap } { N1:StringIdentifier << _PCATCH(gCVfrVarDat= aTypeDB.SetNewTypeName (N1->getText()), N1); >> diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/So= urce/C/VfrCompile/VfrUtilityLib.cpp index 2f97975..b392476 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp @@ -1018,12 +1018,14 @@ CVfrVarDataTypeDB::DataTypeAddField ( { SVfrDataField *pNewField =3D NULL; SVfrDataType *pFieldType =3D NULL; SVfrDataField *pTmp; UINT32 Align; + UINT32 MaxDataTypeSize; =20 CHECK_ERROR_RETURN (GetDataType (TypeName, &pFieldType), VFR_RETURN_SUCC= ESS); + MaxDataTypeSize =3D mNewDataType->mTotalSize; =20 if (strlen (FieldName) >=3D MAX_NAME_LEN) { return VFR_RETURN_INVALID_PARAMETER; } =20 @@ -1055,11 +1057,19 @@ CVfrVarDataTypeDB::DataTypeAddField ( pTmp->mNext =3D pNewField; pNewField->mNext =3D NULL; } =20 mNewDataType->mAlign =3D MIN (mPackAlign, MAX (pFieldType->mAlign, m= NewDataType->mAlign)); - mNewDataType->mTotalSize =3D pNewField->mOffset + (pNewField->mFieldType= ->mTotalSize) * ((ArrayNum =3D=3D 0) ? 1 : ArrayNum); + + if (gUnionTypeStructure) { + if (MaxDataTypeSize < pNewField->mFieldType->mTotalSize) { + mNewDataType->mTotalSize =3D pNewField->mFieldType->mTotalSize; + } + pNewField->mOffset =3D 0; + } else { + mNewDataType->mTotalSize =3D pNewField->mOffset + (pNewField->mFieldTy= pe->mTotalSize) * ((ArrayNum =3D=3D 0) ? 1 : ArrayNum); + } =20 return VFR_RETURN_SUCCESS; } =20 VOID @@ -3715,10 +3725,11 @@ CVfrStringDB::GetUnicodeStringTextSize ( } =20 return StringSize; } =20 +BOOLEAN gUnionTypeStructure =3D FALSE; BOOLEAN VfrCompatibleMode =3D FALSE; =20 CVfrVarDataTypeDB gCVfrVarDataTypeDB; CVfrDefaultStore gCVfrDefaultStore; CVfrDataStorage gCVfrDataStorage; diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h b/BaseTools/Sour= ce/C/VfrCompile/VfrUtilityLib.h index 59509c3..b6791ec 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h @@ -19,10 +19,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #include "string.h" #include "Common/UefiBaseTypes.h" #include "EfiVfr.h" #include "VfrError.h" =20 +extern BOOLEAN gUnionTypeStructure; extern BOOLEAN VfrCompatibleMode; =20 #define MAX_NAME_LEN 64 #define MAX_STRING_LEN 0x100 #define DEFAULT_ALIGN 1 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel