From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (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 79B951A1E00 for ; Fri, 26 Aug 2016 05:56:44 -0700 (PDT) Received: by mail-wm0-x231.google.com with SMTP id f65so277345814wmi.0 for ; Fri, 26 Aug 2016 05:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=frulYaqcJa6GOYAsouDWkY5ShWoe+VviobvZw+jpZ+4=; b=NMQrbxg1rtB6An+LaJ4agfZSmEnYLKch0omeVhvk0hkuQXmslnyb4i0LclCqV+eVjy 9aM+duuFnMflYFavA/vb09ggM/YnCPycUZFxuDjhRYrn4+MPOmxPfGDK9Qh/bGBlh5rI ipsBtCAzWc2GS+cQI+Dize3Ij4bprXcKkKU9o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=frulYaqcJa6GOYAsouDWkY5ShWoe+VviobvZw+jpZ+4=; b=bP+RCtPhGQwVB8nTNC7GVj2USTqoJaq3fWMUhtOTa3P6qXBdBsaL0uCBuJvAghmNtz x6oDGsy4uRmgBVE/+MMJuzopjUUKhR9g+4LRy5y2PzC+diAHByARJyko63joVxq6Ujxv yG5BCH2860XjiHNWBTbFcRFqtN4/jLCzJVsAf+4IiAgIGVtKIyBgXNlpNF8PDkNKE90q qJs5BmT1/7h6CUK51ZGgQEbU8zjBmVdRbnjYb3CMrX74OnEAt0FTUVjuXmkbGrBX7zh0 CAnot9UWY0cZaWOl9Doe6GFuLuNjFN2Q6akY2Y0joIoiMVTnKDbtkpycOPT1zkUuwGLs M30w== X-Gm-Message-State: AE9vXwNWdQKWbjw+LdwQujvoj8jDxCjcHm24RDNJ5ku55m/Yh4NGg5gvJtqA6jMZHRcUIntD X-Received: by 10.194.77.174 with SMTP id t14mr4154939wjw.146.1472216202883; Fri, 26 Aug 2016 05:56:42 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id m81sm43597719wmf.1.2016.08.26.05.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Aug 2016 05:56:42 -0700 (PDT) Date: Fri, 26 Aug 2016 13:56:40 +0100 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, jbrasen@codeaurora.org, feng.tian@intel.com, star.zeng@intel.com, daniil.egranov@arm.com Message-ID: <20160826125640.GG4715@bivouac.eciton.net> References: <1471445945-19239-1-git-send-email-ard.biesheuvel@linaro.org> <1471445945-19239-5-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1471445945-19239-5-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH v3 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: , X-List-Received-Date: Fri, 26 Aug 2016 12:56:45 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Aug 17, 2016 at 04:59:05PM +0200, Ard Biesheuvel wrote: > 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 clue 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 > --- > MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S | 57 +++++--------------- > MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c | 44 ++++++--------- > 2 files changed, 27 insertions(+), 74 deletions(-) > > diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > index d95713e82b0f..f90cd711ec90 100644 > --- a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > @@ -107,45 +107,18 @@ ASM_PFX(EbcLLCALLEXNative): > // > //**************************************************************************** > 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 > > //**************************************************************************** > @@ -157,16 +130,10 @@ ASM_PFX(EbcLLEbcInterpret): > // > //**************************************************************************** > ASM_PFX(EbcLLExecuteEbcImageEntryPoint): > - stp x29, x30, [sp, #-16]! > - // build new paramater 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..f059b0e7e102 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,7 +106,6 @@ PushU64 ( > UINT64 > EFIAPI > EbcInterpret ( > - IN UINTN EntryPoint, > IN UINTN Arg1, > IN UINTN Arg2, > IN UINTN Arg3, > @@ -122,14 +114,8 @@ EbcInterpret ( > 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 EntryPoint, > + IN 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 > ) > { > // > -- > 2.7.4 Neat! Reviewed-by: Leif Lindholm