]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcInt.h
d1631f8e9b690ec2c3d671806256fb85a1cec618
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcInt.h
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EbcInt.h
15
16 Abstract:
17
18 Main routines for the EBC interpreter. Includes the initialization and
19 main interpreter routines.
20
21 --*/
22
23 #ifndef _EBC_INT_H_
24 #define _EBC_INT_H_
25
26 //
27 // The package level header files this module uses
28 //
29 #include <PiDxe.h>
30 //
31 // The protocols, PPI and GUID defintions for this module
32 //
33 #include <Protocol/DebugSupport.h>
34 #include <Protocol/Ebc.h>
35 //
36 // The Library classes this module consumes
37 //
38 #include <Library/BaseLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/BaseMemoryLib.h>
42 #include <Library/UefiBootServicesTableLib.h>
43 #include <Library/MemoryAllocationLib.h>
44
45 typedef INT64 VM_REGISTER;
46 typedef UINT8 *VMIP; // instruction pointer for the VM
47 typedef UINT32 EXCEPTION_FLAGS;
48
49 typedef struct {
50 VM_REGISTER R[8]; // General purpose registers.
51 UINT64 Flags; // Flags register:
52 // 0 Set to 1 if the result of the last compare was true
53 // 1 Set to 1 if stepping
54 // 2..63 Reserved.
55 VMIP Ip; // Instruction pointer.
56 UINTN LastException; //
57 EXCEPTION_FLAGS ExceptionFlags; // to keep track of exceptions
58 UINT32 StopFlags;
59 UINT32 CompilerVersion; // via break(6)
60 UINTN HighStackBottom; // bottom of the upper stack
61 UINTN LowStackTop; // top of the lower stack
62 UINT64 StackRetAddr; // location of final return address on stack
63 UINTN *StackMagicPtr; // pointer to magic value on stack to detect corruption
64 EFI_HANDLE ImageHandle; // for this EBC driver
65 EFI_SYSTEM_TABLE *SystemTable; // for debugging only
66 UINTN LastAddrConverted; // for debug
67 UINTN LastAddrConvertedValue; // for debug
68 VOID *FramePtr;
69 VOID *EntryPoint; // entry point of EBC image
70 UINTN ImageBase;
71 VOID *StackPool;
72 VOID *StackTop;
73 } VM_CONTEXT;
74
75 extern VM_CONTEXT *mVmPtr;
76
77 //
78 // Bits of exception flags field of VM context
79 //
80 #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue
81 #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue
82 #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem
83 #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return
84 //
85 // Flags passed to the internal create-thunks function.
86 //
87 #define FLAG_THUNK_ENTRY_POINT 0x01 // thunk for an image entry point
88 #define FLAG_THUNK_PROTOCOL 0x00 // thunk for an EBC protocol service
89 //
90 // Put this value at the bottom of the VM's stack gap so we can check it on
91 // occasion to make sure the stack has not been corrupted.
92 //
93 #define VM_STACK_KEY_VALUE 0xDEADBEEF
94
95 EFI_STATUS
96 EbcCreateThunks (
97 IN EFI_HANDLE ImageHandle,
98 IN VOID *EbcEntryPoint,
99 OUT VOID **Thunk,
100 IN UINT32 Flags
101 )
102 ;
103
104 EFI_STATUS
105 EbcAddImageThunk (
106 IN EFI_HANDLE ImageHandle,
107 IN VOID *ThunkBuffer,
108 IN UINT32 ThunkSize
109 )
110 ;
111
112 //
113 // The interpreter calls these when an exception is detected,
114 // or as a periodic callback.
115 //
116 EFI_STATUS
117 EbcDebugSignalException (
118 IN EFI_EXCEPTION_TYPE ExceptionType,
119 IN EXCEPTION_FLAGS ExceptionFlags,
120 IN VM_CONTEXT *VmPtr
121 )
122 ;
123
124 //
125 // Define a constant of how often to call the debugger periodic callback
126 // function.
127 //
128 #define EFI_TIMER_UNIT_1MS (1000 * 10)
129 #define EBC_VM_PERIODIC_CALLBACK_RATE (1000 * EFI_TIMER_UNIT_1MS)
130 #define STACK_POOL_SIZE (1024 * 1020)
131 #define MAX_STACK_NUM 4
132
133 EFI_STATUS
134 EbcDebugSignalPeriodic (
135 IN VM_CONTEXT *VmPtr
136 )
137 ;
138
139 //
140 // External low level functions that are native-processor dependent
141 //
142 UINTN
143 EbcLLGetEbcEntryPoint (
144 VOID
145 )
146 ;
147
148 UINTN
149 EbcLLGetStackPointer (
150 VOID
151 )
152 ;
153
154 VOID
155 EbcLLCALLEXNative (
156 IN UINTN CallAddr,
157 IN UINTN EbcSp,
158 IN VOID *FramePtr
159 )
160 ;
161
162 VOID
163 EbcLLCALLEX (
164 IN VM_CONTEXT *VmPtr,
165 IN UINTN CallAddr,
166 IN UINTN EbcSp,
167 IN VOID *FramePtr,
168 IN UINT8 Size
169 )
170 ;
171
172 INT64
173 EbcLLGetReturnValue (
174 VOID
175 )
176 ;
177
178 EFI_STATUS
179 GetEBCStack(
180 EFI_HANDLE Handle,
181 VOID **StackBuffer,
182 UINTN *BufferIndex
183 );
184
185 EFI_STATUS
186 ReturnEBCStack(
187 UINTN Index
188 );
189
190 EFI_STATUS
191 InitEBCStack (
192 VOID
193 );
194
195 EFI_STATUS
196 FreeEBCStack(
197 VOID
198 );
199
200 EFI_STATUS
201 ReturnEBCStackByHandle(
202 EFI_HANDLE Handle
203 );
204 //
205 // Defines for a simple EBC debugger interface
206 //
207 typedef struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL;
208
209 #define EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID \
210 { \
211 0x2a72d11e, 0x7376, 0x40f6, { 0x9c, 0x68, 0x23, 0xfa, 0x2f, 0xe3, 0x63, 0xf1 } \
212 }
213
214 typedef
215 EFI_STATUS
216 (*EBC_DEBUGGER_SIGNAL_EXCEPTION) (
217 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL * This,
218 IN VM_CONTEXT * VmPtr,
219 IN EFI_EXCEPTION_TYPE ExceptionType
220 );
221
222 typedef
223 VOID
224 (*EBC_DEBUGGER_DEBUG) (
225 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL * This,
226 IN VM_CONTEXT * VmPtr
227 );
228
229 typedef
230 UINT32
231 (*EBC_DEBUGGER_DASM) (
232 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL * This,
233 IN VM_CONTEXT * VmPtr,
234 IN UINT16 *DasmString OPTIONAL,
235 IN UINT32 DasmStringSize
236 );
237
238 //
239 // This interface allows you to configure the EBC debug support
240 // driver. For example, turn on or off saving and printing of
241 // delta VM even if called. Or to even disable the entire interface,
242 // in which case all functions become no-ops.
243 //
244 typedef
245 EFI_STATUS
246 (*EBC_DEBUGGER_CONFIGURE) (
247 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL * This,
248 IN UINT32 ConfigId,
249 IN UINTN ConfigValue
250 );
251
252 //
253 // Prototype for the actual EBC debug support protocol interface
254 //
255 struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL {
256 EBC_DEBUGGER_DEBUG Debugger;
257 EBC_DEBUGGER_SIGNAL_EXCEPTION SignalException;
258 EBC_DEBUGGER_DASM Dasm;
259 EBC_DEBUGGER_CONFIGURE Configure;
260 };
261
262 typedef struct {
263 EFI_EBC_PROTOCOL *This;
264 VOID *EntryPoint;
265 EFI_HANDLE ImageHandle;
266 VM_CONTEXT VmContext;
267 } EFI_EBC_THUNK_DATA;
268
269 #define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('e', 'b', 'c', 'p')
270
271 struct _EBC_PROTOCOL_PRIVATE_DATA {
272 UINT32 Signature;
273 EFI_EBC_PROTOCOL EbcProtocol;
274 UINTN StackBase;
275 UINTN StackTop;
276 UINTN StackSize;
277 } ;
278
279 #define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
280 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)
281
282
283 #endif // #ifndef _EBC_INT_H_