]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.asm
Avoid change the return status from above code which will also be used later.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ia32 / 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
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
24.XLIST\r
25\r
26.LIST\r
27\r
28;---------------------------------------------------------------------------\r
29; Assembler options\r
30;---------------------------------------------------------------------------\r
31\r
32.686p\r
7102b199 33.model flat, C\r
7b414b4e 34.code\r
7102b199
JY
35CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD\r
36EbcInterpret PROTO\r
37ExecuteEbcImageEntryPoint PROTO\r
53c71d09 38\r
39;****************************************************************************\r
40; EbcLLCALLEXNative\r
41;\r
42; This function is called to execute an EBC CALLEX instruction\r
7b414b4e 43; to native code.\r
53c71d09 44; This instruction requires that we thunk out to external native\r
7b414b4e 45; code. For IA32, we simply switch stacks and jump to the\r
53c71d09 46; specified function. On return, we restore the stack pointer\r
47; to its original location.\r
48;\r
49; Destroys no working registers.\r
50;****************************************************************************\r
fa97cbf4 51; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
7102b199 52EbcLLCALLEXNative PROC PUBLIC\r
53c71d09 53 push ebp\r
54 push ebx\r
55 mov ebp, esp ; standard function prolog\r
7b414b4e 56\r
53c71d09 57 ; Get function address in a register\r
58 ; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]\r
59 mov ecx, dword ptr [esp]+0Ch\r
7b414b4e 60\r
53c71d09 61 ; Set stack pointer to new value\r
62 ; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]\r
63 mov eax, dword ptr [esp] + 14h\r
64 mov edx, dword ptr [esp] + 10h\r
65 sub eax, edx\r
7b414b4e 66 sub esp, eax\r
53c71d09 67 mov ebx, esp\r
68 push ecx\r
69 push eax\r
70 push edx\r
71 push ebx\r
72 call CopyMem\r
73 pop eax\r
74 pop eax\r
75 pop eax\r
76 pop ecx\r
77\r
78 ; Now call the external routine\r
79 call ecx\r
7b414b4e 80\r
53c71d09 81 ; ebp is preserved by the callee. In this function it\r
82 ; equals the original esp, so set them equal\r
83 mov esp, ebp\r
84\r
85 ; Standard function epilog\r
86 mov esp, ebp\r
87 pop ebx\r
88 pop ebp\r
89 ret\r
7102b199 90EbcLLCALLEXNative ENDP\r
53c71d09 91\r
7102b199
JY
92;****************************************************************************\r
93; EbcLLEbcInterpret\r
53c71d09 94;\r
7102b199
JY
95; Begin executing an EBC image.\r
96;****************************************************************************\r
97; UINT64 EbcLLEbcInterpret(VOID)\r
98EbcLLEbcInterpret PROC PUBLIC\r
99 ;\r
100 ;; mov eax, 0xca112ebc\r
101 ;; mov eax, EbcEntryPoint\r
102 ;; mov ecx, EbcLLEbcInterpret\r
103 ;; jmp ecx\r
104 ;\r
105 ; Caller uses above instruction to jump here\r
106 ; The stack is below:\r
107 ; +-----------+\r
108 ; | RetAddr |\r
109 ; +-----------+\r
110 ; |EntryPoint | (EAX)\r
111 ; +-----------+\r
112 ; | Arg1 | <- EDI\r
113 ; +-----------+\r
114 ; | Arg2 |\r
115 ; +-----------+\r
116 ; | ... |\r
117 ; +-----------+\r
118 ; | Arg16 |\r
119 ; +-----------+\r
120 ; | EDI |\r
121 ; +-----------+\r
122 ; | ESI |\r
123 ; +-----------+\r
124 ; | EBP | <- EBP\r
125 ; +-----------+\r
126 ; | RetAddr | <- ESP is here\r
127 ; +-----------+\r
128 ; | Arg1 | <- ESI\r
129 ; +-----------+\r
130 ; | Arg2 |\r
131 ; +-----------+\r
132 ; | ... |\r
133 ; +-----------+\r
134 ; | Arg16 |\r
135 ; +-----------+\r
136 ; \r
137\r
138 ; Construct new stack\r
139 push ebp\r
140 mov ebp, esp\r
141 push esi\r
142 push edi\r
143 sub esp, 40h\r
144 push eax\r
145 mov esi, ebp\r
146 add esi, 8\r
147 mov edi, esp\r
148 add edi, 4\r
149 mov ecx, 16\r
150 rep movsd\r
151 \r
152 ; call C-code\r
153 call EbcInterpret\r
154 add esp, 44h\r
155 pop edi\r
156 pop esi\r
157 pop ebp\r
158 ret\r
159EbcLLEbcInterpret ENDP\r
160\r
161;****************************************************************************\r
162; EbcLLExecuteEbcImageEntryPoint\r
53c71d09 163;\r
7102b199
JY
164; Begin executing an EBC image.\r
165;****************************************************************************\r
166; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)\r
167EbcLLExecuteEbcImageEntryPoint PROC PUBLIC\r
168 ;\r
169 ;; mov eax, 0xca112ebc\r
170 ;; mov eax, EbcEntryPoint\r
171 ;; mov ecx, EbcLLExecuteEbcImageEntryPoint\r
172 ;; jmp ecx\r
173 ;\r
174 ; Caller uses above instruction to jump here\r
175 ; The stack is below:\r
176 ; +-----------+\r
177 ; | RetAddr |\r
178 ; +-----------+\r
179 ; |EntryPoint | (EAX)\r
180 ; +-----------+\r
181 ; |ImageHandle|\r
182 ; +-----------+\r
183 ; |SystemTable|\r
184 ; +-----------+\r
185 ; | RetAddr | <- ESP is here\r
186 ; +-----------+\r
187 ; |ImageHandle|\r
188 ; +-----------+\r
189 ; |SystemTable|\r
190 ; +-----------+\r
191 ; \r
192 \r
193 ; Construct new stack\r
194 mov [esp - 0Ch], eax\r
195 mov eax, [esp + 04h]\r
196 mov [esp - 08h], eax\r
197 mov eax, [esp + 08h]\r
198 mov [esp - 04h], eax\r
199 \r
200 ; call C-code\r
201 sub esp, 0Ch\r
202 call ExecuteEbcImageEntryPoint\r
203 add esp, 0Ch\r
53c71d09 204 ret\r
7102b199 205EbcLLExecuteEbcImageEntryPoint ENDP\r
53c71d09 206\r
53c71d09 207END\r