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