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 ; This program and the accompanying materials
9 ; are licensed and made available under the terms and conditions of the BSD License
10 ; which accompanies this distribution. The full text of the license may be found at
11 ; http://opensource.org/licenses/bsd-license.php
13 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 title VM ASSEMBLY LANGUAGE ROUTINES
21 ;---------------------------------------------------------------------------
22 ; Equate files needed.
23 ;---------------------------------------------------------------------------
27 CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
29 ExecuteEbcImageEntryPoint PROTO
31 ;****************************************************************************
34 ; This function is called to execute an EBC CALLEX instruction.
35 ; This instruction requires that we thunk out to external native
36 ; code. For x64, we switch stacks, copy the arguments to the stack
37 ; and jump to the specified function.
38 ; On return, we restore the stack pointer to its original location.
40 ; Destroys no working registers.
41 ;****************************************************************************
42 ; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
43 EbcLLCALLEXNative PROC PUBLIC
49 ; Copy FuncAddr to a preserved register.
52 ; Set stack pointer to new value
56 ; Fix X64 native function call prolog. Prepare space for at least 4 arguments,
57 ; even if the native function's arguments are less than 4.
59 ; From MSDN x64 Software Conventions, Overview of x64 Calling Conventions:
60 ; "The caller is responsible for allocating space for parameters to the
61 ; callee, and must always allocate sufficient space for the 4 register
62 ; parameters, even if the callee doesn't have that many parameters.
63 ; This aids in the simplicity of supporting C unprototyped functions,
64 ; and vararg C/C++ functions."
74 ; Fix X64 native function call 16-byte alignment.
76 ; From MSDN x64 Software Conventions, Stack Usage:
77 ; "The stack will always be maintained 16-byte aligned, except within
78 ; the prolog (for example, after the return address is pushed)."
87 ; Considering the worst case, load 4 potiential arguments
89 mov rcx, qword ptr [rsp]
90 mov rdx, qword ptr [rsp+8h]
91 mov r8, qword ptr [rsp+10h]
92 mov r9, qword ptr [rsp+18h]
94 ; Now call the external routine
102 EbcLLCALLEXNative ENDP
104 ;****************************************************************************
107 ; Begin executing an EBC image.
108 ;****************************************************************************
109 ; UINT64 EbcLLEbcInterpret(VOID)
110 EbcLLEbcInterpret PROC PUBLIC
112 ;; mov rax, ca112ebccall2ebch
113 ;; mov r10, EbcEntryPoint
114 ;; mov r11, EbcLLEbcInterpret
117 ; Caller uses above instruction to jump here
118 ; The stack is below:
122 ; |EntryPoint | (R10)
140 ; | RetAddr | <- RSP is here
142 ; | Scratch1 | (RCX) <- RSI
160 ; save old parameter to stack
166 ; Construct new stack
181 ; build new paramater calling convention
195 EbcLLEbcInterpret ENDP
197 ;****************************************************************************
198 ; EbcLLExecuteEbcImageEntryPoint
200 ; Begin executing an EBC image.
201 ;****************************************************************************
202 ; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)
203 EbcLLExecuteEbcImageEntryPoint PROC PUBLIC
205 ;; mov rax, ca112ebccall2ebch
206 ;; mov r10, EbcEntryPoint
207 ;; mov r11, EbcLLExecuteEbcImageEntryPoint
210 ; Caller uses above instruction to jump here
211 ; The stack is below:
215 ; |EntryPoint | (R10)
225 ; | RetAddr | <- RSP is here
227 ; |ImageHandle| (RCX)
229 ; |SystemTable| (RDX)
233 ; build new paramater calling convention
240 call ExecuteEbcImageEntryPoint
243 EbcLLExecuteEbcImageEntryPoint ENDP