]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Ebc/Dxe/x64/EbcLowLevel.asm
Initial import.
[mirror_edk2.git] / EdkModulePkg / Universal / Ebc / Dxe / x64 / EbcLowLevel.asm
1 page ,132
2 title VM ASSEMBLY LANGUAGE ROUTINES
3 ;****************************************************************************
4 ;*
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
10 ;*
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.
13 ;*
14 ;****************************************************************************
15 ;****************************************************************************
16 ; REV 1.0
17 ;****************************************************************************
18 ;
19 ; Rev Date Description
20 ; --- -------- ------------------------------------------------------------
21 ; 1.0 05/09/12 Initial creation of file.
22 ;
23 ;****************************************************************************
24
25 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26 ; This code provides low level routines that support the Virtual Machine
27 ; for option ROMs.
28 ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29
30 ;---------------------------------------------------------------------------
31 ; Equate files needed.
32 ;---------------------------------------------------------------------------
33
34 text SEGMENT
35
36 ;---------------------------------------------------------------------------
37 ;;GenericPostSegment SEGMENT USE16
38 ;---------------------------------------------------------------------------
39
40 ;****************************************************************************
41 ; EbcLLCALLEX
42 ;
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.
48 ;
49 ; Destroys no working registers.
50 ;****************************************************************************
51 ; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
52 EbcLLCALLEXNative PROC
53 push rbp
54 push rbx
55 mov rbp, rsp
56 ; Function prolog
57
58 ; Copy FuncAddr to a preserved register.
59 mov rbx, rcx
60
61 ; Set stack pointer to new value
62 mov rsp, rdx
63
64 ; Considering the worst case, load 4 potiential arguments
65 ; into registers.
66 mov rcx, qword ptr [rsp]
67 mov rdx, qword ptr [rsp+8h]
68 mov r8, qword ptr [rsp+10h]
69 mov r9, qword ptr [rsp+18h]
70
71 ; Now call the external routine
72 call rbx
73
74 ; Function epilog
75 mov rsp, rbp
76 pop rbx
77 pop rbp
78 ret
79 EbcLLCALLEXNative ENDP
80
81
82 ; UINTN EbcLLGetEbcEntryPoint(VOID);
83 ; Routine Description:
84 ; The VM thunk code stuffs an EBC entry point into a processor
85 ; register. Since we can't use inline assembly to get it from
86 ; the interpreter C code, stuff it into the return value
87 ; register and return.
88 ;
89 ; Arguments:
90 ; None.
91 ;
92 ; Returns:
93 ; The contents of the register in which the entry point is passed.
94 ;
95 EbcLLGetEbcEntryPoint PROC
96 ret
97 EbcLLGetEbcEntryPoint ENDP
98
99 ;/*++
100 ;
101 ;Routine Description:
102 ;
103 ; Return the caller's value of the stack pointer.
104 ;
105 ;Arguments:
106 ;
107 ; None.
108 ;
109 ;Returns:
110 ;
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.
114 ;
115 ;--*/
116
117 ; UINTN EbcLLGetStackPointer()
118 EbcLLGetStackPointer PROC
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.
122 add rax, 4
123 ret
124 EbcLLGetStackPointer ENDP
125
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.
132 ;
133 ; Arguments:
134 ; None.
135 ;
136 ; Returns:
137 ; The unmodified value returned by the native code.
138 ;
139 EbcLLGetReturnValue PROC
140 ret
141 EbcLLGetReturnValue ENDP
142
143 text ENDS
144 END
145