MdeModulePkg/EbcDxe AARCH64: simplify interpreter entry point thunks

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 <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Feng Tian <feng.tian@intel.com>
This commit is contained in:
Ard Biesheuvel 2016-08-17 16:36:42 +02:00
parent 3226e315d2
commit 4a2aaff2fc
2 changed files with 35 additions and 82 deletions

View File

@ -110,50 +110,23 @@ ASM_PFX(EbcLLCALLEXNative):
// //
// This function is called by the thunk code to handle an Native to EBC call // 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) // 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. // EBCInterpret is called.
// //
//**************************************************************************** //****************************************************************************
ASM_PFX(EbcLLEbcInterpret): ASM_PFX(EbcLLEbcInterpret):
stp x29, x30, [sp, #-16]! stp x29, x30, [sp, #-16]!
mov x29, sp
// copy the current arguments 9-16 from old location and add arg 7 to stack // push the entry point and the address of args #9 - #16 onto the stack
// keeping 16 byte stack alignment add x17, sp, #16
sub sp, sp, #80 stp x16, x17, [sp, #-16]!
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
// call C-code // call C-code
bl ASM_PFX(EbcInterpret) bl ASM_PFX(EbcInterpret)
add sp, sp, #80
ldp x29, x30, [sp], #16
add sp, sp, #16
ldp x29, x30, [sp], #16
ret ret
//**************************************************************************** //****************************************************************************
@ -165,16 +138,10 @@ ASM_PFX(EbcLLEbcInterpret):
// //
//**************************************************************************** //****************************************************************************
ASM_PFX(EbcLLExecuteEbcImageEntryPoint): ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
stp x29, x30, [sp, #-16]! mov x2, x16
// build new parameter calling convention
mov x2, x1
mov x1, x0
mov x0, x16
// call C-code // tail call to C code
bl ASM_PFX(ExecuteEbcImageEntryPoint) b ASM_PFX(ExecuteEbcImageEntryPoint)
ldp x29, x30, [sp], #16
ret
//**************************************************************************** //****************************************************************************
// mEbcInstructionBufferTemplate // mEbcInstructionBufferTemplate

View File

@ -89,7 +89,6 @@ PushU64 (
This is a thunk function. This is a thunk function.
@param EntryPoint The entrypoint of EBC code.
@param Arg1 The 1st argument. @param Arg1 The 1st argument.
@param Arg2 The 2nd argument. @param Arg2 The 2nd argument.
@param Arg3 The 3rd argument. @param Arg3 The 3rd argument.
@ -98,14 +97,8 @@ PushU64 (
@param Arg6 The 6th argument. @param Arg6 The 6th argument.
@param Arg7 The 7th argument. @param Arg7 The 7th argument.
@param Arg8 The 8th argument. @param Arg8 The 8th argument.
@param Arg9 The 9th argument. @param EntryPoint The entrypoint of EBC code.
@param Arg10 The 10th argument. @param Args9_16[] Array containing arguments #9 to #16.
@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.
@return The value returned by the EBC application we're going to run. @return The value returned by the EBC application we're going to run.
@ -113,23 +106,16 @@ PushU64 (
UINT64 UINT64
EFIAPI EFIAPI
EbcInterpret ( EbcInterpret (
IN UINTN EntryPoint, IN UINTN Arg1,
IN UINTN Arg1, IN UINTN Arg2,
IN UINTN Arg2, IN UINTN Arg3,
IN UINTN Arg3, IN UINTN Arg4,
IN UINTN Arg4, IN UINTN Arg5,
IN UINTN Arg5, IN UINTN Arg6,
IN UINTN Arg6, IN UINTN Arg7,
IN UINTN Arg7, IN UINTN Arg8,
IN UINTN Arg8, IN UINTN EntryPoint,
IN UINTN Arg9, IN CONST UINTN Args9_16[]
IN UINTN Arg10,
IN UINTN Arg11,
IN UINTN Arg12,
IN UINTN Arg13,
IN UINTN Arg14,
IN UINTN Arg15,
IN UINTN Arg16
) )
{ {
// //
@ -193,14 +179,14 @@ EbcInterpret (
// For the worst case, assume there are 4 arguments passed in registers, store // For the worst case, assume there are 4 arguments passed in registers, store
// them to VM's stack. // them to VM's stack.
// //
PushU64 (&VmContext, (UINT64) Arg16); PushU64 (&VmContext, (UINT64) Args9_16[7]);
PushU64 (&VmContext, (UINT64) Arg15); PushU64 (&VmContext, (UINT64) Args9_16[6]);
PushU64 (&VmContext, (UINT64) Arg14); PushU64 (&VmContext, (UINT64) Args9_16[5]);
PushU64 (&VmContext, (UINT64) Arg13); PushU64 (&VmContext, (UINT64) Args9_16[4]);
PushU64 (&VmContext, (UINT64) Arg12); PushU64 (&VmContext, (UINT64) Args9_16[3]);
PushU64 (&VmContext, (UINT64) Arg11); PushU64 (&VmContext, (UINT64) Args9_16[2]);
PushU64 (&VmContext, (UINT64) Arg10); PushU64 (&VmContext, (UINT64) Args9_16[1]);
PushU64 (&VmContext, (UINT64) Arg9); PushU64 (&VmContext, (UINT64) Args9_16[0]);
PushU64 (&VmContext, (UINT64) Arg8); PushU64 (&VmContext, (UINT64) Arg8);
PushU64 (&VmContext, (UINT64) Arg7); PushU64 (&VmContext, (UINT64) Arg7);
PushU64 (&VmContext, (UINT64) Arg6); PushU64 (&VmContext, (UINT64) Arg6);
@ -252,10 +238,10 @@ EbcInterpret (
/** /**
Begin executing an EBC image. Begin executing an EBC image.
@param EntryPoint The entrypoint of EBC code.
@param ImageHandle image handle for the EBC application we're executing @param ImageHandle image handle for the EBC application we're executing
@param SystemTable standard system table passed into an driver's entry @param SystemTable standard system table passed into an driver's entry
point point
@param EntryPoint The entrypoint of EBC code.
@return The value returned by the EBC application we're going to run. @return The value returned by the EBC application we're going to run.
@ -263,9 +249,9 @@ EbcInterpret (
UINT64 UINT64
EFIAPI EFIAPI
ExecuteEbcImageEntryPoint ( ExecuteEbcImageEntryPoint (
IN UINTN EntryPoint,
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable,
IN UINTN EntryPoint
) )
{ {
// //