]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Ebc/Dxe/EbcExecute.h
Fix several typos to make PeiVariable pass build.
[mirror_edk2.git] / MdeModulePkg / Universal / Ebc / Dxe / EbcExecute.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 EbcExecute.h
15
16 Abstract:
17
18 Header file for Virtual Machine support. Contains EBC defines that can
19 be of use to a disassembler for the most part. Also provides function
20 prototypes for VM functions.
21
22 --*/
23
24 #ifndef _EBC_EXECUTE_H_
25 #define _EBC_EXECUTE_H_
26
27 //
28 // VM major/minor version
29 //
30 #define VM_MAJOR_VERSION 1
31 #define VM_MINOR_VERSION 0
32
33 //
34 // Macros to check and set alignment
35 //
36 #define ASSERT_ALIGNED(addr, size) ASSERT (!((UINT32) (addr) & (size - 1)))
37 #define IS_ALIGNED(addr, size) !((UINT32) (addr) & (size - 1))
38
39 //
40 // Define a macro to get the operand. Then we can change it to be either a
41 // direct read or have it call a function to read memory.
42 //
43 #define GETOPERANDS(pVM) (UINT8) (*(UINT8 *) (pVM->Ip + 1))
44 #define GETOPCODE(pVM) (UINT8) (*(UINT8 *) pVM->Ip)
45
46 //
47 // Bit masks for opcode encodings
48 //
49 #define OPCODE_M_OPCODE 0x3F // bits of interest for first level decode
50 #define OPCODE_M_IMMDATA 0x80
51 #define OPCODE_M_IMMDATA64 0x40
52 #define OPCODE_M_64BIT 0x40 // for CMP
53 #define OPCODE_M_RELADDR 0x10 // for CALL instruction
54 #define OPCODE_M_CMPI32_DATA 0x80 // for CMPI
55 #define OPCODE_M_CMPI64 0x40 // for CMPI 32 or 64 bit comparison
56 #define OPERAND_M_MOVIN_N 0x80
57 #define OPERAND_M_CMPI_INDEX 0x10
58
59 //
60 // Masks for instructions that encode presence of indexes for operand1 and/or
61 // operand2.
62 //
63 #define OPCODE_M_IMMED_OP1 0x80
64 #define OPCODE_M_IMMED_OP2 0x40
65
66 //
67 // Bit masks for operand encodings
68 //
69 #define OPERAND_M_INDIRECT1 0x08
70 #define OPERAND_M_INDIRECT2 0x80
71 #define OPERAND_M_OP1 0x07
72 #define OPERAND_M_OP2 0x70
73
74 //
75 // Masks for data manipulation instructions
76 //
77 #define DATAMANIP_M_64 0x40 // 64-bit width operation
78 #define DATAMANIP_M_IMMDATA 0x80
79
80 //
81 // For MOV instructions, need a mask for the opcode when immediate
82 // data applies to R2.
83 //
84 #define OPCODE_M_IMMED_OP2 0x40
85
86 //
87 // The MOVI/MOVIn instructions use bit 6 of operands byte to indicate
88 // if an index is present. Then bits 4 and 5 are used to indicate the width
89 // of the move.
90 //
91 #define MOVI_M_IMMDATA 0x40
92 #define MOVI_M_DATAWIDTH 0xC0
93 #define MOVI_DATAWIDTH16 0x40
94 #define MOVI_DATAWIDTH32 0x80
95 #define MOVI_DATAWIDTH64 0xC0
96 #define MOVI_M_MOVEWIDTH 0x30
97 #define MOVI_MOVEWIDTH8 0x00
98 #define MOVI_MOVEWIDTH16 0x10
99 #define MOVI_MOVEWIDTH32 0x20
100 #define MOVI_MOVEWIDTH64 0x30
101
102 //
103 // Masks for CALL instruction encodings
104 //
105 #define OPERAND_M_RELATIVE_ADDR 0x10
106 #define OPERAND_M_NATIVE_CALL 0x20
107
108 //
109 // Masks for decoding push/pop instructions
110 //
111 #define PUSHPOP_M_IMMDATA 0x80 // opcode bit indicating immediate data
112 #define PUSHPOP_M_64 0x40 // opcode bit indicating 64-bit operation
113 //
114 // Mask for operand of JMP instruction
115 //
116 #define JMP_M_RELATIVE 0x10
117 #define JMP_M_CONDITIONAL 0x80
118 #define JMP_M_CS 0x40
119
120 //
121 // Macros to determine if a given operand is indirect
122 //
123 #define OPERAND1_INDIRECT(op) ((op) & OPERAND_M_INDIRECT1)
124 #define OPERAND2_INDIRECT(op) ((op) & OPERAND_M_INDIRECT2)
125
126 //
127 // Macros to extract the operands from second byte of instructions
128 //
129 #define OPERAND1_REGNUM(op) ((op) & OPERAND_M_OP1)
130 #define OPERAND2_REGNUM(op) (((op) & OPERAND_M_OP2) >> 4)
131
132 #define OPERAND1_CHAR(op) ('0' + OPERAND1_REGNUM (op))
133 #define OPERAND2_CHAR(op) ('0' + OPERAND2_REGNUM (op))
134
135 #define OPERAND1_REGDATA(pvm, op) pvm->R[OPERAND1_REGNUM (op)]
136 #define OPERAND2_REGDATA(pvm, op) pvm->R[OPERAND2_REGNUM (op)]
137
138 //
139 // Condition masks usually for byte 1 encodings of code
140 //
141 #define CONDITION_M_CONDITIONAL 0x80
142 #define CONDITION_M_CS 0x40
143
144 //
145 // Bits in the VM->StopFlags field
146 //
147 #define STOPFLAG_APP_DONE 0x0001
148 #define STOPFLAG_BREAKPOINT 0x0002
149 #define STOPFLAG_INVALID_BREAK 0x0004
150 #define STOPFLAG_BREAK_ON_CALLEX 0x0008
151
152 //
153 // Masks for working with the VM flags register
154 //
155 #define VMFLAGS_CC 0x0001 // condition flag
156 #define VMFLAGS_STEP 0x0002 // step instruction mode
157 #define VMFLAGS_ALL_VALID (VMFLAGS_CC | VMFLAGS_STEP)
158
159 //
160 // Macros for operating on the VM flags register
161 //
162 #define VMFLAG_SET(pVM, Flag) (pVM->Flags |= (Flag))
163 #define VMFLAG_ISSET(pVM, Flag) ((pVM->Flags & (Flag)) ? 1 : 0)
164 #define VMFLAG_CLEAR(pVM, Flag) (pVM->Flags &= ~(Flag))
165
166 //
167 // Debug macro
168 //
169 #define EBCMSG(s) gST->ConOut->OutputString (gST->ConOut, s)
170
171 //
172 // Define OPCODES
173 //
174 #define OPCODE_BREAK 0x00
175 #define OPCODE_JMP 0x01
176 #define OPCODE_JMP8 0x02
177 #define OPCODE_CALL 0x03
178 #define OPCODE_RET 0x04
179 #define OPCODE_CMPEQ 0x05
180 #define OPCODE_CMPLTE 0x06
181 #define OPCODE_CMPGTE 0x07
182 #define OPCODE_CMPULTE 0x08
183 #define OPCODE_CMPUGTE 0x09
184 #define OPCODE_NOT 0x0A
185 #define OPCODE_NEG 0x0B
186 #define OPCODE_ADD 0x0C
187 #define OPCODE_SUB 0x0D
188 #define OPCODE_MUL 0x0E
189 #define OPCODE_MULU 0x0F
190 #define OPCODE_DIV 0x10
191 #define OPCODE_DIVU 0x11
192 #define OPCODE_MOD 0x12
193 #define OPCODE_MODU 0x13
194 #define OPCODE_AND 0x14
195 #define OPCODE_OR 0x15
196 #define OPCODE_XOR 0x16
197 #define OPCODE_SHL 0x17
198 #define OPCODE_SHR 0x18
199 #define OPCODE_ASHR 0x19
200 #define OPCODE_EXTNDB 0x1A
201 #define OPCODE_EXTNDW 0x1B
202 #define OPCODE_EXTNDD 0x1C
203 #define OPCODE_MOVBW 0x1D
204 #define OPCODE_MOVWW 0x1E
205 #define OPCODE_MOVDW 0x1F
206 #define OPCODE_MOVQW 0x20
207 #define OPCODE_MOVBD 0x21
208 #define OPCODE_MOVWD 0x22
209 #define OPCODE_MOVDD 0x23
210 #define OPCODE_MOVQD 0x24
211 #define OPCODE_MOVSNW 0x25 // Move signed natural with word index
212 #define OPCODE_MOVSND 0x26 // Move signed natural with dword index
213 //
214 // #define OPCODE_27 0x27
215 //
216 #define OPCODE_MOVQQ 0x28 // Does this go away?
217 #define OPCODE_LOADSP 0x29
218 #define OPCODE_STORESP 0x2A
219 #define OPCODE_PUSH 0x2B
220 #define OPCODE_POP 0x2C
221 #define OPCODE_CMPIEQ 0x2D
222 #define OPCODE_CMPILTE 0x2E
223 #define OPCODE_CMPIGTE 0x2F
224 #define OPCODE_CMPIULTE 0x30
225 #define OPCODE_CMPIUGTE 0x31
226 #define OPCODE_MOVNW 0x32
227 #define OPCODE_MOVND 0x33
228 //
229 // #define OPCODE_34 0x34
230 //
231 #define OPCODE_PUSHN 0x35
232 #define OPCODE_POPN 0x36
233 #define OPCODE_MOVI 0x37
234 #define OPCODE_MOVIN 0x38
235 #define OPCODE_MOVREL 0x39
236
237 EFI_STATUS
238 EbcExecute (
239 IN VM_CONTEXT *VmPtr
240 )
241 ;
242
243
244
245 UINT64
246 GetVmVersion (
247 VOID
248 )
249 ;
250
251 EFI_STATUS
252 VmWriteMemN (
253 IN VM_CONTEXT *VmPtr,
254 IN UINTN Addr,
255 IN UINTN Data
256 )
257 ;
258
259 EFI_STATUS
260 VmWriteMem64 (
261 IN VM_CONTEXT *VmPtr,
262 UINTN Addr,
263 IN UINT64 Data
264 )
265 ;
266
267 //
268 // Define a protocol for an EBC VM test interface.
269 //
270 #define EFI_EBC_VM_TEST_PROTOCOL_GUID \
271 { \
272 0xAAEACCFDL, 0xF27B, 0x4C17, { 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52 } \
273 }
274
275 //
276 // Define for forward reference.
277 //
278 typedef struct _EFI_EBC_VM_TEST_PROTOCOL EFI_EBC_VM_TEST_PROTOCOL;
279
280 typedef
281 EFI_STATUS
282 (*EBC_VM_TEST_EXECUTE) (
283 IN EFI_EBC_VM_TEST_PROTOCOL * This,
284 IN VM_CONTEXT * VmPtr,
285 IN OUT UINTN *InstructionCount
286 );
287
288 typedef
289 EFI_STATUS
290 (*EBC_VM_TEST_ASM) (
291 IN EFI_EBC_VM_TEST_PROTOCOL * This,
292 IN CHAR16 *AsmText,
293 IN OUT INT8 *Buffer,
294 IN OUT UINTN *BufferLen
295 );
296
297 typedef
298 EFI_STATUS
299 (*EBC_VM_TEST_DASM) (
300 IN EFI_EBC_VM_TEST_PROTOCOL * This,
301 IN OUT CHAR16 *AsmText,
302 IN OUT INT8 *Buffer,
303 IN OUT UINTN *Len
304 );
305
306 //
307 // Prototype for the actual EBC test protocol interface
308 //
309 struct _EFI_EBC_VM_TEST_PROTOCOL {
310 EBC_VM_TEST_EXECUTE Execute;
311 EBC_VM_TEST_ASM Assemble;
312 EBC_VM_TEST_DASM Disassemble;
313 };
314
315 EFI_STATUS
316 EbcExecuteInstructions (
317 IN EFI_EBC_VM_TEST_PROTOCOL *This,
318 IN VM_CONTEXT *VmPtr,
319 IN OUT UINTN *InstructionCount
320 )
321 ;
322
323 #endif // ifndef _EBC_EXECUTE_H_