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, see <http://www.gnu.org/licenses/>.
35 #define PREFIX_REPZ 0x01
36 #define PREFIX_REPNZ 0x02
37 #define PREFIX_LOCK 0x04
38 #define PREFIX_DATA 0x08
39 #define PREFIX_ADR 0x10
42 #define X86_64_ONLY(x) x
43 #define X86_64_DEF(...) __VA_ARGS__
44 #define CODE64(s) ((s)->code64)
45 #define REX_X(s) ((s)->rex_x)
46 #define REX_B(s) ((s)->rex_b)
47 /* XXX: gcc generates push/pop in some opcodes, so we cannot use them */
49 #define BUGGY_64(x) NULL
52 #define X86_64_ONLY(x) NULL
53 #define X86_64_DEF(...)
59 //#define MACRO_TEST 1
61 /* global register indexes */
62 static TCGv_ptr cpu_env
;
63 static TCGv cpu_A0
, cpu_cc_src
, cpu_cc_dst
, cpu_cc_tmp
;
64 static TCGv_i32 cpu_cc_op
;
65 static TCGv cpu_regs
[CPU_NB_REGS
];
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
;
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(HOST_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
)
279 tmp
= tcg_temp_new();
280 tcg_gen_ext8u_tl(tmp
, t0
);
281 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
282 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xff);
283 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
285 tcg_gen_shli_tl(tmp
, tmp
, 8);
286 tcg_gen_andi_tl(cpu_regs
[reg
- 4], cpu_regs
[reg
- 4], ~0xff00);
287 tcg_gen_or_tl(cpu_regs
[reg
- 4], cpu_regs
[reg
- 4], tmp
);
292 tmp
= tcg_temp_new();
293 tcg_gen_ext16u_tl(tmp
, t0
);
294 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
295 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
298 default: /* XXX this shouldn't be reached; abort? */
300 /* For x86_64, this sets the higher half of register to zero.
301 For i386, this is equivalent to a mov. */
302 tcg_gen_ext32u_tl(cpu_regs
[reg
], t0
);
306 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
312 static inline void gen_op_mov_reg_T0(int ot
, int reg
)
314 gen_op_mov_reg_v(ot
, reg
, cpu_T
[0]);
317 static inline void gen_op_mov_reg_T1(int ot
, int reg
)
319 gen_op_mov_reg_v(ot
, reg
, cpu_T
[1]);
322 static inline void gen_op_mov_reg_A0(int size
, int reg
)
328 tmp
= tcg_temp_new();
329 tcg_gen_ext16u_tl(tmp
, cpu_A0
);
330 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
331 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
334 default: /* XXX this shouldn't be reached; abort? */
336 /* For x86_64, this sets the higher half of register to zero.
337 For i386, this is equivalent to a mov. */
338 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_A0
);
342 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_A0
);
348 static inline void gen_op_mov_v_reg(int ot
, TCGv t0
, int reg
)
352 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
355 tcg_gen_shri_tl(t0
, cpu_regs
[reg
- 4], 8);
356 tcg_gen_ext8u_tl(t0
, t0
);
361 tcg_gen_mov_tl(t0
, cpu_regs
[reg
]);
366 static inline void gen_op_mov_TN_reg(int ot
, int t_index
, int reg
)
368 gen_op_mov_v_reg(ot
, cpu_T
[t_index
], reg
);
371 static inline void gen_op_movl_A0_reg(int reg
)
373 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
376 static inline void gen_op_addl_A0_im(int32_t val
)
378 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
380 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
385 static inline void gen_op_addq_A0_im(int64_t val
)
387 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
391 static void gen_add_A0_im(DisasContext
*s
, int val
)
395 gen_op_addq_A0_im(val
);
398 gen_op_addl_A0_im(val
);
401 static inline void gen_op_addl_T0_T1(void)
403 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
406 static inline void gen_op_jmp_T0(void)
408 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, eip
));
411 static inline void gen_op_add_reg_im(int size
, int reg
, int32_t val
)
415 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
416 tcg_gen_ext16u_tl(cpu_tmp0
, cpu_tmp0
);
417 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
418 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
);
421 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
422 /* For x86_64, this sets the higher half of register to zero.
423 For i386, this is equivalent to a nop. */
424 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
425 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
429 tcg_gen_addi_tl(cpu_regs
[reg
], cpu_regs
[reg
], val
);
435 static inline void gen_op_add_reg_T0(int size
, int reg
)
439 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
440 tcg_gen_ext16u_tl(cpu_tmp0
, cpu_tmp0
);
441 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
442 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
);
445 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
446 /* For x86_64, this sets the higher half of register to zero.
447 For i386, this is equivalent to a nop. */
448 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
449 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
453 tcg_gen_add_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_T
[0]);
459 static inline void gen_op_set_cc_op(int32_t val
)
461 tcg_gen_movi_i32(cpu_cc_op
, val
);
464 static inline void gen_op_addl_A0_reg_sN(int shift
, int reg
)
466 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
468 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
469 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
470 /* For x86_64, this sets the higher half of register to zero.
471 For i386, this is equivalent to a nop. */
472 tcg_gen_ext32u_tl(cpu_A0
, cpu_A0
);
475 static inline void gen_op_movl_A0_seg(int reg
)
477 tcg_gen_ld32u_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
) + REG_L_OFFSET
);
480 static inline void gen_op_addl_A0_seg(int reg
)
482 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
483 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
485 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
490 static inline void gen_op_movq_A0_seg(int reg
)
492 tcg_gen_ld_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
495 static inline void gen_op_addq_A0_seg(int reg
)
497 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
498 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
501 static inline void gen_op_movq_A0_reg(int reg
)
503 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
506 static inline void gen_op_addq_A0_reg_sN(int shift
, int reg
)
508 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
510 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
511 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
515 static inline void gen_op_lds_T0_A0(int idx
)
517 int mem_index
= (idx
>> 2) - 1;
520 tcg_gen_qemu_ld8s(cpu_T
[0], cpu_A0
, mem_index
);
523 tcg_gen_qemu_ld16s(cpu_T
[0], cpu_A0
, mem_index
);
527 tcg_gen_qemu_ld32s(cpu_T
[0], cpu_A0
, mem_index
);
532 static inline void gen_op_ld_v(int idx
, TCGv t0
, TCGv a0
)
534 int mem_index
= (idx
>> 2) - 1;
537 tcg_gen_qemu_ld8u(t0
, a0
, mem_index
);
540 tcg_gen_qemu_ld16u(t0
, a0
, mem_index
);
543 tcg_gen_qemu_ld32u(t0
, a0
, mem_index
);
547 /* Should never happen on 32-bit targets. */
549 tcg_gen_qemu_ld64(t0
, a0
, mem_index
);
555 /* XXX: always use ldu or lds */
556 static inline void gen_op_ld_T0_A0(int idx
)
558 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
561 static inline void gen_op_ldu_T0_A0(int idx
)
563 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
566 static inline void gen_op_ld_T1_A0(int idx
)
568 gen_op_ld_v(idx
, cpu_T
[1], cpu_A0
);
571 static inline void gen_op_st_v(int idx
, TCGv t0
, TCGv a0
)
573 int mem_index
= (idx
>> 2) - 1;
576 tcg_gen_qemu_st8(t0
, a0
, mem_index
);
579 tcg_gen_qemu_st16(t0
, a0
, mem_index
);
582 tcg_gen_qemu_st32(t0
, a0
, mem_index
);
586 /* Should never happen on 32-bit targets. */
588 tcg_gen_qemu_st64(t0
, a0
, mem_index
);
594 static inline void gen_op_st_T0_A0(int idx
)
596 gen_op_st_v(idx
, cpu_T
[0], cpu_A0
);
599 static inline void gen_op_st_T1_A0(int idx
)
601 gen_op_st_v(idx
, cpu_T
[1], cpu_A0
);
604 static inline void gen_jmp_im(target_ulong pc
)
606 tcg_gen_movi_tl(cpu_tmp0
, pc
);
607 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, eip
));
610 static inline void gen_string_movl_A0_ESI(DisasContext
*s
)
614 override
= s
->override
;
618 gen_op_movq_A0_seg(override
);
619 gen_op_addq_A0_reg_sN(0, R_ESI
);
621 gen_op_movq_A0_reg(R_ESI
);
627 if (s
->addseg
&& override
< 0)
630 gen_op_movl_A0_seg(override
);
631 gen_op_addl_A0_reg_sN(0, R_ESI
);
633 gen_op_movl_A0_reg(R_ESI
);
636 /* 16 address, always override */
639 gen_op_movl_A0_reg(R_ESI
);
640 gen_op_andl_A0_ffff();
641 gen_op_addl_A0_seg(override
);
645 static inline void gen_string_movl_A0_EDI(DisasContext
*s
)
649 gen_op_movq_A0_reg(R_EDI
);
654 gen_op_movl_A0_seg(R_ES
);
655 gen_op_addl_A0_reg_sN(0, R_EDI
);
657 gen_op_movl_A0_reg(R_EDI
);
660 gen_op_movl_A0_reg(R_EDI
);
661 gen_op_andl_A0_ffff();
662 gen_op_addl_A0_seg(R_ES
);
666 static inline void gen_op_movl_T0_Dshift(int ot
)
668 tcg_gen_ld32s_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, df
));
669 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], ot
);
672 static void gen_extu(int ot
, TCGv reg
)
676 tcg_gen_ext8u_tl(reg
, reg
);
679 tcg_gen_ext16u_tl(reg
, reg
);
682 tcg_gen_ext32u_tl(reg
, reg
);
689 static void gen_exts(int ot
, TCGv reg
)
693 tcg_gen_ext8s_tl(reg
, reg
);
696 tcg_gen_ext16s_tl(reg
, reg
);
699 tcg_gen_ext32s_tl(reg
, reg
);
706 static inline void gen_op_jnz_ecx(int size
, int label1
)
708 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
709 gen_extu(size
+ 1, cpu_tmp0
);
710 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, label1
);
713 static inline void gen_op_jz_ecx(int size
, int label1
)
715 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
716 gen_extu(size
+ 1, cpu_tmp0
);
717 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
720 static void gen_helper_in_func(int ot
, TCGv v
, TCGv_i32 n
)
723 case 0: gen_helper_inb(v
, n
); break;
724 case 1: gen_helper_inw(v
, n
); break;
725 case 2: gen_helper_inl(v
, n
); break;
730 static void gen_helper_out_func(int ot
, TCGv_i32 v
, TCGv_i32 n
)
733 case 0: gen_helper_outb(v
, n
); break;
734 case 1: gen_helper_outw(v
, n
); break;
735 case 2: gen_helper_outl(v
, n
); break;
740 static void gen_check_io(DisasContext
*s
, int ot
, target_ulong cur_eip
,
744 target_ulong next_eip
;
747 if (s
->pe
&& (s
->cpl
> s
->iopl
|| s
->vm86
)) {
748 if (s
->cc_op
!= CC_OP_DYNAMIC
)
749 gen_op_set_cc_op(s
->cc_op
);
752 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
754 case 0: gen_helper_check_iob(cpu_tmp2_i32
); break;
755 case 1: gen_helper_check_iow(cpu_tmp2_i32
); break;
756 case 2: gen_helper_check_iol(cpu_tmp2_i32
); break;
759 if(s
->flags
& HF_SVMI_MASK
) {
761 if (s
->cc_op
!= CC_OP_DYNAMIC
)
762 gen_op_set_cc_op(s
->cc_op
);
766 svm_flags
|= (1 << (4 + ot
));
767 next_eip
= s
->pc
- s
->cs_base
;
768 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
769 gen_helper_svm_check_io(cpu_tmp2_i32
, tcg_const_i32(svm_flags
),
770 tcg_const_i32(next_eip
- cur_eip
));
774 static inline void gen_movs(DisasContext
*s
, int ot
)
776 gen_string_movl_A0_ESI(s
);
777 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
778 gen_string_movl_A0_EDI(s
);
779 gen_op_st_T0_A0(ot
+ s
->mem_index
);
780 gen_op_movl_T0_Dshift(ot
);
781 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
782 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
785 static inline void gen_update_cc_op(DisasContext
*s
)
787 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
788 gen_op_set_cc_op(s
->cc_op
);
789 s
->cc_op
= CC_OP_DYNAMIC
;
793 static void gen_op_update1_cc(void)
795 tcg_gen_discard_tl(cpu_cc_src
);
796 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
799 static void gen_op_update2_cc(void)
801 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
802 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
805 static inline void gen_op_cmpl_T0_T1_cc(void)
807 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
808 tcg_gen_sub_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
811 static inline void gen_op_testl_T0_T1_cc(void)
813 tcg_gen_discard_tl(cpu_cc_src
);
814 tcg_gen_and_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
817 static void gen_op_update_neg_cc(void)
819 tcg_gen_neg_tl(cpu_cc_src
, cpu_T
[0]);
820 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
823 /* compute eflags.C to reg */
824 static void gen_compute_eflags_c(TCGv reg
)
826 gen_helper_cc_compute_c(cpu_tmp2_i32
, cpu_cc_op
);
827 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
830 /* compute all eflags to cc_src */
831 static void gen_compute_eflags(TCGv reg
)
833 gen_helper_cc_compute_all(cpu_tmp2_i32
, cpu_cc_op
);
834 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
837 static inline void gen_setcc_slow_T0(DisasContext
*s
, int jcc_op
)
839 if (s
->cc_op
!= CC_OP_DYNAMIC
)
840 gen_op_set_cc_op(s
->cc_op
);
843 gen_compute_eflags(cpu_T
[0]);
844 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 11);
845 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
848 gen_compute_eflags_c(cpu_T
[0]);
851 gen_compute_eflags(cpu_T
[0]);
852 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 6);
853 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
856 gen_compute_eflags(cpu_tmp0
);
857 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 6);
858 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
859 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
862 gen_compute_eflags(cpu_T
[0]);
863 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 7);
864 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
867 gen_compute_eflags(cpu_T
[0]);
868 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 2);
869 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
872 gen_compute_eflags(cpu_tmp0
);
873 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
874 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 7); /* CC_S */
875 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
876 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
880 gen_compute_eflags(cpu_tmp0
);
881 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
882 tcg_gen_shri_tl(cpu_tmp4
, cpu_tmp0
, 7); /* CC_S */
883 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 6); /* CC_Z */
884 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
885 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
886 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
891 /* return true if setcc_slow is not needed (WARNING: must be kept in
892 sync with gen_jcc1) */
893 static int is_fast_jcc_case(DisasContext
*s
, int b
)
896 jcc_op
= (b
>> 1) & 7;
898 /* we optimize the cmp/jcc case */
903 if (jcc_op
== JCC_O
|| jcc_op
== JCC_P
)
907 /* some jumps are easy to compute */
932 if (jcc_op
!= JCC_Z
&& jcc_op
!= JCC_S
)
942 /* generate a conditional jump to label 'l1' according to jump opcode
943 value 'b'. In the fast case, T0 is guaranted not to be used. */
944 static inline void gen_jcc1(DisasContext
*s
, int cc_op
, int b
, int l1
)
946 int inv
, jcc_op
, size
, cond
;
950 jcc_op
= (b
>> 1) & 7;
953 /* we optimize the cmp/jcc case */
959 size
= cc_op
- CC_OP_SUBB
;
965 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xff);
969 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffff);
974 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffffffff);
982 tcg_gen_brcondi_tl(inv
? TCG_COND_NE
: TCG_COND_EQ
, t0
, 0, l1
);
988 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80);
989 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
993 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x8000);
994 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
999 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80000000);
1000 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
1005 tcg_gen_brcondi_tl(inv
? TCG_COND_GE
: TCG_COND_LT
, cpu_cc_dst
,
1012 cond
= inv
? TCG_COND_GEU
: TCG_COND_LTU
;
1015 cond
= inv
? TCG_COND_GTU
: TCG_COND_LEU
;
1017 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1021 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xff);
1022 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xff);
1026 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffff);
1027 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffff);
1029 #ifdef TARGET_X86_64
1032 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffffffff);
1033 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffffffff);
1040 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1044 cond
= inv
? TCG_COND_GE
: TCG_COND_LT
;
1047 cond
= inv
? TCG_COND_GT
: TCG_COND_LE
;
1049 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1053 tcg_gen_ext8s_tl(cpu_tmp4
, cpu_tmp4
);
1054 tcg_gen_ext8s_tl(t0
, cpu_cc_src
);
1058 tcg_gen_ext16s_tl(cpu_tmp4
, cpu_tmp4
);
1059 tcg_gen_ext16s_tl(t0
, cpu_cc_src
);
1061 #ifdef TARGET_X86_64
1064 tcg_gen_ext32s_tl(cpu_tmp4
, cpu_tmp4
);
1065 tcg_gen_ext32s_tl(t0
, cpu_cc_src
);
1072 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1080 /* some jumps are easy to compute */
1122 size
= (cc_op
- CC_OP_ADDB
) & 3;
1125 size
= (cc_op
- CC_OP_ADDB
) & 3;
1133 gen_setcc_slow_T0(s
, jcc_op
);
1134 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
,
1140 /* XXX: does not work with gdbstub "ice" single step - not a
1142 static int gen_jz_ecx_string(DisasContext
*s
, target_ulong next_eip
)
1146 l1
= gen_new_label();
1147 l2
= gen_new_label();
1148 gen_op_jnz_ecx(s
->aflag
, l1
);
1150 gen_jmp_tb(s
, next_eip
, 1);
1155 static inline void gen_stos(DisasContext
*s
, int ot
)
1157 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1158 gen_string_movl_A0_EDI(s
);
1159 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1160 gen_op_movl_T0_Dshift(ot
);
1161 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1164 static inline void gen_lods(DisasContext
*s
, int ot
)
1166 gen_string_movl_A0_ESI(s
);
1167 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1168 gen_op_mov_reg_T0(ot
, R_EAX
);
1169 gen_op_movl_T0_Dshift(ot
);
1170 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1173 static inline void gen_scas(DisasContext
*s
, int ot
)
1175 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1176 gen_string_movl_A0_EDI(s
);
1177 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1178 gen_op_cmpl_T0_T1_cc();
1179 gen_op_movl_T0_Dshift(ot
);
1180 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1183 static inline void gen_cmps(DisasContext
*s
, int ot
)
1185 gen_string_movl_A0_ESI(s
);
1186 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1187 gen_string_movl_A0_EDI(s
);
1188 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1189 gen_op_cmpl_T0_T1_cc();
1190 gen_op_movl_T0_Dshift(ot
);
1191 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1192 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1195 static inline void gen_ins(DisasContext
*s
, int ot
)
1199 gen_string_movl_A0_EDI(s
);
1200 /* Note: we must do this dummy write first to be restartable in
1201 case of page fault. */
1203 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1204 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1205 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1206 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1207 gen_helper_in_func(ot
, cpu_T
[0], cpu_tmp2_i32
);
1208 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1209 gen_op_movl_T0_Dshift(ot
);
1210 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1215 static inline void gen_outs(DisasContext
*s
, int ot
)
1219 gen_string_movl_A0_ESI(s
);
1220 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1222 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1223 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1224 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1225 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[0]);
1226 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
1228 gen_op_movl_T0_Dshift(ot
);
1229 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1234 /* same method as Valgrind : we generate jumps to current or next
1236 #define GEN_REPZ(op) \
1237 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1238 target_ulong cur_eip, target_ulong next_eip) \
1241 gen_update_cc_op(s); \
1242 l2 = gen_jz_ecx_string(s, next_eip); \
1243 gen_ ## op(s, ot); \
1244 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1245 /* a loop would cause two single step exceptions if ECX = 1 \
1246 before rep string_insn */ \
1248 gen_op_jz_ecx(s->aflag, l2); \
1249 gen_jmp(s, cur_eip); \
1252 #define GEN_REPZ2(op) \
1253 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1254 target_ulong cur_eip, \
1255 target_ulong next_eip, \
1259 gen_update_cc_op(s); \
1260 l2 = gen_jz_ecx_string(s, next_eip); \
1261 gen_ ## op(s, ot); \
1262 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1263 gen_op_set_cc_op(CC_OP_SUBB + ot); \
1264 gen_jcc1(s, CC_OP_SUBB + ot, (JCC_Z << 1) | (nz ^ 1), l2); \
1266 gen_op_jz_ecx(s->aflag, l2); \
1267 gen_jmp(s, cur_eip); \
1278 static void gen_helper_fp_arith_ST0_FT0(int op
)
1281 case 0: gen_helper_fadd_ST0_FT0(); break;
1282 case 1: gen_helper_fmul_ST0_FT0(); break;
1283 case 2: gen_helper_fcom_ST0_FT0(); break;
1284 case 3: gen_helper_fcom_ST0_FT0(); break;
1285 case 4: gen_helper_fsub_ST0_FT0(); break;
1286 case 5: gen_helper_fsubr_ST0_FT0(); break;
1287 case 6: gen_helper_fdiv_ST0_FT0(); break;
1288 case 7: gen_helper_fdivr_ST0_FT0(); break;
1292 /* NOTE the exception in "r" op ordering */
1293 static void gen_helper_fp_arith_STN_ST0(int op
, int opreg
)
1295 TCGv_i32 tmp
= tcg_const_i32(opreg
);
1297 case 0: gen_helper_fadd_STN_ST0(tmp
); break;
1298 case 1: gen_helper_fmul_STN_ST0(tmp
); break;
1299 case 4: gen_helper_fsubr_STN_ST0(tmp
); break;
1300 case 5: gen_helper_fsub_STN_ST0(tmp
); break;
1301 case 6: gen_helper_fdivr_STN_ST0(tmp
); break;
1302 case 7: gen_helper_fdiv_STN_ST0(tmp
); break;
1306 /* if d == OR_TMP0, it means memory operand (address in A0) */
1307 static void gen_op(DisasContext
*s1
, int op
, int ot
, int d
)
1310 gen_op_mov_TN_reg(ot
, 0, d
);
1312 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1316 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1317 gen_op_set_cc_op(s1
->cc_op
);
1318 gen_compute_eflags_c(cpu_tmp4
);
1319 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1320 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1322 gen_op_mov_reg_T0(ot
, d
);
1324 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1325 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1326 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1327 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1328 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1329 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_ADDB
+ ot
);
1330 s1
->cc_op
= CC_OP_DYNAMIC
;
1333 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1334 gen_op_set_cc_op(s1
->cc_op
);
1335 gen_compute_eflags_c(cpu_tmp4
);
1336 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1337 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1339 gen_op_mov_reg_T0(ot
, d
);
1341 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1342 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1343 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1344 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1345 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1346 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_SUBB
+ ot
);
1347 s1
->cc_op
= CC_OP_DYNAMIC
;
1350 gen_op_addl_T0_T1();
1352 gen_op_mov_reg_T0(ot
, d
);
1354 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1355 gen_op_update2_cc();
1356 s1
->cc_op
= CC_OP_ADDB
+ ot
;
1359 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1361 gen_op_mov_reg_T0(ot
, d
);
1363 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1364 gen_op_update2_cc();
1365 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1369 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1371 gen_op_mov_reg_T0(ot
, d
);
1373 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1374 gen_op_update1_cc();
1375 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1378 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1380 gen_op_mov_reg_T0(ot
, d
);
1382 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1383 gen_op_update1_cc();
1384 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1387 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1389 gen_op_mov_reg_T0(ot
, d
);
1391 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1392 gen_op_update1_cc();
1393 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1396 gen_op_cmpl_T0_T1_cc();
1397 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1402 /* if d == OR_TMP0, it means memory operand (address in A0) */
1403 static void gen_inc(DisasContext
*s1
, int ot
, int d
, int c
)
1406 gen_op_mov_TN_reg(ot
, 0, d
);
1408 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1409 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1410 gen_op_set_cc_op(s1
->cc_op
);
1412 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], 1);
1413 s1
->cc_op
= CC_OP_INCB
+ ot
;
1415 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], -1);
1416 s1
->cc_op
= CC_OP_DECB
+ ot
;
1419 gen_op_mov_reg_T0(ot
, d
);
1421 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1422 gen_compute_eflags_c(cpu_cc_src
);
1423 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1426 static void gen_shift_rm_T1(DisasContext
*s
, int ot
, int op1
,
1427 int is_right
, int is_arith
)
1440 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1442 gen_op_mov_TN_reg(ot
, 0, op1
);
1444 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], mask
);
1446 tcg_gen_addi_tl(cpu_tmp5
, cpu_T
[1], -1);
1450 gen_exts(ot
, cpu_T
[0]);
1451 tcg_gen_sar_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1452 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1454 gen_extu(ot
, cpu_T
[0]);
1455 tcg_gen_shr_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1456 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1459 tcg_gen_shl_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1460 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1465 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1467 gen_op_mov_reg_T0(ot
, op1
);
1469 /* update eflags if non zero shift */
1470 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1471 gen_op_set_cc_op(s
->cc_op
);
1473 /* XXX: inefficient */
1474 t0
= tcg_temp_local_new();
1475 t1
= tcg_temp_local_new();
1477 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1478 tcg_gen_mov_tl(t1
, cpu_T3
);
1480 shift_label
= gen_new_label();
1481 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, shift_label
);
1483 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1484 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1486 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1488 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1490 gen_set_label(shift_label
);
1491 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1497 static void gen_shift_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1498 int is_right
, int is_arith
)
1509 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1511 gen_op_mov_TN_reg(ot
, 0, op1
);
1517 gen_exts(ot
, cpu_T
[0]);
1518 tcg_gen_sari_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1519 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], op2
);
1521 gen_extu(ot
, cpu_T
[0]);
1522 tcg_gen_shri_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1523 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], op2
);
1526 tcg_gen_shli_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1527 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], op2
);
1533 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1535 gen_op_mov_reg_T0(ot
, op1
);
1537 /* update eflags if non zero shift */
1539 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
1540 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1542 s
->cc_op
= CC_OP_SARB
+ ot
;
1544 s
->cc_op
= CC_OP_SHLB
+ ot
;
1548 static inline void tcg_gen_lshift(TCGv ret
, TCGv arg1
, target_long arg2
)
1551 tcg_gen_shli_tl(ret
, arg1
, arg2
);
1553 tcg_gen_shri_tl(ret
, arg1
, -arg2
);
1556 static void gen_rot_rm_T1(DisasContext
*s
, int ot
, int op1
,
1560 int label1
, label2
, data_bits
;
1561 TCGv t0
, t1
, t2
, a0
;
1563 /* XXX: inefficient, but we must use local temps */
1564 t0
= tcg_temp_local_new();
1565 t1
= tcg_temp_local_new();
1566 t2
= tcg_temp_local_new();
1567 a0
= tcg_temp_local_new();
1575 if (op1
== OR_TMP0
) {
1576 tcg_gen_mov_tl(a0
, cpu_A0
);
1577 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1579 gen_op_mov_v_reg(ot
, t0
, op1
);
1582 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1584 tcg_gen_andi_tl(t1
, t1
, mask
);
1586 /* Must test zero case to avoid using undefined behaviour in TCG
1588 label1
= gen_new_label();
1589 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label1
);
1592 tcg_gen_andi_tl(cpu_tmp0
, t1
, (1 << (3 + ot
)) - 1);
1594 tcg_gen_mov_tl(cpu_tmp0
, t1
);
1597 tcg_gen_mov_tl(t2
, t0
);
1599 data_bits
= 8 << ot
;
1600 /* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
1601 fix TCG definition) */
1603 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1604 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1605 tcg_gen_shl_tl(t0
, t0
, cpu_tmp0
);
1607 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1608 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1609 tcg_gen_shr_tl(t0
, t0
, cpu_tmp0
);
1611 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1613 gen_set_label(label1
);
1615 if (op1
== OR_TMP0
) {
1616 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1618 gen_op_mov_reg_v(ot
, op1
, t0
);
1622 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1623 gen_op_set_cc_op(s
->cc_op
);
1625 label2
= gen_new_label();
1626 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label2
);
1628 gen_compute_eflags(cpu_cc_src
);
1629 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1630 tcg_gen_xor_tl(cpu_tmp0
, t2
, t0
);
1631 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1632 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1633 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1635 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1637 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1638 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1640 tcg_gen_discard_tl(cpu_cc_dst
);
1641 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1643 gen_set_label(label2
);
1644 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1652 static void gen_rot_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1659 /* XXX: inefficient, but we must use local temps */
1660 t0
= tcg_temp_local_new();
1661 t1
= tcg_temp_local_new();
1662 a0
= tcg_temp_local_new();
1670 if (op1
== OR_TMP0
) {
1671 tcg_gen_mov_tl(a0
, cpu_A0
);
1672 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1674 gen_op_mov_v_reg(ot
, t0
, op1
);
1678 tcg_gen_mov_tl(t1
, t0
);
1681 data_bits
= 8 << ot
;
1683 int shift
= op2
& ((1 << (3 + ot
)) - 1);
1685 tcg_gen_shri_tl(cpu_tmp4
, t0
, shift
);
1686 tcg_gen_shli_tl(t0
, t0
, data_bits
- shift
);
1689 tcg_gen_shli_tl(cpu_tmp4
, t0
, shift
);
1690 tcg_gen_shri_tl(t0
, t0
, data_bits
- shift
);
1692 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1696 if (op1
== OR_TMP0
) {
1697 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1699 gen_op_mov_reg_v(ot
, op1
, t0
);
1704 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1705 gen_op_set_cc_op(s
->cc_op
);
1707 gen_compute_eflags(cpu_cc_src
);
1708 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1709 tcg_gen_xor_tl(cpu_tmp0
, t1
, t0
);
1710 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1711 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1712 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1714 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1716 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1717 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1719 tcg_gen_discard_tl(cpu_cc_dst
);
1720 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1721 s
->cc_op
= CC_OP_EFLAGS
;
1729 /* XXX: add faster immediate = 1 case */
1730 static void gen_rotc_rm_T1(DisasContext
*s
, int ot
, int op1
,
1735 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1736 gen_op_set_cc_op(s
->cc_op
);
1740 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1742 gen_op_mov_TN_reg(ot
, 0, op1
);
1746 case 0: gen_helper_rcrb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1747 case 1: gen_helper_rcrw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1748 case 2: gen_helper_rcrl(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1749 #ifdef TARGET_X86_64
1750 case 3: gen_helper_rcrq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1755 case 0: gen_helper_rclb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1756 case 1: gen_helper_rclw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1757 case 2: gen_helper_rcll(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1758 #ifdef TARGET_X86_64
1759 case 3: gen_helper_rclq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1765 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1767 gen_op_mov_reg_T0(ot
, op1
);
1770 label1
= gen_new_label();
1771 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_cc_tmp
, -1, label1
);
1773 tcg_gen_mov_tl(cpu_cc_src
, cpu_cc_tmp
);
1774 tcg_gen_discard_tl(cpu_cc_dst
);
1775 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1777 gen_set_label(label1
);
1778 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1781 /* XXX: add faster immediate case */
1782 static void gen_shiftd_rm_T1_T3(DisasContext
*s
, int ot
, int op1
,
1785 int label1
, label2
, data_bits
;
1787 TCGv t0
, t1
, t2
, a0
;
1789 t0
= tcg_temp_local_new();
1790 t1
= tcg_temp_local_new();
1791 t2
= tcg_temp_local_new();
1792 a0
= tcg_temp_local_new();
1800 if (op1
== OR_TMP0
) {
1801 tcg_gen_mov_tl(a0
, cpu_A0
);
1802 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1804 gen_op_mov_v_reg(ot
, t0
, op1
);
1807 tcg_gen_andi_tl(cpu_T3
, cpu_T3
, mask
);
1809 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1810 tcg_gen_mov_tl(t2
, cpu_T3
);
1812 /* Must test zero case to avoid using undefined behaviour in TCG
1814 label1
= gen_new_label();
1815 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
1817 tcg_gen_addi_tl(cpu_tmp5
, t2
, -1);
1818 if (ot
== OT_WORD
) {
1819 /* Note: we implement the Intel behaviour for shift count > 16 */
1821 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1822 tcg_gen_shli_tl(cpu_tmp0
, t1
, 16);
1823 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1824 tcg_gen_ext32u_tl(t0
, t0
);
1826 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1828 /* only needed if count > 16, but a test would complicate */
1829 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1830 tcg_gen_shl_tl(cpu_tmp0
, t0
, cpu_tmp5
);
1832 tcg_gen_shr_tl(t0
, t0
, t2
);
1834 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1836 /* XXX: not optimal */
1837 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1838 tcg_gen_shli_tl(t1
, t1
, 16);
1839 tcg_gen_or_tl(t1
, t1
, t0
);
1840 tcg_gen_ext32u_tl(t1
, t1
);
1842 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1843 tcg_gen_subfi_tl(cpu_tmp0
, 32, cpu_tmp5
);
1844 tcg_gen_shr_tl(cpu_tmp5
, t1
, cpu_tmp0
);
1845 tcg_gen_or_tl(cpu_tmp4
, cpu_tmp4
, cpu_tmp5
);
1847 tcg_gen_shl_tl(t0
, t0
, t2
);
1848 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1849 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1850 tcg_gen_or_tl(t0
, t0
, t1
);
1853 data_bits
= 8 << ot
;
1856 tcg_gen_ext32u_tl(t0
, t0
);
1858 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1860 tcg_gen_shr_tl(t0
, t0
, t2
);
1861 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1862 tcg_gen_shl_tl(t1
, t1
, cpu_tmp5
);
1863 tcg_gen_or_tl(t0
, t0
, t1
);
1867 tcg_gen_ext32u_tl(t1
, t1
);
1869 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1871 tcg_gen_shl_tl(t0
, t0
, t2
);
1872 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1873 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1874 tcg_gen_or_tl(t0
, t0
, t1
);
1877 tcg_gen_mov_tl(t1
, cpu_tmp4
);
1879 gen_set_label(label1
);
1881 if (op1
== OR_TMP0
) {
1882 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1884 gen_op_mov_reg_v(ot
, op1
, t0
);
1888 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1889 gen_op_set_cc_op(s
->cc_op
);
1891 label2
= gen_new_label();
1892 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label2
);
1894 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1895 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1897 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1899 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1901 gen_set_label(label2
);
1902 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1910 static void gen_shift(DisasContext
*s1
, int op
, int ot
, int d
, int s
)
1913 gen_op_mov_TN_reg(ot
, 1, s
);
1916 gen_rot_rm_T1(s1
, ot
, d
, 0);
1919 gen_rot_rm_T1(s1
, ot
, d
, 1);
1923 gen_shift_rm_T1(s1
, ot
, d
, 0, 0);
1926 gen_shift_rm_T1(s1
, ot
, d
, 1, 0);
1929 gen_shift_rm_T1(s1
, ot
, d
, 1, 1);
1932 gen_rotc_rm_T1(s1
, ot
, d
, 0);
1935 gen_rotc_rm_T1(s1
, ot
, d
, 1);
1940 static void gen_shifti(DisasContext
*s1
, int op
, int ot
, int d
, int c
)
1944 gen_rot_rm_im(s1
, ot
, d
, c
, 0);
1947 gen_rot_rm_im(s1
, ot
, d
, c
, 1);
1951 gen_shift_rm_im(s1
, ot
, d
, c
, 0, 0);
1954 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 0);
1957 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 1);
1960 /* currently not optimized */
1961 gen_op_movl_T1_im(c
);
1962 gen_shift(s1
, op
, ot
, d
, OR_TMP1
);
1967 static void gen_lea_modrm(DisasContext
*s
, int modrm
, int *reg_ptr
, int *offset_ptr
)
1975 int mod
, rm
, code
, override
, must_add_seg
;
1977 override
= s
->override
;
1978 must_add_seg
= s
->addseg
;
1981 mod
= (modrm
>> 6) & 3;
1993 code
= ldub_code(s
->pc
++);
1994 scale
= (code
>> 6) & 3;
1995 index
= ((code
>> 3) & 7) | REX_X(s
);
2002 if ((base
& 7) == 5) {
2004 disp
= (int32_t)ldl_code(s
->pc
);
2006 if (CODE64(s
) && !havesib
) {
2007 disp
+= s
->pc
+ s
->rip_offset
;
2014 disp
= (int8_t)ldub_code(s
->pc
++);
2018 disp
= ldl_code(s
->pc
);
2024 /* for correct popl handling with esp */
2025 if (base
== 4 && s
->popl_esp_hack
)
2026 disp
+= s
->popl_esp_hack
;
2027 #ifdef TARGET_X86_64
2028 if (s
->aflag
== 2) {
2029 gen_op_movq_A0_reg(base
);
2031 gen_op_addq_A0_im(disp
);
2036 gen_op_movl_A0_reg(base
);
2038 gen_op_addl_A0_im(disp
);
2041 #ifdef TARGET_X86_64
2042 if (s
->aflag
== 2) {
2043 gen_op_movq_A0_im(disp
);
2047 gen_op_movl_A0_im(disp
);
2050 /* XXX: index == 4 is always invalid */
2051 if (havesib
&& (index
!= 4 || scale
!= 0)) {
2052 #ifdef TARGET_X86_64
2053 if (s
->aflag
== 2) {
2054 gen_op_addq_A0_reg_sN(scale
, index
);
2058 gen_op_addl_A0_reg_sN(scale
, index
);
2063 if (base
== R_EBP
|| base
== R_ESP
)
2068 #ifdef TARGET_X86_64
2069 if (s
->aflag
== 2) {
2070 gen_op_addq_A0_seg(override
);
2074 gen_op_addl_A0_seg(override
);
2081 disp
= lduw_code(s
->pc
);
2083 gen_op_movl_A0_im(disp
);
2084 rm
= 0; /* avoid SS override */
2091 disp
= (int8_t)ldub_code(s
->pc
++);
2095 disp
= lduw_code(s
->pc
);
2101 gen_op_movl_A0_reg(R_EBX
);
2102 gen_op_addl_A0_reg_sN(0, R_ESI
);
2105 gen_op_movl_A0_reg(R_EBX
);
2106 gen_op_addl_A0_reg_sN(0, R_EDI
);
2109 gen_op_movl_A0_reg(R_EBP
);
2110 gen_op_addl_A0_reg_sN(0, R_ESI
);
2113 gen_op_movl_A0_reg(R_EBP
);
2114 gen_op_addl_A0_reg_sN(0, R_EDI
);
2117 gen_op_movl_A0_reg(R_ESI
);
2120 gen_op_movl_A0_reg(R_EDI
);
2123 gen_op_movl_A0_reg(R_EBP
);
2127 gen_op_movl_A0_reg(R_EBX
);
2131 gen_op_addl_A0_im(disp
);
2132 gen_op_andl_A0_ffff();
2136 if (rm
== 2 || rm
== 3 || rm
== 6)
2141 gen_op_addl_A0_seg(override
);
2151 static void gen_nop_modrm(DisasContext
*s
, int modrm
)
2153 int mod
, rm
, base
, code
;
2155 mod
= (modrm
>> 6) & 3;
2165 code
= ldub_code(s
->pc
++);
2201 /* used for LEA and MOV AX, mem */
2202 static void gen_add_A0_ds_seg(DisasContext
*s
)
2204 int override
, must_add_seg
;
2205 must_add_seg
= s
->addseg
;
2207 if (s
->override
>= 0) {
2208 override
= s
->override
;
2214 #ifdef TARGET_X86_64
2216 gen_op_addq_A0_seg(override
);
2220 gen_op_addl_A0_seg(override
);
2225 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
2227 static void gen_ldst_modrm(DisasContext
*s
, int modrm
, int ot
, int reg
, int is_store
)
2229 int mod
, rm
, opreg
, disp
;
2231 mod
= (modrm
>> 6) & 3;
2232 rm
= (modrm
& 7) | REX_B(s
);
2236 gen_op_mov_TN_reg(ot
, 0, reg
);
2237 gen_op_mov_reg_T0(ot
, rm
);
2239 gen_op_mov_TN_reg(ot
, 0, rm
);
2241 gen_op_mov_reg_T0(ot
, reg
);
2244 gen_lea_modrm(s
, modrm
, &opreg
, &disp
);
2247 gen_op_mov_TN_reg(ot
, 0, reg
);
2248 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2250 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
2252 gen_op_mov_reg_T0(ot
, reg
);
2257 static inline uint32_t insn_get(DisasContext
*s
, int ot
)
2263 ret
= ldub_code(s
->pc
);
2267 ret
= lduw_code(s
->pc
);
2272 ret
= ldl_code(s
->pc
);
2279 static inline int insn_const_size(unsigned int ot
)
2287 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong eip
)
2289 TranslationBlock
*tb
;
2292 pc
= s
->cs_base
+ eip
;
2294 /* NOTE: we handle the case where the TB spans two pages here */
2295 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) ||
2296 (pc
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
)) {
2297 /* jump to same page: we can use a direct jump */
2298 tcg_gen_goto_tb(tb_num
);
2300 tcg_gen_exit_tb((long)tb
+ tb_num
);
2302 /* jump to another page: currently not optimized */
2308 static inline void gen_jcc(DisasContext
*s
, int b
,
2309 target_ulong val
, target_ulong next_eip
)
2314 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2315 gen_op_set_cc_op(s
->cc_op
);
2316 s
->cc_op
= CC_OP_DYNAMIC
;
2319 l1
= gen_new_label();
2320 gen_jcc1(s
, cc_op
, b
, l1
);
2322 gen_goto_tb(s
, 0, next_eip
);
2325 gen_goto_tb(s
, 1, val
);
2329 l1
= gen_new_label();
2330 l2
= gen_new_label();
2331 gen_jcc1(s
, cc_op
, b
, l1
);
2333 gen_jmp_im(next_eip
);
2343 static void gen_setcc(DisasContext
*s
, int b
)
2345 int inv
, jcc_op
, l1
;
2348 if (is_fast_jcc_case(s
, b
)) {
2349 /* nominal case: we use a jump */
2350 /* XXX: make it faster by adding new instructions in TCG */
2351 t0
= tcg_temp_local_new();
2352 tcg_gen_movi_tl(t0
, 0);
2353 l1
= gen_new_label();
2354 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
2355 tcg_gen_movi_tl(t0
, 1);
2357 tcg_gen_mov_tl(cpu_T
[0], t0
);
2360 /* slow case: it is more efficient not to generate a jump,
2361 although it is questionnable whether this optimization is
2364 jcc_op
= (b
>> 1) & 7;
2365 gen_setcc_slow_T0(s
, jcc_op
);
2367 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
2372 static inline void gen_op_movl_T0_seg(int seg_reg
)
2374 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
2375 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2378 static inline void gen_op_movl_seg_T0_vm(int seg_reg
)
2380 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
2381 tcg_gen_st32_tl(cpu_T
[0], cpu_env
,
2382 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2383 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], 4);
2384 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
2385 offsetof(CPUX86State
,segs
[seg_reg
].base
));
2388 /* move T0 to seg_reg and compute if the CPU state may change. Never
2389 call this function with seg_reg == R_CS */
2390 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
2392 if (s
->pe
&& !s
->vm86
) {
2393 /* XXX: optimize by finding processor state dynamically */
2394 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2395 gen_op_set_cc_op(s
->cc_op
);
2396 gen_jmp_im(cur_eip
);
2397 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
2398 gen_helper_load_seg(tcg_const_i32(seg_reg
), cpu_tmp2_i32
);
2399 /* abort translation because the addseg value may change or
2400 because ss32 may change. For R_SS, translation must always
2401 stop as a special handling must be done to disable hardware
2402 interrupts for the next instruction */
2403 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
2406 gen_op_movl_seg_T0_vm(seg_reg
);
2407 if (seg_reg
== R_SS
)
2412 static inline int svm_is_rep(int prefixes
)
2414 return ((prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) ? 8 : 0);
2418 gen_svm_check_intercept_param(DisasContext
*s
, target_ulong pc_start
,
2419 uint32_t type
, uint64_t param
)
2421 /* no SVM activated; fast case */
2422 if (likely(!(s
->flags
& HF_SVMI_MASK
)))
2424 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2425 gen_op_set_cc_op(s
->cc_op
);
2426 gen_jmp_im(pc_start
- s
->cs_base
);
2427 gen_helper_svm_check_intercept_param(tcg_const_i32(type
),
2428 tcg_const_i64(param
));
2432 gen_svm_check_intercept(DisasContext
*s
, target_ulong pc_start
, uint64_t type
)
2434 gen_svm_check_intercept_param(s
, pc_start
, type
, 0);
2437 static inline void gen_stack_update(DisasContext
*s
, int addend
)
2439 #ifdef TARGET_X86_64
2441 gen_op_add_reg_im(2, R_ESP
, addend
);
2445 gen_op_add_reg_im(1, R_ESP
, addend
);
2447 gen_op_add_reg_im(0, R_ESP
, addend
);
2451 /* generate a push. It depends on ss32, addseg and dflag */
2452 static void gen_push_T0(DisasContext
*s
)
2454 #ifdef TARGET_X86_64
2456 gen_op_movq_A0_reg(R_ESP
);
2458 gen_op_addq_A0_im(-8);
2459 gen_op_st_T0_A0(OT_QUAD
+ s
->mem_index
);
2461 gen_op_addq_A0_im(-2);
2462 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2464 gen_op_mov_reg_A0(2, R_ESP
);
2468 gen_op_movl_A0_reg(R_ESP
);
2470 gen_op_addl_A0_im(-2);
2472 gen_op_addl_A0_im(-4);
2475 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2476 gen_op_addl_A0_seg(R_SS
);
2479 gen_op_andl_A0_ffff();
2480 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2481 gen_op_addl_A0_seg(R_SS
);
2483 gen_op_st_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2484 if (s
->ss32
&& !s
->addseg
)
2485 gen_op_mov_reg_A0(1, R_ESP
);
2487 gen_op_mov_reg_T1(s
->ss32
+ 1, R_ESP
);
2491 /* generate a push. It depends on ss32, addseg and dflag */
2492 /* slower version for T1, only used for call Ev */
2493 static void gen_push_T1(DisasContext
*s
)
2495 #ifdef TARGET_X86_64
2497 gen_op_movq_A0_reg(R_ESP
);
2499 gen_op_addq_A0_im(-8);
2500 gen_op_st_T1_A0(OT_QUAD
+ s
->mem_index
);
2502 gen_op_addq_A0_im(-2);
2503 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2505 gen_op_mov_reg_A0(2, R_ESP
);
2509 gen_op_movl_A0_reg(R_ESP
);
2511 gen_op_addl_A0_im(-2);
2513 gen_op_addl_A0_im(-4);
2516 gen_op_addl_A0_seg(R_SS
);
2519 gen_op_andl_A0_ffff();
2520 gen_op_addl_A0_seg(R_SS
);
2522 gen_op_st_T1_A0(s
->dflag
+ 1 + s
->mem_index
);
2524 if (s
->ss32
&& !s
->addseg
)
2525 gen_op_mov_reg_A0(1, R_ESP
);
2527 gen_stack_update(s
, (-2) << s
->dflag
);
2531 /* two step pop is necessary for precise exceptions */
2532 static void gen_pop_T0(DisasContext
*s
)
2534 #ifdef TARGET_X86_64
2536 gen_op_movq_A0_reg(R_ESP
);
2537 gen_op_ld_T0_A0((s
->dflag
? OT_QUAD
: OT_WORD
) + s
->mem_index
);
2541 gen_op_movl_A0_reg(R_ESP
);
2544 gen_op_addl_A0_seg(R_SS
);
2546 gen_op_andl_A0_ffff();
2547 gen_op_addl_A0_seg(R_SS
);
2549 gen_op_ld_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2553 static void gen_pop_update(DisasContext
*s
)
2555 #ifdef TARGET_X86_64
2556 if (CODE64(s
) && s
->dflag
) {
2557 gen_stack_update(s
, 8);
2561 gen_stack_update(s
, 2 << s
->dflag
);
2565 static void gen_stack_A0(DisasContext
*s
)
2567 gen_op_movl_A0_reg(R_ESP
);
2569 gen_op_andl_A0_ffff();
2570 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2572 gen_op_addl_A0_seg(R_SS
);
2575 /* NOTE: wrap around in 16 bit not fully handled */
2576 static void gen_pusha(DisasContext
*s
)
2579 gen_op_movl_A0_reg(R_ESP
);
2580 gen_op_addl_A0_im(-16 << s
->dflag
);
2582 gen_op_andl_A0_ffff();
2583 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2585 gen_op_addl_A0_seg(R_SS
);
2586 for(i
= 0;i
< 8; i
++) {
2587 gen_op_mov_TN_reg(OT_LONG
, 0, 7 - i
);
2588 gen_op_st_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2589 gen_op_addl_A0_im(2 << s
->dflag
);
2591 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2594 /* NOTE: wrap around in 16 bit not fully handled */
2595 static void gen_popa(DisasContext
*s
)
2598 gen_op_movl_A0_reg(R_ESP
);
2600 gen_op_andl_A0_ffff();
2601 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2602 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], 16 << s
->dflag
);
2604 gen_op_addl_A0_seg(R_SS
);
2605 for(i
= 0;i
< 8; i
++) {
2606 /* ESP is not reloaded */
2608 gen_op_ld_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2609 gen_op_mov_reg_T0(OT_WORD
+ s
->dflag
, 7 - i
);
2611 gen_op_addl_A0_im(2 << s
->dflag
);
2613 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2616 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2621 #ifdef TARGET_X86_64
2623 ot
= s
->dflag
? OT_QUAD
: OT_WORD
;
2626 gen_op_movl_A0_reg(R_ESP
);
2627 gen_op_addq_A0_im(-opsize
);
2628 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2631 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2632 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2634 /* XXX: must save state */
2635 gen_helper_enter64_level(tcg_const_i32(level
),
2636 tcg_const_i32((ot
== OT_QUAD
)),
2639 gen_op_mov_reg_T1(ot
, R_EBP
);
2640 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2641 gen_op_mov_reg_T1(OT_QUAD
, R_ESP
);
2645 ot
= s
->dflag
+ OT_WORD
;
2646 opsize
= 2 << s
->dflag
;
2648 gen_op_movl_A0_reg(R_ESP
);
2649 gen_op_addl_A0_im(-opsize
);
2651 gen_op_andl_A0_ffff();
2652 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2654 gen_op_addl_A0_seg(R_SS
);
2656 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2657 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2659 /* XXX: must save state */
2660 gen_helper_enter_level(tcg_const_i32(level
),
2661 tcg_const_i32(s
->dflag
),
2664 gen_op_mov_reg_T1(ot
, R_EBP
);
2665 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2666 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2670 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2672 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2673 gen_op_set_cc_op(s
->cc_op
);
2674 gen_jmp_im(cur_eip
);
2675 gen_helper_raise_exception(tcg_const_i32(trapno
));
2679 /* an interrupt is different from an exception because of the
2681 static void gen_interrupt(DisasContext
*s
, int intno
,
2682 target_ulong cur_eip
, target_ulong next_eip
)
2684 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2685 gen_op_set_cc_op(s
->cc_op
);
2686 gen_jmp_im(cur_eip
);
2687 gen_helper_raise_interrupt(tcg_const_i32(intno
),
2688 tcg_const_i32(next_eip
- cur_eip
));
2692 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2694 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2695 gen_op_set_cc_op(s
->cc_op
);
2696 gen_jmp_im(cur_eip
);
2701 /* generate a generic end of block. Trace exception is also generated
2703 static void gen_eob(DisasContext
*s
)
2705 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2706 gen_op_set_cc_op(s
->cc_op
);
2707 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2708 gen_helper_reset_inhibit_irq();
2710 if (s
->tb
->flags
& HF_RF_MASK
) {
2711 gen_helper_reset_rf();
2713 if (s
->singlestep_enabled
) {
2716 gen_helper_single_step();
2723 /* generate a jump to eip. No segment change must happen before as a
2724 direct call to the next block may occur */
2725 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2728 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2729 gen_op_set_cc_op(s
->cc_op
);
2730 s
->cc_op
= CC_OP_DYNAMIC
;
2732 gen_goto_tb(s
, tb_num
, eip
);
2740 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2742 gen_jmp_tb(s
, eip
, 0);
2745 static inline void gen_ldq_env_A0(int idx
, int offset
)
2747 int mem_index
= (idx
>> 2) - 1;
2748 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2749 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2752 static inline void gen_stq_env_A0(int idx
, int offset
)
2754 int mem_index
= (idx
>> 2) - 1;
2755 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2756 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2759 static inline void gen_ldo_env_A0(int idx
, int offset
)
2761 int mem_index
= (idx
>> 2) - 1;
2762 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2763 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2764 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2765 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2766 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2769 static inline void gen_sto_env_A0(int idx
, int offset
)
2771 int mem_index
= (idx
>> 2) - 1;
2772 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2773 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2774 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2775 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2776 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2779 static inline void gen_op_movo(int d_offset
, int s_offset
)
2781 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2782 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2783 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
+ 8);
2784 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
+ 8);
2787 static inline void gen_op_movq(int d_offset
, int s_offset
)
2789 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2790 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2793 static inline void gen_op_movl(int d_offset
, int s_offset
)
2795 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
, s_offset
);
2796 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, d_offset
);
2799 static inline void gen_op_movq_env_0(int d_offset
)
2801 tcg_gen_movi_i64(cpu_tmp1_i64
, 0);
2802 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2805 #define SSE_SPECIAL ((void *)1)
2806 #define SSE_DUMMY ((void *)2)
2808 #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm }
2809 #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \
2810 gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, }
2812 static void *sse_op_table1
[256][4] = {
2813 /* 3DNow! extensions */
2814 [0x0e] = { SSE_DUMMY
}, /* femms */
2815 [0x0f] = { SSE_DUMMY
}, /* pf... */
2816 /* pure SSE operations */
2817 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2818 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2819 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd, movsldup, movddup */
2820 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2821 [0x14] = { gen_helper_punpckldq_xmm
, gen_helper_punpcklqdq_xmm
},
2822 [0x15] = { gen_helper_punpckhdq_xmm
, gen_helper_punpckhqdq_xmm
},
2823 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2824 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2826 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2827 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2828 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2829 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd, movntss, movntsd */
2830 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2831 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2832 [0x2e] = { gen_helper_ucomiss
, gen_helper_ucomisd
},
2833 [0x2f] = { gen_helper_comiss
, gen_helper_comisd
},
2834 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2835 [0x51] = SSE_FOP(sqrt
),
2836 [0x52] = { gen_helper_rsqrtps
, NULL
, gen_helper_rsqrtss
, NULL
},
2837 [0x53] = { gen_helper_rcpps
, NULL
, gen_helper_rcpss
, NULL
},
2838 [0x54] = { gen_helper_pand_xmm
, gen_helper_pand_xmm
}, /* andps, andpd */
2839 [0x55] = { gen_helper_pandn_xmm
, gen_helper_pandn_xmm
}, /* andnps, andnpd */
2840 [0x56] = { gen_helper_por_xmm
, gen_helper_por_xmm
}, /* orps, orpd */
2841 [0x57] = { gen_helper_pxor_xmm
, gen_helper_pxor_xmm
}, /* xorps, xorpd */
2842 [0x58] = SSE_FOP(add
),
2843 [0x59] = SSE_FOP(mul
),
2844 [0x5a] = { gen_helper_cvtps2pd
, gen_helper_cvtpd2ps
,
2845 gen_helper_cvtss2sd
, gen_helper_cvtsd2ss
},
2846 [0x5b] = { gen_helper_cvtdq2ps
, gen_helper_cvtps2dq
, gen_helper_cvttps2dq
},
2847 [0x5c] = SSE_FOP(sub
),
2848 [0x5d] = SSE_FOP(min
),
2849 [0x5e] = SSE_FOP(div
),
2850 [0x5f] = SSE_FOP(max
),
2852 [0xc2] = SSE_FOP(cmpeq
),
2853 [0xc6] = { gen_helper_shufps
, gen_helper_shufpd
},
2855 [0x38] = { SSE_SPECIAL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2856 [0x3a] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2858 /* MMX ops and their SSE extensions */
2859 [0x60] = MMX_OP2(punpcklbw
),
2860 [0x61] = MMX_OP2(punpcklwd
),
2861 [0x62] = MMX_OP2(punpckldq
),
2862 [0x63] = MMX_OP2(packsswb
),
2863 [0x64] = MMX_OP2(pcmpgtb
),
2864 [0x65] = MMX_OP2(pcmpgtw
),
2865 [0x66] = MMX_OP2(pcmpgtl
),
2866 [0x67] = MMX_OP2(packuswb
),
2867 [0x68] = MMX_OP2(punpckhbw
),
2868 [0x69] = MMX_OP2(punpckhwd
),
2869 [0x6a] = MMX_OP2(punpckhdq
),
2870 [0x6b] = MMX_OP2(packssdw
),
2871 [0x6c] = { NULL
, gen_helper_punpcklqdq_xmm
},
2872 [0x6d] = { NULL
, gen_helper_punpckhqdq_xmm
},
2873 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2874 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2875 [0x70] = { gen_helper_pshufw_mmx
,
2876 gen_helper_pshufd_xmm
,
2877 gen_helper_pshufhw_xmm
,
2878 gen_helper_pshuflw_xmm
},
2879 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2880 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2881 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2882 [0x74] = MMX_OP2(pcmpeqb
),
2883 [0x75] = MMX_OP2(pcmpeqw
),
2884 [0x76] = MMX_OP2(pcmpeql
),
2885 [0x77] = { SSE_DUMMY
}, /* emms */
2886 [0x78] = { NULL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* extrq_i, insertq_i */
2887 [0x79] = { NULL
, gen_helper_extrq_r
, NULL
, gen_helper_insertq_r
},
2888 [0x7c] = { NULL
, gen_helper_haddpd
, NULL
, gen_helper_haddps
},
2889 [0x7d] = { NULL
, gen_helper_hsubpd
, NULL
, gen_helper_hsubps
},
2890 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2891 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2892 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2893 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2894 [0xd0] = { NULL
, gen_helper_addsubpd
, NULL
, gen_helper_addsubps
},
2895 [0xd1] = MMX_OP2(psrlw
),
2896 [0xd2] = MMX_OP2(psrld
),
2897 [0xd3] = MMX_OP2(psrlq
),
2898 [0xd4] = MMX_OP2(paddq
),
2899 [0xd5] = MMX_OP2(pmullw
),
2900 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2901 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2902 [0xd8] = MMX_OP2(psubusb
),
2903 [0xd9] = MMX_OP2(psubusw
),
2904 [0xda] = MMX_OP2(pminub
),
2905 [0xdb] = MMX_OP2(pand
),
2906 [0xdc] = MMX_OP2(paddusb
),
2907 [0xdd] = MMX_OP2(paddusw
),
2908 [0xde] = MMX_OP2(pmaxub
),
2909 [0xdf] = MMX_OP2(pandn
),
2910 [0xe0] = MMX_OP2(pavgb
),
2911 [0xe1] = MMX_OP2(psraw
),
2912 [0xe2] = MMX_OP2(psrad
),
2913 [0xe3] = MMX_OP2(pavgw
),
2914 [0xe4] = MMX_OP2(pmulhuw
),
2915 [0xe5] = MMX_OP2(pmulhw
),
2916 [0xe6] = { NULL
, gen_helper_cvttpd2dq
, gen_helper_cvtdq2pd
, gen_helper_cvtpd2dq
},
2917 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2918 [0xe8] = MMX_OP2(psubsb
),
2919 [0xe9] = MMX_OP2(psubsw
),
2920 [0xea] = MMX_OP2(pminsw
),
2921 [0xeb] = MMX_OP2(por
),
2922 [0xec] = MMX_OP2(paddsb
),
2923 [0xed] = MMX_OP2(paddsw
),
2924 [0xee] = MMX_OP2(pmaxsw
),
2925 [0xef] = MMX_OP2(pxor
),
2926 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu */
2927 [0xf1] = MMX_OP2(psllw
),
2928 [0xf2] = MMX_OP2(pslld
),
2929 [0xf3] = MMX_OP2(psllq
),
2930 [0xf4] = MMX_OP2(pmuludq
),
2931 [0xf5] = MMX_OP2(pmaddwd
),
2932 [0xf6] = MMX_OP2(psadbw
),
2933 [0xf7] = MMX_OP2(maskmov
),
2934 [0xf8] = MMX_OP2(psubb
),
2935 [0xf9] = MMX_OP2(psubw
),
2936 [0xfa] = MMX_OP2(psubl
),
2937 [0xfb] = MMX_OP2(psubq
),
2938 [0xfc] = MMX_OP2(paddb
),
2939 [0xfd] = MMX_OP2(paddw
),
2940 [0xfe] = MMX_OP2(paddl
),
2943 static void *sse_op_table2
[3 * 8][2] = {
2944 [0 + 2] = MMX_OP2(psrlw
),
2945 [0 + 4] = MMX_OP2(psraw
),
2946 [0 + 6] = MMX_OP2(psllw
),
2947 [8 + 2] = MMX_OP2(psrld
),
2948 [8 + 4] = MMX_OP2(psrad
),
2949 [8 + 6] = MMX_OP2(pslld
),
2950 [16 + 2] = MMX_OP2(psrlq
),
2951 [16 + 3] = { NULL
, gen_helper_psrldq_xmm
},
2952 [16 + 6] = MMX_OP2(psllq
),
2953 [16 + 7] = { NULL
, gen_helper_pslldq_xmm
},
2956 static void *sse_op_table3
[4 * 3] = {
2957 gen_helper_cvtsi2ss
,
2958 gen_helper_cvtsi2sd
,
2959 X86_64_ONLY(gen_helper_cvtsq2ss
),
2960 X86_64_ONLY(gen_helper_cvtsq2sd
),
2962 gen_helper_cvttss2si
,
2963 gen_helper_cvttsd2si
,
2964 X86_64_ONLY(gen_helper_cvttss2sq
),
2965 X86_64_ONLY(gen_helper_cvttsd2sq
),
2967 gen_helper_cvtss2si
,
2968 gen_helper_cvtsd2si
,
2969 X86_64_ONLY(gen_helper_cvtss2sq
),
2970 X86_64_ONLY(gen_helper_cvtsd2sq
),
2973 static void *sse_op_table4
[8][4] = {
2984 static void *sse_op_table5
[256] = {
2985 [0x0c] = gen_helper_pi2fw
,
2986 [0x0d] = gen_helper_pi2fd
,
2987 [0x1c] = gen_helper_pf2iw
,
2988 [0x1d] = gen_helper_pf2id
,
2989 [0x8a] = gen_helper_pfnacc
,
2990 [0x8e] = gen_helper_pfpnacc
,
2991 [0x90] = gen_helper_pfcmpge
,
2992 [0x94] = gen_helper_pfmin
,
2993 [0x96] = gen_helper_pfrcp
,
2994 [0x97] = gen_helper_pfrsqrt
,
2995 [0x9a] = gen_helper_pfsub
,
2996 [0x9e] = gen_helper_pfadd
,
2997 [0xa0] = gen_helper_pfcmpgt
,
2998 [0xa4] = gen_helper_pfmax
,
2999 [0xa6] = gen_helper_movq
, /* pfrcpit1; no need to actually increase precision */
3000 [0xa7] = gen_helper_movq
, /* pfrsqit1 */
3001 [0xaa] = gen_helper_pfsubr
,
3002 [0xae] = gen_helper_pfacc
,
3003 [0xb0] = gen_helper_pfcmpeq
,
3004 [0xb4] = gen_helper_pfmul
,
3005 [0xb6] = gen_helper_movq
, /* pfrcpit2 */
3006 [0xb7] = gen_helper_pmulhrw_mmx
,
3007 [0xbb] = gen_helper_pswapd
,
3008 [0xbf] = gen_helper_pavgb_mmx
/* pavgusb */
3011 struct sse_op_helper_s
{
3012 void *op
[2]; uint32_t ext_mask
;
3014 #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
3015 #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 }
3016 #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 }
3017 #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 }
3018 static struct sse_op_helper_s sse_op_table6
[256] = {
3019 [0x00] = SSSE3_OP(pshufb
),
3020 [0x01] = SSSE3_OP(phaddw
),
3021 [0x02] = SSSE3_OP(phaddd
),
3022 [0x03] = SSSE3_OP(phaddsw
),
3023 [0x04] = SSSE3_OP(pmaddubsw
),
3024 [0x05] = SSSE3_OP(phsubw
),
3025 [0x06] = SSSE3_OP(phsubd
),
3026 [0x07] = SSSE3_OP(phsubsw
),
3027 [0x08] = SSSE3_OP(psignb
),
3028 [0x09] = SSSE3_OP(psignw
),
3029 [0x0a] = SSSE3_OP(psignd
),
3030 [0x0b] = SSSE3_OP(pmulhrsw
),
3031 [0x10] = SSE41_OP(pblendvb
),
3032 [0x14] = SSE41_OP(blendvps
),
3033 [0x15] = SSE41_OP(blendvpd
),
3034 [0x17] = SSE41_OP(ptest
),
3035 [0x1c] = SSSE3_OP(pabsb
),
3036 [0x1d] = SSSE3_OP(pabsw
),
3037 [0x1e] = SSSE3_OP(pabsd
),
3038 [0x20] = SSE41_OP(pmovsxbw
),
3039 [0x21] = SSE41_OP(pmovsxbd
),
3040 [0x22] = SSE41_OP(pmovsxbq
),
3041 [0x23] = SSE41_OP(pmovsxwd
),
3042 [0x24] = SSE41_OP(pmovsxwq
),
3043 [0x25] = SSE41_OP(pmovsxdq
),
3044 [0x28] = SSE41_OP(pmuldq
),
3045 [0x29] = SSE41_OP(pcmpeqq
),
3046 [0x2a] = SSE41_SPECIAL
, /* movntqda */
3047 [0x2b] = SSE41_OP(packusdw
),
3048 [0x30] = SSE41_OP(pmovzxbw
),
3049 [0x31] = SSE41_OP(pmovzxbd
),
3050 [0x32] = SSE41_OP(pmovzxbq
),
3051 [0x33] = SSE41_OP(pmovzxwd
),
3052 [0x34] = SSE41_OP(pmovzxwq
),
3053 [0x35] = SSE41_OP(pmovzxdq
),
3054 [0x37] = SSE42_OP(pcmpgtq
),
3055 [0x38] = SSE41_OP(pminsb
),
3056 [0x39] = SSE41_OP(pminsd
),
3057 [0x3a] = SSE41_OP(pminuw
),
3058 [0x3b] = SSE41_OP(pminud
),
3059 [0x3c] = SSE41_OP(pmaxsb
),
3060 [0x3d] = SSE41_OP(pmaxsd
),
3061 [0x3e] = SSE41_OP(pmaxuw
),
3062 [0x3f] = SSE41_OP(pmaxud
),
3063 [0x40] = SSE41_OP(pmulld
),
3064 [0x41] = SSE41_OP(phminposuw
),
3067 static struct sse_op_helper_s sse_op_table7
[256] = {
3068 [0x08] = SSE41_OP(roundps
),
3069 [0x09] = SSE41_OP(roundpd
),
3070 [0x0a] = SSE41_OP(roundss
),
3071 [0x0b] = SSE41_OP(roundsd
),
3072 [0x0c] = SSE41_OP(blendps
),
3073 [0x0d] = SSE41_OP(blendpd
),
3074 [0x0e] = SSE41_OP(pblendw
),
3075 [0x0f] = SSSE3_OP(palignr
),
3076 [0x14] = SSE41_SPECIAL
, /* pextrb */
3077 [0x15] = SSE41_SPECIAL
, /* pextrw */
3078 [0x16] = SSE41_SPECIAL
, /* pextrd/pextrq */
3079 [0x17] = SSE41_SPECIAL
, /* extractps */
3080 [0x20] = SSE41_SPECIAL
, /* pinsrb */
3081 [0x21] = SSE41_SPECIAL
, /* insertps */
3082 [0x22] = SSE41_SPECIAL
, /* pinsrd/pinsrq */
3083 [0x40] = SSE41_OP(dpps
),
3084 [0x41] = SSE41_OP(dppd
),
3085 [0x42] = SSE41_OP(mpsadbw
),
3086 [0x60] = SSE42_OP(pcmpestrm
),
3087 [0x61] = SSE42_OP(pcmpestri
),
3088 [0x62] = SSE42_OP(pcmpistrm
),
3089 [0x63] = SSE42_OP(pcmpistri
),
3092 static void gen_sse(DisasContext
*s
, int b
, target_ulong pc_start
, int rex_r
)
3094 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
3095 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
3099 if (s
->prefix
& PREFIX_DATA
)
3101 else if (s
->prefix
& PREFIX_REPZ
)
3103 else if (s
->prefix
& PREFIX_REPNZ
)
3107 sse_op2
= sse_op_table1
[b
][b1
];
3110 if ((b
<= 0x5f && b
>= 0x10) || b
== 0xc6 || b
== 0xc2) {
3120 /* simple MMX/SSE operation */
3121 if (s
->flags
& HF_TS_MASK
) {
3122 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
3125 if (s
->flags
& HF_EM_MASK
) {
3127 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
3130 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
3131 if ((b
!= 0x38 && b
!= 0x3a) || (s
->prefix
& PREFIX_DATA
))
3134 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3145 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
3146 the static cpu state) */
3148 gen_helper_enter_mmx();
3151 modrm
= ldub_code(s
->pc
++);
3152 reg
= ((modrm
>> 3) & 7);
3155 mod
= (modrm
>> 6) & 3;
3156 if (sse_op2
== SSE_SPECIAL
) {
3159 case 0x0e7: /* movntq */
3162 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3163 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3165 case 0x1e7: /* movntdq */
3166 case 0x02b: /* movntps */
3167 case 0x12b: /* movntps */
3168 case 0x3f0: /* lddqu */
3171 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3172 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3174 case 0x22b: /* movntss */
3175 case 0x32b: /* movntsd */
3178 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3180 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,
3183 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3184 xmm_regs
[reg
].XMM_L(0)));
3185 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3188 case 0x6e: /* movd mm, ea */
3189 #ifdef TARGET_X86_64
3190 if (s
->dflag
== 2) {
3191 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3192 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3196 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3197 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3198 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3199 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3200 gen_helper_movl_mm_T0_mmx(cpu_ptr0
, cpu_tmp2_i32
);
3203 case 0x16e: /* movd xmm, ea */
3204 #ifdef TARGET_X86_64
3205 if (s
->dflag
== 2) {
3206 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3207 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3208 offsetof(CPUX86State
,xmm_regs
[reg
]));
3209 gen_helper_movq_mm_T0_xmm(cpu_ptr0
, cpu_T
[0]);
3213 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3214 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3215 offsetof(CPUX86State
,xmm_regs
[reg
]));
3216 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3217 gen_helper_movl_mm_T0_xmm(cpu_ptr0
, cpu_tmp2_i32
);
3220 case 0x6f: /* movq mm, ea */
3222 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3223 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3226 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3227 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3228 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3229 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3232 case 0x010: /* movups */
3233 case 0x110: /* movupd */
3234 case 0x028: /* movaps */
3235 case 0x128: /* movapd */
3236 case 0x16f: /* movdqa xmm, ea */
3237 case 0x26f: /* movdqu xmm, ea */
3239 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3240 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3242 rm
= (modrm
& 7) | REX_B(s
);
3243 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
3244 offsetof(CPUX86State
,xmm_regs
[rm
]));
3247 case 0x210: /* movss xmm, ea */
3249 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3250 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3251 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3253 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3254 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3255 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3257 rm
= (modrm
& 7) | REX_B(s
);
3258 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3259 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3262 case 0x310: /* movsd xmm, ea */
3264 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3265 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3267 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3268 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3270 rm
= (modrm
& 7) | REX_B(s
);
3271 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3272 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3275 case 0x012: /* movlps */
3276 case 0x112: /* movlpd */
3278 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3279 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3282 rm
= (modrm
& 7) | REX_B(s
);
3283 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3284 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3287 case 0x212: /* movsldup */
3289 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3290 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3292 rm
= (modrm
& 7) | REX_B(s
);
3293 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3294 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3295 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3296 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(2)));
3298 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3299 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3300 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3301 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3303 case 0x312: /* movddup */
3305 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3306 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3308 rm
= (modrm
& 7) | REX_B(s
);
3309 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3310 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3312 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3313 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3315 case 0x016: /* movhps */
3316 case 0x116: /* movhpd */
3318 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3319 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3322 rm
= (modrm
& 7) | REX_B(s
);
3323 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3324 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3327 case 0x216: /* movshdup */
3329 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3330 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3332 rm
= (modrm
& 7) | REX_B(s
);
3333 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3334 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
3335 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3336 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
3338 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3339 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3340 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3341 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3346 int bit_index
, field_length
;
3348 if (b1
== 1 && reg
!= 0)
3350 field_length
= ldub_code(s
->pc
++) & 0x3F;
3351 bit_index
= ldub_code(s
->pc
++) & 0x3F;
3352 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3353 offsetof(CPUX86State
,xmm_regs
[reg
]));
3355 gen_helper_extrq_i(cpu_ptr0
, tcg_const_i32(bit_index
),
3356 tcg_const_i32(field_length
));
3358 gen_helper_insertq_i(cpu_ptr0
, tcg_const_i32(bit_index
),
3359 tcg_const_i32(field_length
));
3362 case 0x7e: /* movd ea, mm */
3363 #ifdef TARGET_X86_64
3364 if (s
->dflag
== 2) {
3365 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3366 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3367 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3371 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3372 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_L(0)));
3373 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3376 case 0x17e: /* movd ea, xmm */
3377 #ifdef TARGET_X86_64
3378 if (s
->dflag
== 2) {
3379 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3380 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3381 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3385 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3386 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3387 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3390 case 0x27e: /* movq xmm, ea */
3392 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3393 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3395 rm
= (modrm
& 7) | REX_B(s
);
3396 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3397 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3399 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3401 case 0x7f: /* movq ea, mm */
3403 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3404 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3407 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
3408 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3411 case 0x011: /* movups */
3412 case 0x111: /* movupd */
3413 case 0x029: /* movaps */
3414 case 0x129: /* movapd */
3415 case 0x17f: /* movdqa ea, xmm */
3416 case 0x27f: /* movdqu ea, xmm */
3418 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3419 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3421 rm
= (modrm
& 7) | REX_B(s
);
3422 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
3423 offsetof(CPUX86State
,xmm_regs
[reg
]));
3426 case 0x211: /* movss ea, xmm */
3428 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3429 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3430 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3432 rm
= (modrm
& 7) | REX_B(s
);
3433 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
3434 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3437 case 0x311: /* movsd ea, xmm */
3439 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3440 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3442 rm
= (modrm
& 7) | REX_B(s
);
3443 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3444 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3447 case 0x013: /* movlps */
3448 case 0x113: /* movlpd */
3450 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3451 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3456 case 0x017: /* movhps */
3457 case 0x117: /* movhpd */
3459 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3460 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3465 case 0x71: /* shift mm, im */
3468 case 0x171: /* shift xmm, im */
3471 val
= ldub_code(s
->pc
++);
3473 gen_op_movl_T0_im(val
);
3474 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3476 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
3477 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
3479 gen_op_movl_T0_im(val
);
3480 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
3482 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
3483 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
3485 sse_op2
= sse_op_table2
[((b
- 1) & 3) * 8 + (((modrm
>> 3)) & 7)][b1
];
3489 rm
= (modrm
& 7) | REX_B(s
);
3490 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3493 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3495 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3496 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op1_offset
);
3497 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3499 case 0x050: /* movmskps */
3500 rm
= (modrm
& 7) | REX_B(s
);
3501 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3502 offsetof(CPUX86State
,xmm_regs
[rm
]));
3503 gen_helper_movmskps(cpu_tmp2_i32
, cpu_ptr0
);
3504 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3505 gen_op_mov_reg_T0(OT_LONG
, reg
);
3507 case 0x150: /* movmskpd */
3508 rm
= (modrm
& 7) | REX_B(s
);
3509 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3510 offsetof(CPUX86State
,xmm_regs
[rm
]));
3511 gen_helper_movmskpd(cpu_tmp2_i32
, cpu_ptr0
);
3512 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3513 gen_op_mov_reg_T0(OT_LONG
, reg
);
3515 case 0x02a: /* cvtpi2ps */
3516 case 0x12a: /* cvtpi2pd */
3517 gen_helper_enter_mmx();
3519 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3520 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3521 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3524 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3526 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3527 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3528 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3531 gen_helper_cvtpi2ps(cpu_ptr0
, cpu_ptr1
);
3535 gen_helper_cvtpi2pd(cpu_ptr0
, cpu_ptr1
);
3539 case 0x22a: /* cvtsi2ss */
3540 case 0x32a: /* cvtsi2sd */
3541 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3542 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3543 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3544 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3545 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2)];
3546 if (ot
== OT_LONG
) {
3547 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3548 ((void (*)(TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_tmp2_i32
);
3550 ((void (*)(TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_T
[0]);
3553 case 0x02c: /* cvttps2pi */
3554 case 0x12c: /* cvttpd2pi */
3555 case 0x02d: /* cvtps2pi */
3556 case 0x12d: /* cvtpd2pi */
3557 gen_helper_enter_mmx();
3559 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3560 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3561 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3563 rm
= (modrm
& 7) | REX_B(s
);
3564 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3566 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
3567 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3568 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3571 gen_helper_cvttps2pi(cpu_ptr0
, cpu_ptr1
);
3574 gen_helper_cvttpd2pi(cpu_ptr0
, cpu_ptr1
);
3577 gen_helper_cvtps2pi(cpu_ptr0
, cpu_ptr1
);
3580 gen_helper_cvtpd2pi(cpu_ptr0
, cpu_ptr1
);
3584 case 0x22c: /* cvttss2si */
3585 case 0x32c: /* cvttsd2si */
3586 case 0x22d: /* cvtss2si */
3587 case 0x32d: /* cvtsd2si */
3588 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3590 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3592 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
3594 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3595 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3597 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3599 rm
= (modrm
& 7) | REX_B(s
);
3600 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3602 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2) + 4 +
3604 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3605 if (ot
== OT_LONG
) {
3606 ((void (*)(TCGv_i32
, TCGv_ptr
))sse_op2
)(cpu_tmp2_i32
, cpu_ptr0
);
3607 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3609 ((void (*)(TCGv
, TCGv_ptr
))sse_op2
)(cpu_T
[0], cpu_ptr0
);
3611 gen_op_mov_reg_T0(ot
, reg
);
3613 case 0xc4: /* pinsrw */
3616 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3617 val
= ldub_code(s
->pc
++);
3620 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3621 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_W(val
)));
3624 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3625 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_W(val
)));
3628 case 0xc5: /* pextrw */
3632 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3633 val
= ldub_code(s
->pc
++);
3636 rm
= (modrm
& 7) | REX_B(s
);
3637 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3638 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_W(val
)));
3642 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3643 offsetof(CPUX86State
,fpregs
[rm
].mmx
.MMX_W(val
)));
3645 reg
= ((modrm
>> 3) & 7) | rex_r
;
3646 gen_op_mov_reg_T0(ot
, reg
);
3648 case 0x1d6: /* movq ea, xmm */
3650 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3651 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3653 rm
= (modrm
& 7) | REX_B(s
);
3654 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3655 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3656 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3659 case 0x2d6: /* movq2dq */
3660 gen_helper_enter_mmx();
3662 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3663 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3664 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3666 case 0x3d6: /* movdq2q */
3667 gen_helper_enter_mmx();
3668 rm
= (modrm
& 7) | REX_B(s
);
3669 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
),
3670 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3672 case 0xd7: /* pmovmskb */
3677 rm
= (modrm
& 7) | REX_B(s
);
3678 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,xmm_regs
[rm
]));
3679 gen_helper_pmovmskb_xmm(cpu_tmp2_i32
, cpu_ptr0
);
3682 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3683 gen_helper_pmovmskb_mmx(cpu_tmp2_i32
, cpu_ptr0
);
3685 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3686 reg
= ((modrm
>> 3) & 7) | rex_r
;
3687 gen_op_mov_reg_T0(OT_LONG
, reg
);
3690 if (s
->prefix
& PREFIX_REPNZ
)
3694 modrm
= ldub_code(s
->pc
++);
3696 reg
= ((modrm
>> 3) & 7) | rex_r
;
3697 mod
= (modrm
>> 6) & 3;
3699 sse_op2
= sse_op_table6
[b
].op
[b1
];
3702 if (!(s
->cpuid_ext_features
& sse_op_table6
[b
].ext_mask
))
3706 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3708 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3710 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3711 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3713 case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */
3714 case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */
3715 case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */
3716 gen_ldq_env_A0(s
->mem_index
, op2_offset
+
3717 offsetof(XMMReg
, XMM_Q(0)));
3719 case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */
3720 case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */
3721 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3722 (s
->mem_index
>> 2) - 1);
3723 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3724 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, op2_offset
+
3725 offsetof(XMMReg
, XMM_L(0)));
3727 case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */
3728 tcg_gen_qemu_ld16u(cpu_tmp0
, cpu_A0
,
3729 (s
->mem_index
>> 2) - 1);
3730 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, op2_offset
+
3731 offsetof(XMMReg
, XMM_W(0)));
3733 case 0x2a: /* movntqda */
3734 gen_ldo_env_A0(s
->mem_index
, op1_offset
);
3737 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3741 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3743 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3745 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3746 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3747 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3750 if (sse_op2
== SSE_SPECIAL
)
3753 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3754 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3755 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3758 s
->cc_op
= CC_OP_EFLAGS
;
3760 case 0x338: /* crc32 */
3763 modrm
= ldub_code(s
->pc
++);
3764 reg
= ((modrm
>> 3) & 7) | rex_r
;
3766 if (b
!= 0xf0 && b
!= 0xf1)
3768 if (!(s
->cpuid_ext_features
& CPUID_EXT_SSE42
))
3773 else if (b
== 0xf1 && s
->dflag
!= 2)
3774 if (s
->prefix
& PREFIX_DATA
)
3781 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
3782 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3783 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3784 gen_helper_crc32(cpu_T
[0], cpu_tmp2_i32
,
3785 cpu_T
[0], tcg_const_i32(8 << ot
));
3787 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3788 gen_op_mov_reg_T0(ot
, reg
);
3793 modrm
= ldub_code(s
->pc
++);
3795 reg
= ((modrm
>> 3) & 7) | rex_r
;
3796 mod
= (modrm
>> 6) & 3;
3798 sse_op2
= sse_op_table7
[b
].op
[b1
];
3801 if (!(s
->cpuid_ext_features
& sse_op_table7
[b
].ext_mask
))
3804 if (sse_op2
== SSE_SPECIAL
) {
3805 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3806 rm
= (modrm
& 7) | REX_B(s
);
3808 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3809 reg
= ((modrm
>> 3) & 7) | rex_r
;
3810 val
= ldub_code(s
->pc
++);
3812 case 0x14: /* pextrb */
3813 tcg_gen_ld8u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3814 xmm_regs
[reg
].XMM_B(val
& 15)));
3816 gen_op_mov_reg_T0(ot
, rm
);
3818 tcg_gen_qemu_st8(cpu_T
[0], cpu_A0
,
3819 (s
->mem_index
>> 2) - 1);
3821 case 0x15: /* pextrw */
3822 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3823 xmm_regs
[reg
].XMM_W(val
& 7)));
3825 gen_op_mov_reg_T0(ot
, rm
);
3827 tcg_gen_qemu_st16(cpu_T
[0], cpu_A0
,
3828 (s
->mem_index
>> 2) - 1);
3831 if (ot
== OT_LONG
) { /* pextrd */
3832 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3833 offsetof(CPUX86State
,
3834 xmm_regs
[reg
].XMM_L(val
& 3)));
3835 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3837 gen_op_mov_reg_v(ot
, rm
, cpu_T
[0]);
3839 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3840 (s
->mem_index
>> 2) - 1);
3841 } else { /* pextrq */
3842 #ifdef TARGET_X86_64
3843 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3844 offsetof(CPUX86State
,
3845 xmm_regs
[reg
].XMM_Q(val
& 1)));
3847 gen_op_mov_reg_v(ot
, rm
, cpu_tmp1_i64
);
3849 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
3850 (s
->mem_index
>> 2) - 1);
3856 case 0x17: /* extractps */
3857 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3858 xmm_regs
[reg
].XMM_L(val
& 3)));
3860 gen_op_mov_reg_T0(ot
, rm
);
3862 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3863 (s
->mem_index
>> 2) - 1);
3865 case 0x20: /* pinsrb */
3867 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
3869 tcg_gen_qemu_ld8u(cpu_tmp0
, cpu_A0
,
3870 (s
->mem_index
>> 2) - 1);
3871 tcg_gen_st8_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
,
3872 xmm_regs
[reg
].XMM_B(val
& 15)));
3874 case 0x21: /* insertps */
3876 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3877 offsetof(CPUX86State
,xmm_regs
[rm
]
3878 .XMM_L((val
>> 6) & 3)));
3880 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3881 (s
->mem_index
>> 2) - 1);
3882 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3884 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3885 offsetof(CPUX86State
,xmm_regs
[reg
]
3886 .XMM_L((val
>> 4) & 3)));
3888 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3889 cpu_env
, offsetof(CPUX86State
,
3890 xmm_regs
[reg
].XMM_L(0)));
3892 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3893 cpu_env
, offsetof(CPUX86State
,
3894 xmm_regs
[reg
].XMM_L(1)));
3896 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3897 cpu_env
, offsetof(CPUX86State
,
3898 xmm_regs
[reg
].XMM_L(2)));
3900 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3901 cpu_env
, offsetof(CPUX86State
,
3902 xmm_regs
[reg
].XMM_L(3)));
3905 if (ot
== OT_LONG
) { /* pinsrd */
3907 gen_op_mov_v_reg(ot
, cpu_tmp0
, rm
);
3909 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3910 (s
->mem_index
>> 2) - 1);
3911 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3912 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3913 offsetof(CPUX86State
,
3914 xmm_regs
[reg
].XMM_L(val
& 3)));
3915 } else { /* pinsrq */
3916 #ifdef TARGET_X86_64
3918 gen_op_mov_v_reg(ot
, cpu_tmp1_i64
, rm
);
3920 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
3921 (s
->mem_index
>> 2) - 1);
3922 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3923 offsetof(CPUX86State
,
3924 xmm_regs
[reg
].XMM_Q(val
& 1)));
3935 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3937 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3939 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3940 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3941 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3944 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3946 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3948 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3949 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3950 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3953 val
= ldub_code(s
->pc
++);
3955 if ((b
& 0xfc) == 0x60) { /* pcmpXstrX */
3956 s
->cc_op
= CC_OP_EFLAGS
;
3959 /* The helper must use entire 64-bit gp registers */
3963 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3964 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3965 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
3971 /* generic MMX or SSE operation */
3973 case 0x70: /* pshufx insn */
3974 case 0xc6: /* pshufx insn */
3975 case 0xc2: /* compare insns */
3982 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3984 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3985 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3986 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f && b
!= 0x5b) ||
3988 /* specific case for SSE single instructions */
3991 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3992 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3995 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
3998 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4001 rm
= (modrm
& 7) | REX_B(s
);
4002 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
4005 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4007 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4008 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4009 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4012 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4016 case 0x0f: /* 3DNow! data insns */
4017 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
4019 val
= ldub_code(s
->pc
++);
4020 sse_op2
= sse_op_table5
[val
];
4023 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4024 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4025 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4027 case 0x70: /* pshufx insn */
4028 case 0xc6: /* pshufx insn */
4029 val
= ldub_code(s
->pc
++);
4030 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4031 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4032 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4036 val
= ldub_code(s
->pc
++);
4039 sse_op2
= sse_op_table4
[val
][b1
];
4040 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4041 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4042 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4045 /* maskmov : we must prepare A0 */
4048 #ifdef TARGET_X86_64
4049 if (s
->aflag
== 2) {
4050 gen_op_movq_A0_reg(R_EDI
);
4054 gen_op_movl_A0_reg(R_EDI
);
4056 gen_op_andl_A0_ffff();
4058 gen_add_A0_ds_seg(s
);
4060 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4061 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4062 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, cpu_A0
);
4065 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4066 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4067 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4070 if (b
== 0x2e || b
== 0x2f) {
4071 s
->cc_op
= CC_OP_EFLAGS
;
4076 /* convert one instruction. s->is_jmp is set if the translation must
4077 be stopped. Return the next pc value */
4078 static target_ulong
disas_insn(DisasContext
*s
, target_ulong pc_start
)
4080 int b
, prefixes
, aflag
, dflag
;
4082 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
4083 target_ulong next_eip
, tval
;
4086 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
4087 tcg_gen_debug_insn_start(pc_start
);
4095 #ifdef TARGET_X86_64
4100 s
->rip_offset
= 0; /* for relative ip address */
4102 b
= ldub_code(s
->pc
);
4104 /* check prefixes */
4105 #ifdef TARGET_X86_64
4109 prefixes
|= PREFIX_REPZ
;
4112 prefixes
|= PREFIX_REPNZ
;
4115 prefixes
|= PREFIX_LOCK
;
4136 prefixes
|= PREFIX_DATA
;
4139 prefixes
|= PREFIX_ADR
;
4143 rex_w
= (b
>> 3) & 1;
4144 rex_r
= (b
& 0x4) << 1;
4145 s
->rex_x
= (b
& 0x2) << 2;
4146 REX_B(s
) = (b
& 0x1) << 3;
4147 x86_64_hregs
= 1; /* select uniform byte register addressing */
4151 /* 0x66 is ignored if rex.w is set */
4154 if (prefixes
& PREFIX_DATA
)
4157 if (!(prefixes
& PREFIX_ADR
))
4164 prefixes
|= PREFIX_REPZ
;
4167 prefixes
|= PREFIX_REPNZ
;
4170 prefixes
|= PREFIX_LOCK
;
4191 prefixes
|= PREFIX_DATA
;
4194 prefixes
|= PREFIX_ADR
;
4197 if (prefixes
& PREFIX_DATA
)
4199 if (prefixes
& PREFIX_ADR
)
4203 s
->prefix
= prefixes
;
4207 /* lock generation */
4208 if (prefixes
& PREFIX_LOCK
)
4211 /* now check op code */
4215 /**************************/
4216 /* extended op code */
4217 b
= ldub_code(s
->pc
++) | 0x100;
4220 /**************************/
4238 ot
= dflag
+ OT_WORD
;
4241 case 0: /* OP Ev, Gv */
4242 modrm
= ldub_code(s
->pc
++);
4243 reg
= ((modrm
>> 3) & 7) | rex_r
;
4244 mod
= (modrm
>> 6) & 3;
4245 rm
= (modrm
& 7) | REX_B(s
);
4247 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4249 } else if (op
== OP_XORL
&& rm
== reg
) {
4251 /* xor reg, reg optimisation */
4253 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4254 gen_op_mov_reg_T0(ot
, reg
);
4255 gen_op_update1_cc();
4260 gen_op_mov_TN_reg(ot
, 1, reg
);
4261 gen_op(s
, op
, ot
, opreg
);
4263 case 1: /* OP Gv, Ev */
4264 modrm
= ldub_code(s
->pc
++);
4265 mod
= (modrm
>> 6) & 3;
4266 reg
= ((modrm
>> 3) & 7) | rex_r
;
4267 rm
= (modrm
& 7) | REX_B(s
);
4269 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4270 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4271 } else if (op
== OP_XORL
&& rm
== reg
) {
4274 gen_op_mov_TN_reg(ot
, 1, rm
);
4276 gen_op(s
, op
, ot
, reg
);
4278 case 2: /* OP A, Iv */
4279 val
= insn_get(s
, ot
);
4280 gen_op_movl_T1_im(val
);
4281 gen_op(s
, op
, ot
, OR_EAX
);
4290 case 0x80: /* GRP1 */
4299 ot
= dflag
+ OT_WORD
;
4301 modrm
= ldub_code(s
->pc
++);
4302 mod
= (modrm
>> 6) & 3;
4303 rm
= (modrm
& 7) | REX_B(s
);
4304 op
= (modrm
>> 3) & 7;
4310 s
->rip_offset
= insn_const_size(ot
);
4311 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4322 val
= insn_get(s
, ot
);
4325 val
= (int8_t)insn_get(s
, OT_BYTE
);
4328 gen_op_movl_T1_im(val
);
4329 gen_op(s
, op
, ot
, opreg
);
4333 /**************************/
4334 /* inc, dec, and other misc arith */
4335 case 0x40 ... 0x47: /* inc Gv */
4336 ot
= dflag
? OT_LONG
: OT_WORD
;
4337 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
4339 case 0x48 ... 0x4f: /* dec Gv */
4340 ot
= dflag
? OT_LONG
: OT_WORD
;
4341 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
4343 case 0xf6: /* GRP3 */
4348 ot
= dflag
+ OT_WORD
;
4350 modrm
= ldub_code(s
->pc
++);
4351 mod
= (modrm
>> 6) & 3;
4352 rm
= (modrm
& 7) | REX_B(s
);
4353 op
= (modrm
>> 3) & 7;
4356 s
->rip_offset
= insn_const_size(ot
);
4357 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4358 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4360 gen_op_mov_TN_reg(ot
, 0, rm
);
4365 val
= insn_get(s
, ot
);
4366 gen_op_movl_T1_im(val
);
4367 gen_op_testl_T0_T1_cc();
4368 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4371 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
4373 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4375 gen_op_mov_reg_T0(ot
, rm
);
4379 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
4381 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4383 gen_op_mov_reg_T0(ot
, rm
);
4385 gen_op_update_neg_cc();
4386 s
->cc_op
= CC_OP_SUBB
+ ot
;
4391 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4392 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
4393 tcg_gen_ext8u_tl(cpu_T
[1], cpu_T
[1]);
4394 /* XXX: use 32 bit mul which could be faster */
4395 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4396 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4397 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4398 tcg_gen_andi_tl(cpu_cc_src
, cpu_T
[0], 0xff00);
4399 s
->cc_op
= CC_OP_MULB
;
4402 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4403 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
4404 tcg_gen_ext16u_tl(cpu_T
[1], cpu_T
[1]);
4405 /* XXX: use 32 bit mul which could be faster */
4406 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4407 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4408 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4409 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4410 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4411 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4412 s
->cc_op
= CC_OP_MULW
;
4416 #ifdef TARGET_X86_64
4417 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4418 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
4419 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
4420 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4421 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4422 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4423 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4424 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4425 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4429 t0
= tcg_temp_new_i64();
4430 t1
= tcg_temp_new_i64();
4431 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4432 tcg_gen_extu_i32_i64(t0
, cpu_T
[0]);
4433 tcg_gen_extu_i32_i64(t1
, cpu_T
[1]);
4434 tcg_gen_mul_i64(t0
, t0
, t1
);
4435 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4436 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4437 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4438 tcg_gen_shri_i64(t0
, t0
, 32);
4439 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4440 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4441 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4444 s
->cc_op
= CC_OP_MULL
;
4446 #ifdef TARGET_X86_64
4448 gen_helper_mulq_EAX_T0(cpu_T
[0]);
4449 s
->cc_op
= CC_OP_MULQ
;
4457 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4458 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4459 tcg_gen_ext8s_tl(cpu_T
[1], cpu_T
[1]);
4460 /* XXX: use 32 bit mul which could be faster */
4461 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4462 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4463 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4464 tcg_gen_ext8s_tl(cpu_tmp0
, cpu_T
[0]);
4465 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4466 s
->cc_op
= CC_OP_MULB
;
4469 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4470 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4471 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4472 /* XXX: use 32 bit mul which could be faster */
4473 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4474 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4475 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4476 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4477 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4478 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4479 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4480 s
->cc_op
= CC_OP_MULW
;
4484 #ifdef TARGET_X86_64
4485 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4486 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4487 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4488 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4489 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4490 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4491 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4492 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4493 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4494 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4498 t0
= tcg_temp_new_i64();
4499 t1
= tcg_temp_new_i64();
4500 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4501 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4502 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4503 tcg_gen_mul_i64(t0
, t0
, t1
);
4504 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4505 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4506 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4507 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4508 tcg_gen_shri_i64(t0
, t0
, 32);
4509 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4510 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4511 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4514 s
->cc_op
= CC_OP_MULL
;
4516 #ifdef TARGET_X86_64
4518 gen_helper_imulq_EAX_T0(cpu_T
[0]);
4519 s
->cc_op
= CC_OP_MULQ
;
4527 gen_jmp_im(pc_start
- s
->cs_base
);
4528 gen_helper_divb_AL(cpu_T
[0]);
4531 gen_jmp_im(pc_start
- s
->cs_base
);
4532 gen_helper_divw_AX(cpu_T
[0]);
4536 gen_jmp_im(pc_start
- s
->cs_base
);
4537 gen_helper_divl_EAX(cpu_T
[0]);
4539 #ifdef TARGET_X86_64
4541 gen_jmp_im(pc_start
- s
->cs_base
);
4542 gen_helper_divq_EAX(cpu_T
[0]);
4550 gen_jmp_im(pc_start
- s
->cs_base
);
4551 gen_helper_idivb_AL(cpu_T
[0]);
4554 gen_jmp_im(pc_start
- s
->cs_base
);
4555 gen_helper_idivw_AX(cpu_T
[0]);
4559 gen_jmp_im(pc_start
- s
->cs_base
);
4560 gen_helper_idivl_EAX(cpu_T
[0]);
4562 #ifdef TARGET_X86_64
4564 gen_jmp_im(pc_start
- s
->cs_base
);
4565 gen_helper_idivq_EAX(cpu_T
[0]);
4575 case 0xfe: /* GRP4 */
4576 case 0xff: /* GRP5 */
4580 ot
= dflag
+ OT_WORD
;
4582 modrm
= ldub_code(s
->pc
++);
4583 mod
= (modrm
>> 6) & 3;
4584 rm
= (modrm
& 7) | REX_B(s
);
4585 op
= (modrm
>> 3) & 7;
4586 if (op
>= 2 && b
== 0xfe) {
4590 if (op
== 2 || op
== 4) {
4591 /* operand size for jumps is 64 bit */
4593 } else if (op
== 3 || op
== 5) {
4594 /* for call calls, the operand is 16 or 32 bit, even
4596 ot
= dflag
? OT_LONG
: OT_WORD
;
4597 } else if (op
== 6) {
4598 /* default push size is 64 bit */
4599 ot
= dflag
? OT_QUAD
: OT_WORD
;
4603 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4604 if (op
>= 2 && op
!= 3 && op
!= 5)
4605 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4607 gen_op_mov_TN_reg(ot
, 0, rm
);
4611 case 0: /* inc Ev */
4616 gen_inc(s
, ot
, opreg
, 1);
4618 case 1: /* dec Ev */
4623 gen_inc(s
, ot
, opreg
, -1);
4625 case 2: /* call Ev */
4626 /* XXX: optimize if memory (no 'and' is necessary) */
4628 gen_op_andl_T0_ffff();
4629 next_eip
= s
->pc
- s
->cs_base
;
4630 gen_movtl_T1_im(next_eip
);
4635 case 3: /* lcall Ev */
4636 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4637 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4638 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4640 if (s
->pe
&& !s
->vm86
) {
4641 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4642 gen_op_set_cc_op(s
->cc_op
);
4643 gen_jmp_im(pc_start
- s
->cs_base
);
4644 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4645 gen_helper_lcall_protected(cpu_tmp2_i32
, cpu_T
[1],
4646 tcg_const_i32(dflag
),
4647 tcg_const_i32(s
->pc
- pc_start
));
4649 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4650 gen_helper_lcall_real(cpu_tmp2_i32
, cpu_T
[1],
4651 tcg_const_i32(dflag
),
4652 tcg_const_i32(s
->pc
- s
->cs_base
));
4656 case 4: /* jmp Ev */
4658 gen_op_andl_T0_ffff();
4662 case 5: /* ljmp Ev */
4663 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4664 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4665 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4667 if (s
->pe
&& !s
->vm86
) {
4668 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4669 gen_op_set_cc_op(s
->cc_op
);
4670 gen_jmp_im(pc_start
- s
->cs_base
);
4671 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4672 gen_helper_ljmp_protected(cpu_tmp2_i32
, cpu_T
[1],
4673 tcg_const_i32(s
->pc
- pc_start
));
4675 gen_op_movl_seg_T0_vm(R_CS
);
4676 gen_op_movl_T0_T1();
4681 case 6: /* push Ev */
4689 case 0x84: /* test Ev, Gv */
4694 ot
= dflag
+ OT_WORD
;
4696 modrm
= ldub_code(s
->pc
++);
4697 mod
= (modrm
>> 6) & 3;
4698 rm
= (modrm
& 7) | REX_B(s
);
4699 reg
= ((modrm
>> 3) & 7) | rex_r
;
4701 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4702 gen_op_mov_TN_reg(ot
, 1, reg
);
4703 gen_op_testl_T0_T1_cc();
4704 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4707 case 0xa8: /* test eAX, Iv */
4712 ot
= dflag
+ OT_WORD
;
4713 val
= insn_get(s
, ot
);
4715 gen_op_mov_TN_reg(ot
, 0, OR_EAX
);
4716 gen_op_movl_T1_im(val
);
4717 gen_op_testl_T0_T1_cc();
4718 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4721 case 0x98: /* CWDE/CBW */
4722 #ifdef TARGET_X86_64
4724 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4725 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4726 gen_op_mov_reg_T0(OT_QUAD
, R_EAX
);
4730 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4731 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4732 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4734 gen_op_mov_TN_reg(OT_BYTE
, 0, R_EAX
);
4735 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4736 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4739 case 0x99: /* CDQ/CWD */
4740 #ifdef TARGET_X86_64
4742 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
4743 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 63);
4744 gen_op_mov_reg_T0(OT_QUAD
, R_EDX
);
4748 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4749 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4750 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 31);
4751 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4753 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4754 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4755 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 15);
4756 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4759 case 0x1af: /* imul Gv, Ev */
4760 case 0x69: /* imul Gv, Ev, I */
4762 ot
= dflag
+ OT_WORD
;
4763 modrm
= ldub_code(s
->pc
++);
4764 reg
= ((modrm
>> 3) & 7) | rex_r
;
4766 s
->rip_offset
= insn_const_size(ot
);
4769 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4771 val
= insn_get(s
, ot
);
4772 gen_op_movl_T1_im(val
);
4773 } else if (b
== 0x6b) {
4774 val
= (int8_t)insn_get(s
, OT_BYTE
);
4775 gen_op_movl_T1_im(val
);
4777 gen_op_mov_TN_reg(ot
, 1, reg
);
4780 #ifdef TARGET_X86_64
4781 if (ot
== OT_QUAD
) {
4782 gen_helper_imulq_T0_T1(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4785 if (ot
== OT_LONG
) {
4786 #ifdef TARGET_X86_64
4787 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4788 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4789 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4790 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4791 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4792 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4796 t0
= tcg_temp_new_i64();
4797 t1
= tcg_temp_new_i64();
4798 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4799 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4800 tcg_gen_mul_i64(t0
, t0
, t1
);
4801 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4802 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4803 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4804 tcg_gen_shri_i64(t0
, t0
, 32);
4805 tcg_gen_trunc_i64_i32(cpu_T
[1], t0
);
4806 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[1], cpu_tmp0
);
4810 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4811 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4812 /* XXX: use 32 bit mul which could be faster */
4813 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4814 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4815 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4816 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4818 gen_op_mov_reg_T0(ot
, reg
);
4819 s
->cc_op
= CC_OP_MULB
+ ot
;
4822 case 0x1c1: /* xadd Ev, Gv */
4826 ot
= dflag
+ OT_WORD
;
4827 modrm
= ldub_code(s
->pc
++);
4828 reg
= ((modrm
>> 3) & 7) | rex_r
;
4829 mod
= (modrm
>> 6) & 3;
4831 rm
= (modrm
& 7) | REX_B(s
);
4832 gen_op_mov_TN_reg(ot
, 0, reg
);
4833 gen_op_mov_TN_reg(ot
, 1, rm
);
4834 gen_op_addl_T0_T1();
4835 gen_op_mov_reg_T1(ot
, reg
);
4836 gen_op_mov_reg_T0(ot
, rm
);
4838 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4839 gen_op_mov_TN_reg(ot
, 0, reg
);
4840 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4841 gen_op_addl_T0_T1();
4842 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4843 gen_op_mov_reg_T1(ot
, reg
);
4845 gen_op_update2_cc();
4846 s
->cc_op
= CC_OP_ADDB
+ ot
;
4849 case 0x1b1: /* cmpxchg Ev, Gv */
4852 TCGv t0
, t1
, t2
, a0
;
4857 ot
= dflag
+ OT_WORD
;
4858 modrm
= ldub_code(s
->pc
++);
4859 reg
= ((modrm
>> 3) & 7) | rex_r
;
4860 mod
= (modrm
>> 6) & 3;
4861 t0
= tcg_temp_local_new();
4862 t1
= tcg_temp_local_new();
4863 t2
= tcg_temp_local_new();
4864 a0
= tcg_temp_local_new();
4865 gen_op_mov_v_reg(ot
, t1
, reg
);
4867 rm
= (modrm
& 7) | REX_B(s
);
4868 gen_op_mov_v_reg(ot
, t0
, rm
);
4870 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4871 tcg_gen_mov_tl(a0
, cpu_A0
);
4872 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
4873 rm
= 0; /* avoid warning */
4875 label1
= gen_new_label();
4876 tcg_gen_sub_tl(t2
, cpu_regs
[R_EAX
], t0
);
4878 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
4880 label2
= gen_new_label();
4881 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4883 gen_set_label(label1
);
4884 gen_op_mov_reg_v(ot
, rm
, t1
);
4885 gen_set_label(label2
);
4887 tcg_gen_mov_tl(t1
, t0
);
4888 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4889 gen_set_label(label1
);
4891 gen_op_st_v(ot
+ s
->mem_index
, t1
, a0
);
4893 tcg_gen_mov_tl(cpu_cc_src
, t0
);
4894 tcg_gen_mov_tl(cpu_cc_dst
, t2
);
4895 s
->cc_op
= CC_OP_SUBB
+ ot
;
4902 case 0x1c7: /* cmpxchg8b */
4903 modrm
= ldub_code(s
->pc
++);
4904 mod
= (modrm
>> 6) & 3;
4905 if ((mod
== 3) || ((modrm
& 0x38) != 0x8))
4907 #ifdef TARGET_X86_64
4909 if (!(s
->cpuid_ext_features
& CPUID_EXT_CX16
))
4911 gen_jmp_im(pc_start
- s
->cs_base
);
4912 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4913 gen_op_set_cc_op(s
->cc_op
);
4914 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4915 gen_helper_cmpxchg16b(cpu_A0
);
4919 if (!(s
->cpuid_features
& CPUID_CX8
))
4921 gen_jmp_im(pc_start
- s
->cs_base
);
4922 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4923 gen_op_set_cc_op(s
->cc_op
);
4924 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4925 gen_helper_cmpxchg8b(cpu_A0
);
4927 s
->cc_op
= CC_OP_EFLAGS
;
4930 /**************************/
4932 case 0x50 ... 0x57: /* push */
4933 gen_op_mov_TN_reg(OT_LONG
, 0, (b
& 7) | REX_B(s
));
4936 case 0x58 ... 0x5f: /* pop */
4938 ot
= dflag
? OT_QUAD
: OT_WORD
;
4940 ot
= dflag
+ OT_WORD
;
4943 /* NOTE: order is important for pop %sp */
4945 gen_op_mov_reg_T0(ot
, (b
& 7) | REX_B(s
));
4947 case 0x60: /* pusha */
4952 case 0x61: /* popa */
4957 case 0x68: /* push Iv */
4960 ot
= dflag
? OT_QUAD
: OT_WORD
;
4962 ot
= dflag
+ OT_WORD
;
4965 val
= insn_get(s
, ot
);
4967 val
= (int8_t)insn_get(s
, OT_BYTE
);
4968 gen_op_movl_T0_im(val
);
4971 case 0x8f: /* pop Ev */
4973 ot
= dflag
? OT_QUAD
: OT_WORD
;
4975 ot
= dflag
+ OT_WORD
;
4977 modrm
= ldub_code(s
->pc
++);
4978 mod
= (modrm
>> 6) & 3;
4981 /* NOTE: order is important for pop %sp */
4983 rm
= (modrm
& 7) | REX_B(s
);
4984 gen_op_mov_reg_T0(ot
, rm
);
4986 /* NOTE: order is important too for MMU exceptions */
4987 s
->popl_esp_hack
= 1 << ot
;
4988 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
4989 s
->popl_esp_hack
= 0;
4993 case 0xc8: /* enter */
4996 val
= lduw_code(s
->pc
);
4998 level
= ldub_code(s
->pc
++);
4999 gen_enter(s
, val
, level
);
5002 case 0xc9: /* leave */
5003 /* XXX: exception not precise (ESP is updated before potential exception) */
5005 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EBP
);
5006 gen_op_mov_reg_T0(OT_QUAD
, R_ESP
);
5007 } else if (s
->ss32
) {
5008 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
5009 gen_op_mov_reg_T0(OT_LONG
, R_ESP
);
5011 gen_op_mov_TN_reg(OT_WORD
, 0, R_EBP
);
5012 gen_op_mov_reg_T0(OT_WORD
, R_ESP
);
5016 ot
= dflag
? OT_QUAD
: OT_WORD
;
5018 ot
= dflag
+ OT_WORD
;
5020 gen_op_mov_reg_T0(ot
, R_EBP
);
5023 case 0x06: /* push es */
5024 case 0x0e: /* push cs */
5025 case 0x16: /* push ss */
5026 case 0x1e: /* push ds */
5029 gen_op_movl_T0_seg(b
>> 3);
5032 case 0x1a0: /* push fs */
5033 case 0x1a8: /* push gs */
5034 gen_op_movl_T0_seg((b
>> 3) & 7);
5037 case 0x07: /* pop es */
5038 case 0x17: /* pop ss */
5039 case 0x1f: /* pop ds */
5044 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5047 /* if reg == SS, inhibit interrupts/trace. */
5048 /* If several instructions disable interrupts, only the
5050 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5051 gen_helper_set_inhibit_irq();
5055 gen_jmp_im(s
->pc
- s
->cs_base
);
5059 case 0x1a1: /* pop fs */
5060 case 0x1a9: /* pop gs */
5062 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
5065 gen_jmp_im(s
->pc
- s
->cs_base
);
5070 /**************************/
5073 case 0x89: /* mov Gv, Ev */
5077 ot
= dflag
+ OT_WORD
;
5078 modrm
= ldub_code(s
->pc
++);
5079 reg
= ((modrm
>> 3) & 7) | rex_r
;
5081 /* generate a generic store */
5082 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
5085 case 0xc7: /* mov Ev, Iv */
5089 ot
= dflag
+ OT_WORD
;
5090 modrm
= ldub_code(s
->pc
++);
5091 mod
= (modrm
>> 6) & 3;
5093 s
->rip_offset
= insn_const_size(ot
);
5094 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5096 val
= insn_get(s
, ot
);
5097 gen_op_movl_T0_im(val
);
5099 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5101 gen_op_mov_reg_T0(ot
, (modrm
& 7) | REX_B(s
));
5104 case 0x8b: /* mov Ev, Gv */
5108 ot
= OT_WORD
+ dflag
;
5109 modrm
= ldub_code(s
->pc
++);
5110 reg
= ((modrm
>> 3) & 7) | rex_r
;
5112 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5113 gen_op_mov_reg_T0(ot
, reg
);
5115 case 0x8e: /* mov seg, Gv */
5116 modrm
= ldub_code(s
->pc
++);
5117 reg
= (modrm
>> 3) & 7;
5118 if (reg
>= 6 || reg
== R_CS
)
5120 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5121 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5123 /* if reg == SS, inhibit interrupts/trace */
5124 /* If several instructions disable interrupts, only the
5126 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5127 gen_helper_set_inhibit_irq();
5131 gen_jmp_im(s
->pc
- s
->cs_base
);
5135 case 0x8c: /* mov Gv, seg */
5136 modrm
= ldub_code(s
->pc
++);
5137 reg
= (modrm
>> 3) & 7;
5138 mod
= (modrm
>> 6) & 3;
5141 gen_op_movl_T0_seg(reg
);
5143 ot
= OT_WORD
+ dflag
;
5146 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5149 case 0x1b6: /* movzbS Gv, Eb */
5150 case 0x1b7: /* movzwS Gv, Eb */
5151 case 0x1be: /* movsbS Gv, Eb */
5152 case 0x1bf: /* movswS Gv, Eb */
5155 /* d_ot is the size of destination */
5156 d_ot
= dflag
+ OT_WORD
;
5157 /* ot is the size of source */
5158 ot
= (b
& 1) + OT_BYTE
;
5159 modrm
= ldub_code(s
->pc
++);
5160 reg
= ((modrm
>> 3) & 7) | rex_r
;
5161 mod
= (modrm
>> 6) & 3;
5162 rm
= (modrm
& 7) | REX_B(s
);
5165 gen_op_mov_TN_reg(ot
, 0, rm
);
5166 switch(ot
| (b
& 8)) {
5168 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
5171 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
5174 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
5178 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
5181 gen_op_mov_reg_T0(d_ot
, reg
);
5183 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5185 gen_op_lds_T0_A0(ot
+ s
->mem_index
);
5187 gen_op_ldu_T0_A0(ot
+ s
->mem_index
);
5189 gen_op_mov_reg_T0(d_ot
, reg
);
5194 case 0x8d: /* lea */
5195 ot
= dflag
+ OT_WORD
;
5196 modrm
= ldub_code(s
->pc
++);
5197 mod
= (modrm
>> 6) & 3;
5200 reg
= ((modrm
>> 3) & 7) | rex_r
;
5201 /* we must ensure that no segment is added */
5205 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5207 gen_op_mov_reg_A0(ot
- OT_WORD
, reg
);
5210 case 0xa0: /* mov EAX, Ov */
5212 case 0xa2: /* mov Ov, EAX */
5215 target_ulong offset_addr
;
5220 ot
= dflag
+ OT_WORD
;
5221 #ifdef TARGET_X86_64
5222 if (s
->aflag
== 2) {
5223 offset_addr
= ldq_code(s
->pc
);
5225 gen_op_movq_A0_im(offset_addr
);
5230 offset_addr
= insn_get(s
, OT_LONG
);
5232 offset_addr
= insn_get(s
, OT_WORD
);
5234 gen_op_movl_A0_im(offset_addr
);
5236 gen_add_A0_ds_seg(s
);
5238 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
5239 gen_op_mov_reg_T0(ot
, R_EAX
);
5241 gen_op_mov_TN_reg(ot
, 0, R_EAX
);
5242 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5246 case 0xd7: /* xlat */
5247 #ifdef TARGET_X86_64
5248 if (s
->aflag
== 2) {
5249 gen_op_movq_A0_reg(R_EBX
);
5250 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
5251 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5252 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5256 gen_op_movl_A0_reg(R_EBX
);
5257 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
5258 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5259 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5261 gen_op_andl_A0_ffff();
5263 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
5265 gen_add_A0_ds_seg(s
);
5266 gen_op_ldu_T0_A0(OT_BYTE
+ s
->mem_index
);
5267 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
5269 case 0xb0 ... 0xb7: /* mov R, Ib */
5270 val
= insn_get(s
, OT_BYTE
);
5271 gen_op_movl_T0_im(val
);
5272 gen_op_mov_reg_T0(OT_BYTE
, (b
& 7) | REX_B(s
));
5274 case 0xb8 ... 0xbf: /* mov R, Iv */
5275 #ifdef TARGET_X86_64
5279 tmp
= ldq_code(s
->pc
);
5281 reg
= (b
& 7) | REX_B(s
);
5282 gen_movtl_T0_im(tmp
);
5283 gen_op_mov_reg_T0(OT_QUAD
, reg
);
5287 ot
= dflag
? OT_LONG
: OT_WORD
;
5288 val
= insn_get(s
, ot
);
5289 reg
= (b
& 7) | REX_B(s
);
5290 gen_op_movl_T0_im(val
);
5291 gen_op_mov_reg_T0(ot
, reg
);
5295 case 0x91 ... 0x97: /* xchg R, EAX */
5296 ot
= dflag
+ OT_WORD
;
5297 reg
= (b
& 7) | REX_B(s
);
5301 case 0x87: /* xchg Ev, Gv */
5305 ot
= dflag
+ OT_WORD
;
5306 modrm
= ldub_code(s
->pc
++);
5307 reg
= ((modrm
>> 3) & 7) | rex_r
;
5308 mod
= (modrm
>> 6) & 3;
5310 rm
= (modrm
& 7) | REX_B(s
);
5312 gen_op_mov_TN_reg(ot
, 0, reg
);
5313 gen_op_mov_TN_reg(ot
, 1, rm
);
5314 gen_op_mov_reg_T0(ot
, rm
);
5315 gen_op_mov_reg_T1(ot
, reg
);
5317 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5318 gen_op_mov_TN_reg(ot
, 0, reg
);
5319 /* for xchg, lock is implicit */
5320 if (!(prefixes
& PREFIX_LOCK
))
5322 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5323 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5324 if (!(prefixes
& PREFIX_LOCK
))
5325 gen_helper_unlock();
5326 gen_op_mov_reg_T1(ot
, reg
);
5329 case 0xc4: /* les Gv */
5334 case 0xc5: /* lds Gv */
5339 case 0x1b2: /* lss Gv */
5342 case 0x1b4: /* lfs Gv */
5345 case 0x1b5: /* lgs Gv */
5348 ot
= dflag
? OT_LONG
: OT_WORD
;
5349 modrm
= ldub_code(s
->pc
++);
5350 reg
= ((modrm
>> 3) & 7) | rex_r
;
5351 mod
= (modrm
>> 6) & 3;
5354 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5355 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5356 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
5357 /* load the segment first to handle exceptions properly */
5358 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
5359 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
5360 /* then put the data */
5361 gen_op_mov_reg_T1(ot
, reg
);
5363 gen_jmp_im(s
->pc
- s
->cs_base
);
5368 /************************/
5379 ot
= dflag
+ OT_WORD
;
5381 modrm
= ldub_code(s
->pc
++);
5382 mod
= (modrm
>> 6) & 3;
5383 op
= (modrm
>> 3) & 7;
5389 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5392 opreg
= (modrm
& 7) | REX_B(s
);
5397 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
5400 shift
= ldub_code(s
->pc
++);
5402 gen_shifti(s
, op
, ot
, opreg
, shift
);
5417 case 0x1a4: /* shld imm */
5421 case 0x1a5: /* shld cl */
5425 case 0x1ac: /* shrd imm */
5429 case 0x1ad: /* shrd cl */
5433 ot
= dflag
+ OT_WORD
;
5434 modrm
= ldub_code(s
->pc
++);
5435 mod
= (modrm
>> 6) & 3;
5436 rm
= (modrm
& 7) | REX_B(s
);
5437 reg
= ((modrm
>> 3) & 7) | rex_r
;
5439 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5444 gen_op_mov_TN_reg(ot
, 1, reg
);
5447 val
= ldub_code(s
->pc
++);
5448 tcg_gen_movi_tl(cpu_T3
, val
);
5450 tcg_gen_mov_tl(cpu_T3
, cpu_regs
[R_ECX
]);
5452 gen_shiftd_rm_T1_T3(s
, ot
, opreg
, op
);
5455 /************************/
5458 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
5459 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
5460 /* XXX: what to do if illegal op ? */
5461 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5464 modrm
= ldub_code(s
->pc
++);
5465 mod
= (modrm
>> 6) & 3;
5467 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
5470 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5472 case 0x00 ... 0x07: /* fxxxs */
5473 case 0x10 ... 0x17: /* fixxxl */
5474 case 0x20 ... 0x27: /* fxxxl */
5475 case 0x30 ... 0x37: /* fixxx */
5482 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5483 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5484 gen_helper_flds_FT0(cpu_tmp2_i32
);
5487 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5488 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5489 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5492 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5493 (s
->mem_index
>> 2) - 1);
5494 gen_helper_fldl_FT0(cpu_tmp1_i64
);
5498 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5499 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5500 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5504 gen_helper_fp_arith_ST0_FT0(op1
);
5506 /* fcomp needs pop */
5511 case 0x08: /* flds */
5512 case 0x0a: /* fsts */
5513 case 0x0b: /* fstps */
5514 case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
5515 case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
5516 case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
5521 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5522 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5523 gen_helper_flds_ST0(cpu_tmp2_i32
);
5526 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5527 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5528 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5531 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5532 (s
->mem_index
>> 2) - 1);
5533 gen_helper_fldl_ST0(cpu_tmp1_i64
);
5537 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5538 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5539 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5544 /* XXX: the corresponding CPUID bit must be tested ! */
5547 gen_helper_fisttl_ST0(cpu_tmp2_i32
);
5548 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5549 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5552 gen_helper_fisttll_ST0(cpu_tmp1_i64
);
5553 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5554 (s
->mem_index
>> 2) - 1);
5558 gen_helper_fistt_ST0(cpu_tmp2_i32
);
5559 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5560 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5568 gen_helper_fsts_ST0(cpu_tmp2_i32
);
5569 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5570 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5573 gen_helper_fistl_ST0(cpu_tmp2_i32
);
5574 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5575 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5578 gen_helper_fstl_ST0(cpu_tmp1_i64
);
5579 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5580 (s
->mem_index
>> 2) - 1);
5584 gen_helper_fist_ST0(cpu_tmp2_i32
);
5585 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5586 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5594 case 0x0c: /* fldenv mem */
5595 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5596 gen_op_set_cc_op(s
->cc_op
);
5597 gen_jmp_im(pc_start
- s
->cs_base
);
5599 cpu_A0
, tcg_const_i32(s
->dflag
));
5601 case 0x0d: /* fldcw mem */
5602 gen_op_ld_T0_A0(OT_WORD
+ s
->mem_index
);
5603 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5604 gen_helper_fldcw(cpu_tmp2_i32
);
5606 case 0x0e: /* fnstenv mem */
5607 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5608 gen_op_set_cc_op(s
->cc_op
);
5609 gen_jmp_im(pc_start
- s
->cs_base
);
5610 gen_helper_fstenv(cpu_A0
, tcg_const_i32(s
->dflag
));
5612 case 0x0f: /* fnstcw mem */
5613 gen_helper_fnstcw(cpu_tmp2_i32
);
5614 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5615 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5617 case 0x1d: /* fldt mem */
5618 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5619 gen_op_set_cc_op(s
->cc_op
);
5620 gen_jmp_im(pc_start
- s
->cs_base
);
5621 gen_helper_fldt_ST0(cpu_A0
);
5623 case 0x1f: /* fstpt mem */
5624 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5625 gen_op_set_cc_op(s
->cc_op
);
5626 gen_jmp_im(pc_start
- s
->cs_base
);
5627 gen_helper_fstt_ST0(cpu_A0
);
5630 case 0x2c: /* frstor mem */
5631 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5632 gen_op_set_cc_op(s
->cc_op
);
5633 gen_jmp_im(pc_start
- s
->cs_base
);
5634 gen_helper_frstor(cpu_A0
, tcg_const_i32(s
->dflag
));
5636 case 0x2e: /* fnsave mem */
5637 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5638 gen_op_set_cc_op(s
->cc_op
);
5639 gen_jmp_im(pc_start
- s
->cs_base
);
5640 gen_helper_fsave(cpu_A0
, tcg_const_i32(s
->dflag
));
5642 case 0x2f: /* fnstsw mem */
5643 gen_helper_fnstsw(cpu_tmp2_i32
);
5644 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5645 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5647 case 0x3c: /* fbld */
5648 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5649 gen_op_set_cc_op(s
->cc_op
);
5650 gen_jmp_im(pc_start
- s
->cs_base
);
5651 gen_helper_fbld_ST0(cpu_A0
);
5653 case 0x3e: /* fbstp */
5654 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5655 gen_op_set_cc_op(s
->cc_op
);
5656 gen_jmp_im(pc_start
- s
->cs_base
);
5657 gen_helper_fbst_ST0(cpu_A0
);
5660 case 0x3d: /* fildll */
5661 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5662 (s
->mem_index
>> 2) - 1);
5663 gen_helper_fildll_ST0(cpu_tmp1_i64
);
5665 case 0x3f: /* fistpll */
5666 gen_helper_fistll_ST0(cpu_tmp1_i64
);
5667 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5668 (s
->mem_index
>> 2) - 1);
5675 /* register float ops */
5679 case 0x08: /* fld sti */
5681 gen_helper_fmov_ST0_STN(tcg_const_i32((opreg
+ 1) & 7));
5683 case 0x09: /* fxchg sti */
5684 case 0x29: /* fxchg4 sti, undocumented op */
5685 case 0x39: /* fxchg7 sti, undocumented op */
5686 gen_helper_fxchg_ST0_STN(tcg_const_i32(opreg
));
5688 case 0x0a: /* grp d9/2 */
5691 /* check exceptions (FreeBSD FPU probe) */
5692 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5693 gen_op_set_cc_op(s
->cc_op
);
5694 gen_jmp_im(pc_start
- s
->cs_base
);
5701 case 0x0c: /* grp d9/4 */
5704 gen_helper_fchs_ST0();
5707 gen_helper_fabs_ST0();
5710 gen_helper_fldz_FT0();
5711 gen_helper_fcom_ST0_FT0();
5714 gen_helper_fxam_ST0();
5720 case 0x0d: /* grp d9/5 */
5725 gen_helper_fld1_ST0();
5729 gen_helper_fldl2t_ST0();
5733 gen_helper_fldl2e_ST0();
5737 gen_helper_fldpi_ST0();
5741 gen_helper_fldlg2_ST0();
5745 gen_helper_fldln2_ST0();
5749 gen_helper_fldz_ST0();
5756 case 0x0e: /* grp d9/6 */
5767 case 3: /* fpatan */
5768 gen_helper_fpatan();
5770 case 4: /* fxtract */
5771 gen_helper_fxtract();
5773 case 5: /* fprem1 */
5774 gen_helper_fprem1();
5776 case 6: /* fdecstp */
5777 gen_helper_fdecstp();
5780 case 7: /* fincstp */
5781 gen_helper_fincstp();
5785 case 0x0f: /* grp d9/7 */
5790 case 1: /* fyl2xp1 */
5791 gen_helper_fyl2xp1();
5796 case 3: /* fsincos */
5797 gen_helper_fsincos();
5799 case 5: /* fscale */
5800 gen_helper_fscale();
5802 case 4: /* frndint */
5803 gen_helper_frndint();
5814 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
5815 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
5816 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
5822 gen_helper_fp_arith_STN_ST0(op1
, opreg
);
5826 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5827 gen_helper_fp_arith_ST0_FT0(op1
);
5831 case 0x02: /* fcom */
5832 case 0x22: /* fcom2, undocumented op */
5833 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5834 gen_helper_fcom_ST0_FT0();
5836 case 0x03: /* fcomp */
5837 case 0x23: /* fcomp3, undocumented op */
5838 case 0x32: /* fcomp5, undocumented op */
5839 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5840 gen_helper_fcom_ST0_FT0();
5843 case 0x15: /* da/5 */
5845 case 1: /* fucompp */
5846 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5847 gen_helper_fucom_ST0_FT0();
5857 case 0: /* feni (287 only, just do nop here) */
5859 case 1: /* fdisi (287 only, just do nop here) */
5864 case 3: /* fninit */
5865 gen_helper_fninit();
5867 case 4: /* fsetpm (287 only, just do nop here) */
5873 case 0x1d: /* fucomi */
5874 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5875 gen_op_set_cc_op(s
->cc_op
);
5876 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5877 gen_helper_fucomi_ST0_FT0();
5878 s
->cc_op
= CC_OP_EFLAGS
;
5880 case 0x1e: /* fcomi */
5881 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5882 gen_op_set_cc_op(s
->cc_op
);
5883 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5884 gen_helper_fcomi_ST0_FT0();
5885 s
->cc_op
= CC_OP_EFLAGS
;
5887 case 0x28: /* ffree sti */
5888 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5890 case 0x2a: /* fst sti */
5891 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5893 case 0x2b: /* fstp sti */
5894 case 0x0b: /* fstp1 sti, undocumented op */
5895 case 0x3a: /* fstp8 sti, undocumented op */
5896 case 0x3b: /* fstp9 sti, undocumented op */
5897 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5900 case 0x2c: /* fucom st(i) */
5901 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5902 gen_helper_fucom_ST0_FT0();
5904 case 0x2d: /* fucomp st(i) */
5905 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5906 gen_helper_fucom_ST0_FT0();
5909 case 0x33: /* de/3 */
5911 case 1: /* fcompp */
5912 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5913 gen_helper_fcom_ST0_FT0();
5921 case 0x38: /* ffreep sti, undocumented op */
5922 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5925 case 0x3c: /* df/4 */
5928 gen_helper_fnstsw(cpu_tmp2_i32
);
5929 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5930 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
5936 case 0x3d: /* fucomip */
5937 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5938 gen_op_set_cc_op(s
->cc_op
);
5939 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5940 gen_helper_fucomi_ST0_FT0();
5942 s
->cc_op
= CC_OP_EFLAGS
;
5944 case 0x3e: /* fcomip */
5945 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5946 gen_op_set_cc_op(s
->cc_op
);
5947 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5948 gen_helper_fcomi_ST0_FT0();
5950 s
->cc_op
= CC_OP_EFLAGS
;
5952 case 0x10 ... 0x13: /* fcmovxx */
5956 static const uint8_t fcmov_cc
[8] = {
5962 op1
= fcmov_cc
[op
& 3] | (((op
>> 3) & 1) ^ 1);
5963 l1
= gen_new_label();
5964 gen_jcc1(s
, s
->cc_op
, op1
, l1
);
5965 gen_helper_fmov_ST0_STN(tcg_const_i32(opreg
));
5974 /************************/
5977 case 0xa4: /* movsS */
5982 ot
= dflag
+ OT_WORD
;
5984 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5985 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5991 case 0xaa: /* stosS */
5996 ot
= dflag
+ OT_WORD
;
5998 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5999 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6004 case 0xac: /* lodsS */
6009 ot
= dflag
+ OT_WORD
;
6010 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6011 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6016 case 0xae: /* scasS */
6021 ot
= dflag
+ OT_WORD
;
6022 if (prefixes
& PREFIX_REPNZ
) {
6023 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6024 } else if (prefixes
& PREFIX_REPZ
) {
6025 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6028 s
->cc_op
= CC_OP_SUBB
+ ot
;
6032 case 0xa6: /* cmpsS */
6037 ot
= dflag
+ OT_WORD
;
6038 if (prefixes
& PREFIX_REPNZ
) {
6039 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6040 } else if (prefixes
& PREFIX_REPZ
) {
6041 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6044 s
->cc_op
= CC_OP_SUBB
+ ot
;
6047 case 0x6c: /* insS */
6052 ot
= dflag
? OT_LONG
: OT_WORD
;
6053 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6054 gen_op_andl_T0_ffff();
6055 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6056 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
) | 4);
6057 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6058 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6062 gen_jmp(s
, s
->pc
- s
->cs_base
);
6066 case 0x6e: /* outsS */
6071 ot
= dflag
? OT_LONG
: OT_WORD
;
6072 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6073 gen_op_andl_T0_ffff();
6074 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6075 svm_is_rep(prefixes
) | 4);
6076 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6077 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6081 gen_jmp(s
, s
->pc
- s
->cs_base
);
6086 /************************/
6094 ot
= dflag
? OT_LONG
: OT_WORD
;
6095 val
= ldub_code(s
->pc
++);
6096 gen_op_movl_T0_im(val
);
6097 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6098 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6101 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6102 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6103 gen_op_mov_reg_T1(ot
, R_EAX
);
6106 gen_jmp(s
, s
->pc
- s
->cs_base
);
6114 ot
= dflag
? OT_LONG
: OT_WORD
;
6115 val
= ldub_code(s
->pc
++);
6116 gen_op_movl_T0_im(val
);
6117 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6118 svm_is_rep(prefixes
));
6119 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6123 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6124 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6125 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6126 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6129 gen_jmp(s
, s
->pc
- s
->cs_base
);
6137 ot
= dflag
? OT_LONG
: OT_WORD
;
6138 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6139 gen_op_andl_T0_ffff();
6140 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6141 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6144 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6145 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6146 gen_op_mov_reg_T1(ot
, R_EAX
);
6149 gen_jmp(s
, s
->pc
- s
->cs_base
);
6157 ot
= dflag
? OT_LONG
: OT_WORD
;
6158 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6159 gen_op_andl_T0_ffff();
6160 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6161 svm_is_rep(prefixes
));
6162 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6166 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6167 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6168 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6169 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6172 gen_jmp(s
, s
->pc
- s
->cs_base
);
6176 /************************/
6178 case 0xc2: /* ret im */
6179 val
= ldsw_code(s
->pc
);
6182 if (CODE64(s
) && s
->dflag
)
6184 gen_stack_update(s
, val
+ (2 << s
->dflag
));
6186 gen_op_andl_T0_ffff();
6190 case 0xc3: /* ret */
6194 gen_op_andl_T0_ffff();
6198 case 0xca: /* lret im */
6199 val
= ldsw_code(s
->pc
);
6202 if (s
->pe
&& !s
->vm86
) {
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_lret_protected(tcg_const_i32(s
->dflag
),
6207 tcg_const_i32(val
));
6211 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6213 gen_op_andl_T0_ffff();
6214 /* NOTE: keeping EIP updated is not a problem in case of
6218 gen_op_addl_A0_im(2 << s
->dflag
);
6219 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6220 gen_op_movl_seg_T0_vm(R_CS
);
6221 /* add stack offset */
6222 gen_stack_update(s
, val
+ (4 << s
->dflag
));
6226 case 0xcb: /* lret */
6229 case 0xcf: /* iret */
6230 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IRET
);
6233 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6234 s
->cc_op
= CC_OP_EFLAGS
;
6235 } else if (s
->vm86
) {
6237 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6239 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6240 s
->cc_op
= CC_OP_EFLAGS
;
6243 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6244 gen_op_set_cc_op(s
->cc_op
);
6245 gen_jmp_im(pc_start
- s
->cs_base
);
6246 gen_helper_iret_protected(tcg_const_i32(s
->dflag
),
6247 tcg_const_i32(s
->pc
- s
->cs_base
));
6248 s
->cc_op
= CC_OP_EFLAGS
;
6252 case 0xe8: /* call im */
6255 tval
= (int32_t)insn_get(s
, OT_LONG
);
6257 tval
= (int16_t)insn_get(s
, OT_WORD
);
6258 next_eip
= s
->pc
- s
->cs_base
;
6262 gen_movtl_T0_im(next_eip
);
6267 case 0x9a: /* lcall im */
6269 unsigned int selector
, offset
;
6273 ot
= dflag
? OT_LONG
: OT_WORD
;
6274 offset
= insn_get(s
, ot
);
6275 selector
= insn_get(s
, OT_WORD
);
6277 gen_op_movl_T0_im(selector
);
6278 gen_op_movl_T1_imu(offset
);
6281 case 0xe9: /* jmp im */
6283 tval
= (int32_t)insn_get(s
, OT_LONG
);
6285 tval
= (int16_t)insn_get(s
, OT_WORD
);
6286 tval
+= s
->pc
- s
->cs_base
;
6293 case 0xea: /* ljmp im */
6295 unsigned int selector
, offset
;
6299 ot
= dflag
? OT_LONG
: OT_WORD
;
6300 offset
= insn_get(s
, ot
);
6301 selector
= insn_get(s
, OT_WORD
);
6303 gen_op_movl_T0_im(selector
);
6304 gen_op_movl_T1_imu(offset
);
6307 case 0xeb: /* jmp Jb */
6308 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6309 tval
+= s
->pc
- s
->cs_base
;
6314 case 0x70 ... 0x7f: /* jcc Jb */
6315 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6317 case 0x180 ... 0x18f: /* jcc Jv */
6319 tval
= (int32_t)insn_get(s
, OT_LONG
);
6321 tval
= (int16_t)insn_get(s
, OT_WORD
);
6324 next_eip
= s
->pc
- s
->cs_base
;
6328 gen_jcc(s
, b
, tval
, next_eip
);
6331 case 0x190 ... 0x19f: /* setcc Gv */
6332 modrm
= ldub_code(s
->pc
++);
6334 gen_ldst_modrm(s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
6336 case 0x140 ... 0x14f: /* cmov Gv, Ev */
6341 ot
= dflag
+ OT_WORD
;
6342 modrm
= ldub_code(s
->pc
++);
6343 reg
= ((modrm
>> 3) & 7) | rex_r
;
6344 mod
= (modrm
>> 6) & 3;
6345 t0
= tcg_temp_local_new();
6347 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6348 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
6350 rm
= (modrm
& 7) | REX_B(s
);
6351 gen_op_mov_v_reg(ot
, t0
, rm
);
6353 #ifdef TARGET_X86_64
6354 if (ot
== OT_LONG
) {
6355 /* XXX: specific Intel behaviour ? */
6356 l1
= gen_new_label();
6357 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6358 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
6360 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_regs
[reg
]);
6364 l1
= gen_new_label();
6365 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6366 gen_op_mov_reg_v(ot
, reg
, t0
);
6373 /************************/
6375 case 0x9c: /* pushf */
6376 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PUSHF
);
6377 if (s
->vm86
&& s
->iopl
!= 3) {
6378 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6380 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6381 gen_op_set_cc_op(s
->cc_op
);
6382 gen_helper_read_eflags(cpu_T
[0]);
6386 case 0x9d: /* popf */
6387 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_POPF
);
6388 if (s
->vm86
&& s
->iopl
!= 3) {
6389 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6394 gen_helper_write_eflags(cpu_T
[0],
6395 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
)));
6397 gen_helper_write_eflags(cpu_T
[0],
6398 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
) & 0xffff));
6401 if (s
->cpl
<= s
->iopl
) {
6403 gen_helper_write_eflags(cpu_T
[0],
6404 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
)));
6406 gen_helper_write_eflags(cpu_T
[0],
6407 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
) & 0xffff));
6411 gen_helper_write_eflags(cpu_T
[0],
6412 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
)));
6414 gen_helper_write_eflags(cpu_T
[0],
6415 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
) & 0xffff));
6420 s
->cc_op
= CC_OP_EFLAGS
;
6421 /* abort translation because TF flag may change */
6422 gen_jmp_im(s
->pc
- s
->cs_base
);
6426 case 0x9e: /* sahf */
6427 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6429 gen_op_mov_TN_reg(OT_BYTE
, 0, R_AH
);
6430 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6431 gen_op_set_cc_op(s
->cc_op
);
6432 gen_compute_eflags(cpu_cc_src
);
6433 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, CC_O
);
6434 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
6435 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_T
[0]);
6436 s
->cc_op
= CC_OP_EFLAGS
;
6438 case 0x9f: /* lahf */
6439 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6441 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6442 gen_op_set_cc_op(s
->cc_op
);
6443 gen_compute_eflags(cpu_T
[0]);
6444 /* Note: gen_compute_eflags() only gives the condition codes */
6445 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], 0x02);
6446 gen_op_mov_reg_T0(OT_BYTE
, R_AH
);
6448 case 0xf5: /* cmc */
6449 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6450 gen_op_set_cc_op(s
->cc_op
);
6451 gen_compute_eflags(cpu_cc_src
);
6452 tcg_gen_xori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6453 s
->cc_op
= CC_OP_EFLAGS
;
6455 case 0xf8: /* clc */
6456 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6457 gen_op_set_cc_op(s
->cc_op
);
6458 gen_compute_eflags(cpu_cc_src
);
6459 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_C
);
6460 s
->cc_op
= CC_OP_EFLAGS
;
6462 case 0xf9: /* stc */
6463 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6464 gen_op_set_cc_op(s
->cc_op
);
6465 gen_compute_eflags(cpu_cc_src
);
6466 tcg_gen_ori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6467 s
->cc_op
= CC_OP_EFLAGS
;
6469 case 0xfc: /* cld */
6470 tcg_gen_movi_i32(cpu_tmp2_i32
, 1);
6471 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6473 case 0xfd: /* std */
6474 tcg_gen_movi_i32(cpu_tmp2_i32
, -1);
6475 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6478 /************************/
6479 /* bit operations */
6480 case 0x1ba: /* bt/bts/btr/btc Gv, im */
6481 ot
= dflag
+ OT_WORD
;
6482 modrm
= ldub_code(s
->pc
++);
6483 op
= (modrm
>> 3) & 7;
6484 mod
= (modrm
>> 6) & 3;
6485 rm
= (modrm
& 7) | REX_B(s
);
6488 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6489 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6491 gen_op_mov_TN_reg(ot
, 0, rm
);
6494 val
= ldub_code(s
->pc
++);
6495 gen_op_movl_T1_im(val
);
6500 case 0x1a3: /* bt Gv, Ev */
6503 case 0x1ab: /* bts */
6506 case 0x1b3: /* btr */
6509 case 0x1bb: /* btc */
6512 ot
= dflag
+ OT_WORD
;
6513 modrm
= ldub_code(s
->pc
++);
6514 reg
= ((modrm
>> 3) & 7) | rex_r
;
6515 mod
= (modrm
>> 6) & 3;
6516 rm
= (modrm
& 7) | REX_B(s
);
6517 gen_op_mov_TN_reg(OT_LONG
, 1, reg
);
6519 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6520 /* specific case: we need to add a displacement */
6521 gen_exts(ot
, cpu_T
[1]);
6522 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[1], 3 + ot
);
6523 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, ot
);
6524 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
6525 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6527 gen_op_mov_TN_reg(ot
, 0, rm
);
6530 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], (1 << (3 + ot
)) - 1);
6533 tcg_gen_shr_tl(cpu_cc_src
, cpu_T
[0], cpu_T
[1]);
6534 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6537 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6538 tcg_gen_movi_tl(cpu_tmp0
, 1);
6539 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6540 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6543 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6544 tcg_gen_movi_tl(cpu_tmp0
, 1);
6545 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6546 tcg_gen_not_tl(cpu_tmp0
, cpu_tmp0
);
6547 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6551 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6552 tcg_gen_movi_tl(cpu_tmp0
, 1);
6553 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6554 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6557 s
->cc_op
= CC_OP_SARB
+ ot
;
6560 gen_op_st_T0_A0(ot
+ s
->mem_index
);
6562 gen_op_mov_reg_T0(ot
, rm
);
6563 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
6564 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6567 case 0x1bc: /* bsf */
6568 case 0x1bd: /* bsr */
6573 ot
= dflag
+ OT_WORD
;
6574 modrm
= ldub_code(s
->pc
++);
6575 reg
= ((modrm
>> 3) & 7) | rex_r
;
6576 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
6577 gen_extu(ot
, cpu_T
[0]);
6578 label1
= gen_new_label();
6579 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6580 t0
= tcg_temp_local_new();
6581 tcg_gen_mov_tl(t0
, cpu_T
[0]);
6582 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, label1
);
6584 gen_helper_bsr(cpu_T
[0], t0
);
6586 gen_helper_bsf(cpu_T
[0], t0
);
6588 gen_op_mov_reg_T0(ot
, reg
);
6589 tcg_gen_movi_tl(cpu_cc_dst
, 1);
6590 gen_set_label(label1
);
6591 tcg_gen_discard_tl(cpu_cc_src
);
6592 s
->cc_op
= CC_OP_LOGICB
+ ot
;
6596 /************************/
6598 case 0x27: /* daa */
6601 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6602 gen_op_set_cc_op(s
->cc_op
);
6604 s
->cc_op
= CC_OP_EFLAGS
;
6606 case 0x2f: /* das */
6609 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6610 gen_op_set_cc_op(s
->cc_op
);
6612 s
->cc_op
= CC_OP_EFLAGS
;
6614 case 0x37: /* aaa */
6617 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6618 gen_op_set_cc_op(s
->cc_op
);
6620 s
->cc_op
= CC_OP_EFLAGS
;
6622 case 0x3f: /* aas */
6625 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6626 gen_op_set_cc_op(s
->cc_op
);
6628 s
->cc_op
= CC_OP_EFLAGS
;
6630 case 0xd4: /* aam */
6633 val
= ldub_code(s
->pc
++);
6635 gen_exception(s
, EXCP00_DIVZ
, pc_start
- s
->cs_base
);
6637 gen_helper_aam(tcg_const_i32(val
));
6638 s
->cc_op
= CC_OP_LOGICB
;
6641 case 0xd5: /* aad */
6644 val
= ldub_code(s
->pc
++);
6645 gen_helper_aad(tcg_const_i32(val
));
6646 s
->cc_op
= CC_OP_LOGICB
;
6648 /************************/
6650 case 0x90: /* nop */
6651 /* XXX: xchg + rex handling */
6652 /* XXX: correct lock test for all insn */
6653 if (prefixes
& PREFIX_LOCK
)
6655 if (prefixes
& PREFIX_REPZ
) {
6656 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PAUSE
);
6659 case 0x9b: /* fwait */
6660 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
6661 (HF_MP_MASK
| HF_TS_MASK
)) {
6662 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
6664 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6665 gen_op_set_cc_op(s
->cc_op
);
6666 gen_jmp_im(pc_start
- s
->cs_base
);
6670 case 0xcc: /* int3 */
6671 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6673 case 0xcd: /* int N */
6674 val
= ldub_code(s
->pc
++);
6675 if (s
->vm86
&& s
->iopl
!= 3) {
6676 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6678 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6681 case 0xce: /* into */
6684 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6685 gen_op_set_cc_op(s
->cc_op
);
6686 gen_jmp_im(pc_start
- s
->cs_base
);
6687 gen_helper_into(tcg_const_i32(s
->pc
- pc_start
));
6690 case 0xf1: /* icebp (undocumented, exits to external debugger) */
6691 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_ICEBP
);
6693 gen_debug(s
, pc_start
- s
->cs_base
);
6696 tb_flush(cpu_single_env
);
6697 cpu_set_log(CPU_LOG_INT
| CPU_LOG_TB_IN_ASM
);
6701 case 0xfa: /* cli */
6703 if (s
->cpl
<= s
->iopl
) {
6706 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6712 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6716 case 0xfb: /* sti */
6718 if (s
->cpl
<= s
->iopl
) {
6721 /* interruptions are enabled only the first insn after sti */
6722 /* If several instructions disable interrupts, only the
6724 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
6725 gen_helper_set_inhibit_irq();
6726 /* give a chance to handle pending irqs */
6727 gen_jmp_im(s
->pc
- s
->cs_base
);
6730 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6736 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6740 case 0x62: /* bound */
6743 ot
= dflag
? OT_LONG
: OT_WORD
;
6744 modrm
= ldub_code(s
->pc
++);
6745 reg
= (modrm
>> 3) & 7;
6746 mod
= (modrm
>> 6) & 3;
6749 gen_op_mov_TN_reg(ot
, 0, reg
);
6750 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6751 gen_jmp_im(pc_start
- s
->cs_base
);
6752 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6754 gen_helper_boundw(cpu_A0
, cpu_tmp2_i32
);
6756 gen_helper_boundl(cpu_A0
, cpu_tmp2_i32
);
6758 case 0x1c8 ... 0x1cf: /* bswap reg */
6759 reg
= (b
& 7) | REX_B(s
);
6760 #ifdef TARGET_X86_64
6762 gen_op_mov_TN_reg(OT_QUAD
, 0, reg
);
6763 tcg_gen_bswap64_i64(cpu_T
[0], cpu_T
[0]);
6764 gen_op_mov_reg_T0(OT_QUAD
, reg
);
6768 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
6769 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
6770 tcg_gen_bswap32_tl(cpu_T
[0], cpu_T
[0]);
6771 gen_op_mov_reg_T0(OT_LONG
, reg
);
6774 case 0xd6: /* salc */
6777 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6778 gen_op_set_cc_op(s
->cc_op
);
6779 gen_compute_eflags_c(cpu_T
[0]);
6780 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
6781 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
6783 case 0xe0: /* loopnz */
6784 case 0xe1: /* loopz */
6785 case 0xe2: /* loop */
6786 case 0xe3: /* jecxz */
6790 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6791 next_eip
= s
->pc
- s
->cs_base
;
6796 l1
= gen_new_label();
6797 l2
= gen_new_label();
6798 l3
= gen_new_label();
6801 case 0: /* loopnz */
6803 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6804 gen_op_set_cc_op(s
->cc_op
);
6805 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6806 gen_op_jz_ecx(s
->aflag
, l3
);
6807 gen_compute_eflags(cpu_tmp0
);
6808 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_Z
);
6810 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, l1
);
6812 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, l1
);
6816 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6817 gen_op_jnz_ecx(s
->aflag
, l1
);
6821 gen_op_jz_ecx(s
->aflag
, l1
);
6826 gen_jmp_im(next_eip
);
6835 case 0x130: /* wrmsr */
6836 case 0x132: /* rdmsr */
6838 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6840 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6841 gen_op_set_cc_op(s
->cc_op
);
6842 gen_jmp_im(pc_start
- s
->cs_base
);
6850 case 0x131: /* rdtsc */
6851 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6852 gen_op_set_cc_op(s
->cc_op
);
6853 gen_jmp_im(pc_start
- s
->cs_base
);
6859 gen_jmp(s
, s
->pc
- s
->cs_base
);
6862 case 0x133: /* rdpmc */
6863 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6864 gen_op_set_cc_op(s
->cc_op
);
6865 gen_jmp_im(pc_start
- s
->cs_base
);
6868 case 0x134: /* sysenter */
6869 /* For Intel SYSENTER is valid on 64-bit */
6870 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6873 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6875 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6876 gen_op_set_cc_op(s
->cc_op
);
6877 s
->cc_op
= CC_OP_DYNAMIC
;
6879 gen_jmp_im(pc_start
- s
->cs_base
);
6880 gen_helper_sysenter();
6884 case 0x135: /* sysexit */
6885 /* For Intel SYSEXIT is valid on 64-bit */
6886 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6889 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6891 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6892 gen_op_set_cc_op(s
->cc_op
);
6893 s
->cc_op
= CC_OP_DYNAMIC
;
6895 gen_jmp_im(pc_start
- s
->cs_base
);
6896 gen_helper_sysexit(tcg_const_i32(dflag
));
6900 #ifdef TARGET_X86_64
6901 case 0x105: /* syscall */
6902 /* XXX: is it usable in real mode ? */
6903 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6904 gen_op_set_cc_op(s
->cc_op
);
6905 s
->cc_op
= CC_OP_DYNAMIC
;
6907 gen_jmp_im(pc_start
- s
->cs_base
);
6908 gen_helper_syscall(tcg_const_i32(s
->pc
- pc_start
));
6911 case 0x107: /* sysret */
6913 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6915 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6916 gen_op_set_cc_op(s
->cc_op
);
6917 s
->cc_op
= CC_OP_DYNAMIC
;
6919 gen_jmp_im(pc_start
- s
->cs_base
);
6920 gen_helper_sysret(tcg_const_i32(s
->dflag
));
6921 /* condition codes are modified only in long mode */
6923 s
->cc_op
= CC_OP_EFLAGS
;
6928 case 0x1a2: /* cpuid */
6929 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6930 gen_op_set_cc_op(s
->cc_op
);
6931 gen_jmp_im(pc_start
- s
->cs_base
);
6934 case 0xf4: /* hlt */
6936 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6938 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6939 gen_op_set_cc_op(s
->cc_op
);
6940 gen_jmp_im(pc_start
- s
->cs_base
);
6941 gen_helper_hlt(tcg_const_i32(s
->pc
- pc_start
));
6946 modrm
= ldub_code(s
->pc
++);
6947 mod
= (modrm
>> 6) & 3;
6948 op
= (modrm
>> 3) & 7;
6951 if (!s
->pe
|| s
->vm86
)
6953 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_READ
);
6954 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,ldt
.selector
));
6958 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6961 if (!s
->pe
|| s
->vm86
)
6964 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6966 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_WRITE
);
6967 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6968 gen_jmp_im(pc_start
- s
->cs_base
);
6969 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6970 gen_helper_lldt(cpu_tmp2_i32
);
6974 if (!s
->pe
|| s
->vm86
)
6976 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_READ
);
6977 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,tr
.selector
));
6981 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6984 if (!s
->pe
|| s
->vm86
)
6987 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6989 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_WRITE
);
6990 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6991 gen_jmp_im(pc_start
- s
->cs_base
);
6992 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6993 gen_helper_ltr(cpu_tmp2_i32
);
6998 if (!s
->pe
|| s
->vm86
)
7000 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7001 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7002 gen_op_set_cc_op(s
->cc_op
);
7004 gen_helper_verr(cpu_T
[0]);
7006 gen_helper_verw(cpu_T
[0]);
7007 s
->cc_op
= CC_OP_EFLAGS
;
7014 modrm
= ldub_code(s
->pc
++);
7015 mod
= (modrm
>> 6) & 3;
7016 op
= (modrm
>> 3) & 7;
7022 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_GDTR_READ
);
7023 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7024 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.limit
));
7025 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7026 gen_add_A0_im(s
, 2);
7027 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.base
));
7029 gen_op_andl_T0_im(0xffffff);
7030 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7035 case 0: /* monitor */
7036 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7039 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7040 gen_op_set_cc_op(s
->cc_op
);
7041 gen_jmp_im(pc_start
- s
->cs_base
);
7042 #ifdef TARGET_X86_64
7043 if (s
->aflag
== 2) {
7044 gen_op_movq_A0_reg(R_EAX
);
7048 gen_op_movl_A0_reg(R_EAX
);
7050 gen_op_andl_A0_ffff();
7052 gen_add_A0_ds_seg(s
);
7053 gen_helper_monitor(cpu_A0
);
7056 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7059 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7060 gen_op_set_cc_op(s
->cc_op
);
7061 s
->cc_op
= CC_OP_DYNAMIC
;
7063 gen_jmp_im(pc_start
- s
->cs_base
);
7064 gen_helper_mwait(tcg_const_i32(s
->pc
- pc_start
));
7071 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IDTR_READ
);
7072 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7073 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.limit
));
7074 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7075 gen_add_A0_im(s
, 2);
7076 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.base
));
7078 gen_op_andl_T0_im(0xffffff);
7079 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7085 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7086 gen_op_set_cc_op(s
->cc_op
);
7087 gen_jmp_im(pc_start
- s
->cs_base
);
7090 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7093 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7096 gen_helper_vmrun(tcg_const_i32(s
->aflag
),
7097 tcg_const_i32(s
->pc
- pc_start
));
7102 case 1: /* VMMCALL */
7103 if (!(s
->flags
& HF_SVME_MASK
))
7105 gen_helper_vmmcall();
7107 case 2: /* VMLOAD */
7108 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7111 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7114 gen_helper_vmload(tcg_const_i32(s
->aflag
));
7117 case 3: /* VMSAVE */
7118 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7121 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7124 gen_helper_vmsave(tcg_const_i32(s
->aflag
));
7128 if ((!(s
->flags
& HF_SVME_MASK
) &&
7129 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7133 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7140 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7143 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7149 case 6: /* SKINIT */
7150 if ((!(s
->flags
& HF_SVME_MASK
) &&
7151 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7154 gen_helper_skinit();
7156 case 7: /* INVLPGA */
7157 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7160 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7163 gen_helper_invlpga(tcg_const_i32(s
->aflag
));
7169 } else if (s
->cpl
!= 0) {
7170 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7172 gen_svm_check_intercept(s
, pc_start
,
7173 op
==2 ? SVM_EXIT_GDTR_WRITE
: SVM_EXIT_IDTR_WRITE
);
7174 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7175 gen_op_ld_T1_A0(OT_WORD
+ s
->mem_index
);
7176 gen_add_A0_im(s
, 2);
7177 gen_op_ld_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7179 gen_op_andl_T0_im(0xffffff);
7181 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,gdt
.base
));
7182 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,gdt
.limit
));
7184 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,idt
.base
));
7185 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,idt
.limit
));
7190 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_CR0
);
7191 #if defined TARGET_X86_64 && defined HOST_WORDS_BIGENDIAN
7192 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]) + 4);
7194 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]));
7196 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 1);
7200 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7202 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7203 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7204 gen_helper_lmsw(cpu_T
[0]);
7205 gen_jmp_im(s
->pc
- s
->cs_base
);
7210 if (mod
!= 3) { /* invlpg */
7212 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7214 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7215 gen_op_set_cc_op(s
->cc_op
);
7216 gen_jmp_im(pc_start
- s
->cs_base
);
7217 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7218 gen_helper_invlpg(cpu_A0
);
7219 gen_jmp_im(s
->pc
- s
->cs_base
);
7224 case 0: /* swapgs */
7225 #ifdef TARGET_X86_64
7228 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7230 tcg_gen_ld_tl(cpu_T
[0], cpu_env
,
7231 offsetof(CPUX86State
,segs
[R_GS
].base
));
7232 tcg_gen_ld_tl(cpu_T
[1], cpu_env
,
7233 offsetof(CPUX86State
,kernelgsbase
));
7234 tcg_gen_st_tl(cpu_T
[1], cpu_env
,
7235 offsetof(CPUX86State
,segs
[R_GS
].base
));
7236 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
7237 offsetof(CPUX86State
,kernelgsbase
));
7245 case 1: /* rdtscp */
7246 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_RDTSCP
))
7248 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7249 gen_op_set_cc_op(s
->cc_op
);
7250 gen_jmp_im(pc_start
- s
->cs_base
);
7253 gen_helper_rdtscp();
7256 gen_jmp(s
, s
->pc
- s
->cs_base
);
7268 case 0x108: /* invd */
7269 case 0x109: /* wbinvd */
7271 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7273 gen_svm_check_intercept(s
, pc_start
, (b
& 2) ? SVM_EXIT_INVD
: SVM_EXIT_WBINVD
);
7277 case 0x63: /* arpl or movslS (x86_64) */
7278 #ifdef TARGET_X86_64
7281 /* d_ot is the size of destination */
7282 d_ot
= dflag
+ OT_WORD
;
7284 modrm
= ldub_code(s
->pc
++);
7285 reg
= ((modrm
>> 3) & 7) | rex_r
;
7286 mod
= (modrm
>> 6) & 3;
7287 rm
= (modrm
& 7) | REX_B(s
);
7290 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
7292 if (d_ot
== OT_QUAD
)
7293 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
7294 gen_op_mov_reg_T0(d_ot
, reg
);
7296 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7297 if (d_ot
== OT_QUAD
) {
7298 gen_op_lds_T0_A0(OT_LONG
+ s
->mem_index
);
7300 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7302 gen_op_mov_reg_T0(d_ot
, reg
);
7310 if (!s
->pe
|| s
->vm86
)
7312 t0
= tcg_temp_local_new();
7313 t1
= tcg_temp_local_new();
7314 t2
= tcg_temp_local_new();
7316 modrm
= ldub_code(s
->pc
++);
7317 reg
= (modrm
>> 3) & 7;
7318 mod
= (modrm
>> 6) & 3;
7321 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7322 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7324 gen_op_mov_v_reg(ot
, t0
, rm
);
7326 gen_op_mov_v_reg(ot
, t1
, reg
);
7327 tcg_gen_andi_tl(cpu_tmp0
, t0
, 3);
7328 tcg_gen_andi_tl(t1
, t1
, 3);
7329 tcg_gen_movi_tl(t2
, 0);
7330 label1
= gen_new_label();
7331 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_tmp0
, t1
, label1
);
7332 tcg_gen_andi_tl(t0
, t0
, ~3);
7333 tcg_gen_or_tl(t0
, t0
, t1
);
7334 tcg_gen_movi_tl(t2
, CC_Z
);
7335 gen_set_label(label1
);
7337 gen_op_st_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7339 gen_op_mov_reg_v(ot
, rm
, t0
);
7341 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7342 gen_op_set_cc_op(s
->cc_op
);
7343 gen_compute_eflags(cpu_cc_src
);
7344 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_Z
);
7345 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t2
);
7346 s
->cc_op
= CC_OP_EFLAGS
;
7352 case 0x102: /* lar */
7353 case 0x103: /* lsl */
7357 if (!s
->pe
|| s
->vm86
)
7359 ot
= dflag
? OT_LONG
: OT_WORD
;
7360 modrm
= ldub_code(s
->pc
++);
7361 reg
= ((modrm
>> 3) & 7) | rex_r
;
7362 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7363 t0
= tcg_temp_local_new();
7364 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7365 gen_op_set_cc_op(s
->cc_op
);
7367 gen_helper_lar(t0
, cpu_T
[0]);
7369 gen_helper_lsl(t0
, cpu_T
[0]);
7370 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_src
, CC_Z
);
7371 label1
= gen_new_label();
7372 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
7373 gen_op_mov_reg_v(ot
, reg
, t0
);
7374 gen_set_label(label1
);
7375 s
->cc_op
= CC_OP_EFLAGS
;
7380 modrm
= ldub_code(s
->pc
++);
7381 mod
= (modrm
>> 6) & 3;
7382 op
= (modrm
>> 3) & 7;
7384 case 0: /* prefetchnta */
7385 case 1: /* prefetchnt0 */
7386 case 2: /* prefetchnt0 */
7387 case 3: /* prefetchnt0 */
7390 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7391 /* nothing more to do */
7393 default: /* nop (multi byte) */
7394 gen_nop_modrm(s
, modrm
);
7398 case 0x119 ... 0x11f: /* nop (multi byte) */
7399 modrm
= ldub_code(s
->pc
++);
7400 gen_nop_modrm(s
, modrm
);
7402 case 0x120: /* mov reg, crN */
7403 case 0x122: /* mov crN, reg */
7405 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7407 modrm
= ldub_code(s
->pc
++);
7408 if ((modrm
& 0xc0) != 0xc0)
7410 rm
= (modrm
& 7) | REX_B(s
);
7411 reg
= ((modrm
>> 3) & 7) | rex_r
;
7416 if ((prefixes
& PREFIX_LOCK
) && (reg
== 0) &&
7417 (s
->cpuid_ext3_features
& CPUID_EXT3_CR8LEG
)) {
7426 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7427 gen_op_set_cc_op(s
->cc_op
);
7428 gen_jmp_im(pc_start
- s
->cs_base
);
7430 gen_op_mov_TN_reg(ot
, 0, rm
);
7431 gen_helper_write_crN(tcg_const_i32(reg
), cpu_T
[0]);
7432 gen_jmp_im(s
->pc
- s
->cs_base
);
7435 gen_helper_read_crN(cpu_T
[0], tcg_const_i32(reg
));
7436 gen_op_mov_reg_T0(ot
, rm
);
7444 case 0x121: /* mov reg, drN */
7445 case 0x123: /* mov drN, reg */
7447 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7449 modrm
= ldub_code(s
->pc
++);
7450 if ((modrm
& 0xc0) != 0xc0)
7452 rm
= (modrm
& 7) | REX_B(s
);
7453 reg
= ((modrm
>> 3) & 7) | rex_r
;
7458 /* XXX: do it dynamically with CR4.DE bit */
7459 if (reg
== 4 || reg
== 5 || reg
>= 8)
7462 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_DR0
+ reg
);
7463 gen_op_mov_TN_reg(ot
, 0, rm
);
7464 gen_helper_movl_drN_T0(tcg_const_i32(reg
), cpu_T
[0]);
7465 gen_jmp_im(s
->pc
- s
->cs_base
);
7468 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_DR0
+ reg
);
7469 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,dr
[reg
]));
7470 gen_op_mov_reg_T0(ot
, rm
);
7474 case 0x106: /* clts */
7476 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7478 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7480 /* abort block because static cpu state changed */
7481 gen_jmp_im(s
->pc
- s
->cs_base
);
7485 /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
7486 case 0x1c3: /* MOVNTI reg, mem */
7487 if (!(s
->cpuid_features
& CPUID_SSE2
))
7489 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
7490 modrm
= ldub_code(s
->pc
++);
7491 mod
= (modrm
>> 6) & 3;
7494 reg
= ((modrm
>> 3) & 7) | rex_r
;
7495 /* generate a generic store */
7496 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
7499 modrm
= ldub_code(s
->pc
++);
7500 mod
= (modrm
>> 6) & 3;
7501 op
= (modrm
>> 3) & 7;
7503 case 0: /* fxsave */
7504 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7505 (s
->prefix
& PREFIX_LOCK
))
7507 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7508 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7511 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7512 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7513 gen_op_set_cc_op(s
->cc_op
);
7514 gen_jmp_im(pc_start
- s
->cs_base
);
7515 gen_helper_fxsave(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7517 case 1: /* fxrstor */
7518 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7519 (s
->prefix
& PREFIX_LOCK
))
7521 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7522 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7525 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7526 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7527 gen_op_set_cc_op(s
->cc_op
);
7528 gen_jmp_im(pc_start
- s
->cs_base
);
7529 gen_helper_fxrstor(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7531 case 2: /* ldmxcsr */
7532 case 3: /* stmxcsr */
7533 if (s
->flags
& HF_TS_MASK
) {
7534 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7537 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
7540 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7542 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7543 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7545 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7546 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
7549 case 5: /* lfence */
7550 case 6: /* mfence */
7551 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE
))
7554 case 7: /* sfence / clflush */
7555 if ((modrm
& 0xc7) == 0xc0) {
7557 /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
7558 if (!(s
->cpuid_features
& CPUID_SSE
))
7562 if (!(s
->cpuid_features
& CPUID_CLFLUSH
))
7564 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7571 case 0x10d: /* 3DNow! prefetch(w) */
7572 modrm
= ldub_code(s
->pc
++);
7573 mod
= (modrm
>> 6) & 3;
7576 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7577 /* ignore for now */
7579 case 0x1aa: /* rsm */
7580 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_RSM
);
7581 if (!(s
->flags
& HF_SMM_MASK
))
7583 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7584 gen_op_set_cc_op(s
->cc_op
);
7585 s
->cc_op
= CC_OP_DYNAMIC
;
7587 gen_jmp_im(s
->pc
- s
->cs_base
);
7591 case 0x1b8: /* SSE4.2 popcnt */
7592 if ((prefixes
& (PREFIX_REPZ
| PREFIX_LOCK
| PREFIX_REPNZ
)) !=
7595 if (!(s
->cpuid_ext_features
& CPUID_EXT_POPCNT
))
7598 modrm
= ldub_code(s
->pc
++);
7599 reg
= ((modrm
>> 3) & 7);
7601 if (s
->prefix
& PREFIX_DATA
)
7603 else if (s
->dflag
!= 2)
7608 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
7609 gen_helper_popcnt(cpu_T
[0], cpu_T
[0], tcg_const_i32(ot
));
7610 gen_op_mov_reg_T0(ot
, reg
);
7612 s
->cc_op
= CC_OP_EFLAGS
;
7614 case 0x10e ... 0x10f:
7615 /* 3DNow! instructions, ignore prefixes */
7616 s
->prefix
&= ~(PREFIX_REPZ
| PREFIX_REPNZ
| PREFIX_DATA
);
7617 case 0x110 ... 0x117:
7618 case 0x128 ... 0x12f:
7619 case 0x138 ... 0x13a:
7620 case 0x150 ... 0x179:
7621 case 0x17c ... 0x17f:
7623 case 0x1c4 ... 0x1c6:
7624 case 0x1d0 ... 0x1fe:
7625 gen_sse(s
, b
, pc_start
, rex_r
);
7630 /* lock generation */
7631 if (s
->prefix
& PREFIX_LOCK
)
7632 gen_helper_unlock();
7635 if (s
->prefix
& PREFIX_LOCK
)
7636 gen_helper_unlock();
7637 /* XXX: ensure that no lock was generated */
7638 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
7642 void optimize_flags_init(void)
7644 #if TCG_TARGET_REG_BITS == 32
7645 assert(sizeof(CCTable
) == (1 << 3));
7647 assert(sizeof(CCTable
) == (1 << 4));
7649 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
7650 cpu_cc_op
= tcg_global_mem_new_i32(TCG_AREG0
,
7651 offsetof(CPUState
, cc_op
), "cc_op");
7652 cpu_cc_src
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_src
),
7654 cpu_cc_dst
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_dst
),
7656 cpu_cc_tmp
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_tmp
),
7659 #ifdef TARGET_X86_64
7660 cpu_regs
[R_EAX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7661 offsetof(CPUState
, regs
[R_EAX
]), "rax");
7662 cpu_regs
[R_ECX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7663 offsetof(CPUState
, regs
[R_ECX
]), "rcx");
7664 cpu_regs
[R_EDX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7665 offsetof(CPUState
, regs
[R_EDX
]), "rdx");
7666 cpu_regs
[R_EBX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7667 offsetof(CPUState
, regs
[R_EBX
]), "rbx");
7668 cpu_regs
[R_ESP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7669 offsetof(CPUState
, regs
[R_ESP
]), "rsp");
7670 cpu_regs
[R_EBP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7671 offsetof(CPUState
, regs
[R_EBP
]), "rbp");
7672 cpu_regs
[R_ESI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7673 offsetof(CPUState
, regs
[R_ESI
]), "rsi");
7674 cpu_regs
[R_EDI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7675 offsetof(CPUState
, regs
[R_EDI
]), "rdi");
7676 cpu_regs
[8] = tcg_global_mem_new_i64(TCG_AREG0
,
7677 offsetof(CPUState
, regs
[8]), "r8");
7678 cpu_regs
[9] = tcg_global_mem_new_i64(TCG_AREG0
,
7679 offsetof(CPUState
, regs
[9]), "r9");
7680 cpu_regs
[10] = tcg_global_mem_new_i64(TCG_AREG0
,
7681 offsetof(CPUState
, regs
[10]), "r10");
7682 cpu_regs
[11] = tcg_global_mem_new_i64(TCG_AREG0
,
7683 offsetof(CPUState
, regs
[11]), "r11");
7684 cpu_regs
[12] = tcg_global_mem_new_i64(TCG_AREG0
,
7685 offsetof(CPUState
, regs
[12]), "r12");
7686 cpu_regs
[13] = tcg_global_mem_new_i64(TCG_AREG0
,
7687 offsetof(CPUState
, regs
[13]), "r13");
7688 cpu_regs
[14] = tcg_global_mem_new_i64(TCG_AREG0
,
7689 offsetof(CPUState
, regs
[14]), "r14");
7690 cpu_regs
[15] = tcg_global_mem_new_i64(TCG_AREG0
,
7691 offsetof(CPUState
, regs
[15]), "r15");
7693 cpu_regs
[R_EAX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7694 offsetof(CPUState
, regs
[R_EAX
]), "eax");
7695 cpu_regs
[R_ECX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7696 offsetof(CPUState
, regs
[R_ECX
]), "ecx");
7697 cpu_regs
[R_EDX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7698 offsetof(CPUState
, regs
[R_EDX
]), "edx");
7699 cpu_regs
[R_EBX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7700 offsetof(CPUState
, regs
[R_EBX
]), "ebx");
7701 cpu_regs
[R_ESP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7702 offsetof(CPUState
, regs
[R_ESP
]), "esp");
7703 cpu_regs
[R_EBP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7704 offsetof(CPUState
, regs
[R_EBP
]), "ebp");
7705 cpu_regs
[R_ESI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7706 offsetof(CPUState
, regs
[R_ESI
]), "esi");
7707 cpu_regs
[R_EDI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7708 offsetof(CPUState
, regs
[R_EDI
]), "edi");
7711 /* register helpers */
7712 #define GEN_HELPER 2
7716 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
7717 basic block 'tb'. If search_pc is TRUE, also generate PC
7718 information for each intermediate instruction. */
7719 static inline void gen_intermediate_code_internal(CPUState
*env
,
7720 TranslationBlock
*tb
,
7723 DisasContext dc1
, *dc
= &dc1
;
7724 target_ulong pc_ptr
;
7725 uint16_t *gen_opc_end
;
7729 target_ulong pc_start
;
7730 target_ulong cs_base
;
7734 /* generate intermediate code */
7736 cs_base
= tb
->cs_base
;
7738 cflags
= tb
->cflags
;
7740 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
7741 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
7742 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
7743 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
7745 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
7746 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
7747 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
7748 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
7749 dc
->singlestep_enabled
= env
->singlestep_enabled
;
7750 dc
->cc_op
= CC_OP_DYNAMIC
;
7751 dc
->cs_base
= cs_base
;
7753 dc
->popl_esp_hack
= 0;
7754 /* select memory access functions */
7756 if (flags
& HF_SOFTMMU_MASK
) {
7758 dc
->mem_index
= 2 * 4;
7760 dc
->mem_index
= 1 * 4;
7762 dc
->cpuid_features
= env
->cpuid_features
;
7763 dc
->cpuid_ext_features
= env
->cpuid_ext_features
;
7764 dc
->cpuid_ext2_features
= env
->cpuid_ext2_features
;
7765 dc
->cpuid_ext3_features
= env
->cpuid_ext3_features
;
7766 #ifdef TARGET_X86_64
7767 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
7768 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
7771 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
7772 (flags
& HF_INHIBIT_IRQ_MASK
)
7773 #ifndef CONFIG_SOFTMMU
7774 || (flags
& HF_SOFTMMU_MASK
)
7778 /* check addseg logic */
7779 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
7780 printf("ERROR addseg\n");
7783 cpu_T
[0] = tcg_temp_new();
7784 cpu_T
[1] = tcg_temp_new();
7785 cpu_A0
= tcg_temp_new();
7786 cpu_T3
= tcg_temp_new();
7788 cpu_tmp0
= tcg_temp_new();
7789 cpu_tmp1_i64
= tcg_temp_new_i64();
7790 cpu_tmp2_i32
= tcg_temp_new_i32();
7791 cpu_tmp3_i32
= tcg_temp_new_i32();
7792 cpu_tmp4
= tcg_temp_new();
7793 cpu_tmp5
= tcg_temp_new();
7794 cpu_ptr0
= tcg_temp_new_ptr();
7795 cpu_ptr1
= tcg_temp_new_ptr();
7797 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7799 dc
->is_jmp
= DISAS_NEXT
;
7803 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7805 max_insns
= CF_COUNT_MASK
;
7809 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
7810 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7811 if (bp
->pc
== pc_ptr
&&
7812 !((bp
->flags
& BP_CPU
) && (tb
->flags
& HF_RF_MASK
))) {
7813 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
7819 j
= gen_opc_ptr
- gen_opc_buf
;
7823 gen_opc_instr_start
[lj
++] = 0;
7825 gen_opc_pc
[lj
] = pc_ptr
;
7826 gen_opc_cc_op
[lj
] = dc
->cc_op
;
7827 gen_opc_instr_start
[lj
] = 1;
7828 gen_opc_icount
[lj
] = num_insns
;
7830 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7833 pc_ptr
= disas_insn(dc
, pc_ptr
);
7835 /* stop translation if indicated */
7838 /* if single step mode, we generate only one instruction and
7839 generate an exception */
7840 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
7841 the flag and abort the translation to give the irqs a
7842 change to be happen */
7843 if (dc
->tf
|| dc
->singlestep_enabled
||
7844 (flags
& HF_INHIBIT_IRQ_MASK
)) {
7845 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7849 /* if too long translation, stop generation too */
7850 if (gen_opc_ptr
>= gen_opc_end
||
7851 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32) ||
7852 num_insns
>= max_insns
) {
7853 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7858 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7863 if (tb
->cflags
& CF_LAST_IO
)
7865 gen_icount_end(tb
, num_insns
);
7866 *gen_opc_ptr
= INDEX_op_end
;
7867 /* we don't forget to fill the last values */
7869 j
= gen_opc_ptr
- gen_opc_buf
;
7872 gen_opc_instr_start
[lj
++] = 0;
7876 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, X86_DUMP_CCOP
);
7877 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
7879 qemu_log("----------------\n");
7880 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
7881 #ifdef TARGET_X86_64
7886 disas_flags
= !dc
->code32
;
7887 log_target_disas(pc_start
, pc_ptr
- pc_start
, disas_flags
);
7893 tb
->size
= pc_ptr
- pc_start
;
7894 tb
->icount
= num_insns
;
7898 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
7900 gen_intermediate_code_internal(env
, tb
, 0);
7903 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
7905 gen_intermediate_code_internal(env
, tb
, 1);
7908 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7909 unsigned long searched_pc
, int pc_pos
, void *puc
)
7913 if (qemu_loglevel_mask(CPU_LOG_TB_OP
)) {
7915 qemu_log("RESTORE:\n");
7916 for(i
= 0;i
<= pc_pos
; i
++) {
7917 if (gen_opc_instr_start
[i
]) {
7918 qemu_log("0x%04x: " TARGET_FMT_lx
"\n", i
, gen_opc_pc
[i
]);
7921 qemu_log("spc=0x%08lx pc_pos=0x%x eip=" TARGET_FMT_lx
" cs_base=%x\n",
7922 searched_pc
, pc_pos
, gen_opc_pc
[pc_pos
] - tb
->cs_base
,
7923 (uint32_t)tb
->cs_base
);
7926 env
->eip
= gen_opc_pc
[pc_pos
] - tb
->cs_base
;
7927 cc_op
= gen_opc_cc_op
[pc_pos
];
7928 if (cc_op
!= CC_OP_DYNAMIC
)