From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 947B3D802AD for ; Mon, 6 May 2024 03:38:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=V82o4GHVKjYoFkPftxAn3pNXSdd/4hV1GObICGbF6hM=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1714966714; v=1; b=yoZVKNzsZzyl817eRQkESL/ALfIv9+64ndoYSpZ4N0sFVMZ2DWb/Xd1PJ4rskLub8c8+c95v eqSeJcL0jL+mRMNVbQgLP8AFXN6aOQbYNMLu902DrotoxJkGl5diVl1L08lLRhB3ZJhiwtUZpJF NcB/sHqQLYos0ieP9GYoPQljPlA+AtXHj2p0vscEJghSjcW5Pmysmn1j8COTH6OyIk+tZA1u1u4 CpvdSM2QMdAaE2JvesF2dqG7CuFset9//E5Q4bU2lIune3n5SoHuL3Bd7Nhcj4+7OqIn9SyFrRV ycr75CDglBZxmU/sKY7xlWsr1OjsUM7HFfoFVJPW8Wc/Q== X-Received: by 127.0.0.2 with SMTP id icwwYY7687511xR0M7qppcJ1; Sun, 05 May 2024 20:38:34 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mx.groups.io with SMTP id smtpd.web11.12734.1714966712330816329 for ; Sun, 05 May 2024 20:38:32 -0700 X-CSE-ConnectionGUID: YLqC+2HNT0is5KienxqYcQ== X-CSE-MsgGUID: lf9fyCXcTUGdp0+WsJ+o5A== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="14501492" X-IronPort-AV: E=Sophos;i="6.07,257,1708416000"; d="scan'208,217";a="14501492" X-Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 20:38:32 -0700 X-CSE-ConnectionGUID: 6YYRkxdpQJWHPcOg/7gd4A== X-CSE-MsgGUID: 5xpnQcUbTmOTsjeL+zlQ3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,257,1708416000"; d="scan'208,217";a="58906265" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 05 May 2024 20:38:31 -0700 X-Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 5 May 2024 20:38:30 -0700 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Sun, 5 May 2024 20:38:30 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.100) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sun, 5 May 2024 20:38:29 -0700 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by IA0PR11MB7815.namprd11.prod.outlook.com (2603:10b6:208:404::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 03:38:27 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::41a4:c775:32e6:76a8]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::41a4:c775:32e6:76a8%4]) with mapi id 15.20.7544.041; Mon, 6 May 2024 03:38:27 +0000 From: "Ni, Ray" To: "Wu, Jiaxin" , "devel@edk2.groups.io" CC: "Zeng, Star" , Gerd Hoffmann , "Kumar, Rahul R" Subject: Re: [edk2-devel] [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic Thread-Topic: [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocation logic Thread-Index: AQHal9PPylstn2GvX06D0TuIedDWNLGJnfVK Date: Mon, 6 May 2024 03:38:27 +0000 Message-ID: References: <20240426121720.54308-1-jiaxin.wu@intel.com> <20240426121720.54308-15-jiaxin.wu@intel.com> In-Reply-To: <20240426121720.54308-15-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|IA0PR11MB7815:EE_ x-ms-office365-filtering-correlation-id: 3829424f-93f2-4649-4291-08dc6d7dfda2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: =?us-ascii?Q?Jod6y8GcTV/6Pdl/2Y2TRakvDDNkWlcMlayvFuvg/6JFpiEp5Ebahm+bD3yb?= =?us-ascii?Q?igKIbC8a5vL/PjaJr3jYojLU0iAerCV7dySFRU3z54L9UgPYrnT7vOVhM3cM?= =?us-ascii?Q?H+sSxBS3omyHSDvo+HTgDthejspPL+i4zHXcCh0hT9qUCKk6ksHSabegaBYW?= =?us-ascii?Q?MoMMXrzvn6a/Qe1LMR+gOy7mnxnKl8ZXXNoQOTMcMilBjf457bbUMYxZO0Un?= =?us-ascii?Q?OUTw7diDpftAVphGoaU4omqOn4QseDtf5M3XzTVrNXLas07KcuEANVPvg07i?= =?us-ascii?Q?jeaQlbKGhaEtnXQjrvSbG1reXjp+7m0R4rRfL8kWbl/4rmGjG8S8JJjzPSyq?= =?us-ascii?Q?oqw5vDs0EqmNU4kYh5u/DMRa6ziRu/mSzDCxKKdBaDkVkhGs8UTbjGhsajNN?= =?us-ascii?Q?fAdZwO3GNa8ee/1d1ul3gm2g0begarG6gV81wPQG7s/spVYt6jTtOEbV29ne?= =?us-ascii?Q?1yZmLbapYNGUhz1d3UzRI3Atup2mLaQIKusGzrqXhG7Hfu1l7ThSWRW3cIA3?= =?us-ascii?Q?5uiKTwaeuguF01ivxenkoxRYbpifrkmjuyGU9QpdwnRIqtbwpLG/PYUlm7J9?= =?us-ascii?Q?oPQXW8c28FTMnDgLNBFZjm5Jf6Kv0DXYNGDpgW7bPq9iL+mGDZZLFFJA2Ybv?= =?us-ascii?Q?jWv5kmO4P6K7h3l2ZOkupAdjxWI+/JEEXHHrXawOMafCdl+Jwgxa22YP2xGA?= =?us-ascii?Q?IS8+vJYWezIf2OJr50+dvZ7/+hoskq53V+0vVZre9H2A2kIOGkyV+R2sIFHd?= =?us-ascii?Q?hX/wIO98THBK/4Z20IAesTyHX+NZUtDfmie+Q4rnUdo5ub1RRWKt6xLvo/AQ?= =?us-ascii?Q?RCqiH3vQeV7aAua2D3raReQabpLIW2QOy+xUn5I5UNy0DBlI3hD75lzfKJyC?= =?us-ascii?Q?mUvWiCs4EjqvPQje5s48+efP7PZ8Sb/iddFen6Y1N32LbLFImCpSG9eW5gcp?= =?us-ascii?Q?7BQnAhQn2SgxdBKNW2CHV09fmSUPo9G+vXDrAvPFHbYSfFZwjMfyIZMYBg2n?= =?us-ascii?Q?pqX14xof5GIbaiWkGZ3uuvqCj0KrrdlpkX667HqT1Rbxb9bxqWWhKm7qnCmD?= =?us-ascii?Q?6T97PWpZY/mswA5TSiA3KvW2jsv1u1I8Tc6Dr0A64G8YpmGahwJOOM293vIA?= =?us-ascii?Q?ShIbV81x/Q0VOxVA8+XVdqvEX+8yhSTcx2Kf7/9rsdC/tD9c4RyErDkBcckt?= =?us-ascii?Q?wtcvR2WbRW2/ZdY28as7fCQ+UIe+peWhLD8ERjiU0C5DIGj3dgB6e5Y909Sp?= =?us-ascii?Q?dY2VhJicSLqovRXplRsDytVrbz7ZZa4u9n+iAIQemdwzNixFM12yIF+swIw9?= =?us-ascii?Q?3YS+4QYlaQjoDYon9GGhPS0kFceVoWMefn9lKtDoUS4acQ=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?zgwS6iCbveaOUIxcmStLVYGmxSn6jS58KwTESkvErN8jddEzCDC2kLkfvt7n?= =?us-ascii?Q?RCVoTI++bEAtN+2NdgtiToBx8ZoSsVUaD78aPfoJM0M3X3qC+PNFee5RMIAB?= =?us-ascii?Q?TKpB6RQJg4XpTXM6i5DfJuWMxTQEj662ghvkKyU1eNV5FV7Oi0JPt1HTmtCw?= =?us-ascii?Q?Go3Q15KxBbEBMKAk5HxLt1aFEevg7QcIBZlOmVNdyQ59kMrmUxjHFvNvSR3A?= =?us-ascii?Q?Z41tGdB3byJVA/vAZLjNJAcccbryTSx3NG2wnlVw2hQCb+pDZgIPHdfVF/YF?= =?us-ascii?Q?DsoHFriSsSXRlpsNQcv97vgOHX+F1h+TnBe1a7jK7Yvq+2A7nVsTr+la4qsq?= =?us-ascii?Q?8QYUShH+4hoIntlH6Opx/6BnmF1YGnyc6jqG8VqZQqDivc6bedGGL+r/qyMS?= =?us-ascii?Q?sLAQMe5NF3GF3wnlPNxAJ7O/PXhxjk4L235n3qxM8t5rSNtKBAKafmc7apUQ?= =?us-ascii?Q?r5Ax/s2ip1k9BBdJws9rKpo0XBa/78pw50ESvuPpRl2vmFB/8rOfeOZPZhBg?= =?us-ascii?Q?9K8hcilf1/Sv+wSWr6keG7A3EjjzxLltAedHwnKdRpUbF3gaF7lj4w5S+qOs?= =?us-ascii?Q?o1xJItO8w3rEm5eCT2zB9LYk0jWy8KtTFz6PvxP+H6IOrHtkcfLCaV9Bd4Fp?= =?us-ascii?Q?4lQMOSnjTvh5xhuCCyVv5z/ZZKp/oDPL+9E5g84E9HzD5xYFpiyq7QA0ftTR?= =?us-ascii?Q?qO1/pqKWyRZAYWYcZZImUN3Hp+Z0w5bnQ3mGOJvPbKKKpNSR0xv/Nqnc84aH?= =?us-ascii?Q?UlWmW2+Fx2WxqcFaotwLDbTBMzSI+Cpdjj8/iHwu2/hmxPnA2tt78K51NcGp?= =?us-ascii?Q?+YeFRXi3U68kRnabTS8fQGBpL27ZbbqS8OtnDabC0+LqVUI6m1GXaKi9d+K+?= =?us-ascii?Q?uX9L1/E/VDuZXZLQmSw4SZrL6/UwZxuEYwEcy7aq9c/2G7sPfjy693WvNYRM?= =?us-ascii?Q?wqg97oJ8y9D0PZPQYYPMTfclmOEhVhUV6Btl0I1d6D1zB8ly1AJxI/I86u5D?= =?us-ascii?Q?E/L2qVCqgDQ0HvncsdQ6+oJdx49MXMyV4cqw3a8MQT2Qb2p8bbRjgUks+9G9?= =?us-ascii?Q?hPZYRD/ipsmDQ7HB98pTiKTyJYHrMVk17oomRK1BYffJnDiAzmIHI5fncIdw?= =?us-ascii?Q?dkvSTPqleFFvYoHXmx+KenDFqUaPROSfLBDRDDTPwpMr0/deM8VE+1dQ73sK?= =?us-ascii?Q?ki7OHb7ObHe1c2pEyQvNE4u5T762DX6WzFbGDZr5ZyhUwWLepHKQtkPpqF4J?= =?us-ascii?Q?SQMItXlQ1nLHDXAxm9GbDku0mZosQlenHPp10uJ8Dd/ejaZ/bnFcnOSFkyCw?= =?us-ascii?Q?bRVq/NZ4MkEAHQ3o0JTN0kwhQQw28ooq5T1z0t/EmIPj12cLTLrqlAoFCmaw?= =?us-ascii?Q?7/8IUl+X6IJC9T0SaffgXgIoVI+k/7Eqra8ZmjHvopHQg8aI0JDLiRws95Rn?= =?us-ascii?Q?Bb9sMCZNAskCV7mlNz29EjdnTRpV03TmmDGY+jeA3/9tXEGzqepTdylzDHvH?= =?us-ascii?Q?1uevXO3gYCqEobr7Kjv2PnBC+PPnqIEJBQCEODiZcslFqH2U8+B0NcaLsVfR?= =?us-ascii?Q?5hbEGiP4luM3IJfQ1iM=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3829424f-93f2-4649-4291-08dc6d7dfda2 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 May 2024 03:38:27.3195 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: RaqsK7485DFpfNkDQcmcs6y6E+m4wV4kz8hRaDuVBt65PHW54UCyoiV64FKst9OAqT279ckh40tVIxUNwNIZQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB7815 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Sun, 05 May 2024 20:38:32 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: x9xQeqGDMn8GN80LUmKV1hnIx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB82441E9DC6BC989A188801408C1C2MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=yoZVKNzs; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) --_000_MN6PR11MB82441E9DC6BC989A188801408C1C2MN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni Thanks, Ray ________________________________ From: Wu, Jiaxin Sent: Friday, April 26, 2024 20:17 To: devel@edk2.groups.io Cc: Ni, Ray ; Zeng, Star ; Gerd Hoff= mann ; Kumar, Rahul R Subject: [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases relocat= ion logic This patch is to remove legacy SmBase relocation in PiSmmCpuDxeSmm Driver. The responsibility for SmBase relocation has been transferred to the SmmRelocationInit interface, which now handles the following tasks: 1. Relocates the SmBase for each processor. 2. Generates the gSmmBaseHobGuid HOB. As a result of this change, the PiSmmCpuDxeSmm driver's role in SMM environment setup is simplified to: 1. Utilize the gSmmBaseHobGuid to determine the SmBase. 2. Perform the ExecuteFirstSmiInit() to do early SMM initialization. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 21 +- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 42 ---- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 96 -------- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 10 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 334 +++--------------------= ---- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 103 +-------- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 - UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 69 ------ UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c | 69 ------ UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm | 146 ------------ 11 files changed, 40 insertions(+), 856 deletions(-) delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/= CpuS3.c index b14c289a27..d67fb49890 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -639,27 +639,14 @@ InitializeCpuProcedure ( // InitializeCpuBeforeRebase (IsBsp); } if (IsBsp) { - DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated is %d\n", mSmmReloca= ted)); - // - // Check whether Smm Relocation is done or not. - // If not, will do the SmmBases Relocation here!!! + // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execut= e first SMI init. // - if (!mSmmRelocated) { - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); - } else { - // - // Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to exec= ute first SMI init. - // - ExecuteFirstSmiInit (); - } + ExecuteFirstSmiInit (); } // // Skip initialization if mAcpiCpuData is not valid // @@ -978,13 +965,13 @@ InitSmmS3ResumeState ( SmmS3ResumeState->SmmS3StackBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Allo= catePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); if (SmmS3ResumeState->SmmS3StackBase =3D=3D 0) { SmmS3ResumeState->SmmS3StackSize =3D 0; } - SmmS3ResumeState->SmmS3Cr0 =3D mSmmCr0; + SmmS3ResumeState->SmmS3Cr0 =3D (UINT32)AsmReadCr0 (); SmmS3ResumeState->SmmS3Cr3 =3D Cr3; - SmmS3ResumeState->SmmS3Cr4 =3D mSmmCr4; + SmmS3ResumeState->SmmS3Cr4 =3D (UINT32)AsmReadCr4 (); if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { SmmS3ResumeState->Signature =3D SMM_S3_RESUME_SMM_64; } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmC= puDxeSmm/Ia32/Semaphore.c deleted file mode 100644 index a9fcc89dda..0000000000 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - - mRebasedFlag =3D RebasedFlag; - - CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DE= FAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress =3D (UINTN)HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSe= maphoreComplete, - (UINT64)(UINTN)&SmmRelocationSe= maphoreComplete - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmm= CpuDxeSmm/Ia32/SmmInit.nasm deleted file mode 100644 index b5e77a1a5b..0000000000 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm +++ /dev/null @@ -1,96 +0,0 @@ -;-------------------------------------------------------------------------= ----- ; -; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
-; SPDX-License-Identifier: BSD-2-Clause-Patent -; -; Module Name: -; -; SmmInit.nasm -; -; Abstract: -; -; Functions for relocating SMBASE's for all processors -; -;-------------------------------------------------------------------------= ------ - -%include "StuffRsbNasm.inc" - -extern ASM_PFX(SmmInitHandler) -extern ASM_PFX(mRebasedFlag) -extern ASM_PFX(mSmmRelocationOriginalAddress) - -global ASM_PFX(gPatchSmmCr3) -global ASM_PFX(gPatchSmmCr4) -global ASM_PFX(gPatchSmmCr0) -global ASM_PFX(gPatchSmmInitStack) -global ASM_PFX(gcSmiInitGdtr) -global ASM_PFX(gcSmmInitSize) -global ASM_PFX(gcSmmInitTemplate) - -%define PROTECT_MODE_CS 0x8 -%define PROTECT_MODE_DS 0x20 - - SECTION .text - -ASM_PFX(gcSmiInitGdtr): - DW 0 - DQ 0 - -global ASM_PFX(SmmStartup) - -BITS 16 -ASM_PFX(SmmStartup): - mov eax, 0x80000001 ; read capability - cpuid - mov ebx, edx ; rdmsr will change edx. keep it i= n ebx. - and ebx, BIT20 ; extract NX capability bit - shr ebx, 9 ; shift bit to IA32_EFER.NXE[BIT11= ] position - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr3): - mov cr3, eax -o32 lgdt [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))] - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr4): - mov cr4, eax - mov ecx, 0xc0000080 ; IA32_EFER MSR - rdmsr - or eax, ebx ; set NXE bit if NX is available - wrmsr - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr0): - mov di, PROTECT_MODE_DS - mov cr0, eax - jmp PROTECT_MODE_CS : dword @32bit - -BITS 32 -@32bit: - mov ds, edi - mov es, edi - mov fs, edi - mov gs, edi - mov ss, edi - mov esp, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmInitStack): - call ASM_PFX(SmmInitHandler) - StuffRsb32 - rsm - -BITS 16 -ASM_PFX(gcSmmInitTemplate): - mov ebp, ASM_PFX(SmmStartup) - sub ebp, 0x30000 - jmp ebp - -ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate) - -BITS 32 -global ASM_PFX(SmmRelocationSemaphoreComplete) -ASM_PFX(SmmRelocationSemaphoreComplete): - push eax - mov eax, [ASM_PFX(mRebasedFlag)] - mov byte [eax], 1 - pop eax - jmp [ASM_PFX(mSmmRelocationOriginalAddress)] - -global ASM_PFX(PiSmmCpuSmmInitFixupAddress) -ASM_PFX(PiSmmCpuSmmInitFixupAddress): - ret diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 081f0c1501..10baf3ceb9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1511,26 +1511,24 @@ SmiRendezvous ( UINTN Index; UINTN Cr2; ASSERT (CpuIndex < mMaxNumberOfCpus); - if (mSmmRelocated) { - ASSERT (mSmmInitialized !=3D NULL); - } + ASSERT (mSmmInitialized !=3D NULL); // // Save Cr2 because Page Fault exception in SMM may override its value, // when using on-demand paging for above 4G memory. // Cr2 =3D 0; SaveCr2 (&Cr2); - if (mSmmRelocated && !mSmmInitialized[CpuIndex]) { + if (!mSmmInitialized[CpuIndex]) { // - // Perform SmmInitHandler for CpuIndex + // Perform InitializeSmm for CpuIndex // - SmmInitHandler (); + InitializeSmm (); // // Restore Cr2 // RestoreCr2 (Cr2); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 499f979d34..fb18168b53 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -54,15 +54,10 @@ CPU_HOT_PLUG_DATA mCpuHotPlugData =3D { // // Global pointer used to access mSmmCpuPrivateData from outside and insid= e SMM // SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate =3D &mSmmCpuPrivateData; -// -// SMM Relocation variables -// -volatile BOOLEAN *mRebased; - /// /// Handle for the SMM CPU Protocol /// EFI_HANDLE mSmmCpuHandle =3D NULL; @@ -83,11 +78,10 @@ EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL mSmmMemoryAttribut= e =3D { EdkiiSmmClearMemoryAttributes }; EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable[EXCEPTION_VECTOR_NUMBER]; -BOOLEAN mSmmRelocated =3D FALSE; volatile BOOLEAN *mSmmInitialized =3D NULL; UINT32 mBspApicId =3D 0; // // SMM stack information @@ -133,16 +127,10 @@ SPIN_LOCK *mConfigSmmCodeAccessCheckLock =3D NULL; EFI_SMRAM_DESCRIPTOR *mSmmCpuSmramRanges; UINTN mSmmCpuSmramRangeCount; UINT8 mPhysicalAddressBits; -// -// Control register contents saved for SMM S3 resume state initialization. -// -UINT32 mSmmCr0; -UINT32 mSmmCr4; - /** Initialize IDT to setup exception handlers for SMM. **/ VOID @@ -335,37 +323,32 @@ SmmWriteSaveState ( return Status; } /** - C function for SMI handler. To change all processor's SMMBase Register. + Initialize SMM environment. **/ VOID -EFIAPI -SmmInitHandler ( +InitializeSmm ( VOID ) { UINT32 ApicId; UINTN Index; BOOLEAN IsBsp; - // - // Update SMM IDT entries' code segment and load IDT - // - AsmWriteIdtr (&gcSmiIdtr); ApicId =3D GetApicId (); IsBsp =3D (BOOLEAN)(mBspApicId =3D=3D ApicId); ASSERT (mNumberOfCpus <=3D mMaxNumberOfCpus); for (Index =3D 0; Index < mNumberOfCpus; Index++) { if (ApicId =3D=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Process= orId) { PERF_CODE ( - MpPerfBegin (Index, SMM_MP_PERF_PROCEDURE_ID (SmmInitHandler)); + MpPerfBegin (Index, SMM_MP_PERF_PROCEDURE_ID (InitializeSmm)); ); // // Initialize SMM specific features on the currently executing CPU // SmmCpuFeaturesInitializeProcessor ( @@ -386,19 +369,12 @@ SmmInitHandler ( // Initialize private data during S3 resume // InitializeMpSyncData (); } - if (!mSmmRelocated) { - // - // Hook return after RSM to set SMM re-based flag - // - SemaphoreHook (Index, &mRebased[Index]); - } - PERF_CODE ( - MpPerfEnd (Index, SMM_MP_PERF_PROCEDURE_ID (SmmInitHandler)); + MpPerfEnd (Index, SMM_MP_PERF_PROCEDURE_ID (InitializeSmm)); ); return; } } @@ -454,111 +430,10 @@ ExecuteFirstSmiInit ( } PERF_FUNCTION_END (); } -/** - Relocate SmmBases for each processor. - - Execute on first boot and all S3 resumes - -**/ -VOID -EFIAPI -SmmRelocateBases ( - VOID - ) -{ - UINT8 BakBuf[BACK_BUF_SIZE]; - SMRAM_SAVE_STATE_MAP BakBuf2; - SMRAM_SAVE_STATE_MAP *CpuStatePtr; - UINT8 *U8Ptr; - UINTN Index; - UINTN BspIndex; - - PERF_FUNCTION_BEGIN (); - - // - // Make sure the reserved size is large enough for procedure SmmInitTemp= late. - // - ASSERT (sizeof (BakBuf) >=3D gcSmmInitSize); - - // - // Patch ASM code template with current CR0, CR3, and CR4 values - // - mSmmCr0 =3D (UINT32)AsmReadCr0 (); - PatchInstructionX86 (gPatchSmmCr0, mSmmCr0, 4); - PatchInstructionX86 (gPatchSmmCr3, AsmReadCr3 (), 4); - mSmmCr4 =3D (UINT32)AsmReadCr4 (); - PatchInstructionX86 (gPatchSmmCr4, mSmmCr4 & (~CR4_CET_ENABLE), 4); - - // - // Patch GDTR for SMM base relocation - // - gcSmiInitGdtr.Base =3D gcSmiGdtr.Base; - gcSmiInitGdtr.Limit =3D gcSmiGdtr.Limit; - - U8Ptr =3D (UINT8 *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET= ); - CpuStatePtr =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMR= AM_SAVE_STATE_MAP_OFFSET); - - // - // Backup original contents at address 0x38000 - // - CopyMem (BakBuf, U8Ptr, sizeof (BakBuf)); - CopyMem (&BakBuf2, CpuStatePtr, sizeof (BakBuf2)); - - // - // Load image for relocation - // - CopyMem (U8Ptr, gcSmmInitTemplate, gcSmmInitSize); - - // - // Retrieve the local APIC ID of current processor - // - mBspApicId =3D GetApicId (); - - // - // Relocate SM bases for all APs - // This is APs' 1st SMI - rebase will be done here, and APs' default SMI= handler will be overridden by gcSmmInitTemplate - // - BspIndex =3D (UINTN)-1; - for (Index =3D 0; Index < mNumberOfCpus; Index++) { - mRebased[Index] =3D FALSE; - if (mBspApicId !=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Proce= ssorId) { - SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId= ); - // - // Wait for this AP to finish its 1st SMI - // - while (!mRebased[Index]) { - } - } else { - // - // BSP will be Relocated later - // - BspIndex =3D Index; - } - } - - // - // Relocate BSP's SMM base - // - ASSERT (BspIndex !=3D (UINTN)-1); - SendSmiIpi (mBspApicId); - // - // Wait for the BSP to finish its 1st SMI - // - while (!mRebased[BspIndex]) { - } - - // - // Restore contents at address 0x38000 - // - CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2)); - CopyMem (U8Ptr, BakBuf, sizeof (BakBuf)); - PERF_FUNCTION_END (); -} - /** SMM Ready To Lock event notification handler. The CPU S3 data is copied to SMRAM for security and mSmmReadyToLock is s= et to perform additional lock actions that must be performed from SMM on the n= ext SMI. @@ -881,12 +756,10 @@ PiCpuSmmEntry ( IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; UINTN Index; - VOID *Buffer; - UINTN BufferPages; UINTN TileCodeSize; UINTN TileDataSize; UINTN TileSize; UINT8 *Stacks; VOID *Registration; @@ -901,11 +774,10 @@ PiCpuSmmEntry ( PERF_FUNCTION_BEGIN (); // // Initialize address fixup // - PiSmmCpuSmmInitFixupAddress (); PiSmmCpuSmiEntryFixupAddress (); // // Initialize Debug Agent to support source level debug in SMM code // @@ -1113,66 +985,34 @@ PiCpuSmmEntry ( // context must be reduced. // ASSERT (TileSize <=3D (SMRAM_SAVE_STATE_MAP_OFFSET + sizeof (SMRAM_SAVE_= STATE_MAP) - SMM_HANDLER_OFFSET)); // - // Retrive the allocated SmmBase from gSmmBaseHobGuid. If found, + // Check whether the Required TileSize is enough. + // + if (TileSize > SIZE_8KB) { + DEBUG ((DEBUG_ERROR, "The Range of Smbase in SMRAM is not enough -- Re= quired TileSize =3D 0x%08x, Actual TileSize =3D 0x%08x\n", TileSize, SIZE_8= KB)); + FreePool (gSmmCpuPrivate->ProcessorInfo); + CpuDeadLoop (); + return RETURN_BUFFER_TOO_SMALL; + } + + // + // Retrieve the allocated SmmBase from gSmmBaseHobGuid. If found, // means the SmBase relocation has been done. // mCpuHotPlugData.SmBase =3D NULL; Status =3D GetSmBase (mMaxNumberOfCpus, &mCpuHotPlugData= .SmBase); - if (Status =3D=3D EFI_OUT_OF_RESOURCES) { - ASSERT (Status !=3D EFI_OUT_OF_RESOURCES); + ASSERT (!EFI_ERROR (Status)); + if (EFI_ERROR (Status)) { CpuDeadLoop (); } - if (!EFI_ERROR (Status)) { - ASSERT (mCpuHotPlugData.SmBase !=3D NULL); - // - // Check whether the Required TileSize is enough. - // - if (TileSize > SIZE_8KB) { - DEBUG ((DEBUG_ERROR, "The Range of Smbase in SMRAM is not enough -- = Required TileSize =3D 0x%08x, Actual TileSize =3D 0x%08x\n", TileSize, SIZE= _8KB)); - FreePool (mCpuHotPlugData.SmBase); - FreePool (gSmmCpuPrivate->ProcessorInfo); - CpuDeadLoop (); - return RETURN_BUFFER_TOO_SMALL; - } - - mSmmRelocated =3D TRUE; - } else { - ASSERT (Status =3D=3D EFI_NOT_FOUND); - ASSERT (mCpuHotPlugData.SmBase =3D=3D NULL); - // - // When the HOB doesn't exist, allocate new SMBASE itself. - // - DEBUG ((DEBUG_INFO, "PiCpuSmmEntry: gSmmBaseHobGuid not found!\n")); - - mCpuHotPlugData.SmBase =3D (UINTN *)AllocatePool (sizeof (UINTN) * mMa= xNumberOfCpus); - if (mCpuHotPlugData.SmBase =3D=3D NULL) { - ASSERT (mCpuHotPlugData.SmBase !=3D NULL); - CpuDeadLoop (); - } - - // - // very old processors (i486 + pentium) need 32k not 4k alignment, exc= lude them. - // - ASSERT (FamilyId >=3D 6); - // - // Allocate buffer for all of the tiles. - // - BufferPages =3D EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberO= fCpus - 1)); - Buffer =3D AllocateAlignedCodePages (BufferPages, SIZE_4KB); - if (Buffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "Failed to allocate %Lu pages.\n", (UINT64)Buff= erPages)); - CpuDeadLoop (); - return EFI_OUT_OF_RESOURCES; - } - - ASSERT (Buffer !=3D NULL); - DEBUG ((DEBUG_INFO, "New Allcoated SMRAM SaveState Buffer (0x%08x, 0x%= 08x)\n", Buffer, EFI_PAGES_TO_SIZE (BufferPages))); - } + // + // ASSERT SmBase has been relocated. + // + ASSERT (mCpuHotPlugData.SmBase !=3D NULL); // // Allocate buffer for pointers to array in SMM_CPU_PRIVATE_DATA. // gSmmCpuPrivate->Operation =3D (SMM_CPU_OPERATION *)AllocatePool (sizeof = (SMM_CPU_OPERATION) * mMaxNumberOfCpus); @@ -1198,14 +1038,10 @@ PiCpuSmmEntry ( // Retrieve APIC ID of each enabled processor from the MP Services proto= col. // Also compute the SMBASE address, CPU Save State address, and CPU Save= state // size for each CPU in the platform // for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { - if (!mSmmRelocated) { - mCpuHotPlugData.SmBase[Index] =3D (UINTN)Buffer + Index * TileSize -= SMM_HANDLER_OFFSET; - } - gSmmCpuPrivate->CpuSaveStateSize[Index] =3D sizeof (SMRAM_SAVE_STATE_M= AP); gSmmCpuPrivate->CpuSaveState[Index] =3D (VOID *)(mCpuHotPlugData.S= mBase[Index] + SMRAM_SAVE_STATE_MAP_OFFSET); gSmmCpuPrivate->Operation[Index] =3D SmmCpuNone; if (Index < mNumberOfCpus) { @@ -1297,45 +1133,15 @@ PiCpuSmmEntry ( DEBUG ((DEBUG_INFO, "PcdCpuSmmStackGuard - 0x%x\n", FeaturePcdGet (= PcdCpuSmmStackGuard))); if ((PcdGet32 (PcdControlFlowEnforcementPropertyMask) !=3D 0) && mCetSup= ported) { DEBUG ((DEBUG_INFO, "mSmmShadowStackSize - 0x%x\n", mSmmShadowSta= ckSize)); } - // - // Set SMI stack for SMM base relocation - // - PatchInstructionX86 ( - gPatchSmmInitStack, - (UINTN)(Stacks + mSmmStackSize - sizeof (UINTN)), - sizeof (UINTN) - ); - // // Initialize IDT // InitializeSmmIdt (); - // - // Check whether Smm Relocation is done or not. - // If not, will do the SmmBases Relocation here!!! - // - if (!mSmmRelocated) { - // - // Relocate SMM Base addresses to the ones allocated from SMRAM - // - mRebased =3D (BOOLEAN *)AllocateZeroPool (sizeof (BOOLEAN) * mMaxNumbe= rOfCpus); - ASSERT (mRebased !=3D NULL); - SmmRelocateBases (); - - // - // Call hook for BSP to perform extra actions in normal mode after all - // SMM base addresses have been relocated on all CPUs - // - SmmCpuFeaturesSmmRelocationComplete (); - } - - DEBUG ((DEBUG_INFO, "mXdSupported - 0x%x\n", mXdSupported)); - // // SMM Time initialization // InitializeSmmTimer (); @@ -1368,19 +1174,19 @@ PiCpuSmmEntry ( // // For relocated SMBASE, some MSRs & CSRs are still required to be confi= gured in SMM Mode for SMM Initialization. // Those MSRs & CSRs must be configured before normal SMI sources happen= . // So, here is to issue SMI IPI (All Excluding Self SMM IPI + BSP SMM I= PI) to execute first SMI init. // - if (mSmmRelocated) { - ExecuteFirstSmiInit (); + ExecuteFirstSmiInit (); - // - // Call hook for BSP to perform extra actions in normal mode after all - // SMM base addresses have been relocated on all CPUs - // - SmmCpuFeaturesSmmRelocationComplete (); - } + // + // Call hook for BSP to perform extra actions in normal mode after all + // SMM base addresses have been relocated on all CPUs + // + SmmCpuFeaturesSmmRelocationComplete (); + + DEBUG ((DEBUG_INFO, "mXdSupported - 0x%x\n", mXdSupported)); // // Fill in SMM Reserved Regions // gSmmCpuPrivate->SmmReservedSmramRegion[0].SmramReservedStart =3D 0; @@ -1767,92 +1573,10 @@ AllocateCodePages ( } return (VOID *)(UINTN)Memory; } -/** - Allocate aligned pages for code. - - @param[in] Pages Number of pages to be allocated. - @param[in] Alignment The requested alignment of the allocat= ion. - Must be a power of two. - If Alignment is zero, then byte alignm= ent is used. - - @return Allocated memory. -**/ -VOID * -AllocateAlignedCodePages ( - IN UINTN Pages, - IN UINTN Alignment - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Memory; - UINTN AlignedMemory; - UINTN AlignmentMask; - UINTN UnalignedPages; - UINTN RealPages; - - // - // Alignment must be a power of two or zero. - // - ASSERT ((Alignment & (Alignment - 1)) =3D=3D 0); - - if (Pages =3D=3D 0) { - return NULL; - } - - if (Alignment > EFI_PAGE_SIZE) { - // - // Calculate the total number of pages since alignment is larger than = page size. - // - AlignmentMask =3D Alignment - 1; - RealPages =3D Pages + EFI_SIZE_TO_PAGES (Alignment); - // - // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not ov= erflow. - // - ASSERT (RealPages > Pages); - - Status =3D gSmst->SmmAllocatePages (AllocateAnyPages, EfiRuntimeServic= esCode, RealPages, &Memory); - if (EFI_ERROR (Status)) { - return NULL; - } - - AlignedMemory =3D ((UINTN)Memory + AlignmentMask) & ~AlignmentMask; - UnalignedPages =3D EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory); - if (UnalignedPages > 0) { - // - // Free first unaligned page(s). - // - Status =3D gSmst->SmmFreePages (Memory, UnalignedPages); - ASSERT_EFI_ERROR (Status); - } - - Memory =3D AlignedMemory + EFI_PAGES_TO_SIZE (Pages); - UnalignedPages =3D RealPages - Pages - UnalignedPages; - if (UnalignedPages > 0) { - // - // Free last unaligned page(s). - // - Status =3D gSmst->SmmFreePages (Memory, UnalignedPages); - ASSERT_EFI_ERROR (Status); - } - } else { - // - // Do not over-allocate pages in this case. - // - Status =3D gSmst->SmmAllocatePages (AllocateAnyPages, EfiRuntimeServic= esCode, Pages, &Memory); - if (EFI_ERROR (Status)) { - return NULL; - } - - AlignedMemory =3D (UINTN)Memory; - } - - return (VOID *)AlignedMemory; -} - /** Perform the remaining tasks. **/ VOID diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 7f244ea803..f42910ddf1 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -186,18 +186,10 @@ typedef struct { // Code select value // #define PROTECT_MODE_CODE_SEGMENT 0x08 #define LONG_MODE_CODE_SEGMENT 0x38 -// -// The size 0x20 must be bigger than -// the size of template code of SmmInit. Currently, -// the size of SmmInit requires the 0x16 Bytes buffer -// at least. -// -#define BACK_BUF_SIZE 0x20 - #define EXCEPTION_VECTOR_NUMBER 0x20 #define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL // @@ -355,16 +347,15 @@ SmmWriteSaveState ( IN UINTN CpuIndex, IN CONST VOID *Buffer ); /** - C function for SMI handler. To change all processor's SMMBase Register. + Initialize SMM environment. **/ VOID -EFIAPI -SmmInitHandler ( +InitializeSmm ( VOID ); /** Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute firs= t SMI init. @@ -373,22 +364,13 @@ SmmInitHandler ( VOID ExecuteFirstSmiInit ( VOID ); -extern BOOLEAN mSmmRelocated; extern volatile BOOLEAN *mSmmInitialized; extern UINT32 mBspApicId; -extern CONST UINT8 gcSmmInitTemplate[]; -extern CONST UINT16 gcSmmInitSize; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0; -extern UINT32 mSmmCr0; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3; -extern UINT32 mSmmCr4; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4; -X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack; X86_ASSEMBLY_PATCH_LABEL mPatchCetSupported; extern BOOLEAN mCetSupported; /** Semaphore operation for all processor relocate SMMBase. @@ -473,11 +455,10 @@ extern UINT64 gPhyMask; extern SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData; extern UINTN mSmmStackArrayBase; extern UINTN mSmmStackArrayEnd; extern UINTN mSmmStackSize; extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService; -extern IA32_DESCRIPTOR gcSmiInitGdtr; extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores; extern UINTN mSemaphoreSize; extern SPIN_LOCK *mPFLock; extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock; extern EFI_SMRAM_DESCRIPTOR *mSmmCpuSmramRanges; @@ -791,22 +772,10 @@ VOID FindSmramInfo ( OUT UINT32 *SmrrBase, OUT UINT32 *SmrrSize ); -/** - Relocate SmmBases for each processor. - - Execute on first boot and all S3 resumes - -**/ -VOID -EFIAPI -SmmRelocateBases ( - VOID - ); - /** Page Fault handler for SMM use. @param InterruptType Defines the type of interrupt or exception that occurred on the processor.This parameter is pro= cessor architecture specific. @@ -847,62 +816,19 @@ PerformPreTasks ( VOID InitMsrSpinLockByIndex ( IN UINT32 MsrIndex ); -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ); - /** Configure SMM Code Access Check feature for all processors. SMM Feature Control MSR will be locked after configuration. **/ VOID ConfigSmmCodeAccessCheck ( VOID ); -/** - Hook the code executed immediately after an RSM instruction on the curre= ntly - executing CPU. The mode of code executed immediately after RSM must be - detected, and the appropriate hook must be selected. Always clear the a= uto - HALT restart flag if it is set. - - @param[in] CpuIndex The processor index for the currentl= y - executing CPU. - @param[in] CpuState Pointer to SMRAM Save State Map for = the - currently executing CPU. - @param[in] NewInstructionPointer32 Instruction pointer to use if resumi= ng to - 32-bit mode from 64-bit SMM. - @param[in] NewInstructionPointer Instruction pointer to use if resumi= ng to - same mode as SMM. - - @retval The value of the original instruction pointer before it was hook= ed. - -**/ -UINT64 -EFIAPI -HookReturnFromSmm ( - IN UINTN CpuIndex, - SMRAM_SAVE_STATE_MAP *CpuState, - UINT64 NewInstructionPointer32, - UINT64 NewInstructionPointer - ); - /** Get the size of the SMI Handler in bytes. @retval The size, in bytes, of the SMI Handler. @@ -1103,26 +1029,10 @@ AllocatePageTableMemory ( VOID * AllocateCodePages ( IN UINTN Pages ); -/** - Allocate aligned pages for code. - - @param[in] Pages Number of pages to be allocated. - @param[in] Alignment The requested alignment of the allocat= ion. - Must be a power of two. - If Alignment is zero, then byte alignm= ent is used. - - @return Allocated memory. -**/ -VOID * -AllocateAlignedCodePages ( - IN UINTN Pages, - IN UINTN Alignment - ); - // // S3 related global variable and function prototype. // extern BOOLEAN mSmmS3Flag; @@ -1300,19 +1210,10 @@ EdkiiSmmGetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 *Attributes ); -/** - This function fixes up the address of the global variable or function - referred in SmmInit assembly files to be the absolute address. -**/ -VOID -EFIAPI -PiSmmCpuSmmInitFixupAddress ( - ); - /** This function fixes up the address of the global variable or function referred in SmiEntry assembly files to be the absolute address. **/ VOID diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index a018954ed7..1a230ad2d0 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -45,28 +45,24 @@ SmmMp.c SmmMpPerf.h SmmMpPerf.c [Sources.Ia32] - Ia32/Semaphore.c Ia32/PageTbl.c Ia32/SmmFuncsArch.c Ia32/SmmProfileArch.c Ia32/SmmProfileArch.h - Ia32/SmmInit.nasm Ia32/SmiEntry.nasm Ia32/SmiException.nasm Ia32/MpFuncs.nasm Ia32/Cet.nasm [Sources.X64] - X64/Semaphore.c X64/PageTbl.c X64/SmmFuncsArch.c X64/SmmProfileArch.c X64/SmmProfileArch.h - X64/SmmInit.nasm X64/SmiEntry.nasm X64/SmiException.nasm X64/MpFuncs.nasm X64/Cet.nasm diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h b/UefiCpuPkg/PiSmmCpuDxe= Smm/SmmMpPerf.h index 591b212c06..2e2ea3c76e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h @@ -12,11 +12,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // The list of all MP procedures that need to be perf-logged. // #define SMM_MP_PERF_PROCEDURE_LIST(_) \ - _(SmmInitHandler), \ + _(InitializeSmm), \ _(SmmRendezvousEntry), \ _(PlatformValidSmi), \ _(SmmRendezvousExit), \ _(SmmMpProcedureMax) // Add new entries above this line diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmC= puDxeSmm/SmramSaveState.c index 1e316ee0ac..b9a62aeeb0 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c @@ -67,79 +67,10 @@ IA32_DESCRIPTOR gSmiHandlerIdtr; /// /// The mode of the CPU at the time an SMI occurs /// UINT8 mSmmSaveStateRegisterLma; -/** - Hook the code executed immediately after an RSM instruction on the curre= ntly - executing CPU. The mode of code executed immediately after RSM must be - detected, and the appropriate hook must be selected. Always clear the a= uto - HALT restart flag if it is set. - - @param[in] CpuIndex The processor index for the currentl= y - executing CPU. - @param[in] CpuState Pointer to SMRAM Save State Map for = the - currently executing CPU. - @param[in] NewInstructionPointer32 Instruction pointer to use if resumi= ng to - 32-bit mode from 64-bit SMM. - @param[in] NewInstructionPointer Instruction pointer to use if resumi= ng to - same mode as SMM. - - @retval The value of the original instruction pointer before it was hook= ed. - -**/ -UINT64 -EFIAPI -HookReturnFromSmm ( - IN UINTN CpuIndex, - SMRAM_SAVE_STATE_MAP *CpuState, - UINT64 NewInstructionPointer32, - UINT64 NewInstructionPointer - ) -{ - UINT64 OriginalInstructionPointer; - - OriginalInstructionPointer =3D SmmCpuFeaturesHookReturnFromSmm ( - CpuIndex, - CpuState, - NewInstructionPointer32, - NewInstructionPointer - ); - if (OriginalInstructionPointer !=3D 0) { - return OriginalInstructionPointer; - } - - if (mSmmSaveStateRegisterLma =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA_32BI= T) { - OriginalInstructionPointer =3D (UINT64)CpuState->x86._EIP; - CpuState->x86._EIP =3D (UINT32)NewInstructionPointer; - // - // Clear the auto HALT restart flag so the RSM instruction returns - // program control to the instruction following the HLT instruction. - // - if ((CpuState->x86.AutoHALTRestart & BIT0) !=3D 0) { - CpuState->x86.AutoHALTRestart &=3D ~BIT0; - } - } else { - OriginalInstructionPointer =3D CpuState->x64._RIP; - if ((CpuState->x64.IA32_EFER & LMA) =3D=3D 0) { - CpuState->x64._RIP =3D (UINT32)NewInstructionPointer32; - } else { - CpuState->x64._RIP =3D (UINT32)NewInstructionPointer; - } - - // - // Clear the auto HALT restart flag so the RSM instruction returns - // program control to the instruction following the HLT instruction. - // - if ((CpuState->x64.AutoHALTRestart & BIT0) !=3D 0) { - CpuState->x64.AutoHALTRestart &=3D ~BIT0; - } - } - - return OriginalInstructionPointer; -} - /** Get the size of the SMI Handler in bytes. @retval The size, in bytes, of the SMI Handler. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c b/UefiCpuPkg/PiSmmCp= uDxeSmm/X64/Semaphore.c deleted file mode 100644 index dafbc3390e..0000000000 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c +++ /dev/null @@ -1,69 +0,0 @@ -/** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. - -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "PiSmmCpuDxeSmm.h" - -X86_ASSEMBLY_PATCH_LABEL gPatchSmmRelocationOriginalAddressPtr32; -X86_ASSEMBLY_PATCH_LABEL gPatchRebasedFlagAddr32; - -UINTN mSmmRelocationOriginalAddress; -volatile BOOLEAN *mRebasedFlag; - -/** -AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode. -**/ -VOID -SmmRelocationSemaphoreComplete32 ( - VOID - ); - -/** - Hook return address of SMM Save State so that semaphore code - can be executed immediately after AP exits SMM to indicate to - the BSP that an AP has exited SMM after SMBASE relocation. - - @param[in] CpuIndex The processor index. - @param[in] RebasedFlag A pointer to a flag that is set to TRUE - immediately after AP exits SMM. - -**/ -VOID -SemaphoreHook ( - IN UINTN CpuIndex, - IN volatile BOOLEAN *RebasedFlag - ) -{ - SMRAM_SAVE_STATE_MAP *CpuState; - UINTN TempValue; - - mRebasedFlag =3D RebasedFlag; - PatchInstructionX86 ( - gPatchRebasedFlagAddr32, - (UINT32)(UINTN)mRebasedFlag, - 4 - ); - - CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DE= FAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); - mSmmRelocationOriginalAddress =3D HookReturnFromSmm ( - CpuIndex, - CpuState, - (UINT64)(UINTN)&SmmRelocationSemaphore= Complete32, - (UINT64)(UINTN)&SmmRelocationSemaphore= Complete - ); - - // - // Use temp value to fix ICC compiler warning - // - TempValue =3D (UINTN)&mSmmRelocationOriginalAddress; - PatchInstructionX86 ( - gPatchSmmRelocationOriginalAddressPtr32, - (UINT32)TempValue, - 4 - ); -} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm b/UefiCpuPkg/PiSmmC= puDxeSmm/X64/SmmInit.nasm deleted file mode 100644 index 9cf3a6dcf9..0000000000 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm +++ /dev/null @@ -1,146 +0,0 @@ -;-------------------------------------------------------------------------= ----- ; -; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
-; SPDX-License-Identifier: BSD-2-Clause-Patent -; -; Module Name: -; -; SmmInit.nasm -; -; Abstract: -; -; Functions for relocating SMBASE's for all processors -; -;-------------------------------------------------------------------------= ------ - -%include "StuffRsbNasm.inc" - -extern ASM_PFX(SmmInitHandler) -extern ASM_PFX(mRebasedFlag) -extern ASM_PFX(mSmmRelocationOriginalAddress) - -global ASM_PFX(gPatchSmmCr3) -global ASM_PFX(gPatchSmmCr4) -global ASM_PFX(gPatchSmmCr0) -global ASM_PFX(gPatchSmmInitStack) -global ASM_PFX(gcSmiInitGdtr) -global ASM_PFX(gcSmmInitSize) -global ASM_PFX(gcSmmInitTemplate) -global ASM_PFX(gPatchRebasedFlagAddr32) -global ASM_PFX(gPatchSmmRelocationOriginalAddressPtr32) - -%define LONG_MODE_CS 0x38 - - DEFAULT REL - SECTION .text - -ASM_PFX(gcSmiInitGdtr): - DW 0 - DQ 0 - -global ASM_PFX(SmmStartup) - -BITS 16 -ASM_PFX(SmmStartup): - mov eax, 0x80000001 ; read capability - cpuid - mov ebx, edx ; rdmsr will change edx. keep it i= n ebx. - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr3): - mov cr3, eax -o32 lgdt [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))] - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr4): - or ah, 2 ; enable XMM registers access - mov cr4, eax - mov ecx, 0xc0000080 ; IA32_EFER MSR - rdmsr - or ah, BIT0 ; set LME bit - test ebx, BIT20 ; check NXE capability - jz .1 - or ah, BIT3 ; set NXE bit -.1: - wrmsr - mov eax, strict dword 0 ; source operand will be patched -ASM_PFX(gPatchSmmCr0): - mov cr0, eax ; enable protected mode & paging - jmp LONG_MODE_CS : dword 0 ; offset will be patched to @LongM= ode -@PatchLongModeOffset: - -BITS 64 -@LongMode: ; long-mode starts here - mov rsp, strict qword 0 ; source operand will be patched -ASM_PFX(gPatchSmmInitStack): - and sp, 0xfff0 ; make sure RSP is 16-byte aligned - ; - ; According to X64 calling convention, XMM0~5 are volatile, we need to= save - ; them before calling C-function. - ; - sub rsp, 0x60 - movdqa [rsp], xmm0 - movdqa [rsp + 0x10], xmm1 - movdqa [rsp + 0x20], xmm2 - movdqa [rsp + 0x30], xmm3 - movdqa [rsp + 0x40], xmm4 - movdqa [rsp + 0x50], xmm5 - - add rsp, -0x20 - call ASM_PFX(SmmInitHandler) - add rsp, 0x20 - - ; - ; Restore XMM0~5 after calling C-function. - ; - movdqa xmm0, [rsp] - movdqa xmm1, [rsp + 0x10] - movdqa xmm2, [rsp + 0x20] - movdqa xmm3, [rsp + 0x30] - movdqa xmm4, [rsp + 0x40] - movdqa xmm5, [rsp + 0x50] - - StuffRsb64 - rsm - -BITS 16 -ASM_PFX(gcSmmInitTemplate): - mov ebp, [cs:@L1 - ASM_PFX(gcSmmInitTemplate) + 0x8000] - sub ebp, 0x30000 - jmp ebp -@L1: - DQ 0; ASM_PFX(SmmStartup) - -ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate) - -BITS 64 -global ASM_PFX(SmmRelocationSemaphoreComplete) -ASM_PFX(SmmRelocationSemaphoreComplete): - push rax - mov rax, [ASM_PFX(mRebasedFlag)] - mov byte [rax], 1 - pop rax - jmp [ASM_PFX(mSmmRelocationOriginalAddress)] - -; -; Semaphore code running in 32-bit mode -; -BITS 32 -global ASM_PFX(SmmRelocationSemaphoreComplete32) -ASM_PFX(SmmRelocationSemaphoreComplete32): - push eax - mov eax, strict dword 0 ; source operand will be pa= tched -ASM_PFX(gPatchRebasedFlagAddr32): - mov byte [eax], 1 - pop eax - jmp dword [dword 0] ; destination will be patch= ed -ASM_PFX(gPatchSmmRelocationOriginalAddressPtr32): - -BITS 64 -global ASM_PFX(PiSmmCpuSmmInitFixupAddress) -ASM_PFX(PiSmmCpuSmmInitFixupAddress): - lea rax, [@LongMode] - lea rcx, [@PatchLongModeOffset - 6] - mov dword [rcx], eax - - lea rax, [ASM_PFX(SmmStartup)] - lea rcx, [@L1] - mov qword [rcx], rax - ret -- 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118588): https://edk2.groups.io/g/devel/message/118588 Mute This Topic: https://groups.io/mt/105748928/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB82441E9DC6BC989A188801408C1C2MN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Ray Ni <ray.ni@intel.com>

Thanks,
Ray

From: Wu, Jiaxin <jiaxin= .wu@intel.com>
Sent: Friday, April 26, 2024 20:17
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel= .com>; Gerd Hoffmann <kraxel@redhat.com>; Kumar, Rahul R <rahul= .r.kumar@intel.com>
Subject: [PATCH v4 14/14] UefiCpuPkg/PiSmmCpuDxeSmm: Remove SmBases = relocation logic
 
This patch is to remove legacy SmBase relocation i= n
PiSmmCpuDxeSmm Driver. The responsibility for SmBase
relocation has been transferred to the SmmRelocationInit
interface, which now handles the following tasks:
1. Relocates the SmBase for each processor.
2. Generates the gSmmBaseHobGuid HOB.

As a result of this change, the PiSmmCpuDxeSmm driver's
role in SMM environment setup is simplified to:
1. Utilize the gSmmBaseHobGuid to determine the SmBase.
2. Perform the ExecuteFirstSmiInit() to do early SMM
initialization.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c      =       |  21 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c   |  42 ---= -
 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm  |  96 --------=
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c     &n= bsp;  |  10 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c   | 334 +++-----= -------------------
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h   | 103 +-------= -
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf |   4 -
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h     &n= bsp;  |   2 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c   |  69 ---= ---
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c    |  6= 9 ------
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm   | 146 --------= ----
 11 files changed, 40 insertions(+), 856 deletions(-)
 delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c
 delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
 delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c
 delete mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/= CpuS3.c
index b14c289a27..d67fb49890 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
@@ -639,27 +639,14 @@ InitializeCpuProcedure (
     //
     InitializeCpuBeforeRebase (IsBsp);
   }
 
   if (IsBsp) {
-    DEBUG ((DEBUG_INFO, "SmmRestoreCpu: mSmmRelocated = is %d\n", mSmmRelocated));
-
     //
-    // Check whether Smm Relocation is done or not.
-    // If not, will do the SmmBases Relocation here!!!
+    // Issue SMI IPI (All Excluding  Self SMM IPI + BS= P SMM IPI) to execute first SMI init.
     //
-    if (!mSmmRelocated) {
-      //
-      // Restore SMBASE for BSP and all APs
-      //
-      SmmRelocateBases ();
-    } else {
-      //
-      // Issue SMI IPI (All Excluding  Self = SMM IPI + BSP SMM IPI) to execute first SMI init.
-      //
-      ExecuteFirstSmiInit ();
-    }
+    ExecuteFirstSmiInit ();
   }
 
   //
   // Skip initialization if mAcpiCpuData is not valid
   //
@@ -978,13 +965,13 @@ InitSmmS3ResumeState (
     SmmS3ResumeState->SmmS3StackBase =3D (EFI_PHYSI= CAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeStat= e->SmmS3StackSize));
     if (SmmS3ResumeState->SmmS3StackBase =3D=3D 0) = {
       SmmS3ResumeState->SmmS3StackSize = =3D 0;
     }
 
-    SmmS3ResumeState->SmmS3Cr0 =3D mSmmCr0;
+    SmmS3ResumeState->SmmS3Cr0 =3D (UINT32)AsmReadCr0 ()= ;
     SmmS3ResumeState->SmmS3Cr3 =3D Cr3;
-    SmmS3ResumeState->SmmS3Cr4 =3D mSmmCr4;
+    SmmS3ResumeState->SmmS3Cr4 =3D (UINT32)AsmReadCr4 ()= ;
 
     if (sizeof (UINTN) =3D=3D sizeof (UINT64)) {
       SmmS3ResumeState->Signature =3D SMM= _S3_RESUME_SMM_64;
     }
 
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmC= puDxeSmm/Ia32/Semaphore.c
deleted file mode 100644
index a9fcc89dda..0000000000
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/** @file
-Semaphore mechanism to indicate to the BSP that an AP has exited SMM
-after SMBASE relocation.
-
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR&g= t;
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "PiSmmCpuDxeSmm.h"
-
-UINTN           &nb= sp; mSmmRelocationOriginalAddress;
-volatile BOOLEAN  *mRebasedFlag;
-
-/**
-  Hook return address of SMM Save State so that semaphore code
-  can be executed immediately after AP exits SMM to indicate to
-  the BSP that an AP has exited SMM after SMBASE relocation.
-
-  @param[in] CpuIndex     The processor index. -  @param[in] RebasedFlag  A pointer to a flag that is set to TRU= E
-            &n= bsp;            = ; immediately after AP exits SMM.
-
-**/
-VOID
-SemaphoreHook (
-  IN UINTN          = ;   CpuIndex,
-  IN volatile BOOLEAN  *RebasedFlag
-  )
-{
-  SMRAM_SAVE_STATE_MAP  *CpuState;
-
-  mRebasedFlag =3D RebasedFlag;
-
-  CpuState          = ;            =3D (SM= RAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFS= ET);
-  mSmmRelocationOriginalAddress =3D (UINTN)HookReturnFromSmm (
-            &n= bsp;            = ;            &n= bsp;     CpuIndex,
-            &n= bsp;            = ;            &n= bsp;     CpuState,
-            &n= bsp;            = ;            &n= bsp;     (UINT64)(UINTN)&SmmRelocationSemaphoreComp= lete,
-            &n= bsp;            = ;            &n= bsp;     (UINT64)(UINTN)&SmmRelocationSemaphoreComp= lete
-            &n= bsp;            = ;            &n= bsp;     );
-}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm b/UefiCpuPkg/PiSmm= CpuDxeSmm/Ia32/SmmInit.nasm
deleted file mode 100644
index b5e77a1a5b..0000000000
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
+++ /dev/null
@@ -1,96 +0,0 @@
-;-------------------------------------------------------------------------= ----- ;
-; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR= >
-; SPDX-License-Identifier: BSD-2-Clause-Patent
-;
-; Module Name:
-;
-;   SmmInit.nasm
-;
-; Abstract:
-;
-;   Functions for relocating SMBASE's for all processors
-;
-;-------------------------------------------------------------------------= ------
-
-%include "StuffRsbNasm.inc"
-
-extern ASM_PFX(SmmInitHandler)
-extern ASM_PFX(mRebasedFlag)
-extern ASM_PFX(mSmmRelocationOriginalAddress)
-
-global ASM_PFX(gPatchSmmCr3)
-global ASM_PFX(gPatchSmmCr4)
-global ASM_PFX(gPatchSmmCr0)
-global ASM_PFX(gPatchSmmInitStack)
-global ASM_PFX(gcSmiInitGdtr)
-global ASM_PFX(gcSmmInitSize)
-global ASM_PFX(gcSmmInitTemplate)
-
-%define PROTECT_MODE_CS 0x8
-%define PROTECT_MODE_DS 0x20
-
-    SECTION .text
-
-ASM_PFX(gcSmiInitGdtr):
-            DW = ;     0
-            DQ = ;     0
-
-global ASM_PFX(SmmStartup)
-
-BITS 16
-ASM_PFX(SmmStartup):
-    mov     eax, 0x80000001  =            ; read capabil= ity
-    cpuid
-    mov     ebx, edx   &= nbsp;           &nbs= p;    ; rdmsr will change edx. keep it in ebx.
-    and     ebx, BIT20   = ;            &n= bsp;  ; extract NX capability bit
-    shr     ebx, 9   &nb= sp;            =       ; shift bit to IA32_EFER.NXE[BIT11] position=
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr3):
-    mov     cr3, eax
-o32 lgdt    [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(Smm= Startup))]
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr4):
-    mov     cr4, eax
-    mov     ecx, 0xc0000080  =            ; IA32_EFER MS= R
-    rdmsr
-    or      eax, ebx  &n= bsp;            = ;     ; set NXE bit if NX is available
-    wrmsr
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr0):
-    mov     di, PROTECT_MODE_DS
-    mov     cr0, eax
-    jmp     PROTECT_MODE_CS : dword @32= bit
-
-BITS 32
-@32bit:
-    mov     ds, edi
-    mov     es, edi
-    mov     fs, edi
-    mov     gs, edi
-    mov     ss, edi
-    mov     esp, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmInitStack):
-    call    ASM_PFX(SmmInitHandler)
-    StuffRsb32
-    rsm
-
-BITS 16
-ASM_PFX(gcSmmInitTemplate):
-    mov ebp, ASM_PFX(SmmStartup)
-    sub ebp, 0x30000
-    jmp ebp
-
-ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate)
-
-BITS 32
-global ASM_PFX(SmmRelocationSemaphoreComplete)
-ASM_PFX(SmmRelocationSemaphoreComplete):
-    push    eax
-    mov     eax, [ASM_PFX(mRebasedFlag)= ]
-    mov     byte [eax], 1
-    pop     eax
-    jmp     [ASM_PFX(mSmmRelocationOrig= inalAddress)]
-
-global ASM_PFX(PiSmmCpuSmmInitFixupAddress)
-ASM_PFX(PiSmmCpuSmmInitFixupAddress):
-    ret
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c
index 081f0c1501..10baf3ceb9 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1511,26 +1511,24 @@ SmiRendezvous (
   UINTN       Index;
   UINTN       Cr2;
 
   ASSERT (CpuIndex < mMaxNumberOfCpus);
 
-  if (mSmmRelocated) {
-    ASSERT (mSmmInitialized !=3D NULL);
-  }
+  ASSERT (mSmmInitialized !=3D NULL);
 
   //
   // Save Cr2 because Page Fault exception in SMM may override i= ts value,
   // when using on-demand paging for above 4G memory.
   //
   Cr2 =3D 0;
   SaveCr2 (&Cr2);
 
-  if (mSmmRelocated && !mSmmInitialized[CpuIndex]) {
+  if (!mSmmInitialized[CpuIndex]) {
     //
-    // Perform SmmInitHandler for CpuIndex
+    // Perform InitializeSmm for CpuIndex
     //
-    SmmInitHandler ();
+    InitializeSmm ();
 
     //
     // Restore Cr2
     //
     RestoreCr2 (Cr2);
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c
index 499f979d34..fb18168b53 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -54,15 +54,10 @@ CPU_HOT_PLUG_DATA  mCpuHotPlugData =3D {
 //
 // Global pointer used to access mSmmCpuPrivateData from outside and = inside SMM
 //
 SMM_CPU_PRIVATE_DATA  *gSmmCpuPrivate =3D &mSmmCpuPrivateDat= a;
 
-//
-// SMM Relocation variables
-//
-volatile BOOLEAN  *mRebased;
-
 ///
 /// Handle for the SMM CPU Protocol
 ///
 EFI_HANDLE  mSmmCpuHandle =3D NULL;
 
@@ -83,11 +78,10 @@ EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL  mSmmMemoryAtt= ribute =3D {
   EdkiiSmmClearMemoryAttributes
 };
 
 EFI_CPU_INTERRUPT_HANDLER  mExternalVectorTable[EXCEPTION_VECTOR= _NUMBER];
 
-BOOLEAN           mSmmRe= located    =3D FALSE;
 volatile BOOLEAN  *mSmmInitialized =3D NULL;
 UINT32          &nb= sp; mBspApicId       =3D 0;
 
 //
 // SMM stack information
@@ -133,16 +127,10 @@ SPIN_LOCK  *mConfigSmmCodeAccessCheckLock =3D NU= LL;
 EFI_SMRAM_DESCRIPTOR  *mSmmCpuSmramRanges;
 UINTN          &nbs= p;      mSmmCpuSmramRangeCount;
 
 UINT8  mPhysicalAddressBits;
 
-//
-// Control register contents saved for SMM S3 resume state initialization.=
-//
-UINT32  mSmmCr0;
-UINT32  mSmmCr4;
-
 /**
   Initialize IDT to setup exception handlers for SMM.
 
 **/
 VOID
@@ -335,37 +323,32 @@ SmmWriteSaveState (
 
   return Status;
 }
 
 /**
-  C function for SMI handler. To change all processor's SMMBase Regis= ter.
+  Initialize SMM environment.
 
 **/
 VOID
-EFIAPI
-SmmInitHandler (
+InitializeSmm (
   VOID
   )
 {
   UINT32   ApicId;
   UINTN    Index;
   BOOLEAN  IsBsp;
 
-  //
-  // Update SMM IDT entries' code segment and load IDT
-  //
-  AsmWriteIdtr (&gcSmiIdtr);
   ApicId =3D GetApicId ();
 
   IsBsp =3D (BOOLEAN)(mBspApicId =3D=3D ApicId);
 
   ASSERT (mNumberOfCpus <=3D mMaxNumberOfCpus);
 
   for (Index =3D 0; Index < mNumberOfCpus; Index++) {
     if (ApicId =3D=3D (UINT32)gSmmCpuPrivate->Proce= ssorInfo[Index].ProcessorId) {
       PERF_CODE (
-        MpPerfBegin (Index, SMM_MP_PERF= _PROCEDURE_ID (SmmInitHandler));
+        MpPerfBegin (Index, SMM_MP_PERF= _PROCEDURE_ID (InitializeSmm));
         );
       //
       // Initialize SMM specific features on= the currently executing CPU
       //
       SmmCpuFeaturesInitializeProcessor ( @@ -386,19 +369,12 @@ SmmInitHandler (
         // Initialize private data= during S3 resume
         //
         InitializeMpSyncData ();        }
 
-      if (!mSmmRelocated) {
-        //
-        // Hook return after RSM to set= SMM re-based flag
-        //
-        SemaphoreHook (Index, &mReb= ased[Index]);
-      }
-
       PERF_CODE (
-        MpPerfEnd (Index, SMM_MP_PERF_P= ROCEDURE_ID (SmmInitHandler));
+        MpPerfEnd (Index, SMM_MP_PERF_P= ROCEDURE_ID (InitializeSmm));
         );
 
       return;
     }
   }
@@ -454,111 +430,10 @@ ExecuteFirstSmiInit (
   }
 
   PERF_FUNCTION_END ();
 }
 
-/**
-  Relocate SmmBases for each processor.
-
-  Execute on first boot and all S3 resumes
-
-**/
-VOID
-EFIAPI
-SmmRelocateBases (
-  VOID
-  )
-{
-  UINT8          &n= bsp;      BakBuf[BACK_BUF_SIZE];
-  SMRAM_SAVE_STATE_MAP  BakBuf2;
-  SMRAM_SAVE_STATE_MAP  *CpuStatePtr;
-  UINT8          &n= bsp;      *U8Ptr;
-  UINTN          &n= bsp;      Index;
-  UINTN          &n= bsp;      BspIndex;
-
-  PERF_FUNCTION_BEGIN ();
-
-  //
-  // Make sure the reserved size is large enough for procedure SmmIni= tTemplate.
-  //
-  ASSERT (sizeof (BakBuf) >=3D gcSmmInitSize);
-
-  //
-  // Patch ASM code template with current CR0, CR3, and CR4 values -  //
-  mSmmCr0 =3D (UINT32)AsmReadCr0 ();
-  PatchInstructionX86 (gPatchSmmCr0, mSmmCr0, 4);
-  PatchInstructionX86 (gPatchSmmCr3, AsmReadCr3 (), 4);
-  mSmmCr4 =3D (UINT32)AsmReadCr4 ();
-  PatchInstructionX86 (gPatchSmmCr4, mSmmCr4 & (~CR4_CET_ENABLE),= 4);
-
-  //
-  // Patch GDTR for SMM base relocation
-  //
-  gcSmiInitGdtr.Base  =3D gcSmiGdtr.Base;
-  gcSmiInitGdtr.Limit =3D gcSmiGdtr.Limit;
-
-  U8Ptr       =3D (UINT8 *)(UINTN)(SMM_= DEFAULT_SMBASE + SMM_HANDLER_OFFSET);
-  CpuStatePtr =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE = + SMRAM_SAVE_STATE_MAP_OFFSET);
-
-  //
-  // Backup original contents at address 0x38000
-  //
-  CopyMem (BakBuf, U8Ptr, sizeof (BakBuf));
-  CopyMem (&BakBuf2, CpuStatePtr, sizeof (BakBuf2));
-
-  //
-  // Load image for relocation
-  //
-  CopyMem (U8Ptr, gcSmmInitTemplate, gcSmmInitSize);
-
-  //
-  // Retrieve the local APIC ID of current processor
-  //
-  mBspApicId =3D GetApicId ();
-
-  //
-  // Relocate SM bases for all APs
-  // This is APs' 1st SMI - rebase will be done here, and APs' defaul= t SMI handler will be overridden by gcSmmInitTemplate
-  //
-  BspIndex =3D (UINTN)-1;
-  for (Index =3D 0; Index < mNumberOfCpus; Index++) {
-    mRebased[Index] =3D FALSE;
-    if (mBspApicId !=3D (UINT32)gSmmCpuPrivate->Processo= rInfo[Index].ProcessorId) {
-      SendSmiIpi ((UINT32)gSmmCpuPrivate->Proc= essorInfo[Index].ProcessorId);
-      //
-      // Wait for this AP to finish its 1st SMI -      //
-      while (!mRebased[Index]) {
-      }
-    } else {
-      //
-      // BSP will be Relocated later
-      //
-      BspIndex =3D Index;
-    }
-  }
-
-  //
-  // Relocate BSP's SMM base
-  //
-  ASSERT (BspIndex !=3D (UINTN)-1);
-  SendSmiIpi (mBspApicId);
-  //
-  // Wait for the BSP to finish its 1st SMI
-  //
-  while (!mRebased[BspIndex]) {
-  }
-
-  //
-  // Restore contents at address 0x38000
-  //
-  CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2));
-  CopyMem (U8Ptr, BakBuf, sizeof (BakBuf));
-  PERF_FUNCTION_END ();
-}
-
 /**
   SMM Ready To Lock event notification handler.
 
   The CPU S3 data is copied to SMRAM for security and mSmmReadyT= oLock is set to
   perform additional lock actions that must be performed from SM= M on the next SMI.
@@ -881,12 +756,10 @@ PiCpuSmmEntry (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
   EFI_STATUS  Status;
   UINTN       Index;
-  VOID        *Buffer;
-  UINTN       BufferPages;
   UINTN       TileCodeSize;
   UINTN       TileDataSize;
   UINTN       TileSize;
   UINT8       *Stacks;
   VOID        *Registration;<= br> @@ -901,11 +774,10 @@ PiCpuSmmEntry (
   PERF_FUNCTION_BEGIN ();
 
   //
   // Initialize address fixup
   //
-  PiSmmCpuSmmInitFixupAddress ();
   PiSmmCpuSmiEntryFixupAddress ();
 
   //
   // Initialize Debug Agent to support source level debug in SMM= code
   //
@@ -1113,66 +985,34 @@ PiCpuSmmEntry (
   // context must be reduced.
   //
   ASSERT (TileSize <=3D (SMRAM_SAVE_STATE_MAP_OFFSET + sizeof= (SMRAM_SAVE_STATE_MAP) - SMM_HANDLER_OFFSET));
 
   //
-  // Retrive the allocated SmmBase from gSmmBaseHobGuid. If found, +  // Check whether the Required TileSize is enough.
+  //
+  if (TileSize > SIZE_8KB) {
+    DEBUG ((DEBUG_ERROR, "The Range of Smbase in SMRAM= is not enough -- Required TileSize =3D 0x%08x, Actual TileSize =3D 0x%08x\= n", TileSize, SIZE_8KB));
+    FreePool (gSmmCpuPrivate->ProcessorInfo);
+    CpuDeadLoop ();
+    return RETURN_BUFFER_TOO_SMALL;
+  }
+
+  //
+  // Retrieve the allocated SmmBase from gSmmBaseHobGuid. If found,    // means the SmBase relocation has been done.
   //
   mCpuHotPlugData.SmBase =3D NULL;
   Status         &n= bsp;       =3D GetSmBase (mMaxNumberOfCpus, &= amp;mCpuHotPlugData.SmBase);
-  if (Status =3D=3D EFI_OUT_OF_RESOURCES) {
-    ASSERT (Status !=3D EFI_OUT_OF_RESOURCES);
+  ASSERT (!EFI_ERROR (Status));
+  if (EFI_ERROR (Status)) {
     CpuDeadLoop ();
   }
 
-  if (!EFI_ERROR (Status)) {
-    ASSERT (mCpuHotPlugData.SmBase !=3D NULL);
-    //
-    // Check whether the Required TileSize is enough.
-    //
-    if (TileSize > SIZE_8KB) {
-      DEBUG ((DEBUG_ERROR, "The Range of Smb= ase in SMRAM is not enough -- Required TileSize =3D 0x%08x, Actual TileSize= =3D 0x%08x\n", TileSize, SIZE_8KB));
-      FreePool (mCpuHotPlugData.SmBase);
-      FreePool (gSmmCpuPrivate->ProcessorInfo)= ;
-      CpuDeadLoop ();
-      return RETURN_BUFFER_TOO_SMALL;
-    }
-
-    mSmmRelocated =3D TRUE;
-  } else {
-    ASSERT (Status =3D=3D EFI_NOT_FOUND);
-    ASSERT (mCpuHotPlugData.SmBase =3D=3D NULL);
-    //
-    // When the HOB doesn't exist, allocate new SMBASE itse= lf.
-    //
-    DEBUG ((DEBUG_INFO, "PiCpuSmmEntry: gSmmBaseHobGui= d not found!\n"));
-
-    mCpuHotPlugData.SmBase =3D (UINTN *)AllocatePool (sizeo= f (UINTN) * mMaxNumberOfCpus);
-    if (mCpuHotPlugData.SmBase =3D=3D NULL) {
-      ASSERT (mCpuHotPlugData.SmBase !=3D NULL);<= br> -      CpuDeadLoop ();
-    }
-
-    //
-    // very old processors (i486 + pentium) need 32k not 4k= alignment, exclude them.
-    //
-    ASSERT (FamilyId >=3D 6);
-    //
-    // Allocate buffer for all of the tiles.
-    //
-    BufferPages =3D EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize= * (mMaxNumberOfCpus - 1));
-    Buffer      =3D AllocateAligne= dCodePages (BufferPages, SIZE_4KB);
-    if (Buffer =3D=3D NULL) {
-      DEBUG ((DEBUG_ERROR, "Failed to alloca= te %Lu pages.\n", (UINT64)BufferPages));
-      CpuDeadLoop ();
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    ASSERT (Buffer !=3D NULL);
-    DEBUG ((DEBUG_INFO, "New Allcoated SMRAM SaveState= Buffer (0x%08x, 0x%08x)\n", Buffer, EFI_PAGES_TO_SIZE (BufferPages)))= ;
-  }
+  //
+  // ASSERT SmBase has been relocated.
+  //
+  ASSERT (mCpuHotPlugData.SmBase !=3D NULL);
 
   //
   // Allocate buffer for pointers to array in  SMM_CPU_PRIV= ATE_DATA.
   //
   gSmmCpuPrivate->Operation =3D (SMM_CPU_OPERATION *)Allocate= Pool (sizeof (SMM_CPU_OPERATION) * mMaxNumberOfCpus);
@@ -1198,14 +1038,10 @@ PiCpuSmmEntry (
   // Retrieve APIC ID of each enabled processor from the MP Serv= ices protocol.
   // Also compute the SMBASE address, CPU Save State address, an= d CPU Save state
   // size for each CPU in the platform
   //
   for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) {
-    if (!mSmmRelocated) {
-      mCpuHotPlugData.SmBase[Index] =3D (UINTN)Bu= ffer + Index * TileSize - SMM_HANDLER_OFFSET;
-    }
-
     gSmmCpuPrivate->CpuSaveStateSize[Index] =3D siz= eof (SMRAM_SAVE_STATE_MAP);
     gSmmCpuPrivate->CpuSaveState[Index]  =    =3D (VOID *)(mCpuHotPlugData.SmBase[Index] + SMRAM_SAVE_STATE_= MAP_OFFSET);
     gSmmCpuPrivate->Operation[Index]  &nb= sp;     =3D SmmCpuNone;
 
     if (Index < mNumberOfCpus) {
@@ -1297,45 +1133,15 @@ PiCpuSmmEntry (
   DEBUG ((DEBUG_INFO, "PcdCpuSmmStackGuard   = ;   - 0x%x\n", FeaturePcdGet (PcdCpuSmmStackGuard)));
   if ((PcdGet32 (PcdControlFlowEnforcementPropertyMask) !=3D 0) = && mCetSupported) {
     DEBUG ((DEBUG_INFO, "mSmmShadowStackSize = ;     - 0x%x\n", mSmmShadowStackSize));
   }
 
-  //
-  // Set SMI stack for SMM base relocation
-  //
-  PatchInstructionX86 (
-    gPatchSmmInitStack,
-    (UINTN)(Stacks + mSmmStackSize - sizeof (UINTN)),
-    sizeof (UINTN)
-    );
-
   //
   // Initialize IDT
   //
   InitializeSmmIdt ();
 
-  //
-  // Check whether Smm Relocation is done or not.
-  // If not, will do the SmmBases Relocation here!!!
-  //
-  if (!mSmmRelocated) {
-    //
-    // Relocate SMM Base addresses to the ones allocated fr= om SMRAM
-    //
-    mRebased =3D (BOOLEAN *)AllocateZeroPool (sizeof (BOOLE= AN) * mMaxNumberOfCpus);
-    ASSERT (mRebased !=3D NULL);
-    SmmRelocateBases ();
-
-    //
-    // Call hook for BSP to perform extra actions in normal= mode after all
-    // SMM base addresses have been relocated on all CPUs -    //
-    SmmCpuFeaturesSmmRelocationComplete ();
-  }
-
-  DEBUG ((DEBUG_INFO, "mXdSupported - 0x%x\n", mXdSupported= ));
-
   //
   // SMM Time initialization
   //
   InitializeSmmTimer ();
 
@@ -1368,19 +1174,19 @@ PiCpuSmmEntry (
   //
   // For relocated SMBASE, some MSRs & CSRs are still requir= ed to be configured in SMM Mode for SMM Initialization.
   // Those MSRs & CSRs must be configured before normal SMI = sources happen.
   // So, here is to issue SMI IPI (All Excluding  Self SMM = IPI + BSP SMM IPI) to execute first SMI init.
   //
-  if (mSmmRelocated) {
-    ExecuteFirstSmiInit ();
+  ExecuteFirstSmiInit ();
 
-    //
-    // Call hook for BSP to perform extra actions in normal= mode after all
-    // SMM base addresses have been relocated on all CPUs -    //
-    SmmCpuFeaturesSmmRelocationComplete ();
-  }
+  //
+  // Call hook for BSP to perform extra actions in normal mode after = all
+  // SMM base addresses have been relocated on all CPUs
+  //
+  SmmCpuFeaturesSmmRelocationComplete ();
+
+  DEBUG ((DEBUG_INFO, "mXdSupported - 0x%x\n", mXdSupported= ));
 
   //
   // Fill in SMM Reserved Regions
   //
   gSmmCpuPrivate->SmmReservedSmramRegion[0].SmramReservedStar= t =3D 0;
@@ -1767,92 +1573,10 @@ AllocateCodePages (
   }
 
   return (VOID *)(UINTN)Memory;
 }
 
-/**
-  Allocate aligned pages for code.
-
-  @param[in]  Pages       &nb= sp;         Number of pages to be a= llocated.
-  @param[in]  Alignment       = ;      The requested alignment of the allocation.<= br> -            &n= bsp;            = ;           Must be a pow= er of two.
-            &n= bsp;            = ;           If Alignment = is zero, then byte alignment is used.
-
-  @return Allocated memory.
-**/
-VOID *
-AllocateAlignedCodePages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  )
-{
-  EFI_STATUS         &nb= sp;  Status;
-  EFI_PHYSICAL_ADDRESS  Memory;
-  UINTN          &n= bsp;      AlignedMemory;
-  UINTN          &n= bsp;      AlignmentMask;
-  UINTN          &n= bsp;      UnalignedPages;
-  UINTN          &n= bsp;      RealPages;
-
-  //
-  // Alignment must be a power of two or zero.
-  //
-  ASSERT ((Alignment & (Alignment - 1)) =3D=3D 0);
-
-  if (Pages =3D=3D 0) {
-    return NULL;
-  }
-
-  if (Alignment > EFI_PAGE_SIZE) {
-    //
-    // Calculate the total number of pages since alignment = is larger than page size.
-    //
-    AlignmentMask =3D Alignment - 1;
-    RealPages     =3D Pages + EFI_SIZE_= TO_PAGES (Alignment);
-    //
-    // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignme= nt) does not overflow.
-    //
-    ASSERT (RealPages > Pages);
-
-    Status =3D gSmst->SmmAllocatePages (AllocateAnyPages= , EfiRuntimeServicesCode, RealPages, &Memory);
-    if (EFI_ERROR (Status)) {
-      return NULL;
-    }
-
-    AlignedMemory  =3D ((UINTN)Memory + AlignmentMask)= & ~AlignmentMask;
-    UnalignedPages =3D EFI_SIZE_TO_PAGES (AlignedMemory - (= UINTN)Memory);
-    if (UnalignedPages > 0) {
-      //
-      // Free first unaligned page(s).
-      //
-      Status =3D gSmst->SmmFreePages (Memory, = UnalignedPages);
-      ASSERT_EFI_ERROR (Status);
-    }
-
-    Memory         = =3D AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
-    UnalignedPages =3D RealPages - Pages - UnalignedPages;<= br> -    if (UnalignedPages > 0) {
-      //
-      // Free last unaligned page(s).
-      //
-      Status =3D gSmst->SmmFreePages (Memory, = UnalignedPages);
-      ASSERT_EFI_ERROR (Status);
-    }
-  } else {
-    //
-    // Do not over-allocate pages in this case.
-    //
-    Status =3D gSmst->SmmAllocatePages (AllocateAnyPages= , EfiRuntimeServicesCode, Pages, &Memory);
-    if (EFI_ERROR (Status)) {
-      return NULL;
-    }
-
-    AlignedMemory =3D (UINTN)Memory;
-  }
-
-  return (VOID *)AlignedMemory;
-}
-
 /**
   Perform the remaining tasks.
 
 **/
 VOID
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h
index 7f244ea803..f42910ddf1 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
@@ -186,18 +186,10 @@ typedef struct {
 // Code select value
 //
 #define PROTECT_MODE_CODE_SEGMENT  0x08
 #define LONG_MODE_CODE_SEGMENT     0x38
 
-//
-// The size 0x20 must be bigger than
-// the size of template code of SmmInit. Currently,
-// the size of SmmInit requires the 0x16 Bytes buffer
-// at least.
-//
-#define BACK_BUF_SIZE  0x20
-
 #define EXCEPTION_VECTOR_NUMBER  0x20
 
 #define INVALID_APIC_ID  0xFFFFFFFFFFFFFFFFULL
 
 //
@@ -355,16 +347,15 @@ SmmWriteSaveState (
   IN UINTN         =             &nb= sp;  CpuIndex,
   IN CONST VOID        &= nbsp;          *Buffer
   );
 
 /**
-  C function for SMI handler. To change all processor's SMMBase Regis= ter.
+  Initialize SMM environment.
 
 **/
 VOID
-EFIAPI
-SmmInitHandler (
+InitializeSmm (
   VOID
   );
 
 /**
   Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to ex= ecute first SMI init.
@@ -373,22 +364,13 @@ SmmInitHandler (
 VOID
 ExecuteFirstSmiInit (
   VOID
   );
 
-extern BOOLEAN          =   mSmmRelocated;
 extern volatile  BOOLEAN  *mSmmInitialized;
 extern UINT32         &n= bsp;   mBspApicId;
 
-extern CONST UINT8        gcSmmInitTemp= late[];
-extern CONST UINT16       gcSmmInitSize;
-X86_ASSEMBLY_PATCH_LABEL  gPatchSmmCr0;
-extern UINT32          &= nbsp;  mSmmCr0;
-X86_ASSEMBLY_PATCH_LABEL  gPatchSmmCr3;
-extern UINT32          &= nbsp;  mSmmCr4;
-X86_ASSEMBLY_PATCH_LABEL  gPatchSmmCr4;
-X86_ASSEMBLY_PATCH_LABEL  gPatchSmmInitStack;
 X86_ASSEMBLY_PATCH_LABEL  mPatchCetSupported;
 extern BOOLEAN         &= nbsp;  mCetSupported;
 
 /**
   Semaphore operation for all processor relocate SMMBase.
@@ -473,11 +455,10 @@ extern UINT64      &nbs= p;            &= nbsp;    gPhyMask;
 extern SMM_DISPATCHER_MP_SYNC_DATA   *mSmmMpSyncData;
 extern UINTN         &nb= sp;            =    mSmmStackArrayBase;
 extern UINTN         &nb= sp;            =    mSmmStackArrayEnd;
 extern UINTN         &nb= sp;            =    mSmmStackSize;
 extern EFI_SMM_CPU_SERVICE_PROTOCOL  mSmmCpuService;
-extern IA32_DESCRIPTOR        &nbs= p;      gcSmiInitGdtr;
 extern SMM_CPU_SEMAPHORES       &n= bsp;    mSmmCpuSemaphores;
 extern UINTN         &nb= sp;            =    mSemaphoreSize;
 extern SPIN_LOCK         = ;            *mPFLoc= k;
 extern SPIN_LOCK         = ;            *mConfi= gSmmCodeAccessCheckLock;
 extern EFI_SMRAM_DESCRIPTOR       =    *mSmmCpuSmramRanges;
@@ -791,22 +772,10 @@ VOID
 FindSmramInfo (
   OUT UINT32  *SmrrBase,
   OUT UINT32  *SmrrSize
   );
 
-/**
-  Relocate SmmBases for each processor.
-
-  Execute on first boot and all S3 resumes
-
-**/
-VOID
-EFIAPI
-SmmRelocateBases (
-  VOID
-  );
-
 /**
   Page Fault handler for SMM use.
 
   @param  InterruptType    Defines the type = of interrupt or exception that
            &nb= sp;            =    occurred on the processor.This parameter is processor architec= ture specific.
@@ -847,62 +816,19 @@ PerformPreTasks (
 VOID
 InitMsrSpinLockByIndex (
   IN UINT32  MsrIndex
   );
 
-/**
-  Hook return address of SMM Save State so that semaphore code
-  can be executed immediately after AP exits SMM to indicate to
-  the BSP that an AP has exited SMM after SMBASE relocation.
-
-  @param[in] CpuIndex     The processor index. -  @param[in] RebasedFlag  A pointer to a flag that is set to TRU= E
-            &n= bsp;            = ; immediately after AP exits SMM.
-
-**/
-VOID
-SemaphoreHook (
-  IN UINTN          = ;   CpuIndex,
-  IN volatile BOOLEAN  *RebasedFlag
-  );
-
 /**
 Configure SMM Code Access Check feature for all processors.
 SMM Feature Control MSR will be locked after configuration.
 **/
 VOID
 ConfigSmmCodeAccessCheck (
   VOID
   );
 
-/**
-  Hook the code executed immediately after an RSM instruction on the = currently
-  executing CPU.  The mode of code executed immediately after RS= M must be
-  detected, and the appropriate hook must be selected.  Always c= lear the auto
-  HALT restart flag if it is set.
-
-  @param[in] CpuIndex        =          The processor index for th= e currently
-            &n= bsp;            = ;             e= xecuting CPU.
-  @param[in] CpuState        =          Pointer to SMRAM Save Stat= e Map for the
-            &n= bsp;            = ;             c= urrently executing CPU.
-  @param[in] NewInstructionPointer32  Instruction pointer to use= if resuming to
-            &n= bsp;            = ;             3= 2-bit mode from 64-bit SMM.
-  @param[in] NewInstructionPointer    Instruction poin= ter to use if resuming to
-            &n= bsp;            = ;             s= ame mode as SMM.
-
-  @retval The value of the original instruction pointer before it was= hooked.
-
-**/
-UINT64
-EFIAPI
-HookReturnFromSmm (
-  IN UINTN          = ;    CpuIndex,
-  SMRAM_SAVE_STATE_MAP  *CpuState,
-  UINT64          &= nbsp;     NewInstructionPointer32,
-  UINT64          &= nbsp;     NewInstructionPointer
-  );
-
 /**
   Get the size of the SMI Handler in bytes.
 
   @retval The size, in bytes, of the SMI Handler.
 
@@ -1103,26 +1029,10 @@ AllocatePageTableMemory (
 VOID *
 AllocateCodePages (
   IN UINTN  Pages
   );
 
-/**
-  Allocate aligned pages for code.
-
-  @param[in]  Pages       &nb= sp;         Number of pages to be a= llocated.
-  @param[in]  Alignment       = ;      The requested alignment of the allocation.<= br> -            &n= bsp;            = ;           Must be a pow= er of two.
-            &n= bsp;            = ;           If Alignment = is zero, then byte alignment is used.
-
-  @return Allocated memory.
-**/
-VOID *
-AllocateAlignedCodePages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  );
-
 //
 // S3 related global variable and function prototype.
 //
 
 extern BOOLEAN  mSmmS3Flag;
@@ -1300,19 +1210,10 @@ EdkiiSmmGetMemoryAttributes (
   IN  EFI_PHYSICAL_ADDRESS     &nb= sp;           BaseAddress= ,
   IN  UINT64        = ;            &n= bsp;          Length,
   IN  UINT64        = ;            &n= bsp;          *Attributes
   );
 
-/**
-  This function fixes up the address of the global variable or functi= on
-  referred in SmmInit assembly files to be the absolute address.
-**/
-VOID
-EFIAPI
-PiSmmCpuSmmInitFixupAddress (
-  );
-
 /**
   This function fixes up the address of the global variable or f= unction
   referred in SmiEntry assembly files to be the absolute address= .
 **/
 VOID
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf
index a018954ed7..1a230ad2d0 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -45,28 +45,24 @@
   SmmMp.c
   SmmMpPerf.h
   SmmMpPerf.c
 
 [Sources.Ia32]
-  Ia32/Semaphore.c
   Ia32/PageTbl.c
   Ia32/SmmFuncsArch.c
   Ia32/SmmProfileArch.c
   Ia32/SmmProfileArch.h
-  Ia32/SmmInit.nasm
   Ia32/SmiEntry.nasm
   Ia32/SmiException.nasm
   Ia32/MpFuncs.nasm
   Ia32/Cet.nasm
 
 [Sources.X64]
-  X64/Semaphore.c
   X64/PageTbl.c
   X64/SmmFuncsArch.c
   X64/SmmProfileArch.c
   X64/SmmProfileArch.h
-  X64/SmmInit.nasm
   X64/SmiEntry.nasm
   X64/SmiException.nasm
   X64/MpFuncs.nasm
   X64/Cet.nasm
 
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h b/UefiCpuPkg/PiSmmCpuDxe= Smm/SmmMpPerf.h
index 591b212c06..2e2ea3c76e 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
@@ -12,11 +12,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 //
 // The list of all MP procedures that need to be perf-logged.
 //
 #define  SMM_MP_PERF_PROCEDURE_LIST(_) \
-  _(SmmInitHandler), \
+  _(InitializeSmm), \
   _(SmmRendezvousEntry), \
   _(PlatformValidSmi), \
   _(SmmRendezvousExit), \
   _(SmmMpProcedureMax) // Add new entries above this line
 
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmC= puDxeSmm/SmramSaveState.c
index 1e316ee0ac..b9a62aeeb0 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
@@ -67,79 +67,10 @@ IA32_DESCRIPTOR  gSmiHandlerIdtr;
 ///
 /// The mode of the CPU at the time an SMI occurs
 ///
 UINT8  mSmmSaveStateRegisterLma;
 
-/**
-  Hook the code executed immediately after an RSM instruction on the = currently
-  executing CPU.  The mode of code executed immediately after RS= M must be
-  detected, and the appropriate hook must be selected.  Always c= lear the auto
-  HALT restart flag if it is set.
-
-  @param[in] CpuIndex        =          The processor index for th= e currently
-            &n= bsp;            = ;             e= xecuting CPU.
-  @param[in] CpuState        =          Pointer to SMRAM Save Stat= e Map for the
-            &n= bsp;            = ;             c= urrently executing CPU.
-  @param[in] NewInstructionPointer32  Instruction pointer to use= if resuming to
-            &n= bsp;            = ;             3= 2-bit mode from 64-bit SMM.
-  @param[in] NewInstructionPointer    Instruction poin= ter to use if resuming to
-            &n= bsp;            = ;             s= ame mode as SMM.
-
-  @retval The value of the original instruction pointer before it was= hooked.
-
-**/
-UINT64
-EFIAPI
-HookReturnFromSmm (
-  IN UINTN          = ;    CpuIndex,
-  SMRAM_SAVE_STATE_MAP  *CpuState,
-  UINT64          &= nbsp;     NewInstructionPointer32,
-  UINT64          &= nbsp;     NewInstructionPointer
-  )
-{
-  UINT64  OriginalInstructionPointer;
-
-  OriginalInstructionPointer =3D SmmCpuFeaturesHookReturnFromSmm ( -            &n= bsp;            = ;        CpuIndex,
-            &n= bsp;            = ;        CpuState,
-            &n= bsp;            = ;        NewInstructionPointer32,
-            &n= bsp;            = ;        NewInstructionPointer
-            &n= bsp;            = ;        );
-  if (OriginalInstructionPointer !=3D 0) {
-    return OriginalInstructionPointer;
-  }
-
-  if (mSmmSaveStateRegisterLma =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA= _32BIT) {
-    OriginalInstructionPointer =3D (UINT64)CpuState->x86= ._EIP;
-    CpuState->x86._EIP     &nbs= p;   =3D (UINT32)NewInstructionPointer;
-    //
-    // Clear the auto HALT restart flag so the RSM instruct= ion returns
-    // program control to the instruction following the HLT= instruction.
-    //
-    if ((CpuState->x86.AutoHALTRestart & BIT0) !=3D = 0) {
-      CpuState->x86.AutoHALTRestart &=3D ~= BIT0;
-    }
-  } else {
-    OriginalInstructionPointer =3D CpuState->x64._RIP; -    if ((CpuState->x64.IA32_EFER & LMA) =3D=3D 0) {<= br> -      CpuState->x64._RIP =3D (UINT32)NewInstru= ctionPointer32;
-    } else {
-      CpuState->x64._RIP =3D (UINT32)NewInstru= ctionPointer;
-    }
-
-    //
-    // Clear the auto HALT restart flag so the RSM instruct= ion returns
-    // program control to the instruction following the HLT= instruction.
-    //
-    if ((CpuState->x64.AutoHALTRestart & BIT0) !=3D = 0) {
-      CpuState->x64.AutoHALTRestart &=3D ~= BIT0;
-    }
-  }
-
-  return OriginalInstructionPointer;
-}
-
 /**
   Get the size of the SMI Handler in bytes.
 
   @retval The size, in bytes, of the SMI Handler.
 
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c b/UefiCpuPkg/PiSmmCp= uDxeSmm/X64/Semaphore.c
deleted file mode 100644
index dafbc3390e..0000000000
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/** @file
-Semaphore mechanism to indicate to the BSP that an AP has exited SMM
-after SMBASE relocation.
-
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR&g= t;
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "PiSmmCpuDxeSmm.h"
-
-X86_ASSEMBLY_PATCH_LABEL  gPatchSmmRelocationOriginalAddressPtr32; -X86_ASSEMBLY_PATCH_LABEL  gPatchRebasedFlagAddr32;
-
-UINTN           &nb= sp; mSmmRelocationOriginalAddress;
-volatile BOOLEAN  *mRebasedFlag;
-
-/**
-AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode.
-**/
-VOID
-SmmRelocationSemaphoreComplete32 (
-  VOID
-  );
-
-/**
-  Hook return address of SMM Save State so that semaphore code
-  can be executed immediately after AP exits SMM to indicate to
-  the BSP that an AP has exited SMM after SMBASE relocation.
-
-  @param[in] CpuIndex     The processor index. -  @param[in] RebasedFlag  A pointer to a flag that is set to TRU= E
-            &n= bsp;            = ; immediately after AP exits SMM.
-
-**/
-VOID
-SemaphoreHook (
-  IN UINTN          = ;   CpuIndex,
-  IN volatile BOOLEAN  *RebasedFlag
-  )
-{
-  SMRAM_SAVE_STATE_MAP  *CpuState;
-  UINTN          &n= bsp;      TempValue;
-
-  mRebasedFlag =3D RebasedFlag;
-  PatchInstructionX86 (
-    gPatchRebasedFlagAddr32,
-    (UINT32)(UINTN)mRebasedFlag,
-    4
-    );
-
-  CpuState          = ;            =3D (SM= RAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFS= ET);
-  mSmmRelocationOriginalAddress =3D HookReturnFromSmm (
-            &n= bsp;            = ;           CpuIndex,
-            &n= bsp;            = ;           CpuState,
-            &n= bsp;            = ;           (UINT64)(UINT= N)&SmmRelocationSemaphoreComplete32,
-            &n= bsp;            = ;           (UINT64)(UINT= N)&SmmRelocationSemaphoreComplete
-            &n= bsp;            = ;           );
-
-  //
-  // Use temp value to fix ICC compiler warning
-  //
-  TempValue =3D (UINTN)&mSmmRelocationOriginalAddress;
-  PatchInstructionX86 (
-    gPatchSmmRelocationOriginalAddressPtr32,
-    (UINT32)TempValue,
-    4
-    );
-}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm b/UefiCpuPkg/PiSmmC= puDxeSmm/X64/SmmInit.nasm
deleted file mode 100644
index 9cf3a6dcf9..0000000000
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
+++ /dev/null
@@ -1,146 +0,0 @@
-;-------------------------------------------------------------------------= ----- ;
-; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR= >
-; SPDX-License-Identifier: BSD-2-Clause-Patent
-;
-; Module Name:
-;
-;   SmmInit.nasm
-;
-; Abstract:
-;
-;   Functions for relocating SMBASE's for all processors
-;
-;-------------------------------------------------------------------------= ------
-
-%include "StuffRsbNasm.inc"
-
-extern ASM_PFX(SmmInitHandler)
-extern ASM_PFX(mRebasedFlag)
-extern ASM_PFX(mSmmRelocationOriginalAddress)
-
-global ASM_PFX(gPatchSmmCr3)
-global ASM_PFX(gPatchSmmCr4)
-global ASM_PFX(gPatchSmmCr0)
-global ASM_PFX(gPatchSmmInitStack)
-global ASM_PFX(gcSmiInitGdtr)
-global ASM_PFX(gcSmmInitSize)
-global ASM_PFX(gcSmmInitTemplate)
-global ASM_PFX(gPatchRebasedFlagAddr32)
-global ASM_PFX(gPatchSmmRelocationOriginalAddressPtr32)
-
-%define LONG_MODE_CS 0x38
-
-    DEFAULT REL
-    SECTION .text
-
-ASM_PFX(gcSmiInitGdtr):
-            DW = ;     0
-            DQ = ;     0
-
-global ASM_PFX(SmmStartup)
-
-BITS 16
-ASM_PFX(SmmStartup):
-    mov     eax, 0x80000001  =            ; read capabil= ity
-    cpuid
-    mov     ebx, edx   &= nbsp;           &nbs= p;    ; rdmsr will change edx. keep it in ebx.
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr3):
-    mov     cr3, eax
-o32 lgdt    [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(Smm= Startup))]
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr4):
-    or      ah,  2  = ;            &n= bsp;       ; enable XMM registers access
-    mov     cr4, eax
-    mov     ecx, 0xc0000080  =            ; IA32_EFER MS= R
-    rdmsr
-    or      ah, BIT0  &n= bsp;            = ;     ; set LME bit
-    test    ebx, BIT20   &nbs= p;            &= nbsp; ; check NXE capability
-    jz      .1
-    or      ah, BIT3  &n= bsp;            = ;     ; set NXE bit
-.1:
-    wrmsr
-    mov     eax, strict dword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmCr0):
-    mov     cr0, eax   &= nbsp;           &nbs= p;    ; enable protected mode & paging
-    jmp     LONG_MODE_CS : dword 0 = ;     ; offset will be patched to @LongMode
-@PatchLongModeOffset:
-
-BITS 64
-@LongMode:          &nbs= p;            &= nbsp;      ; long-mode starts here
-    mov     rsp, strict qword 0 &n= bsp;       ; source operand will be patched -ASM_PFX(gPatchSmmInitStack):
-    and     sp, 0xfff0   = ;            &n= bsp;  ; make sure RSP is 16-byte aligned
-    ;
-    ; According to X64 calling convention, XMM0~5 are volat= ile, we need to save
-    ; them before calling C-function.
-    ;
-    sub     rsp, 0x60
-    movdqa  [rsp], xmm0
-    movdqa  [rsp + 0x10], xmm1
-    movdqa  [rsp + 0x20], xmm2
-    movdqa  [rsp + 0x30], xmm3
-    movdqa  [rsp + 0x40], xmm4
-    movdqa  [rsp + 0x50], xmm5
-
-    add     rsp, -0x20
-    call    ASM_PFX(SmmInitHandler)
-    add     rsp, 0x20
-
-    ;
-    ; Restore XMM0~5 after calling C-function.
-    ;
-    movdqa  xmm0, [rsp]
-    movdqa  xmm1, [rsp + 0x10]
-    movdqa  xmm2, [rsp + 0x20]
-    movdqa  xmm3, [rsp + 0x30]
-    movdqa  xmm4, [rsp + 0x40]
-    movdqa  xmm5, [rsp + 0x50]
-
-    StuffRsb64
-    rsm
-
-BITS 16
-ASM_PFX(gcSmmInitTemplate):
-    mov ebp, [cs:@L1 - ASM_PFX(gcSmmInitTemplate) + 0x8000]=
-    sub ebp, 0x30000
-    jmp ebp
-@L1:
-    DQ     0; ASM_PFX(SmmStartup)
-
-ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate)
-
-BITS 64
-global ASM_PFX(SmmRelocationSemaphoreComplete)
-ASM_PFX(SmmRelocationSemaphoreComplete):
-    push    rax
-    mov     rax, [ASM_PFX(mRebasedFlag)= ]
-    mov     byte [rax], 1
-    pop     rax
-    jmp     [ASM_PFX(mSmmRelocationOrig= inalAddress)]
-
-;
-; Semaphore code running in 32-bit mode
-;
-BITS 32
-global ASM_PFX(SmmRelocationSemaphoreComplete32)
-ASM_PFX(SmmRelocationSemaphoreComplete32):
-    push    eax
-    mov     eax, strict dword 0 &n= bsp;            = ;  ; source operand will be patched
-ASM_PFX(gPatchRebasedFlagAddr32):
-    mov     byte [eax], 1
-    pop     eax
-    jmp     dword [dword 0]  =             &nb= sp;     ; destination will be patched
-ASM_PFX(gPatchSmmRelocationOriginalAddressPtr32):
-
-BITS 64
-global ASM_PFX(PiSmmCpuSmmInitFixupAddress)
-ASM_PFX(PiSmmCpuSmmInitFixupAddress):
-    lea    rax, [@LongMode]
-    lea    rcx, [@PatchLongModeOffset - 6] -    mov    dword [rcx], eax
-
-    lea    rax, [ASM_PFX(SmmStartup)]
-    lea    rcx, [@L1]
-    mov    qword [rcx], rax
-    ret
--
2.16.2.windows.1

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#118588) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB82441E9DC6BC989A188801408C1C2MN6PR11MB8244namp_--