From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CJ4ILsj0; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: ted.kuo@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646893257; x=1678429257; h=from:to:cc:subject:date:message-id; bh=JtijLgAcyLOWM+U7LjOfU+37+E7N7kT5Wfngh62UmrA=; b=CJ4ILsj02amNbn2O8LSibRaXmDZBOwgFdEaFoZcJzaRSbdkpvfo/qb0h NA3H5XW+GGY2hKKnsC88gzUgjD7DTNw382EHG1S805Eg09zkGTkd/alkO KdUFtlKol0OtFAQOnoY0qLV7S04Hq0ca2FIhVorW5VUO7eSgDplWQiisx qMK1znKVDx/f6jj8eYTinZ9KDgyiH3ky2UGwHl/SbvjMuRndNTlU6sQ2S soGEOgc12XrAFMlM3eHvxeSTKEmuVtSyKT4Y2/xrOw/p5p+mM95omMUMs +A4ORcFF7CSnVy/b7Y4mltLEY86fiPCe1iSgVjob6jmAjzCISVTXt0pUm w==; 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" 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" 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: X-Mailer: git-send-email 2.16.2.windows.1 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3865 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/Core/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/Core/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/PeiMain.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 ); +/** + 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 temporary RAM, the stack location and + the BFV location. + @param PpiList Points to a list of one or more PPI descriptors to 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-hosted 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 initialize 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/PeiMain.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 +[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/Core/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 stack + call ASM_PFX(PeiCore) + jmp $ ; Should never reach here + ret + -- 2.16.2.windows.1