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