]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.asm
Remove assumption on EAX and R10 usage for IA32 compiler and X64 compiler.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / X64 / EbcLowLevel.asm
CommitLineData
7b414b4e 1;/** @file\r
f45af90b 2; \r
3; This code provides low level routines that support the Virtual Machine.\r
4; for option ROMs.\r
5; \r
fa97cbf4 6; Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 7; This program and the accompanying materials\r
7b414b4e 8; are licensed and made available under the terms and conditions of the BSD License\r
9; which accompanies this distribution. The full text of the license may be found at\r
10; http://opensource.org/licenses/bsd-license.php\r
f45af90b 11; \r
7b414b4e 12; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
f45af90b 14; \r
7b414b4e 15;**/\r
16\r
7b414b4e 17 page ,132\r
18 title VM ASSEMBLY LANGUAGE ROUTINES\r
53c71d09 19\r
20;---------------------------------------------------------------------------\r
21; Equate files needed.\r
22;---------------------------------------------------------------------------\r
23\r
fa97cbf4 24.CODE\r
53c71d09 25\r
fa97cbf4 26CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD\r
7102b199
JY
27EbcInterpret PROTO\r
28ExecuteEbcImageEntryPoint PROTO\r
53c71d09 29\r
30;****************************************************************************\r
31; EbcLLCALLEX\r
32;\r
7b414b4e 33; This function is called to execute an EBC CALLEX instruction.\r
53c71d09 34; This instruction requires that we thunk out to external native\r
35; code. For x64, we switch stacks, copy the arguments to the stack\r
7b414b4e 36; and jump to the specified function.\r
53c71d09 37; On return, we restore the stack pointer to its original location.\r
38;\r
39; Destroys no working registers.\r
40;****************************************************************************\r
fa97cbf4 41; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
db01f13e 42EbcLLCALLEXNative PROC PUBLIC\r
53c71d09 43 push rbp\r
44 push rbx\r
45 mov rbp, rsp\r
46 ; Function prolog\r
7b414b4e 47\r
53c71d09 48 ; Copy FuncAddr to a preserved register.\r
49 mov rbx, rcx\r
50\r
51 ; Set stack pointer to new value\r
52 sub r8, rdx\r
53 sub rsp, r8\r
54 mov rcx, rsp\r
55 sub rsp, 20h\r
7b414b4e 56 call CopyMem\r
53c71d09 57 add rsp, 20h\r
7b414b4e 58\r
53c71d09 59 ; Considering the worst case, load 4 potiential arguments\r
60 ; into registers.\r
61 mov rcx, qword ptr [rsp]\r
62 mov rdx, qword ptr [rsp+8h]\r
63 mov r8, qword ptr [rsp+10h]\r
64 mov r9, qword ptr [rsp+18h]\r
65\r
66 ; Now call the external routine\r
67 call rbx\r
7b414b4e 68\r
53c71d09 69 ; Function epilog\r
70 mov rsp, rbp\r
71 pop rbx\r
72 pop rbp\r
73 ret\r
74EbcLLCALLEXNative ENDP\r
75\r
7102b199
JY
76;****************************************************************************\r
77; EbcLLEbcInterpret\r
53c71d09 78;\r
7102b199
JY
79; Begin executing an EBC image.\r
80;****************************************************************************\r
81; UINT64 EbcLLEbcInterpret(VOID)\r
82EbcLLEbcInterpret PROC PUBLIC\r
83 ;\r
84 ;; mov rax, ca112ebccall2ebch\r
85 ;; mov r10, EbcEntryPoint\r
86 ;; mov r11, EbcLLEbcInterpret\r
87 ;; jmp r11\r
88 ;\r
89 ; Caller uses above instruction to jump here\r
90 ; The stack is below:\r
91 ; +-----------+\r
92 ; | RetAddr |\r
93 ; +-----------+\r
94 ; |EntryPoint | (R10)\r
95 ; +-----------+\r
96 ; | Arg1 | <- RDI\r
97 ; +-----------+\r
98 ; | Arg2 |\r
99 ; +-----------+\r
100 ; | ... |\r
101 ; +-----------+\r
102 ; | Arg16 |\r
103 ; +-----------+\r
104 ; | Dummy |\r
105 ; +-----------+\r
106 ; | RDI |\r
107 ; +-----------+\r
108 ; | RSI |\r
109 ; +-----------+\r
110 ; | RBP | <- RBP\r
111 ; +-----------+\r
112 ; | RetAddr | <- RSP is here\r
113 ; +-----------+\r
114 ; | Scratch1 | (RCX) <- RSI\r
115 ; +-----------+\r
116 ; | Scratch2 | (RDX)\r
117 ; +-----------+\r
118 ; | Scratch3 | (R8)\r
119 ; +-----------+\r
120 ; | Scratch4 | (R9)\r
121 ; +-----------+\r
122 ; | Arg5 |\r
123 ; +-----------+\r
124 ; | Arg6 |\r
125 ; +-----------+\r
126 ; | ... |\r
127 ; +-----------+\r
128 ; | Arg16 |\r
129 ; +-----------+\r
130 ;\r
131\r
132 ; save old parameter to stack\r
133 mov [rsp + 08h], rcx\r
134 mov [rsp + 10h], rdx\r
135 mov [rsp + 18h], r8\r
136 mov [rsp + 20h], r9\r
137\r
138 ; Construct new stack\r
139 push rbp\r
140 mov rbp, rsp\r
141 push rsi\r
142 push rdi\r
143 push rbx\r
144 sub rsp, 80h\r
145 push r10\r
146 mov rsi, rbp\r
147 add rsi, 10h\r
148 mov rdi, rsp\r
149 add rdi, 8\r
150 mov rcx, 16\r
151 rep movsq\r
152 \r
153 ; build new paramater calling convention\r
154 mov r9, [rsp + 18h]\r
155 mov r8, [rsp + 10h]\r
156 mov rdx, [rsp + 08h]\r
157 mov rcx, r10\r
158\r
159 ; call C-code\r
160 call EbcInterpret\r
161 add rsp, 88h\r
162 pop rbx\r
163 pop rdi\r
164 pop rsi\r
165 pop rbp\r
166 ret\r
167EbcLLEbcInterpret ENDP\r
168\r
169;****************************************************************************\r
170; EbcLLExecuteEbcImageEntryPoint\r
53c71d09 171;\r
7102b199
JY
172; Begin executing an EBC image.\r
173;****************************************************************************\r
174; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)\r
175EbcLLExecuteEbcImageEntryPoint PROC PUBLIC\r
176 ;\r
177 ;; mov rax, ca112ebccall2ebch\r
178 ;; mov r10, EbcEntryPoint\r
179 ;; mov r11, EbcLLExecuteEbcImageEntryPoint\r
180 ;; jmp r11\r
181 ;\r
182 ; Caller uses above instruction to jump here\r
183 ; The stack is below:\r
184 ; +-----------+\r
185 ; | RetAddr |\r
186 ; +-----------+\r
187 ; |EntryPoint | (R10)\r
188 ; +-----------+\r
189 ; |ImageHandle|\r
190 ; +-----------+\r
191 ; |SystemTable|\r
192 ; +-----------+\r
193 ; | Dummy |\r
194 ; +-----------+\r
195 ; | Dummy |\r
196 ; +-----------+\r
197 ; | RetAddr | <- RSP is here\r
198 ; +-----------+\r
199 ; |ImageHandle| (RCX)\r
200 ; +-----------+\r
201 ; |SystemTable| (RDX)\r
202 ; +-----------+\r
203 ; \r
204\r
205 ; build new paramater calling convention\r
206 mov r8, rdx\r
207 mov rdx, rcx\r
208 mov rcx, r10\r
209\r
210 ; call C-code\r
211 sub rsp, 28h\r
212 call ExecuteEbcImageEntryPoint\r
213 add rsp, 28h\r
53c71d09 214 ret\r
7102b199 215EbcLLExecuteEbcImageEntryPoint ENDP\r
53c71d09 216\r
53c71d09 217END\r
218\r