3 ; This code provides low level routines that support the Virtual Machine.
6 ; Copyright (c) 2006 - 2008, Intel Corporation. <BR>
7 ; All rights reserved. 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.
18 title VM ASSEMBLY LANGUAGE ROUTINES
20 ;---------------------------------------------------------------------------
21 ; Equate files needed.
22 ;---------------------------------------------------------------------------
26 ;---------------------------------------------------------------------------
27 ;;GenericPostSegment SEGMENT USE16
28 ;---------------------------------------------------------------------------
30 ;****************************************************************************
33 ; This function is called to execute an EBC CALLEX instruction.
34 ; This instruction requires that we thunk out to external native
35 ; code. For x64, we switch stacks, copy the arguments to the stack
36 ; and jump to the specified function.
37 ; On return, we restore the stack pointer to its original location.
39 ; Destroys no working registers.
40 ;****************************************************************************
41 ; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
43 CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
46 EbcLLCALLEXNative PROC PUBLIC
52 ; Copy FuncAddr to a preserved register.
55 ; Set stack pointer to new value
63 ; Considering the worst case, load 4 potiential arguments
65 mov rcx, qword ptr [rsp]
66 mov rdx, qword ptr [rsp+8h]
67 mov r8, qword ptr [rsp+10h]
68 mov r9, qword ptr [rsp+18h]
70 ; Now call the external routine
78 EbcLLCALLEXNative ENDP
81 ; UINTN EbcLLGetEbcEntryPoint(VOID);
82 ; Routine Description:
83 ; The VM thunk code stuffs an EBC entry point into a processor
84 ; register. Since we can't use inline assembly to get it from
85 ; the interpreter C code, stuff it into the return value
86 ; register and return.
92 ; The contents of the register in which the entry point is passed.
94 EbcLLGetEbcEntryPoint PROC PUBLIC
97 EbcLLGetEbcEntryPoint ENDP
101 ;Routine Description:
103 ; Return the caller's value of the stack pointer.
111 ; The current value of the stack pointer for the caller. We
112 ; adjust it by 4 here because when they called us, the return address
113 ; is put on the stack, thereby lowering it by 4 bytes.
117 ; UINTN EbcLLGetStackPointer()
118 EbcLLGetStackPointer PROC PUBLIC
119 mov rax, rsp ; get current stack pointer
120 ; Stack adjusted by this much when we were called,
121 ; For this function, it's 4.
124 EbcLLGetStackPointer ENDP
126 ; UINT64 EbcLLGetReturnValue(VOID);
127 ; Routine Description:
128 ; When EBC calls native, on return the VM has to stuff the return
129 ; value into a VM register. It's assumed here that the value is still
130 ; in the register, so simply return and the caller should get the
131 ; return result properly.
137 ; The unmodified value returned by the native code.
139 EbcLLGetReturnValue PROC PUBLIC
141 EbcLLGetReturnValue ENDP