]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcInt.h
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcInt.h
CommitLineData
fb0b259e 1/** @file\r
2 Main routines for the EBC interpreter. Includes the initialization and\r
3 main interpreter routines.\r
53c71d09 4\r
c8ad2d7a 5Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 6This program and the accompanying materials\r
fb0b259e 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
53c71d09 10\r
fb0b259e 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
53c71d09 13\r
fb0b259e 14**/\r
53c71d09 15\r
16#ifndef _EBC_INT_H_\r
17#define _EBC_INT_H_\r
18\r
ed7748fe 19\r
60c93673 20#include <Uefi.h>\r
ed7748fe 21\r
53c71d09 22#include <Protocol/DebugSupport.h>\r
23#include <Protocol/Ebc.h>\r
c8ad2d7a
LG
24#include <Protocol/EbcVmTest.h>\r
25#include <Protocol/EbcSimpleDebugger.h>\r
ed7748fe 26\r
53c71d09 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
53c71d09 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
8e3bc754 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
53c71d09 71EFI_STATUS\r
72EbcCreateThunks (\r
73 IN EFI_HANDLE ImageHandle,\r
74 IN VOID *EbcEntryPoint,\r
75 OUT VOID **Thunk,\r
ea7cb08c 76 IN UINT32 Flags\r
77 );\r
53c71d09 78\r
8e3bc754 79/**\r
80 Add a thunk to our list of thunks for a given image handle.\r
ead7e7dc 81 Also flush the instruction cache since we've written thunk code\r
8e3bc754 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
53c71d09 92EFI_STATUS\r
93EbcAddImageThunk (\r
ea7cb08c 94 IN EFI_HANDLE ImageHandle,\r
95 IN VOID *ThunkBuffer,\r
96 IN UINT32 ThunkSize\r
97 );\r
53c71d09 98\r
99//\r
100// The interpreter calls these when an exception is detected,\r
101// or as a periodic callback.\r
102//\r
8e3bc754 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
34e4e297 107 @param ExceptionFlags Specifies the exception context.\r
8e3bc754 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
53c71d09 114EFI_STATUS\r
115EbcDebugSignalException (\r
ea7cb08c 116 IN EFI_EXCEPTION_TYPE ExceptionType,\r
117 IN EXCEPTION_FLAGS ExceptionFlags,\r
118 IN VM_CONTEXT *VmPtr\r
119 );\r
53c71d09 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
53c71d09 130//\r
131// External low level functions that are native-processor dependent\r
34e4e297 132//\r
ea7cb08c 133/**\r
34e4e297 134 The VM thunk code stuffs an EBC entry point into a processor\r
8e3bc754 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
34e4e297 138\r
8e3bc754 139 @return The contents of the register in which the entry point is passed.\r
ea7cb08c 140\r
141**/\r
53c71d09 142UINTN\r
8e3bc754 143EFIAPI\r
53c71d09 144EbcLLGetEbcEntryPoint (\r
145 VOID\r
ea7cb08c 146 );\r
53c71d09 147\r
8e3bc754 148/**\r
149 Returns the caller's value of the stack pointer.\r
150\r
151 We adjust it by 4 here because when they called us, the return address\r
152 is put on the stack, thereby lowering it by 4 bytes.\r
153\r
ea7cb08c 154 @return The current value of the stack pointer for the caller.\r
8e3bc754 155\r
156**/\r
53c71d09 157UINTN\r
8e3bc754 158EFIAPI\r
53c71d09 159EbcLLGetStackPointer (\r
160 VOID\r
ea7cb08c 161 );\r
53c71d09 162\r
8e3bc754 163/**\r
164 This function is called to execute an EBC CALLEX instruction.\r
165 This instruction requires that we thunk out to external native\r
34e4e297 166 code. For x64, we switch stacks, copy the arguments to the stack\r
8e3bc754 167 and jump to the specified function.\r
168 On return, we restore the stack pointer to its original location.\r
169 Destroys no working registers.\r
170\r
171 @param CallAddr The function address.\r
172 @param EbcSp The new EBC stack pointer.\r
173 @param FramePtr The frame pointer.\r
ea7cb08c 174\r
8e3bc754 175**/\r
53c71d09 176VOID\r
8e3bc754 177EFIAPI\r
53c71d09 178EbcLLCALLEXNative (\r
179 IN UINTN CallAddr,\r
180 IN UINTN EbcSp,\r
181 IN VOID *FramePtr\r
ea7cb08c 182 );\r
53c71d09 183\r
8e3bc754 184/**\r
185 This function is called to execute an EBC CALLEX instruction.\r
186 The function check the callee's content to see whether it is common native\r
187 code or a thunk to another piece of EBC code.\r
188 If the callee is common native code, use EbcLLCAllEXASM to manipulate,\r
189 otherwise, set the VM->IP to target EBC code directly to avoid another VM\r
190 be startup which cost time and stack space.\r
191\r
192 @param VmPtr Pointer to a VM context.\r
193 @param FuncAddr Callee's address\r
194 @param NewStackPointer New stack pointer after the call\r
195 @param FramePtr New frame pointer after the call\r
196 @param Size The size of call instruction\r
197\r
198**/\r
53c71d09 199VOID\r
200EbcLLCALLEX (\r
201 IN VM_CONTEXT *VmPtr,\r
8e3bc754 202 IN UINTN FuncAddr,\r
203 IN UINTN NewStackPointer,\r
53c71d09 204 IN VOID *FramePtr,\r
205 IN UINT8 Size\r
ea7cb08c 206 );\r
53c71d09 207\r
8e3bc754 208/**\r
209 When EBC calls native, on return the VM has to stuff the return\r
210 value into a VM register. It's assumed here that the value is still\r
211 in the register, so simply return and the caller should get the\r
212 return result properly.\r
213\r
ea7cb08c 214 @return The unmodified value returned by the native code.\r
8e3bc754 215\r
216**/\r
53c71d09 217INT64\r
8e3bc754 218EFIAPI\r
53c71d09 219EbcLLGetReturnValue (\r
220 VOID\r
ea7cb08c 221 );\r
53c71d09 222\r
8e3bc754 223/**\r
ead7e7dc 224 Returns the stack index and buffer assosicated with the Handle parameter.\r
8e3bc754 225\r
34e4e297 226 @param Handle The EFI handle as the index to the EBC stack.\r
8e3bc754 227 @param StackBuffer A pointer to hold the returned stack buffer.\r
228 @param BufferIndex A pointer to hold the returned stack index.\r
34e4e297 229\r
8e3bc754 230 @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any\r
231 existing EBC stack.\r
232 @retval EFI_SUCCESS The stack index and buffer were found and\r
233 returned to the caller.\r
234\r
235**/\r
53c71d09 236EFI_STATUS\r
237GetEBCStack(\r
8e3bc754 238 IN EFI_HANDLE Handle,\r
239 OUT VOID **StackBuffer,\r
240 OUT UINTN *BufferIndex\r
53c71d09 241 );\r
242\r
8e3bc754 243/**\r
34e4e297 244 Returns from the EBC stack by stack Index.\r
245\r
8e3bc754 246 @param Index Specifies which EBC stack to return from.\r
34e4e297 247\r
8e3bc754 248 @retval EFI_SUCCESS The function completed successfully.\r
249\r
250**/\r
53c71d09 251EFI_STATUS\r
252ReturnEBCStack(\r
8e3bc754 253 IN UINTN Index\r
53c71d09 254 );\r
255\r
8e3bc754 256/**\r
257 Allocates memory to hold all the EBC stacks.\r
258\r
34e4e297 259 @retval EFI_SUCCESS The EBC stacks were allocated successfully.\r
8e3bc754 260 @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.\r
261\r
262**/\r
53c71d09 263EFI_STATUS\r
264InitEBCStack (\r
265 VOID\r
266 );\r
267\r
8e3bc754 268/**\r
269 Free all EBC stacks allocated before.\r
270\r
271 @retval EFI_SUCCESS All the EBC stacks were freed.\r
272\r
273**/\r
53c71d09 274EFI_STATUS\r
275FreeEBCStack(\r
276 VOID\r
277 );\r
278\r
8e3bc754 279/**\r
34e4e297 280 Returns from the EBC stack associated with the Handle parameter.\r
281\r
8e3bc754 282 @param Handle Specifies the EFI handle to find the EBC stack with.\r
34e4e297 283\r
8e3bc754 284 @retval EFI_SUCCESS The function completed successfully.\r
285\r
286**/\r
53c71d09 287EFI_STATUS\r
288ReturnEBCStackByHandle(\r
8e3bc754 289 IN EFI_HANDLE Handle\r
53c71d09 290 );\r
34e4e297 291\r
53c71d09 292typedef struct {\r
293 EFI_EBC_PROTOCOL *This;\r
294 VOID *EntryPoint;\r
295 EFI_HANDLE ImageHandle;\r
296 VM_CONTEXT VmContext;\r
297} EFI_EBC_THUNK_DATA;\r
298\r
f3f2e05d 299#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('e', 'b', 'c', 'p')\r
53c71d09 300\r
53c71d09 301\r
302#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
303 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)\r
304\r
305\r
306#endif // #ifndef _EBC_INT_H_\r