2 * Copyright (C) 2016 Veertu Inc,
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef HVF_X86_DECODE_H
19 #define HVF_X86_DECODE_H
24 typedef enum x86_prefix
{
30 PREFIX_CS_SEG_OVEERIDE
= 0x2e,
31 PREFIX_SS_SEG_OVEERIDE
= 0x36,
32 PREFIX_DS_SEG_OVEERIDE
= 0x3e,
33 PREFIX_ES_SEG_OVEERIDE
= 0x26,
34 PREFIX_FS_SEG_OVEERIDE
= 0x64,
35 PREFIX_GS_SEG_OVEERIDE
= 0x65,
37 PREFIX_OP_SIZE_OVERRIDE
= 0x66,
39 PREFIX_ADDR_SIZE_OVERRIDE
= 0x67,
45 X86_DECODE_CMD_INVL
= 0,
48 X86_DECODE_CMD_PUSH_SEG
,
50 X86_DECODE_CMD_POP_SEG
,
54 X86_DECODE_CMD_CALL_NEAR
,
55 X86_DECODE_CMD_CALL_NEAR_ABS_INDIRECT
,
56 X86_DECODE_CMD_CALL_FAR_ABS_INDIRECT
,
57 X86_DECODE_CMD_CALL_FAR
,
73 X86_DECODE_CMD_JMP_NEAR
,
74 X86_DECODE_CMD_JMP_NEAR_ABS_INDIRECT
,
75 X86_DECODE_CMD_JMP_FAR
,
76 X86_DECODE_CMD_JMP_FAR_ABS_INDIRECT
,
81 X86_DECODE_CMD_MOV_TO_SEG
,
82 X86_DECODE_CMD_MOV_FROM_SEG
,
99 X86_DECODE_CMD_RDTSCP
,
100 X86_DECODE_CMD_INVLPG
,
101 X86_DECODE_CMD_MOV_TO_CR
,
102 X86_DECODE_CMD_MOV_FROM_CR
,
103 X86_DECODE_CMD_MOV_TO_DR
,
104 X86_DECODE_CMD_MOV_FROM_DR
,
105 X86_DECODE_CMD_PUSHF
,
107 X86_DECODE_CMD_CPUID
,
121 X86_DECODE_CMD_IMUL_3
,
122 X86_DECODE_CMD_IMUL_2
,
123 X86_DECODE_CMD_IMUL_1
,
129 X86_DECODE_CMD_BSWAP
,
131 X86_DECODE_CMD_RDTSC
,
132 X86_DECODE_CMD_RDMSR
,
133 X86_DECODE_CMD_WRMSR
,
134 X86_DECODE_CMD_ENTER
,
135 X86_DECODE_CMD_LEAVE
,
145 X86_DECODE_CMD_PUSHA
,
161 X86_DECODE_CMD_WBINVD
,
174 X86_DECODE_CMD_CMPXCHG8B
,
175 X86_DECODE_CMD_CMPXCHG
,
176 X86_DECODE_CMD_POPCNT
,
178 X86_DECODE_CMD_FNINIT
,
180 X86_DECODE_CMD_FLDxx
,
181 X86_DECODE_CMD_FNSTCW
,
182 X86_DECODE_CMD_FNSTSW
,
183 X86_DECODE_CMD_FNSETPM
,
184 X86_DECODE_CMD_FSAVE
,
185 X86_DECODE_CMD_FRSTOR
,
186 X86_DECODE_CMD_FXSAVE
,
187 X86_DECODE_CMD_FXRSTOR
,
193 X86_DECODE_CMD_MFENCE
,
194 X86_DECODE_CMD_SFENCE
,
195 X86_DECODE_CMD_LFENCE
,
196 X86_DECODE_CMD_PREFETCH
,
197 X86_DECODE_CMD_CLFLUSH
,
200 X86_DECODE_CMD_FUCOM
,
201 X86_DECODE_CMD_FUCOMI
,
202 X86_DECODE_CMD_FLDCW
,
205 X86_DECODE_CMD_FCMOV
,
206 X86_DECODE_CMD_FRNDINT
,
212 const char *decode_cmd_to_string(enum x86_decode_cmd cmd
);
214 typedef struct x86_modrm
{
223 } __attribute__ ((__packed__
)) x86_modrm
;
225 typedef struct x86_sib
{
234 } __attribute__ ((__packed__
)) x86_sib
;
236 typedef struct x86_rex
{
247 } __attribute__ ((__packed__
)) x86_rex
;
249 typedef enum x86_var_type
{
255 /* for floating point computations */
262 typedef struct x86_decode_op
{
263 enum x86_var_type type
;
272 typedef struct x86_decode
{
276 enum x86_decode_cmd cmd
;
281 int op_size_override
;
282 int addr_size_override
;
283 int segment_override
;
284 int control_change_inst
;
289 uint32_t displacement
;
290 uint8_t displacement_size
;
295 struct x86_modrm modrm
;
296 struct x86_decode_op op
[4];
302 uint64_t sign(uint64_t val
, int size
);
304 uint32_t decode_instruction(CPUX86State
*env
, struct x86_decode
*decode
);
306 target_ulong
get_reg_ref(CPUX86State
*env
, int reg
, int rex
, int is_extended
,
308 target_ulong
get_reg_val(CPUX86State
*env
, int reg
, int rex
, int is_extended
,
310 void calc_modrm_operand(CPUX86State
*env
, struct x86_decode
*decode
,
311 struct x86_decode_op
*op
);
312 target_ulong
decode_linear_addr(CPUX86State
*env
, struct x86_decode
*decode
,
313 target_ulong addr
, enum X86Seg seg
);
315 void init_decoder(void);
316 void calc_modrm_operand16(CPUX86State
*env
, struct x86_decode
*decode
,
317 struct x86_decode_op
*op
);
318 void calc_modrm_operand32(CPUX86State
*env
, struct x86_decode
*decode
,
319 struct x86_decode_op
*op
);
320 void calc_modrm_operand64(CPUX86State
*env
, struct x86_decode
*decode
,
321 struct x86_decode_op
*op
);
322 void set_addressing_size(CPUX86State
*env
, struct x86_decode
*decode
);
323 void set_operand_size(CPUX86State
*env
, struct x86_decode
*decode
);