From patchwork Tue Aug 30 14:27:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 74992 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2178525qga; Tue, 30 Aug 2016 07:27:48 -0700 (PDT) X-Received: by 10.98.73.131 with SMTP id r3mr6756038pfi.112.1472567264619; Tue, 30 Aug 2016 07:27:44 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id z25si45480772pff.143.2016.08.30.07.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Aug 2016 07:27:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 885F61A1E36; Tue, 30 Aug 2016 07:27:41 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F2EAD1A1E2F for ; Tue, 30 Aug 2016 07:27:39 -0700 (PDT) Received: by mail-wm0-x22d.google.com with SMTP id i5so39167854wmg.0 for ; Tue, 30 Aug 2016 07:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CN/1c5IXSpwvN+2Nc5tA09BYpkiOdEEYdo0eK03Pdv8=; b=DkpH1XqkoiK+nqMjvFBldk2ecytrh8eIn7rRDM9RZxker50Sh57mLt+inypcsjCi1r iAho8WCjqw8wk2hF3AGPBAYXnRw/Tbo7sIyAmYySovRK5wuo4FcevPKqSGBKM6DaFJwL SeO0r2Gv3XEv7pktF13P8kAtIWfpThPkbVMSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CN/1c5IXSpwvN+2Nc5tA09BYpkiOdEEYdo0eK03Pdv8=; b=GYk9g8tWHnivEiedFH7N/bu8THnX1J/DVHx6V3j1YOqgi1KIF52RuJt+nqvxBP95Wl g/EtdNu8Y1cPjWjVHnqhh6ci/KhLfbt6FyaTqJ7nvyULSDz7OSDDFnB9qBkuTuFJREut nz+fFBlabYBIrRSLq9R1e2CSEAsE5TfOUXzXYmjnmoGMJ55ws8SKjoMtAB0jQdHydHHK kFIL/PV9mPiOQ4dOJ1qIMDKmkOLJ65WQ7ospaQArRze8YE+YrYkXE9pjZZvCtzcOn0Vi w54iw06s9F+rDUipr5kstzJBY3nLfBShoga8INXN/Uvll05v2G99EeIxQ3dA9WNl4qWf ZfDQ== X-Gm-Message-State: AE9vXwO9Vko6WCNLH0WWhJw9BiPQDUR4ARZAFalDy0Yba5F1Cd+kubPd/FJQcj2/1KpGutfI X-Received: by 10.28.62.204 with SMTP id l195mr15278930wma.117.1472567258506; Tue, 30 Aug 2016 07:27:38 -0700 (PDT) Received: from localhost.localdomain ([160.165.12.73]) by smtp.gmail.com with ESMTPSA id us9sm39773620wjb.43.2016.08.30.07.27.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Aug 2016 07:27:37 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Tue, 30 Aug 2016 15:27:24 +0100 Message-Id: <1472567244-32031-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472567244-32031-1-git-send-email-ard.biesheuvel@linaro.org> References: <1472567244-32031-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v4 4/4] MdeModulePkg/EbcDxe AARCH64: simplify interpreter entry point thunks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The prototypes of EbcInterpret() and ExecuteEbcImageEntryPoint() are private to the AARCH64 implementation of EbcDxe, so we can shuffle the arguments around a bit and make the assembler thunking glue a lot simpler. For ExecuteEbcImageEntryPoint(), this involves passing the EntryPoint argument as the third parameter, rather than the first, which allows us to do a tail call. For EbcInterpret(), instead of copying each argument beyond #8 from one native stack frame to the next (before another copy is made into the VM stack), pass a pointer to the argument stack. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S | 59 +++++-------------- MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c | 60 ++++++++------------ 2 files changed, 36 insertions(+), 83 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S index 34794c06a644..b1f09725ecf0 100644 --- a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S @@ -110,50 +110,23 @@ ASM_PFX(EbcLLCALLEXNative): // // This function is called by the thunk code to handle an Native to EBC call // This can handle up to 16 arguments (1-8 on in x0-x7, 9-16 are on the stack) -// x16 contains the Entry point that will be the first argument when +// x16 contains the Entry point that will be the first stacked argument when // EBCInterpret is called. // //**************************************************************************** ASM_PFX(EbcLLEbcInterpret): - stp x29, x30, [sp, #-16]! - - // copy the current arguments 9-16 from old location and add arg 7 to stack - // keeping 16 byte stack alignment - sub sp, sp, #80 - str x7, [sp] - ldr x11, [sp, #96] - str x11, [sp, #8] - ldr x11, [sp, #104] - str x11, [sp, #16] - ldr x11, [sp, #112] - str x11, [sp, #24] - ldr x11, [sp, #120] - str x11, [sp, #32] - ldr x11, [sp, #128] - str x11, [sp, #40] - ldr x11, [sp, #136] - str x11, [sp, #48] - ldr x11, [sp, #144] - str x11, [sp, #56] - ldr x11, [sp, #152] - str x11, [sp, #64] - - // Shift arguments and add entry point and as argument 1 - mov x7, x6 - mov x6, x5 - mov x5, x4 - mov x4, x3 - mov x3, x2 - mov x2, x1 - mov x1, x0 - mov x0, x16 + stp x29, x30, [sp, #-16]! + mov x29, sp - // call C-code - bl ASM_PFX(EbcInterpret) - add sp, sp, #80 + // push the entry point and the address of args #9 - #16 onto the stack + add x17, sp, #16 + stp x16, x17, [sp, #-16]! - ldp x29, x30, [sp], #16 + // call C-code + bl ASM_PFX(EbcInterpret) + add sp, sp, #16 + ldp x29, x30, [sp], #16 ret //**************************************************************************** @@ -165,16 +138,10 @@ ASM_PFX(EbcLLEbcInterpret): // //**************************************************************************** ASM_PFX(EbcLLExecuteEbcImageEntryPoint): - stp x29, x30, [sp, #-16]! - // build new parameter calling convention - mov x2, x1 - mov x1, x0 - mov x0, x16 + mov x2, x16 - // call C-code - bl ASM_PFX(ExecuteEbcImageEntryPoint) - ldp x29, x30, [sp], #16 - ret + // tail call to C code + b ASM_PFX(ExecuteEbcImageEntryPoint) //**************************************************************************** // mEbcInstructionBufferTemplate diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c index a5f21f400274..c5cc76d7bdcb 100644 --- a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c @@ -89,7 +89,6 @@ PushU64 ( This is a thunk function. - @param EntryPoint The entrypoint of EBC code. @param Arg1 The 1st argument. @param Arg2 The 2nd argument. @param Arg3 The 3rd argument. @@ -98,14 +97,8 @@ PushU64 ( @param Arg6 The 6th argument. @param Arg7 The 7th argument. @param Arg8 The 8th argument. - @param Arg9 The 9th argument. - @param Arg10 The 10th argument. - @param Arg11 The 11th argument. - @param Arg12 The 12th argument. - @param Arg13 The 13th argument. - @param Arg14 The 14th argument. - @param Arg15 The 15th argument. - @param Arg16 The 16th argument. + @param EntryPoint The entrypoint of EBC code. + @param Args9_16[] Array containing arguments #9 to #16. @return The value returned by the EBC application we're going to run. @@ -113,23 +106,16 @@ PushU64 ( UINT64 EFIAPI EbcInterpret ( - IN UINTN EntryPoint, - IN UINTN Arg1, - IN UINTN Arg2, - IN UINTN Arg3, - IN UINTN Arg4, - IN UINTN Arg5, - IN UINTN Arg6, - IN UINTN Arg7, - IN UINTN Arg8, - IN UINTN Arg9, - IN UINTN Arg10, - IN UINTN Arg11, - IN UINTN Arg12, - IN UINTN Arg13, - IN UINTN Arg14, - IN UINTN Arg15, - IN UINTN Arg16 + IN UINTN Arg1, + IN UINTN Arg2, + IN UINTN Arg3, + IN UINTN Arg4, + IN UINTN Arg5, + IN UINTN Arg6, + IN UINTN Arg7, + IN UINTN Arg8, + IN UINTN EntryPoint, + IN CONST UINTN Args9_16[] ) { // @@ -193,14 +179,14 @@ EbcInterpret ( // For the worst case, assume there are 4 arguments passed in registers, store // them to VM's stack. // - PushU64 (&VmContext, (UINT64) Arg16); - PushU64 (&VmContext, (UINT64) Arg15); - PushU64 (&VmContext, (UINT64) Arg14); - PushU64 (&VmContext, (UINT64) Arg13); - PushU64 (&VmContext, (UINT64) Arg12); - PushU64 (&VmContext, (UINT64) Arg11); - PushU64 (&VmContext, (UINT64) Arg10); - PushU64 (&VmContext, (UINT64) Arg9); + PushU64 (&VmContext, (UINT64) Args9_16[7]); + PushU64 (&VmContext, (UINT64) Args9_16[6]); + PushU64 (&VmContext, (UINT64) Args9_16[5]); + PushU64 (&VmContext, (UINT64) Args9_16[4]); + PushU64 (&VmContext, (UINT64) Args9_16[3]); + PushU64 (&VmContext, (UINT64) Args9_16[2]); + PushU64 (&VmContext, (UINT64) Args9_16[1]); + PushU64 (&VmContext, (UINT64) Args9_16[0]); PushU64 (&VmContext, (UINT64) Arg8); PushU64 (&VmContext, (UINT64) Arg7); PushU64 (&VmContext, (UINT64) Arg6); @@ -252,10 +238,10 @@ EbcInterpret ( /** Begin executing an EBC image. - @param EntryPoint The entrypoint of EBC code. @param ImageHandle image handle for the EBC application we're executing @param SystemTable standard system table passed into an driver's entry point + @param EntryPoint The entrypoint of EBC code. @return The value returned by the EBC application we're going to run. @@ -263,9 +249,9 @@ EbcInterpret ( UINT64 EFIAPI ExecuteEbcImageEntryPoint ( - IN UINTN EntryPoint, IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable + IN EFI_SYSTEM_TABLE *SystemTable, + IN UINTN EntryPoint ) { //