]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.asm
MdeModulePkg: INF/DEC file updates to EDK II packages
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / X64 / EbcLowLevel.asm
1 ;/** @file
2 ;
3 ; This code provides low level routines that support the Virtual Machine.
4 ; for option ROMs.
5 ;
6 ; Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
7 ; 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
11 ;
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.
14 ;
15 ;**/
16
17 page ,132
18 title VM ASSEMBLY LANGUAGE ROUTINES
19
20 ;---------------------------------------------------------------------------
21 ; Equate files needed.
22 ;---------------------------------------------------------------------------
23
24 .CODE
25
26 CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD
27 EbcInterpret PROTO
28 ExecuteEbcImageEntryPoint PROTO
29
30 ;****************************************************************************
31 ; EbcLLCALLEX
32 ;
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.
38 ;
39 ; Destroys no working registers.
40 ;****************************************************************************
41 ; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
42 EbcLLCALLEXNative PROC PUBLIC
43 push rbp
44 push rbx
45 mov rbp, rsp
46 ; Function prolog
47
48 ; Copy FuncAddr to a preserved register.
49 mov rbx, rcx
50
51 ; Set stack pointer to new value
52 sub r8, rdx
53 sub rsp, r8
54 mov rcx, rsp
55 sub rsp, 20h
56 call CopyMem
57 add rsp, 20h
58
59 ; Considering the worst case, load 4 potiential arguments
60 ; into registers.
61 mov rcx, qword ptr [rsp]
62 mov rdx, qword ptr [rsp+8h]
63 mov r8, qword ptr [rsp+10h]
64 mov r9, qword ptr [rsp+18h]
65
66 ; Now call the external routine
67 call rbx
68
69 ; Function epilog
70 mov rsp, rbp
71 pop rbx
72 pop rbp
73 ret
74 EbcLLCALLEXNative ENDP
75
76 ;****************************************************************************
77 ; EbcLLEbcInterpret
78 ;
79 ; Begin executing an EBC image.
80 ;****************************************************************************
81 ; UINT64 EbcLLEbcInterpret(VOID)
82 EbcLLEbcInterpret PROC PUBLIC
83 ;
84 ;; mov rax, ca112ebccall2ebch
85 ;; mov r10, EbcEntryPoint
86 ;; mov r11, EbcLLEbcInterpret
87 ;; jmp r11
88 ;
89 ; Caller uses above instruction to jump here
90 ; The stack is below:
91 ; +-----------+
92 ; | RetAddr |
93 ; +-----------+
94 ; |EntryPoint | (R10)
95 ; +-----------+
96 ; | Arg1 | <- RDI
97 ; +-----------+
98 ; | Arg2 |
99 ; +-----------+
100 ; | ... |
101 ; +-----------+
102 ; | Arg16 |
103 ; +-----------+
104 ; | Dummy |
105 ; +-----------+
106 ; | RDI |
107 ; +-----------+
108 ; | RSI |
109 ; +-----------+
110 ; | RBP | <- RBP
111 ; +-----------+
112 ; | RetAddr | <- RSP is here
113 ; +-----------+
114 ; | Scratch1 | (RCX) <- RSI
115 ; +-----------+
116 ; | Scratch2 | (RDX)
117 ; +-----------+
118 ; | Scratch3 | (R8)
119 ; +-----------+
120 ; | Scratch4 | (R9)
121 ; +-----------+
122 ; | Arg5 |
123 ; +-----------+
124 ; | Arg6 |
125 ; +-----------+
126 ; | ... |
127 ; +-----------+
128 ; | Arg16 |
129 ; +-----------+
130 ;
131
132 ; save old parameter to stack
133 mov [rsp + 08h], rcx
134 mov [rsp + 10h], rdx
135 mov [rsp + 18h], r8
136 mov [rsp + 20h], r9
137
138 ; Construct new stack
139 push rbp
140 mov rbp, rsp
141 push rsi
142 push rdi
143 push rbx
144 sub rsp, 80h
145 push r10
146 mov rsi, rbp
147 add rsi, 10h
148 mov rdi, rsp
149 add rdi, 8
150 mov rcx, 16
151 rep movsq
152
153 ; build new paramater calling convention
154 mov r9, [rsp + 18h]
155 mov r8, [rsp + 10h]
156 mov rdx, [rsp + 08h]
157 mov rcx, r10
158
159 ; call C-code
160 call EbcInterpret
161 add rsp, 88h
162 pop rbx
163 pop rdi
164 pop rsi
165 pop rbp
166 ret
167 EbcLLEbcInterpret ENDP
168
169 ;****************************************************************************
170 ; EbcLLExecuteEbcImageEntryPoint
171 ;
172 ; Begin executing an EBC image.
173 ;****************************************************************************
174 ; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)
175 EbcLLExecuteEbcImageEntryPoint PROC PUBLIC
176 ;
177 ;; mov rax, ca112ebccall2ebch
178 ;; mov r10, EbcEntryPoint
179 ;; mov r11, EbcLLExecuteEbcImageEntryPoint
180 ;; jmp r11
181 ;
182 ; Caller uses above instruction to jump here
183 ; The stack is below:
184 ; +-----------+
185 ; | RetAddr |
186 ; +-----------+
187 ; |EntryPoint | (R10)
188 ; +-----------+
189 ; |ImageHandle|
190 ; +-----------+
191 ; |SystemTable|
192 ; +-----------+
193 ; | Dummy |
194 ; +-----------+
195 ; | Dummy |
196 ; +-----------+
197 ; | RetAddr | <- RSP is here
198 ; +-----------+
199 ; |ImageHandle| (RCX)
200 ; +-----------+
201 ; |SystemTable| (RDX)
202 ; +-----------+
203 ;
204
205 ; build new paramater calling convention
206 mov r8, rdx
207 mov rdx, rcx
208 mov rcx, r10
209
210 ; call C-code
211 sub rsp, 28h
212 call ExecuteEbcImageEntryPoint
213 add rsp, 28h
214 ret
215 EbcLLExecuteEbcImageEntryPoint ENDP
216
217 END
218