3 ; This code provides low level routines that support the Virtual Machine.
6 ; Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
7 ; Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR>
8 ; SPDX-License-Identifier: BSD-2-Clause-Patent
12 ;---------------------------------------------------------------------------
13 ; Equate files needed.
14 ;---------------------------------------------------------------------------
19 extern ASM_PFX(CopyMem)
20 extern ASM_PFX(EbcInterpret)
21 extern ASM_PFX(ExecuteEbcImageEntryPoint)
23 ;****************************************************************************
26 ; This function is called to execute an EBC CALLEX instruction.
27 ; This instruction requires that we thunk out to external native
28 ; code. For x64, we switch stacks, copy the arguments to the stack
29 ; and jump to the specified function.
30 ; On return, we restore the stack pointer to its original location.
32 ; Destroys no working registers.
33 ;****************************************************************************
34 ; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
35 global ASM_PFX(EbcLLCALLEXNative)
36 ASM_PFX(EbcLLCALLEXNative):
42 ; Copy FuncAddr to a preserved register.
45 ; Set stack pointer to new value
49 ; Fix X64 native function call prolog. Prepare space for at least 4 arguments,
50 ; even if the native function's arguments are less than 4.
52 ; From MSDN x64 Software Conventions, Overview of x64 Calling Conventions:
53 ; "The caller is responsible for allocating space for parameters to the
54 ; callee, and must always allocate sufficient space for the 4 register
55 ; parameters, even if the callee doesn't have that many parameters.
56 ; This aids in the simplicity of supporting C unprototyped functions,
57 ; and vararg C/C++ functions."
67 ; Fix X64 native function call 16-byte alignment.
69 ; From MSDN x64 Software Conventions, Stack Usage:
70 ; "The stack will always be maintained 16-byte aligned, except within
71 ; the prolog (for example, after the return address is pushed)."
80 ; Considering the worst case, load 4 potiential arguments
83 mov rdx, qword [rsp+0x8]
84 mov r8, qword [rsp+0x10]
85 mov r9, qword [rsp+0x18]
87 ; Now call the external routine
96 ;****************************************************************************
99 ; Begin executing an EBC image.
100 ;****************************************************************************
101 ; UINT64 EbcLLEbcInterpret(VOID)
102 global ASM_PFX(EbcLLEbcInterpret)
103 ASM_PFX(EbcLLEbcInterpret):
105 ;; mov rax, ca112ebccall2ebch
106 ;; mov r10, EbcEntryPoint
107 ;; mov r11, EbcLLEbcInterpret
110 ; Caller uses above instruction to jump here
111 ; The stack is below:
115 ; |EntryPoint | (R10)
133 ; | RetAddr | <- RSP is here
135 ; | Scratch1 | (RCX) <- RSI
153 ; save old parameter to stack
155 mov [rsp + 0x10], rdx
159 ; Construct new stack
174 ; build new paramater calling convention
181 call ASM_PFX(EbcInterpret)
189 ;****************************************************************************
190 ; EbcLLExecuteEbcImageEntryPoint
192 ; Begin executing an EBC image.
193 ;****************************************************************************
194 ; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)
195 global ASM_PFX(EbcLLExecuteEbcImageEntryPoint)
196 ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
198 ;; mov rax, ca112ebccall2ebch
199 ;; mov r10, EbcEntryPoint
200 ;; mov r11, EbcLLExecuteEbcImageEntryPoint
203 ; Caller uses above instruction to jump here
204 ; The stack is below:
208 ; |EntryPoint | (R10)
218 ; | RetAddr | <- RSP is here
220 ; |ImageHandle| (RCX)
222 ; |SystemTable| (RDX)
226 ; build new paramater calling convention
233 call ASM_PFX(ExecuteEbcImageEntryPoint)