From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jordan.l.justen@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 821E72194EB7D for ; Sun, 17 Feb 2019 20:12:01 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Feb 2019 20:12:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,383,1544515200"; d="scan'208";a="321197990" Received: from mmdandap-mobl1.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.254.8.66]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2019 20:12:00 -0800 From: Jordan Justen To: edk2-devel@lists.01.org Cc: Jordan Justen , Jian J Wang , Hao Wu , Ray Ni , Star Zeng Date: Sun, 17 Feb 2019 20:11:39 -0800 Message-Id: <20190218041141.21363-9-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20190218041141.21363-1-jordan.l.justen@intel.com> References: <20190218041141.21363-1-jordan.l.justen@intel.com> MIME-Version: 1.0 Subject: [PATCH 08/10] MdeModulePkg/Core/Pei: Use assembly for X64 TemporaryRamMigration X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Feb 2019 04:12:01 -0000 Content-Transfer-Encoding: 8bit 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 Cc: Jian J Wang Cc: Hao Wu Cc: Ray Ni Cc: Star Zeng --- .../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.
+# +# 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.
+; +; 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 + + 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