]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcInt.h
MdeModulePkg: INF/DEC file updates to EDK II packages
[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 This function is called to execute an EBC CALLEX instruction.\r
150 This instruction requires that we thunk out to external native\r
34e4e297 151 code. For x64, we switch stacks, copy the arguments to the stack\r
8e3bc754 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
ea7cb08c 159\r
fa97cbf4
JY
160 @return The unmodified value returned by the native code.\r
161\r
8e3bc754 162**/\r
fa97cbf4 163INT64\r
8e3bc754 164EFIAPI\r
53c71d09 165EbcLLCALLEXNative (\r
166 IN UINTN CallAddr,\r
167 IN UINTN EbcSp,\r
168 IN VOID *FramePtr\r
ea7cb08c 169 );\r
53c71d09 170\r
8e3bc754 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
53c71d09 186VOID\r
187EbcLLCALLEX (\r
188 IN VM_CONTEXT *VmPtr,\r
8e3bc754 189 IN UINTN FuncAddr,\r
190 IN UINTN NewStackPointer,\r
53c71d09 191 IN VOID *FramePtr,\r
192 IN UINT8 Size\r
ea7cb08c 193 );\r
53c71d09 194\r
8e3bc754 195/**\r
ead7e7dc 196 Returns the stack index and buffer assosicated with the Handle parameter.\r
8e3bc754 197\r
34e4e297 198 @param Handle The EFI handle as the index to the EBC stack.\r
8e3bc754 199 @param StackBuffer A pointer to hold the returned stack buffer.\r
200 @param BufferIndex A pointer to hold the returned stack index.\r
34e4e297 201\r
8e3bc754 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
53c71d09 208EFI_STATUS\r
209GetEBCStack(\r
8e3bc754 210 IN EFI_HANDLE Handle,\r
211 OUT VOID **StackBuffer,\r
212 OUT UINTN *BufferIndex\r
53c71d09 213 );\r
214\r
8e3bc754 215/**\r
34e4e297 216 Returns from the EBC stack by stack Index.\r
217\r
8e3bc754 218 @param Index Specifies which EBC stack to return from.\r
34e4e297 219\r
8e3bc754 220 @retval EFI_SUCCESS The function completed successfully.\r
221\r
222**/\r
53c71d09 223EFI_STATUS\r
224ReturnEBCStack(\r
8e3bc754 225 IN UINTN Index\r
53c71d09 226 );\r
227\r
8e3bc754 228/**\r
229 Allocates memory to hold all the EBC stacks.\r
230\r
34e4e297 231 @retval EFI_SUCCESS The EBC stacks were allocated successfully.\r
8e3bc754 232 @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.\r
233\r
234**/\r
53c71d09 235EFI_STATUS\r
236InitEBCStack (\r
237 VOID\r
238 );\r
239\r
8e3bc754 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
53c71d09 246EFI_STATUS\r
247FreeEBCStack(\r
248 VOID\r
249 );\r
250\r
8e3bc754 251/**\r
34e4e297 252 Returns from the EBC stack associated with the Handle parameter.\r
253\r
8e3bc754 254 @param Handle Specifies the EFI handle to find the EBC stack with.\r
34e4e297 255\r
8e3bc754 256 @retval EFI_SUCCESS The function completed successfully.\r
257\r
258**/\r
53c71d09 259EFI_STATUS\r
260ReturnEBCStackByHandle(\r
8e3bc754 261 IN EFI_HANDLE Handle\r
53c71d09 262 );\r
34e4e297 263\r
53c71d09 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
f3f2e05d 271#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('e', 'b', 'c', 'p')\r
53c71d09 272\r
53c71d09 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