From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.43]) by mx.groups.io with SMTP id smtpd.web12.4122.1588704648576244890 for ; Tue, 05 May 2020 11:50:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=jXspkPzr; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.43, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RMSxZDyPHXsHTnnCMHFHBT23jeDxVBD2KbffeTy3LdlduFEP/8uSBPkDbNqprCROsR+RdGvtxpR5j0kBmY4WtiYoUqSyKUtfBzMIJ6VtmPqKG8dxUPyist32i/9/34g7uZLBGjoC/jJpRp1SYV/OXcsUr3DFQ+PS04kJio9kTzhGT8eIZhlmEkJrJ6bd1T/BSaNtKXfOxqhwq9fEx5b/xgqPAgy+JBD34kmRDgScplIodtGKHGkP1wTIX2sTE1uMh4RQx/DSfZ3nPDn1qDyEa39j517mR70PuwUcYk055ZTnPhD/c+gTFaOV8Xfz06lmwNlHcWK6AuzDsuhQ0CXDQg== 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=kJChMrAZ5SenAYWfcD07sXdrfCuGALHAYlJkxSMGSOg=; b=ROFqA/2/Qy0ITr7zvgw0+NQrm16p/IKcUcOmBBsJulH65fmrXQBlePOFnrYjtn+yGOntP7Pk0FNHE5xfXlZs+VXH/uTZgO+mUJkE9JpnZoJQzabX39aRwNY+8O8W/SksoBJqO3mPLALPCp7j9uc+1Mq7aQ8xmTF9gg7eP990U1UWeK2bIuqfKL1TmTxXRdeiOtaOopsWrMuEYyYKgFFiC/7G59xdRtMc7tVSdLLocwT8elbEwlB904UsRlf6AjewmIH5QJgcePikPdPRQ7pEuD8y19A6PJmheXJxY6yODW5Q6/A/oqGPq4EN6kbuSbRG4ydrLHmnbr1vPdjHo/oX8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kJChMrAZ5SenAYWfcD07sXdrfCuGALHAYlJkxSMGSOg=; b=jXspkPzrECvhzv5fQ/StKH4+w3ScR9ZDCLr8sKd9lazRz0MIJNqqVS861NzwKvSFG6lUXvvD9j8tX47sbtX4jp6CD96LLiJs4GvjUNjvb1F6NH6uq5dczpBoikYXm0bAH7GLFnH5kfLlrXBnt1nLfEgj7vW2a7lZAUd2KJMghvQ= Authentication-Results: apple.com; dkim=none (message not signed) header.d=none;apple.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB2469.namprd12.prod.outlook.com (2603:10b6:4:af::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 18:50:46 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.2958.030; Tue, 5 May 2020 18:50:46 +0000 Subject: Re: [edk2-devel] [PATCH 1/4] UefiCpuPkg/CpuExceptionHandler: Make XCODE5 changes toolchain specific To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Anthony Perard , Benjamin You , Guo Dong , Julien Grall , Maurice Ma , Andrew Fish References: <160B00E54624ADAA.10991@groups.io> From: "Lendacky, Thomas" Message-ID: <0bb8a47d-7172-61dc-c4b7-e123c5bc66e3@amd.com> Date: Tue, 5 May 2020 13:50:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 In-Reply-To: <160B00E54624ADAA.10991@groups.io> X-ClientProxiedBy: SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from office-linux.texastahm.com (67.79.209.213) by SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 18:50:45 +0000 X-Originating-IP: [67.79.209.213] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 77530275-9ff5-40bb-60a0-08d7f125389a X-MS-TrafficTypeDiagnostic: DM5PR12MB2469:|DM5PR12MB2469: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g0DfQ8z+OaIg87q5aV0rwGy9x5iJ9LBW7wnDxeJ+HXa0L98B9BFhh0BfIybbybAhpnR7EmHCg5XO8M/ZQ7ccq2k2zeGV4uUFQk/YNkLRmjiYhXK29r4k+pwkSdnEL3TJdORlvMgJzNJ+ffkSZOP/8d5mjvvMytkK2sbSXYzK0ekgrdG3CNxKs7nezN6RrBqZW9Je766nJbzyKqSXuS2EYrRr6ufzUi0jsmQlSy1U+/1FYzXoT24dSwlHMbpSuPe7KPY3CzgMaThXjFfEF6mW1gdYgdVcf+c7a7pOqf5h3jP7zeMlv/dYrS9Fcuvz0F9nsCbp3tPCYnl1lQtH7dBna0yGyn1IZXPk17NLIvZNtf/MjxTMlJp2tkrMsy9L2FWijSOoTTVS0bvVAJMOQYq/34itRHzEyej5DSt28xLtq1S4ZEU94MrAHwKbtQTL6r2AMdx36LBSp7A6R7kqPbSy6epjSJ2xO6GbuamVq+c0cL8WapNWtzjTNiY38e0t3t8GUJT0XxSL+pE+uQlwVljl24AuVgRW+XfGk4Lzs2b+rVphk17+Q9dLmaF1WlqJvXqQNHI5yAmh0wpr3EEgZQjOka0jSusABwY5KnpXcODIjlxWSLRMWE8JK4HKEUGbSP4JrNMs6teCSaLPgGpbiJ1RdA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(39860400002)(366004)(136003)(396003)(346002)(33430700001)(66946007)(30864003)(52116002)(45080400002)(316002)(186003)(66476007)(54906003)(478600001)(66556008)(26005)(6506007)(956004)(31686004)(16526019)(31696002)(19627235002)(53546011)(2616005)(4326008)(5660300002)(86362001)(36756003)(6486002)(2906002)(8676002)(966005)(8936002)(33440700001)(6916009)(6512007)(7416002)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /ulGap5JLaDSivXOeDdgDzlniFmQkt+mIDWuWh8mmju/6Zx3I3nzNWsFwAHvT76A3gbxEggRCdGY2h2xySsGIvIg8bLNDcdFiUlwugcyp87vgFdeh2/XVu/QG3fJLWZ7mRr3Ys1oLDJlzKpMeeopIzOMxsjieE718arnmOApGK9qheHSBXUu36O0BjBOAKy+dgYs3AY1AA+v00C5ngFQx8kPbQpE5CxNNa9eVU4eUiFWY2NFK/RODnovI1B4vEu6aNBZPxs0ITiKFM/pZ800+pAoMI7c75YEC+ee+hUQ3F+wCVE9pqTIwl3zdwa9QwgQinbWPW8hf+THC56Ln3yHYxTWjczFOOd2kLuFsiyxDy5We5BxCIcUuzH8piQufPG+ivNPYzhX1LsMBfqh15W8WCkmhWbXKlxc0xUD6H+ZCIRTDMNOEyShJ1OzBGnjrCkOdq3BuZfq0QuonE04Sz48JqUXDLiy3G2M/9dodgl0HdyfMjOkyYM+DiCpjBiYW5Rx2/ioecqq+xJME4NP3UOqL5K+gSwZd7H91j6o5HVPQTYa8+U6ZHABHu+3O+BPMqCujtDTcmDlvvYW2eVAD9ScATpRmg3m7qakYlP5G5AZqdOxlVshbc07YUI+RQ0SWbhUMghJ3ZkMaSgL0fMgj0wyKbmmcCKPydlTDTuvMuM7SjJLLmg/hg+qXqkZ/+e+jDIJTMvqpFEoEFGZzoaLMD1nkfwWrsSWSfsT4beA6PfATdCf8JrfmILSiHTejOwZj3yVPCw6Fi9UgA4a1IuPo4rkIEmut/ZoJUgH55akx1x8p+s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77530275-9ff5-40bb-60a0-08d7f125389a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 18:50:46.5348 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: THUQ7cJ6F+/4jgunswYTBHidUXWZnkL7ExV/C7eqAZT65u43QxuWt0k9sKTVHa0FoGpka0vwRvXzfIPdWOK3Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2469 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 5/1/20 3:17 PM, Lendacky, Thomas via groups.io wrote: > BZ: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2340&data=02%7C01%7Cthomas.lendacky%40amd.com%7Ca1268b8e6d554b6c55ca08d7ee0cbf84%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637239610850064292&sdata=soYzRSutJ%2Bepugf2XnzRUpMCLa1GaKoBD%2FX1F4HPCt8%3D&reserved=0 > > Commit 2db0ccc2d7fe ("UefiCpuPkg: Update CpuExceptionHandlerLib pass > XCODE5 tool chain") introduced binary patching into the exception handling > support. CPU exception handling is allowed during SEC and this results in > binary patching of flash, which should not be done. > > Separate the changes from commit 2db0ccc2d7fe into an XCODE5 toolchain > specific file, Xcode5ExceptionHandlerAsm.nasm, and create new INF files > for an XCODE5 version of CpuExceptionHandlerLib. Update the UefiCpuPkg.dsc > file to use the new files when the XCODE5 toolchain is used. I used the same FILE_GUID for the new INF files as the old ones. I wasn't sure if they should get new GUIDs or use the same GUID as the original since only one of the libraries will/should be used at a time. Let me know if they need new GUIDs and I'll update and repost the series. Thanks, Tom > > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Liming Gao > Signed-off-by: Tom Lendacky > --- > UefiCpuPkg/UefiCpuPkg.dsc | 23 + > .../Xcode5DxeCpuExceptionHandlerLib.inf | 64 +++ > .../Xcode5PeiCpuExceptionHandlerLib.inf | 63 +++ > .../Xcode5SecPeiCpuExceptionHandlerLib.inf | 55 +++ > .../Xcode5SmmCpuExceptionHandlerLib.inf | 59 +++ > .../X64/Xcode5ExceptionHandlerAsm.nasm | 413 ++++++++++++++++++ > 6 files changed, 677 insertions(+) > create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf > create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf > create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf > create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf > create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm > > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc > index d28cb5cccb52..ad298011232d 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -59,7 +59,11 @@ [LibraryClasses] > > [LibraryClasses.common.SEC] > PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf > +!if $(TOOL_CHAIN_TAG) != "XCODE5" > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf > +!else > + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf > +!endif > HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf > PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > @@ -73,12 +77,20 @@ [LibraryClasses.common.PEIM] > > [LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] > PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf > +!if $(TOOL_CHAIN_TAG) != "XCODE5" > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf > +!else > + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf > +!endif > > [LibraryClasses.common.DXE_DRIVER] > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > +!if $(TOOL_CHAIN_TAG) != "XCODE5" > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf > +!else > + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf > +!endif > MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf > > @@ -86,7 +98,11 @@ [LibraryClasses.common.DXE_SMM_DRIVER] > SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > +!if $(TOOL_CHAIN_TAG) != "XCODE5" > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf > +!else > + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf > +!endif > > [LibraryClasses.common.UEFI_APPLICATION] > UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf > @@ -122,10 +138,17 @@ [Components.IA32, Components.X64] > UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf > UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf > UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf > +!if $(TOOL_CHAIN_TAG) != "XCODE5" > UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf > UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf > UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf > UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf > +!else > + UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf > + UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf > + UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf > + UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf > +!endif > UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf > UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf > new file mode 100644 > index 000000000000..ef37efec6246 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5DxeCpuExceptionHandlerLib.inf > @@ -0,0 +1,64 @@ > +## @file > +# CPU Exception Handler library instance for DXE modules. > +# > +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = Xcode5DxeCpuExceptionHandlerLib > + MODULE_UNI_FILE = DxeCpuExceptionHandlerLib.uni > + FILE_GUID = B6E9835A-EDCF-4748-98A8-27D3C722E02D > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.1 > + LIBRARY_CLASS = CpuExceptionHandlerLib|DXE_CORE DXE_DRIVER UEFI_APPLICATION > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources.Ia32] > + Ia32/ExceptionHandlerAsm.nasm > + Ia32/ExceptionTssEntryAsm.nasm > + Ia32/ArchExceptionHandler.c > + Ia32/ArchInterruptDefs.h > + Ia32/ArchAMDSevVcHandler.c > + > +[Sources.X64] > + X64/Xcode5ExceptionHandlerAsm.nasm > + X64/ArchExceptionHandler.c > + X64/ArchInterruptDefs.h > + X64/ArchAMDSevVcHandler.c > + > +[Sources.common] > + CpuExceptionCommon.h > + CpuExceptionCommon.c > + PeiDxeSmmCpuException.c > + DxeException.c > + AMDSevVcHandler.c > + AMDSevVcCommon.h > + > +[Pcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard > + gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList > + gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + SerialPortLib > + PrintLib > + SynchronizationLib > + LocalApicLib > + PeCoffGetEntryPointLib > + MemoryAllocationLib > + DebugLib > + VmgExitLib > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf > new file mode 100644 > index 000000000000..830ed1eb8bad > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5PeiCpuExceptionHandlerLib.inf > @@ -0,0 +1,63 @@ > +## @file > +# CPU Exception Handler library instance for PEI module. > +# > +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = Xcode5PeiCpuExceptionHandlerLib > + MODULE_UNI_FILE = PeiCpuExceptionHandlerLib.uni > + FILE_GUID = 980DDA67-44A6-4897-99E6-275290B71F9E > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.1 > + LIBRARY_CLASS = CpuExceptionHandlerLib|PEI_CORE PEIM > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources.Ia32] > + Ia32/ExceptionHandlerAsm.nasm > + Ia32/ExceptionTssEntryAsm.nasm > + Ia32/ArchExceptionHandler.c > + Ia32/ArchInterruptDefs.h > + Ia32/ArchAMDSevVcHandler.c > + > +[Sources.X64] > + X64/Xcode5ExceptionHandlerAsm.nasm > + X64/ArchExceptionHandler.c > + X64/ArchInterruptDefs.h > + X64/ArchAMDSevVcHandler.c > + > +[Sources.common] > + CpuExceptionCommon.h > + CpuExceptionCommon.c > + PeiCpuException.c > + PeiDxeSmmCpuException.c > + AMDSevVcHandler.c > + AMDSevVcCommon.h > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + SerialPortLib > + PrintLib > + LocalApicLib > + PeCoffGetEntryPointLib > + HobLib > + MemoryAllocationLib > + SynchronizationLib > + VmgExitLib > + > +[Pcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES > + > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf > new file mode 100644 > index 000000000000..36420be22faa > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf > @@ -0,0 +1,55 @@ > +## @file > +# CPU Exception Handler library instance for SEC/PEI modules. > +# > +# Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = Xcode5SecPeiCpuExceptionHandlerLib > + MODULE_UNI_FILE = SecPeiCpuExceptionHandlerLib.uni > + FILE_GUID = CA4BBC99-DFC6-4234-B553-8B6586B7B113 > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.1 > + LIBRARY_CLASS = CpuExceptionHandlerLib|SEC PEI_CORE PEIM > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources.Ia32] > + Ia32/ExceptionHandlerAsm.nasm > + Ia32/ExceptionTssEntryAsm.nasm > + Ia32/ArchExceptionHandler.c > + Ia32/ArchInterruptDefs.h > + Ia32/ArchAMDSevVcHandler.c > + > +[Sources.X64] > + X64/Xcode5ExceptionHandlerAsm.nasm > + X64/ArchExceptionHandler.c > + X64/ArchInterruptDefs.h > + X64/ArchAMDSevVcHandler.c > + > +[Sources.common] > + CpuExceptionCommon.h > + CpuExceptionCommon.c > + SecPeiCpuException.c > + AMDSevVcHandler.c > + AMDSevVcCommon.h > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + SerialPortLib > + PrintLib > + LocalApicLib > + PeCoffGetEntryPointLib > + VmgExitLib > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf > new file mode 100644 > index 000000000000..8f71a45c86d5 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SmmCpuExceptionHandlerLib.inf > @@ -0,0 +1,59 @@ > +## @file > +# CPU Exception Handler library instance for SMM modules. > +# > +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = Xcode5SmmCpuExceptionHandlerLib > + MODULE_UNI_FILE = SmmCpuExceptionHandlerLib.uni > + FILE_GUID = 8D2C439B-3981-42ff-9CE5-1B50ECA502D6 > + MODULE_TYPE = DXE_SMM_DRIVER > + VERSION_STRING = 1.1 > + LIBRARY_CLASS = CpuExceptionHandlerLib|DXE_SMM_DRIVER > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources.Ia32] > + Ia32/ExceptionHandlerAsm.nasm > + Ia32/ExceptionTssEntryAsm.nasm > + Ia32/ArchExceptionHandler.c > + Ia32/ArchInterruptDefs.h > + Ia32/ArchAMDSevVcHandler.c > + > +[Sources.X64] > + X64/Xcode5ExceptionHandlerAsm.nasm > + X64/ArchExceptionHandler.c > + X64/ArchInterruptDefs.h > + X64/ArchAMDSevVcHandler.c > + > +[Sources.common] > + CpuExceptionCommon.h > + CpuExceptionCommon.c > + PeiDxeSmmCpuException.c > + SmmException.c > + AMDSevVcHandler.c > + AMDSevVcCommon.h > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + SerialPortLib > + PrintLib > + SynchronizationLib > + LocalApicLib > + PeCoffGetEntryPointLib > + DebugLib > + VmgExitLib > + > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm > new file mode 100644 > index 000000000000..26cae56cc5cf > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm > @@ -0,0 +1,413 @@ > +;------------------------------------------------------------------------------ ; > +; Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; ExceptionHandlerAsm.Asm > +; > +; Abstract: > +; > +; x64 CPU Exception Handler > +; > +; Notes: > +; > +;------------------------------------------------------------------------------ > + > +; > +; CommonExceptionHandler() > +; > + > +%define VC_EXCEPTION 29 > + > +extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions > +extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag > +extern ASM_PFX(CommonExceptionHandler) > + > +SECTION .data > + > +DEFAULT REL > +SECTION .text > + > +ALIGN 8 > + > +AsmIdtVectorBegin: > +%rep 32 > + db 0x6a ; push #VectorNum > + db ($ - AsmIdtVectorBegin) / ((AsmIdtVectorEnd - AsmIdtVectorBegin) / 32) ; VectorNum > + push rax > + mov rax, strict qword 0 ; mov rax, ASM_PFX(CommonInterruptEntry) > + jmp rax > +%endrep > +AsmIdtVectorEnd: > + > +HookAfterStubHeaderBegin: > + db 0x6a ; push > +@VectorNum: > + db 0 ; 0 will be fixed > + push rax > + mov rax, strict qword 0 ; mov rax, HookAfterStubHeaderEnd > +JmpAbsoluteAddress: > + jmp rax > +HookAfterStubHeaderEnd: > + mov rax, rsp > + and sp, 0xfff0 ; make sure 16-byte aligned for exception context > + sub rsp, 0x18 ; reserve room for filling exception data later > + push rcx > + mov rcx, [rax + 8] > + bt [ASM_PFX(mErrorCodeFlag)], ecx > + jnc .0 > + push qword [rsp] ; push additional rcx to make stack alignment > +.0: > + xchg rcx, [rsp] ; restore rcx, save Exception Number in stack > + push qword [rax] ; push rax into stack to keep code consistence > + > +;---------------------------------------; > +; CommonInterruptEntry ; > +;---------------------------------------; > +; The follow algorithm is used for the common interrupt routine. > +; Entry from each interrupt with a push eax and eax=interrupt number > +; Stack frame would be as follows as specified in IA32 manuals: > +; > +; +---------------------+ <-- 16-byte aligned ensured by processor > +; + Old SS + > +; +---------------------+ > +; + Old RSP + > +; +---------------------+ > +; + RFlags + > +; +---------------------+ > +; + CS + > +; +---------------------+ > +; + RIP + > +; +---------------------+ > +; + Error Code + > +; +---------------------+ > +; + Vector Number + > +; +---------------------+ > +; + RBP + > +; +---------------------+ <-- RBP, 16-byte aligned > +; The follow algorithm is used for the common interrupt routine. > +global ASM_PFX(CommonInterruptEntry) > +ASM_PFX(CommonInterruptEntry): > + cli > + pop rax > + ; > + ; All interrupt handlers are invoked through interrupt gates, so > + ; IF flag automatically cleared at the entry point > + ; > + xchg rcx, [rsp] ; Save rcx into stack and save vector number into rcx > + and rcx, 0xFF > + cmp ecx, 32 ; Intel reserved vector for exceptions? > + jae NoErrorCode > + bt [ASM_PFX(mErrorCodeFlag)], ecx > + jc HasErrorCode > + > +NoErrorCode: > + > + ; > + ; Push a dummy error code on the stack > + ; to maintain coherent stack map > + ; > + push qword [rsp] > + mov qword [rsp + 8], 0 > +HasErrorCode: > + push rbp > + mov rbp, rsp > + push 0 ; clear EXCEPTION_HANDLER_CONTEXT.OldIdtHandler > + push 0 ; clear EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag > + > + ; > + ; Stack: > + ; +---------------------+ <-- 16-byte aligned ensured by processor > + ; + Old SS + > + ; +---------------------+ > + ; + Old RSP + > + ; +---------------------+ > + ; + RFlags + > + ; +---------------------+ > + ; + CS + > + ; +---------------------+ > + ; + RIP + > + ; +---------------------+ > + ; + Error Code + > + ; +---------------------+ > + ; + RCX / Vector Number + > + ; +---------------------+ > + ; + RBP + > + ; +---------------------+ <-- RBP, 16-byte aligned > + ; > + > + ; > + ; Since here the stack pointer is 16-byte aligned, so > + ; EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64 > + ; is 16-byte aligned > + ; > + > +;; UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; > +;; UINT64 R8, R9, R10, R11, R12, R13, R14, R15; > + push r15 > + push r14 > + push r13 > + push r12 > + push r11 > + push r10 > + push r9 > + push r8 > + push rax > + push qword [rbp + 8] ; RCX > + push rdx > + push rbx > + push qword [rbp + 48] ; RSP > + push qword [rbp] ; RBP > + push rsi > + push rdi > + > +;; UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero > + movzx rax, word [rbp + 56] > + push rax ; for ss > + movzx rax, word [rbp + 32] > + push rax ; for cs > + mov rax, ds > + push rax > + mov rax, es > + push rax > + mov rax, fs > + push rax > + mov rax, gs > + push rax > + > + mov [rbp + 8], rcx ; save vector number > + > +;; UINT64 Rip; > + push qword [rbp + 24] > + > +;; UINT64 Gdtr[2], Idtr[2]; > + xor rax, rax > + push rax > + push rax > + sidt [rsp] > + mov bx, word [rsp] > + mov rax, qword [rsp + 2] > + mov qword [rsp], rax > + mov word [rsp + 8], bx > + > + xor rax, rax > + push rax > + push rax > + sgdt [rsp] > + mov bx, word [rsp] > + mov rax, qword [rsp + 2] > + mov qword [rsp], rax > + mov word [rsp + 8], bx > + > +;; UINT64 Ldtr, Tr; > + xor rax, rax > + str ax > + push rax > + sldt ax > + push rax > + > +;; UINT64 RFlags; > + push qword [rbp + 40] > + > +;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8; > + mov rax, cr8 > + push rax > + mov rax, cr4 > + or rax, 0x208 > + mov cr4, rax > + push rax > + mov rax, cr3 > + push rax > + mov rax, cr2 > + push rax > + xor rax, rax > + push rax > + mov rax, cr0 > + push rax > + > +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; > + cmp qword [rbp + 8], VC_EXCEPTION > + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored > + > + mov rax, dr7 > + push rax > + mov rax, dr6 > + push rax > + mov rax, dr3 > + push rax > + mov rax, dr2 > + push rax > + mov rax, dr1 > + push rax > + mov rax, dr0 > + push rax > + jmp DrFinish > + > +VcDebugRegs: > +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid exception recursion > + xor rax, rax > + push rax > + push rax > + push rax > + push rax > + push rax > + push rax > + > +DrFinish: > +;; FX_SAVE_STATE_X64 FxSaveState; > + sub rsp, 512 > + mov rdi, rsp > + db 0xf, 0xae, 0x7 ;fxsave [rdi] > + > +;; UEFI calling convention for x64 requires that Direction flag in EFLAGs is clear > + cld > + > +;; UINT32 ExceptionData; > + push qword [rbp + 16] > + > +;; Prepare parameter and call > + mov rcx, [rbp + 8] > + mov rdx, rsp > + ; > + ; Per X64 calling convention, allocate maximum parameter stack space > + ; and make sure RSP is 16-byte aligned > + ; > + sub rsp, 4 * 8 + 8 > + call ASM_PFX(CommonExceptionHandler) > + add rsp, 4 * 8 + 8 > + > + cli > +;; UINT64 ExceptionData; > + add rsp, 8 > + > +;; FX_SAVE_STATE_X64 FxSaveState; > + > + mov rsi, rsp > + db 0xf, 0xae, 0xE ; fxrstor [rsi] > + add rsp, 512 > + > +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; > +;; Skip restoration of DRx registers to support in-circuit emualators > +;; or debuggers set breakpoint in interrupt/exception context > + add rsp, 8 * 6 > + > +;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8; > + pop rax > + mov cr0, rax > + add rsp, 8 ; not for Cr1 > + pop rax > + mov cr2, rax > + pop rax > + mov cr3, rax > + pop rax > + mov cr4, rax > + pop rax > + mov cr8, rax > + > +;; UINT64 RFlags; > + pop qword [rbp + 40] > + > +;; UINT64 Ldtr, Tr; > +;; UINT64 Gdtr[2], Idtr[2]; > +;; Best not let anyone mess with these particular registers... > + add rsp, 48 > + > +;; UINT64 Rip; > + pop qword [rbp + 24] > + > +;; UINT64 Gs, Fs, Es, Ds, Cs, Ss; > + pop rax > + ; mov gs, rax ; not for gs > + pop rax > + ; mov fs, rax ; not for fs > + ; (X64 will not use fs and gs, so we do not restore it) > + pop rax > + mov es, rax > + pop rax > + mov ds, rax > + pop qword [rbp + 32] ; for cs > + pop qword [rbp + 56] ; for ss > + > +;; UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; > +;; UINT64 R8, R9, R10, R11, R12, R13, R14, R15; > + pop rdi > + pop rsi > + add rsp, 8 ; not for rbp > + pop qword [rbp + 48] ; for rsp > + pop rbx > + pop rdx > + pop rcx > + pop rax > + pop r8 > + pop r9 > + pop r10 > + pop r11 > + pop r12 > + pop r13 > + pop r14 > + pop r15 > + > + mov rsp, rbp > + pop rbp > + add rsp, 16 > + cmp qword [rsp - 32], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler > + jz DoReturn > + cmp qword [rsp - 40], 1 ; check EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag > + jz ErrorCode > + jmp qword [rsp - 32] > +ErrorCode: > + sub rsp, 8 > + jmp qword [rsp - 24] > + > +DoReturn: > + cmp qword [ASM_PFX(mDoFarReturnFlag)], 0 ; Check if need to do far return instead of IRET > + jz DoIret > + push rax > + mov rax, rsp ; save old RSP to rax > + mov rsp, [rsp + 0x20] > + push qword [rax + 0x10] ; save CS in new location > + push qword [rax + 0x8] ; save EIP in new location > + push qword [rax + 0x18] ; save EFLAGS in new location > + mov rax, [rax] ; restore rax > + popfq ; restore EFLAGS > + DB 0x48 ; prefix to composite "retq" with next "retf" > + retf ; far return > +DoIret: > + iretq > + > +;------------------------------------------------------------------------------------- > +; GetTemplateAddressMap (&AddressMap); > +;------------------------------------------------------------------------------------- > +; comments here for definition of address map > +global ASM_PFX(AsmGetTemplateAddressMap) > +ASM_PFX(AsmGetTemplateAddressMap): > + lea rax, [AsmIdtVectorBegin] > + mov qword [rcx], rax > + mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32 > + lea rax, [HookAfterStubHeaderBegin] > + mov qword [rcx + 0x10], rax > + > +; Fix up CommonInterruptEntry address > + lea rax, [ASM_PFX(CommonInterruptEntry)] > + lea rcx, [AsmIdtVectorBegin] > +%rep 32 > + mov qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)], rax > + add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32 > +%endrep > +; Fix up HookAfterStubHeaderEnd > + lea rax, [HookAfterStubHeaderEnd] > + lea rcx, [JmpAbsoluteAddress] > + mov qword [rcx - 8], rax > + > + ret > + > +;------------------------------------------------------------------------------------- > +; AsmVectorNumFixup (*NewVectorAddr, VectorNum, *OldVectorAddr); > +;------------------------------------------------------------------------------------- > +global ASM_PFX(AsmVectorNumFixup) > +ASM_PFX(AsmVectorNumFixup): > + mov rax, rdx > + mov [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al > + ret > + >