]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcInt.h
MdeModulePkg/PeiCore: allocate BootServicesCode memory for PE/COFF images
[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
53c71d09 36//\r
37// Flags passed to the internal create-thunks function.\r
38//\r
39#define FLAG_THUNK_ENTRY_POINT 0x01 // thunk for an image entry point\r
40#define FLAG_THUNK_PROTOCOL 0x00 // thunk for an EBC protocol service\r
41//\r
42// Put this value at the bottom of the VM's stack gap so we can check it on\r
43// occasion to make sure the stack has not been corrupted.\r
44//\r
45#define VM_STACK_KEY_VALUE 0xDEADBEEF\r
46\r
8e3bc754 47/**\r
48 Create thunks for an EBC image entry point, or an EBC protocol service.\r
49\r
50 @param ImageHandle Image handle for the EBC image. If not null, then\r
51 we're creating a thunk for an image entry point.\r
52 @param EbcEntryPoint Address of the EBC code that the thunk is to call\r
53 @param Thunk Returned thunk we create here\r
54 @param Flags Flags indicating options for creating the thunk\r
55\r
56 @retval EFI_SUCCESS The thunk was created successfully.\r
57 @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit\r
58 aligned.\r
59 @retval EFI_OUT_OF_RESOURCES There is not enough memory to created the EBC\r
60 Thunk.\r
61 @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough.\r
62\r
63**/\r
53c71d09 64EFI_STATUS\r
65EbcCreateThunks (\r
66 IN EFI_HANDLE ImageHandle,\r
67 IN VOID *EbcEntryPoint,\r
68 OUT VOID **Thunk,\r
ea7cb08c 69 IN UINT32 Flags\r
70 );\r
53c71d09 71\r
8e3bc754 72/**\r
73 Add a thunk to our list of thunks for a given image handle.\r
ead7e7dc 74 Also flush the instruction cache since we've written thunk code\r
8e3bc754 75 to memory that will be executed eventually.\r
76\r
77 @param ImageHandle The image handle to which the thunk is tied.\r
78 @param ThunkBuffer The buffer that has been created/allocated.\r
79 @param ThunkSize The size of the thunk memory allocated.\r
80\r
81 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
82 @retval EFI_SUCCESS The function completed successfully.\r
83\r
84**/\r
53c71d09 85EFI_STATUS\r
86EbcAddImageThunk (\r
ea7cb08c 87 IN EFI_HANDLE ImageHandle,\r
88 IN VOID *ThunkBuffer,\r
89 IN UINT32 ThunkSize\r
90 );\r
53c71d09 91\r
53c71d09 92//\r
93// Define a constant of how often to call the debugger periodic callback\r
94// function.\r
95//\r
96#define EFI_TIMER_UNIT_1MS (1000 * 10)\r
97#define EBC_VM_PERIODIC_CALLBACK_RATE (1000 * EFI_TIMER_UNIT_1MS)\r
98#define STACK_POOL_SIZE (1024 * 1020)\r
99#define MAX_STACK_NUM 4\r
100\r
53c71d09 101//\r
102// External low level functions that are native-processor dependent\r
34e4e297 103//\r
ea7cb08c 104/**\r
34e4e297 105 The VM thunk code stuffs an EBC entry point into a processor\r
8e3bc754 106 register. Since we can't use inline assembly to get it from\r
107 the interpreter C code, stuff it into the return value\r
108 register and return.\r
34e4e297 109\r
8e3bc754 110 @return The contents of the register in which the entry point is passed.\r
ea7cb08c 111\r
112**/\r
53c71d09 113UINTN\r
8e3bc754 114EFIAPI\r
53c71d09 115EbcLLGetEbcEntryPoint (\r
116 VOID\r
ea7cb08c 117 );\r
53c71d09 118\r
8e3bc754 119/**\r
120 This function is called to execute an EBC CALLEX instruction.\r
121 This instruction requires that we thunk out to external native\r
34e4e297 122 code. For x64, we switch stacks, copy the arguments to the stack\r
8e3bc754 123 and jump to the specified function.\r
124 On return, we restore the stack pointer to its original location.\r
125 Destroys no working registers.\r
126\r
127 @param CallAddr The function address.\r
128 @param EbcSp The new EBC stack pointer.\r
129 @param FramePtr The frame pointer.\r
ea7cb08c 130\r
fa97cbf4
JY
131 @return The unmodified value returned by the native code.\r
132\r
8e3bc754 133**/\r
fa97cbf4 134INT64\r
8e3bc754 135EFIAPI\r
53c71d09 136EbcLLCALLEXNative (\r
137 IN UINTN CallAddr,\r
138 IN UINTN EbcSp,\r
139 IN VOID *FramePtr\r
ea7cb08c 140 );\r
53c71d09 141\r
8e3bc754 142/**\r
143 This function is called to execute an EBC CALLEX instruction.\r
144 The function check the callee's content to see whether it is common native\r
145 code or a thunk to another piece of EBC code.\r
146 If the callee is common native code, use EbcLLCAllEXASM to manipulate,\r
147 otherwise, set the VM->IP to target EBC code directly to avoid another VM\r
148 be startup which cost time and stack space.\r
149\r
150 @param VmPtr Pointer to a VM context.\r
151 @param FuncAddr Callee's address\r
152 @param NewStackPointer New stack pointer after the call\r
153 @param FramePtr New frame pointer after the call\r
154 @param Size The size of call instruction\r
155\r
156**/\r
53c71d09 157VOID\r
158EbcLLCALLEX (\r
159 IN VM_CONTEXT *VmPtr,\r
8e3bc754 160 IN UINTN FuncAddr,\r
161 IN UINTN NewStackPointer,\r
53c71d09 162 IN VOID *FramePtr,\r
163 IN UINT8 Size\r
ea7cb08c 164 );\r
53c71d09 165\r
8e3bc754 166/**\r
ead7e7dc 167 Returns the stack index and buffer assosicated with the Handle parameter.\r
8e3bc754 168\r
34e4e297 169 @param Handle The EFI handle as the index to the EBC stack.\r
8e3bc754 170 @param StackBuffer A pointer to hold the returned stack buffer.\r
171 @param BufferIndex A pointer to hold the returned stack index.\r
34e4e297 172\r
8e3bc754 173 @retval EFI_OUT_OF_RESOURCES The Handle parameter does not correspond to any\r
174 existing EBC stack.\r
175 @retval EFI_SUCCESS The stack index and buffer were found and\r
176 returned to the caller.\r
177\r
178**/\r
53c71d09 179EFI_STATUS\r
180GetEBCStack(\r
8e3bc754 181 IN EFI_HANDLE Handle,\r
182 OUT VOID **StackBuffer,\r
183 OUT UINTN *BufferIndex\r
53c71d09 184 );\r
185\r
8e3bc754 186/**\r
34e4e297 187 Returns from the EBC stack by stack Index.\r
188\r
8e3bc754 189 @param Index Specifies which EBC stack to return from.\r
34e4e297 190\r
8e3bc754 191 @retval EFI_SUCCESS The function completed successfully.\r
192\r
193**/\r
53c71d09 194EFI_STATUS\r
195ReturnEBCStack(\r
8e3bc754 196 IN UINTN Index\r
53c71d09 197 );\r
198\r
8e3bc754 199/**\r
200 Allocates memory to hold all the EBC stacks.\r
201\r
34e4e297 202 @retval EFI_SUCCESS The EBC stacks were allocated successfully.\r
8e3bc754 203 @retval EFI_OUT_OF_RESOURCES Not enough memory available for EBC stacks.\r
204\r
205**/\r
53c71d09 206EFI_STATUS\r
207InitEBCStack (\r
208 VOID\r
209 );\r
210\r
8e3bc754 211/**\r
212 Free all EBC stacks allocated before.\r
213\r
214 @retval EFI_SUCCESS All the EBC stacks were freed.\r
215\r
216**/\r
53c71d09 217EFI_STATUS\r
218FreeEBCStack(\r
219 VOID\r
220 );\r
221\r
8e3bc754 222/**\r
34e4e297 223 Returns from the EBC stack associated with the Handle parameter.\r
224\r
8e3bc754 225 @param Handle Specifies the EFI handle to find the EBC stack with.\r
34e4e297 226\r
8e3bc754 227 @retval EFI_SUCCESS The function completed successfully.\r
228\r
229**/\r
53c71d09 230EFI_STATUS\r
231ReturnEBCStackByHandle(\r
8e3bc754 232 IN EFI_HANDLE Handle\r
53c71d09 233 );\r
34e4e297 234\r
53c71d09 235typedef struct {\r
236 EFI_EBC_PROTOCOL *This;\r
237 VOID *EntryPoint;\r
238 EFI_HANDLE ImageHandle;\r
239 VM_CONTEXT VmContext;\r
240} EFI_EBC_THUNK_DATA;\r
241\r
f3f2e05d 242#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('e', 'b', 'c', 'p')\r
53c71d09 243\r
53c71d09 244\r
245#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
246 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)\r
247\r
248\r
249#endif // #ifndef _EBC_INT_H_\r