]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/EbcDxe/EbcInt.h
Remove assumption on EAX and R10 usage for IA32 compiler and X64 compiler.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcInt.h
... / ...
CommitLineData
1/** @file\r
2 Main routines for the EBC interpreter. Includes the initialization and\r
3 main interpreter routines.\r
4\r
5Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _EBC_INT_H_\r
17#define _EBC_INT_H_\r
18\r
19\r
20#include <Uefi.h>\r
21\r
22#include <Protocol/DebugSupport.h>\r
23#include <Protocol/Ebc.h>\r
24#include <Protocol/EbcVmTest.h>\r
25#include <Protocol/EbcSimpleDebugger.h>\r
26\r
27#include <Library/BaseLib.h>\r
28#include <Library/DebugLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/BaseMemoryLib.h>\r
31#include <Library/UefiBootServicesTableLib.h>\r
32#include <Library/MemoryAllocationLib.h>\r
33\r
34extern VM_CONTEXT *mVmPtr;\r
35\r
36//\r
37// Bits of exception flags field of VM context\r
38//\r
39#define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue\r
40#define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue\r
41#define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem\r
42#define EXCEPTION_FLAG_NONE 0x00000000 // for normal return\r
43//\r
44// Flags passed to the internal create-thunks function.\r
45//\r
46#define FLAG_THUNK_ENTRY_POINT 0x01 // thunk for an image entry point\r
47#define FLAG_THUNK_PROTOCOL 0x00 // thunk for an EBC protocol service\r
48//\r
49// Put this value at the bottom of the VM's stack gap so we can check it on\r
50// occasion to make sure the stack has not been corrupted.\r
51//\r
52#define VM_STACK_KEY_VALUE 0xDEADBEEF\r
53\r
54/**\r
55 Create thunks for an EBC image entry point, or an EBC protocol service.\r
56\r
57 @param ImageHandle Image handle for the EBC image. If not null, then\r
58 we're creating a thunk for an image entry point.\r
59 @param EbcEntryPoint Address of the EBC code that the thunk is to call\r
60 @param Thunk Returned thunk we create here\r
61 @param Flags Flags indicating options for creating the thunk\r
62\r
63 @retval EFI_SUCCESS The thunk was created successfully.\r
64 @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit\r
65 aligned.\r
66 @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC\r
67 Thunk.\r
68 @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.\r
69\r
70**/\r
71EFI_STATUS\r
72EbcCreateThunks (\r
73 IN EFI_HANDLE ImageHandle,\r
74 IN VOID *EbcEntryPoint,\r
75 OUT VOID **Thunk,\r
76 IN UINT32 Flags\r
77 );\r
78\r
79/**\r
80 Add a thunk to our list of thunks for a given image handle.\r
81 Also flush the instruction cache since we've written thunk code\r
82 to memory that will be executed eventually.\r
83\r
84 @param ImageHandle The image handle to which the thunk is tied.\r
85 @param ThunkBuffer The buffer that has been created/allocated.\r
86 @param ThunkSize The size of the thunk memory allocated.\r
87\r
88 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
89 @retval EFI_SUCCESS The function completed successfully.\r
90\r
91**/\r
92EFI_STATUS\r
93EbcAddImageThunk (\r
94 IN EFI_HANDLE ImageHandle,\r
95 IN VOID *ThunkBuffer,\r
96 IN UINT32 ThunkSize\r
97 );\r
98\r
99//\r
100// The interpreter calls these when an exception is detected,\r
101// or as a periodic callback.\r
102//\r
103/**\r
104 The VM interpreter calls this function when an exception is detected.\r
105\r
106 @param ExceptionType Specifies the processor exception detected.\r
107 @param ExceptionFlags Specifies the exception context.\r
108 @param VmPtr Pointer to a VM context for passing info to the\r
109 EFI debugger.\r
110\r
111 @retval EFI_SUCCESS This function completed successfully.\r
112\r
113**/\r
114EFI_STATUS\r
115EbcDebugSignalException (\r
116 IN EFI_EXCEPTION_TYPE ExceptionType,\r
117 IN EXCEPTION_FLAGS ExceptionFlags,\r
118 IN VM_CONTEXT *VmPtr\r
119 );\r
120\r
121//\r
122// Define a constant of how often to call the debugger periodic callback\r
123// function.\r
124//\r
125#define EFI_TIMER_UNIT_1MS (1000 * 10)\r
126#define EBC_VM_PERIODIC_CALLBACK_RATE (1000 * EFI_TIMER_UNIT_1MS)\r
127#define STACK_POOL_SIZE (1024 * 1020)\r
128#define MAX_STACK_NUM 4\r
129\r
130//\r
131// External low level functions that are native-processor dependent\r
132//\r
133/**\r
134 The VM thunk code stuffs an EBC entry point into a processor\r
135 register. Since we can't use inline assembly to get it from\r
136 the interpreter C code, stuff it into the return value\r
137 register and return.\r
138\r
139 @return The contents of the register in which the entry point is passed.\r
140\r
141**/\r
142UINTN\r
143EFIAPI\r
144EbcLLGetEbcEntryPoint (\r
145 VOID\r
146 );\r
147\r
148/**\r
149 This function is called to execute an EBC CALLEX instruction.\r
150 This instruction requires that we thunk out to external native\r
151 code. For x64, we switch stacks, copy the arguments to the stack\r
152 and jump to the specified function.\r
153 On return, we restore the stack pointer to its original location.\r
154 Destroys no working registers.\r
155\r
156 @param CallAddr The function address.\r
157 @param EbcSp The new EBC stack pointer.\r
158 @param FramePtr The frame pointer.\r
159\r
160 @return The unmodified value returned by the native code.\r
161\r
162**/\r
163INT64\r
164EFIAPI\r
165EbcLLCALLEXNative (\r
166 IN UINTN CallAddr,\r
167 IN UINTN EbcSp,\r
168 IN VOID *FramePtr\r
169 );\r
170\r
171/**\r
172 This function is called to execute an EBC CALLEX instruction.\r
173 The function check the callee's content to see whether it is common native\r
174 code or a thunk to another piece of EBC code.\r
175 If the callee is common native code, use EbcLLCAllEXASM to manipulate,\r
176 otherwise, set the VM->IP to target EBC code directly to avoid another VM\r
177 be startup which cost time and stack space.\r
178\r
179 @param VmPtr Pointer to a VM context.\r
180 @param FuncAddr Callee's address\r
181 @param NewStackPointer New stack pointer after the call\r
182 @param FramePtr New frame pointer after the call\r
183 @param Size The size of call instruction\r
184\r
185**/\r
186VOID\r
187EbcLLCALLEX (\r
188 IN VM_CONTEXT *VmPtr,\r
189 IN UINTN FuncAddr,\r
190 IN UINTN NewStackPointer,\r
191 IN VOID *FramePtr,\r
192 IN UINT8 Size\r
193 );\r
194\r
195/**\r
196 Returns the stack index and buffer assosicated with the Handle parameter.\r
197\r
198 @param Handle The EFI handle as the index to the EBC stack.\r
199 @param StackBuffer A pointer to hold the returned stack buffer.\r
200 @param BufferIndex A pointer to hold the returned stack index.\r
201\r
202 @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any\r
203 existing EBC stack.\r
204 @retval EFI_SUCCESS The stack index and buffer were found and\r
205 returned to the caller.\r
206\r
207**/\r
208EFI_STATUS\r
209GetEBCStack(\r
210 IN EFI_HANDLE Handle,\r
211 OUT VOID **StackBuffer,\r
212 OUT UINTN *BufferIndex\r
213 );\r
214\r
215/**\r
216 Returns from the EBC stack by stack Index.\r
217\r
218 @param Index Specifies which EBC stack to return from.\r
219\r
220 @retval EFI_SUCCESS The function completed successfully.\r
221\r
222**/\r
223EFI_STATUS\r
224ReturnEBCStack(\r
225 IN UINTN Index\r
226 );\r
227\r
228/**\r
229 Allocates memory to hold all the EBC stacks.\r
230\r
231 @retval EFI_SUCCESS The EBC stacks were allocated successfully.\r
232 @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.\r
233\r
234**/\r
235EFI_STATUS\r
236InitEBCStack (\r
237 VOID\r
238 );\r
239\r
240/**\r
241 Free all EBC stacks allocated before.\r
242\r
243 @retval EFI_SUCCESS All the EBC stacks were freed.\r
244\r
245**/\r
246EFI_STATUS\r
247FreeEBCStack(\r
248 VOID\r
249 );\r
250\r
251/**\r
252 Returns from the EBC stack associated with the Handle parameter.\r
253\r
254 @param Handle Specifies the EFI handle to find the EBC stack with.\r
255\r
256 @retval EFI_SUCCESS The function completed successfully.\r
257\r
258**/\r
259EFI_STATUS\r
260ReturnEBCStackByHandle(\r
261 IN EFI_HANDLE Handle\r
262 );\r
263\r
264typedef struct {\r
265 EFI_EBC_PROTOCOL *This;\r
266 VOID *EntryPoint;\r
267 EFI_HANDLE ImageHandle;\r
268 VM_CONTEXT VmContext;\r
269} EFI_EBC_THUNK_DATA;\r
270\r
271#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('e', 'b', 'c', 'p')\r
272\r
273\r
274#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
275 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)\r
276\r
277\r
278#endif // #ifndef _EBC_INT_H_\r