From nobody Sun May 19 19:10:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87397+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87397+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1646893259; cv=none; d=zohomail.com; s=zohoarc; b=MWajhFroEqrGCzZ3KqkJk56YIOLd6HdJQK5SPcI4UEBRONyOqW6LtVz5l3sQe8GNaznWqocTZiqBWdgr9Y5SKQO1w0wtAc9yNFUaWn1oPJZ+zM45M+Yyeoa7mqYY8QOdMfOGPdR1q8HfefO5lUsmaEl5cugXjtOup/Pda8T28/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646893259; h=Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=4xqYhz2cwvoXTCxTKaw5o6r1Cea0NzXKor7oYV0n1rg=; b=LHvCrYD9urpy/OL/OsItdj2eRB4wJF1ZFIM40Ta2PCZolkndT8GCwo76lCiLhYAVncLQB1KdDMc5Mi8Bxvl/wfCwf7hMrhHmHpiEVN4zyy7A8OyYZYhqwt/aKMk1Ivs6lbAwQ2g4dTDZRLg3fjRUsYYpm0fiYD/yZfnqsweHp4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87397+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1646893259626866.6455138329663; Wed, 9 Mar 2022 22:20:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id MFO1YY1788612xTEwyfqqNI5; Wed, 09 Mar 2022 22:20:59 -0800 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.6625.1646893257575267571 for ; Wed, 09 Mar 2022 22:20:58 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10281"; a="242616173" X-IronPort-AV: E=Sophos;i="5.90,169,1643702400"; d="scan'208";a="242616173" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2022 22:20:56 -0800 X-IronPort-AV: E=Sophos;i="5.90,169,1643702400"; d="scan'208";a="554495987" X-Received: from tedkuo1-win10.gar.corp.intel.com ([10.5.215.13]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2022 22:20:53 -0800 From: "Kuo, Ted" To: devel@edk2.groups.io Cc: Dandan Bi , Liming Gao , Debkumar De , Harry Han , Catharine West , Jian J Wang , Ashraf Ali S Subject: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit Date: Thu, 10 Mar 2022 14:20:41 +0800 Message-Id: Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ted.kuo@intel.com X-Gm-Message-State: F2FK70MeTlcoPiHWpyzJhJOux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1646893259; bh=5DQ95FrM9bzyyQU1uVBoEeyOI23Fzdm6ZWoWztx+LkQ=; h=Cc:Date:From:Reply-To:Subject:To; b=P6nLmcuM8sLjiXtB4Ka313VHykACP5+Uq1w0pbU9gC/i3WKjSNE7IHGiqWAEoUT7FI6 PfNhBeOUWOmj3CAzRWDhKYVxhp45jZBYZpETROZBuaeqKD3AxtTY95OZO93XXsIW25ftO 1whyaOQl8hrNS0UEVRAJLSGHcbBRxq+n3GY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1646893260156100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3865 Use SwitchPeiCore instead of calling PeiCore directly when switching PeiCore from temporary memory to permanent memory. For PEI 32bit, SwitchPeiCore always calls PeiCore without any additional step. For PEI 64bit, SwitchPeiCore makes RSP 16-byte boundary aligned and then allocate 32 bytes as a shadow store on call stack before calling PeiCore. Cc: Dandan Bi Cc: Liming Gao Cc: Debkumar De Cc: Harry Han Cc: Catharine West Cc: Jian J Wang Cc: Ashraf Ali S Signed-off-by: Ted Kuo --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 2 +- MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm | 33 +++++++++++++++++++++++ MdeModulePkg/Core/Pei/PeiMain.h | 25 ++++++++++++++++++ MdeModulePkg/Core/Pei/PeiMain.inf | 6 +++++ MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm | 38 +++++++++++++++++++++++= ++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm create mode 100644 MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 3552feda8f..5af6e6e86f 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -871,7 +871,7 @@ PeiCheckAndSwitchStack ( // // Entry PEI Phase 2 // - PeiCore (SecCoreData, NULL, Private); + SwitchPeiCore (SecCoreData, NULL, Private); } else { // // Migrate memory pages allocated in pre-memory phase. diff --git a/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm b/MdeModulePkg/C= ore/Pei/Ia32/SwitchPeiCore.nasm new file mode 100644 index 0000000000..23cfb5090b --- /dev/null +++ b/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm @@ -0,0 +1,33 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (c) 2022, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Abstract: +; +; Switch PeiCore from temporary memory to permanent memory. +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +extern ASM_PFX(PeiCore) + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; SwitchPeiCore ( +; EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, +; EFI_PEI_PPI_DESCRIPTOR *PpiList, +; VOID *Data +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(SwitchPeiCore) +ASM_PFX(SwitchPeiCore): + push DWORD [esp + 12] + push DWORD [esp + 12] + push DWORD [esp + 12] + call ASM_PFX(PeiCore) + jmp $ ; Should never reach here + ret + diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMai= n.h index 556beddad5..8e8ed3dadf 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -2038,4 +2038,29 @@ PeiReinitializeFv ( IN PEI_CORE_INSTANCE *PrivateData ); =20 +/** + This routine is invoked by main entry of PeiMain module during transition + from temporary memory to permanent memory. + + @param SecCoreDataPtr Points to a data structure containing information= about the PEI core's operating + environment, such as the size and location of tem= porary RAM, the stack location and + the BFV location. + @param PpiList Points to a list of one or more PPI descriptors t= o be installed initially by the PEI core. + An empty PPI list consists of a single descriptor= with the end-tag + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of= its initialization + phase, the PEI Foundation will add these SEC-host= ed PPIs to its PPI database such + that both the PEI Foundation and any modules can = leverage the associated service + calls and/or code in these early PPIs + @param Data Pointer to old core data that is used to initiali= ze the + core's data areas. + If NULL, it is first PeiCore entering. + +**/ +VOID +EFIAPI +SwitchPeiCore ( + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, + IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, + IN VOID *Data + ); #endif diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index 0cf357371a..b597aed8f6 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -47,6 +47,12 @@ PciCfg2/PciCfg2.c PeiMain.h =20 +[Sources.IA32] + Ia32/SwitchPeiCore.nasm + +[Sources.X64] + X64/SwitchPeiCore.nasm + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec diff --git a/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm b/MdeModulePkg/Co= re/Pei/X64/SwitchPeiCore.nasm new file mode 100644 index 0000000000..94e09be757 --- /dev/null +++ b/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm @@ -0,0 +1,38 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (c) 2022, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Abstract: +; +; Switch PeiCore from temporary memory to permanent memory. +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +extern ASM_PFX(PeiCore) + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; SwitchPeiCore ( +; EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, +; EFI_PEI_PPI_DESCRIPTOR *PpiList, +; VOID *Data +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(SwitchPeiCore) +ASM_PFX(SwitchPeiCore): + ; + ; Per X64 calling convention, make sure RSP is 16-byte aligned. + ; + mov rax, rsp + and rax, 0fh + sub rsp, rax + + sub rsp, 20h ; Allocate 32 bytes as a shadow store on call st= ack + call ASM_PFX(PeiCore) + jmp $ ; Should never reach here + ret + --=20 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 (#87397): https://edk2.groups.io/g/devel/message/87397 Mute This Topic: https://groups.io/mt/89681320/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-