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