3 # This code provides low level routines that support the Virtual Machine
6 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #---------------------------------------------------------------------------
18 # Equate files needed.
19 #---------------------------------------------------------------------------
21 ASM_GLOBAL ASM_PFX(CopyMem);
22 ASM_GLOBAL ASM_PFX(EbcInterpret);
23 ASM_GLOBAL ASM_PFX(ExecuteEbcImageEntryPoint);
25 #****************************************************************************
28 # This function is called to execute an EBC CALLEX instruction.
29 # This instruction requires that we thunk out to external native
30 # code. For x64, we switch stacks, copy the arguments to the stack
31 # and jump to the specified function.
32 # On return, we restore the stack pointer to its original location.
34 # Destroys no working registers.
35 #****************************************************************************
36 # VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
37 ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative);
38 ASM_PFX(EbcLLCALLEXNative):
44 # Copy FuncAddr to a preserved register.
47 # Set stack pointer to new value
51 # Fix X64 native function call prolog. Prepare space for at least 4 arguments,
52 # even if the native function's arguments are less than 4.
54 # From MSDN x64 Software Conventions, Overview of x64 Calling Conventions:
55 # "The caller is responsible for allocating space for parameters to the
56 # callee, and must always allocate sufficient space for the 4 register
57 # parameters, even if the callee doesn't have that many parameters.
58 # This aids in the simplicity of supporting C unprototyped functions,
59 # and vararg C/C++ functions."
69 # Fix X64 native function call 16-byte alignment.
71 # From MSDN x64 Software Conventions, Stack Usage:
72 # "The stack will always be maintained 16-byte aligned, except within
73 # the prolog (for example, after the return address is pushed)."
75 and $0xFFFFFFFFFFFFFFF0, %rsp
82 # Considering the worst case, load 4 potiential arguments
89 # Now call the external routine
98 ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret);
99 ASM_PFX(EbcLLEbcInterpret):
100 # save old parameter to stack
106 # Construct new stack
121 # build new paramater calling convention
128 call ASM_PFX(EbcInterpret)
136 ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint);
137 ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
138 # build new paramater calling convention
145 call ASM_PFX(ExecuteEbcImageEntryPoint)