public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit
@ 2022-03-10  6:20 Kuo, Ted
  0 siblings, 0 replies; 4+ messages in thread
From: Kuo, Ted @ 2022-03-10  6:20 UTC (permalink / raw)
  To: devel
  Cc: Dandan Bi, Liming Gao, Debkumar De, Harry Han, Catharine West,
	Jian J Wang, Ashraf Ali S

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 <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Debkumar De <debkumar.de@intel.com>
Cc: Harry Han <harry.han@intel.com>
Cc: Catharine West <catharine.west@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 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.<BR>
+; 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.<BR>
+; 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread
[parent not found: <16DAF0B16C1B1922.28111@groups.io>]

end of thread, other threads:[~2022-03-18 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-10  6:20 [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit Kuo, Ted
     [not found] <16DAF0B16C1B1922.28111@groups.io>
2022-03-17  1:04 ` Kuo, Ted
2022-03-17 11:08   ` Marvin Häuser
2022-03-18 13:46     ` Kuo, Ted

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox