]>
Commit | Line | Data |
---|---|---|
d1f95000 | 1 | /** @file\r |
2 | Describes the protocol interface to the EBC interpreter.\r | |
3 | \r | |
9df063a0 HT |
4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials \r | |
d1f95000 | 6 | are licensed and made available under the terms and conditions of the BSD License \r |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
d1f95000 | 13 | **/\r |
14 | \r | |
15 | #ifndef __EFI_EBC_PROTOCOL_H__\r | |
16 | #define __EFI_EBC_PROTOCOL_H__\r | |
17 | \r | |
18 | #define EFI_EBC_INTERPRETER_PROTOCOL_GUID \\r | |
19 | { \\r | |
20 | 0x13AC6DD1, 0x73D0, 0x11D4, {0xB0, 0x6B, 0x00, 0xAA, 0x00, 0xBD, 0x6D, 0xE7 } \\r | |
21 | }\r | |
22 | \r | |
3e2c7843 PB |
23 | //\r |
24 | // Define OPCODES\r | |
25 | //\r | |
26 | #define OPCODE_BREAK 0x00\r | |
27 | #define OPCODE_JMP 0x01\r | |
28 | #define OPCODE_JMP8 0x02\r | |
29 | #define OPCODE_CALL 0x03\r | |
30 | #define OPCODE_RET 0x04\r | |
31 | #define OPCODE_CMPEQ 0x05\r | |
32 | #define OPCODE_CMPLTE 0x06\r | |
33 | #define OPCODE_CMPGTE 0x07\r | |
34 | #define OPCODE_CMPULTE 0x08\r | |
35 | #define OPCODE_CMPUGTE 0x09\r | |
36 | #define OPCODE_NOT 0x0A\r | |
37 | #define OPCODE_NEG 0x0B\r | |
38 | #define OPCODE_ADD 0x0C\r | |
39 | #define OPCODE_SUB 0x0D\r | |
40 | #define OPCODE_MUL 0x0E\r | |
41 | #define OPCODE_MULU 0x0F\r | |
42 | #define OPCODE_DIV 0x10\r | |
43 | #define OPCODE_DIVU 0x11\r | |
44 | #define OPCODE_MOD 0x12\r | |
45 | #define OPCODE_MODU 0x13\r | |
46 | #define OPCODE_AND 0x14\r | |
47 | #define OPCODE_OR 0x15\r | |
48 | #define OPCODE_XOR 0x16\r | |
49 | #define OPCODE_SHL 0x17\r | |
50 | #define OPCODE_SHR 0x18\r | |
51 | #define OPCODE_ASHR 0x19\r | |
52 | #define OPCODE_EXTNDB 0x1A\r | |
53 | #define OPCODE_EXTNDW 0x1B\r | |
54 | #define OPCODE_EXTNDD 0x1C\r | |
55 | #define OPCODE_MOVBW 0x1D\r | |
56 | #define OPCODE_MOVWW 0x1E\r | |
57 | #define OPCODE_MOVDW 0x1F\r | |
58 | #define OPCODE_MOVQW 0x20\r | |
59 | #define OPCODE_MOVBD 0x21\r | |
60 | #define OPCODE_MOVWD 0x22\r | |
61 | #define OPCODE_MOVDD 0x23\r | |
62 | #define OPCODE_MOVQD 0x24\r | |
63 | #define OPCODE_MOVSNW 0x25 // Move signed natural with word index\r | |
64 | #define OPCODE_MOVSND 0x26 // Move signed natural with dword index\r | |
65 | //\r | |
66 | // #define OPCODE_27 0x27\r | |
67 | //\r | |
68 | #define OPCODE_MOVQQ 0x28 // Does this go away?\r | |
69 | #define OPCODE_LOADSP 0x29\r | |
70 | #define OPCODE_STORESP 0x2A\r | |
71 | #define OPCODE_PUSH 0x2B\r | |
72 | #define OPCODE_POP 0x2C\r | |
73 | #define OPCODE_CMPIEQ 0x2D\r | |
74 | #define OPCODE_CMPILTE 0x2E\r | |
75 | #define OPCODE_CMPIGTE 0x2F\r | |
76 | #define OPCODE_CMPIULTE 0x30\r | |
77 | #define OPCODE_CMPIUGTE 0x31\r | |
78 | #define OPCODE_MOVNW 0x32\r | |
79 | #define OPCODE_MOVND 0x33\r | |
80 | //\r | |
81 | // #define OPCODE_34 0x34\r | |
82 | //\r | |
83 | #define OPCODE_PUSHN 0x35\r | |
84 | #define OPCODE_POPN 0x36\r | |
85 | #define OPCODE_MOVI 0x37\r | |
86 | #define OPCODE_MOVIN 0x38\r | |
87 | #define OPCODE_MOVREL 0x39\r | |
88 | \r | |
89 | //\r | |
90 | // Bit masks for opcode encodings\r | |
91 | //\r | |
92 | #define OPCODE_M_OPCODE 0x3F // bits of interest for first level decode\r | |
93 | #define OPCODE_M_IMMDATA 0x80\r | |
94 | #define OPCODE_M_IMMDATA64 0x40\r | |
95 | #define OPCODE_M_64BIT 0x40 // for CMP\r | |
96 | #define OPCODE_M_RELADDR 0x10 // for CALL instruction\r | |
97 | #define OPCODE_M_CMPI32_DATA 0x80 // for CMPI\r | |
98 | #define OPCODE_M_CMPI64 0x40 // for CMPI 32 or 64 bit comparison\r | |
99 | #define OPERAND_M_MOVIN_N 0x80\r | |
100 | #define OPERAND_M_CMPI_INDEX 0x10\r | |
101 | \r | |
102 | //\r | |
103 | // Masks for instructions that encode presence of indexes for operand1 and/or\r | |
104 | // operand2.\r | |
105 | //\r | |
106 | #define OPCODE_M_IMMED_OP1 0x80\r | |
107 | #define OPCODE_M_IMMED_OP2 0x40\r | |
108 | \r | |
109 | //\r | |
110 | // Bit masks for operand encodings\r | |
111 | //\r | |
112 | #define OPERAND_M_INDIRECT1 0x08\r | |
113 | #define OPERAND_M_INDIRECT2 0x80\r | |
114 | #define OPERAND_M_OP1 0x07\r | |
115 | #define OPERAND_M_OP2 0x70\r | |
116 | \r | |
117 | //\r | |
118 | // Masks for data manipulation instructions\r | |
119 | //\r | |
120 | #define DATAMANIP_M_64 0x40 // 64-bit width operation\r | |
121 | #define DATAMANIP_M_IMMDATA 0x80\r | |
122 | \r | |
123 | //\r | |
124 | // For MOV instructions, need a mask for the opcode when immediate\r | |
125 | // data applies to R2.\r | |
126 | //\r | |
127 | #define OPCODE_M_IMMED_OP2 0x40\r | |
128 | \r | |
129 | //\r | |
130 | // The MOVI/MOVIn instructions use bit 6 of operands byte to indicate\r | |
131 | // if an index is present. Then bits 4 and 5 are used to indicate the width\r | |
132 | // of the move.\r | |
133 | //\r | |
134 | #define MOVI_M_IMMDATA 0x40\r | |
135 | #define MOVI_M_DATAWIDTH 0xC0\r | |
136 | #define MOVI_DATAWIDTH16 0x40\r | |
137 | #define MOVI_DATAWIDTH32 0x80\r | |
138 | #define MOVI_DATAWIDTH64 0xC0\r | |
139 | #define MOVI_M_MOVEWIDTH 0x30\r | |
140 | #define MOVI_MOVEWIDTH8 0x00\r | |
141 | #define MOVI_MOVEWIDTH16 0x10\r | |
142 | #define MOVI_MOVEWIDTH32 0x20\r | |
143 | #define MOVI_MOVEWIDTH64 0x30\r | |
144 | \r | |
145 | //\r | |
146 | // Masks for CALL instruction encodings\r | |
147 | //\r | |
148 | #define OPERAND_M_RELATIVE_ADDR 0x10\r | |
149 | #define OPERAND_M_NATIVE_CALL 0x20\r | |
150 | \r | |
151 | //\r | |
152 | // Masks for decoding push/pop instructions\r | |
153 | //\r | |
154 | #define PUSHPOP_M_IMMDATA 0x80 // opcode bit indicating immediate data\r | |
155 | #define PUSHPOP_M_64 0x40 // opcode bit indicating 64-bit operation\r | |
156 | //\r | |
157 | // Mask for operand of JMP instruction\r | |
158 | //\r | |
159 | #define JMP_M_RELATIVE 0x10\r | |
160 | #define JMP_M_CONDITIONAL 0x80\r | |
161 | #define JMP_M_CS 0x40\r | |
162 | \r | |
163 | //\r | |
164 | // Macros to determine if a given operand is indirect\r | |
165 | //\r | |
166 | #define OPERAND1_INDIRECT(op) ((op) & OPERAND_M_INDIRECT1)\r | |
167 | #define OPERAND2_INDIRECT(op) ((op) & OPERAND_M_INDIRECT2)\r | |
168 | \r | |
169 | //\r | |
170 | // Macros to extract the operands from second byte of instructions\r | |
171 | //\r | |
172 | #define OPERAND1_REGNUM(op) ((op) & OPERAND_M_OP1)\r | |
173 | #define OPERAND2_REGNUM(op) (((op) & OPERAND_M_OP2) >> 4)\r | |
174 | \r | |
175 | #define OPERAND1_CHAR(op) ('0' + OPERAND1_REGNUM (op))\r | |
176 | #define OPERAND2_CHAR(op) ('0' + OPERAND2_REGNUM (op))\r | |
177 | \r | |
178 | //\r | |
179 | // Condition masks usually for byte 1 encodings of code\r | |
180 | //\r | |
181 | #define CONDITION_M_CONDITIONAL 0x80\r | |
182 | #define CONDITION_M_CS 0x40\r | |
183 | \r | |
99e8ed21 | 184 | ///\r |
185 | /// Protocol Guid Name defined in spec.\r | |
186 | ///\r | |
d1f95000 | 187 | #define EFI_EBC_PROTOCOL_GUID EFI_EBC_INTERPRETER_PROTOCOL_GUID\r |
188 | \r | |
99e8ed21 | 189 | ///\r |
190 | /// Define for forward reference.\r | |
191 | ///\r | |
d1f95000 | 192 | typedef struct _EFI_EBC_PROTOCOL EFI_EBC_PROTOCOL;\r |
193 | \r | |
194 | /**\r | |
4ca9b6c4 LG |
195 | Creates a thunk for an EBC entry point, returning the address of the thunk.\r |
196 | \r | |
197 | A PE32+ EBC image, like any other PE32+ image, contains an optional header that specifies the\r | |
630b4187 | 198 | entry point for image execution. However, for EBC images, this is the entry point of EBC\r |
199 | instructions, so is not directly executable by the native processor. Therefore, when an EBC image is\r | |
200 | loaded, the loader must call this service to get a pointer to native code (thunk) that can be executed,\r | |
4ca9b6c4 LG |
201 | which will invoke the interpreter to begin execution at the original EBC entry point.\r |
202 | \r | |
203 | @param This A pointer to the EFI_EBC_PROTOCOL instance.\r | |
204 | @param ImageHandle Handle of image for which the thunk is being created.\r | |
205 | @param EbcEntryPoint Address of the actual EBC entry point or protocol service the thunk should call.\r | |
f754f721 | 206 | @param Thunk Returned pointer to a thunk created.\r |
4ca9b6c4 LG |
207 | \r |
208 | @retval EFI_SUCCESS The function completed successfully.\r | |
209 | @retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.\r | |
210 | @retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.\r | |
d1f95000 | 211 | **/\r |
212 | typedef\r | |
213 | EFI_STATUS\r | |
8b13229b | 214 | (EFIAPI *EFI_EBC_CREATE_THUNK)(\r |
d1f95000 | 215 | IN EFI_EBC_PROTOCOL *This,\r |
216 | IN EFI_HANDLE ImageHandle,\r | |
217 | IN VOID *EbcEntryPoint,\r | |
218 | OUT VOID **Thunk\r | |
219 | );\r | |
220 | \r | |
221 | /**\r | |
4ca9b6c4 | 222 | Called prior to unloading an EBC image from memory.\r |
d1f95000 | 223 | \r |
4ca9b6c4 LG |
224 | This function is called after an EBC image has exited, but before the image is actually unloaded. It\r |
225 | is intended to provide the interpreter with the opportunity to perform any cleanup that may be\r | |
226 | necessary as a result of loading and executing the image.\r | |
d1f95000 | 227 | \r |
4ca9b6c4 LG |
228 | @param This A pointer to the EFI_EBC_PROTOCOL instance.\r |
229 | @param ImageHandle Image handle of the EBC image that is being unloaded from memory.\r | |
d1f95000 | 230 | \r |
4ca9b6c4 LG |
231 | @retval EFI_SUCCESS The function completed successfully.\r |
232 | @retval EFI_INVALID_PARAMETER Image handle is not recognized as belonging \r | |
233 | to an EBC image that has been executed.\r | |
d1f95000 | 234 | **/\r |
235 | typedef\r | |
236 | EFI_STATUS\r | |
8b13229b | 237 | (EFIAPI *EFI_EBC_UNLOAD_IMAGE)(\r |
d1f95000 | 238 | IN EFI_EBC_PROTOCOL *This,\r |
239 | IN EFI_HANDLE ImageHandle\r | |
240 | );\r | |
241 | \r | |
242 | /**\r | |
4ca9b6c4 LG |
243 | This is the prototype for the Flush callback routine. A pointer to a routine \r |
244 | of this type is passed to the EBC EFI_EBC_REGISTER_ICACHE_FLUSH protocol service.\r | |
d1f95000 | 245 | \r |
4ca9b6c4 LG |
246 | @param Start The beginning physical address to flush from the processor's instruction cache.\r |
247 | @param Length The number of bytes to flush from the processor's instruction cache.\r | |
d1f95000 | 248 | \r |
4ca9b6c4 | 249 | @retval EFI_SUCCESS The function completed successfully.\r |
d1f95000 | 250 | \r |
251 | **/\r | |
252 | typedef\r | |
253 | EFI_STATUS\r | |
8b13229b | 254 | (EFIAPI *EBC_ICACHE_FLUSH)(\r |
d1f95000 | 255 | IN EFI_PHYSICAL_ADDRESS Start,\r |
256 | IN UINT64 Length\r | |
257 | );\r | |
258 | \r | |
259 | /**\r | |
74fec708 LG |
260 | Registers a callback function that the EBC interpreter calls to flush \r |
261 | the processor instruction cache following creation of thunks.\r | |
d1f95000 | 262 | \r |
4ca9b6c4 LG |
263 | @param This A pointer to the EFI_EBC_PROTOCOL instance.\r |
264 | @param Flush Pointer to a function of type EBC_ICACH_FLUSH.\r | |
d1f95000 | 265 | \r |
4ca9b6c4 | 266 | @retval EFI_SUCCESS The function completed successfully.\r |
d1f95000 | 267 | \r |
268 | **/\r | |
269 | typedef\r | |
270 | EFI_STATUS\r | |
8b13229b | 271 | (EFIAPI *EFI_EBC_REGISTER_ICACHE_FLUSH)(\r |
d1f95000 | 272 | IN EFI_EBC_PROTOCOL *This,\r |
273 | IN EBC_ICACHE_FLUSH Flush\r | |
274 | );\r | |
275 | \r | |
276 | /**\r | |
4ca9b6c4 LG |
277 | Called to get the version of the interpreter.\r |
278 | \r | |
279 | This function is called to get the version of the loaded EBC interpreter. The value and format of the\r | |
280 | returned version is identical to that returned by the EBC BREAK 1 instruction.\r | |
d1f95000 | 281 | \r |
4ca9b6c4 | 282 | @param This A pointer to the EFI_EBC_PROTOCOL instance. \r |
f754f721 | 283 | @param Version Pointer to where to store the returned version of the interpreter.\r |
d1f95000 | 284 | \r |
4ca9b6c4 LG |
285 | @retval EFI_SUCCESS The function completed successfully.\r |
286 | @retval EFI_INVALID_PARAMETER Version pointer is NULL.\r | |
d1f95000 | 287 | \r |
288 | **/\r | |
289 | typedef\r | |
290 | EFI_STATUS\r | |
8b13229b | 291 | (EFIAPI *EFI_EBC_GET_VERSION)(\r |
d1f95000 | 292 | IN EFI_EBC_PROTOCOL *This,\r |
293 | IN OUT UINT64 *Version\r | |
294 | );\r | |
295 | \r | |
44717a39 | 296 | ///\r |
297 | /// The EFI EBC protocol provides services to load and execute EBC images, which will typically be\r | |
298 | /// loaded into option ROMs. The image loader will load the EBC image, perform standard relocations,\r | |
299 | /// and invoke the CreateThunk() service to create a thunk for the EBC image's entry point. The\r | |
300 | /// image can then be run using the standard EFI start image services.\r | |
301 | ///\r | |
d1f95000 | 302 | struct _EFI_EBC_PROTOCOL {\r |
303 | EFI_EBC_CREATE_THUNK CreateThunk;\r | |
304 | EFI_EBC_UNLOAD_IMAGE UnloadImage;\r | |
305 | EFI_EBC_REGISTER_ICACHE_FLUSH RegisterICacheFlush;\r | |
306 | EFI_EBC_GET_VERSION GetVersion;\r | |
307 | };\r | |
308 | \r | |
309 | //\r | |
310 | // Extern the global EBC protocol GUID\r | |
311 | //\r | |
312 | extern EFI_GUID gEfiEbcProtocolGuid;\r | |
313 | \r | |
314 | #endif\r |