]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/Ia32/EbcLowLevel.nasm
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ia32 / EbcLowLevel.nasm
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 ; SPDX-License-Identifier: BSD-2-Clause-Patent
8 ;
9 ;**/
10
11 ;---------------------------------------------------------------------------
12 ; Equate files needed.
13 ;---------------------------------------------------------------------------
14
15 ;---------------------------------------------------------------------------
16 ; Assembler options
17 ;---------------------------------------------------------------------------
18
19 SECTION .text
20 extern ASM_PFX(CopyMem)
21 extern ASM_PFX(EbcInterpret)
22 extern ASM_PFX(ExecuteEbcImageEntryPoint)
23
24 ;****************************************************************************
25 ; EbcLLCALLEXNative
26 ;
27 ; This function is called to execute an EBC CALLEX instruction
28 ; to native code.
29 ; This instruction requires that we thunk out to external native
30 ; code. For IA32, we simply switch stacks and jump to the
31 ; specified function. On return, we restore the stack pointer
32 ; to its original location.
33 ;
34 ; Destroys no working registers.
35 ;****************************************************************************
36 ; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
37 global ASM_PFX(EbcLLCALLEXNative)
38 ASM_PFX(EbcLLCALLEXNative):
39 push ebp
40 push ebx
41 mov ebp, esp ; standard function prolog
42
43 ; Get function address in a register
44 ; mov ecx, FuncAddr => mov ecx, dword ptr [FuncAddr]
45 mov ecx, dword [esp + 0xC]
46
47 ; Set stack pointer to new value
48 ; mov eax, NewStackPointer => mov eax, dword ptr [NewSp]
49 mov eax, dword [esp + 0x14]
50 mov edx, dword [esp + 0x10]
51 sub eax, edx
52 sub esp, eax
53 mov ebx, esp
54 push ecx
55 push eax
56 push edx
57 push ebx
58 call ASM_PFX(CopyMem)
59 pop eax
60 pop eax
61 pop eax
62 pop ecx
63
64 ; Now call the external routine
65 call ecx
66
67 ; ebp is preserved by the callee. In this function it
68 ; equals the original esp, so set them equal
69 mov esp, ebp
70
71 ; Standard function epilog
72 mov esp, ebp
73 pop ebx
74 pop ebp
75 ret
76
77 ;****************************************************************************
78 ; EbcLLEbcInterpret
79 ;
80 ; Begin executing an EBC image.
81 ;****************************************************************************
82 ; UINT64 EbcLLEbcInterpret(VOID)
83 global ASM_PFX(EbcLLEbcInterpret)
84 ASM_PFX(EbcLLEbcInterpret):
85 ;
86 ;; mov eax, 0xca112ebc
87 ;; mov eax, EbcEntryPoint
88 ;; mov ecx, EbcLLEbcInterpret
89 ;; jmp ecx
90 ;
91 ; Caller uses above instruction to jump here
92 ; The stack is below:
93 ; +-----------+
94 ; | RetAddr |
95 ; +-----------+
96 ; |EntryPoint | (EAX)
97 ; +-----------+
98 ; | Arg1 | <- EDI
99 ; +-----------+
100 ; | Arg2 |
101 ; +-----------+
102 ; | ... |
103 ; +-----------+
104 ; | Arg16 |
105 ; +-----------+
106 ; | EDI |
107 ; +-----------+
108 ; | ESI |
109 ; +-----------+
110 ; | EBP | <- EBP
111 ; +-----------+
112 ; | RetAddr | <- ESP is here
113 ; +-----------+
114 ; | Arg1 | <- ESI
115 ; +-----------+
116 ; | Arg2 |
117 ; +-----------+
118 ; | ... |
119 ; +-----------+
120 ; | Arg16 |
121 ; +-----------+
122 ;
123
124 ; Construct new stack
125 push ebp
126 mov ebp, esp
127 push esi
128 push edi
129 sub esp, 0x40
130 push eax
131 mov esi, ebp
132 add esi, 8
133 mov edi, esp
134 add edi, 4
135 mov ecx, 16
136 rep movsd
137
138 ; call C-code
139 call ASM_PFX(EbcInterpret)
140 add esp, 0x44
141 pop edi
142 pop esi
143 pop ebp
144 ret
145
146 ;****************************************************************************
147 ; EbcLLExecuteEbcImageEntryPoint
148 ;
149 ; Begin executing an EBC image.
150 ;****************************************************************************
151 ; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)
152 global ASM_PFX(EbcLLExecuteEbcImageEntryPoint)
153 ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
154 ;
155 ;; mov eax, 0xca112ebc
156 ;; mov eax, EbcEntryPoint
157 ;; mov ecx, EbcLLExecuteEbcImageEntryPoint
158 ;; jmp ecx
159 ;
160 ; Caller uses above instruction to jump here
161 ; The stack is below:
162 ; +-----------+
163 ; | RetAddr |
164 ; +-----------+
165 ; |EntryPoint | (EAX)
166 ; +-----------+
167 ; |ImageHandle|
168 ; +-----------+
169 ; |SystemTable|
170 ; +-----------+
171 ; | RetAddr | <- ESP is here
172 ; +-----------+
173 ; |ImageHandle|
174 ; +-----------+
175 ; |SystemTable|
176 ; +-----------+
177 ;
178
179 ; Construct new stack
180 mov [esp - 0xC], eax
181 mov eax, [esp + 0x4]
182 mov [esp - 0x8], eax
183 mov eax, [esp + 0x8]
184 mov [esp - 0x4], eax
185
186 ; call C-code
187 sub esp, 0xC
188 call ASM_PFX(ExecuteEbcImageEntryPoint)
189 add esp, 0xC
190 ret
191