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