2 title VM ASSEMBLY LANGUAGE ROUTINES
3 ;****************************************************************************
5 ;* Copyright (c) 2006, Intel Corporation
6 ;* All rights reserved. This program and the accompanying materials
7 ;* are licensed and made available under the terms and conditions of the BSD License
8 ;* which accompanies this distribution. The full text of the license may be found at
9 ;* http://opensource.org/licenses/bsd-license.php
11 ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 ;****************************************************************************
15 ;****************************************************************************
17 ;****************************************************************************
19 ; Rev Date Description
20 ; --- -------- ------------------------------------------------------------
21 ; 1.0 05/09/12 Initial creation of file.
23 ;****************************************************************************
25 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26 ; This code provides low level routines that support the Virtual Machine
28 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30 ;---------------------------------------------------------------------------
31 ; Equate files needed.
32 ;---------------------------------------------------------------------------
36 ;---------------------------------------------------------------------------
37 ;;GenericPostSegment SEGMENT USE16
38 ;---------------------------------------------------------------------------
40 ;****************************************************************************
43 ; This function is called to execute an EBC CALLEX instruction.
44 ; This instruction requires that we thunk out to external native
45 ; code. For x64, we switch stacks, copy the arguments to the stack
46 ; and jump to the specified function.
47 ; On return, we restore the stack pointer to its original location.
49 ; Destroys no working registers.
50 ;****************************************************************************
51 ; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
53 CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
56 EbcLLCALLEXNative PROC NEAR PUBLIC
62 ; Copy FuncAddr to a preserved register.
65 ; Set stack pointer to new value
73 ; Considering the worst case, load 4 potiential arguments
75 mov rcx, qword ptr [rsp]
76 mov rdx, qword ptr [rsp+8h]
77 mov r8, qword ptr [rsp+10h]
78 mov r9, qword ptr [rsp+18h]
80 ; Now call the external routine
88 EbcLLCALLEXNative ENDP
91 ; UINTN EbcLLGetEbcEntryPoint(VOID);
92 ; Routine Description:
93 ; The VM thunk code stuffs an EBC entry point into a processor
94 ; register. Since we can't use inline assembly to get it from
95 ; the interpreter C code, stuff it into the return value
96 ; register and return.
102 ; The contents of the register in which the entry point is passed.
104 EbcLLGetEbcEntryPoint PROC NEAR PUBLIC
106 EbcLLGetEbcEntryPoint ENDP
110 ;Routine Description:
112 ; Return the caller's value of the stack pointer.
120 ; The current value of the stack pointer for the caller. We
121 ; adjust it by 4 here because when they called us, the return address
122 ; is put on the stack, thereby lowering it by 4 bytes.
126 ; UINTN EbcLLGetStackPointer()
127 EbcLLGetStackPointer PROC NEAR PUBLIC
128 mov rax, rsp ; get current stack pointer
129 ; Stack adjusted by this much when we were called,
130 ; For this function, it's 4.
133 EbcLLGetStackPointer ENDP
135 ; UINT64 EbcLLGetReturnValue(VOID);
136 ; Routine Description:
137 ; When EBC calls native, on return the VM has to stuff the return
138 ; value into a VM register. It's assumed here that the value is still
139 ; in the register, so simply return and the caller should get the
140 ; return result properly.
146 ; The unmodified value returned by the native code.
148 EbcLLGetReturnValue PROC NEAR PUBLIC
150 EbcLLGetReturnValue ENDP