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