public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jordan Justen <jordan.l.justen@intel.com>
To: edk2-devel@lists.01.org
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>, Hao Wu <hao.a.wu@intel.com>,
	Ray Ni <ray.ni@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH 08/10] MdeModulePkg/Core/Pei: Use assembly for X64 TemporaryRamMigration
Date: Sun, 17 Feb 2019 20:11:39 -0800	[thread overview]
Message-ID: <20190218041141.21363-9-jordan.l.justen@intel.com> (raw)
In-Reply-To: <20190218041141.21363-1-jordan.l.justen@intel.com>

Some compilers may optimize register usage in ways that are
incompatible with the TemporaryRamSupport PPI. Using assembly code to
call the TemporaryRamMigration function prevents this issue.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 .../Dispatcher/X64/TemporaryRamMigration.S    | 69 +++++++++++++++++
 .../Dispatcher/X64/TemporaryRamMigration.nasm | 75 +++++++++++++++++++
 MdeModulePkg/Core/Pei/PeiMain.inf             | 14 +++-
 3 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.S
 create mode 100644 MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.nasm

diff --git a/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.S b/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.S
new file mode 100644
index 0000000000..cd9d902224
--- /dev/null
+++ b/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.S
@@ -0,0 +1,69 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials are licensed and made
+# available under the terms and conditions of the BSD License which
+# accompanies this distribution. The full text of the license may be
+# found at http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
+# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED.
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# PeiTemporaryRamMigration (
+#   IN  PEI_CORE_TEMPORARY_RAM_TRANSITION  *TempRamTransitionData
+#   );
+#
+# @param[in]  RCX   Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+#
+# @return     None  This routine does not return
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(PeiTemporaryRamMigration)
+ASM_PFX(PeiTemporaryRamMigration):
+
+    #
+    # We never return from this call
+    #
+    add     $8, %rsp
+
+    #
+    #   (rax) Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+    #
+    mov     %rcx, %rax
+
+    #
+    # We'll store the new location of TempRamTransitionData after
+    # migration in rbx. By the X64 calling convention we should
+    # normally save rbx, but we won't be returning to the caller, so
+    # we don't need to save it. By the same rule, the
+    # TemporaryRamMigration PPI call should preserve rbx for us.
+    #
+    mov     %rcx, %rbx
+    add     0x18(%rax), %rbx
+    sub     0x10(%rax), %rbx
+
+    #
+    # Setup parameters and call TemporaryRamSupport->TemporaryRamMigration
+    #   (rcx) PeiServices
+    #   (rdx) TemporaryMemoryBase
+    #   (r8)  PermanentMemoryBase
+    #   (r9)  CopySize
+    #
+    mov     0x08(%rax), %rcx
+    mov     0x10(%rax), %rdx
+    mov     0x18(%rax), %r8
+    mov     0x20(%rax), %r9
+    callq   *(%rax)
+
+    #
+    # Setup parameters and call PeiTemporaryRamMigrated
+    #   (rcx) Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+    #
+    mov     %rbx, %rcx
+    call    ASM_PFX(PeiTemporaryRamMigrated)
diff --git a/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.nasm b/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.nasm
new file mode 100644
index 0000000000..2783b0f403
--- /dev/null
+++ b/MdeModulePkg/Core/Pei/Dispatcher/X64/TemporaryRamMigration.nasm
@@ -0,0 +1,75 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+;
+; This program and the accompanying materials are licensed and made
+; available under the terms and conditions of the BSD License which
+; accompanies this distribution. The full text of the license may be
+; found at http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
+; BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
+; EXPRESS OR IMPLIED.
+;
+;------------------------------------------------------------------------------
+
+#include <Base.h>
+
+    SECTION .text
+
+extern ASM_PFX(PeiTemporaryRamMigrated)
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; PeiTemporaryRamMigration (
+;   IN  PEI_CORE_TEMPORARY_RAM_TRANSITION  *TempRamTransitionData
+;   );
+;
+; @param[in]  RCX   Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+;
+; @return     None  This routine does not return
+;------------------------------------------------------------------------------
+global ASM_PFX(PeiTemporaryRamMigration)
+ASM_PFX(PeiTemporaryRamMigration):
+
+    ;
+    ; We never return from this call
+    ;
+    add     rsp, 8
+
+    ;
+    ;   (rax) Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+    ;
+    mov     rax, rcx
+
+    ;
+    ; We'll store the new location of TempRamTransitionData after
+    ; migration in rbx. By the X64 calling convention we should
+    ; normally save rbx, but we won't be returning to the caller, so
+    ; we don't need to save it. By the same rule, the
+    ; TemporaryRamMigration PPI call should preserve rbx for us.
+    ;
+    mov     rbx, rcx
+    add     rbx, [rax + 0x18]
+    sub     rbx, [rax + 0x10]
+
+    ;
+    ; Setup parameters and call TemporaryRamSupport->TemporaryRamMigration
+    ;   (rcx) PeiServices
+    ;   (rdx) TemporaryMemoryBase
+    ;   (r8)  PermanentMemoryBase
+    ;   (r9)  CopySize
+    ;
+    mov     rcx, [rax + 0x08]
+    mov     rdx, [rax + 0x10]
+    mov     r8, [rax + 0x18]
+    mov     r9, [rax + 0x20]
+    call    [rax + 0x00]
+
+    ;
+    ; Setup parameters and call PeiTemporaryRamMigrated
+    ;   (rcx) Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+    ;
+    mov     rcx, rbx
+    call    ASM_PFX(PeiTemporaryRamMigrated)
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf
index 94b26b3572..1646f73385 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -45,7 +45,6 @@
   FwVol/FwVol.c
   FwVol/FwVol.h
   Dispatcher/Dispatcher.c
