4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
36 #define PREFIX_REPZ 0x01
37 #define PREFIX_REPNZ 0x02
38 #define PREFIX_LOCK 0x04
39 #define PREFIX_DATA 0x08
40 #define PREFIX_ADR 0x10
43 #define X86_64_ONLY(x) x
44 #define X86_64_DEF(...) __VA_ARGS__
45 #define CODE64(s) ((s)->code64)
46 #define REX_X(s) ((s)->rex_x)
47 #define REX_B(s) ((s)->rex_b)
48 /* XXX: gcc generates push/pop in some opcodes, so we cannot use them */
50 #define BUGGY_64(x) NULL
53 #define X86_64_ONLY(x) NULL
54 #define X86_64_DEF(...)
60 //#define MACRO_TEST 1
62 /* global register indexes */
63 static TCGv_ptr cpu_env
;
64 static TCGv cpu_A0
, cpu_cc_src
, cpu_cc_dst
, cpu_cc_tmp
;
65 static TCGv_i32 cpu_cc_op
;
67 static TCGv cpu_T
[2], cpu_T3
;
68 /* local register indexes (only used inside old micro ops) */
69 static TCGv cpu_tmp0
, cpu_tmp4
;
70 static TCGv_ptr cpu_ptr0
, cpu_ptr1
;
71 static TCGv_i32 cpu_tmp2_i32
, cpu_tmp3_i32
;
72 static TCGv_i64 cpu_tmp1_i64
;
73 static TCGv cpu_tmp5
, cpu_tmp6
;
75 #include "gen-icount.h"
78 static int x86_64_hregs
;
81 typedef struct DisasContext
{
82 /* current insn context */
83 int override
; /* -1 if no override */
86 target_ulong pc
; /* pc = eip + cs_base */
87 int is_jmp
; /* 1 = means jump (stop translation), 2 means CPU
88 static state change (stop translation) */
89 /* current block context */
90 target_ulong cs_base
; /* base of CS segment */
91 int pe
; /* protected mode */
92 int code32
; /* 32 bit code segment */
94 int lma
; /* long mode active */
95 int code64
; /* 64 bit code segment */
98 int ss32
; /* 32 bit stack segment */
99 int cc_op
; /* current CC operation */
100 int addseg
; /* non zero if either DS/ES/SS have a non zero base */
101 int f_st
; /* currently unused */
102 int vm86
; /* vm86 mode */
105 int tf
; /* TF cpu flag */
106 int singlestep_enabled
; /* "hardware" single step enabled */
107 int jmp_opt
; /* use direct block chaining for direct jumps */
108 int mem_index
; /* select memory access functions */
109 uint64_t flags
; /* all execution flags */
110 struct TranslationBlock
*tb
;
111 int popl_esp_hack
; /* for correct popl with esp base handling */
112 int rip_offset
; /* only used in x86_64, but left for simplicity */
114 int cpuid_ext_features
;
115 int cpuid_ext2_features
;
116 int cpuid_ext3_features
;
119 static void gen_eob(DisasContext
*s
);
120 static void gen_jmp(DisasContext
*s
, target_ulong eip
);
121 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
);
123 /* i386 arith/logic operations */
143 OP_SHL1
, /* undocumented */
167 /* I386 int registers */
168 OR_EAX
, /* MUST be even numbered */
177 OR_TMP0
= 16, /* temporary operand register */
179 OR_A0
, /* temporary register used when doing address evaluation */
182 static inline void gen_op_movl_T0_0(void)
184 tcg_gen_movi_tl(cpu_T
[0], 0);
187 static inline void gen_op_movl_T0_im(int32_t val
)
189 tcg_gen_movi_tl(cpu_T
[0], val
);
192 static inline void gen_op_movl_T0_imu(uint32_t val
)
194 tcg_gen_movi_tl(cpu_T
[0], val
);
197 static inline void gen_op_movl_T1_im(int32_t val
)
199 tcg_gen_movi_tl(cpu_T
[1], val
);
202 static inline void gen_op_movl_T1_imu(uint32_t val
)
204 tcg_gen_movi_tl(cpu_T
[1], val
);
207 static inline void gen_op_movl_A0_im(uint32_t val
)
209 tcg_gen_movi_tl(cpu_A0
, val
);
213 static inline void gen_op_movq_A0_im(int64_t val
)
215 tcg_gen_movi_tl(cpu_A0
, val
);
219 static inline void gen_movtl_T0_im(target_ulong val
)
221 tcg_gen_movi_tl(cpu_T
[0], val
);
224 static inline void gen_movtl_T1_im(target_ulong val
)
226 tcg_gen_movi_tl(cpu_T
[1], val
);
229 static inline void gen_op_andl_T0_ffff(void)
231 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
234 static inline void gen_op_andl_T0_im(uint32_t val
)
236 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], val
);
239 static inline void gen_op_movl_T0_T1(void)
241 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
244 static inline void gen_op_andl_A0_ffff(void)
246 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffff);
251 #define NB_OP_SIZES 4
253 #else /* !TARGET_X86_64 */
255 #define NB_OP_SIZES 3
257 #endif /* !TARGET_X86_64 */
259 #if defined(WORDS_BIGENDIAN)
260 #define REG_B_OFFSET (sizeof(target_ulong) - 1)
261 #define REG_H_OFFSET (sizeof(target_ulong) - 2)
262 #define REG_W_OFFSET (sizeof(target_ulong) - 2)
263 #define REG_L_OFFSET (sizeof(target_ulong) - 4)
264 #define REG_LH_OFFSET (sizeof(target_ulong) - 8)
266 #define REG_B_OFFSET 0
267 #define REG_H_OFFSET 1
268 #define REG_W_OFFSET 0
269 #define REG_L_OFFSET 0
270 #define REG_LH_OFFSET 4
273 static inline void gen_op_mov_reg_v(int ot
, int reg
, TCGv t0
)
277 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
278 tcg_gen_st8_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_B_OFFSET
);
280 tcg_gen_st8_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
- 4]) + REG_H_OFFSET
);
284 tcg_gen_st16_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_W_OFFSET
);
288 tcg_gen_st32_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
289 /* high part of register set to zero */
290 tcg_gen_movi_tl(cpu_tmp0
, 0);
291 tcg_gen_st32_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_LH_OFFSET
);
295 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
300 tcg_gen_st32_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
306 static inline void gen_op_mov_reg_T0(int ot
, int reg
)
308 gen_op_mov_reg_v(ot
, reg
, cpu_T
[0]);
311 static inline void gen_op_mov_reg_T1(int ot
, int reg
)
313 gen_op_mov_reg_v(ot
, reg
, cpu_T
[1]);
316 static inline void gen_op_mov_reg_A0(int size
, int reg
)
320 tcg_gen_st16_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_W_OFFSET
);
324 tcg_gen_st32_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
325 /* high part of register set to zero */
326 tcg_gen_movi_tl(cpu_tmp0
, 0);
327 tcg_gen_st32_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_LH_OFFSET
);
331 tcg_gen_st_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
336 tcg_gen_st32_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
342 static inline void gen_op_mov_v_reg(int ot
, TCGv t0
, int reg
)
346 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
349 tcg_gen_ld8u_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
- 4]) + REG_H_OFFSET
);
354 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
359 static inline void gen_op_mov_TN_reg(int ot
, int t_index
, int reg
)
361 gen_op_mov_v_reg(ot
, cpu_T
[t_index
], reg
);
364 static inline void gen_op_movl_A0_reg(int reg
)
366 tcg_gen_ld32u_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
369 static inline void gen_op_addl_A0_im(int32_t val
)
371 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
373 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
378 static inline void gen_op_addq_A0_im(int64_t val
)
380 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
384 static void gen_add_A0_im(DisasContext
*s
, int val
)
388 gen_op_addq_A0_im(val
);
391 gen_op_addl_A0_im(val
);
394 static inline void gen_op_addl_T0_T1(void)
396 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
399 static inline void gen_op_jmp_T0(void)
401 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, eip
));
404 static inline void gen_op_add_reg_im(int size
, int reg
, int32_t val
)
408 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
409 tcg_gen_addi_tl(cpu_tmp0
, cpu_tmp0
, val
);
410 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_W_OFFSET
);
413 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
414 tcg_gen_addi_tl(cpu_tmp0
, cpu_tmp0
, val
);
416 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, 0xffffffff);
418 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
422 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
423 tcg_gen_addi_tl(cpu_tmp0
, cpu_tmp0
, val
);
424 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
430 static inline void gen_op_add_reg_T0(int size
, int reg
)
434 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
435 tcg_gen_add_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[0]);
436 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_W_OFFSET
);
439 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
440 tcg_gen_add_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[0]);
442 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, 0xffffffff);
444 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
448 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
449 tcg_gen_add_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[0]);
450 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
456 static inline void gen_op_set_cc_op(int32_t val
)
458 tcg_gen_movi_i32(cpu_cc_op
, val
);
461 static inline void gen_op_addl_A0_reg_sN(int shift
, int reg
)
463 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
465 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
466 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
468 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
472 static inline void gen_op_movl_A0_seg(int reg
)
474 tcg_gen_ld32u_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
) + REG_L_OFFSET
);
477 static inline void gen_op_addl_A0_seg(int reg
)
479 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
480 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
482 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
487 static inline void gen_op_movq_A0_seg(int reg
)
489 tcg_gen_ld_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
492 static inline void gen_op_addq_A0_seg(int reg
)
494 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
495 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
498 static inline void gen_op_movq_A0_reg(int reg
)
500 tcg_gen_ld_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
503 static inline void gen_op_addq_A0_reg_sN(int shift
, int reg
)
505 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]));
507 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
508 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
512 static inline void gen_op_lds_T0_A0(int idx
)
514 int mem_index
= (idx
>> 2) - 1;
517 tcg_gen_qemu_ld8s(cpu_T
[0], cpu_A0
, mem_index
);
520 tcg_gen_qemu_ld16s(cpu_T
[0], cpu_A0
, mem_index
);
524 tcg_gen_qemu_ld32s(cpu_T
[0], cpu_A0
, mem_index
);
529 static inline void gen_op_ld_v(int idx
, TCGv t0
, TCGv a0
)
531 int mem_index
= (idx
>> 2) - 1;
534 tcg_gen_qemu_ld8u(t0
, a0
, mem_index
);
537 tcg_gen_qemu_ld16u(t0
, a0
, mem_index
);
540 tcg_gen_qemu_ld32u(t0
, a0
, mem_index
);
544 /* Should never happen on 32-bit targets. */
546 tcg_gen_qemu_ld64(t0
, a0
, mem_index
);
552 /* XXX: always use ldu or lds */
553 static inline void gen_op_ld_T0_A0(int idx
)
555 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
558 static inline void gen_op_ldu_T0_A0(int idx
)
560 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
563 static inline void gen_op_ld_T1_A0(int idx
)
565 gen_op_ld_v(idx
, cpu_T
[1], cpu_A0
);
568 static inline void gen_op_st_v(int idx
, TCGv t0
, TCGv a0
)
570 int mem_index
= (idx
>> 2) - 1;
573 tcg_gen_qemu_st8(t0
, a0
, mem_index
);
576 tcg_gen_qemu_st16(t0
, a0
, mem_index
);
579 tcg_gen_qemu_st32(t0
, a0
, mem_index
);
583 /* Should never happen on 32-bit targets. */
585 tcg_gen_qemu_st64(t0
, a0
, mem_index
);
591 static inline void gen_op_st_T0_A0(int idx
)
593 gen_op_st_v(idx
, cpu_T
[0], cpu_A0
);
596 static inline void gen_op_st_T1_A0(int idx
)
598 gen_op_st_v(idx
, cpu_T
[1], cpu_A0
);
601 static inline void gen_jmp_im(target_ulong pc
)
603 tcg_gen_movi_tl(cpu_tmp0
, pc
);
604 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, eip
));
607 static inline void gen_string_movl_A0_ESI(DisasContext
*s
)
611 override
= s
->override
;
615 gen_op_movq_A0_seg(override
);
616 gen_op_addq_A0_reg_sN(0, R_ESI
);
618 gen_op_movq_A0_reg(R_ESI
);
624 if (s
->addseg
&& override
< 0)
627 gen_op_movl_A0_seg(override
);
628 gen_op_addl_A0_reg_sN(0, R_ESI
);
630 gen_op_movl_A0_reg(R_ESI
);
633 /* 16 address, always override */
636 gen_op_movl_A0_reg(R_ESI
);
637 gen_op_andl_A0_ffff();
638 gen_op_addl_A0_seg(override
);
642 static inline void gen_string_movl_A0_EDI(DisasContext
*s
)
646 gen_op_movq_A0_reg(R_EDI
);
651 gen_op_movl_A0_seg(R_ES
);
652 gen_op_addl_A0_reg_sN(0, R_EDI
);
654 gen_op_movl_A0_reg(R_EDI
);
657 gen_op_movl_A0_reg(R_EDI
);
658 gen_op_andl_A0_ffff();
659 gen_op_addl_A0_seg(R_ES
);
663 static inline void gen_op_movl_T0_Dshift(int ot
)
665 tcg_gen_ld32s_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, df
));
666 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], ot
);
669 static void gen_extu(int ot
, TCGv reg
)
673 tcg_gen_ext8u_tl(reg
, reg
);
676 tcg_gen_ext16u_tl(reg
, reg
);
679 tcg_gen_ext32u_tl(reg
, reg
);
686 static void gen_exts(int ot
, TCGv reg
)
690 tcg_gen_ext8s_tl(reg
, reg
);
693 tcg_gen_ext16s_tl(reg
, reg
);
696 tcg_gen_ext32s_tl(reg
, reg
);
703 static inline void gen_op_jnz_ecx(int size
, int label1
)
705 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[R_ECX
]));
706 gen_extu(size
+ 1, cpu_tmp0
);
707 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, label1
);
710 static inline void gen_op_jz_ecx(int size
, int label1
)
712 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[R_ECX
]));
713 gen_extu(size
+ 1, cpu_tmp0
);
714 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
717 static void gen_helper_in_func(int ot
, TCGv v
, TCGv_i32 n
)
720 case 0: gen_helper_inb(v
, n
); break;
721 case 1: gen_helper_inw(v
, n
); break;
722 case 2: gen_helper_inl(v
, n
); break;
727 static void gen_helper_out_func(int ot
, TCGv_i32 v
, TCGv_i32 n
)
730 case 0: gen_helper_outb(v
, n
); break;
731 case 1: gen_helper_outw(v
, n
); break;
732 case 2: gen_helper_outl(v
, n
); break;
737 static void gen_check_io(DisasContext
*s
, int ot
, target_ulong cur_eip
,
741 target_ulong next_eip
;
744 if (s
->pe
&& (s
->cpl
> s
->iopl
|| s
->vm86
)) {
745 if (s
->cc_op
!= CC_OP_DYNAMIC
)
746 gen_op_set_cc_op(s
->cc_op
);
749 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
751 case 0: gen_helper_check_iob(cpu_tmp2_i32
); break;
752 case 1: gen_helper_check_iow(cpu_tmp2_i32
); break;
753 case 2: gen_helper_check_iol(cpu_tmp2_i32
); break;
756 if(s
->flags
& HF_SVMI_MASK
) {
758 if (s
->cc_op
!= CC_OP_DYNAMIC
)
759 gen_op_set_cc_op(s
->cc_op
);
763 svm_flags
|= (1 << (4 + ot
));
764 next_eip
= s
->pc
- s
->cs_base
;
765 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
766 gen_helper_svm_check_io(cpu_tmp2_i32
, tcg_const_i32(svm_flags
),
767 tcg_const_i32(next_eip
- cur_eip
));
771 static inline void gen_movs(DisasContext
*s
, int ot
)
773 gen_string_movl_A0_ESI(s
);
774 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
775 gen_string_movl_A0_EDI(s
);
776 gen_op_st_T0_A0(ot
+ s
->mem_index
);
777 gen_op_movl_T0_Dshift(ot
);
778 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
779 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
782 static inline void gen_update_cc_op(DisasContext
*s
)
784 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
785 gen_op_set_cc_op(s
->cc_op
);
786 s
->cc_op
= CC_OP_DYNAMIC
;
790 static void gen_op_update1_cc(void)
792 tcg_gen_discard_tl(cpu_cc_src
);
793 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
796 static void gen_op_update2_cc(void)
798 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
799 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
802 static inline void gen_op_cmpl_T0_T1_cc(void)
804 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
805 tcg_gen_sub_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
808 static inline void gen_op_testl_T0_T1_cc(void)
810 tcg_gen_discard_tl(cpu_cc_src
);
811 tcg_gen_and_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
814 static void gen_op_update_neg_cc(void)
816 tcg_gen_neg_tl(cpu_cc_src
, cpu_T
[0]);
817 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
820 /* compute eflags.C to reg */
821 static void gen_compute_eflags_c(TCGv reg
)
823 gen_helper_cc_compute_c(cpu_tmp2_i32
, cpu_cc_op
);
824 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
827 /* compute all eflags to cc_src */
828 static void gen_compute_eflags(TCGv reg
)
830 gen_helper_cc_compute_all(cpu_tmp2_i32
, cpu_cc_op
);
831 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
834 static inline void gen_setcc_slow_T0(DisasContext
*s
, int jcc_op
)
836 if (s
->cc_op
!= CC_OP_DYNAMIC
)
837 gen_op_set_cc_op(s
->cc_op
);
840 gen_compute_eflags(cpu_T
[0]);
841 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 11);
842 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
845 gen_compute_eflags_c(cpu_T
[0]);
848 gen_compute_eflags(cpu_T
[0]);
849 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 6);
850 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
853 gen_compute_eflags(cpu_tmp0
);
854 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 6);
855 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
856 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
859 gen_compute_eflags(cpu_T
[0]);
860 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 7);
861 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
864 gen_compute_eflags(cpu_T
[0]);
865 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 2);
866 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
869 gen_compute_eflags(cpu_tmp0
);
870 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
871 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 7); /* CC_S */
872 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
873 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
877 gen_compute_eflags(cpu_tmp0
);
878 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
879 tcg_gen_shri_tl(cpu_tmp4
, cpu_tmp0
, 7); /* CC_S */
880 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 6); /* CC_Z */
881 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
882 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
883 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
888 /* return true if setcc_slow is not needed (WARNING: must be kept in
889 sync with gen_jcc1) */
890 static int is_fast_jcc_case(DisasContext
*s
, int b
)
893 jcc_op
= (b
>> 1) & 7;
895 /* we optimize the cmp/jcc case */
900 if (jcc_op
== JCC_O
|| jcc_op
== JCC_P
)
904 /* some jumps are easy to compute */
929 if (jcc_op
!= JCC_Z
&& jcc_op
!= JCC_S
)
939 /* generate a conditional jump to label 'l1' according to jump opcode
940 value 'b'. In the fast case, T0 is guaranted not to be used. */
941 static inline void gen_jcc1(DisasContext
*s
, int cc_op
, int b
, int l1
)
943 int inv
, jcc_op
, size
, cond
;
947 jcc_op
= (b
>> 1) & 7;
950 /* we optimize the cmp/jcc case */
956 size
= cc_op
- CC_OP_SUBB
;
962 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xff);
966 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffff);
971 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffffffff);
979 tcg_gen_brcondi_tl(inv
? TCG_COND_NE
: TCG_COND_EQ
, t0
, 0, l1
);
985 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80);
986 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
990 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x8000);
991 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
996 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80000000);
997 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
1002 tcg_gen_brcondi_tl(inv
? TCG_COND_GE
: TCG_COND_LT
, cpu_cc_dst
,
1009 cond
= inv
? TCG_COND_GEU
: TCG_COND_LTU
;
1012 cond
= inv
? TCG_COND_GTU
: TCG_COND_LEU
;
1014 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1018 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xff);
1019 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xff);
1023 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffff);
1024 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffff);
1026 #ifdef TARGET_X86_64
1029 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffffffff);
1030 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffffffff);
1037 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1041 cond
= inv
? TCG_COND_GE
: TCG_COND_LT
;
1044 cond
= inv
? TCG_COND_GT
: TCG_COND_LE
;
1046 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1050 tcg_gen_ext8s_tl(cpu_tmp4
, cpu_tmp4
);
1051 tcg_gen_ext8s_tl(t0
, cpu_cc_src
);
1055 tcg_gen_ext16s_tl(cpu_tmp4
, cpu_tmp4
);
1056 tcg_gen_ext16s_tl(t0
, cpu_cc_src
);
1058 #ifdef TARGET_X86_64
1061 tcg_gen_ext32s_tl(cpu_tmp4
, cpu_tmp4
);
1062 tcg_gen_ext32s_tl(t0
, cpu_cc_src
);
1069 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1077 /* some jumps are easy to compute */
1119 size
= (cc_op
- CC_OP_ADDB
) & 3;
1122 size
= (cc_op
- CC_OP_ADDB
) & 3;
1130 gen_setcc_slow_T0(s
, jcc_op
);
1131 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
,
1137 /* XXX: does not work with gdbstub "ice" single step - not a
1139 static int gen_jz_ecx_string(DisasContext
*s
, target_ulong next_eip
)
1143 l1
= gen_new_label();
1144 l2
= gen_new_label();
1145 gen_op_jnz_ecx(s
->aflag
, l1
);
1147 gen_jmp_tb(s
, next_eip
, 1);
1152 static inline void gen_stos(DisasContext
*s
, int ot
)
1154 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1155 gen_string_movl_A0_EDI(s
);
1156 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1157 gen_op_movl_T0_Dshift(ot
);
1158 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1161 static inline void gen_lods(DisasContext
*s
, int ot
)
1163 gen_string_movl_A0_ESI(s
);
1164 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1165 gen_op_mov_reg_T0(ot
, R_EAX
);
1166 gen_op_movl_T0_Dshift(ot
);
1167 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1170 static inline void gen_scas(DisasContext
*s
, int ot
)
1172 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1173 gen_string_movl_A0_EDI(s
);
1174 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1175 gen_op_cmpl_T0_T1_cc();
1176 gen_op_movl_T0_Dshift(ot
);
1177 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1180 static inline void gen_cmps(DisasContext
*s
, int ot
)
1182 gen_string_movl_A0_ESI(s
);
1183 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1184 gen_string_movl_A0_EDI(s
);
1185 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1186 gen_op_cmpl_T0_T1_cc();
1187 gen_op_movl_T0_Dshift(ot
);
1188 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1189 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1192 static inline void gen_ins(DisasContext
*s
, int ot
)
1196 gen_string_movl_A0_EDI(s
);
1197 /* Note: we must do this dummy write first to be restartable in
1198 case of page fault. */
1200 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1201 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1202 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1203 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1204 gen_helper_in_func(ot
, cpu_T
[0], cpu_tmp2_i32
);
1205 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1206 gen_op_movl_T0_Dshift(ot
);
1207 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1212 static inline void gen_outs(DisasContext
*s
, int ot
)
1216 gen_string_movl_A0_ESI(s
);
1217 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1219 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1220 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1221 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1222 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[0]);
1223 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
1225 gen_op_movl_T0_Dshift(ot
);
1226 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1231 /* same method as Valgrind : we generate jumps to current or next
1233 #define GEN_REPZ(op) \
1234 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1235 target_ulong cur_eip, target_ulong next_eip) \
1238 gen_update_cc_op(s); \
1239 l2 = gen_jz_ecx_string(s, next_eip); \
1240 gen_ ## op(s, ot); \
1241 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1242 /* a loop would cause two single step exceptions if ECX = 1 \
1243 before rep string_insn */ \
1245 gen_op_jz_ecx(s->aflag, l2); \
1246 gen_jmp(s, cur_eip); \
1249 #define GEN_REPZ2(op) \
1250 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1251 target_ulong cur_eip, \
1252 target_ulong next_eip, \
1256 gen_update_cc_op(s); \
1257 l2 = gen_jz_ecx_string(s, next_eip); \
1258 gen_ ## op(s, ot); \
1259 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1260 gen_op_set_cc_op(CC_OP_SUBB + ot); \
1261 gen_jcc1(s, CC_OP_SUBB + ot, (JCC_Z << 1) | (nz ^ 1), l2); \
1263 gen_op_jz_ecx(s->aflag, l2); \
1264 gen_jmp(s, cur_eip); \
1275 static void gen_helper_fp_arith_ST0_FT0(int op
)
1278 case 0: gen_helper_fadd_ST0_FT0(); break;
1279 case 1: gen_helper_fmul_ST0_FT0(); break;
1280 case 2: gen_helper_fcom_ST0_FT0(); break;
1281 case 3: gen_helper_fcom_ST0_FT0(); break;
1282 case 4: gen_helper_fsub_ST0_FT0(); break;
1283 case 5: gen_helper_fsubr_ST0_FT0(); break;
1284 case 6: gen_helper_fdiv_ST0_FT0(); break;
1285 case 7: gen_helper_fdivr_ST0_FT0(); break;
1289 /* NOTE the exception in "r" op ordering */
1290 static void gen_helper_fp_arith_STN_ST0(int op
, int opreg
)
1292 TCGv_i32 tmp
= tcg_const_i32(opreg
);
1294 case 0: gen_helper_fadd_STN_ST0(tmp
); break;
1295 case 1: gen_helper_fmul_STN_ST0(tmp
); break;
1296 case 4: gen_helper_fsubr_STN_ST0(tmp
); break;
1297 case 5: gen_helper_fsub_STN_ST0(tmp
); break;
1298 case 6: gen_helper_fdivr_STN_ST0(tmp
); break;
1299 case 7: gen_helper_fdiv_STN_ST0(tmp
); break;
1303 /* if d == OR_TMP0, it means memory operand (address in A0) */
1304 static void gen_op(DisasContext
*s1
, int op
, int ot
, int d
)
1307 gen_op_mov_TN_reg(ot
, 0, d
);
1309 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1313 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1314 gen_op_set_cc_op(s1
->cc_op
);
1315 gen_compute_eflags_c(cpu_tmp4
);
1316 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1317 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1319 gen_op_mov_reg_T0(ot
, d
);
1321 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1322 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1323 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1324 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1325 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1326 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_ADDB
+ ot
);
1327 s1
->cc_op
= CC_OP_DYNAMIC
;
1330 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1331 gen_op_set_cc_op(s1
->cc_op
);
1332 gen_compute_eflags_c(cpu_tmp4
);
1333 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1334 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1336 gen_op_mov_reg_T0(ot
, d
);
1338 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1339 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1340 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1341 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1342 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1343 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_SUBB
+ ot
);
1344 s1
->cc_op
= CC_OP_DYNAMIC
;
1347 gen_op_addl_T0_T1();
1349 gen_op_mov_reg_T0(ot
, d
);
1351 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1352 gen_op_update2_cc();
1353 s1
->cc_op
= CC_OP_ADDB
+ ot
;
1356 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1358 gen_op_mov_reg_T0(ot
, d
);
1360 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1361 gen_op_update2_cc();
1362 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1366 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1368 gen_op_mov_reg_T0(ot
, d
);
1370 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1371 gen_op_update1_cc();
1372 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1375 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1377 gen_op_mov_reg_T0(ot
, d
);
1379 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1380 gen_op_update1_cc();
1381 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1384 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1386 gen_op_mov_reg_T0(ot
, d
);
1388 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1389 gen_op_update1_cc();
1390 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1393 gen_op_cmpl_T0_T1_cc();
1394 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1399 /* if d == OR_TMP0, it means memory operand (address in A0) */
1400 static void gen_inc(DisasContext
*s1
, int ot
, int d
, int c
)
1403 gen_op_mov_TN_reg(ot
, 0, d
);
1405 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1406 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1407 gen_op_set_cc_op(s1
->cc_op
);
1409 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], 1);
1410 s1
->cc_op
= CC_OP_INCB
+ ot
;
1412 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], -1);
1413 s1
->cc_op
= CC_OP_DECB
+ ot
;
1416 gen_op_mov_reg_T0(ot
, d
);
1418 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1419 gen_compute_eflags_c(cpu_cc_src
);
1420 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1423 static void gen_shift_rm_T1(DisasContext
*s
, int ot
, int op1
,
1424 int is_right
, int is_arith
)
1437 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1439 gen_op_mov_TN_reg(ot
, 0, op1
);
1441 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], mask
);
1443 tcg_gen_addi_tl(cpu_tmp5
, cpu_T
[1], -1);
1447 gen_exts(ot
, cpu_T
[0]);
1448 tcg_gen_sar_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1449 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1451 gen_extu(ot
, cpu_T
[0]);
1452 tcg_gen_shr_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1453 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1456 tcg_gen_shl_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1457 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1462 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1464 gen_op_mov_reg_T0(ot
, op1
);
1466 /* update eflags if non zero shift */
1467 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1468 gen_op_set_cc_op(s
->cc_op
);
1470 /* XXX: inefficient */
1471 t0
= tcg_temp_local_new();
1472 t1
= tcg_temp_local_new();
1474 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1475 tcg_gen_mov_tl(t1
, cpu_T3
);
1477 shift_label
= gen_new_label();
1478 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, shift_label
);
1480 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1481 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1483 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1485 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1487 gen_set_label(shift_label
);
1488 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1494 static void gen_shift_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1495 int is_right
, int is_arith
)
1506 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1508 gen_op_mov_TN_reg(ot
, 0, op1
);
1514 gen_exts(ot
, cpu_T
[0]);
1515 tcg_gen_sari_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1516 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], op2
);
1518 gen_extu(ot
, cpu_T
[0]);
1519 tcg_gen_shri_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1520 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], op2
);
1523 tcg_gen_shli_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1524 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], op2
);
1530 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1532 gen_op_mov_reg_T0(ot
, op1
);
1534 /* update eflags if non zero shift */
1536 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
1537 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1539 s
->cc_op
= CC_OP_SARB
+ ot
;
1541 s
->cc_op
= CC_OP_SHLB
+ ot
;
1545 static inline void tcg_gen_lshift(TCGv ret
, TCGv arg1
, target_long arg2
)
1548 tcg_gen_shli_tl(ret
, arg1
, arg2
);
1550 tcg_gen_shri_tl(ret
, arg1
, -arg2
);
1553 static void gen_rot_rm_T1(DisasContext
*s
, int ot
, int op1
,
1557 int label1
, label2
, data_bits
;
1558 TCGv t0
, t1
, t2
, a0
;
1560 /* XXX: inefficient, but we must use local temps */
1561 t0
= tcg_temp_local_new();
1562 t1
= tcg_temp_local_new();
1563 t2
= tcg_temp_local_new();
1564 a0
= tcg_temp_local_new();
1572 if (op1
== OR_TMP0
) {
1573 tcg_gen_mov_tl(a0
, cpu_A0
);
1574 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1576 gen_op_mov_v_reg(ot
, t0
, op1
);
1579 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1581 tcg_gen_andi_tl(t1
, t1
, mask
);
1583 /* Must test zero case to avoid using undefined behaviour in TCG
1585 label1
= gen_new_label();
1586 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label1
);
1589 tcg_gen_andi_tl(cpu_tmp0
, t1
, (1 << (3 + ot
)) - 1);
1591 tcg_gen_mov_tl(cpu_tmp0
, t1
);
1594 tcg_gen_mov_tl(t2
, t0
);
1596 data_bits
= 8 << ot
;
1597 /* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
1598 fix TCG definition) */
1600 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1601 tcg_gen_sub_tl(cpu_tmp0
, tcg_const_tl(data_bits
), cpu_tmp0
);
1602 tcg_gen_shl_tl(t0
, t0
, cpu_tmp0
);
1604 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1605 tcg_gen_sub_tl(cpu_tmp0
, tcg_const_tl(data_bits
), cpu_tmp0
);
1606 tcg_gen_shr_tl(t0
, t0
, cpu_tmp0
);
1608 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1610 gen_set_label(label1
);
1612 if (op1
== OR_TMP0
) {
1613 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1615 gen_op_mov_reg_v(ot
, op1
, t0
);
1619 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1620 gen_op_set_cc_op(s
->cc_op
);
1622 label2
= gen_new_label();
1623 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label2
);
1625 gen_compute_eflags(cpu_cc_src
);
1626 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1627 tcg_gen_xor_tl(cpu_tmp0
, t2
, t0
);
1628 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1629 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1630 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1632 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1634 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1635 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1637 tcg_gen_discard_tl(cpu_cc_dst
);
1638 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1640 gen_set_label(label2
);
1641 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1649 static void gen_rot_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1656 /* XXX: inefficient, but we must use local temps */
1657 t0
= tcg_temp_local_new();
1658 t1
= tcg_temp_local_new();
1659 a0
= tcg_temp_local_new();
1667 if (op1
== OR_TMP0
) {
1668 tcg_gen_mov_tl(a0
, cpu_A0
);
1669 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1671 gen_op_mov_v_reg(ot
, t0
, op1
);
1675 tcg_gen_mov_tl(t1
, t0
);
1678 data_bits
= 8 << ot
;
1680 int shift
= op2
& ((1 << (3 + ot
)) - 1);
1682 tcg_gen_shri_tl(cpu_tmp4
, t0
, shift
);
1683 tcg_gen_shli_tl(t0
, t0
, data_bits
- shift
);
1686 tcg_gen_shli_tl(cpu_tmp4
, t0
, shift
);
1687 tcg_gen_shri_tl(t0
, t0
, data_bits
- shift
);
1689 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1693 if (op1
== OR_TMP0
) {
1694 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1696 gen_op_mov_reg_v(ot
, op1
, t0
);
1701 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1702 gen_op_set_cc_op(s
->cc_op
);
1704 gen_compute_eflags(cpu_cc_src
);
1705 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1706 tcg_gen_xor_tl(cpu_tmp0
, t1
, t0
);
1707 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1708 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1709 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1711 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1713 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1714 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1716 tcg_gen_discard_tl(cpu_cc_dst
);
1717 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1718 s
->cc_op
= CC_OP_EFLAGS
;
1726 /* XXX: add faster immediate = 1 case */
1727 static void gen_rotc_rm_T1(DisasContext
*s
, int ot
, int op1
,
1732 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1733 gen_op_set_cc_op(s
->cc_op
);
1737 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1739 gen_op_mov_TN_reg(ot
, 0, op1
);
1743 case 0: gen_helper_rcrb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1744 case 1: gen_helper_rcrw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1745 case 2: gen_helper_rcrl(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1746 #ifdef TARGET_X86_64
1747 case 3: gen_helper_rcrq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1752 case 0: gen_helper_rclb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1753 case 1: gen_helper_rclw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1754 case 2: gen_helper_rcll(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1755 #ifdef TARGET_X86_64
1756 case 3: gen_helper_rclq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1762 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1764 gen_op_mov_reg_T0(ot
, op1
);
1767 label1
= gen_new_label();
1768 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_cc_tmp
, -1, label1
);
1770 tcg_gen_mov_tl(cpu_cc_src
, cpu_cc_tmp
);
1771 tcg_gen_discard_tl(cpu_cc_dst
);
1772 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1774 gen_set_label(label1
);
1775 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1778 /* XXX: add faster immediate case */
1779 static void gen_shiftd_rm_T1_T3(DisasContext
*s
, int ot
, int op1
,
1782 int label1
, label2
, data_bits
;
1784 TCGv t0
, t1
, t2
, a0
;
1786 t0
= tcg_temp_local_new();
1787 t1
= tcg_temp_local_new();
1788 t2
= tcg_temp_local_new();
1789 a0
= tcg_temp_local_new();
1797 if (op1
== OR_TMP0
) {
1798 tcg_gen_mov_tl(a0
, cpu_A0
);
1799 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1801 gen_op_mov_v_reg(ot
, t0
, op1
);
1804 tcg_gen_andi_tl(cpu_T3
, cpu_T3
, mask
);
1806 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1807 tcg_gen_mov_tl(t2
, cpu_T3
);
1809 /* Must test zero case to avoid using undefined behaviour in TCG
1811 label1
= gen_new_label();
1812 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
1814 tcg_gen_addi_tl(cpu_tmp5
, t2
, -1);
1815 if (ot
== OT_WORD
) {
1816 /* Note: we implement the Intel behaviour for shift count > 16 */
1818 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1819 tcg_gen_shli_tl(cpu_tmp0
, t1
, 16);
1820 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1821 tcg_gen_ext32u_tl(t0
, t0
);
1823 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1825 /* only needed if count > 16, but a test would complicate */
1826 tcg_gen_sub_tl(cpu_tmp5
, tcg_const_tl(32), t2
);
1827 tcg_gen_shl_tl(cpu_tmp0
, t0
, cpu_tmp5
);
1829 tcg_gen_shr_tl(t0
, t0
, t2
);
1831 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1833 /* XXX: not optimal */
1834 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1835 tcg_gen_shli_tl(t1
, t1
, 16);
1836 tcg_gen_or_tl(t1
, t1
, t0
);
1837 tcg_gen_ext32u_tl(t1
, t1
);
1839 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1840 tcg_gen_sub_tl(cpu_tmp0
, tcg_const_tl(32), cpu_tmp5
);
1841 tcg_gen_shr_tl(cpu_tmp6
, t1
, cpu_tmp0
);
1842 tcg_gen_or_tl(cpu_tmp4
, cpu_tmp4
, cpu_tmp6
);
1844 tcg_gen_shl_tl(t0
, t0
, t2
);
1845 tcg_gen_sub_tl(cpu_tmp5
, tcg_const_tl(32), t2
);
1846 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1847 tcg_gen_or_tl(t0
, t0
, t1
);
1850 data_bits
= 8 << ot
;
1853 tcg_gen_ext32u_tl(t0
, t0
);
1855 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1857 tcg_gen_shr_tl(t0
, t0
, t2
);
1858 tcg_gen_sub_tl(cpu_tmp5
, tcg_const_tl(data_bits
), t2
);
1859 tcg_gen_shl_tl(t1
, t1
, cpu_tmp5
);
1860 tcg_gen_or_tl(t0
, t0
, t1
);
1864 tcg_gen_ext32u_tl(t1
, t1
);
1866 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1868 tcg_gen_shl_tl(t0
, t0
, t2
);
1869 tcg_gen_sub_tl(cpu_tmp5
, tcg_const_tl(data_bits
), t2
);
1870 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1871 tcg_gen_or_tl(t0
, t0
, t1
);
1874 tcg_gen_mov_tl(t1
, cpu_tmp4
);
1876 gen_set_label(label1
);
1878 if (op1
== OR_TMP0
) {
1879 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1881 gen_op_mov_reg_v(ot
, op1
, t0
);
1885 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1886 gen_op_set_cc_op(s
->cc_op
);
1888 label2
= gen_new_label();
1889 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label2
);
1891 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1892 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1894 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1896 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1898 gen_set_label(label2
);
1899 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1907 static void gen_shift(DisasContext
*s1
, int op
, int ot
, int d
, int s
)
1910 gen_op_mov_TN_reg(ot
, 1, s
);
1913 gen_rot_rm_T1(s1
, ot
, d
, 0);
1916 gen_rot_rm_T1(s1
, ot
, d
, 1);
1920 gen_shift_rm_T1(s1
, ot
, d
, 0, 0);
1923 gen_shift_rm_T1(s1
, ot
, d
, 1, 0);
1926 gen_shift_rm_T1(s1
, ot
, d
, 1, 1);
1929 gen_rotc_rm_T1(s1
, ot
, d
, 0);
1932 gen_rotc_rm_T1(s1
, ot
, d
, 1);
1937 static void gen_shifti(DisasContext
*s1
, int op
, int ot
, int d
, int c
)
1941 gen_rot_rm_im(s1
, ot
, d
, c
, 0);
1944 gen_rot_rm_im(s1
, ot
, d
, c
, 1);
1948 gen_shift_rm_im(s1
, ot
, d
, c
, 0, 0);
1951 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 0);
1954 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 1);
1957 /* currently not optimized */
1958 gen_op_movl_T1_im(c
);
1959 gen_shift(s1
, op
, ot
, d
, OR_TMP1
);
1964 static void gen_lea_modrm(DisasContext
*s
, int modrm
, int *reg_ptr
, int *offset_ptr
)
1972 int mod
, rm
, code
, override
, must_add_seg
;
1974 override
= s
->override
;
1975 must_add_seg
= s
->addseg
;
1978 mod
= (modrm
>> 6) & 3;
1990 code
= ldub_code(s
->pc
++);
1991 scale
= (code
>> 6) & 3;
1992 index
= ((code
>> 3) & 7) | REX_X(s
);
1999 if ((base
& 7) == 5) {
2001 disp
= (int32_t)ldl_code(s
->pc
);
2003 if (CODE64(s
) && !havesib
) {
2004 disp
+= s
->pc
+ s
->rip_offset
;
2011 disp
= (int8_t)ldub_code(s
->pc
++);
2015 disp
= ldl_code(s
->pc
);
2021 /* for correct popl handling with esp */
2022 if (base
== 4 && s
->popl_esp_hack
)
2023 disp
+= s
->popl_esp_hack
;
2024 #ifdef TARGET_X86_64
2025 if (s
->aflag
== 2) {
2026 gen_op_movq_A0_reg(base
);
2028 gen_op_addq_A0_im(disp
);
2033 gen_op_movl_A0_reg(base
);
2035 gen_op_addl_A0_im(disp
);
2038 #ifdef TARGET_X86_64
2039 if (s
->aflag
== 2) {
2040 gen_op_movq_A0_im(disp
);
2044 gen_op_movl_A0_im(disp
);
2047 /* XXX: index == 4 is always invalid */
2048 if (havesib
&& (index
!= 4 || scale
!= 0)) {
2049 #ifdef TARGET_X86_64
2050 if (s
->aflag
== 2) {
2051 gen_op_addq_A0_reg_sN(scale
, index
);
2055 gen_op_addl_A0_reg_sN(scale
, index
);
2060 if (base
== R_EBP
|| base
== R_ESP
)
2065 #ifdef TARGET_X86_64
2066 if (s
->aflag
== 2) {
2067 gen_op_addq_A0_seg(override
);
2071 gen_op_addl_A0_seg(override
);
2078 disp
= lduw_code(s
->pc
);
2080 gen_op_movl_A0_im(disp
);
2081 rm
= 0; /* avoid SS override */
2088 disp
= (int8_t)ldub_code(s
->pc
++);
2092 disp
= lduw_code(s
->pc
);
2098 gen_op_movl_A0_reg(R_EBX
);
2099 gen_op_addl_A0_reg_sN(0, R_ESI
);
2102 gen_op_movl_A0_reg(R_EBX
);
2103 gen_op_addl_A0_reg_sN(0, R_EDI
);
2106 gen_op_movl_A0_reg(R_EBP
);
2107 gen_op_addl_A0_reg_sN(0, R_ESI
);
2110 gen_op_movl_A0_reg(R_EBP
);
2111 gen_op_addl_A0_reg_sN(0, R_EDI
);
2114 gen_op_movl_A0_reg(R_ESI
);
2117 gen_op_movl_A0_reg(R_EDI
);
2120 gen_op_movl_A0_reg(R_EBP
);
2124 gen_op_movl_A0_reg(R_EBX
);
2128 gen_op_addl_A0_im(disp
);
2129 gen_op_andl_A0_ffff();
2133 if (rm
== 2 || rm
== 3 || rm
== 6)
2138 gen_op_addl_A0_seg(override
);
2148 static void gen_nop_modrm(DisasContext
*s
, int modrm
)
2150 int mod
, rm
, base
, code
;
2152 mod
= (modrm
>> 6) & 3;
2162 code
= ldub_code(s
->pc
++);
2198 /* used for LEA and MOV AX, mem */
2199 static void gen_add_A0_ds_seg(DisasContext
*s
)
2201 int override
, must_add_seg
;
2202 must_add_seg
= s
->addseg
;
2204 if (s
->override
>= 0) {
2205 override
= s
->override
;
2211 #ifdef TARGET_X86_64
2213 gen_op_addq_A0_seg(override
);
2217 gen_op_addl_A0_seg(override
);
2222 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
2224 static void gen_ldst_modrm(DisasContext
*s
, int modrm
, int ot
, int reg
, int is_store
)
2226 int mod
, rm
, opreg
, disp
;
2228 mod
= (modrm
>> 6) & 3;
2229 rm
= (modrm
& 7) | REX_B(s
);
2233 gen_op_mov_TN_reg(ot
, 0, reg
);
2234 gen_op_mov_reg_T0(ot
, rm
);
2236 gen_op_mov_TN_reg(ot
, 0, rm
);
2238 gen_op_mov_reg_T0(ot
, reg
);
2241 gen_lea_modrm(s
, modrm
, &opreg
, &disp
);
2244 gen_op_mov_TN_reg(ot
, 0, reg
);
2245 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2247 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
2249 gen_op_mov_reg_T0(ot
, reg
);
2254 static inline uint32_t insn_get(DisasContext
*s
, int ot
)
2260 ret
= ldub_code(s
->pc
);
2264 ret
= lduw_code(s
->pc
);
2269 ret
= ldl_code(s
->pc
);
2276 static inline int insn_const_size(unsigned int ot
)
2284 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong eip
)
2286 TranslationBlock
*tb
;
2289 pc
= s
->cs_base
+ eip
;
2291 /* NOTE: we handle the case where the TB spans two pages here */
2292 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) ||
2293 (pc
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
)) {
2294 /* jump to same page: we can use a direct jump */
2295 tcg_gen_goto_tb(tb_num
);
2297 tcg_gen_exit_tb((long)tb
+ tb_num
);
2299 /* jump to another page: currently not optimized */
2305 static inline void gen_jcc(DisasContext
*s
, int b
,
2306 target_ulong val
, target_ulong next_eip
)
2311 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2312 gen_op_set_cc_op(s
->cc_op
);
2313 s
->cc_op
= CC_OP_DYNAMIC
;
2316 l1
= gen_new_label();
2317 gen_jcc1(s
, cc_op
, b
, l1
);
2319 gen_goto_tb(s
, 0, next_eip
);
2322 gen_goto_tb(s
, 1, val
);
2326 l1
= gen_new_label();
2327 l2
= gen_new_label();
2328 gen_jcc1(s
, cc_op
, b
, l1
);
2330 gen_jmp_im(next_eip
);
2340 static void gen_setcc(DisasContext
*s
, int b
)
2342 int inv
, jcc_op
, l1
;
2345 if (is_fast_jcc_case(s
, b
)) {
2346 /* nominal case: we use a jump */
2347 /* XXX: make it faster by adding new instructions in TCG */
2348 t0
= tcg_temp_local_new();
2349 tcg_gen_movi_tl(t0
, 0);
2350 l1
= gen_new_label();
2351 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
2352 tcg_gen_movi_tl(t0
, 1);
2354 tcg_gen_mov_tl(cpu_T
[0], t0
);
2357 /* slow case: it is more efficient not to generate a jump,
2358 although it is questionnable whether this optimization is
2361 jcc_op
= (b
>> 1) & 7;
2362 gen_setcc_slow_T0(s
, jcc_op
);
2364 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
2369 static inline void gen_op_movl_T0_seg(int seg_reg
)
2371 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
2372 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2375 static inline void gen_op_movl_seg_T0_vm(int seg_reg
)
2377 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
2378 tcg_gen_st32_tl(cpu_T
[0], cpu_env
,
2379 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2380 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], 4);
2381 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
2382 offsetof(CPUX86State
,segs
[seg_reg
].base
));
2385 /* move T0 to seg_reg and compute if the CPU state may change. Never
2386 call this function with seg_reg == R_CS */
2387 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
2389 if (s
->pe
&& !s
->vm86
) {
2390 /* XXX: optimize by finding processor state dynamically */
2391 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2392 gen_op_set_cc_op(s
->cc_op
);
2393 gen_jmp_im(cur_eip
);
2394 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
2395 gen_helper_load_seg(tcg_const_i32(seg_reg
), cpu_tmp2_i32
);
2396 /* abort translation because the addseg value may change or
2397 because ss32 may change. For R_SS, translation must always
2398 stop as a special handling must be done to disable hardware
2399 interrupts for the next instruction */
2400 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
2403 gen_op_movl_seg_T0_vm(seg_reg
);
2404 if (seg_reg
== R_SS
)
2409 static inline int svm_is_rep(int prefixes
)
2411 return ((prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) ? 8 : 0);
2415 gen_svm_check_intercept_param(DisasContext
*s
, target_ulong pc_start
,
2416 uint32_t type
, uint64_t param
)
2418 /* no SVM activated; fast case */
2419 if (likely(!(s
->flags
& HF_SVMI_MASK
)))
2421 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2422 gen_op_set_cc_op(s
->cc_op
);
2423 gen_jmp_im(pc_start
- s
->cs_base
);
2424 gen_helper_svm_check_intercept_param(tcg_const_i32(type
),
2425 tcg_const_i64(param
));
2429 gen_svm_check_intercept(DisasContext
*s
, target_ulong pc_start
, uint64_t type
)
2431 gen_svm_check_intercept_param(s
, pc_start
, type
, 0);
2434 static inline void gen_stack_update(DisasContext
*s
, int addend
)
2436 #ifdef TARGET_X86_64
2438 gen_op_add_reg_im(2, R_ESP
, addend
);
2442 gen_op_add_reg_im(1, R_ESP
, addend
);
2444 gen_op_add_reg_im(0, R_ESP
, addend
);
2448 /* generate a push. It depends on ss32, addseg and dflag */
2449 static void gen_push_T0(DisasContext
*s
)
2451 #ifdef TARGET_X86_64
2453 gen_op_movq_A0_reg(R_ESP
);
2455 gen_op_addq_A0_im(-8);
2456 gen_op_st_T0_A0(OT_QUAD
+ s
->mem_index
);
2458 gen_op_addq_A0_im(-2);
2459 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2461 gen_op_mov_reg_A0(2, R_ESP
);
2465 gen_op_movl_A0_reg(R_ESP
);
2467 gen_op_addl_A0_im(-2);
2469 gen_op_addl_A0_im(-4);
2472 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2473 gen_op_addl_A0_seg(R_SS
);
2476 gen_op_andl_A0_ffff();
2477 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2478 gen_op_addl_A0_seg(R_SS
);
2480 gen_op_st_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2481 if (s
->ss32
&& !s
->addseg
)
2482 gen_op_mov_reg_A0(1, R_ESP
);
2484 gen_op_mov_reg_T1(s
->ss32
+ 1, R_ESP
);
2488 /* generate a push. It depends on ss32, addseg and dflag */
2489 /* slower version for T1, only used for call Ev */
2490 static void gen_push_T1(DisasContext
*s
)
2492 #ifdef TARGET_X86_64
2494 gen_op_movq_A0_reg(R_ESP
);
2496 gen_op_addq_A0_im(-8);
2497 gen_op_st_T1_A0(OT_QUAD
+ s
->mem_index
);
2499 gen_op_addq_A0_im(-2);
2500 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2502 gen_op_mov_reg_A0(2, R_ESP
);
2506 gen_op_movl_A0_reg(R_ESP
);
2508 gen_op_addl_A0_im(-2);
2510 gen_op_addl_A0_im(-4);
2513 gen_op_addl_A0_seg(R_SS
);
2516 gen_op_andl_A0_ffff();
2517 gen_op_addl_A0_seg(R_SS
);
2519 gen_op_st_T1_A0(s
->dflag
+ 1 + s
->mem_index
);
2521 if (s
->ss32
&& !s
->addseg
)
2522 gen_op_mov_reg_A0(1, R_ESP
);
2524 gen_stack_update(s
, (-2) << s
->dflag
);
2528 /* two step pop is necessary for precise exceptions */
2529 static void gen_pop_T0(DisasContext
*s
)
2531 #ifdef TARGET_X86_64
2533 gen_op_movq_A0_reg(R_ESP
);
2534 gen_op_ld_T0_A0((s
->dflag
? OT_QUAD
: OT_WORD
) + s
->mem_index
);
2538 gen_op_movl_A0_reg(R_ESP
);
2541 gen_op_addl_A0_seg(R_SS
);
2543 gen_op_andl_A0_ffff();
2544 gen_op_addl_A0_seg(R_SS
);
2546 gen_op_ld_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2550 static void gen_pop_update(DisasContext
*s
)
2552 #ifdef TARGET_X86_64
2553 if (CODE64(s
) && s
->dflag
) {
2554 gen_stack_update(s
, 8);
2558 gen_stack_update(s
, 2 << s
->dflag
);
2562 static void gen_stack_A0(DisasContext
*s
)
2564 gen_op_movl_A0_reg(R_ESP
);
2566 gen_op_andl_A0_ffff();
2567 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2569 gen_op_addl_A0_seg(R_SS
);
2572 /* NOTE: wrap around in 16 bit not fully handled */
2573 static void gen_pusha(DisasContext
*s
)
2576 gen_op_movl_A0_reg(R_ESP
);
2577 gen_op_addl_A0_im(-16 << s
->dflag
);
2579 gen_op_andl_A0_ffff();
2580 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2582 gen_op_addl_A0_seg(R_SS
);
2583 for(i
= 0;i
< 8; i
++) {
2584 gen_op_mov_TN_reg(OT_LONG
, 0, 7 - i
);
2585 gen_op_st_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2586 gen_op_addl_A0_im(2 << s
->dflag
);
2588 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2591 /* NOTE: wrap around in 16 bit not fully handled */
2592 static void gen_popa(DisasContext
*s
)
2595 gen_op_movl_A0_reg(R_ESP
);
2597 gen_op_andl_A0_ffff();
2598 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2599 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], 16 << s
->dflag
);
2601 gen_op_addl_A0_seg(R_SS
);
2602 for(i
= 0;i
< 8; i
++) {
2603 /* ESP is not reloaded */
2605 gen_op_ld_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2606 gen_op_mov_reg_T0(OT_WORD
+ s
->dflag
, 7 - i
);
2608 gen_op_addl_A0_im(2 << s
->dflag
);
2610 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2613 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2618 #ifdef TARGET_X86_64
2620 ot
= s
->dflag
? OT_QUAD
: OT_WORD
;
2623 gen_op_movl_A0_reg(R_ESP
);
2624 gen_op_addq_A0_im(-opsize
);
2625 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2628 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2629 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2631 /* XXX: must save state */
2632 gen_helper_enter64_level(tcg_const_i32(level
),
2633 tcg_const_i32((ot
== OT_QUAD
)),
2636 gen_op_mov_reg_T1(ot
, R_EBP
);
2637 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2638 gen_op_mov_reg_T1(OT_QUAD
, R_ESP
);
2642 ot
= s
->dflag
+ OT_WORD
;
2643 opsize
= 2 << s
->dflag
;
2645 gen_op_movl_A0_reg(R_ESP
);
2646 gen_op_addl_A0_im(-opsize
);
2648 gen_op_andl_A0_ffff();
2649 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2651 gen_op_addl_A0_seg(R_SS
);
2653 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2654 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2656 /* XXX: must save state */
2657 gen_helper_enter_level(tcg_const_i32(level
),
2658 tcg_const_i32(s
->dflag
),
2661 gen_op_mov_reg_T1(ot
, R_EBP
);
2662 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2663 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2667 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2669 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2670 gen_op_set_cc_op(s
->cc_op
);
2671 gen_jmp_im(cur_eip
);
2672 gen_helper_raise_exception(tcg_const_i32(trapno
));
2676 /* an interrupt is different from an exception because of the
2678 static void gen_interrupt(DisasContext
*s
, int intno
,
2679 target_ulong cur_eip
, target_ulong next_eip
)
2681 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2682 gen_op_set_cc_op(s
->cc_op
);
2683 gen_jmp_im(cur_eip
);
2684 gen_helper_raise_interrupt(tcg_const_i32(intno
),
2685 tcg_const_i32(next_eip
- cur_eip
));
2689 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2691 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2692 gen_op_set_cc_op(s
->cc_op
);
2693 gen_jmp_im(cur_eip
);
2698 /* generate a generic end of block. Trace exception is also generated
2700 static void gen_eob(DisasContext
*s
)
2702 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2703 gen_op_set_cc_op(s
->cc_op
);
2704 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2705 gen_helper_reset_inhibit_irq();
2707 if (s
->singlestep_enabled
) {
2710 gen_helper_single_step();
2717 /* generate a jump to eip. No segment change must happen before as a
2718 direct call to the next block may occur */
2719 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2722 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2723 gen_op_set_cc_op(s
->cc_op
);
2724 s
->cc_op
= CC_OP_DYNAMIC
;
2726 gen_goto_tb(s
, tb_num
, eip
);
2734 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2736 gen_jmp_tb(s
, eip
, 0);
2739 static inline void gen_ldq_env_A0(int idx
, int offset
)
2741 int mem_index
= (idx
>> 2) - 1;
2742 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2743 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2746 static inline void gen_stq_env_A0(int idx
, int offset
)
2748 int mem_index
= (idx
>> 2) - 1;
2749 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2750 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2753 static inline void gen_ldo_env_A0(int idx
, int offset
)
2755 int mem_index
= (idx
>> 2) - 1;
2756 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2757 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2758 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2759 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2760 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2763 static inline void gen_sto_env_A0(int idx
, int offset
)
2765 int mem_index
= (idx
>> 2) - 1;
2766 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2767 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2768 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2769 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2770 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2773 static inline void gen_op_movo(int d_offset
, int s_offset
)
2775 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2776 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2777 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
+ 8);
2778 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
+ 8);
2781 static inline void gen_op_movq(int d_offset
, int s_offset
)
2783 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2784 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2787 static inline void gen_op_movl(int d_offset
, int s_offset
)
2789 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
, s_offset
);
2790 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, d_offset
);
2793 static inline void gen_op_movq_env_0(int d_offset
)
2795 tcg_gen_movi_i64(cpu_tmp1_i64
, 0);
2796 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2799 #define SSE_SPECIAL ((void *)1)
2800 #define SSE_DUMMY ((void *)2)
2802 #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm }
2803 #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \
2804 gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, }
2806 static void *sse_op_table1
[256][4] = {
2807 /* 3DNow! extensions */
2808 [0x0e] = { SSE_DUMMY
}, /* femms */
2809 [0x0f] = { SSE_DUMMY
}, /* pf... */
2810 /* pure SSE operations */
2811 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2812 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2813 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd, movsldup, movddup */
2814 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2815 [0x14] = { gen_helper_punpckldq_xmm
, gen_helper_punpcklqdq_xmm
},
2816 [0x15] = { gen_helper_punpckhdq_xmm
, gen_helper_punpckhqdq_xmm
},
2817 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2818 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2820 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2821 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2822 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2823 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd */
2824 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2825 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2826 [0x2e] = { gen_helper_ucomiss
, gen_helper_ucomisd
},
2827 [0x2f] = { gen_helper_comiss
, gen_helper_comisd
},
2828 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2829 [0x51] = SSE_FOP(sqrt
),
2830 [0x52] = { gen_helper_rsqrtps
, NULL
, gen_helper_rsqrtss
, NULL
},
2831 [0x53] = { gen_helper_rcpps
, NULL
, gen_helper_rcpss
, NULL
},
2832 [0x54] = { gen_helper_pand_xmm
, gen_helper_pand_xmm
}, /* andps, andpd */
2833 [0x55] = { gen_helper_pandn_xmm
, gen_helper_pandn_xmm
}, /* andnps, andnpd */
2834 [0x56] = { gen_helper_por_xmm
, gen_helper_por_xmm
}, /* orps, orpd */
2835 [0x57] = { gen_helper_pxor_xmm
, gen_helper_pxor_xmm
}, /* xorps, xorpd */
2836 [0x58] = SSE_FOP(add
),
2837 [0x59] = SSE_FOP(mul
),
2838 [0x5a] = { gen_helper_cvtps2pd
, gen_helper_cvtpd2ps
,
2839 gen_helper_cvtss2sd
, gen_helper_cvtsd2ss
},
2840 [0x5b] = { gen_helper_cvtdq2ps
, gen_helper_cvtps2dq
, gen_helper_cvttps2dq
},
2841 [0x5c] = SSE_FOP(sub
),
2842 [0x5d] = SSE_FOP(min
),
2843 [0x5e] = SSE_FOP(div
),
2844 [0x5f] = SSE_FOP(max
),
2846 [0xc2] = SSE_FOP(cmpeq
),
2847 [0xc6] = { gen_helper_shufps
, gen_helper_shufpd
},
2849 [0x38] = { SSE_SPECIAL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2850 [0x3a] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2852 /* MMX ops and their SSE extensions */
2853 [0x60] = MMX_OP2(punpcklbw
),
2854 [0x61] = MMX_OP2(punpcklwd
),
2855 [0x62] = MMX_OP2(punpckldq
),
2856 [0x63] = MMX_OP2(packsswb
),
2857 [0x64] = MMX_OP2(pcmpgtb
),
2858 [0x65] = MMX_OP2(pcmpgtw
),
2859 [0x66] = MMX_OP2(pcmpgtl
),
2860 [0x67] = MMX_OP2(packuswb
),
2861 [0x68] = MMX_OP2(punpckhbw
),
2862 [0x69] = MMX_OP2(punpckhwd
),
2863 [0x6a] = MMX_OP2(punpckhdq
),
2864 [0x6b] = MMX_OP2(packssdw
),
2865 [0x6c] = { NULL
, gen_helper_punpcklqdq_xmm
},
2866 [0x6d] = { NULL
, gen_helper_punpckhqdq_xmm
},
2867 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2868 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2869 [0x70] = { gen_helper_pshufw_mmx
,
2870 gen_helper_pshufd_xmm
,
2871 gen_helper_pshufhw_xmm
,
2872 gen_helper_pshuflw_xmm
},
2873 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2874 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2875 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2876 [0x74] = MMX_OP2(pcmpeqb
),
2877 [0x75] = MMX_OP2(pcmpeqw
),
2878 [0x76] = MMX_OP2(pcmpeql
),
2879 [0x77] = { SSE_DUMMY
}, /* emms */
2880 [0x7c] = { NULL
, gen_helper_haddpd
, NULL
, gen_helper_haddps
},
2881 [0x7d] = { NULL
, gen_helper_hsubpd
, NULL
, gen_helper_hsubps
},
2882 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2883 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2884 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2885 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2886 [0xd0] = { NULL
, gen_helper_addsubpd
, NULL
, gen_helper_addsubps
},
2887 [0xd1] = MMX_OP2(psrlw
),
2888 [0xd2] = MMX_OP2(psrld
),
2889 [0xd3] = MMX_OP2(psrlq
),
2890 [0xd4] = MMX_OP2(paddq
),
2891 [0xd5] = MMX_OP2(pmullw
),
2892 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2893 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2894 [0xd8] = MMX_OP2(psubusb
),
2895 [0xd9] = MMX_OP2(psubusw
),
2896 [0xda] = MMX_OP2(pminub
),
2897 [0xdb] = MMX_OP2(pand
),
2898 [0xdc] = MMX_OP2(paddusb
),
2899 [0xdd] = MMX_OP2(paddusw
),
2900 [0xde] = MMX_OP2(pmaxub
),
2901 [0xdf] = MMX_OP2(pandn
),
2902 [0xe0] = MMX_OP2(pavgb
),
2903 [0xe1] = MMX_OP2(psraw
),
2904 [0xe2] = MMX_OP2(psrad
),
2905 [0xe3] = MMX_OP2(pavgw
),
2906 [0xe4] = MMX_OP2(pmulhuw
),
2907 [0xe5] = MMX_OP2(pmulhw
),
2908 [0xe6] = { NULL
, gen_helper_cvttpd2dq
, gen_helper_cvtdq2pd
, gen_helper_cvtpd2dq
},
2909 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2910 [0xe8] = MMX_OP2(psubsb
),
2911 [0xe9] = MMX_OP2(psubsw
),
2912 [0xea] = MMX_OP2(pminsw
),
2913 [0xeb] = MMX_OP2(por
),
2914 [0xec] = MMX_OP2(paddsb
),
2915 [0xed] = MMX_OP2(paddsw
),
2916 [0xee] = MMX_OP2(pmaxsw
),
2917 [0xef] = MMX_OP2(pxor
),
2918 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu */
2919 [0xf1] = MMX_OP2(psllw
),
2920 [0xf2] = MMX_OP2(pslld
),
2921 [0xf3] = MMX_OP2(psllq
),
2922 [0xf4] = MMX_OP2(pmuludq
),
2923 [0xf5] = MMX_OP2(pmaddwd
),
2924 [0xf6] = MMX_OP2(psadbw
),
2925 [0xf7] = MMX_OP2(maskmov
),
2926 [0xf8] = MMX_OP2(psubb
),
2927 [0xf9] = MMX_OP2(psubw
),
2928 [0xfa] = MMX_OP2(psubl
),
2929 [0xfb] = MMX_OP2(psubq
),
2930 [0xfc] = MMX_OP2(paddb
),
2931 [0xfd] = MMX_OP2(paddw
),
2932 [0xfe] = MMX_OP2(paddl
),
2935 static void *sse_op_table2
[3 * 8][2] = {
2936 [0 + 2] = MMX_OP2(psrlw
),
2937 [0 + 4] = MMX_OP2(psraw
),
2938 [0 + 6] = MMX_OP2(psllw
),
2939 [8 + 2] = MMX_OP2(psrld
),
2940 [8 + 4] = MMX_OP2(psrad
),
2941 [8 + 6] = MMX_OP2(pslld
),
2942 [16 + 2] = MMX_OP2(psrlq
),
2943 [16 + 3] = { NULL
, gen_helper_psrldq_xmm
},
2944 [16 + 6] = MMX_OP2(psllq
),
2945 [16 + 7] = { NULL
, gen_helper_pslldq_xmm
},
2948 static void *sse_op_table3
[4 * 3] = {
2949 gen_helper_cvtsi2ss
,
2950 gen_helper_cvtsi2sd
,
2951 X86_64_ONLY(gen_helper_cvtsq2ss
),
2952 X86_64_ONLY(gen_helper_cvtsq2sd
),
2954 gen_helper_cvttss2si
,
2955 gen_helper_cvttsd2si
,
2956 X86_64_ONLY(gen_helper_cvttss2sq
),
2957 X86_64_ONLY(gen_helper_cvttsd2sq
),
2959 gen_helper_cvtss2si
,
2960 gen_helper_cvtsd2si
,
2961 X86_64_ONLY(gen_helper_cvtss2sq
),
2962 X86_64_ONLY(gen_helper_cvtsd2sq
),
2965 static void *sse_op_table4
[8][4] = {
2976 static void *sse_op_table5
[256] = {
2977 [0x0c] = gen_helper_pi2fw
,
2978 [0x0d] = gen_helper_pi2fd
,
2979 [0x1c] = gen_helper_pf2iw
,
2980 [0x1d] = gen_helper_pf2id
,
2981 [0x8a] = gen_helper_pfnacc
,
2982 [0x8e] = gen_helper_pfpnacc
,
2983 [0x90] = gen_helper_pfcmpge
,
2984 [0x94] = gen_helper_pfmin
,
2985 [0x96] = gen_helper_pfrcp
,
2986 [0x97] = gen_helper_pfrsqrt
,
2987 [0x9a] = gen_helper_pfsub
,
2988 [0x9e] = gen_helper_pfadd
,
2989 [0xa0] = gen_helper_pfcmpgt
,
2990 [0xa4] = gen_helper_pfmax
,
2991 [0xa6] = gen_helper_movq
, /* pfrcpit1; no need to actually increase precision */
2992 [0xa7] = gen_helper_movq
, /* pfrsqit1 */
2993 [0xaa] = gen_helper_pfsubr
,
2994 [0xae] = gen_helper_pfacc
,
2995 [0xb0] = gen_helper_pfcmpeq
,
2996 [0xb4] = gen_helper_pfmul
,
2997 [0xb6] = gen_helper_movq
, /* pfrcpit2 */
2998 [0xb7] = gen_helper_pmulhrw_mmx
,
2999 [0xbb] = gen_helper_pswapd
,
3000 [0xbf] = gen_helper_pavgb_mmx
/* pavgusb */
3003 struct sse_op_helper_s
{
3004 void *op
[2]; uint32_t ext_mask
;
3006 #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
3007 #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 }
3008 #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 }
3009 #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 }
3010 static struct sse_op_helper_s sse_op_table6
[256] = {
3011 [0x00] = SSSE3_OP(pshufb
),
3012 [0x01] = SSSE3_OP(phaddw
),
3013 [0x02] = SSSE3_OP(phaddd
),
3014 [0x03] = SSSE3_OP(phaddsw
),
3015 [0x04] = SSSE3_OP(pmaddubsw
),
3016 [0x05] = SSSE3_OP(phsubw
),
3017 [0x06] = SSSE3_OP(phsubd
),
3018 [0x07] = SSSE3_OP(phsubsw
),
3019 [0x08] = SSSE3_OP(psignb
),
3020 [0x09] = SSSE3_OP(psignw
),
3021 [0x0a] = SSSE3_OP(psignd
),
3022 [0x0b] = SSSE3_OP(pmulhrsw
),
3023 [0x10] = SSE41_OP(pblendvb
),
3024 [0x14] = SSE41_OP(blendvps
),
3025 [0x15] = SSE41_OP(blendvpd
),
3026 [0x17] = SSE41_OP(ptest
),
3027 [0x1c] = SSSE3_OP(pabsb
),
3028 [0x1d] = SSSE3_OP(pabsw
),
3029 [0x1e] = SSSE3_OP(pabsd
),
3030 [0x20] = SSE41_OP(pmovsxbw
),
3031 [0x21] = SSE41_OP(pmovsxbd
),
3032 [0x22] = SSE41_OP(pmovsxbq
),
3033 [0x23] = SSE41_OP(pmovsxwd
),
3034 [0x24] = SSE41_OP(pmovsxwq
),
3035 [0x25] = SSE41_OP(pmovsxdq
),
3036 [0x28] = SSE41_OP(pmuldq
),
3037 [0x29] = SSE41_OP(pcmpeqq
),
3038 [0x2a] = SSE41_SPECIAL
, /* movntqda */
3039 [0x2b] = SSE41_OP(packusdw
),
3040 [0x30] = SSE41_OP(pmovzxbw
),
3041 [0x31] = SSE41_OP(pmovzxbd
),
3042 [0x32] = SSE41_OP(pmovzxbq
),
3043 [0x33] = SSE41_OP(pmovzxwd
),
3044 [0x34] = SSE41_OP(pmovzxwq
),
3045 [0x35] = SSE41_OP(pmovzxdq
),
3046 [0x37] = SSE42_OP(pcmpgtq
),
3047 [0x38] = SSE41_OP(pminsb
),
3048 [0x39] = SSE41_OP(pminsd
),
3049 [0x3a] = SSE41_OP(pminuw
),
3050 [0x3b] = SSE41_OP(pminud
),
3051 [0x3c] = SSE41_OP(pmaxsb
),
3052 [0x3d] = SSE41_OP(pmaxsd
),
3053 [0x3e] = SSE41_OP(pmaxuw
),
3054 [0x3f] = SSE41_OP(pmaxud
),
3055 [0x40] = SSE41_OP(pmulld
),
3056 [0x41] = SSE41_OP(phminposuw
),
3059 static struct sse_op_helper_s sse_op_table7
[256] = {
3060 [0x08] = SSE41_OP(roundps
),
3061 [0x09] = SSE41_OP(roundpd
),
3062 [0x0a] = SSE41_OP(roundss
),
3063 [0x0b] = SSE41_OP(roundsd
),
3064 [0x0c] = SSE41_OP(blendps
),
3065 [0x0d] = SSE41_OP(blendpd
),
3066 [0x0e] = SSE41_OP(pblendw
),
3067 [0x0f] = SSSE3_OP(palignr
),
3068 [0x14] = SSE41_SPECIAL
, /* pextrb */
3069 [0x15] = SSE41_SPECIAL
, /* pextrw */
3070 [0x16] = SSE41_SPECIAL
, /* pextrd/pextrq */
3071 [0x17] = SSE41_SPECIAL
, /* extractps */
3072 [0x20] = SSE41_SPECIAL
, /* pinsrb */
3073 [0x21] = SSE41_SPECIAL
, /* insertps */
3074 [0x22] = SSE41_SPECIAL
, /* pinsrd/pinsrq */
3075 [0x40] = SSE41_OP(dpps
),
3076 [0x41] = SSE41_OP(dppd
),
3077 [0x42] = SSE41_OP(mpsadbw
),
3078 [0x60] = SSE42_OP(pcmpestrm
),
3079 [0x61] = SSE42_OP(pcmpestri
),
3080 [0x62] = SSE42_OP(pcmpistrm
),
3081 [0x63] = SSE42_OP(pcmpistri
),
3084 static void gen_sse(DisasContext
*s
, int b
, target_ulong pc_start
, int rex_r
)
3086 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
3087 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
3091 if (s
->prefix
& PREFIX_DATA
)
3093 else if (s
->prefix
& PREFIX_REPZ
)
3095 else if (s
->prefix
& PREFIX_REPNZ
)
3099 sse_op2
= sse_op_table1
[b
][b1
];
3102 if ((b
<= 0x5f && b
>= 0x10) || b
== 0xc6 || b
== 0xc2) {
3112 /* simple MMX/SSE operation */
3113 if (s
->flags
& HF_TS_MASK
) {
3114 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
3117 if (s
->flags
& HF_EM_MASK
) {
3119 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
3122 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
3123 if ((b
!= 0x38 && b
!= 0x3a) || (s
->prefix
& PREFIX_DATA
))
3126 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3137 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
3138 the static cpu state) */
3140 gen_helper_enter_mmx();
3143 modrm
= ldub_code(s
->pc
++);
3144 reg
= ((modrm
>> 3) & 7);
3147 mod
= (modrm
>> 6) & 3;
3148 if (sse_op2
== SSE_SPECIAL
) {
3151 case 0x0e7: /* movntq */
3154 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3155 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3157 case 0x1e7: /* movntdq */
3158 case 0x02b: /* movntps */
3159 case 0x12b: /* movntps */
3160 case 0x3f0: /* lddqu */
3163 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3164 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3166 case 0x6e: /* movd mm, ea */
3167 #ifdef TARGET_X86_64
3168 if (s
->dflag
== 2) {
3169 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3170 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3174 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3175 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3176 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3177 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3178 gen_helper_movl_mm_T0_mmx(cpu_ptr0
, cpu_tmp2_i32
);
3181 case 0x16e: /* movd xmm, ea */
3182 #ifdef TARGET_X86_64
3183 if (s
->dflag
== 2) {
3184 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3185 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3186 offsetof(CPUX86State
,xmm_regs
[reg
]));
3187 gen_helper_movq_mm_T0_xmm(cpu_ptr0
, cpu_T
[0]);
3191 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3192 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3193 offsetof(CPUX86State
,xmm_regs
[reg
]));
3194 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3195 gen_helper_movl_mm_T0_xmm(cpu_ptr0
, cpu_tmp2_i32
);
3198 case 0x6f: /* movq mm, ea */
3200 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3201 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3204 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3205 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3206 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3207 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3210 case 0x010: /* movups */
3211 case 0x110: /* movupd */
3212 case 0x028: /* movaps */
3213 case 0x128: /* movapd */
3214 case 0x16f: /* movdqa xmm, ea */
3215 case 0x26f: /* movdqu xmm, ea */
3217 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3218 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3220 rm
= (modrm
& 7) | REX_B(s
);
3221 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
3222 offsetof(CPUX86State
,xmm_regs
[rm
]));
3225 case 0x210: /* movss xmm, ea */
3227 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3228 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3229 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3231 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3232 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3233 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3235 rm
= (modrm
& 7) | REX_B(s
);
3236 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3237 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3240 case 0x310: /* movsd xmm, ea */
3242 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3243 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3245 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3246 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3248 rm
= (modrm
& 7) | REX_B(s
);
3249 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3250 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3253 case 0x012: /* movlps */
3254 case 0x112: /* movlpd */
3256 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3257 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3260 rm
= (modrm
& 7) | REX_B(s
);
3261 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3262 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3265 case 0x212: /* movsldup */
3267 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3268 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3270 rm
= (modrm
& 7) | REX_B(s
);
3271 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3272 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3273 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3274 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(2)));
3276 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3277 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3278 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3279 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3281 case 0x312: /* movddup */
3283 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3284 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3286 rm
= (modrm
& 7) | REX_B(s
);
3287 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3288 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3290 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3291 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3293 case 0x016: /* movhps */
3294 case 0x116: /* movhpd */
3296 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3297 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3300 rm
= (modrm
& 7) | REX_B(s
);
3301 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3302 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3305 case 0x216: /* movshdup */
3307 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3308 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3310 rm
= (modrm
& 7) | REX_B(s
);
3311 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3312 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
3313 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3314 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
3316 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3317 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3318 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3319 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3321 case 0x7e: /* movd ea, mm */
3322 #ifdef TARGET_X86_64
3323 if (s
->dflag
== 2) {
3324 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3325 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3326 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3330 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3331 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_L(0)));
3332 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3335 case 0x17e: /* movd ea, xmm */
3336 #ifdef TARGET_X86_64
3337 if (s
->dflag
== 2) {
3338 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3339 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3340 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3344 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3345 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3346 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3349 case 0x27e: /* movq xmm, ea */
3351 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3352 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3354 rm
= (modrm
& 7) | REX_B(s
);
3355 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3356 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3358 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3360 case 0x7f: /* movq ea, mm */
3362 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3363 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3366 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
3367 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3370 case 0x011: /* movups */
3371 case 0x111: /* movupd */
3372 case 0x029: /* movaps */
3373 case 0x129: /* movapd */
3374 case 0x17f: /* movdqa ea, xmm */
3375 case 0x27f: /* movdqu ea, xmm */
3377 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3378 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3380 rm
= (modrm
& 7) | REX_B(s
);
3381 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
3382 offsetof(CPUX86State
,xmm_regs
[reg
]));
3385 case 0x211: /* movss ea, xmm */
3387 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3388 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3389 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3391 rm
= (modrm
& 7) | REX_B(s
);
3392 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
3393 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3396 case 0x311: /* movsd ea, xmm */
3398 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3399 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3401 rm
= (modrm
& 7) | REX_B(s
);
3402 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3403 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3406 case 0x013: /* movlps */
3407 case 0x113: /* movlpd */
3409 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3410 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3415 case 0x017: /* movhps */
3416 case 0x117: /* movhpd */
3418 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3419 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3424 case 0x71: /* shift mm, im */
3427 case 0x171: /* shift xmm, im */
3430 val
= ldub_code(s
->pc
++);
3432 gen_op_movl_T0_im(val
);
3433 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3435 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
3436 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
3438 gen_op_movl_T0_im(val
);
3439 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
3441 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
3442 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
3444 sse_op2
= sse_op_table2
[((b
- 1) & 3) * 8 + (((modrm
>> 3)) & 7)][b1
];
3448 rm
= (modrm
& 7) | REX_B(s
);
3449 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3452 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3454 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3455 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op1_offset
);
3456 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3458 case 0x050: /* movmskps */
3459 rm
= (modrm
& 7) | REX_B(s
);
3460 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3461 offsetof(CPUX86State
,xmm_regs
[rm
]));
3462 gen_helper_movmskps(cpu_tmp2_i32
, cpu_ptr0
);
3463 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3464 gen_op_mov_reg_T0(OT_LONG
, reg
);
3466 case 0x150: /* movmskpd */
3467 rm
= (modrm
& 7) | REX_B(s
);
3468 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3469 offsetof(CPUX86State
,xmm_regs
[rm
]));
3470 gen_helper_movmskpd(cpu_tmp2_i32
, cpu_ptr0
);
3471 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3472 gen_op_mov_reg_T0(OT_LONG
, reg
);
3474 case 0x02a: /* cvtpi2ps */
3475 case 0x12a: /* cvtpi2pd */
3476 gen_helper_enter_mmx();
3478 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3479 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3480 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3483 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3485 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3486 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3487 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3490 gen_helper_cvtpi2ps(cpu_ptr0
, cpu_ptr1
);
3494 gen_helper_cvtpi2pd(cpu_ptr0
, cpu_ptr1
);
3498 case 0x22a: /* cvtsi2ss */
3499 case 0x32a: /* cvtsi2sd */
3500 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3501 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3502 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3503 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3504 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2)];
3505 if (ot
== OT_LONG
) {
3506 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3507 ((void (*)(TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_tmp2_i32
);
3509 ((void (*)(TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_T
[0]);
3512 case 0x02c: /* cvttps2pi */
3513 case 0x12c: /* cvttpd2pi */
3514 case 0x02d: /* cvtps2pi */
3515 case 0x12d: /* cvtpd2pi */
3516 gen_helper_enter_mmx();
3518 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3519 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3520 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3522 rm
= (modrm
& 7) | REX_B(s
);
3523 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3525 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
3526 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3527 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3530 gen_helper_cvttps2pi(cpu_ptr0
, cpu_ptr1
);
3533 gen_helper_cvttpd2pi(cpu_ptr0
, cpu_ptr1
);
3536 gen_helper_cvtps2pi(cpu_ptr0
, cpu_ptr1
);
3539 gen_helper_cvtpd2pi(cpu_ptr0
, cpu_ptr1
);
3543 case 0x22c: /* cvttss2si */
3544 case 0x32c: /* cvttsd2si */
3545 case 0x22d: /* cvtss2si */
3546 case 0x32d: /* cvtsd2si */
3547 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3549 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3551 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
3553 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3554 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3556 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3558 rm
= (modrm
& 7) | REX_B(s
);
3559 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3561 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2) + 4 +
3563 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3564 if (ot
== OT_LONG
) {
3565 ((void (*)(TCGv_i32
, TCGv_ptr
))sse_op2
)(cpu_tmp2_i32
, cpu_ptr0
);
3566 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3568 ((void (*)(TCGv
, TCGv_ptr
))sse_op2
)(cpu_T
[0], cpu_ptr0
);
3570 gen_op_mov_reg_T0(ot
, reg
);
3572 case 0xc4: /* pinsrw */
3575 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3576 val
= ldub_code(s
->pc
++);
3579 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3580 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_W(val
)));
3583 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3584 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_W(val
)));
3587 case 0xc5: /* pextrw */
3591 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3592 val
= ldub_code(s
->pc
++);
3595 rm
= (modrm
& 7) | REX_B(s
);
3596 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3597 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_W(val
)));
3601 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3602 offsetof(CPUX86State
,fpregs
[rm
].mmx
.MMX_W(val
)));
3604 reg
= ((modrm
>> 3) & 7) | rex_r
;
3605 gen_op_mov_reg_T0(ot
, reg
);
3607 case 0x1d6: /* movq ea, xmm */
3609 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3610 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3612 rm
= (modrm
& 7) | REX_B(s
);
3613 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3614 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3615 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3618 case 0x2d6: /* movq2dq */
3619 gen_helper_enter_mmx();
3621 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3622 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3623 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3625 case 0x3d6: /* movdq2q */
3626 gen_helper_enter_mmx();
3627 rm
= (modrm
& 7) | REX_B(s
);
3628 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
),
3629 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3631 case 0xd7: /* pmovmskb */
3636 rm
= (modrm
& 7) | REX_B(s
);
3637 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,xmm_regs
[rm
]));
3638 gen_helper_pmovmskb_xmm(cpu_tmp2_i32
, cpu_ptr0
);
3641 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3642 gen_helper_pmovmskb_mmx(cpu_tmp2_i32
, cpu_ptr0
);
3644 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3645 reg
= ((modrm
>> 3) & 7) | rex_r
;
3646 gen_op_mov_reg_T0(OT_LONG
, reg
);
3649 if (s
->prefix
& PREFIX_REPNZ
)
3653 modrm
= ldub_code(s
->pc
++);
3655 reg
= ((modrm
>> 3) & 7) | rex_r
;
3656 mod
= (modrm
>> 6) & 3;
3658 sse_op2
= sse_op_table6
[b
].op
[b1
];
3661 if (!(s
->cpuid_ext_features
& sse_op_table6
[b
].ext_mask
))
3665 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3667 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3669 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3670 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3672 case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */
3673 case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */
3674 case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */
3675 gen_ldq_env_A0(s
->mem_index
, op2_offset
+
3676 offsetof(XMMReg
, XMM_Q(0)));
3678 case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */
3679 case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */
3680 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3681 (s
->mem_index
>> 2) - 1);
3682 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3683 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, op2_offset
+
3684 offsetof(XMMReg
, XMM_L(0)));
3686 case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */
3687 tcg_gen_qemu_ld16u(cpu_tmp0
, cpu_A0
,
3688 (s
->mem_index
>> 2) - 1);
3689 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, op2_offset
+
3690 offsetof(XMMReg
, XMM_W(0)));
3692 case 0x2a: /* movntqda */
3693 gen_ldo_env_A0(s
->mem_index
, op1_offset
);
3696 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3700 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3702 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3704 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3705 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3706 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3709 if (sse_op2
== SSE_SPECIAL
)
3712 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3713 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3714 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3717 s
->cc_op
= CC_OP_EFLAGS
;
3719 case 0x338: /* crc32 */
3722 modrm
= ldub_code(s
->pc
++);
3723 reg
= ((modrm
>> 3) & 7) | rex_r
;
3725 if (b
!= 0xf0 && b
!= 0xf1)
3727 if (!(s
->cpuid_ext_features
& CPUID_EXT_SSE42
))
3732 else if (b
== 0xf1 && s
->dflag
!= 2)
3733 if (s
->prefix
& PREFIX_DATA
)
3740 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
3741 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3742 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3743 gen_helper_crc32(cpu_T
[0], cpu_tmp2_i32
,
3744 cpu_T
[0], tcg_const_i32(8 << ot
));
3746 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3747 gen_op_mov_reg_T0(ot
, reg
);
3752 modrm
= ldub_code(s
->pc
++);
3754 reg
= ((modrm
>> 3) & 7) | rex_r
;
3755 mod
= (modrm
>> 6) & 3;
3757 sse_op2
= sse_op_table7
[b
].op
[b1
];
3760 if (!(s
->cpuid_ext_features
& sse_op_table7
[b
].ext_mask
))
3763 if (sse_op2
== SSE_SPECIAL
) {
3764 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3765 rm
= (modrm
& 7) | REX_B(s
);
3767 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3768 reg
= ((modrm
>> 3) & 7) | rex_r
;
3769 val
= ldub_code(s
->pc
++);
3771 case 0x14: /* pextrb */
3772 tcg_gen_ld8u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3773 xmm_regs
[reg
].XMM_B(val
& 15)));
3775 gen_op_mov_reg_T0(ot
, rm
);
3777 tcg_gen_qemu_st8(cpu_T
[0], cpu_A0
,
3778 (s
->mem_index
>> 2) - 1);
3780 case 0x15: /* pextrw */
3781 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3782 xmm_regs
[reg
].XMM_W(val
& 7)));
3784 gen_op_mov_reg_T0(ot
, rm
);
3786 tcg_gen_qemu_st16(cpu_T
[0], cpu_A0
,
3787 (s
->mem_index
>> 2) - 1);
3790 if (ot
== OT_LONG
) { /* pextrd */
3791 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3792 offsetof(CPUX86State
,
3793 xmm_regs
[reg
].XMM_L(val
& 3)));
3794 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3796 gen_op_mov_reg_v(ot
, rm
, cpu_T
[0]);
3798 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3799 (s
->mem_index
>> 2) - 1);
3800 } else { /* pextrq */
3801 #ifdef TARGET_X86_64
3802 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3803 offsetof(CPUX86State
,
3804 xmm_regs
[reg
].XMM_Q(val
& 1)));
3806 gen_op_mov_reg_v(ot
, rm
, cpu_tmp1_i64
);
3808 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
3809 (s
->mem_index
>> 2) - 1);
3815 case 0x17: /* extractps */
3816 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3817 xmm_regs
[reg
].XMM_L(val
& 3)));
3819 gen_op_mov_reg_T0(ot
, rm
);
3821 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3822 (s
->mem_index
>> 2) - 1);
3824 case 0x20: /* pinsrb */
3826 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
3828 tcg_gen_qemu_ld8u(cpu_tmp0
, cpu_A0
,
3829 (s
->mem_index
>> 2) - 1);
3830 tcg_gen_st8_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
,
3831 xmm_regs
[reg
].XMM_B(val
& 15)));
3833 case 0x21: /* insertps */
3835 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3836 offsetof(CPUX86State
,xmm_regs
[rm
]
3837 .XMM_L((val
>> 6) & 3)));
3839 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3840 (s
->mem_index
>> 2) - 1);
3841 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3843 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3844 offsetof(CPUX86State
,xmm_regs
[reg
]
3845 .XMM_L((val
>> 4) & 3)));
3847 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3848 cpu_env
, offsetof(CPUX86State
,
3849 xmm_regs
[reg
].XMM_L(0)));
3851 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3852 cpu_env
, offsetof(CPUX86State
,
3853 xmm_regs
[reg
].XMM_L(1)));
3855 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3856 cpu_env
, offsetof(CPUX86State
,
3857 xmm_regs
[reg
].XMM_L(2)));
3859 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3860 cpu_env
, offsetof(CPUX86State
,
3861 xmm_regs
[reg
].XMM_L(3)));
3864 if (ot
== OT_LONG
) { /* pinsrd */
3866 gen_op_mov_v_reg(ot
, cpu_tmp0
, rm
);
3868 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3869 (s
->mem_index
>> 2) - 1);
3870 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3871 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3872 offsetof(CPUX86State
,
3873 xmm_regs
[reg
].XMM_L(val
& 3)));
3874 } else { /* pinsrq */
3875 #ifdef TARGET_X86_64
3877 gen_op_mov_v_reg(ot
, cpu_tmp1_i64
, rm
);
3879 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
3880 (s
->mem_index
>> 2) - 1);
3881 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3882 offsetof(CPUX86State
,
3883 xmm_regs
[reg
].XMM_Q(val
& 1)));
3894 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3896 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3898 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3899 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3900 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3903 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3905 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3907 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3908 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3909 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3912 val
= ldub_code(s
->pc
++);
3914 if ((b
& 0xfc) == 0x60) { /* pcmpXstrX */
3915 s
->cc_op
= CC_OP_EFLAGS
;
3918 /* The helper must use entire 64-bit gp registers */
3922 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3923 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3924 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
3930 /* generic MMX or SSE operation */
3932 case 0x70: /* pshufx insn */
3933 case 0xc6: /* pshufx insn */
3934 case 0xc2: /* compare insns */
3941 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3943 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3944 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3945 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f && b
!= 0x5b) ||
3947 /* specific case for SSE single instructions */
3950 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3951 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3954 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
3957 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3960 rm
= (modrm
& 7) | REX_B(s
);
3961 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3964 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3966 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3967 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3968 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3971 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3975 case 0x0f: /* 3DNow! data insns */
3976 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3978 val
= ldub_code(s
->pc
++);
3979 sse_op2
= sse_op_table5
[val
];
3982 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3983 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3984 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3986 case 0x70: /* pshufx insn */
3987 case 0xc6: /* pshufx insn */
3988 val
= ldub_code(s
->pc
++);
3989 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3990 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3991 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
3995 val
= ldub_code(s
->pc
++);
3998 sse_op2
= sse_op_table4
[val
][b1
];
3999 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4000 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4001 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4004 /* maskmov : we must prepare A0 */
4007 #ifdef TARGET_X86_64
4008 if (s
->aflag
== 2) {
4009 gen_op_movq_A0_reg(R_EDI
);
4013 gen_op_movl_A0_reg(R_EDI
);
4015 gen_op_andl_A0_ffff();
4017 gen_add_A0_ds_seg(s
);
4019 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4020 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4021 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, cpu_A0
);
4024 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4025 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4026 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4029 if (b
== 0x2e || b
== 0x2f) {
4030 s
->cc_op
= CC_OP_EFLAGS
;
4035 /* convert one instruction. s->is_jmp is set if the translation must
4036 be stopped. Return the next pc value */
4037 static target_ulong
disas_insn(DisasContext
*s
, target_ulong pc_start
)
4039 int b
, prefixes
, aflag
, dflag
;
4041 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
4042 target_ulong next_eip
, tval
;
4045 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
4046 tcg_gen_debug_insn_start(pc_start
);
4054 #ifdef TARGET_X86_64
4059 s
->rip_offset
= 0; /* for relative ip address */
4061 b
= ldub_code(s
->pc
);
4063 /* check prefixes */
4064 #ifdef TARGET_X86_64
4068 prefixes
|= PREFIX_REPZ
;
4071 prefixes
|= PREFIX_REPNZ
;
4074 prefixes
|= PREFIX_LOCK
;
4095 prefixes
|= PREFIX_DATA
;
4098 prefixes
|= PREFIX_ADR
;
4102 rex_w
= (b
>> 3) & 1;
4103 rex_r
= (b
& 0x4) << 1;
4104 s
->rex_x
= (b
& 0x2) << 2;
4105 REX_B(s
) = (b
& 0x1) << 3;
4106 x86_64_hregs
= 1; /* select uniform byte register addressing */
4110 /* 0x66 is ignored if rex.w is set */
4113 if (prefixes
& PREFIX_DATA
)
4116 if (!(prefixes
& PREFIX_ADR
))
4123 prefixes
|= PREFIX_REPZ
;
4126 prefixes
|= PREFIX_REPNZ
;
4129 prefixes
|= PREFIX_LOCK
;
4150 prefixes
|= PREFIX_DATA
;
4153 prefixes
|= PREFIX_ADR
;
4156 if (prefixes
& PREFIX_DATA
)
4158 if (prefixes
& PREFIX_ADR
)
4162 s
->prefix
= prefixes
;
4166 /* lock generation */
4167 if (prefixes
& PREFIX_LOCK
)
4170 /* now check op code */
4174 /**************************/
4175 /* extended op code */
4176 b
= ldub_code(s
->pc
++) | 0x100;
4179 /**************************/
4197 ot
= dflag
+ OT_WORD
;
4200 case 0: /* OP Ev, Gv */
4201 modrm
= ldub_code(s
->pc
++);
4202 reg
= ((modrm
>> 3) & 7) | rex_r
;
4203 mod
= (modrm
>> 6) & 3;
4204 rm
= (modrm
& 7) | REX_B(s
);
4206 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4208 } else if (op
== OP_XORL
&& rm
== reg
) {
4210 /* xor reg, reg optimisation */
4212 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4213 gen_op_mov_reg_T0(ot
, reg
);
4214 gen_op_update1_cc();
4219 gen_op_mov_TN_reg(ot
, 1, reg
);
4220 gen_op(s
, op
, ot
, opreg
);
4222 case 1: /* OP Gv, Ev */
4223 modrm
= ldub_code(s
->pc
++);
4224 mod
= (modrm
>> 6) & 3;
4225 reg
= ((modrm
>> 3) & 7) | rex_r
;
4226 rm
= (modrm
& 7) | REX_B(s
);
4228 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4229 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4230 } else if (op
== OP_XORL
&& rm
== reg
) {
4233 gen_op_mov_TN_reg(ot
, 1, rm
);
4235 gen_op(s
, op
, ot
, reg
);
4237 case 2: /* OP A, Iv */
4238 val
= insn_get(s
, ot
);
4239 gen_op_movl_T1_im(val
);
4240 gen_op(s
, op
, ot
, OR_EAX
);
4249 case 0x80: /* GRP1 */
4258 ot
= dflag
+ OT_WORD
;
4260 modrm
= ldub_code(s
->pc
++);
4261 mod
= (modrm
>> 6) & 3;
4262 rm
= (modrm
& 7) | REX_B(s
);
4263 op
= (modrm
>> 3) & 7;
4269 s
->rip_offset
= insn_const_size(ot
);
4270 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4281 val
= insn_get(s
, ot
);
4284 val
= (int8_t)insn_get(s
, OT_BYTE
);
4287 gen_op_movl_T1_im(val
);
4288 gen_op(s
, op
, ot
, opreg
);
4292 /**************************/
4293 /* inc, dec, and other misc arith */
4294 case 0x40 ... 0x47: /* inc Gv */
4295 ot
= dflag
? OT_LONG
: OT_WORD
;
4296 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
4298 case 0x48 ... 0x4f: /* dec Gv */
4299 ot
= dflag
? OT_LONG
: OT_WORD
;
4300 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
4302 case 0xf6: /* GRP3 */
4307 ot
= dflag
+ OT_WORD
;
4309 modrm
= ldub_code(s
->pc
++);
4310 mod
= (modrm
>> 6) & 3;
4311 rm
= (modrm
& 7) | REX_B(s
);
4312 op
= (modrm
>> 3) & 7;
4315 s
->rip_offset
= insn_const_size(ot
);
4316 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4317 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4319 gen_op_mov_TN_reg(ot
, 0, rm
);
4324 val
= insn_get(s
, ot
);
4325 gen_op_movl_T1_im(val
);
4326 gen_op_testl_T0_T1_cc();
4327 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4330 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
4332 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4334 gen_op_mov_reg_T0(ot
, rm
);
4338 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
4340 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4342 gen_op_mov_reg_T0(ot
, rm
);
4344 gen_op_update_neg_cc();
4345 s
->cc_op
= CC_OP_SUBB
+ ot
;
4350 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4351 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
4352 tcg_gen_ext8u_tl(cpu_T
[1], cpu_T
[1]);
4353 /* XXX: use 32 bit mul which could be faster */
4354 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4355 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4356 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4357 tcg_gen_andi_tl(cpu_cc_src
, cpu_T
[0], 0xff00);
4358 s
->cc_op
= CC_OP_MULB
;
4361 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4362 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
4363 tcg_gen_ext16u_tl(cpu_T
[1], cpu_T
[1]);
4364 /* XXX: use 32 bit mul which could be faster */
4365 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4366 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4367 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4368 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4369 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4370 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4371 s
->cc_op
= CC_OP_MULW
;
4375 #ifdef TARGET_X86_64
4376 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4377 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
4378 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
4379 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4380 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4381 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4382 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4383 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4384 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4388 t0
= tcg_temp_new_i64();
4389 t1
= tcg_temp_new_i64();
4390 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4391 tcg_gen_extu_i32_i64(t0
, cpu_T
[0]);
4392 tcg_gen_extu_i32_i64(t1
, cpu_T
[1]);
4393 tcg_gen_mul_i64(t0
, t0
, t1
);
4394 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4395 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4396 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4397 tcg_gen_shri_i64(t0
, t0
, 32);
4398 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4399 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4400 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4403 s
->cc_op
= CC_OP_MULL
;
4405 #ifdef TARGET_X86_64
4407 gen_helper_mulq_EAX_T0(cpu_T
[0]);
4408 s
->cc_op
= CC_OP_MULQ
;
4416 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4417 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4418 tcg_gen_ext8s_tl(cpu_T
[1], cpu_T
[1]);
4419 /* XXX: use 32 bit mul which could be faster */
4420 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4421 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4422 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4423 tcg_gen_ext8s_tl(cpu_tmp0
, cpu_T
[0]);
4424 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4425 s
->cc_op
= CC_OP_MULB
;
4428 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4429 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4430 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4431 /* XXX: use 32 bit mul which could be faster */
4432 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4433 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4434 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4435 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4436 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4437 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4438 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4439 s
->cc_op
= CC_OP_MULW
;
4443 #ifdef TARGET_X86_64
4444 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4445 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4446 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4447 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4448 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4449 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4450 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4451 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4452 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4453 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4457 t0
= tcg_temp_new_i64();
4458 t1
= tcg_temp_new_i64();
4459 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4460 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4461 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4462 tcg_gen_mul_i64(t0
, t0
, t1
);
4463 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4464 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4465 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4466 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4467 tcg_gen_shri_i64(t0
, t0
, 32);
4468 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4469 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4470 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4473 s
->cc_op
= CC_OP_MULL
;
4475 #ifdef TARGET_X86_64
4477 gen_helper_imulq_EAX_T0(cpu_T
[0]);
4478 s
->cc_op
= CC_OP_MULQ
;
4486 gen_jmp_im(pc_start
- s
->cs_base
);
4487 gen_helper_divb_AL(cpu_T
[0]);
4490 gen_jmp_im(pc_start
- s
->cs_base
);
4491 gen_helper_divw_AX(cpu_T
[0]);
4495 gen_jmp_im(pc_start
- s
->cs_base
);
4496 gen_helper_divl_EAX(cpu_T
[0]);
4498 #ifdef TARGET_X86_64
4500 gen_jmp_im(pc_start
- s
->cs_base
);
4501 gen_helper_divq_EAX(cpu_T
[0]);
4509 gen_jmp_im(pc_start
- s
->cs_base
);
4510 gen_helper_idivb_AL(cpu_T
[0]);
4513 gen_jmp_im(pc_start
- s
->cs_base
);
4514 gen_helper_idivw_AX(cpu_T
[0]);
4518 gen_jmp_im(pc_start
- s
->cs_base
);
4519 gen_helper_idivl_EAX(cpu_T
[0]);
4521 #ifdef TARGET_X86_64
4523 gen_jmp_im(pc_start
- s
->cs_base
);
4524 gen_helper_idivq_EAX(cpu_T
[0]);
4534 case 0xfe: /* GRP4 */
4535 case 0xff: /* GRP5 */
4539 ot
= dflag
+ OT_WORD
;
4541 modrm
= ldub_code(s
->pc
++);
4542 mod
= (modrm
>> 6) & 3;
4543 rm
= (modrm
& 7) | REX_B(s
);
4544 op
= (modrm
>> 3) & 7;
4545 if (op
>= 2 && b
== 0xfe) {
4549 if (op
== 2 || op
== 4) {
4550 /* operand size for jumps is 64 bit */
4552 } else if (op
== 3 || op
== 5) {
4553 /* for call calls, the operand is 16 or 32 bit, even
4555 ot
= dflag
? OT_LONG
: OT_WORD
;
4556 } else if (op
== 6) {
4557 /* default push size is 64 bit */
4558 ot
= dflag
? OT_QUAD
: OT_WORD
;
4562 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4563 if (op
>= 2 && op
!= 3 && op
!= 5)
4564 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4566 gen_op_mov_TN_reg(ot
, 0, rm
);
4570 case 0: /* inc Ev */
4575 gen_inc(s
, ot
, opreg
, 1);
4577 case 1: /* dec Ev */
4582 gen_inc(s
, ot
, opreg
, -1);
4584 case 2: /* call Ev */
4585 /* XXX: optimize if memory (no 'and' is necessary) */
4587 gen_op_andl_T0_ffff();
4588 next_eip
= s
->pc
- s
->cs_base
;
4589 gen_movtl_T1_im(next_eip
);
4594 case 3: /* lcall Ev */
4595 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4596 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4597 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4599 if (s
->pe
&& !s
->vm86
) {
4600 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4601 gen_op_set_cc_op(s
->cc_op
);
4602 gen_jmp_im(pc_start
- s
->cs_base
);
4603 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4604 gen_helper_lcall_protected(cpu_tmp2_i32
, cpu_T
[1],
4605 tcg_const_i32(dflag
),
4606 tcg_const_i32(s
->pc
- pc_start
));
4608 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4609 gen_helper_lcall_real(cpu_tmp2_i32
, cpu_T
[1],
4610 tcg_const_i32(dflag
),
4611 tcg_const_i32(s
->pc
- s
->cs_base
));
4615 case 4: /* jmp Ev */
4617 gen_op_andl_T0_ffff();
4621 case 5: /* ljmp Ev */
4622 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4623 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4624 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4626 if (s
->pe
&& !s
->vm86
) {
4627 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4628 gen_op_set_cc_op(s
->cc_op
);
4629 gen_jmp_im(pc_start
- s
->cs_base
);
4630 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4631 gen_helper_ljmp_protected(cpu_tmp2_i32
, cpu_T
[1],
4632 tcg_const_i32(s
->pc
- pc_start
));
4634 gen_op_movl_seg_T0_vm(R_CS
);
4635 gen_op_movl_T0_T1();
4640 case 6: /* push Ev */
4648 case 0x84: /* test Ev, Gv */
4653 ot
= dflag
+ OT_WORD
;
4655 modrm
= ldub_code(s
->pc
++);
4656 mod
= (modrm
>> 6) & 3;
4657 rm
= (modrm
& 7) | REX_B(s
);
4658 reg
= ((modrm
>> 3) & 7) | rex_r
;
4660 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4661 gen_op_mov_TN_reg(ot
, 1, reg
);
4662 gen_op_testl_T0_T1_cc();
4663 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4666 case 0xa8: /* test eAX, Iv */
4671 ot
= dflag
+ OT_WORD
;
4672 val
= insn_get(s
, ot
);
4674 gen_op_mov_TN_reg(ot
, 0, OR_EAX
);
4675 gen_op_movl_T1_im(val
);
4676 gen_op_testl_T0_T1_cc();
4677 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4680 case 0x98: /* CWDE/CBW */
4681 #ifdef TARGET_X86_64
4683 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4684 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4685 gen_op_mov_reg_T0(OT_QUAD
, R_EAX
);
4689 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4690 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4691 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4693 gen_op_mov_TN_reg(OT_BYTE
, 0, R_EAX
);
4694 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4695 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4698 case 0x99: /* CDQ/CWD */
4699 #ifdef TARGET_X86_64
4701 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
4702 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 63);
4703 gen_op_mov_reg_T0(OT_QUAD
, R_EDX
);
4707 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4708 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4709 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 31);
4710 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4712 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4713 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4714 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 15);
4715 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4718 case 0x1af: /* imul Gv, Ev */
4719 case 0x69: /* imul Gv, Ev, I */
4721 ot
= dflag
+ OT_WORD
;
4722 modrm
= ldub_code(s
->pc
++);
4723 reg
= ((modrm
>> 3) & 7) | rex_r
;
4725 s
->rip_offset
= insn_const_size(ot
);
4728 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4730 val
= insn_get(s
, ot
);
4731 gen_op_movl_T1_im(val
);
4732 } else if (b
== 0x6b) {
4733 val
= (int8_t)insn_get(s
, OT_BYTE
);
4734 gen_op_movl_T1_im(val
);
4736 gen_op_mov_TN_reg(ot
, 1, reg
);
4739 #ifdef TARGET_X86_64
4740 if (ot
== OT_QUAD
) {
4741 gen_helper_imulq_T0_T1(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4744 if (ot
== OT_LONG
) {
4745 #ifdef TARGET_X86_64
4746 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4747 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4748 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4749 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4750 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4751 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4755 t0
= tcg_temp_new_i64();
4756 t1
= tcg_temp_new_i64();
4757 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4758 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4759 tcg_gen_mul_i64(t0
, t0
, t1
);
4760 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4761 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4762 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4763 tcg_gen_shri_i64(t0
, t0
, 32);
4764 tcg_gen_trunc_i64_i32(cpu_T
[1], t0
);
4765 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[1], cpu_tmp0
);
4769 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4770 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4771 /* XXX: use 32 bit mul which could be faster */
4772 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4773 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4774 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4775 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4777 gen_op_mov_reg_T0(ot
, reg
);
4778 s
->cc_op
= CC_OP_MULB
+ ot
;
4781 case 0x1c1: /* xadd Ev, Gv */
4785 ot
= dflag
+ OT_WORD
;
4786 modrm
= ldub_code(s
->pc
++);
4787 reg
= ((modrm
>> 3) & 7) | rex_r
;
4788 mod
= (modrm
>> 6) & 3;
4790 rm
= (modrm
& 7) | REX_B(s
);
4791 gen_op_mov_TN_reg(ot
, 0, reg
);
4792 gen_op_mov_TN_reg(ot
, 1, rm
);
4793 gen_op_addl_T0_T1();
4794 gen_op_mov_reg_T1(ot
, reg
);
4795 gen_op_mov_reg_T0(ot
, rm
);
4797 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4798 gen_op_mov_TN_reg(ot
, 0, reg
);
4799 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4800 gen_op_addl_T0_T1();
4801 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4802 gen_op_mov_reg_T1(ot
, reg
);
4804 gen_op_update2_cc();
4805 s
->cc_op
= CC_OP_ADDB
+ ot
;
4808 case 0x1b1: /* cmpxchg Ev, Gv */
4811 TCGv t0
, t1
, t2
, a0
;
4816 ot
= dflag
+ OT_WORD
;
4817 modrm
= ldub_code(s
->pc
++);
4818 reg
= ((modrm
>> 3) & 7) | rex_r
;
4819 mod
= (modrm
>> 6) & 3;
4820 t0
= tcg_temp_local_new();
4821 t1
= tcg_temp_local_new();
4822 t2
= tcg_temp_local_new();
4823 a0
= tcg_temp_local_new();
4824 gen_op_mov_v_reg(ot
, t1
, reg
);
4826 rm
= (modrm
& 7) | REX_B(s
);
4827 gen_op_mov_v_reg(ot
, t0
, rm
);
4829 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4830 tcg_gen_mov_tl(a0
, cpu_A0
);
4831 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
4832 rm
= 0; /* avoid warning */
4834 label1
= gen_new_label();
4835 tcg_gen_ld_tl(t2
, cpu_env
, offsetof(CPUState
, regs
[R_EAX
]));
4836 tcg_gen_sub_tl(t2
, t2
, t0
);
4838 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
4840 label2
= gen_new_label();
4841 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4843 gen_set_label(label1
);
4844 gen_op_mov_reg_v(ot
, rm
, t1
);
4845 gen_set_label(label2
);
4847 tcg_gen_mov_tl(t1
, t0
);
4848 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4849 gen_set_label(label1
);
4851 gen_op_st_v(ot
+ s
->mem_index
, t1
, a0
);
4853 tcg_gen_mov_tl(cpu_cc_src
, t0
);
4854 tcg_gen_mov_tl(cpu_cc_dst
, t2
);
4855 s
->cc_op
= CC_OP_SUBB
+ ot
;
4862 case 0x1c7: /* cmpxchg8b */
4863 modrm
= ldub_code(s
->pc
++);
4864 mod
= (modrm
>> 6) & 3;
4865 if ((mod
== 3) || ((modrm
& 0x38) != 0x8))
4867 #ifdef TARGET_X86_64
4869 if (!(s
->cpuid_ext_features
& CPUID_EXT_CX16
))
4871 gen_jmp_im(pc_start
- s
->cs_base
);
4872 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4873 gen_op_set_cc_op(s
->cc_op
);
4874 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4875 gen_helper_cmpxchg16b(cpu_A0
);
4879 if (!(s
->cpuid_features
& CPUID_CX8
))
4881 gen_jmp_im(pc_start
- s
->cs_base
);
4882 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4883 gen_op_set_cc_op(s
->cc_op
);
4884 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4885 gen_helper_cmpxchg8b(cpu_A0
);
4887 s
->cc_op
= CC_OP_EFLAGS
;
4890 /**************************/
4892 case 0x50 ... 0x57: /* push */
4893 gen_op_mov_TN_reg(OT_LONG
, 0, (b
& 7) | REX_B(s
));
4896 case 0x58 ... 0x5f: /* pop */
4898 ot
= dflag
? OT_QUAD
: OT_WORD
;
4900 ot
= dflag
+ OT_WORD
;
4903 /* NOTE: order is important for pop %sp */
4905 gen_op_mov_reg_T0(ot
, (b
& 7) | REX_B(s
));
4907 case 0x60: /* pusha */
4912 case 0x61: /* popa */
4917 case 0x68: /* push Iv */
4920 ot
= dflag
? OT_QUAD
: OT_WORD
;
4922 ot
= dflag
+ OT_WORD
;
4925 val
= insn_get(s
, ot
);
4927 val
= (int8_t)insn_get(s
, OT_BYTE
);
4928 gen_op_movl_T0_im(val
);
4931 case 0x8f: /* pop Ev */
4933 ot
= dflag
? OT_QUAD
: OT_WORD
;
4935 ot
= dflag
+ OT_WORD
;
4937 modrm
= ldub_code(s
->pc
++);
4938 mod
= (modrm
>> 6) & 3;
4941 /* NOTE: order is important for pop %sp */
4943 rm
= (modrm
& 7) | REX_B(s
);
4944 gen_op_mov_reg_T0(ot
, rm
);
4946 /* NOTE: order is important too for MMU exceptions */
4947 s
->popl_esp_hack
= 1 << ot
;
4948 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
4949 s
->popl_esp_hack
= 0;
4953 case 0xc8: /* enter */
4956 val
= lduw_code(s
->pc
);
4958 level
= ldub_code(s
->pc
++);
4959 gen_enter(s
, val
, level
);
4962 case 0xc9: /* leave */
4963 /* XXX: exception not precise (ESP is updated before potential exception) */
4965 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EBP
);
4966 gen_op_mov_reg_T0(OT_QUAD
, R_ESP
);
4967 } else if (s
->ss32
) {
4968 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
4969 gen_op_mov_reg_T0(OT_LONG
, R_ESP
);
4971 gen_op_mov_TN_reg(OT_WORD
, 0, R_EBP
);
4972 gen_op_mov_reg_T0(OT_WORD
, R_ESP
);
4976 ot
= dflag
? OT_QUAD
: OT_WORD
;
4978 ot
= dflag
+ OT_WORD
;
4980 gen_op_mov_reg_T0(ot
, R_EBP
);
4983 case 0x06: /* push es */
4984 case 0x0e: /* push cs */
4985 case 0x16: /* push ss */
4986 case 0x1e: /* push ds */
4989 gen_op_movl_T0_seg(b
>> 3);
4992 case 0x1a0: /* push fs */
4993 case 0x1a8: /* push gs */
4994 gen_op_movl_T0_seg((b
>> 3) & 7);
4997 case 0x07: /* pop es */
4998 case 0x17: /* pop ss */
4999 case 0x1f: /* pop ds */
5004 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5007 /* if reg == SS, inhibit interrupts/trace. */
5008 /* If several instructions disable interrupts, only the
5010 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5011 gen_helper_set_inhibit_irq();
5015 gen_jmp_im(s
->pc
- s
->cs_base
);
5019 case 0x1a1: /* pop fs */
5020 case 0x1a9: /* pop gs */
5022 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
5025 gen_jmp_im(s
->pc
- s
->cs_base
);
5030 /**************************/
5033 case 0x89: /* mov Gv, Ev */
5037 ot
= dflag
+ OT_WORD
;
5038 modrm
= ldub_code(s
->pc
++);
5039 reg
= ((modrm
>> 3) & 7) | rex_r
;
5041 /* generate a generic store */
5042 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
5045 case 0xc7: /* mov Ev, Iv */
5049 ot
= dflag
+ OT_WORD
;
5050 modrm
= ldub_code(s
->pc
++);
5051 mod
= (modrm
>> 6) & 3;
5053 s
->rip_offset
= insn_const_size(ot
);
5054 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5056 val
= insn_get(s
, ot
);
5057 gen_op_movl_T0_im(val
);
5059 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5061 gen_op_mov_reg_T0(ot
, (modrm
& 7) | REX_B(s
));
5064 case 0x8b: /* mov Ev, Gv */
5068 ot
= OT_WORD
+ dflag
;
5069 modrm
= ldub_code(s
->pc
++);
5070 reg
= ((modrm
>> 3) & 7) | rex_r
;
5072 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5073 gen_op_mov_reg_T0(ot
, reg
);
5075 case 0x8e: /* mov seg, Gv */
5076 modrm
= ldub_code(s
->pc
++);
5077 reg
= (modrm
>> 3) & 7;
5078 if (reg
>= 6 || reg
== R_CS
)
5080 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5081 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5083 /* if reg == SS, inhibit interrupts/trace */
5084 /* If several instructions disable interrupts, only the
5086 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5087 gen_helper_set_inhibit_irq();
5091 gen_jmp_im(s
->pc
- s
->cs_base
);
5095 case 0x8c: /* mov Gv, seg */
5096 modrm
= ldub_code(s
->pc
++);
5097 reg
= (modrm
>> 3) & 7;
5098 mod
= (modrm
>> 6) & 3;
5101 gen_op_movl_T0_seg(reg
);
5103 ot
= OT_WORD
+ dflag
;
5106 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5109 case 0x1b6: /* movzbS Gv, Eb */
5110 case 0x1b7: /* movzwS Gv, Eb */
5111 case 0x1be: /* movsbS Gv, Eb */
5112 case 0x1bf: /* movswS Gv, Eb */
5115 /* d_ot is the size of destination */
5116 d_ot
= dflag
+ OT_WORD
;
5117 /* ot is the size of source */
5118 ot
= (b
& 1) + OT_BYTE
;
5119 modrm
= ldub_code(s
->pc
++);
5120 reg
= ((modrm
>> 3) & 7) | rex_r
;
5121 mod
= (modrm
>> 6) & 3;
5122 rm
= (modrm
& 7) | REX_B(s
);
5125 gen_op_mov_TN_reg(ot
, 0, rm
);
5126 switch(ot
| (b
& 8)) {
5128 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
5131 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
5134 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
5138 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
5141 gen_op_mov_reg_T0(d_ot
, reg
);
5143 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5145 gen_op_lds_T0_A0(ot
+ s
->mem_index
);
5147 gen_op_ldu_T0_A0(ot
+ s
->mem_index
);
5149 gen_op_mov_reg_T0(d_ot
, reg
);
5154 case 0x8d: /* lea */
5155 ot
= dflag
+ OT_WORD
;
5156 modrm
= ldub_code(s
->pc
++);
5157 mod
= (modrm
>> 6) & 3;
5160 reg
= ((modrm
>> 3) & 7) | rex_r
;
5161 /* we must ensure that no segment is added */
5165 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5167 gen_op_mov_reg_A0(ot
- OT_WORD
, reg
);
5170 case 0xa0: /* mov EAX, Ov */
5172 case 0xa2: /* mov Ov, EAX */
5175 target_ulong offset_addr
;
5180 ot
= dflag
+ OT_WORD
;
5181 #ifdef TARGET_X86_64
5182 if (s
->aflag
== 2) {
5183 offset_addr
= ldq_code(s
->pc
);
5185 gen_op_movq_A0_im(offset_addr
);
5190 offset_addr
= insn_get(s
, OT_LONG
);
5192 offset_addr
= insn_get(s
, OT_WORD
);
5194 gen_op_movl_A0_im(offset_addr
);
5196 gen_add_A0_ds_seg(s
);
5198 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
5199 gen_op_mov_reg_T0(ot
, R_EAX
);
5201 gen_op_mov_TN_reg(ot
, 0, R_EAX
);
5202 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5206 case 0xd7: /* xlat */
5207 #ifdef TARGET_X86_64
5208 if (s
->aflag
== 2) {
5209 gen_op_movq_A0_reg(R_EBX
);
5210 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
5211 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5212 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5216 gen_op_movl_A0_reg(R_EBX
);
5217 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
5218 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5219 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5221 gen_op_andl_A0_ffff();
5223 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
5225 gen_add_A0_ds_seg(s
);
5226 gen_op_ldu_T0_A0(OT_BYTE
+ s
->mem_index
);
5227 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
5229 case 0xb0 ... 0xb7: /* mov R, Ib */
5230 val
= insn_get(s
, OT_BYTE
);
5231 gen_op_movl_T0_im(val
);
5232 gen_op_mov_reg_T0(OT_BYTE
, (b
& 7) | REX_B(s
));
5234 case 0xb8 ... 0xbf: /* mov R, Iv */
5235 #ifdef TARGET_X86_64
5239 tmp
= ldq_code(s
->pc
);
5241 reg
= (b
& 7) | REX_B(s
);
5242 gen_movtl_T0_im(tmp
);
5243 gen_op_mov_reg_T0(OT_QUAD
, reg
);
5247 ot
= dflag
? OT_LONG
: OT_WORD
;
5248 val
= insn_get(s
, ot
);
5249 reg
= (b
& 7) | REX_B(s
);
5250 gen_op_movl_T0_im(val
);
5251 gen_op_mov_reg_T0(ot
, reg
);
5255 case 0x91 ... 0x97: /* xchg R, EAX */
5256 ot
= dflag
+ OT_WORD
;
5257 reg
= (b
& 7) | REX_B(s
);
5261 case 0x87: /* xchg Ev, Gv */
5265 ot
= dflag
+ OT_WORD
;
5266 modrm
= ldub_code(s
->pc
++);
5267 reg
= ((modrm
>> 3) & 7) | rex_r
;
5268 mod
= (modrm
>> 6) & 3;
5270 rm
= (modrm
& 7) | REX_B(s
);
5272 gen_op_mov_TN_reg(ot
, 0, reg
);
5273 gen_op_mov_TN_reg(ot
, 1, rm
);
5274 gen_op_mov_reg_T0(ot
, rm
);
5275 gen_op_mov_reg_T1(ot
, reg
);
5277 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5278 gen_op_mov_TN_reg(ot
, 0, reg
);
5279 /* for xchg, lock is implicit */
5280 if (!(prefixes
& PREFIX_LOCK
))
5282 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5283 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5284 if (!(prefixes
& PREFIX_LOCK
))
5285 gen_helper_unlock();
5286 gen_op_mov_reg_T1(ot
, reg
);
5289 case 0xc4: /* les Gv */
5294 case 0xc5: /* lds Gv */
5299 case 0x1b2: /* lss Gv */
5302 case 0x1b4: /* lfs Gv */
5305 case 0x1b5: /* lgs Gv */
5308 ot
= dflag
? OT_LONG
: OT_WORD
;
5309 modrm
= ldub_code(s
->pc
++);
5310 reg
= ((modrm
>> 3) & 7) | rex_r
;
5311 mod
= (modrm
>> 6) & 3;
5314 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5315 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5316 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
5317 /* load the segment first to handle exceptions properly */
5318 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
5319 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
5320 /* then put the data */
5321 gen_op_mov_reg_T1(ot
, reg
);
5323 gen_jmp_im(s
->pc
- s
->cs_base
);
5328 /************************/
5339 ot
= dflag
+ OT_WORD
;
5341 modrm
= ldub_code(s
->pc
++);
5342 mod
= (modrm
>> 6) & 3;
5343 op
= (modrm
>> 3) & 7;
5349 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5352 opreg
= (modrm
& 7) | REX_B(s
);
5357 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
5360 shift
= ldub_code(s
->pc
++);
5362 gen_shifti(s
, op
, ot
, opreg
, shift
);
5377 case 0x1a4: /* shld imm */
5381 case 0x1a5: /* shld cl */
5385 case 0x1ac: /* shrd imm */
5389 case 0x1ad: /* shrd cl */
5393 ot
= dflag
+ OT_WORD
;
5394 modrm
= ldub_code(s
->pc
++);
5395 mod
= (modrm
>> 6) & 3;
5396 rm
= (modrm
& 7) | REX_B(s
);
5397 reg
= ((modrm
>> 3) & 7) | rex_r
;
5399 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5404 gen_op_mov_TN_reg(ot
, 1, reg
);
5407 val
= ldub_code(s
->pc
++);
5408 tcg_gen_movi_tl(cpu_T3
, val
);
5410 tcg_gen_ld_tl(cpu_T3
, cpu_env
, offsetof(CPUState
, regs
[R_ECX
]));
5412 gen_shiftd_rm_T1_T3(s
, ot
, opreg
, op
);
5415 /************************/
5418 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
5419 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
5420 /* XXX: what to do if illegal op ? */
5421 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5424 modrm
= ldub_code(s
->pc
++);
5425 mod
= (modrm
>> 6) & 3;
5427 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
5430 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5432 case 0x00 ... 0x07: /* fxxxs */
5433 case 0x10 ... 0x17: /* fixxxl */
5434 case 0x20 ... 0x27: /* fxxxl */
5435 case 0x30 ... 0x37: /* fixxx */
5442 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5443 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5444 gen_helper_flds_FT0(cpu_tmp2_i32
);
5447 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5448 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5449 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5452 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5453 (s
->mem_index
>> 2) - 1);
5454 gen_helper_fldl_FT0(cpu_tmp1_i64
);
5458 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5459 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5460 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5464 gen_helper_fp_arith_ST0_FT0(op1
);
5466 /* fcomp needs pop */
5471 case 0x08: /* flds */
5472 case 0x0a: /* fsts */
5473 case 0x0b: /* fstps */
5474 case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
5475 case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
5476 case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
5481 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5482 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5483 gen_helper_flds_ST0(cpu_tmp2_i32
);
5486 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5487 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5488 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5491 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5492 (s
->mem_index
>> 2) - 1);
5493 gen_helper_fldl_ST0(cpu_tmp1_i64
);
5497 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5498 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5499 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5504 /* XXX: the corresponding CPUID bit must be tested ! */
5507 gen_helper_fisttl_ST0(cpu_tmp2_i32
);
5508 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5509 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5512 gen_helper_fisttll_ST0(cpu_tmp1_i64
);
5513 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5514 (s
->mem_index
>> 2) - 1);
5518 gen_helper_fistt_ST0(cpu_tmp2_i32
);
5519 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5520 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5528 gen_helper_fsts_ST0(cpu_tmp2_i32
);
5529 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5530 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5533 gen_helper_fistl_ST0(cpu_tmp2_i32
);
5534 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5535 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5538 gen_helper_fstl_ST0(cpu_tmp1_i64
);
5539 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5540 (s
->mem_index
>> 2) - 1);
5544 gen_helper_fist_ST0(cpu_tmp2_i32
);
5545 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5546 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5554 case 0x0c: /* fldenv mem */
5555 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5556 gen_op_set_cc_op(s
->cc_op
);
5557 gen_jmp_im(pc_start
- s
->cs_base
);
5559 cpu_A0
, tcg_const_i32(s
->dflag
));
5561 case 0x0d: /* fldcw mem */
5562 gen_op_ld_T0_A0(OT_WORD
+ s
->mem_index
);
5563 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5564 gen_helper_fldcw(cpu_tmp2_i32
);
5566 case 0x0e: /* fnstenv mem */
5567 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5568 gen_op_set_cc_op(s
->cc_op
);
5569 gen_jmp_im(pc_start
- s
->cs_base
);
5570 gen_helper_fstenv(cpu_A0
, tcg_const_i32(s
->dflag
));
5572 case 0x0f: /* fnstcw mem */
5573 gen_helper_fnstcw(cpu_tmp2_i32
);
5574 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5575 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5577 case 0x1d: /* fldt mem */
5578 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5579 gen_op_set_cc_op(s
->cc_op
);
5580 gen_jmp_im(pc_start
- s
->cs_base
);
5581 gen_helper_fldt_ST0(cpu_A0
);
5583 case 0x1f: /* fstpt mem */
5584 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5585 gen_op_set_cc_op(s
->cc_op
);
5586 gen_jmp_im(pc_start
- s
->cs_base
);
5587 gen_helper_fstt_ST0(cpu_A0
);
5590 case 0x2c: /* frstor mem */
5591 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5592 gen_op_set_cc_op(s
->cc_op
);
5593 gen_jmp_im(pc_start
- s
->cs_base
);
5594 gen_helper_frstor(cpu_A0
, tcg_const_i32(s
->dflag
));
5596 case 0x2e: /* fnsave mem */
5597 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5598 gen_op_set_cc_op(s
->cc_op
);
5599 gen_jmp_im(pc_start
- s
->cs_base
);
5600 gen_helper_fsave(cpu_A0
, tcg_const_i32(s
->dflag
));
5602 case 0x2f: /* fnstsw mem */
5603 gen_helper_fnstsw(cpu_tmp2_i32
);
5604 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5605 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5607 case 0x3c: /* fbld */
5608 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5609 gen_op_set_cc_op(s
->cc_op
);
5610 gen_jmp_im(pc_start
- s
->cs_base
);
5611 gen_helper_fbld_ST0(cpu_A0
);
5613 case 0x3e: /* fbstp */
5614 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5615 gen_op_set_cc_op(s
->cc_op
);
5616 gen_jmp_im(pc_start
- s
->cs_base
);
5617 gen_helper_fbst_ST0(cpu_A0
);
5620 case 0x3d: /* fildll */
5621 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5622 (s
->mem_index
>> 2) - 1);
5623 gen_helper_fildll_ST0(cpu_tmp1_i64
);
5625 case 0x3f: /* fistpll */
5626 gen_helper_fistll_ST0(cpu_tmp1_i64
);
5627 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5628 (s
->mem_index
>> 2) - 1);
5635 /* register float ops */
5639 case 0x08: /* fld sti */
5641 gen_helper_fmov_ST0_STN(tcg_const_i32((opreg
+ 1) & 7));
5643 case 0x09: /* fxchg sti */
5644 case 0x29: /* fxchg4 sti, undocumented op */
5645 case 0x39: /* fxchg7 sti, undocumented op */
5646 gen_helper_fxchg_ST0_STN(tcg_const_i32(opreg
));
5648 case 0x0a: /* grp d9/2 */
5651 /* check exceptions (FreeBSD FPU probe) */
5652 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5653 gen_op_set_cc_op(s
->cc_op
);
5654 gen_jmp_im(pc_start
- s
->cs_base
);
5661 case 0x0c: /* grp d9/4 */
5664 gen_helper_fchs_ST0();
5667 gen_helper_fabs_ST0();
5670 gen_helper_fldz_FT0();
5671 gen_helper_fcom_ST0_FT0();
5674 gen_helper_fxam_ST0();
5680 case 0x0d: /* grp d9/5 */
5685 gen_helper_fld1_ST0();
5689 gen_helper_fldl2t_ST0();
5693 gen_helper_fldl2e_ST0();
5697 gen_helper_fldpi_ST0();
5701 gen_helper_fldlg2_ST0();
5705 gen_helper_fldln2_ST0();
5709 gen_helper_fldz_ST0();
5716 case 0x0e: /* grp d9/6 */
5727 case 3: /* fpatan */
5728 gen_helper_fpatan();
5730 case 4: /* fxtract */
5731 gen_helper_fxtract();
5733 case 5: /* fprem1 */
5734 gen_helper_fprem1();
5736 case 6: /* fdecstp */
5737 gen_helper_fdecstp();
5740 case 7: /* fincstp */
5741 gen_helper_fincstp();
5745 case 0x0f: /* grp d9/7 */
5750 case 1: /* fyl2xp1 */
5751 gen_helper_fyl2xp1();
5756 case 3: /* fsincos */
5757 gen_helper_fsincos();
5759 case 5: /* fscale */
5760 gen_helper_fscale();
5762 case 4: /* frndint */
5763 gen_helper_frndint();
5774 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
5775 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
5776 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
5782 gen_helper_fp_arith_STN_ST0(op1
, opreg
);
5786 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5787 gen_helper_fp_arith_ST0_FT0(op1
);
5791 case 0x02: /* fcom */
5792 case 0x22: /* fcom2, undocumented op */
5793 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5794 gen_helper_fcom_ST0_FT0();
5796 case 0x03: /* fcomp */
5797 case 0x23: /* fcomp3, undocumented op */
5798 case 0x32: /* fcomp5, undocumented op */
5799 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5800 gen_helper_fcom_ST0_FT0();
5803 case 0x15: /* da/5 */
5805 case 1: /* fucompp */
5806 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5807 gen_helper_fucom_ST0_FT0();
5817 case 0: /* feni (287 only, just do nop here) */
5819 case 1: /* fdisi (287 only, just do nop here) */
5824 case 3: /* fninit */
5825 gen_helper_fninit();
5827 case 4: /* fsetpm (287 only, just do nop here) */
5833 case 0x1d: /* fucomi */
5834 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5835 gen_op_set_cc_op(s
->cc_op
);
5836 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5837 gen_helper_fucomi_ST0_FT0();
5838 s
->cc_op
= CC_OP_EFLAGS
;
5840 case 0x1e: /* fcomi */
5841 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5842 gen_op_set_cc_op(s
->cc_op
);
5843 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5844 gen_helper_fcomi_ST0_FT0();
5845 s
->cc_op
= CC_OP_EFLAGS
;
5847 case 0x28: /* ffree sti */
5848 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5850 case 0x2a: /* fst sti */
5851 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5853 case 0x2b: /* fstp sti */
5854 case 0x0b: /* fstp1 sti, undocumented op */
5855 case 0x3a: /* fstp8 sti, undocumented op */
5856 case 0x3b: /* fstp9 sti, undocumented op */
5857 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5860 case 0x2c: /* fucom st(i) */
5861 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5862 gen_helper_fucom_ST0_FT0();
5864 case 0x2d: /* fucomp st(i) */
5865 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5866 gen_helper_fucom_ST0_FT0();
5869 case 0x33: /* de/3 */
5871 case 1: /* fcompp */
5872 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5873 gen_helper_fcom_ST0_FT0();
5881 case 0x38: /* ffreep sti, undocumented op */
5882 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5885 case 0x3c: /* df/4 */
5888 gen_helper_fnstsw(cpu_tmp2_i32
);
5889 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5890 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
5896 case 0x3d: /* fucomip */
5897 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5898 gen_op_set_cc_op(s
->cc_op
);
5899 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5900 gen_helper_fucomi_ST0_FT0();
5902 s
->cc_op
= CC_OP_EFLAGS
;
5904 case 0x3e: /* fcomip */
5905 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5906 gen_op_set_cc_op(s
->cc_op
);
5907 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5908 gen_helper_fcomi_ST0_FT0();
5910 s
->cc_op
= CC_OP_EFLAGS
;
5912 case 0x10 ... 0x13: /* fcmovxx */
5916 static const uint8_t fcmov_cc
[8] = {
5922 op1
= fcmov_cc
[op
& 3] | (((op
>> 3) & 1) ^ 1);
5923 l1
= gen_new_label();
5924 gen_jcc1(s
, s
->cc_op
, op1
, l1
);
5925 gen_helper_fmov_ST0_STN(tcg_const_i32(opreg
));
5934 /************************/
5937 case 0xa4: /* movsS */
5942 ot
= dflag
+ OT_WORD
;
5944 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5945 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5951 case 0xaa: /* stosS */
5956 ot
= dflag
+ OT_WORD
;
5958 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5959 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5964 case 0xac: /* lodsS */
5969 ot
= dflag
+ OT_WORD
;
5970 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5971 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5976 case 0xae: /* scasS */
5981 ot
= dflag
+ OT_WORD
;
5982 if (prefixes
& PREFIX_REPNZ
) {
5983 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
5984 } else if (prefixes
& PREFIX_REPZ
) {
5985 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
5988 s
->cc_op
= CC_OP_SUBB
+ ot
;
5992 case 0xa6: /* cmpsS */
5997 ot
= dflag
+ OT_WORD
;
5998 if (prefixes
& PREFIX_REPNZ
) {
5999 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6000 } else if (prefixes
& PREFIX_REPZ
) {
6001 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6004 s
->cc_op
= CC_OP_SUBB
+ ot
;
6007 case 0x6c: /* insS */
6012 ot
= dflag
? OT_LONG
: OT_WORD
;
6013 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6014 gen_op_andl_T0_ffff();
6015 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6016 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
) | 4);
6017 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6018 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6022 gen_jmp(s
, s
->pc
- s
->cs_base
);
6026 case 0x6e: /* outsS */
6031 ot
= dflag
? OT_LONG
: OT_WORD
;
6032 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6033 gen_op_andl_T0_ffff();
6034 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6035 svm_is_rep(prefixes
) | 4);
6036 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6037 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6041 gen_jmp(s
, s
->pc
- s
->cs_base
);
6046 /************************/
6054 ot
= dflag
? OT_LONG
: OT_WORD
;
6055 val
= ldub_code(s
->pc
++);
6056 gen_op_movl_T0_im(val
);
6057 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6058 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6061 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6062 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6063 gen_op_mov_reg_T1(ot
, R_EAX
);
6066 gen_jmp(s
, s
->pc
- s
->cs_base
);
6074 ot
= dflag
? OT_LONG
: OT_WORD
;
6075 val
= ldub_code(s
->pc
++);
6076 gen_op_movl_T0_im(val
);
6077 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6078 svm_is_rep(prefixes
));
6079 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6083 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6084 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6085 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6086 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6089 gen_jmp(s
, s
->pc
- s
->cs_base
);
6097 ot
= dflag
? OT_LONG
: OT_WORD
;
6098 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6099 gen_op_andl_T0_ffff();
6100 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6101 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6104 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6105 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6106 gen_op_mov_reg_T1(ot
, R_EAX
);
6109 gen_jmp(s
, s
->pc
- s
->cs_base
);
6117 ot
= dflag
? OT_LONG
: OT_WORD
;
6118 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6119 gen_op_andl_T0_ffff();
6120 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6121 svm_is_rep(prefixes
));
6122 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6126 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6127 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6128 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6129 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6132 gen_jmp(s
, s
->pc
- s
->cs_base
);
6136 /************************/
6138 case 0xc2: /* ret im */
6139 val
= ldsw_code(s
->pc
);
6142 if (CODE64(s
) && s
->dflag
)
6144 gen_stack_update(s
, val
+ (2 << s
->dflag
));
6146 gen_op_andl_T0_ffff();
6150 case 0xc3: /* ret */
6154 gen_op_andl_T0_ffff();
6158 case 0xca: /* lret im */
6159 val
= ldsw_code(s
->pc
);
6162 if (s
->pe
&& !s
->vm86
) {
6163 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6164 gen_op_set_cc_op(s
->cc_op
);
6165 gen_jmp_im(pc_start
- s
->cs_base
);
6166 gen_helper_lret_protected(tcg_const_i32(s
->dflag
),
6167 tcg_const_i32(val
));
6171 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6173 gen_op_andl_T0_ffff();
6174 /* NOTE: keeping EIP updated is not a problem in case of
6178 gen_op_addl_A0_im(2 << s
->dflag
);
6179 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6180 gen_op_movl_seg_T0_vm(R_CS
);
6181 /* add stack offset */
6182 gen_stack_update(s
, val
+ (4 << s
->dflag
));
6186 case 0xcb: /* lret */
6189 case 0xcf: /* iret */
6190 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IRET
);
6193 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6194 s
->cc_op
= CC_OP_EFLAGS
;
6195 } else if (s
->vm86
) {
6197 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6199 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6200 s
->cc_op
= CC_OP_EFLAGS
;
6203 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6204 gen_op_set_cc_op(s
->cc_op
);
6205 gen_jmp_im(pc_start
- s
->cs_base
);
6206 gen_helper_iret_protected(tcg_const_i32(s
->dflag
),
6207 tcg_const_i32(s
->pc
- s
->cs_base
));
6208 s
->cc_op
= CC_OP_EFLAGS
;
6212 case 0xe8: /* call im */
6215 tval
= (int32_t)insn_get(s
, OT_LONG
);
6217 tval
= (int16_t)insn_get(s
, OT_WORD
);
6218 next_eip
= s
->pc
- s
->cs_base
;
6222 gen_movtl_T0_im(next_eip
);
6227 case 0x9a: /* lcall im */
6229 unsigned int selector
, offset
;
6233 ot
= dflag
? OT_LONG
: OT_WORD
;
6234 offset
= insn_get(s
, ot
);
6235 selector
= insn_get(s
, OT_WORD
);
6237 gen_op_movl_T0_im(selector
);
6238 gen_op_movl_T1_imu(offset
);
6241 case 0xe9: /* jmp im */
6243 tval
= (int32_t)insn_get(s
, OT_LONG
);
6245 tval
= (int16_t)insn_get(s
, OT_WORD
);
6246 tval
+= s
->pc
- s
->cs_base
;
6253 case 0xea: /* ljmp im */
6255 unsigned int selector
, offset
;
6259 ot
= dflag
? OT_LONG
: OT_WORD
;
6260 offset
= insn_get(s
, ot
);
6261 selector
= insn_get(s
, OT_WORD
);
6263 gen_op_movl_T0_im(selector
);
6264 gen_op_movl_T1_imu(offset
);
6267 case 0xeb: /* jmp Jb */
6268 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6269 tval
+= s
->pc
- s
->cs_base
;
6274 case 0x70 ... 0x7f: /* jcc Jb */
6275 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6277 case 0x180 ... 0x18f: /* jcc Jv */
6279 tval
= (int32_t)insn_get(s
, OT_LONG
);
6281 tval
= (int16_t)insn_get(s
, OT_WORD
);
6284 next_eip
= s
->pc
- s
->cs_base
;
6288 gen_jcc(s
, b
, tval
, next_eip
);
6291 case 0x190 ... 0x19f: /* setcc Gv */
6292 modrm
= ldub_code(s
->pc
++);
6294 gen_ldst_modrm(s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
6296 case 0x140 ... 0x14f: /* cmov Gv, Ev */
6301 ot
= dflag
+ OT_WORD
;
6302 modrm
= ldub_code(s
->pc
++);
6303 reg
= ((modrm
>> 3) & 7) | rex_r
;
6304 mod
= (modrm
>> 6) & 3;
6305 t0
= tcg_temp_local_new();
6307 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6308 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
6310 rm
= (modrm
& 7) | REX_B(s
);
6311 gen_op_mov_v_reg(ot
, t0
, rm
);
6313 #ifdef TARGET_X86_64
6314 if (ot
== OT_LONG
) {
6315 /* XXX: specific Intel behaviour ? */
6316 l1
= gen_new_label();
6317 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6318 tcg_gen_st32_tl(t0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_L_OFFSET
);
6320 tcg_gen_movi_tl(cpu_tmp0
, 0);
6321 tcg_gen_st32_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, regs
[reg
]) + REG_LH_OFFSET
);
6325 l1
= gen_new_label();
6326 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6327 gen_op_mov_reg_v(ot
, reg
, t0
);
6334 /************************/
6336 case 0x9c: /* pushf */
6337 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PUSHF
);
6338 if (s
->vm86
&& s
->iopl
!= 3) {
6339 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6341 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6342 gen_op_set_cc_op(s
->cc_op
);
6343 gen_helper_read_eflags(cpu_T
[0]);
6347 case 0x9d: /* popf */
6348 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_POPF
);
6349 if (s
->vm86
&& s
->iopl
!= 3) {
6350 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6355 gen_helper_write_eflags(cpu_T
[0],
6356 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
)));
6358 gen_helper_write_eflags(cpu_T
[0],
6359 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
) & 0xffff));
6362 if (s
->cpl
<= s
->iopl
) {
6364 gen_helper_write_eflags(cpu_T
[0],
6365 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
)));
6367 gen_helper_write_eflags(cpu_T
[0],
6368 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
) & 0xffff));
6372 gen_helper_write_eflags(cpu_T
[0],
6373 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
)));
6375 gen_helper_write_eflags(cpu_T
[0],
6376 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
) & 0xffff));
6381 s
->cc_op
= CC_OP_EFLAGS
;
6382 /* abort translation because TF flag may change */
6383 gen_jmp_im(s
->pc
- s
->cs_base
);
6387 case 0x9e: /* sahf */
6388 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6390 gen_op_mov_TN_reg(OT_BYTE
, 0, R_AH
);
6391 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6392 gen_op_set_cc_op(s
->cc_op
);
6393 gen_compute_eflags(cpu_cc_src
);
6394 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, CC_O
);
6395 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
6396 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_T
[0]);
6397 s
->cc_op
= CC_OP_EFLAGS
;
6399 case 0x9f: /* lahf */
6400 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6402 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6403 gen_op_set_cc_op(s
->cc_op
);
6404 gen_compute_eflags(cpu_T
[0]);
6405 /* Note: gen_compute_eflags() only gives the condition codes */
6406 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], 0x02);
6407 gen_op_mov_reg_T0(OT_BYTE
, R_AH
);
6409 case 0xf5: /* cmc */
6410 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6411 gen_op_set_cc_op(s
->cc_op
);
6412 gen_compute_eflags(cpu_cc_src
);
6413 tcg_gen_xori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6414 s
->cc_op
= CC_OP_EFLAGS
;
6416 case 0xf8: /* clc */
6417 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6418 gen_op_set_cc_op(s
->cc_op
);
6419 gen_compute_eflags(cpu_cc_src
);
6420 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_C
);
6421 s
->cc_op
= CC_OP_EFLAGS
;
6423 case 0xf9: /* stc */
6424 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6425 gen_op_set_cc_op(s
->cc_op
);
6426 gen_compute_eflags(cpu_cc_src
);
6427 tcg_gen_ori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6428 s
->cc_op
= CC_OP_EFLAGS
;
6430 case 0xfc: /* cld */
6431 tcg_gen_movi_i32(cpu_tmp2_i32
, 1);
6432 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6434 case 0xfd: /* std */
6435 tcg_gen_movi_i32(cpu_tmp2_i32
, -1);
6436 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6439 /************************/
6440 /* bit operations */
6441 case 0x1ba: /* bt/bts/btr/btc Gv, im */
6442 ot
= dflag
+ OT_WORD
;
6443 modrm
= ldub_code(s
->pc
++);
6444 op
= (modrm
>> 3) & 7;
6445 mod
= (modrm
>> 6) & 3;
6446 rm
= (modrm
& 7) | REX_B(s
);
6449 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6450 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6452 gen_op_mov_TN_reg(ot
, 0, rm
);
6455 val
= ldub_code(s
->pc
++);
6456 gen_op_movl_T1_im(val
);
6461 case 0x1a3: /* bt Gv, Ev */
6464 case 0x1ab: /* bts */
6467 case 0x1b3: /* btr */
6470 case 0x1bb: /* btc */
6473 ot
= dflag
+ OT_WORD
;
6474 modrm
= ldub_code(s
->pc
++);
6475 reg
= ((modrm
>> 3) & 7) | rex_r
;
6476 mod
= (modrm
>> 6) & 3;
6477 rm
= (modrm
& 7) | REX_B(s
);
6478 gen_op_mov_TN_reg(OT_LONG
, 1, reg
);
6480 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6481 /* specific case: we need to add a displacement */
6482 gen_exts(ot
, cpu_T
[1]);
6483 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[1], 3 + ot
);
6484 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, ot
);
6485 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
6486 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6488 gen_op_mov_TN_reg(ot
, 0, rm
);
6491 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], (1 << (3 + ot
)) - 1);
6494 tcg_gen_shr_tl(cpu_cc_src
, cpu_T
[0], cpu_T
[1]);
6495 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6498 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6499 tcg_gen_movi_tl(cpu_tmp0
, 1);
6500 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6501 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6504 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6505 tcg_gen_movi_tl(cpu_tmp0
, 1);
6506 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6507 tcg_gen_not_tl(cpu_tmp0
, cpu_tmp0
);
6508 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6512 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6513 tcg_gen_movi_tl(cpu_tmp0
, 1);
6514 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6515 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6518 s
->cc_op
= CC_OP_SARB
+ ot
;
6521 gen_op_st_T0_A0(ot
+ s
->mem_index
);
6523 gen_op_mov_reg_T0(ot
, rm
);
6524 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
6525 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6528 case 0x1bc: /* bsf */
6529 case 0x1bd: /* bsr */
6534 ot
= dflag
+ OT_WORD
;
6535 modrm
= ldub_code(s
->pc
++);
6536 reg
= ((modrm
>> 3) & 7) | rex_r
;
6537 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
6538 gen_extu(ot
, cpu_T
[0]);
6539 label1
= gen_new_label();
6540 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6541 t0
= tcg_temp_local_new();
6542 tcg_gen_mov_tl(t0
, cpu_T
[0]);
6543 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, label1
);
6545 gen_helper_bsr(cpu_T
[0], t0
);
6547 gen_helper_bsf(cpu_T
[0], t0
);
6549 gen_op_mov_reg_T0(ot
, reg
);
6550 tcg_gen_movi_tl(cpu_cc_dst
, 1);
6551 gen_set_label(label1
);
6552 tcg_gen_discard_tl(cpu_cc_src
);
6553 s
->cc_op
= CC_OP_LOGICB
+ ot
;
6557 /************************/
6559 case 0x27: /* daa */
6562 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6563 gen_op_set_cc_op(s
->cc_op
);
6565 s
->cc_op
= CC_OP_EFLAGS
;
6567 case 0x2f: /* das */
6570 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6571 gen_op_set_cc_op(s
->cc_op
);
6573 s
->cc_op
= CC_OP_EFLAGS
;
6575 case 0x37: /* aaa */
6578 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6579 gen_op_set_cc_op(s
->cc_op
);
6581 s
->cc_op
= CC_OP_EFLAGS
;
6583 case 0x3f: /* aas */
6586 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6587 gen_op_set_cc_op(s
->cc_op
);
6589 s
->cc_op
= CC_OP_EFLAGS
;
6591 case 0xd4: /* aam */
6594 val
= ldub_code(s
->pc
++);
6596 gen_exception(s
, EXCP00_DIVZ
, pc_start
- s
->cs_base
);
6598 gen_helper_aam(tcg_const_i32(val
));
6599 s
->cc_op
= CC_OP_LOGICB
;
6602 case 0xd5: /* aad */
6605 val
= ldub_code(s
->pc
++);
6606 gen_helper_aad(tcg_const_i32(val
));
6607 s
->cc_op
= CC_OP_LOGICB
;
6609 /************************/
6611 case 0x90: /* nop */
6612 /* XXX: xchg + rex handling */
6613 /* XXX: correct lock test for all insn */
6614 if (prefixes
& PREFIX_LOCK
)
6616 if (prefixes
& PREFIX_REPZ
) {
6617 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PAUSE
);
6620 case 0x9b: /* fwait */
6621 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
6622 (HF_MP_MASK
| HF_TS_MASK
)) {
6623 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
6625 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6626 gen_op_set_cc_op(s
->cc_op
);
6627 gen_jmp_im(pc_start
- s
->cs_base
);
6631 case 0xcc: /* int3 */
6632 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6634 case 0xcd: /* int N */
6635 val
= ldub_code(s
->pc
++);
6636 if (s
->vm86
&& s
->iopl
!= 3) {
6637 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6639 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6642 case 0xce: /* into */
6645 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6646 gen_op_set_cc_op(s
->cc_op
);
6647 gen_jmp_im(pc_start
- s
->cs_base
);
6648 gen_helper_into(tcg_const_i32(s
->pc
- pc_start
));
6651 case 0xf1: /* icebp (undocumented, exits to external debugger) */
6652 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_ICEBP
);
6654 gen_debug(s
, pc_start
- s
->cs_base
);
6657 tb_flush(cpu_single_env
);
6658 cpu_set_log(CPU_LOG_INT
| CPU_LOG_TB_IN_ASM
);
6662 case 0xfa: /* cli */
6664 if (s
->cpl
<= s
->iopl
) {
6667 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6673 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6677 case 0xfb: /* sti */
6679 if (s
->cpl
<= s
->iopl
) {
6682 /* interruptions are enabled only the first insn after sti */
6683 /* If several instructions disable interrupts, only the
6685 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
6686 gen_helper_set_inhibit_irq();
6687 /* give a chance to handle pending irqs */
6688 gen_jmp_im(s
->pc
- s
->cs_base
);
6691 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6697 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6701 case 0x62: /* bound */
6704 ot
= dflag
? OT_LONG
: OT_WORD
;
6705 modrm
= ldub_code(s
->pc
++);
6706 reg
= (modrm
>> 3) & 7;
6707 mod
= (modrm
>> 6) & 3;
6710 gen_op_mov_TN_reg(ot
, 0, reg
);
6711 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6712 gen_jmp_im(pc_start
- s
->cs_base
);
6713 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6715 gen_helper_boundw(cpu_A0
, cpu_tmp2_i32
);
6717 gen_helper_boundl(cpu_A0
, cpu_tmp2_i32
);
6719 case 0x1c8 ... 0x1cf: /* bswap reg */
6720 reg
= (b
& 7) | REX_B(s
);
6721 #ifdef TARGET_X86_64
6723 gen_op_mov_TN_reg(OT_QUAD
, 0, reg
);
6724 tcg_gen_bswap64_i64(cpu_T
[0], cpu_T
[0]);
6725 gen_op_mov_reg_T0(OT_QUAD
, reg
);
6729 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
6730 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
6731 tcg_gen_bswap32_tl(cpu_T
[0], cpu_T
[0]);
6732 gen_op_mov_reg_T0(OT_LONG
, reg
);
6735 case 0xd6: /* salc */
6738 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6739 gen_op_set_cc_op(s
->cc_op
);
6740 gen_compute_eflags_c(cpu_T
[0]);
6741 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
6742 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
6744 case 0xe0: /* loopnz */
6745 case 0xe1: /* loopz */
6746 case 0xe2: /* loop */
6747 case 0xe3: /* jecxz */
6751 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6752 next_eip
= s
->pc
- s
->cs_base
;
6757 l1
= gen_new_label();
6758 l2
= gen_new_label();
6759 l3
= gen_new_label();
6762 case 0: /* loopnz */
6764 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6765 gen_op_set_cc_op(s
->cc_op
);
6766 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6767 gen_op_jz_ecx(s
->aflag
, l3
);
6768 gen_compute_eflags(cpu_tmp0
);
6769 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_Z
);
6771 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, l1
);
6773 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, l1
);
6777 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6778 gen_op_jnz_ecx(s
->aflag
, l1
);
6782 gen_op_jz_ecx(s
->aflag
, l1
);
6787 gen_jmp_im(next_eip
);
6796 case 0x130: /* wrmsr */
6797 case 0x132: /* rdmsr */
6799 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6801 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6802 gen_op_set_cc_op(s
->cc_op
);
6803 gen_jmp_im(pc_start
- s
->cs_base
);
6811 case 0x131: /* rdtsc */
6812 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6813 gen_op_set_cc_op(s
->cc_op
);
6814 gen_jmp_im(pc_start
- s
->cs_base
);
6820 gen_jmp(s
, s
->pc
- s
->cs_base
);
6823 case 0x133: /* rdpmc */
6824 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6825 gen_op_set_cc_op(s
->cc_op
);
6826 gen_jmp_im(pc_start
- s
->cs_base
);
6829 case 0x134: /* sysenter */
6830 /* For Intel SYSENTER is valid on 64-bit */
6831 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6834 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6836 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6837 gen_op_set_cc_op(s
->cc_op
);
6838 s
->cc_op
= CC_OP_DYNAMIC
;
6840 gen_jmp_im(pc_start
- s
->cs_base
);
6841 gen_helper_sysenter();
6845 case 0x135: /* sysexit */
6846 /* For Intel SYSEXIT is valid on 64-bit */
6847 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6850 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6852 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6853 gen_op_set_cc_op(s
->cc_op
);
6854 s
->cc_op
= CC_OP_DYNAMIC
;
6856 gen_jmp_im(pc_start
- s
->cs_base
);
6857 gen_helper_sysexit(tcg_const_i32(dflag
));
6861 #ifdef TARGET_X86_64
6862 case 0x105: /* syscall */
6863 /* XXX: is it usable in real mode ? */
6864 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6865 gen_op_set_cc_op(s
->cc_op
);
6866 s
->cc_op
= CC_OP_DYNAMIC
;
6868 gen_jmp_im(pc_start
- s
->cs_base
);
6869 gen_helper_syscall(tcg_const_i32(s
->pc
- pc_start
));
6872 case 0x107: /* sysret */
6874 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6876 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6877 gen_op_set_cc_op(s
->cc_op
);
6878 s
->cc_op
= CC_OP_DYNAMIC
;
6880 gen_jmp_im(pc_start
- s
->cs_base
);
6881 gen_helper_sysret(tcg_const_i32(s
->dflag
));
6882 /* condition codes are modified only in long mode */
6884 s
->cc_op
= CC_OP_EFLAGS
;
6889 case 0x1a2: /* cpuid */
6890 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6891 gen_op_set_cc_op(s
->cc_op
);
6892 gen_jmp_im(pc_start
- s
->cs_base
);
6895 case 0xf4: /* hlt */
6897 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6899 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6900 gen_op_set_cc_op(s
->cc_op
);
6901 gen_jmp_im(pc_start
- s
->cs_base
);
6902 gen_helper_hlt(tcg_const_i32(s
->pc
- pc_start
));
6907 modrm
= ldub_code(s
->pc
++);
6908 mod
= (modrm
>> 6) & 3;
6909 op
= (modrm
>> 3) & 7;
6912 if (!s
->pe
|| s
->vm86
)
6914 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_READ
);
6915 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,ldt
.selector
));
6919 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6922 if (!s
->pe
|| s
->vm86
)
6925 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6927 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_WRITE
);
6928 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6929 gen_jmp_im(pc_start
- s
->cs_base
);
6930 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6931 gen_helper_lldt(cpu_tmp2_i32
);
6935 if (!s
->pe
|| s
->vm86
)
6937 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_READ
);
6938 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,tr
.selector
));
6942 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6945 if (!s
->pe
|| s
->vm86
)
6948 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6950 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_WRITE
);
6951 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6952 gen_jmp_im(pc_start
- s
->cs_base
);
6953 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6954 gen_helper_ltr(cpu_tmp2_i32
);
6959 if (!s
->pe
|| s
->vm86
)
6961 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6962 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6963 gen_op_set_cc_op(s
->cc_op
);
6965 gen_helper_verr(cpu_T
[0]);
6967 gen_helper_verw(cpu_T
[0]);
6968 s
->cc_op
= CC_OP_EFLAGS
;
6975 modrm
= ldub_code(s
->pc
++);
6976 mod
= (modrm
>> 6) & 3;
6977 op
= (modrm
>> 3) & 7;
6983 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_GDTR_READ
);
6984 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6985 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.limit
));
6986 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
6987 gen_add_A0_im(s
, 2);
6988 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.base
));
6990 gen_op_andl_T0_im(0xffffff);
6991 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
6996 case 0: /* monitor */
6997 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7000 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7001 gen_op_set_cc_op(s
->cc_op
);
7002 gen_jmp_im(pc_start
- s
->cs_base
);
7003 #ifdef TARGET_X86_64
7004 if (s
->aflag
== 2) {
7005 gen_op_movq_A0_reg(R_EAX
);
7009 gen_op_movl_A0_reg(R_EAX
);
7011 gen_op_andl_A0_ffff();
7013 gen_add_A0_ds_seg(s
);
7014 gen_helper_monitor(cpu_A0
);
7017 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7020 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7021 gen_op_set_cc_op(s
->cc_op
);
7022 s
->cc_op
= CC_OP_DYNAMIC
;
7024 gen_jmp_im(pc_start
- s
->cs_base
);
7025 gen_helper_mwait(tcg_const_i32(s
->pc
- pc_start
));
7032 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IDTR_READ
);
7033 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7034 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.limit
));
7035 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7036 gen_add_A0_im(s
, 2);
7037 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.base
));
7039 gen_op_andl_T0_im(0xffffff);
7040 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7046 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7047 gen_op_set_cc_op(s
->cc_op
);
7048 gen_jmp_im(pc_start
- s
->cs_base
);
7051 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7054 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7057 gen_helper_vmrun(tcg_const_i32(s
->aflag
),
7058 tcg_const_i32(s
->pc
- pc_start
));
7063 case 1: /* VMMCALL */
7064 if (!(s
->flags
& HF_SVME_MASK
))
7066 gen_helper_vmmcall();
7068 case 2: /* VMLOAD */
7069 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7072 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7075 gen_helper_vmload(tcg_const_i32(s
->aflag
));
7078 case 3: /* VMSAVE */
7079 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7082 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7085 gen_helper_vmsave(tcg_const_i32(s
->aflag
));
7089 if ((!(s
->flags
& HF_SVME_MASK
) &&
7090 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7094 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7101 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7104 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7110 case 6: /* SKINIT */
7111 if ((!(s
->flags
& HF_SVME_MASK
) &&
7112 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7115 gen_helper_skinit();
7117 case 7: /* INVLPGA */
7118 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7121 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7124 gen_helper_invlpga(tcg_const_i32(s
->aflag
));
7130 } else if (s
->cpl
!= 0) {
7131 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7133 gen_svm_check_intercept(s
, pc_start
,
7134 op
==2 ? SVM_EXIT_GDTR_WRITE
: SVM_EXIT_IDTR_WRITE
);
7135 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7136 gen_op_ld_T1_A0(OT_WORD
+ s
->mem_index
);
7137 gen_add_A0_im(s
, 2);
7138 gen_op_ld_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7140 gen_op_andl_T0_im(0xffffff);
7142 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,gdt
.base
));
7143 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,gdt
.limit
));
7145 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,idt
.base
));
7146 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,idt
.limit
));
7151 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_CR0
);
7152 #if defined TARGET_X86_64 && defined WORDS_BIGENDIAN
7153 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]) + 4);
7155 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]));
7157 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 1);
7161 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7163 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7164 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7165 gen_helper_lmsw(cpu_T
[0]);
7166 gen_jmp_im(s
->pc
- s
->cs_base
);
7170 case 7: /* invlpg */
7172 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7175 #ifdef TARGET_X86_64
7176 if (CODE64(s
) && rm
== 0) {
7178 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,segs
[R_GS
].base
));
7179 tcg_gen_ld_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,kernelgsbase
));
7180 tcg_gen_st_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,segs
[R_GS
].base
));
7181 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,kernelgsbase
));
7188 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7189 gen_op_set_cc_op(s
->cc_op
);
7190 gen_jmp_im(pc_start
- s
->cs_base
);
7191 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7192 gen_helper_invlpg(cpu_A0
);
7193 gen_jmp_im(s
->pc
- s
->cs_base
);
7202 case 0x108: /* invd */
7203 case 0x109: /* wbinvd */
7205 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7207 gen_svm_check_intercept(s
, pc_start
, (b
& 2) ? SVM_EXIT_INVD
: SVM_EXIT_WBINVD
);
7211 case 0x63: /* arpl or movslS (x86_64) */
7212 #ifdef TARGET_X86_64
7215 /* d_ot is the size of destination */
7216 d_ot
= dflag
+ OT_WORD
;
7218 modrm
= ldub_code(s
->pc
++);
7219 reg
= ((modrm
>> 3) & 7) | rex_r
;
7220 mod
= (modrm
>> 6) & 3;
7221 rm
= (modrm
& 7) | REX_B(s
);
7224 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
7226 if (d_ot
== OT_QUAD
)
7227 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
7228 gen_op_mov_reg_T0(d_ot
, reg
);
7230 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7231 if (d_ot
== OT_QUAD
) {
7232 gen_op_lds_T0_A0(OT_LONG
+ s
->mem_index
);
7234 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7236 gen_op_mov_reg_T0(d_ot
, reg
);
7244 if (!s
->pe
|| s
->vm86
)
7246 t0
= tcg_temp_local_new();
7247 t1
= tcg_temp_local_new();
7248 t2
= tcg_temp_local_new();
7250 modrm
= ldub_code(s
->pc
++);
7251 reg
= (modrm
>> 3) & 7;
7252 mod
= (modrm
>> 6) & 3;
7255 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7256 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7258 gen_op_mov_v_reg(ot
, t0
, rm
);
7260 gen_op_mov_v_reg(ot
, t1
, reg
);
7261 tcg_gen_andi_tl(cpu_tmp0
, t0
, 3);
7262 tcg_gen_andi_tl(t1
, t1
, 3);
7263 tcg_gen_movi_tl(t2
, 0);
7264 label1
= gen_new_label();
7265 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_tmp0
, t1
, label1
);
7266 tcg_gen_andi_tl(t0
, t0
, ~3);
7267 tcg_gen_or_tl(t0
, t0
, t1
);
7268 tcg_gen_movi_tl(t2
, CC_Z
);
7269 gen_set_label(label1
);
7271 gen_op_st_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7273 gen_op_mov_reg_v(ot
, rm
, t0
);
7275 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7276 gen_op_set_cc_op(s
->cc_op
);
7277 gen_compute_eflags(cpu_cc_src
);
7278 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_Z
);
7279 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t2
);
7280 s
->cc_op
= CC_OP_EFLAGS
;
7286 case 0x102: /* lar */
7287 case 0x103: /* lsl */
7291 if (!s
->pe
|| s
->vm86
)
7293 ot
= dflag
? OT_LONG
: OT_WORD
;
7294 modrm
= ldub_code(s
->pc
++);
7295 reg
= ((modrm
>> 3) & 7) | rex_r
;
7296 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7297 t0
= tcg_temp_local_new();
7298 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7299 gen_op_set_cc_op(s
->cc_op
);
7301 gen_helper_lar(t0
, cpu_T
[0]);
7303 gen_helper_lsl(t0
, cpu_T
[0]);
7304 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_src
, CC_Z
);
7305 label1
= gen_new_label();
7306 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
7307 gen_op_mov_reg_v(ot
, reg
, t0
);
7308 gen_set_label(label1
);
7309 s
->cc_op
= CC_OP_EFLAGS
;
7314 modrm
= ldub_code(s
->pc
++);
7315 mod
= (modrm
>> 6) & 3;
7316 op
= (modrm
>> 3) & 7;
7318 case 0: /* prefetchnta */
7319 case 1: /* prefetchnt0 */
7320 case 2: /* prefetchnt0 */
7321 case 3: /* prefetchnt0 */
7324 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7325 /* nothing more to do */
7327 default: /* nop (multi byte) */
7328 gen_nop_modrm(s
, modrm
);
7332 case 0x119 ... 0x11f: /* nop (multi byte) */
7333 modrm
= ldub_code(s
->pc
++);
7334 gen_nop_modrm(s
, modrm
);
7336 case 0x120: /* mov reg, crN */
7337 case 0x122: /* mov crN, reg */
7339 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7341 modrm
= ldub_code(s
->pc
++);
7342 if ((modrm
& 0xc0) != 0xc0)
7344 rm
= (modrm
& 7) | REX_B(s
);
7345 reg
= ((modrm
>> 3) & 7) | rex_r
;
7356 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7357 gen_op_set_cc_op(s
->cc_op
);
7358 gen_jmp_im(pc_start
- s
->cs_base
);
7360 gen_op_mov_TN_reg(ot
, 0, rm
);
7361 gen_helper_write_crN(tcg_const_i32(reg
), cpu_T
[0]);
7362 gen_jmp_im(s
->pc
- s
->cs_base
);
7365 gen_helper_read_crN(cpu_T
[0], tcg_const_i32(reg
));
7366 gen_op_mov_reg_T0(ot
, rm
);
7374 case 0x121: /* mov reg, drN */
7375 case 0x123: /* mov drN, reg */
7377 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7379 modrm
= ldub_code(s
->pc
++);
7380 if ((modrm
& 0xc0) != 0xc0)
7382 rm
= (modrm
& 7) | REX_B(s
);
7383 reg
= ((modrm
>> 3) & 7) | rex_r
;
7388 /* XXX: do it dynamically with CR4.DE bit */
7389 if (reg
== 4 || reg
== 5 || reg
>= 8)
7392 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_DR0
+ reg
);
7393 gen_op_mov_TN_reg(ot
, 0, rm
);
7394 gen_helper_movl_drN_T0(tcg_const_i32(reg
), cpu_T
[0]);
7395 gen_jmp_im(s
->pc
- s
->cs_base
);
7398 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_DR0
+ reg
);
7399 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,dr
[reg
]));
7400 gen_op_mov_reg_T0(ot
, rm
);
7404 case 0x106: /* clts */
7406 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7408 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7410 /* abort block because static cpu state changed */
7411 gen_jmp_im(s
->pc
- s
->cs_base
);
7415 /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
7416 case 0x1c3: /* MOVNTI reg, mem */
7417 if (!(s
->cpuid_features
& CPUID_SSE2
))
7419 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
7420 modrm
= ldub_code(s
->pc
++);
7421 mod
= (modrm
>> 6) & 3;
7424 reg
= ((modrm
>> 3) & 7) | rex_r
;
7425 /* generate a generic store */
7426 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
7429 modrm
= ldub_code(s
->pc
++);
7430 mod
= (modrm
>> 6) & 3;
7431 op
= (modrm
>> 3) & 7;
7433 case 0: /* fxsave */
7434 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7435 (s
->flags
& HF_EM_MASK
))
7437 if (s
->flags
& HF_TS_MASK
) {
7438 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7441 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7442 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7443 gen_op_set_cc_op(s
->cc_op
);
7444 gen_jmp_im(pc_start
- s
->cs_base
);
7445 gen_helper_fxsave(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7447 case 1: /* fxrstor */
7448 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7449 (s
->flags
& HF_EM_MASK
))
7451 if (s
->flags
& HF_TS_MASK
) {
7452 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7455 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7456 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7457 gen_op_set_cc_op(s
->cc_op
);
7458 gen_jmp_im(pc_start
- s
->cs_base
);
7459 gen_helper_fxrstor(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7461 case 2: /* ldmxcsr */
7462 case 3: /* stmxcsr */
7463 if (s
->flags
& HF_TS_MASK
) {
7464 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7467 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
7470 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7472 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7473 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7475 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7476 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
7479 case 5: /* lfence */
7480 case 6: /* mfence */
7481 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE
))
7484 case 7: /* sfence / clflush */
7485 if ((modrm
& 0xc7) == 0xc0) {
7487 /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
7488 if (!(s
->cpuid_features
& CPUID_SSE
))
7492 if (!(s
->cpuid_features
& CPUID_CLFLUSH
))
7494 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7501 case 0x10d: /* 3DNow! prefetch(w) */
7502 modrm
= ldub_code(s
->pc
++);
7503 mod
= (modrm
>> 6) & 3;
7506 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7507 /* ignore for now */
7509 case 0x1aa: /* rsm */
7510 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_RSM
);
7511 if (!(s
->flags
& HF_SMM_MASK
))
7513 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7514 gen_op_set_cc_op(s
->cc_op
);
7515 s
->cc_op
= CC_OP_DYNAMIC
;
7517 gen_jmp_im(s
->pc
- s
->cs_base
);
7521 case 0x1b8: /* SSE4.2 popcnt */
7522 if ((prefixes
& (PREFIX_REPZ
| PREFIX_LOCK
| PREFIX_REPNZ
)) !=
7525 if (!(s
->cpuid_ext_features
& CPUID_EXT_POPCNT
))
7528 modrm
= ldub_code(s
->pc
++);
7529 reg
= ((modrm
>> 3) & 7);
7531 if (s
->prefix
& PREFIX_DATA
)
7533 else if (s
->dflag
!= 2)
7538 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
7539 gen_helper_popcnt(cpu_T
[0], cpu_T
[0], tcg_const_i32(ot
));
7540 gen_op_mov_reg_T0(ot
, reg
);
7542 s
->cc_op
= CC_OP_EFLAGS
;
7544 case 0x10e ... 0x10f:
7545 /* 3DNow! instructions, ignore prefixes */
7546 s
->prefix
&= ~(PREFIX_REPZ
| PREFIX_REPNZ
| PREFIX_DATA
);
7547 case 0x110 ... 0x117:
7548 case 0x128 ... 0x12f:
7549 case 0x138 ... 0x13a:
7550 case 0x150 ... 0x177:
7551 case 0x17c ... 0x17f:
7553 case 0x1c4 ... 0x1c6:
7554 case 0x1d0 ... 0x1fe:
7555 gen_sse(s
, b
, pc_start
, rex_r
);
7560 /* lock generation */
7561 if (s
->prefix
& PREFIX_LOCK
)
7562 gen_helper_unlock();
7565 if (s
->prefix
& PREFIX_LOCK
)
7566 gen_helper_unlock();
7567 /* XXX: ensure that no lock was generated */
7568 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
7572 void optimize_flags_init(void)
7574 #if TCG_TARGET_REG_BITS == 32
7575 assert(sizeof(CCTable
) == (1 << 3));
7577 assert(sizeof(CCTable
) == (1 << 4));
7579 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
7580 cpu_cc_op
= tcg_global_mem_new_i32(TCG_AREG0
,
7581 offsetof(CPUState
, cc_op
), "cc_op");
7582 cpu_cc_src
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_src
),
7584 cpu_cc_dst
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_dst
),
7586 cpu_cc_tmp
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_tmp
),
7589 /* register helpers */
7590 #define GEN_HELPER 2
7594 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
7595 basic block 'tb'. If search_pc is TRUE, also generate PC
7596 information for each intermediate instruction. */
7597 static inline void gen_intermediate_code_internal(CPUState
*env
,
7598 TranslationBlock
*tb
,
7601 DisasContext dc1
, *dc
= &dc1
;
7602 target_ulong pc_ptr
;
7603 uint16_t *gen_opc_end
;
7607 target_ulong pc_start
;
7608 target_ulong cs_base
;
7612 /* generate intermediate code */
7614 cs_base
= tb
->cs_base
;
7616 cflags
= tb
->cflags
;
7618 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
7619 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
7620 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
7621 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
7623 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
7624 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
7625 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
7626 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
7627 dc
->singlestep_enabled
= env
->singlestep_enabled
;
7628 dc
->cc_op
= CC_OP_DYNAMIC
;
7629 dc
->cs_base
= cs_base
;
7631 dc
->popl_esp_hack
= 0;
7632 /* select memory access functions */
7634 if (flags
& HF_SOFTMMU_MASK
) {
7636 dc
->mem_index
= 2 * 4;
7638 dc
->mem_index
= 1 * 4;
7640 dc
->cpuid_features
= env
->cpuid_features
;
7641 dc
->cpuid_ext_features
= env
->cpuid_ext_features
;
7642 dc
->cpuid_ext2_features
= env
->cpuid_ext2_features
;
7643 dc
->cpuid_ext3_features
= env
->cpuid_ext3_features
;
7644 #ifdef TARGET_X86_64
7645 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
7646 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
7649 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
7650 (flags
& HF_INHIBIT_IRQ_MASK
)
7651 #ifndef CONFIG_SOFTMMU
7652 || (flags
& HF_SOFTMMU_MASK
)
7656 /* check addseg logic */
7657 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
7658 printf("ERROR addseg\n");
7661 cpu_T
[0] = tcg_temp_new();
7662 cpu_T
[1] = tcg_temp_new();
7663 cpu_A0
= tcg_temp_new();
7664 cpu_T3
= tcg_temp_new();
7666 cpu_tmp0
= tcg_temp_new();
7667 cpu_tmp1_i64
= tcg_temp_new_i64();
7668 cpu_tmp2_i32
= tcg_temp_new_i32();
7669 cpu_tmp3_i32
= tcg_temp_new_i32();
7670 cpu_tmp4
= tcg_temp_new();
7671 cpu_tmp5
= tcg_temp_new();
7672 cpu_tmp6
= tcg_temp_new();
7673 cpu_ptr0
= tcg_temp_new_ptr();
7674 cpu_ptr1
= tcg_temp_new_ptr();
7676 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7678 dc
->is_jmp
= DISAS_NEXT
;
7682 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7684 max_insns
= CF_COUNT_MASK
;
7688 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
7689 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7690 if (bp
->pc
== pc_ptr
) {
7691 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
7697 j
= gen_opc_ptr
- gen_opc_buf
;
7701 gen_opc_instr_start
[lj
++] = 0;
7703 gen_opc_pc
[lj
] = pc_ptr
;
7704 gen_opc_cc_op
[lj
] = dc
->cc_op
;
7705 gen_opc_instr_start
[lj
] = 1;
7706 gen_opc_icount
[lj
] = num_insns
;
7708 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7711 pc_ptr
= disas_insn(dc
, pc_ptr
);
7713 /* stop translation if indicated */
7716 /* if single step mode, we generate only one instruction and
7717 generate an exception */
7718 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
7719 the flag and abort the translation to give the irqs a
7720 change to be happen */
7721 if (dc
->tf
|| dc
->singlestep_enabled
||
7722 (flags
& HF_INHIBIT_IRQ_MASK
)) {
7723 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7727 /* if too long translation, stop generation too */
7728 if (gen_opc_ptr
>= gen_opc_end
||
7729 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32) ||
7730 num_insns
>= max_insns
) {
7731 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7736 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7741 if (tb
->cflags
& CF_LAST_IO
)
7743 gen_icount_end(tb
, num_insns
);
7744 *gen_opc_ptr
= INDEX_op_end
;
7745 /* we don't forget to fill the last values */
7747 j
= gen_opc_ptr
- gen_opc_buf
;
7750 gen_opc_instr_start
[lj
++] = 0;
7754 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, X86_DUMP_CCOP
);
7755 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
7757 qemu_log("----------------\n");
7758 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
7759 #ifdef TARGET_X86_64
7764 disas_flags
= !dc
->code32
;
7765 log_target_disas(pc_start
, pc_ptr
- pc_start
, disas_flags
);
7771 tb
->size
= pc_ptr
- pc_start
;
7772 tb
->icount
= num_insns
;
7776 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
7778 gen_intermediate_code_internal(env
, tb
, 0);
7781 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
7783 gen_intermediate_code_internal(env
, tb
, 1);
7786 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7787 unsigned long searched_pc
, int pc_pos
, void *puc
)
7791 if (qemu_loglevel_mask(CPU_LOG_TB_OP
)) {
7793 qemu_log("RESTORE:\n");
7794 for(i
= 0;i
<= pc_pos
; i
++) {
7795 if (gen_opc_instr_start
[i
]) {
7796 qemu_log("0x%04x: " TARGET_FMT_lx
"\n", i
, gen_opc_pc
[i
]);
7799 qemu_log("spc=0x%08lx pc_pos=0x%x eip=" TARGET_FMT_lx
" cs_base=%x\n",
7800 searched_pc
, pc_pos
, gen_opc_pc
[pc_pos
] - tb
->cs_base
,
7801 (uint32_t)tb
->cs_base
);
7804 env
->eip
= gen_opc_pc
[pc_pos
] - tb
->cs_base
;
7805 cc_op
= gen_opc_cc_op
[pc_pos
];
7806 if (cc_op
!= CC_OP_DYNAMIC
)