-  Dispatcher/TemporaryRamMigration.c
   Dependency/Dependency.c
   Dependency/Dependency.h
   BootMode/BootMode.c
@@ -53,6 +52,19 @@
   PciCfg2/PciCfg2.c
   PeiMain.h
 
+[Sources.Ia32]
+  Dispatcher/TemporaryRamMigration.c
+
+[Sources.X64]
+  Dispatcher/X64/TemporaryRamMigration.nasm
+  Dispatcher/X64/TemporaryRamMigration.S
+
+[Sources.ARM]
+  Dispatcher/TemporaryRamMigration.c
+
+[Sources.AARCH64]
+  Dispatcher/TemporaryRamMigration.c
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
-- 
2.20.0.rc1



  parent reply	other threads:[~2019-02-18  4:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-18  4:11 [PATCH 00/10] Fix PEI Core issue during TemporaryRamMigration Jordan Justen
2019-02-18  4:11 ` [PATCH 01/10] EmulatorPkg/build.sh: Fix missing usage of -b BUILDTARGET parameter Jordan Justen
2019-02-18  4:11 ` [PATCH 02/10] EmulatorPkg/Unix/Host: Use PcdInitValueInTempStack to init temp-ram Jordan Justen
2019-02-18  4:11 ` [PATCH 03/10] EmulatorPkg/Sec: Replace assembly temp-ram support with C code Jordan Justen
2019-02-18  4:11 ` [PATCH 04/10] EmulatorPkg/Sec: Disable optimizations for TemporaryRamMigration function Jordan Justen
2019-02-18  4:11 ` [PATCH 05/10] OvmfPkg/Sec: Swap TemporaryRam Stack and Heap locations Jordan Justen
2019-02-18 12:58   ` Laszlo Ersek
2019-02-18  4:11 ` [PATCH 06/10] OvmfPkg/Sec: Disable optimizations for TemporaryRamMigration Jordan Justen
2019-02-18  7:53   ` Ard Biesheuvel
2019-02-18  9:08     ` Jordan Justen
2019-02-18  9:32       ` Ard Biesheuvel
2019-02-18 13:01         ` Laszlo Ersek
2019-02-19 22:50         ` Brian J. Johnson
2019-02-19 23:58           ` Jordan Justen
2019-02-20  8:52         ` Jordan Justen
2019-02-20  8:59           ` Ard Biesheuvel
2019-02-18  4:11 ` [PATCH 07/10] MdeModePkg/Core/Pei: Add code path to allow assembly temp-ram migration Jordan Justen
2019-02-18  4:11 ` Jordan Justen [this message]
2019-02-18  4:11 ` [PATCH 09/10] MdeModulePkg/Core/Pei: Use assembly for IA32 TemporaryRamMigration Jordan Justen
2019-02-18  4:11 ` [PATCH 10/10] OvmfPkg/Sec: Fill Temp Ram after TemporaryRamMigration Jordan Justen
2019-02-18 13:15   ` Laszlo Ersek
2019-02-19  2:46 ` [PATCH 00/10] Fix PEI Core issue during TemporaryRamMigration Ni, Ray
2019-02-19 13:25   ` Gao, Liming
2019-02-20 13:27     ` Ni, Ray
2019-02-20 17:43       ` Jordan Justen
2019-02-21  0:15         ` Ni, Ray
2019-02-21  1:03           ` Jordan Justen
2019-02-21  4:43             ` Ni, Ray
2019-02-19 19:27   ` Jordan Justen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190218041141.21363-9-jordan.l.justen@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox