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/>.
27 #include "disas/disas.h"
34 #define PREFIX_REPZ 0x01
35 #define PREFIX_REPNZ 0x02
36 #define PREFIX_LOCK 0x04
37 #define PREFIX_DATA 0x08
38 #define PREFIX_ADR 0x10
41 #define CODE64(s) ((s)->code64)
42 #define REX_X(s) ((s)->rex_x)
43 #define REX_B(s) ((s)->rex_b)
50 //#define MACRO_TEST 1
52 /* global register indexes */
53 static TCGv_ptr cpu_env
;
54 static TCGv cpu_A0
, cpu_cc_src
, cpu_cc_dst
, cpu_cc_tmp
;
55 static TCGv_i32 cpu_cc_op
;
56 static TCGv cpu_regs
[CPU_NB_REGS
];
58 static TCGv cpu_T
[2], cpu_T3
;
59 /* local register indexes (only used inside old micro ops) */
60 static TCGv cpu_tmp0
, cpu_tmp4
;
61 static TCGv_ptr cpu_ptr0
, cpu_ptr1
;
62 static TCGv_i32 cpu_tmp2_i32
, cpu_tmp3_i32
;
63 static TCGv_i64 cpu_tmp1_i64
;
66 static uint8_t gen_opc_cc_op
[OPC_BUF_SIZE
];
68 #include "exec/gen-icount.h"
71 static int x86_64_hregs
;
74 typedef struct DisasContext
{
75 /* current insn context */
76 int override
; /* -1 if no override */
79 target_ulong pc
; /* pc = eip + cs_base */
80 int is_jmp
; /* 1 = means jump (stop translation), 2 means CPU
81 static state change (stop translation) */
82 /* current block context */
83 target_ulong cs_base
; /* base of CS segment */
84 int pe
; /* protected mode */
85 int code32
; /* 32 bit code segment */
87 int lma
; /* long mode active */
88 int code64
; /* 64 bit code segment */
91 int ss32
; /* 32 bit stack segment */
92 int cc_op
; /* current CC operation */
93 int addseg
; /* non zero if either DS/ES/SS have a non zero base */
94 int f_st
; /* currently unused */
95 int vm86
; /* vm86 mode */
98 int tf
; /* TF cpu flag */
99 int singlestep_enabled
; /* "hardware" single step enabled */
100 int jmp_opt
; /* use direct block chaining for direct jumps */
101 int mem_index
; /* select memory access functions */
102 uint64_t flags
; /* all execution flags */
103 struct TranslationBlock
*tb
;
104 int popl_esp_hack
; /* for correct popl with esp base handling */
105 int rip_offset
; /* only used in x86_64, but left for simplicity */
107 int cpuid_ext_features
;
108 int cpuid_ext2_features
;
109 int cpuid_ext3_features
;
110 int cpuid_7_0_ebx_features
;
113 static void gen_eob(DisasContext
*s
);
114 static void gen_jmp(DisasContext
*s
, target_ulong eip
);
115 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
);
117 /* i386 arith/logic operations */
137 OP_SHL1
, /* undocumented */
161 /* I386 int registers */
162 OR_EAX
, /* MUST be even numbered */
171 OR_TMP0
= 16, /* temporary operand register */
173 OR_A0
, /* temporary register used when doing address evaluation */
176 static inline void gen_op_movl_T0_0(void)
178 tcg_gen_movi_tl(cpu_T
[0], 0);
181 static inline void gen_op_movl_T0_im(int32_t val
)
183 tcg_gen_movi_tl(cpu_T
[0], val
);
186 static inline void gen_op_movl_T0_imu(uint32_t val
)
188 tcg_gen_movi_tl(cpu_T
[0], val
);
191 static inline void gen_op_movl_T1_im(int32_t val
)
193 tcg_gen_movi_tl(cpu_T
[1], val
);
196 static inline void gen_op_movl_T1_imu(uint32_t val
)
198 tcg_gen_movi_tl(cpu_T
[1], val
);
201 static inline void gen_op_movl_A0_im(uint32_t val
)
203 tcg_gen_movi_tl(cpu_A0
, val
);
207 static inline void gen_op_movq_A0_im(int64_t val
)
209 tcg_gen_movi_tl(cpu_A0
, val
);
213 static inline void gen_movtl_T0_im(target_ulong val
)
215 tcg_gen_movi_tl(cpu_T
[0], val
);
218 static inline void gen_movtl_T1_im(target_ulong val
)
220 tcg_gen_movi_tl(cpu_T
[1], val
);
223 static inline void gen_op_andl_T0_ffff(void)
225 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
228 static inline void gen_op_andl_T0_im(uint32_t val
)
230 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], val
);
233 static inline void gen_op_movl_T0_T1(void)
235 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
238 static inline void gen_op_andl_A0_ffff(void)
240 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffff);
245 #define NB_OP_SIZES 4
247 #else /* !TARGET_X86_64 */
249 #define NB_OP_SIZES 3
251 #endif /* !TARGET_X86_64 */
253 #if defined(HOST_WORDS_BIGENDIAN)
254 #define REG_B_OFFSET (sizeof(target_ulong) - 1)
255 #define REG_H_OFFSET (sizeof(target_ulong) - 2)
256 #define REG_W_OFFSET (sizeof(target_ulong) - 2)
257 #define REG_L_OFFSET (sizeof(target_ulong) - 4)
258 #define REG_LH_OFFSET (sizeof(target_ulong) - 8)
260 #define REG_B_OFFSET 0
261 #define REG_H_OFFSET 1
262 #define REG_W_OFFSET 0
263 #define REG_L_OFFSET 0
264 #define REG_LH_OFFSET 4
267 /* In instruction encodings for byte register accesses the
268 * register number usually indicates "low 8 bits of register N";
269 * however there are some special cases where N 4..7 indicates
270 * [AH, CH, DH, BH], ie "bits 15..8 of register N-4". Return
271 * true for this special case, false otherwise.
273 static inline bool byte_reg_is_xH(int reg
)
279 if (reg
>= 8 || x86_64_hregs
) {
286 static inline void gen_op_mov_reg_v(int ot
, int reg
, TCGv t0
)
290 if (!byte_reg_is_xH(reg
)) {
291 tcg_gen_deposit_tl(cpu_regs
[reg
], cpu_regs
[reg
], t0
, 0, 8);
293 tcg_gen_deposit_tl(cpu_regs
[reg
- 4], cpu_regs
[reg
- 4], t0
, 8, 8);
297 tcg_gen_deposit_tl(cpu_regs
[reg
], cpu_regs
[reg
], t0
, 0, 16);
299 default: /* XXX this shouldn't be reached; abort? */
301 /* For x86_64, this sets the higher half of register to zero.
302 For i386, this is equivalent to a mov. */
303 tcg_gen_ext32u_tl(cpu_regs
[reg
], t0
);
307 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
313 static inline void gen_op_mov_reg_T0(int ot
, int reg
)
315 gen_op_mov_reg_v(ot
, reg
, cpu_T
[0]);
318 static inline void gen_op_mov_reg_T1(int ot
, int reg
)
320 gen_op_mov_reg_v(ot
, reg
, cpu_T
[1]);
323 static inline void gen_op_mov_reg_A0(int size
, int reg
)
327 tcg_gen_deposit_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_A0
, 0, 16);
329 default: /* XXX this shouldn't be reached; abort? */
331 /* For x86_64, this sets the higher half of register to zero.
332 For i386, this is equivalent to a mov. */
333 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_A0
);
337 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_A0
);
343 static inline void gen_op_mov_v_reg(int ot
, TCGv t0
, int reg
)
345 if (ot
== OT_BYTE
&& byte_reg_is_xH(reg
)) {
346 tcg_gen_shri_tl(t0
, cpu_regs
[reg
- 4], 8);
347 tcg_gen_ext8u_tl(t0
, t0
);
349 tcg_gen_mov_tl(t0
, cpu_regs
[reg
]);
353 static inline void gen_op_mov_TN_reg(int ot
, int t_index
, int reg
)
355 gen_op_mov_v_reg(ot
, cpu_T
[t_index
], reg
);
358 static inline void gen_op_movl_A0_reg(int reg
)
360 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
363 static inline void gen_op_addl_A0_im(int32_t val
)
365 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
367 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
372 static inline void gen_op_addq_A0_im(int64_t val
)
374 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
378 static void gen_add_A0_im(DisasContext
*s
, int val
)
382 gen_op_addq_A0_im(val
);
385 gen_op_addl_A0_im(val
);
388 static inline void gen_op_addl_T0_T1(void)
390 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
393 static inline void gen_op_jmp_T0(void)
395 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, eip
));
398 static inline void gen_op_add_reg_im(int size
, int reg
, int32_t val
)
402 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
403 tcg_gen_deposit_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
, 0, 16);
406 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
407 /* For x86_64, this sets the higher half of register to zero.
408 For i386, this is equivalent to a nop. */
409 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
410 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
414 tcg_gen_addi_tl(cpu_regs
[reg
], cpu_regs
[reg
], val
);
420 static inline void gen_op_add_reg_T0(int size
, int reg
)
424 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
425 tcg_gen_deposit_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
, 0, 16);
428 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
429 /* For x86_64, this sets the higher half of register to zero.
430 For i386, this is equivalent to a nop. */
431 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
432 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
436 tcg_gen_add_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_T
[0]);
442 static inline void gen_op_set_cc_op(int32_t val
)
444 tcg_gen_movi_i32(cpu_cc_op
, val
);
447 static inline void gen_op_addl_A0_reg_sN(int shift
, int reg
)
449 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
451 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
452 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
453 /* For x86_64, this sets the higher half of register to zero.
454 For i386, this is equivalent to a nop. */
455 tcg_gen_ext32u_tl(cpu_A0
, cpu_A0
);
458 static inline void gen_op_movl_A0_seg(int reg
)
460 tcg_gen_ld32u_tl(cpu_A0
, cpu_env
, offsetof(CPUX86State
, segs
[reg
].base
) + REG_L_OFFSET
);
463 static inline void gen_op_addl_A0_seg(DisasContext
*s
, int reg
)
465 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
, segs
[reg
].base
));
468 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
469 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
471 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
472 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
475 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
480 static inline void gen_op_movq_A0_seg(int reg
)
482 tcg_gen_ld_tl(cpu_A0
, cpu_env
, offsetof(CPUX86State
, segs
[reg
].base
));
485 static inline void gen_op_addq_A0_seg(int reg
)
487 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
, segs
[reg
].base
));
488 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
491 static inline void gen_op_movq_A0_reg(int reg
)
493 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
496 static inline void gen_op_addq_A0_reg_sN(int shift
, int reg
)
498 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
500 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
501 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
505 static inline void gen_op_lds_T0_A0(int idx
)
507 int mem_index
= (idx
>> 2) - 1;
510 tcg_gen_qemu_ld8s(cpu_T
[0], cpu_A0
, mem_index
);
513 tcg_gen_qemu_ld16s(cpu_T
[0], cpu_A0
, mem_index
);
517 tcg_gen_qemu_ld32s(cpu_T
[0], cpu_A0
, mem_index
);
522 static inline void gen_op_ld_v(int idx
, TCGv t0
, TCGv a0
)
524 int mem_index
= (idx
>> 2) - 1;
527 tcg_gen_qemu_ld8u(t0
, a0
, mem_index
);
530 tcg_gen_qemu_ld16u(t0
, a0
, mem_index
);
533 tcg_gen_qemu_ld32u(t0
, a0
, mem_index
);
537 /* Should never happen on 32-bit targets. */
539 tcg_gen_qemu_ld64(t0
, a0
, mem_index
);
545 /* XXX: always use ldu or lds */
546 static inline void gen_op_ld_T0_A0(int idx
)
548 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
551 static inline void gen_op_ldu_T0_A0(int idx
)
553 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
556 static inline void gen_op_ld_T1_A0(int idx
)
558 gen_op_ld_v(idx
, cpu_T
[1], cpu_A0
);
561 static inline void gen_op_st_v(int idx
, TCGv t0
, TCGv a0
)
563 int mem_index
= (idx
>> 2) - 1;
566 tcg_gen_qemu_st8(t0
, a0
, mem_index
);
569 tcg_gen_qemu_st16(t0
, a0
, mem_index
);
572 tcg_gen_qemu_st32(t0
, a0
, mem_index
);
576 /* Should never happen on 32-bit targets. */
578 tcg_gen_qemu_st64(t0
, a0
, mem_index
);
584 static inline void gen_op_st_T0_A0(int idx
)
586 gen_op_st_v(idx
, cpu_T
[0], cpu_A0
);
589 static inline void gen_op_st_T1_A0(int idx
)
591 gen_op_st_v(idx
, cpu_T
[1], cpu_A0
);
594 static inline void gen_jmp_im(target_ulong pc
)
596 tcg_gen_movi_tl(cpu_tmp0
, pc
);
597 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
, eip
));
600 static inline void gen_string_movl_A0_ESI(DisasContext
*s
)
604 override
= s
->override
;
608 gen_op_movq_A0_seg(override
);
609 gen_op_addq_A0_reg_sN(0, R_ESI
);
611 gen_op_movq_A0_reg(R_ESI
);
617 if (s
->addseg
&& override
< 0)
620 gen_op_movl_A0_seg(override
);
621 gen_op_addl_A0_reg_sN(0, R_ESI
);
623 gen_op_movl_A0_reg(R_ESI
);
626 /* 16 address, always override */
629 gen_op_movl_A0_reg(R_ESI
);
630 gen_op_andl_A0_ffff();
631 gen_op_addl_A0_seg(s
, override
);
635 static inline void gen_string_movl_A0_EDI(DisasContext
*s
)
639 gen_op_movq_A0_reg(R_EDI
);
644 gen_op_movl_A0_seg(R_ES
);
645 gen_op_addl_A0_reg_sN(0, R_EDI
);
647 gen_op_movl_A0_reg(R_EDI
);
650 gen_op_movl_A0_reg(R_EDI
);
651 gen_op_andl_A0_ffff();
652 gen_op_addl_A0_seg(s
, R_ES
);
656 static inline void gen_op_movl_T0_Dshift(int ot
)
658 tcg_gen_ld32s_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, df
));
659 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], ot
);
662 static void gen_extu(int ot
, TCGv reg
)
666 tcg_gen_ext8u_tl(reg
, reg
);
669 tcg_gen_ext16u_tl(reg
, reg
);
672 tcg_gen_ext32u_tl(reg
, reg
);
679 static void gen_exts(int ot
, TCGv reg
)
683 tcg_gen_ext8s_tl(reg
, reg
);
686 tcg_gen_ext16s_tl(reg
, reg
);
689 tcg_gen_ext32s_tl(reg
, reg
);
696 static inline void gen_op_jnz_ecx(int size
, int label1
)
698 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
699 gen_extu(size
+ 1, cpu_tmp0
);
700 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, label1
);
703 static inline void gen_op_jz_ecx(int size
, int label1
)
705 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
706 gen_extu(size
+ 1, cpu_tmp0
);
707 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
710 static void gen_helper_in_func(int ot
, TCGv v
, TCGv_i32 n
)
713 case 0: gen_helper_inb(v
, n
); break;
714 case 1: gen_helper_inw(v
, n
); break;
715 case 2: gen_helper_inl(v
, n
); break;
720 static void gen_helper_out_func(int ot
, TCGv_i32 v
, TCGv_i32 n
)
723 case 0: gen_helper_outb(v
, n
); break;
724 case 1: gen_helper_outw(v
, n
); break;
725 case 2: gen_helper_outl(v
, n
); break;
730 static void gen_check_io(DisasContext
*s
, int ot
, target_ulong cur_eip
,
734 target_ulong next_eip
;
737 if (s
->pe
&& (s
->cpl
> s
->iopl
|| s
->vm86
)) {
738 if (s
->cc_op
!= CC_OP_DYNAMIC
)
739 gen_op_set_cc_op(s
->cc_op
);
742 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
745 gen_helper_check_iob(cpu_env
, cpu_tmp2_i32
);
748 gen_helper_check_iow(cpu_env
, cpu_tmp2_i32
);
751 gen_helper_check_iol(cpu_env
, cpu_tmp2_i32
);
755 if(s
->flags
& HF_SVMI_MASK
) {
757 if (s
->cc_op
!= CC_OP_DYNAMIC
)
758 gen_op_set_cc_op(s
->cc_op
);
761 svm_flags
|= (1 << (4 + ot
));
762 next_eip
= s
->pc
- s
->cs_base
;
763 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
764 gen_helper_svm_check_io(cpu_env
, cpu_tmp2_i32
,
765 tcg_const_i32(svm_flags
),
766 tcg_const_i32(next_eip
- cur_eip
));
770 static inline void gen_movs(DisasContext
*s
, int ot
)
772 gen_string_movl_A0_ESI(s
);
773 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
774 gen_string_movl_A0_EDI(s
);
775 gen_op_st_T0_A0(ot
+ s
->mem_index
);
776 gen_op_movl_T0_Dshift(ot
);
777 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
778 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
781 static inline void gen_update_cc_op(DisasContext
*s
)
783 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
784 gen_op_set_cc_op(s
->cc_op
);
785 s
->cc_op
= CC_OP_DYNAMIC
;
789 static void gen_op_update1_cc(void)
791 tcg_gen_discard_tl(cpu_cc_src
);
792 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
795 static void gen_op_update2_cc(void)
797 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
798 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
801 static inline void gen_op_cmpl_T0_T1_cc(void)
803 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
804 tcg_gen_sub_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
807 static inline void gen_op_testl_T0_T1_cc(void)
809 tcg_gen_discard_tl(cpu_cc_src
);
810 tcg_gen_and_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
813 static void gen_op_update_neg_cc(void)
815 tcg_gen_neg_tl(cpu_cc_src
, cpu_T
[0]);
816 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
819 /* compute eflags.C to reg */
820 static void gen_compute_eflags_c(TCGv reg
)
822 gen_helper_cc_compute_c(cpu_tmp2_i32
, cpu_env
, cpu_cc_op
);
823 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
826 /* compute all eflags to cc_src */
827 static void gen_compute_eflags(TCGv reg
)
829 gen_helper_cc_compute_all(cpu_tmp2_i32
, cpu_env
, cpu_cc_op
);
830 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
833 static inline void gen_setcc_slow_T0(DisasContext
*s
, int jcc_op
)
835 if (s
->cc_op
!= CC_OP_DYNAMIC
)
836 gen_op_set_cc_op(s
->cc_op
);
839 gen_compute_eflags(cpu_T
[0]);
840 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 11);
841 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
844 gen_compute_eflags_c(cpu_T
[0]);
847 gen_compute_eflags(cpu_T
[0]);
848 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 6);
849 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
852 gen_compute_eflags(cpu_tmp0
);
853 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 6);
854 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
855 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
858 gen_compute_eflags(cpu_T
[0]);
859 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 7);
860 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
863 gen_compute_eflags(cpu_T
[0]);
864 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 2);
865 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
868 gen_compute_eflags(cpu_tmp0
);
869 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
870 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 7); /* CC_S */
871 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
872 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
876 gen_compute_eflags(cpu_tmp0
);
877 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
878 tcg_gen_shri_tl(cpu_tmp4
, cpu_tmp0
, 7); /* CC_S */
879 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 6); /* CC_Z */
880 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
881 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
882 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
887 /* return true if setcc_slow is not needed (WARNING: must be kept in
888 sync with gen_jcc1) */
889 static int is_fast_jcc_case(DisasContext
*s
, int b
)
892 jcc_op
= (b
>> 1) & 7;
894 /* we optimize the cmp/jcc case */
899 if (jcc_op
== JCC_O
|| jcc_op
== JCC_P
)
903 /* some jumps are easy to compute */
928 if (jcc_op
!= JCC_Z
&& jcc_op
!= JCC_S
)
938 /* generate a conditional jump to label 'l1' according to jump opcode
939 value 'b'. In the fast case, T0 is guaranted not to be used. */
940 static inline void gen_jcc1(DisasContext
*s
, int cc_op
, int b
, int l1
)
942 int inv
, jcc_op
, size
, cond
;
946 jcc_op
= (b
>> 1) & 7;
949 /* we optimize the cmp/jcc case */
955 size
= cc_op
- CC_OP_SUBB
;
961 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xff);
965 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffff);
970 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffffffff);
978 tcg_gen_brcondi_tl(inv
? TCG_COND_NE
: TCG_COND_EQ
, t0
, 0, l1
);
984 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80);
985 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
989 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x8000);
990 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
995 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80000000);
996 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
1001 tcg_gen_brcondi_tl(inv
? TCG_COND_GE
: TCG_COND_LT
, cpu_cc_dst
,
1008 cond
= inv
? TCG_COND_GEU
: TCG_COND_LTU
;
1011 cond
= inv
? TCG_COND_GTU
: TCG_COND_LEU
;
1013 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1017 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xff);
1018 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xff);
1022 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffff);
1023 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffff);
1025 #ifdef TARGET_X86_64
1028 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffffffff);
1029 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffffffff);
1036 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1040 cond
= inv
? TCG_COND_GE
: TCG_COND_LT
;
1043 cond
= inv
? TCG_COND_GT
: TCG_COND_LE
;
1045 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1049 tcg_gen_ext8s_tl(cpu_tmp4
, cpu_tmp4
);
1050 tcg_gen_ext8s_tl(t0
, cpu_cc_src
);
1054 tcg_gen_ext16s_tl(cpu_tmp4
, cpu_tmp4
);
1055 tcg_gen_ext16s_tl(t0
, cpu_cc_src
);
1057 #ifdef TARGET_X86_64
1060 tcg_gen_ext32s_tl(cpu_tmp4
, cpu_tmp4
);
1061 tcg_gen_ext32s_tl(t0
, cpu_cc_src
);
1068 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1076 /* some jumps are easy to compute */
1118 size
= (cc_op
- CC_OP_ADDB
) & 3;
1121 size
= (cc_op
- CC_OP_ADDB
) & 3;
1129 gen_setcc_slow_T0(s
, jcc_op
);
1130 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
,
1136 /* XXX: does not work with gdbstub "ice" single step - not a
1138 static int gen_jz_ecx_string(DisasContext
*s
, target_ulong next_eip
)
1142 l1
= gen_new_label();
1143 l2
= gen_new_label();
1144 gen_op_jnz_ecx(s
->aflag
, l1
);
1146 gen_jmp_tb(s
, next_eip
, 1);
1151 static inline void gen_stos(DisasContext
*s
, int ot
)
1153 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1154 gen_string_movl_A0_EDI(s
);
1155 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1156 gen_op_movl_T0_Dshift(ot
);
1157 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1160 static inline void gen_lods(DisasContext
*s
, int ot
)
1162 gen_string_movl_A0_ESI(s
);
1163 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1164 gen_op_mov_reg_T0(ot
, R_EAX
);
1165 gen_op_movl_T0_Dshift(ot
);
1166 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1169 static inline void gen_scas(DisasContext
*s
, int ot
)
1171 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1172 gen_string_movl_A0_EDI(s
);
1173 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1174 gen_op_cmpl_T0_T1_cc();
1175 gen_op_movl_T0_Dshift(ot
);
1176 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1179 static inline void gen_cmps(DisasContext
*s
, int ot
)
1181 gen_string_movl_A0_ESI(s
);
1182 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1183 gen_string_movl_A0_EDI(s
);
1184 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1185 gen_op_cmpl_T0_T1_cc();
1186 gen_op_movl_T0_Dshift(ot
);
1187 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1188 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1191 static inline void gen_ins(DisasContext
*s
, int ot
)
1195 gen_string_movl_A0_EDI(s
);
1196 /* Note: we must do this dummy write first to be restartable in
1197 case of page fault. */
1199 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1200 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1201 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1202 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1203 gen_helper_in_func(ot
, cpu_T
[0], cpu_tmp2_i32
);
1204 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1205 gen_op_movl_T0_Dshift(ot
);
1206 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1211 static inline void gen_outs(DisasContext
*s
, int ot
)
1215 gen_string_movl_A0_ESI(s
);
1216 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1218 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1219 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1220 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1221 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[0]);
1222 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
1224 gen_op_movl_T0_Dshift(ot
);
1225 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1230 /* same method as Valgrind : we generate jumps to current or next
1232 #define GEN_REPZ(op) \
1233 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1234 target_ulong cur_eip, target_ulong next_eip) \
1237 gen_update_cc_op(s); \
1238 l2 = gen_jz_ecx_string(s, next_eip); \
1239 gen_ ## op(s, ot); \
1240 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1241 /* a loop would cause two single step exceptions if ECX = 1 \
1242 before rep string_insn */ \
1244 gen_op_jz_ecx(s->aflag, l2); \
1245 gen_jmp(s, cur_eip); \
1248 #define GEN_REPZ2(op) \
1249 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1250 target_ulong cur_eip, \
1251 target_ulong next_eip, \
1255 gen_update_cc_op(s); \
1256 l2 = gen_jz_ecx_string(s, next_eip); \
1257 gen_ ## op(s, ot); \
1258 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1259 gen_op_set_cc_op(CC_OP_SUBB + ot); \
1260 gen_jcc1(s, CC_OP_SUBB + ot, (JCC_Z << 1) | (nz ^ 1), l2); \
1262 gen_op_jz_ecx(s->aflag, l2); \
1263 gen_jmp(s, cur_eip); \
1274 static void gen_helper_fp_arith_ST0_FT0(int op
)
1278 gen_helper_fadd_ST0_FT0(cpu_env
);
1281 gen_helper_fmul_ST0_FT0(cpu_env
);
1284 gen_helper_fcom_ST0_FT0(cpu_env
);
1287 gen_helper_fcom_ST0_FT0(cpu_env
);
1290 gen_helper_fsub_ST0_FT0(cpu_env
);
1293 gen_helper_fsubr_ST0_FT0(cpu_env
);
1296 gen_helper_fdiv_ST0_FT0(cpu_env
);
1299 gen_helper_fdivr_ST0_FT0(cpu_env
);
1304 /* NOTE the exception in "r" op ordering */
1305 static void gen_helper_fp_arith_STN_ST0(int op
, int opreg
)
1307 TCGv_i32 tmp
= tcg_const_i32(opreg
);
1310 gen_helper_fadd_STN_ST0(cpu_env
, tmp
);
1313 gen_helper_fmul_STN_ST0(cpu_env
, tmp
);
1316 gen_helper_fsubr_STN_ST0(cpu_env
, tmp
);
1319 gen_helper_fsub_STN_ST0(cpu_env
, tmp
);
1322 gen_helper_fdivr_STN_ST0(cpu_env
, tmp
);
1325 gen_helper_fdiv_STN_ST0(cpu_env
, tmp
);
1330 /* if d == OR_TMP0, it means memory operand (address in A0) */
1331 static void gen_op(DisasContext
*s1
, int op
, int ot
, int d
)
1334 gen_op_mov_TN_reg(ot
, 0, d
);
1336 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1340 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1341 gen_op_set_cc_op(s1
->cc_op
);
1342 gen_compute_eflags_c(cpu_tmp4
);
1343 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1344 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1346 gen_op_mov_reg_T0(ot
, d
);
1348 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1349 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1350 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1351 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1352 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1353 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_ADDB
+ ot
);
1354 s1
->cc_op
= CC_OP_DYNAMIC
;
1357 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1358 gen_op_set_cc_op(s1
->cc_op
);
1359 gen_compute_eflags_c(cpu_tmp4
);
1360 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1361 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1363 gen_op_mov_reg_T0(ot
, d
);
1365 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1366 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1367 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1368 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1369 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1370 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_SUBB
+ ot
);
1371 s1
->cc_op
= CC_OP_DYNAMIC
;
1374 gen_op_addl_T0_T1();
1376 gen_op_mov_reg_T0(ot
, d
);
1378 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1379 gen_op_update2_cc();
1380 s1
->cc_op
= CC_OP_ADDB
+ ot
;
1383 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1385 gen_op_mov_reg_T0(ot
, d
);
1387 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1388 gen_op_update2_cc();
1389 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1393 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1395 gen_op_mov_reg_T0(ot
, d
);
1397 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1398 gen_op_update1_cc();
1399 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1402 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1404 gen_op_mov_reg_T0(ot
, d
);
1406 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1407 gen_op_update1_cc();
1408 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1411 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1413 gen_op_mov_reg_T0(ot
, d
);
1415 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1416 gen_op_update1_cc();
1417 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1420 gen_op_cmpl_T0_T1_cc();
1421 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1426 /* if d == OR_TMP0, it means memory operand (address in A0) */
1427 static void gen_inc(DisasContext
*s1
, int ot
, int d
, int c
)
1430 gen_op_mov_TN_reg(ot
, 0, d
);
1432 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1433 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1434 gen_op_set_cc_op(s1
->cc_op
);
1436 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], 1);
1437 s1
->cc_op
= CC_OP_INCB
+ ot
;
1439 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], -1);
1440 s1
->cc_op
= CC_OP_DECB
+ ot
;
1443 gen_op_mov_reg_T0(ot
, d
);
1445 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1446 gen_compute_eflags_c(cpu_cc_src
);
1447 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1450 static void gen_shift_rm_T1(DisasContext
*s
, int ot
, int op1
,
1451 int is_right
, int is_arith
)
1457 if (ot
== OT_QUAD
) {
1464 if (op1
== OR_TMP0
) {
1465 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1467 gen_op_mov_TN_reg(ot
, 0, op1
);
1470 t0
= tcg_temp_local_new();
1471 t1
= tcg_temp_local_new();
1472 t2
= tcg_temp_local_new();
1474 tcg_gen_andi_tl(t2
, cpu_T
[1], mask
);
1478 gen_exts(ot
, cpu_T
[0]);
1479 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1480 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[0], t2
);
1482 gen_extu(ot
, cpu_T
[0]);
1483 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1484 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], t2
);
1487 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1488 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[0], t2
);
1492 if (op1
== OR_TMP0
) {
1493 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1495 gen_op_mov_reg_T0(ot
, op1
);
1498 /* update eflags if non zero shift */
1499 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
1500 gen_op_set_cc_op(s
->cc_op
);
1503 tcg_gen_mov_tl(t1
, cpu_T
[0]);
1505 shift_label
= gen_new_label();
1506 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, shift_label
);
1508 tcg_gen_addi_tl(t2
, t2
, -1);
1509 tcg_gen_mov_tl(cpu_cc_dst
, t1
);
1513 tcg_gen_sar_tl(cpu_cc_src
, t0
, t2
);
1515 tcg_gen_shr_tl(cpu_cc_src
, t0
, t2
);
1518 tcg_gen_shl_tl(cpu_cc_src
, t0
, t2
);
1522 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1524 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1527 gen_set_label(shift_label
);
1528 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1535 static void gen_shift_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1536 int is_right
, int is_arith
)
1547 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1549 gen_op_mov_TN_reg(ot
, 0, op1
);
1555 gen_exts(ot
, cpu_T
[0]);
1556 tcg_gen_sari_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1557 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], op2
);
1559 gen_extu(ot
, cpu_T
[0]);
1560 tcg_gen_shri_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1561 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], op2
);
1564 tcg_gen_shli_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1565 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], op2
);
1571 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1573 gen_op_mov_reg_T0(ot
, op1
);
1575 /* update eflags if non zero shift */
1577 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
1578 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1580 s
->cc_op
= CC_OP_SARB
+ ot
;
1582 s
->cc_op
= CC_OP_SHLB
+ ot
;
1586 static inline void tcg_gen_lshift(TCGv ret
, TCGv arg1
, target_long arg2
)
1589 tcg_gen_shli_tl(ret
, arg1
, arg2
);
1591 tcg_gen_shri_tl(ret
, arg1
, -arg2
);
1594 static void gen_rot_rm_T1(DisasContext
*s
, int ot
, int op1
,
1598 int label1
, label2
, data_bits
;
1599 TCGv t0
, t1
, t2
, a0
;
1601 /* XXX: inefficient, but we must use local temps */
1602 t0
= tcg_temp_local_new();
1603 t1
= tcg_temp_local_new();
1604 t2
= tcg_temp_local_new();
1605 a0
= tcg_temp_local_new();
1613 if (op1
== OR_TMP0
) {
1614 tcg_gen_mov_tl(a0
, cpu_A0
);
1615 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1617 gen_op_mov_v_reg(ot
, t0
, op1
);
1620 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1622 tcg_gen_andi_tl(t1
, t1
, mask
);
1624 /* Must test zero case to avoid using undefined behaviour in TCG
1626 label1
= gen_new_label();
1627 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label1
);
1630 tcg_gen_andi_tl(cpu_tmp0
, t1
, (1 << (3 + ot
)) - 1);
1632 tcg_gen_mov_tl(cpu_tmp0
, t1
);
1635 tcg_gen_mov_tl(t2
, t0
);
1637 data_bits
= 8 << ot
;
1638 /* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
1639 fix TCG definition) */
1641 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1642 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1643 tcg_gen_shl_tl(t0
, t0
, cpu_tmp0
);
1645 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1646 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1647 tcg_gen_shr_tl(t0
, t0
, cpu_tmp0
);
1649 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1651 gen_set_label(label1
);
1653 if (op1
== OR_TMP0
) {
1654 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1656 gen_op_mov_reg_v(ot
, op1
, t0
);
1660 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1661 gen_op_set_cc_op(s
->cc_op
);
1663 label2
= gen_new_label();
1664 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label2
);
1666 gen_compute_eflags(cpu_cc_src
);
1667 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1668 tcg_gen_xor_tl(cpu_tmp0
, t2
, t0
);
1669 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1670 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1671 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1673 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1675 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1676 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1678 tcg_gen_discard_tl(cpu_cc_dst
);
1679 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1681 gen_set_label(label2
);
1682 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1690 static void gen_rot_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1697 /* XXX: inefficient, but we must use local temps */
1698 t0
= tcg_temp_local_new();
1699 t1
= tcg_temp_local_new();
1700 a0
= tcg_temp_local_new();
1708 if (op1
== OR_TMP0
) {
1709 tcg_gen_mov_tl(a0
, cpu_A0
);
1710 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1712 gen_op_mov_v_reg(ot
, t0
, op1
);
1716 tcg_gen_mov_tl(t1
, t0
);
1719 data_bits
= 8 << ot
;
1721 int shift
= op2
& ((1 << (3 + ot
)) - 1);
1723 tcg_gen_shri_tl(cpu_tmp4
, t0
, shift
);
1724 tcg_gen_shli_tl(t0
, t0
, data_bits
- shift
);
1727 tcg_gen_shli_tl(cpu_tmp4
, t0
, shift
);
1728 tcg_gen_shri_tl(t0
, t0
, data_bits
- shift
);
1730 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1734 if (op1
== OR_TMP0
) {
1735 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1737 gen_op_mov_reg_v(ot
, op1
, t0
);
1742 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1743 gen_op_set_cc_op(s
->cc_op
);
1745 gen_compute_eflags(cpu_cc_src
);
1746 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1747 tcg_gen_xor_tl(cpu_tmp0
, t1
, t0
);
1748 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1749 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1750 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1752 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1754 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1755 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1757 tcg_gen_discard_tl(cpu_cc_dst
);
1758 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1759 s
->cc_op
= CC_OP_EFLAGS
;
1767 /* XXX: add faster immediate = 1 case */
1768 static void gen_rotc_rm_T1(DisasContext
*s
, int ot
, int op1
,
1773 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1774 gen_op_set_cc_op(s
->cc_op
);
1778 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1780 gen_op_mov_TN_reg(ot
, 0, op1
);
1785 gen_helper_rcrb(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1788 gen_helper_rcrw(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1791 gen_helper_rcrl(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1793 #ifdef TARGET_X86_64
1795 gen_helper_rcrq(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1802 gen_helper_rclb(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1805 gen_helper_rclw(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1808 gen_helper_rcll(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1810 #ifdef TARGET_X86_64
1812 gen_helper_rclq(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
1819 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1821 gen_op_mov_reg_T0(ot
, op1
);
1824 label1
= gen_new_label();
1825 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_cc_tmp
, -1, label1
);
1827 tcg_gen_mov_tl(cpu_cc_src
, cpu_cc_tmp
);
1828 tcg_gen_discard_tl(cpu_cc_dst
);
1829 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1831 gen_set_label(label1
);
1832 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1835 /* XXX: add faster immediate case */
1836 static void gen_shiftd_rm_T1_T3(DisasContext
*s
, int ot
, int op1
,
1839 int label1
, label2
, data_bits
;
1841 TCGv t0
, t1
, t2
, a0
;
1843 t0
= tcg_temp_local_new();
1844 t1
= tcg_temp_local_new();
1845 t2
= tcg_temp_local_new();
1846 a0
= tcg_temp_local_new();
1854 if (op1
== OR_TMP0
) {
1855 tcg_gen_mov_tl(a0
, cpu_A0
);
1856 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1858 gen_op_mov_v_reg(ot
, t0
, op1
);
1861 tcg_gen_andi_tl(cpu_T3
, cpu_T3
, mask
);
1863 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1864 tcg_gen_mov_tl(t2
, cpu_T3
);
1866 /* Must test zero case to avoid using undefined behaviour in TCG
1868 label1
= gen_new_label();
1869 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
1871 tcg_gen_addi_tl(cpu_tmp5
, t2
, -1);
1872 if (ot
== OT_WORD
) {
1873 /* Note: we implement the Intel behaviour for shift count > 16 */
1875 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1876 tcg_gen_shli_tl(cpu_tmp0
, t1
, 16);
1877 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1878 tcg_gen_ext32u_tl(t0
, t0
);
1880 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1882 /* only needed if count > 16, but a test would complicate */
1883 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1884 tcg_gen_shl_tl(cpu_tmp0
, t0
, cpu_tmp5
);
1886 tcg_gen_shr_tl(t0
, t0
, t2
);
1888 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1890 /* XXX: not optimal */
1891 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1892 tcg_gen_shli_tl(t1
, t1
, 16);
1893 tcg_gen_or_tl(t1
, t1
, t0
);
1894 tcg_gen_ext32u_tl(t1
, t1
);
1896 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1897 tcg_gen_subfi_tl(cpu_tmp0
, 32, cpu_tmp5
);
1898 tcg_gen_shr_tl(cpu_tmp5
, t1
, cpu_tmp0
);
1899 tcg_gen_or_tl(cpu_tmp4
, cpu_tmp4
, cpu_tmp5
);
1901 tcg_gen_shl_tl(t0
, t0
, t2
);
1902 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1903 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1904 tcg_gen_or_tl(t0
, t0
, t1
);
1907 data_bits
= 8 << ot
;
1910 tcg_gen_ext32u_tl(t0
, t0
);
1912 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1914 tcg_gen_shr_tl(t0
, t0
, t2
);
1915 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1916 tcg_gen_shl_tl(t1
, t1
, cpu_tmp5
);
1917 tcg_gen_or_tl(t0
, t0
, t1
);
1921 tcg_gen_ext32u_tl(t1
, t1
);
1923 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1925 tcg_gen_shl_tl(t0
, t0
, t2
);
1926 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1927 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1928 tcg_gen_or_tl(t0
, t0
, t1
);
1931 tcg_gen_mov_tl(t1
, cpu_tmp4
);
1933 gen_set_label(label1
);
1935 if (op1
== OR_TMP0
) {
1936 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1938 gen_op_mov_reg_v(ot
, op1
, t0
);
1942 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1943 gen_op_set_cc_op(s
->cc_op
);
1945 label2
= gen_new_label();
1946 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label2
);
1948 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1949 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1951 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1953 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1955 gen_set_label(label2
);
1956 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1964 static void gen_shift(DisasContext
*s1
, int op
, int ot
, int d
, int s
)
1967 gen_op_mov_TN_reg(ot
, 1, s
);
1970 gen_rot_rm_T1(s1
, ot
, d
, 0);
1973 gen_rot_rm_T1(s1
, ot
, d
, 1);
1977 gen_shift_rm_T1(s1
, ot
, d
, 0, 0);
1980 gen_shift_rm_T1(s1
, ot
, d
, 1, 0);
1983 gen_shift_rm_T1(s1
, ot
, d
, 1, 1);
1986 gen_rotc_rm_T1(s1
, ot
, d
, 0);
1989 gen_rotc_rm_T1(s1
, ot
, d
, 1);
1994 static void gen_shifti(DisasContext
*s1
, int op
, int ot
, int d
, int c
)
1998 gen_rot_rm_im(s1
, ot
, d
, c
, 0);
2001 gen_rot_rm_im(s1
, ot
, d
, c
, 1);
2005 gen_shift_rm_im(s1
, ot
, d
, c
, 0, 0);
2008 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 0);
2011 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 1);
2014 /* currently not optimized */
2015 gen_op_movl_T1_im(c
);
2016 gen_shift(s1
, op
, ot
, d
, OR_TMP1
);
2021 static void gen_lea_modrm(CPUX86State
*env
, DisasContext
*s
, int modrm
,
2022 int *reg_ptr
, int *offset_ptr
)
2030 int mod
, rm
, code
, override
, must_add_seg
;
2032 override
= s
->override
;
2033 must_add_seg
= s
->addseg
;
2036 mod
= (modrm
>> 6) & 3;
2048 code
= cpu_ldub_code(env
, s
->pc
++);
2049 scale
= (code
>> 6) & 3;
2050 index
= ((code
>> 3) & 7) | REX_X(s
);
2057 if ((base
& 7) == 5) {
2059 disp
= (int32_t)cpu_ldl_code(env
, s
->pc
);
2061 if (CODE64(s
) && !havesib
) {
2062 disp
+= s
->pc
+ s
->rip_offset
;
2069 disp
= (int8_t)cpu_ldub_code(env
, s
->pc
++);
2073 disp
= (int32_t)cpu_ldl_code(env
, s
->pc
);
2079 /* for correct popl handling with esp */
2080 if (base
== 4 && s
->popl_esp_hack
)
2081 disp
+= s
->popl_esp_hack
;
2082 #ifdef TARGET_X86_64
2083 if (s
->aflag
== 2) {
2084 gen_op_movq_A0_reg(base
);
2086 gen_op_addq_A0_im(disp
);
2091 gen_op_movl_A0_reg(base
);
2093 gen_op_addl_A0_im(disp
);
2096 #ifdef TARGET_X86_64
2097 if (s
->aflag
== 2) {
2098 gen_op_movq_A0_im(disp
);
2102 gen_op_movl_A0_im(disp
);
2105 /* index == 4 means no index */
2106 if (havesib
&& (index
!= 4)) {
2107 #ifdef TARGET_X86_64
2108 if (s
->aflag
== 2) {
2109 gen_op_addq_A0_reg_sN(scale
, index
);
2113 gen_op_addl_A0_reg_sN(scale
, index
);
2118 if (base
== R_EBP
|| base
== R_ESP
)
2123 #ifdef TARGET_X86_64
2124 if (s
->aflag
== 2) {
2125 gen_op_addq_A0_seg(override
);
2129 gen_op_addl_A0_seg(s
, override
);
2136 disp
= cpu_lduw_code(env
, s
->pc
);
2138 gen_op_movl_A0_im(disp
);
2139 rm
= 0; /* avoid SS override */
2146 disp
= (int8_t)cpu_ldub_code(env
, s
->pc
++);
2150 disp
= cpu_lduw_code(env
, s
->pc
);
2156 gen_op_movl_A0_reg(R_EBX
);
2157 gen_op_addl_A0_reg_sN(0, R_ESI
);
2160 gen_op_movl_A0_reg(R_EBX
);
2161 gen_op_addl_A0_reg_sN(0, R_EDI
);
2164 gen_op_movl_A0_reg(R_EBP
);
2165 gen_op_addl_A0_reg_sN(0, R_ESI
);
2168 gen_op_movl_A0_reg(R_EBP
);
2169 gen_op_addl_A0_reg_sN(0, R_EDI
);
2172 gen_op_movl_A0_reg(R_ESI
);
2175 gen_op_movl_A0_reg(R_EDI
);
2178 gen_op_movl_A0_reg(R_EBP
);
2182 gen_op_movl_A0_reg(R_EBX
);
2186 gen_op_addl_A0_im(disp
);
2187 gen_op_andl_A0_ffff();
2191 if (rm
== 2 || rm
== 3 || rm
== 6)
2196 gen_op_addl_A0_seg(s
, override
);
2206 static void gen_nop_modrm(CPUX86State
*env
, DisasContext
*s
, int modrm
)
2208 int mod
, rm
, base
, code
;
2210 mod
= (modrm
>> 6) & 3;
2220 code
= cpu_ldub_code(env
, s
->pc
++);
2256 /* used for LEA and MOV AX, mem */
2257 static void gen_add_A0_ds_seg(DisasContext
*s
)
2259 int override
, must_add_seg
;
2260 must_add_seg
= s
->addseg
;
2262 if (s
->override
>= 0) {
2263 override
= s
->override
;
2267 #ifdef TARGET_X86_64
2269 gen_op_addq_A0_seg(override
);
2273 gen_op_addl_A0_seg(s
, override
);
2278 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
2280 static void gen_ldst_modrm(CPUX86State
*env
, DisasContext
*s
, int modrm
,
2281 int ot
, int reg
, int is_store
)
2283 int mod
, rm
, opreg
, disp
;
2285 mod
= (modrm
>> 6) & 3;
2286 rm
= (modrm
& 7) | REX_B(s
);
2290 gen_op_mov_TN_reg(ot
, 0, reg
);
2291 gen_op_mov_reg_T0(ot
, rm
);
2293 gen_op_mov_TN_reg(ot
, 0, rm
);
2295 gen_op_mov_reg_T0(ot
, reg
);
2298 gen_lea_modrm(env
, s
, modrm
, &opreg
, &disp
);
2301 gen_op_mov_TN_reg(ot
, 0, reg
);
2302 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2304 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
2306 gen_op_mov_reg_T0(ot
, reg
);
2311 static inline uint32_t insn_get(CPUX86State
*env
, DisasContext
*s
, int ot
)
2317 ret
= cpu_ldub_code(env
, s
->pc
);
2321 ret
= cpu_lduw_code(env
, s
->pc
);
2326 ret
= cpu_ldl_code(env
, s
->pc
);
2333 static inline int insn_const_size(unsigned int ot
)
2341 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong eip
)
2343 TranslationBlock
*tb
;
2346 pc
= s
->cs_base
+ eip
;
2348 /* NOTE: we handle the case where the TB spans two pages here */
2349 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) ||
2350 (pc
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
)) {
2351 /* jump to same page: we can use a direct jump */
2352 tcg_gen_goto_tb(tb_num
);
2354 tcg_gen_exit_tb((tcg_target_long
)tb
+ tb_num
);
2356 /* jump to another page: currently not optimized */
2362 static inline void gen_jcc(DisasContext
*s
, int b
,
2363 target_ulong val
, target_ulong next_eip
)
2368 gen_update_cc_op(s
);
2370 l1
= gen_new_label();
2371 gen_jcc1(s
, cc_op
, b
, l1
);
2373 gen_goto_tb(s
, 0, next_eip
);
2376 gen_goto_tb(s
, 1, val
);
2377 s
->is_jmp
= DISAS_TB_JUMP
;
2380 l1
= gen_new_label();
2381 l2
= gen_new_label();
2382 gen_jcc1(s
, cc_op
, b
, l1
);
2384 gen_jmp_im(next_eip
);
2394 static void gen_setcc(DisasContext
*s
, int b
)
2396 int inv
, jcc_op
, l1
;
2399 if (is_fast_jcc_case(s
, b
)) {
2400 /* nominal case: we use a jump */
2401 /* XXX: make it faster by adding new instructions in TCG */
2402 t0
= tcg_temp_local_new();
2403 tcg_gen_movi_tl(t0
, 0);
2404 l1
= gen_new_label();
2405 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
2406 tcg_gen_movi_tl(t0
, 1);
2408 tcg_gen_mov_tl(cpu_T
[0], t0
);
2411 /* slow case: it is more efficient not to generate a jump,
2412 although it is questionnable whether this optimization is
2415 jcc_op
= (b
>> 1) & 7;
2416 gen_setcc_slow_T0(s
, jcc_op
);
2418 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
2423 static inline void gen_op_movl_T0_seg(int seg_reg
)
2425 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
2426 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2429 static inline void gen_op_movl_seg_T0_vm(int seg_reg
)
2431 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
2432 tcg_gen_st32_tl(cpu_T
[0], cpu_env
,
2433 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2434 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], 4);
2435 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
2436 offsetof(CPUX86State
,segs
[seg_reg
].base
));
2439 /* move T0 to seg_reg and compute if the CPU state may change. Never
2440 call this function with seg_reg == R_CS */
2441 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
2443 if (s
->pe
&& !s
->vm86
) {
2444 /* XXX: optimize by finding processor state dynamically */
2445 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2446 gen_op_set_cc_op(s
->cc_op
);
2447 gen_jmp_im(cur_eip
);
2448 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
2449 gen_helper_load_seg(cpu_env
, tcg_const_i32(seg_reg
), cpu_tmp2_i32
);
2450 /* abort translation because the addseg value may change or
2451 because ss32 may change. For R_SS, translation must always
2452 stop as a special handling must be done to disable hardware
2453 interrupts for the next instruction */
2454 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
2455 s
->is_jmp
= DISAS_TB_JUMP
;
2457 gen_op_movl_seg_T0_vm(seg_reg
);
2458 if (seg_reg
== R_SS
)
2459 s
->is_jmp
= DISAS_TB_JUMP
;
2463 static inline int svm_is_rep(int prefixes
)
2465 return ((prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) ? 8 : 0);
2469 gen_svm_check_intercept_param(DisasContext
*s
, target_ulong pc_start
,
2470 uint32_t type
, uint64_t param
)
2472 /* no SVM activated; fast case */
2473 if (likely(!(s
->flags
& HF_SVMI_MASK
)))
2475 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2476 gen_op_set_cc_op(s
->cc_op
);
2477 gen_jmp_im(pc_start
- s
->cs_base
);
2478 gen_helper_svm_check_intercept_param(cpu_env
, tcg_const_i32(type
),
2479 tcg_const_i64(param
));
2483 gen_svm_check_intercept(DisasContext
*s
, target_ulong pc_start
, uint64_t type
)
2485 gen_svm_check_intercept_param(s
, pc_start
, type
, 0);
2488 static inline void gen_stack_update(DisasContext
*s
, int addend
)
2490 #ifdef TARGET_X86_64
2492 gen_op_add_reg_im(2, R_ESP
, addend
);
2496 gen_op_add_reg_im(1, R_ESP
, addend
);
2498 gen_op_add_reg_im(0, R_ESP
, addend
);
2502 /* generate a push. It depends on ss32, addseg and dflag */
2503 static void gen_push_T0(DisasContext
*s
)
2505 #ifdef TARGET_X86_64
2507 gen_op_movq_A0_reg(R_ESP
);
2509 gen_op_addq_A0_im(-8);
2510 gen_op_st_T0_A0(OT_QUAD
+ s
->mem_index
);
2512 gen_op_addq_A0_im(-2);
2513 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2515 gen_op_mov_reg_A0(2, R_ESP
);
2519 gen_op_movl_A0_reg(R_ESP
);
2521 gen_op_addl_A0_im(-2);
2523 gen_op_addl_A0_im(-4);
2526 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2527 gen_op_addl_A0_seg(s
, R_SS
);
2530 gen_op_andl_A0_ffff();
2531 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2532 gen_op_addl_A0_seg(s
, R_SS
);
2534 gen_op_st_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2535 if (s
->ss32
&& !s
->addseg
)
2536 gen_op_mov_reg_A0(1, R_ESP
);
2538 gen_op_mov_reg_T1(s
->ss32
+ 1, R_ESP
);
2542 /* generate a push. It depends on ss32, addseg and dflag */
2543 /* slower version for T1, only used for call Ev */
2544 static void gen_push_T1(DisasContext
*s
)
2546 #ifdef TARGET_X86_64
2548 gen_op_movq_A0_reg(R_ESP
);
2550 gen_op_addq_A0_im(-8);
2551 gen_op_st_T1_A0(OT_QUAD
+ s
->mem_index
);
2553 gen_op_addq_A0_im(-2);
2554 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2556 gen_op_mov_reg_A0(2, R_ESP
);
2560 gen_op_movl_A0_reg(R_ESP
);
2562 gen_op_addl_A0_im(-2);
2564 gen_op_addl_A0_im(-4);
2567 gen_op_addl_A0_seg(s
, R_SS
);
2570 gen_op_andl_A0_ffff();
2571 gen_op_addl_A0_seg(s
, R_SS
);
2573 gen_op_st_T1_A0(s
->dflag
+ 1 + s
->mem_index
);
2575 if (s
->ss32
&& !s
->addseg
)
2576 gen_op_mov_reg_A0(1, R_ESP
);
2578 gen_stack_update(s
, (-2) << s
->dflag
);
2582 /* two step pop is necessary for precise exceptions */
2583 static void gen_pop_T0(DisasContext
*s
)
2585 #ifdef TARGET_X86_64
2587 gen_op_movq_A0_reg(R_ESP
);
2588 gen_op_ld_T0_A0((s
->dflag
? OT_QUAD
: OT_WORD
) + s
->mem_index
);
2592 gen_op_movl_A0_reg(R_ESP
);
2595 gen_op_addl_A0_seg(s
, R_SS
);
2597 gen_op_andl_A0_ffff();
2598 gen_op_addl_A0_seg(s
, R_SS
);
2600 gen_op_ld_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2604 static void gen_pop_update(DisasContext
*s
)
2606 #ifdef TARGET_X86_64
2607 if (CODE64(s
) && s
->dflag
) {
2608 gen_stack_update(s
, 8);
2612 gen_stack_update(s
, 2 << s
->dflag
);
2616 static void gen_stack_A0(DisasContext
*s
)
2618 gen_op_movl_A0_reg(R_ESP
);
2620 gen_op_andl_A0_ffff();
2621 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2623 gen_op_addl_A0_seg(s
, R_SS
);
2626 /* NOTE: wrap around in 16 bit not fully handled */
2627 static void gen_pusha(DisasContext
*s
)
2630 gen_op_movl_A0_reg(R_ESP
);
2631 gen_op_addl_A0_im(-16 << s
->dflag
);
2633 gen_op_andl_A0_ffff();
2634 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2636 gen_op_addl_A0_seg(s
, R_SS
);
2637 for(i
= 0;i
< 8; i
++) {
2638 gen_op_mov_TN_reg(OT_LONG
, 0, 7 - i
);
2639 gen_op_st_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2640 gen_op_addl_A0_im(2 << s
->dflag
);
2642 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2645 /* NOTE: wrap around in 16 bit not fully handled */
2646 static void gen_popa(DisasContext
*s
)
2649 gen_op_movl_A0_reg(R_ESP
);
2651 gen_op_andl_A0_ffff();
2652 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2653 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], 16 << s
->dflag
);
2655 gen_op_addl_A0_seg(s
, R_SS
);
2656 for(i
= 0;i
< 8; i
++) {
2657 /* ESP is not reloaded */
2659 gen_op_ld_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2660 gen_op_mov_reg_T0(OT_WORD
+ s
->dflag
, 7 - i
);
2662 gen_op_addl_A0_im(2 << s
->dflag
);
2664 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2667 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2672 #ifdef TARGET_X86_64
2674 ot
= s
->dflag
? OT_QUAD
: OT_WORD
;
2677 gen_op_movl_A0_reg(R_ESP
);
2678 gen_op_addq_A0_im(-opsize
);
2679 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2682 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2683 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2685 /* XXX: must save state */
2686 gen_helper_enter64_level(cpu_env
, tcg_const_i32(level
),
2687 tcg_const_i32((ot
== OT_QUAD
)),
2690 gen_op_mov_reg_T1(ot
, R_EBP
);
2691 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2692 gen_op_mov_reg_T1(OT_QUAD
, R_ESP
);
2696 ot
= s
->dflag
+ OT_WORD
;
2697 opsize
= 2 << s
->dflag
;
2699 gen_op_movl_A0_reg(R_ESP
);
2700 gen_op_addl_A0_im(-opsize
);
2702 gen_op_andl_A0_ffff();
2703 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2705 gen_op_addl_A0_seg(s
, R_SS
);
2707 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2708 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2710 /* XXX: must save state */
2711 gen_helper_enter_level(cpu_env
, tcg_const_i32(level
),
2712 tcg_const_i32(s
->dflag
),
2715 gen_op_mov_reg_T1(ot
, R_EBP
);
2716 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2717 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2721 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2723 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2724 gen_op_set_cc_op(s
->cc_op
);
2725 gen_jmp_im(cur_eip
);
2726 gen_helper_raise_exception(cpu_env
, tcg_const_i32(trapno
));
2727 s
->is_jmp
= DISAS_TB_JUMP
;
2730 /* an interrupt is different from an exception because of the
2732 static void gen_interrupt(DisasContext
*s
, int intno
,
2733 target_ulong cur_eip
, target_ulong next_eip
)
2735 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2736 gen_op_set_cc_op(s
->cc_op
);
2737 gen_jmp_im(cur_eip
);
2738 gen_helper_raise_interrupt(cpu_env
, tcg_const_i32(intno
),
2739 tcg_const_i32(next_eip
- cur_eip
));
2740 s
->is_jmp
= DISAS_TB_JUMP
;
2743 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2745 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2746 gen_op_set_cc_op(s
->cc_op
);
2747 gen_jmp_im(cur_eip
);
2748 gen_helper_debug(cpu_env
);
2749 s
->is_jmp
= DISAS_TB_JUMP
;
2752 /* generate a generic end of block. Trace exception is also generated
2754 static void gen_eob(DisasContext
*s
)
2756 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2757 gen_op_set_cc_op(s
->cc_op
);
2758 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2759 gen_helper_reset_inhibit_irq(cpu_env
);
2761 if (s
->tb
->flags
& HF_RF_MASK
) {
2762 gen_helper_reset_rf(cpu_env
);
2764 if (s
->singlestep_enabled
) {
2765 gen_helper_debug(cpu_env
);
2767 gen_helper_single_step(cpu_env
);
2771 s
->is_jmp
= DISAS_TB_JUMP
;
2774 /* generate a jump to eip. No segment change must happen before as a
2775 direct call to the next block may occur */
2776 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2779 gen_update_cc_op(s
);
2780 gen_goto_tb(s
, tb_num
, eip
);
2781 s
->is_jmp
= DISAS_TB_JUMP
;
2788 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2790 gen_jmp_tb(s
, eip
, 0);
2793 static inline void gen_ldq_env_A0(int idx
, int offset
)
2795 int mem_index
= (idx
>> 2) - 1;
2796 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2797 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2800 static inline void gen_stq_env_A0(int idx
, int offset
)
2802 int mem_index
= (idx
>> 2) - 1;
2803 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2804 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2807 static inline void gen_ldo_env_A0(int idx
, int offset
)
2809 int mem_index
= (idx
>> 2) - 1;
2810 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2811 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2812 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2813 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2814 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2817 static inline void gen_sto_env_A0(int idx
, int offset
)
2819 int mem_index
= (idx
>> 2) - 1;
2820 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2821 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2822 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2823 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2824 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2827 static inline void gen_op_movo(int d_offset
, int s_offset
)
2829 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2830 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2831 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
+ 8);
2832 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
+ 8);
2835 static inline void gen_op_movq(int d_offset
, int s_offset
)
2837 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2838 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2841 static inline void gen_op_movl(int d_offset
, int s_offset
)
2843 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
, s_offset
);
2844 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, d_offset
);
2847 static inline void gen_op_movq_env_0(int d_offset
)
2849 tcg_gen_movi_i64(cpu_tmp1_i64
, 0);
2850 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2853 typedef void (*SSEFunc_i_ep
)(TCGv_i32 val
, TCGv_ptr env
, TCGv_ptr reg
);
2854 typedef void (*SSEFunc_l_ep
)(TCGv_i64 val
, TCGv_ptr env
, TCGv_ptr reg
);
2855 typedef void (*SSEFunc_0_epi
)(TCGv_ptr env
, TCGv_ptr reg
, TCGv_i32 val
);
2856 typedef void (*SSEFunc_0_epl
)(TCGv_ptr env
, TCGv_ptr reg
, TCGv_i64 val
);
2857 typedef void (*SSEFunc_0_epp
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
);
2858 typedef void (*SSEFunc_0_eppi
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
,
2860 typedef void (*SSEFunc_0_ppi
)(TCGv_ptr reg_a
, TCGv_ptr reg_b
, TCGv_i32 val
);
2861 typedef void (*SSEFunc_0_eppt
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
,
2864 #define SSE_SPECIAL ((void *)1)
2865 #define SSE_DUMMY ((void *)2)
2867 #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm }
2868 #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \
2869 gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, }
2871 static const SSEFunc_0_epp sse_op_table1
[256][4] = {
2872 /* 3DNow! extensions */
2873 [0x0e] = { SSE_DUMMY
}, /* femms */
2874 [0x0f] = { SSE_DUMMY
}, /* pf... */
2875 /* pure SSE operations */
2876 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2877 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2878 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd, movsldup, movddup */
2879 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2880 [0x14] = { gen_helper_punpckldq_xmm
, gen_helper_punpcklqdq_xmm
},
2881 [0x15] = { gen_helper_punpckhdq_xmm
, gen_helper_punpckhqdq_xmm
},
2882 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2883 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2885 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2886 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2887 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2888 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd, movntss, movntsd */
2889 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2890 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2891 [0x2e] = { gen_helper_ucomiss
, gen_helper_ucomisd
},
2892 [0x2f] = { gen_helper_comiss
, gen_helper_comisd
},
2893 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2894 [0x51] = SSE_FOP(sqrt
),
2895 [0x52] = { gen_helper_rsqrtps
, NULL
, gen_helper_rsqrtss
, NULL
},
2896 [0x53] = { gen_helper_rcpps
, NULL
, gen_helper_rcpss
, NULL
},
2897 [0x54] = { gen_helper_pand_xmm
, gen_helper_pand_xmm
}, /* andps, andpd */
2898 [0x55] = { gen_helper_pandn_xmm
, gen_helper_pandn_xmm
}, /* andnps, andnpd */
2899 [0x56] = { gen_helper_por_xmm
, gen_helper_por_xmm
}, /* orps, orpd */
2900 [0x57] = { gen_helper_pxor_xmm
, gen_helper_pxor_xmm
}, /* xorps, xorpd */
2901 [0x58] = SSE_FOP(add
),
2902 [0x59] = SSE_FOP(mul
),
2903 [0x5a] = { gen_helper_cvtps2pd
, gen_helper_cvtpd2ps
,
2904 gen_helper_cvtss2sd
, gen_helper_cvtsd2ss
},
2905 [0x5b] = { gen_helper_cvtdq2ps
, gen_helper_cvtps2dq
, gen_helper_cvttps2dq
},
2906 [0x5c] = SSE_FOP(sub
),
2907 [0x5d] = SSE_FOP(min
),
2908 [0x5e] = SSE_FOP(div
),
2909 [0x5f] = SSE_FOP(max
),
2911 [0xc2] = SSE_FOP(cmpeq
),
2912 [0xc6] = { (SSEFunc_0_epp
)gen_helper_shufps
,
2913 (SSEFunc_0_epp
)gen_helper_shufpd
}, /* XXX: casts */
2915 [0x38] = { SSE_SPECIAL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2916 [0x3a] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2918 /* MMX ops and their SSE extensions */
2919 [0x60] = MMX_OP2(punpcklbw
),
2920 [0x61] = MMX_OP2(punpcklwd
),
2921 [0x62] = MMX_OP2(punpckldq
),
2922 [0x63] = MMX_OP2(packsswb
),
2923 [0x64] = MMX_OP2(pcmpgtb
),
2924 [0x65] = MMX_OP2(pcmpgtw
),
2925 [0x66] = MMX_OP2(pcmpgtl
),
2926 [0x67] = MMX_OP2(packuswb
),
2927 [0x68] = MMX_OP2(punpckhbw
),
2928 [0x69] = MMX_OP2(punpckhwd
),
2929 [0x6a] = MMX_OP2(punpckhdq
),
2930 [0x6b] = MMX_OP2(packssdw
),
2931 [0x6c] = { NULL
, gen_helper_punpcklqdq_xmm
},
2932 [0x6d] = { NULL
, gen_helper_punpckhqdq_xmm
},
2933 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2934 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2935 [0x70] = { (SSEFunc_0_epp
)gen_helper_pshufw_mmx
,
2936 (SSEFunc_0_epp
)gen_helper_pshufd_xmm
,
2937 (SSEFunc_0_epp
)gen_helper_pshufhw_xmm
,
2938 (SSEFunc_0_epp
)gen_helper_pshuflw_xmm
}, /* XXX: casts */
2939 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2940 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2941 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2942 [0x74] = MMX_OP2(pcmpeqb
),
2943 [0x75] = MMX_OP2(pcmpeqw
),
2944 [0x76] = MMX_OP2(pcmpeql
),
2945 [0x77] = { SSE_DUMMY
}, /* emms */
2946 [0x78] = { NULL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* extrq_i, insertq_i */
2947 [0x79] = { NULL
, gen_helper_extrq_r
, NULL
, gen_helper_insertq_r
},
2948 [0x7c] = { NULL
, gen_helper_haddpd
, NULL
, gen_helper_haddps
},
2949 [0x7d] = { NULL
, gen_helper_hsubpd
, NULL
, gen_helper_hsubps
},
2950 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2951 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2952 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2953 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2954 [0xd0] = { NULL
, gen_helper_addsubpd
, NULL
, gen_helper_addsubps
},
2955 [0xd1] = MMX_OP2(psrlw
),
2956 [0xd2] = MMX_OP2(psrld
),
2957 [0xd3] = MMX_OP2(psrlq
),
2958 [0xd4] = MMX_OP2(paddq
),
2959 [0xd5] = MMX_OP2(pmullw
),
2960 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2961 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2962 [0xd8] = MMX_OP2(psubusb
),
2963 [0xd9] = MMX_OP2(psubusw
),
2964 [0xda] = MMX_OP2(pminub
),
2965 [0xdb] = MMX_OP2(pand
),
2966 [0xdc] = MMX_OP2(paddusb
),
2967 [0xdd] = MMX_OP2(paddusw
),
2968 [0xde] = MMX_OP2(pmaxub
),
2969 [0xdf] = MMX_OP2(pandn
),
2970 [0xe0] = MMX_OP2(pavgb
),
2971 [0xe1] = MMX_OP2(psraw
),
2972 [0xe2] = MMX_OP2(psrad
),
2973 [0xe3] = MMX_OP2(pavgw
),
2974 [0xe4] = MMX_OP2(pmulhuw
),
2975 [0xe5] = MMX_OP2(pmulhw
),
2976 [0xe6] = { NULL
, gen_helper_cvttpd2dq
, gen_helper_cvtdq2pd
, gen_helper_cvtpd2dq
},
2977 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2978 [0xe8] = MMX_OP2(psubsb
),
2979 [0xe9] = MMX_OP2(psubsw
),
2980 [0xea] = MMX_OP2(pminsw
),
2981 [0xeb] = MMX_OP2(por
),
2982 [0xec] = MMX_OP2(paddsb
),
2983 [0xed] = MMX_OP2(paddsw
),
2984 [0xee] = MMX_OP2(pmaxsw
),
2985 [0xef] = MMX_OP2(pxor
),
2986 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu */
2987 [0xf1] = MMX_OP2(psllw
),
2988 [0xf2] = MMX_OP2(pslld
),
2989 [0xf3] = MMX_OP2(psllq
),
2990 [0xf4] = MMX_OP2(pmuludq
),
2991 [0xf5] = MMX_OP2(pmaddwd
),
2992 [0xf6] = MMX_OP2(psadbw
),
2993 [0xf7] = { (SSEFunc_0_epp
)gen_helper_maskmov_mmx
,
2994 (SSEFunc_0_epp
)gen_helper_maskmov_xmm
}, /* XXX: casts */
2995 [0xf8] = MMX_OP2(psubb
),
2996 [0xf9] = MMX_OP2(psubw
),
2997 [0xfa] = MMX_OP2(psubl
),
2998 [0xfb] = MMX_OP2(psubq
),
2999 [0xfc] = MMX_OP2(paddb
),
3000 [0xfd] = MMX_OP2(paddw
),
3001 [0xfe] = MMX_OP2(paddl
),
3004 static const SSEFunc_0_epp sse_op_table2
[3 * 8][2] = {
3005 [0 + 2] = MMX_OP2(psrlw
),
3006 [0 + 4] = MMX_OP2(psraw
),
3007 [0 + 6] = MMX_OP2(psllw
),
3008 [8 + 2] = MMX_OP2(psrld
),
3009 [8 + 4] = MMX_OP2(psrad
),
3010 [8 + 6] = MMX_OP2(pslld
),
3011 [16 + 2] = MMX_OP2(psrlq
),
3012 [16 + 3] = { NULL
, gen_helper_psrldq_xmm
},
3013 [16 + 6] = MMX_OP2(psllq
),
3014 [16 + 7] = { NULL
, gen_helper_pslldq_xmm
},
3017 static const SSEFunc_0_epi sse_op_table3ai
[] = {
3018 gen_helper_cvtsi2ss
,
3022 #ifdef TARGET_X86_64
3023 static const SSEFunc_0_epl sse_op_table3aq
[] = {
3024 gen_helper_cvtsq2ss
,
3029 static const SSEFunc_i_ep sse_op_table3bi
[] = {
3030 gen_helper_cvttss2si
,
3031 gen_helper_cvtss2si
,
3032 gen_helper_cvttsd2si
,
3036 #ifdef TARGET_X86_64
3037 static const SSEFunc_l_ep sse_op_table3bq
[] = {
3038 gen_helper_cvttss2sq
,
3039 gen_helper_cvtss2sq
,
3040 gen_helper_cvttsd2sq
,
3045 static const SSEFunc_0_epp sse_op_table4
[8][4] = {
3056 static const SSEFunc_0_epp sse_op_table5
[256] = {
3057 [0x0c] = gen_helper_pi2fw
,
3058 [0x0d] = gen_helper_pi2fd
,
3059 [0x1c] = gen_helper_pf2iw
,
3060 [0x1d] = gen_helper_pf2id
,
3061 [0x8a] = gen_helper_pfnacc
,
3062 [0x8e] = gen_helper_pfpnacc
,
3063 [0x90] = gen_helper_pfcmpge
,
3064 [0x94] = gen_helper_pfmin
,
3065 [0x96] = gen_helper_pfrcp
,
3066 [0x97] = gen_helper_pfrsqrt
,
3067 [0x9a] = gen_helper_pfsub
,
3068 [0x9e] = gen_helper_pfadd
,
3069 [0xa0] = gen_helper_pfcmpgt
,
3070 [0xa4] = gen_helper_pfmax
,
3071 [0xa6] = gen_helper_movq
, /* pfrcpit1; no need to actually increase precision */
3072 [0xa7] = gen_helper_movq
, /* pfrsqit1 */
3073 [0xaa] = gen_helper_pfsubr
,
3074 [0xae] = gen_helper_pfacc
,
3075 [0xb0] = gen_helper_pfcmpeq
,
3076 [0xb4] = gen_helper_pfmul
,
3077 [0xb6] = gen_helper_movq
, /* pfrcpit2 */
3078 [0xb7] = gen_helper_pmulhrw_mmx
,
3079 [0xbb] = gen_helper_pswapd
,
3080 [0xbf] = gen_helper_pavgb_mmx
/* pavgusb */
3083 struct SSEOpHelper_epp
{
3084 SSEFunc_0_epp op
[2];
3088 struct SSEOpHelper_eppi
{
3089 SSEFunc_0_eppi op
[2];
3093 #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
3094 #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 }
3095 #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 }
3096 #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 }
3098 static const struct SSEOpHelper_epp sse_op_table6
[256] = {
3099 [0x00] = SSSE3_OP(pshufb
),
3100 [0x01] = SSSE3_OP(phaddw
),
3101 [0x02] = SSSE3_OP(phaddd
),
3102 [0x03] = SSSE3_OP(phaddsw
),
3103 [0x04] = SSSE3_OP(pmaddubsw
),
3104 [0x05] = SSSE3_OP(phsubw
),
3105 [0x06] = SSSE3_OP(phsubd
),
3106 [0x07] = SSSE3_OP(phsubsw
),
3107 [0x08] = SSSE3_OP(psignb
),
3108 [0x09] = SSSE3_OP(psignw
),
3109 [0x0a] = SSSE3_OP(psignd
),
3110 [0x0b] = SSSE3_OP(pmulhrsw
),
3111 [0x10] = SSE41_OP(pblendvb
),
3112 [0x14] = SSE41_OP(blendvps
),
3113 [0x15] = SSE41_OP(blendvpd
),
3114 [0x17] = SSE41_OP(ptest
),
3115 [0x1c] = SSSE3_OP(pabsb
),
3116 [0x1d] = SSSE3_OP(pabsw
),
3117 [0x1e] = SSSE3_OP(pabsd
),
3118 [0x20] = SSE41_OP(pmovsxbw
),
3119 [0x21] = SSE41_OP(pmovsxbd
),
3120 [0x22] = SSE41_OP(pmovsxbq
),
3121 [0x23] = SSE41_OP(pmovsxwd
),
3122 [0x24] = SSE41_OP(pmovsxwq
),
3123 [0x25] = SSE41_OP(pmovsxdq
),
3124 [0x28] = SSE41_OP(pmuldq
),
3125 [0x29] = SSE41_OP(pcmpeqq
),
3126 [0x2a] = SSE41_SPECIAL
, /* movntqda */
3127 [0x2b] = SSE41_OP(packusdw
),
3128 [0x30] = SSE41_OP(pmovzxbw
),
3129 [0x31] = SSE41_OP(pmovzxbd
),
3130 [0x32] = SSE41_OP(pmovzxbq
),
3131 [0x33] = SSE41_OP(pmovzxwd
),
3132 [0x34] = SSE41_OP(pmovzxwq
),
3133 [0x35] = SSE41_OP(pmovzxdq
),
3134 [0x37] = SSE42_OP(pcmpgtq
),
3135 [0x38] = SSE41_OP(pminsb
),
3136 [0x39] = SSE41_OP(pminsd
),
3137 [0x3a] = SSE41_OP(pminuw
),
3138 [0x3b] = SSE41_OP(pminud
),
3139 [0x3c] = SSE41_OP(pmaxsb
),
3140 [0x3d] = SSE41_OP(pmaxsd
),
3141 [0x3e] = SSE41_OP(pmaxuw
),
3142 [0x3f] = SSE41_OP(pmaxud
),
3143 [0x40] = SSE41_OP(pmulld
),
3144 [0x41] = SSE41_OP(phminposuw
),
3147 static const struct SSEOpHelper_eppi sse_op_table7
[256] = {
3148 [0x08] = SSE41_OP(roundps
),
3149 [0x09] = SSE41_OP(roundpd
),
3150 [0x0a] = SSE41_OP(roundss
),
3151 [0x0b] = SSE41_OP(roundsd
),
3152 [0x0c] = SSE41_OP(blendps
),
3153 [0x0d] = SSE41_OP(blendpd
),
3154 [0x0e] = SSE41_OP(pblendw
),
3155 [0x0f] = SSSE3_OP(palignr
),
3156 [0x14] = SSE41_SPECIAL
, /* pextrb */
3157 [0x15] = SSE41_SPECIAL
, /* pextrw */
3158 [0x16] = SSE41_SPECIAL
, /* pextrd/pextrq */
3159 [0x17] = SSE41_SPECIAL
, /* extractps */
3160 [0x20] = SSE41_SPECIAL
, /* pinsrb */
3161 [0x21] = SSE41_SPECIAL
, /* insertps */
3162 [0x22] = SSE41_SPECIAL
, /* pinsrd/pinsrq */
3163 [0x40] = SSE41_OP(dpps
),
3164 [0x41] = SSE41_OP(dppd
),
3165 [0x42] = SSE41_OP(mpsadbw
),
3166 [0x60] = SSE42_OP(pcmpestrm
),
3167 [0x61] = SSE42_OP(pcmpestri
),
3168 [0x62] = SSE42_OP(pcmpistrm
),
3169 [0x63] = SSE42_OP(pcmpistri
),
3172 static void gen_sse(CPUX86State
*env
, DisasContext
*s
, int b
,
3173 target_ulong pc_start
, int rex_r
)
3175 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
3176 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
3177 SSEFunc_0_epp sse_fn_epp
;
3178 SSEFunc_0_eppi sse_fn_eppi
;
3179 SSEFunc_0_ppi sse_fn_ppi
;
3180 SSEFunc_0_eppt sse_fn_eppt
;
3183 if (s
->prefix
& PREFIX_DATA
)
3185 else if (s
->prefix
& PREFIX_REPZ
)
3187 else if (s
->prefix
& PREFIX_REPNZ
)
3191 sse_fn_epp
= sse_op_table1
[b
][b1
];
3195 if ((b
<= 0x5f && b
>= 0x10) || b
== 0xc6 || b
== 0xc2) {
3205 /* simple MMX/SSE operation */
3206 if (s
->flags
& HF_TS_MASK
) {
3207 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
3210 if (s
->flags
& HF_EM_MASK
) {
3212 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
3215 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
3216 if ((b
!= 0x38 && b
!= 0x3a) || (s
->prefix
& PREFIX_DATA
))
3219 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3222 gen_helper_emms(cpu_env
);
3227 gen_helper_emms(cpu_env
);
3230 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
3231 the static cpu state) */
3233 gen_helper_enter_mmx(cpu_env
);
3236 modrm
= cpu_ldub_code(env
, s
->pc
++);
3237 reg
= ((modrm
>> 3) & 7);
3240 mod
= (modrm
>> 6) & 3;
3241 if (sse_fn_epp
== SSE_SPECIAL
) {
3244 case 0x0e7: /* movntq */
3247 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3248 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3250 case 0x1e7: /* movntdq */
3251 case 0x02b: /* movntps */
3252 case 0x12b: /* movntps */
3255 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3256 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3258 case 0x3f0: /* lddqu */
3261 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3262 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3264 case 0x22b: /* movntss */
3265 case 0x32b: /* movntsd */
3268 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3270 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,
3273 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3274 xmm_regs
[reg
].XMM_L(0)));
3275 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3278 case 0x6e: /* movd mm, ea */
3279 #ifdef TARGET_X86_64
3280 if (s
->dflag
== 2) {
3281 gen_ldst_modrm(env
, s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3282 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3286 gen_ldst_modrm(env
, s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3287 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3288 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3289 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3290 gen_helper_movl_mm_T0_mmx(cpu_ptr0
, cpu_tmp2_i32
);
3293 case 0x16e: /* movd xmm, ea */
3294 #ifdef TARGET_X86_64
3295 if (s
->dflag
== 2) {
3296 gen_ldst_modrm(env
, s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3297 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3298 offsetof(CPUX86State
,xmm_regs
[reg
]));
3299 gen_helper_movq_mm_T0_xmm(cpu_ptr0
, cpu_T
[0]);
3303 gen_ldst_modrm(env
, s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3304 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3305 offsetof(CPUX86State
,xmm_regs
[reg
]));
3306 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3307 gen_helper_movl_mm_T0_xmm(cpu_ptr0
, cpu_tmp2_i32
);
3310 case 0x6f: /* movq mm, ea */
3312 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3313 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3316 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3317 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3318 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3319 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3322 case 0x010: /* movups */
3323 case 0x110: /* movupd */
3324 case 0x028: /* movaps */
3325 case 0x128: /* movapd */
3326 case 0x16f: /* movdqa xmm, ea */
3327 case 0x26f: /* movdqu xmm, ea */
3329 gen_lea_modrm(env
, 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_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
3334 offsetof(CPUX86State
,xmm_regs
[rm
]));
3337 case 0x210: /* movss xmm, ea */
3339 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3340 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3341 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3343 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3344 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3345 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3347 rm
= (modrm
& 7) | REX_B(s
);
3348 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3349 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3352 case 0x310: /* movsd xmm, ea */
3354 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3355 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3357 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3358 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3360 rm
= (modrm
& 7) | REX_B(s
);
3361 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3362 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3365 case 0x012: /* movlps */
3366 case 0x112: /* movlpd */
3368 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3369 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3372 rm
= (modrm
& 7) | REX_B(s
);
3373 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3374 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3377 case 0x212: /* movsldup */
3379 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3380 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3382 rm
= (modrm
& 7) | REX_B(s
);
3383 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3384 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3385 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3386 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(2)));
3388 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3389 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3390 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3391 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3393 case 0x312: /* movddup */
3395 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3396 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3398 rm
= (modrm
& 7) | REX_B(s
);
3399 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3400 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3402 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3403 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3405 case 0x016: /* movhps */
3406 case 0x116: /* movhpd */
3408 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3409 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3412 rm
= (modrm
& 7) | REX_B(s
);
3413 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3414 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3417 case 0x216: /* movshdup */
3419 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3420 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3422 rm
= (modrm
& 7) | REX_B(s
);
3423 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3424 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
3425 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3426 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
3428 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3429 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3430 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3431 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3436 int bit_index
, field_length
;
3438 if (b1
== 1 && reg
!= 0)
3440 field_length
= cpu_ldub_code(env
, s
->pc
++) & 0x3F;
3441 bit_index
= cpu_ldub_code(env
, s
->pc
++) & 0x3F;
3442 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3443 offsetof(CPUX86State
,xmm_regs
[reg
]));
3445 gen_helper_extrq_i(cpu_env
, cpu_ptr0
,
3446 tcg_const_i32(bit_index
),
3447 tcg_const_i32(field_length
));
3449 gen_helper_insertq_i(cpu_env
, cpu_ptr0
,
3450 tcg_const_i32(bit_index
),
3451 tcg_const_i32(field_length
));
3454 case 0x7e: /* movd ea, mm */
3455 #ifdef TARGET_X86_64
3456 if (s
->dflag
== 2) {
3457 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3458 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3459 gen_ldst_modrm(env
, s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3463 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3464 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_L(0)));
3465 gen_ldst_modrm(env
, s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3468 case 0x17e: /* movd ea, xmm */
3469 #ifdef TARGET_X86_64
3470 if (s
->dflag
== 2) {
3471 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3472 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3473 gen_ldst_modrm(env
, s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3477 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3478 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3479 gen_ldst_modrm(env
, s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3482 case 0x27e: /* movq xmm, ea */
3484 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3485 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3487 rm
= (modrm
& 7) | REX_B(s
);
3488 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3489 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3491 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3493 case 0x7f: /* movq ea, mm */
3495 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3496 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3499 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
3500 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3503 case 0x011: /* movups */
3504 case 0x111: /* movupd */
3505 case 0x029: /* movaps */
3506 case 0x129: /* movapd */
3507 case 0x17f: /* movdqa ea, xmm */
3508 case 0x27f: /* movdqu ea, xmm */
3510 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3511 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3513 rm
= (modrm
& 7) | REX_B(s
);
3514 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
3515 offsetof(CPUX86State
,xmm_regs
[reg
]));
3518 case 0x211: /* movss ea, xmm */
3520 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3521 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3522 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3524 rm
= (modrm
& 7) | REX_B(s
);
3525 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
3526 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3529 case 0x311: /* movsd ea, xmm */
3531 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3532 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3534 rm
= (modrm
& 7) | REX_B(s
);
3535 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3536 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3539 case 0x013: /* movlps */
3540 case 0x113: /* movlpd */
3542 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3543 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3548 case 0x017: /* movhps */
3549 case 0x117: /* movhpd */
3551 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3552 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3557 case 0x71: /* shift mm, im */
3560 case 0x171: /* shift xmm, im */
3566 val
= cpu_ldub_code(env
, s
->pc
++);
3568 gen_op_movl_T0_im(val
);
3569 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3571 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
3572 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
3574 gen_op_movl_T0_im(val
);
3575 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
3577 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
3578 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
3580 sse_fn_epp
= sse_op_table2
[((b
- 1) & 3) * 8 +
3581 (((modrm
>> 3)) & 7)][b1
];
3586 rm
= (modrm
& 7) | REX_B(s
);
3587 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3590 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3592 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3593 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op1_offset
);
3594 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3596 case 0x050: /* movmskps */
3597 rm
= (modrm
& 7) | REX_B(s
);
3598 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3599 offsetof(CPUX86State
,xmm_regs
[rm
]));
3600 gen_helper_movmskps(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3601 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3602 gen_op_mov_reg_T0(OT_LONG
, reg
);
3604 case 0x150: /* movmskpd */
3605 rm
= (modrm
& 7) | REX_B(s
);
3606 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3607 offsetof(CPUX86State
,xmm_regs
[rm
]));
3608 gen_helper_movmskpd(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3609 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3610 gen_op_mov_reg_T0(OT_LONG
, reg
);
3612 case 0x02a: /* cvtpi2ps */
3613 case 0x12a: /* cvtpi2pd */
3614 gen_helper_enter_mmx(cpu_env
);
3616 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3617 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3618 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3621 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3623 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3624 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3625 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3628 gen_helper_cvtpi2ps(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3632 gen_helper_cvtpi2pd(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3636 case 0x22a: /* cvtsi2ss */
3637 case 0x32a: /* cvtsi2sd */
3638 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3639 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
3640 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3641 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3642 if (ot
== OT_LONG
) {
3643 SSEFunc_0_epi sse_fn_epi
= sse_op_table3ai
[(b
>> 8) & 1];
3644 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3645 sse_fn_epi(cpu_env
, cpu_ptr0
, cpu_tmp2_i32
);
3647 #ifdef TARGET_X86_64
3648 SSEFunc_0_epl sse_fn_epl
= sse_op_table3aq
[(b
>> 8) & 1];
3649 sse_fn_epl(cpu_env
, cpu_ptr0
, cpu_T
[0]);
3655 case 0x02c: /* cvttps2pi */
3656 case 0x12c: /* cvttpd2pi */
3657 case 0x02d: /* cvtps2pi */
3658 case 0x12d: /* cvtpd2pi */
3659 gen_helper_enter_mmx(cpu_env
);
3661 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3662 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3663 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3665 rm
= (modrm
& 7) | REX_B(s
);
3666 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3668 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
3669 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3670 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3673 gen_helper_cvttps2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3676 gen_helper_cvttpd2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3679 gen_helper_cvtps2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3682 gen_helper_cvtpd2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3686 case 0x22c: /* cvttss2si */
3687 case 0x32c: /* cvttsd2si */
3688 case 0x22d: /* cvtss2si */
3689 case 0x32d: /* cvtsd2si */
3690 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3692 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3694 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
3696 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3697 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3699 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3701 rm
= (modrm
& 7) | REX_B(s
);
3702 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3704 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3705 if (ot
== OT_LONG
) {
3706 SSEFunc_i_ep sse_fn_i_ep
=
3707 sse_op_table3bi
[((b
>> 7) & 2) | (b
& 1)];
3708 sse_fn_i_ep(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3709 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3711 #ifdef TARGET_X86_64
3712 SSEFunc_l_ep sse_fn_l_ep
=
3713 sse_op_table3bq
[((b
>> 7) & 2) | (b
& 1)];
3714 sse_fn_l_ep(cpu_T
[0], cpu_env
, cpu_ptr0
);
3719 gen_op_mov_reg_T0(ot
, reg
);
3721 case 0xc4: /* pinsrw */
3724 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3725 val
= cpu_ldub_code(env
, s
->pc
++);
3728 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3729 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_W(val
)));
3732 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3733 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_W(val
)));
3736 case 0xc5: /* pextrw */
3740 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3741 val
= cpu_ldub_code(env
, s
->pc
++);
3744 rm
= (modrm
& 7) | REX_B(s
);
3745 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3746 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_W(val
)));
3750 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3751 offsetof(CPUX86State
,fpregs
[rm
].mmx
.MMX_W(val
)));
3753 reg
= ((modrm
>> 3) & 7) | rex_r
;
3754 gen_op_mov_reg_T0(ot
, reg
);
3756 case 0x1d6: /* movq ea, xmm */
3758 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3759 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3761 rm
= (modrm
& 7) | REX_B(s
);
3762 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3763 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3764 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3767 case 0x2d6: /* movq2dq */
3768 gen_helper_enter_mmx(cpu_env
);
3770 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3771 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3772 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3774 case 0x3d6: /* movdq2q */
3775 gen_helper_enter_mmx(cpu_env
);
3776 rm
= (modrm
& 7) | REX_B(s
);
3777 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
),
3778 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3780 case 0xd7: /* pmovmskb */
3785 rm
= (modrm
& 7) | REX_B(s
);
3786 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,xmm_regs
[rm
]));
3787 gen_helper_pmovmskb_xmm(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3790 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3791 gen_helper_pmovmskb_mmx(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3793 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3794 reg
= ((modrm
>> 3) & 7) | rex_r
;
3795 gen_op_mov_reg_T0(OT_LONG
, reg
);
3798 if (s
->prefix
& PREFIX_REPNZ
)
3802 modrm
= cpu_ldub_code(env
, s
->pc
++);
3804 reg
= ((modrm
>> 3) & 7) | rex_r
;
3805 mod
= (modrm
>> 6) & 3;
3810 sse_fn_epp
= sse_op_table6
[b
].op
[b1
];
3814 if (!(s
->cpuid_ext_features
& sse_op_table6
[b
].ext_mask
))
3818 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3820 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3822 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3823 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3825 case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */
3826 case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */
3827 case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */
3828 gen_ldq_env_A0(s
->mem_index
, op2_offset
+
3829 offsetof(XMMReg
, XMM_Q(0)));
3831 case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */
3832 case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */
3833 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3834 (s
->mem_index
>> 2) - 1);
3835 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3836 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, op2_offset
+
3837 offsetof(XMMReg
, XMM_L(0)));
3839 case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */
3840 tcg_gen_qemu_ld16u(cpu_tmp0
, cpu_A0
,
3841 (s
->mem_index
>> 2) - 1);
3842 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, op2_offset
+
3843 offsetof(XMMReg
, XMM_W(0)));
3845 case 0x2a: /* movntqda */
3846 gen_ldo_env_A0(s
->mem_index
, op1_offset
);
3849 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3853 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3855 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3857 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3858 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3859 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3862 if (sse_fn_epp
== SSE_SPECIAL
) {
3866 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3867 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3868 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3871 s
->cc_op
= CC_OP_EFLAGS
;
3873 case 0x338: /* crc32 */
3876 modrm
= cpu_ldub_code(env
, s
->pc
++);
3877 reg
= ((modrm
>> 3) & 7) | rex_r
;
3879 if (b
!= 0xf0 && b
!= 0xf1)
3881 if (!(s
->cpuid_ext_features
& CPUID_EXT_SSE42
))
3886 else if (b
== 0xf1 && s
->dflag
!= 2)
3887 if (s
->prefix
& PREFIX_DATA
)
3894 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
3895 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3896 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
3897 gen_helper_crc32(cpu_T
[0], cpu_tmp2_i32
,
3898 cpu_T
[0], tcg_const_i32(8 << ot
));
3900 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3901 gen_op_mov_reg_T0(ot
, reg
);
3906 modrm
= cpu_ldub_code(env
, s
->pc
++);
3908 reg
= ((modrm
>> 3) & 7) | rex_r
;
3909 mod
= (modrm
>> 6) & 3;
3914 sse_fn_eppi
= sse_op_table7
[b
].op
[b1
];
3918 if (!(s
->cpuid_ext_features
& sse_op_table7
[b
].ext_mask
))
3921 if (sse_fn_eppi
== SSE_SPECIAL
) {
3922 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3923 rm
= (modrm
& 7) | REX_B(s
);
3925 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
3926 reg
= ((modrm
>> 3) & 7) | rex_r
;
3927 val
= cpu_ldub_code(env
, s
->pc
++);
3929 case 0x14: /* pextrb */
3930 tcg_gen_ld8u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3931 xmm_regs
[reg
].XMM_B(val
& 15)));
3933 gen_op_mov_reg_T0(ot
, rm
);
3935 tcg_gen_qemu_st8(cpu_T
[0], cpu_A0
,
3936 (s
->mem_index
>> 2) - 1);
3938 case 0x15: /* pextrw */
3939 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3940 xmm_regs
[reg
].XMM_W(val
& 7)));
3942 gen_op_mov_reg_T0(ot
, rm
);
3944 tcg_gen_qemu_st16(cpu_T
[0], cpu_A0
,
3945 (s
->mem_index
>> 2) - 1);
3948 if (ot
== OT_LONG
) { /* pextrd */
3949 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3950 offsetof(CPUX86State
,
3951 xmm_regs
[reg
].XMM_L(val
& 3)));
3952 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3954 gen_op_mov_reg_v(ot
, rm
, cpu_T
[0]);
3956 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3957 (s
->mem_index
>> 2) - 1);
3958 } else { /* pextrq */
3959 #ifdef TARGET_X86_64
3960 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3961 offsetof(CPUX86State
,
3962 xmm_regs
[reg
].XMM_Q(val
& 1)));
3964 gen_op_mov_reg_v(ot
, rm
, cpu_tmp1_i64
);
3966 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
3967 (s
->mem_index
>> 2) - 1);
3973 case 0x17: /* extractps */
3974 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3975 xmm_regs
[reg
].XMM_L(val
& 3)));
3977 gen_op_mov_reg_T0(ot
, rm
);
3979 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3980 (s
->mem_index
>> 2) - 1);
3982 case 0x20: /* pinsrb */
3984 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
3986 tcg_gen_qemu_ld8u(cpu_tmp0
, cpu_A0
,
3987 (s
->mem_index
>> 2) - 1);
3988 tcg_gen_st8_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
,
3989 xmm_regs
[reg
].XMM_B(val
& 15)));
3991 case 0x21: /* insertps */
3993 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3994 offsetof(CPUX86State
,xmm_regs
[rm
]
3995 .XMM_L((val
>> 6) & 3)));
3997 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3998 (s
->mem_index
>> 2) - 1);
3999 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
4001 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
4002 offsetof(CPUX86State
,xmm_regs
[reg
]
4003 .XMM_L((val
>> 4) & 3)));
4005 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4006 cpu_env
, offsetof(CPUX86State
,
4007 xmm_regs
[reg
].XMM_L(0)));
4009 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4010 cpu_env
, offsetof(CPUX86State
,
4011 xmm_regs
[reg
].XMM_L(1)));
4013 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4014 cpu_env
, offsetof(CPUX86State
,
4015 xmm_regs
[reg
].XMM_L(2)));
4017 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4018 cpu_env
, offsetof(CPUX86State
,
4019 xmm_regs
[reg
].XMM_L(3)));
4022 if (ot
== OT_LONG
) { /* pinsrd */
4024 gen_op_mov_v_reg(ot
, cpu_tmp0
, rm
);
4026 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
4027 (s
->mem_index
>> 2) - 1);
4028 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
4029 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
4030 offsetof(CPUX86State
,
4031 xmm_regs
[reg
].XMM_L(val
& 3)));
4032 } else { /* pinsrq */
4033 #ifdef TARGET_X86_64
4035 gen_op_mov_v_reg(ot
, cpu_tmp1_i64
, rm
);
4037 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
4038 (s
->mem_index
>> 2) - 1);
4039 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
4040 offsetof(CPUX86State
,
4041 xmm_regs
[reg
].XMM_Q(val
& 1)));
4052 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
4054 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
4056 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
4057 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4058 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4061 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4063 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4065 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4066 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4067 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4070 val
= cpu_ldub_code(env
, s
->pc
++);
4072 if ((b
& 0xfc) == 0x60) { /* pcmpXstrX */
4073 s
->cc_op
= CC_OP_EFLAGS
;
4076 /* The helper must use entire 64-bit gp registers */
4080 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4081 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4082 sse_fn_eppi(cpu_env
, cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4088 /* generic MMX or SSE operation */
4090 case 0x70: /* pshufx insn */
4091 case 0xc6: /* pshufx insn */
4092 case 0xc2: /* compare insns */
4099 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
4101 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4102 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
4103 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f && b
!= 0x5b) ||
4105 /* specific case for SSE single instructions */
4108 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
4109 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
4112 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
4115 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4118 rm
= (modrm
& 7) | REX_B(s
);
4119 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
4122 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4124 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4125 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4126 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4129 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4133 case 0x0f: /* 3DNow! data insns */
4134 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
4136 val
= cpu_ldub_code(env
, s
->pc
++);
4137 sse_fn_epp
= sse_op_table5
[val
];
4141 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4142 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4143 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4145 case 0x70: /* pshufx insn */
4146 case 0xc6: /* pshufx insn */
4147 val
= cpu_ldub_code(env
, s
->pc
++);
4148 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4149 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4150 /* XXX: introduce a new table? */
4151 sse_fn_ppi
= (SSEFunc_0_ppi
)sse_fn_epp
;
4152 sse_fn_ppi(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4156 val
= cpu_ldub_code(env
, s
->pc
++);
4159 sse_fn_epp
= sse_op_table4
[val
][b1
];
4161 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4162 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4163 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4166 /* maskmov : we must prepare A0 */
4169 #ifdef TARGET_X86_64
4170 if (s
->aflag
== 2) {
4171 gen_op_movq_A0_reg(R_EDI
);
4175 gen_op_movl_A0_reg(R_EDI
);
4177 gen_op_andl_A0_ffff();
4179 gen_add_A0_ds_seg(s
);
4181 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4182 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4183 /* XXX: introduce a new table? */
4184 sse_fn_eppt
= (SSEFunc_0_eppt
)sse_fn_epp
;
4185 sse_fn_eppt(cpu_env
, cpu_ptr0
, cpu_ptr1
, cpu_A0
);
4188 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4189 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4190 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4193 if (b
== 0x2e || b
== 0x2f) {
4194 s
->cc_op
= CC_OP_EFLAGS
;
4199 /* convert one instruction. s->is_jmp is set if the translation must
4200 be stopped. Return the next pc value */
4201 static target_ulong
disas_insn(CPUX86State
*env
, DisasContext
*s
,
4202 target_ulong pc_start
)
4204 int b
, prefixes
, aflag
, dflag
;
4206 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
4207 target_ulong next_eip
, tval
;
4210 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
4211 tcg_gen_debug_insn_start(pc_start
);
4220 #ifdef TARGET_X86_64
4225 s
->rip_offset
= 0; /* for relative ip address */
4227 b
= cpu_ldub_code(env
, s
->pc
);
4229 /* check prefixes */
4230 #ifdef TARGET_X86_64
4234 prefixes
|= PREFIX_REPZ
;
4237 prefixes
|= PREFIX_REPNZ
;
4240 prefixes
|= PREFIX_LOCK
;
4261 prefixes
|= PREFIX_DATA
;
4264 prefixes
|= PREFIX_ADR
;
4268 rex_w
= (b
>> 3) & 1;
4269 rex_r
= (b
& 0x4) << 1;
4270 s
->rex_x
= (b
& 0x2) << 2;
4271 REX_B(s
) = (b
& 0x1) << 3;
4272 x86_64_hregs
= 1; /* select uniform byte register addressing */
4276 /* 0x66 is ignored if rex.w is set */
4279 if (prefixes
& PREFIX_DATA
)
4282 if (!(prefixes
& PREFIX_ADR
))
4289 prefixes
|= PREFIX_REPZ
;
4292 prefixes
|= PREFIX_REPNZ
;
4295 prefixes
|= PREFIX_LOCK
;
4316 prefixes
|= PREFIX_DATA
;
4319 prefixes
|= PREFIX_ADR
;
4322 if (prefixes
& PREFIX_DATA
)
4324 if (prefixes
& PREFIX_ADR
)
4328 s
->prefix
= prefixes
;
4332 /* lock generation */
4333 if (prefixes
& PREFIX_LOCK
)
4336 /* now check op code */
4340 /**************************/
4341 /* extended op code */
4342 b
= cpu_ldub_code(env
, s
->pc
++) | 0x100;
4345 /**************************/
4363 ot
= dflag
+ OT_WORD
;
4366 case 0: /* OP Ev, Gv */
4367 modrm
= cpu_ldub_code(env
, s
->pc
++);
4368 reg
= ((modrm
>> 3) & 7) | rex_r
;
4369 mod
= (modrm
>> 6) & 3;
4370 rm
= (modrm
& 7) | REX_B(s
);
4372 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4374 } else if (op
== OP_XORL
&& rm
== reg
) {
4376 /* xor reg, reg optimisation */
4378 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4379 gen_op_mov_reg_T0(ot
, reg
);
4380 gen_op_update1_cc();
4385 gen_op_mov_TN_reg(ot
, 1, reg
);
4386 gen_op(s
, op
, ot
, opreg
);
4388 case 1: /* OP Gv, Ev */
4389 modrm
= cpu_ldub_code(env
, s
->pc
++);
4390 mod
= (modrm
>> 6) & 3;
4391 reg
= ((modrm
>> 3) & 7) | rex_r
;
4392 rm
= (modrm
& 7) | REX_B(s
);
4394 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4395 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4396 } else if (op
== OP_XORL
&& rm
== reg
) {
4399 gen_op_mov_TN_reg(ot
, 1, rm
);
4401 gen_op(s
, op
, ot
, reg
);
4403 case 2: /* OP A, Iv */
4404 val
= insn_get(env
, s
, ot
);
4405 gen_op_movl_T1_im(val
);
4406 gen_op(s
, op
, ot
, OR_EAX
);
4415 case 0x80: /* GRP1 */
4424 ot
= dflag
+ OT_WORD
;
4426 modrm
= cpu_ldub_code(env
, s
->pc
++);
4427 mod
= (modrm
>> 6) & 3;
4428 rm
= (modrm
& 7) | REX_B(s
);
4429 op
= (modrm
>> 3) & 7;
4435 s
->rip_offset
= insn_const_size(ot
);
4436 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4447 val
= insn_get(env
, s
, ot
);
4450 val
= (int8_t)insn_get(env
, s
, OT_BYTE
);
4453 gen_op_movl_T1_im(val
);
4454 gen_op(s
, op
, ot
, opreg
);
4458 /**************************/
4459 /* inc, dec, and other misc arith */
4460 case 0x40 ... 0x47: /* inc Gv */
4461 ot
= dflag
? OT_LONG
: OT_WORD
;
4462 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
4464 case 0x48 ... 0x4f: /* dec Gv */
4465 ot
= dflag
? OT_LONG
: OT_WORD
;
4466 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
4468 case 0xf6: /* GRP3 */
4473 ot
= dflag
+ OT_WORD
;
4475 modrm
= cpu_ldub_code(env
, s
->pc
++);
4476 mod
= (modrm
>> 6) & 3;
4477 rm
= (modrm
& 7) | REX_B(s
);
4478 op
= (modrm
>> 3) & 7;
4481 s
->rip_offset
= insn_const_size(ot
);
4482 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4483 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4485 gen_op_mov_TN_reg(ot
, 0, rm
);
4490 val
= insn_get(env
, s
, ot
);
4491 gen_op_movl_T1_im(val
);
4492 gen_op_testl_T0_T1_cc();
4493 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4496 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
4498 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4500 gen_op_mov_reg_T0(ot
, rm
);
4504 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
4506 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4508 gen_op_mov_reg_T0(ot
, rm
);
4510 gen_op_update_neg_cc();
4511 s
->cc_op
= CC_OP_SUBB
+ ot
;
4516 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4517 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
4518 tcg_gen_ext8u_tl(cpu_T
[1], cpu_T
[1]);
4519 /* XXX: use 32 bit mul which could be faster */
4520 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4521 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4522 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4523 tcg_gen_andi_tl(cpu_cc_src
, cpu_T
[0], 0xff00);
4524 s
->cc_op
= CC_OP_MULB
;
4527 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4528 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
4529 tcg_gen_ext16u_tl(cpu_T
[1], cpu_T
[1]);
4530 /* XXX: use 32 bit mul which could be faster */
4531 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4532 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4533 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4534 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4535 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4536 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4537 s
->cc_op
= CC_OP_MULW
;
4541 #ifdef TARGET_X86_64
4542 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4543 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
4544 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
4545 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4546 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4547 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4548 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4549 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4550 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4554 t0
= tcg_temp_new_i64();
4555 t1
= tcg_temp_new_i64();
4556 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4557 tcg_gen_extu_i32_i64(t0
, cpu_T
[0]);
4558 tcg_gen_extu_i32_i64(t1
, cpu_T
[1]);
4559 tcg_gen_mul_i64(t0
, t0
, t1
);
4560 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4561 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4562 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4563 tcg_gen_shri_i64(t0
, t0
, 32);
4564 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4565 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4566 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4569 s
->cc_op
= CC_OP_MULL
;
4571 #ifdef TARGET_X86_64
4573 gen_helper_mulq_EAX_T0(cpu_env
, cpu_T
[0]);
4574 s
->cc_op
= CC_OP_MULQ
;
4582 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4583 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4584 tcg_gen_ext8s_tl(cpu_T
[1], cpu_T
[1]);
4585 /* XXX: use 32 bit mul which could be faster */
4586 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4587 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4588 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4589 tcg_gen_ext8s_tl(cpu_tmp0
, cpu_T
[0]);
4590 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4591 s
->cc_op
= CC_OP_MULB
;
4594 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4595 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4596 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4597 /* XXX: use 32 bit mul which could be faster */
4598 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4599 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4600 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4601 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4602 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4603 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4604 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4605 s
->cc_op
= CC_OP_MULW
;
4609 #ifdef TARGET_X86_64
4610 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4611 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4612 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4613 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4614 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4615 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4616 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4617 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4618 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4619 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4623 t0
= tcg_temp_new_i64();
4624 t1
= tcg_temp_new_i64();
4625 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4626 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4627 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4628 tcg_gen_mul_i64(t0
, t0
, t1
);
4629 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4630 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4631 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4632 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4633 tcg_gen_shri_i64(t0
, t0
, 32);
4634 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4635 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4636 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4639 s
->cc_op
= CC_OP_MULL
;
4641 #ifdef TARGET_X86_64
4643 gen_helper_imulq_EAX_T0(cpu_env
, cpu_T
[0]);
4644 s
->cc_op
= CC_OP_MULQ
;
4652 gen_jmp_im(pc_start
- s
->cs_base
);
4653 gen_helper_divb_AL(cpu_env
, cpu_T
[0]);
4656 gen_jmp_im(pc_start
- s
->cs_base
);
4657 gen_helper_divw_AX(cpu_env
, cpu_T
[0]);
4661 gen_jmp_im(pc_start
- s
->cs_base
);
4662 gen_helper_divl_EAX(cpu_env
, cpu_T
[0]);
4664 #ifdef TARGET_X86_64
4666 gen_jmp_im(pc_start
- s
->cs_base
);
4667 gen_helper_divq_EAX(cpu_env
, cpu_T
[0]);
4675 gen_jmp_im(pc_start
- s
->cs_base
);
4676 gen_helper_idivb_AL(cpu_env
, cpu_T
[0]);
4679 gen_jmp_im(pc_start
- s
->cs_base
);
4680 gen_helper_idivw_AX(cpu_env
, cpu_T
[0]);
4684 gen_jmp_im(pc_start
- s
->cs_base
);
4685 gen_helper_idivl_EAX(cpu_env
, cpu_T
[0]);
4687 #ifdef TARGET_X86_64
4689 gen_jmp_im(pc_start
- s
->cs_base
);
4690 gen_helper_idivq_EAX(cpu_env
, cpu_T
[0]);
4700 case 0xfe: /* GRP4 */
4701 case 0xff: /* GRP5 */
4705 ot
= dflag
+ OT_WORD
;
4707 modrm
= cpu_ldub_code(env
, s
->pc
++);
4708 mod
= (modrm
>> 6) & 3;
4709 rm
= (modrm
& 7) | REX_B(s
);
4710 op
= (modrm
>> 3) & 7;
4711 if (op
>= 2 && b
== 0xfe) {
4715 if (op
== 2 || op
== 4) {
4716 /* operand size for jumps is 64 bit */
4718 } else if (op
== 3 || op
== 5) {
4719 ot
= dflag
? OT_LONG
+ (rex_w
== 1) : OT_WORD
;
4720 } else if (op
== 6) {
4721 /* default push size is 64 bit */
4722 ot
= dflag
? OT_QUAD
: OT_WORD
;
4726 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4727 if (op
>= 2 && op
!= 3 && op
!= 5)
4728 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4730 gen_op_mov_TN_reg(ot
, 0, rm
);
4734 case 0: /* inc Ev */
4739 gen_inc(s
, ot
, opreg
, 1);
4741 case 1: /* dec Ev */
4746 gen_inc(s
, ot
, opreg
, -1);
4748 case 2: /* call Ev */
4749 /* XXX: optimize if memory (no 'and' is necessary) */
4751 gen_op_andl_T0_ffff();
4752 next_eip
= s
->pc
- s
->cs_base
;
4753 gen_movtl_T1_im(next_eip
);
4758 case 3: /* lcall Ev */
4759 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4760 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4761 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4763 if (s
->pe
&& !s
->vm86
) {
4764 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4765 gen_op_set_cc_op(s
->cc_op
);
4766 gen_jmp_im(pc_start
- s
->cs_base
);
4767 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4768 gen_helper_lcall_protected(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4769 tcg_const_i32(dflag
),
4770 tcg_const_i32(s
->pc
- pc_start
));
4772 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4773 gen_helper_lcall_real(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4774 tcg_const_i32(dflag
),
4775 tcg_const_i32(s
->pc
- s
->cs_base
));
4779 case 4: /* jmp Ev */
4781 gen_op_andl_T0_ffff();
4785 case 5: /* ljmp Ev */
4786 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4787 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4788 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4790 if (s
->pe
&& !s
->vm86
) {
4791 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4792 gen_op_set_cc_op(s
->cc_op
);
4793 gen_jmp_im(pc_start
- s
->cs_base
);
4794 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4795 gen_helper_ljmp_protected(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4796 tcg_const_i32(s
->pc
- pc_start
));
4798 gen_op_movl_seg_T0_vm(R_CS
);
4799 gen_op_movl_T0_T1();
4804 case 6: /* push Ev */
4812 case 0x84: /* test Ev, Gv */
4817 ot
= dflag
+ OT_WORD
;
4819 modrm
= cpu_ldub_code(env
, s
->pc
++);
4820 reg
= ((modrm
>> 3) & 7) | rex_r
;
4822 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
4823 gen_op_mov_TN_reg(ot
, 1, reg
);
4824 gen_op_testl_T0_T1_cc();
4825 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4828 case 0xa8: /* test eAX, Iv */
4833 ot
= dflag
+ OT_WORD
;
4834 val
= insn_get(env
, s
, ot
);
4836 gen_op_mov_TN_reg(ot
, 0, OR_EAX
);
4837 gen_op_movl_T1_im(val
);
4838 gen_op_testl_T0_T1_cc();
4839 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4842 case 0x98: /* CWDE/CBW */
4843 #ifdef TARGET_X86_64
4845 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4846 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4847 gen_op_mov_reg_T0(OT_QUAD
, R_EAX
);
4851 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4852 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4853 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4855 gen_op_mov_TN_reg(OT_BYTE
, 0, R_EAX
);
4856 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4857 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4860 case 0x99: /* CDQ/CWD */
4861 #ifdef TARGET_X86_64
4863 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
4864 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 63);
4865 gen_op_mov_reg_T0(OT_QUAD
, R_EDX
);
4869 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4870 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4871 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 31);
4872 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4874 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4875 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4876 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 15);
4877 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4880 case 0x1af: /* imul Gv, Ev */
4881 case 0x69: /* imul Gv, Ev, I */
4883 ot
= dflag
+ OT_WORD
;
4884 modrm
= cpu_ldub_code(env
, s
->pc
++);
4885 reg
= ((modrm
>> 3) & 7) | rex_r
;
4887 s
->rip_offset
= insn_const_size(ot
);
4890 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
4892 val
= insn_get(env
, s
, ot
);
4893 gen_op_movl_T1_im(val
);
4894 } else if (b
== 0x6b) {
4895 val
= (int8_t)insn_get(env
, s
, OT_BYTE
);
4896 gen_op_movl_T1_im(val
);
4898 gen_op_mov_TN_reg(ot
, 1, reg
);
4901 #ifdef TARGET_X86_64
4902 if (ot
== OT_QUAD
) {
4903 gen_helper_imulq_T0_T1(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
4906 if (ot
== OT_LONG
) {
4907 #ifdef TARGET_X86_64
4908 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4909 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4910 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4911 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4912 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4913 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4917 t0
= tcg_temp_new_i64();
4918 t1
= tcg_temp_new_i64();
4919 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4920 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4921 tcg_gen_mul_i64(t0
, t0
, t1
);
4922 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4923 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4924 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4925 tcg_gen_shri_i64(t0
, t0
, 32);
4926 tcg_gen_trunc_i64_i32(cpu_T
[1], t0
);
4927 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[1], cpu_tmp0
);
4931 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4932 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4933 /* XXX: use 32 bit mul which could be faster */
4934 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4935 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4936 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4937 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4939 gen_op_mov_reg_T0(ot
, reg
);
4940 s
->cc_op
= CC_OP_MULB
+ ot
;
4943 case 0x1c1: /* xadd Ev, Gv */
4947 ot
= dflag
+ OT_WORD
;
4948 modrm
= cpu_ldub_code(env
, s
->pc
++);
4949 reg
= ((modrm
>> 3) & 7) | rex_r
;
4950 mod
= (modrm
>> 6) & 3;
4952 rm
= (modrm
& 7) | REX_B(s
);
4953 gen_op_mov_TN_reg(ot
, 0, reg
);
4954 gen_op_mov_TN_reg(ot
, 1, rm
);
4955 gen_op_addl_T0_T1();
4956 gen_op_mov_reg_T1(ot
, reg
);
4957 gen_op_mov_reg_T0(ot
, rm
);
4959 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4960 gen_op_mov_TN_reg(ot
, 0, reg
);
4961 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4962 gen_op_addl_T0_T1();
4963 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4964 gen_op_mov_reg_T1(ot
, reg
);
4966 gen_op_update2_cc();
4967 s
->cc_op
= CC_OP_ADDB
+ ot
;
4970 case 0x1b1: /* cmpxchg Ev, Gv */
4973 TCGv t0
, t1
, t2
, a0
;
4978 ot
= dflag
+ OT_WORD
;
4979 modrm
= cpu_ldub_code(env
, s
->pc
++);
4980 reg
= ((modrm
>> 3) & 7) | rex_r
;
4981 mod
= (modrm
>> 6) & 3;
4982 t0
= tcg_temp_local_new();
4983 t1
= tcg_temp_local_new();
4984 t2
= tcg_temp_local_new();
4985 a0
= tcg_temp_local_new();
4986 gen_op_mov_v_reg(ot
, t1
, reg
);
4988 rm
= (modrm
& 7) | REX_B(s
);
4989 gen_op_mov_v_reg(ot
, t0
, rm
);
4991 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
4992 tcg_gen_mov_tl(a0
, cpu_A0
);
4993 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
4994 rm
= 0; /* avoid warning */
4996 label1
= gen_new_label();
4997 tcg_gen_sub_tl(t2
, cpu_regs
[R_EAX
], t0
);
4999 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
5000 label2
= gen_new_label();
5002 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
5004 gen_set_label(label1
);
5005 gen_op_mov_reg_v(ot
, rm
, t1
);
5007 /* perform no-op store cycle like physical cpu; must be
5008 before changing accumulator to ensure idempotency if
5009 the store faults and the instruction is restarted */
5010 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
5011 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
5013 gen_set_label(label1
);
5014 gen_op_st_v(ot
+ s
->mem_index
, t1
, a0
);
5016 gen_set_label(label2
);
5017 tcg_gen_mov_tl(cpu_cc_src
, t0
);
5018 tcg_gen_mov_tl(cpu_cc_dst
, t2
);
5019 s
->cc_op
= CC_OP_SUBB
+ ot
;
5026 case 0x1c7: /* cmpxchg8b */
5027 modrm
= cpu_ldub_code(env
, s
->pc
++);
5028 mod
= (modrm
>> 6) & 3;
5029 if ((mod
== 3) || ((modrm
& 0x38) != 0x8))
5031 #ifdef TARGET_X86_64
5033 if (!(s
->cpuid_ext_features
& CPUID_EXT_CX16
))
5035 gen_jmp_im(pc_start
- s
->cs_base
);
5036 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5037 gen_op_set_cc_op(s
->cc_op
);
5038 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5039 gen_helper_cmpxchg16b(cpu_env
, cpu_A0
);
5043 if (!(s
->cpuid_features
& CPUID_CX8
))
5045 gen_jmp_im(pc_start
- s
->cs_base
);
5046 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5047 gen_op_set_cc_op(s
->cc_op
);
5048 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5049 gen_helper_cmpxchg8b(cpu_env
, cpu_A0
);
5051 s
->cc_op
= CC_OP_EFLAGS
;
5054 /**************************/
5056 case 0x50 ... 0x57: /* push */
5057 gen_op_mov_TN_reg(OT_LONG
, 0, (b
& 7) | REX_B(s
));
5060 case 0x58 ... 0x5f: /* pop */
5062 ot
= dflag
? OT_QUAD
: OT_WORD
;
5064 ot
= dflag
+ OT_WORD
;
5067 /* NOTE: order is important for pop %sp */
5069 gen_op_mov_reg_T0(ot
, (b
& 7) | REX_B(s
));
5071 case 0x60: /* pusha */
5076 case 0x61: /* popa */
5081 case 0x68: /* push Iv */
5084 ot
= dflag
? OT_QUAD
: OT_WORD
;
5086 ot
= dflag
+ OT_WORD
;
5089 val
= insn_get(env
, s
, ot
);
5091 val
= (int8_t)insn_get(env
, s
, OT_BYTE
);
5092 gen_op_movl_T0_im(val
);
5095 case 0x8f: /* pop Ev */
5097 ot
= dflag
? OT_QUAD
: OT_WORD
;
5099 ot
= dflag
+ OT_WORD
;
5101 modrm
= cpu_ldub_code(env
, s
->pc
++);
5102 mod
= (modrm
>> 6) & 3;
5105 /* NOTE: order is important for pop %sp */
5107 rm
= (modrm
& 7) | REX_B(s
);
5108 gen_op_mov_reg_T0(ot
, rm
);
5110 /* NOTE: order is important too for MMU exceptions */
5111 s
->popl_esp_hack
= 1 << ot
;
5112 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 1);
5113 s
->popl_esp_hack
= 0;
5117 case 0xc8: /* enter */
5120 val
= cpu_lduw_code(env
, s
->pc
);
5122 level
= cpu_ldub_code(env
, s
->pc
++);
5123 gen_enter(s
, val
, level
);
5126 case 0xc9: /* leave */
5127 /* XXX: exception not precise (ESP is updated before potential exception) */
5129 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EBP
);
5130 gen_op_mov_reg_T0(OT_QUAD
, R_ESP
);
5131 } else if (s
->ss32
) {
5132 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
5133 gen_op_mov_reg_T0(OT_LONG
, R_ESP
);
5135 gen_op_mov_TN_reg(OT_WORD
, 0, R_EBP
);
5136 gen_op_mov_reg_T0(OT_WORD
, R_ESP
);
5140 ot
= dflag
? OT_QUAD
: OT_WORD
;
5142 ot
= dflag
+ OT_WORD
;
5144 gen_op_mov_reg_T0(ot
, R_EBP
);
5147 case 0x06: /* push es */
5148 case 0x0e: /* push cs */
5149 case 0x16: /* push ss */
5150 case 0x1e: /* push ds */
5153 gen_op_movl_T0_seg(b
>> 3);
5156 case 0x1a0: /* push fs */
5157 case 0x1a8: /* push gs */
5158 gen_op_movl_T0_seg((b
>> 3) & 7);
5161 case 0x07: /* pop es */
5162 case 0x17: /* pop ss */
5163 case 0x1f: /* pop ds */
5168 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5171 /* if reg == SS, inhibit interrupts/trace. */
5172 /* If several instructions disable interrupts, only the
5174 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5175 gen_helper_set_inhibit_irq(cpu_env
);
5179 gen_jmp_im(s
->pc
- s
->cs_base
);
5183 case 0x1a1: /* pop fs */
5184 case 0x1a9: /* pop gs */
5186 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
5189 gen_jmp_im(s
->pc
- s
->cs_base
);
5194 /**************************/
5197 case 0x89: /* mov Gv, Ev */
5201 ot
= dflag
+ OT_WORD
;
5202 modrm
= cpu_ldub_code(env
, s
->pc
++);
5203 reg
= ((modrm
>> 3) & 7) | rex_r
;
5205 /* generate a generic store */
5206 gen_ldst_modrm(env
, s
, modrm
, ot
, reg
, 1);
5209 case 0xc7: /* mov Ev, Iv */
5213 ot
= dflag
+ OT_WORD
;
5214 modrm
= cpu_ldub_code(env
, s
->pc
++);
5215 mod
= (modrm
>> 6) & 3;
5217 s
->rip_offset
= insn_const_size(ot
);
5218 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5220 val
= insn_get(env
, s
, ot
);
5221 gen_op_movl_T0_im(val
);
5223 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5225 gen_op_mov_reg_T0(ot
, (modrm
& 7) | REX_B(s
));
5228 case 0x8b: /* mov Ev, Gv */
5232 ot
= OT_WORD
+ dflag
;
5233 modrm
= cpu_ldub_code(env
, s
->pc
++);
5234 reg
= ((modrm
>> 3) & 7) | rex_r
;
5236 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
5237 gen_op_mov_reg_T0(ot
, reg
);
5239 case 0x8e: /* mov seg, Gv */
5240 modrm
= cpu_ldub_code(env
, s
->pc
++);
5241 reg
= (modrm
>> 3) & 7;
5242 if (reg
>= 6 || reg
== R_CS
)
5244 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5245 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5247 /* if reg == SS, inhibit interrupts/trace */
5248 /* If several instructions disable interrupts, only the
5250 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5251 gen_helper_set_inhibit_irq(cpu_env
);
5255 gen_jmp_im(s
->pc
- s
->cs_base
);
5259 case 0x8c: /* mov Gv, seg */
5260 modrm
= cpu_ldub_code(env
, s
->pc
++);
5261 reg
= (modrm
>> 3) & 7;
5262 mod
= (modrm
>> 6) & 3;
5265 gen_op_movl_T0_seg(reg
);
5267 ot
= OT_WORD
+ dflag
;
5270 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 1);
5273 case 0x1b6: /* movzbS Gv, Eb */
5274 case 0x1b7: /* movzwS Gv, Eb */
5275 case 0x1be: /* movsbS Gv, Eb */
5276 case 0x1bf: /* movswS Gv, Eb */
5279 /* d_ot is the size of destination */
5280 d_ot
= dflag
+ OT_WORD
;
5281 /* ot is the size of source */
5282 ot
= (b
& 1) + OT_BYTE
;
5283 modrm
= cpu_ldub_code(env
, s
->pc
++);
5284 reg
= ((modrm
>> 3) & 7) | rex_r
;
5285 mod
= (modrm
>> 6) & 3;
5286 rm
= (modrm
& 7) | REX_B(s
);
5289 gen_op_mov_TN_reg(ot
, 0, rm
);
5290 switch(ot
| (b
& 8)) {
5292 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
5295 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
5298 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
5302 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
5305 gen_op_mov_reg_T0(d_ot
, reg
);
5307 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5309 gen_op_lds_T0_A0(ot
+ s
->mem_index
);
5311 gen_op_ldu_T0_A0(ot
+ s
->mem_index
);
5313 gen_op_mov_reg_T0(d_ot
, reg
);
5318 case 0x8d: /* lea */
5319 ot
= dflag
+ OT_WORD
;
5320 modrm
= cpu_ldub_code(env
, s
->pc
++);
5321 mod
= (modrm
>> 6) & 3;
5324 reg
= ((modrm
>> 3) & 7) | rex_r
;
5325 /* we must ensure that no segment is added */
5329 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5331 gen_op_mov_reg_A0(ot
- OT_WORD
, reg
);
5334 case 0xa0: /* mov EAX, Ov */
5336 case 0xa2: /* mov Ov, EAX */
5339 target_ulong offset_addr
;
5344 ot
= dflag
+ OT_WORD
;
5345 #ifdef TARGET_X86_64
5346 if (s
->aflag
== 2) {
5347 offset_addr
= cpu_ldq_code(env
, s
->pc
);
5349 gen_op_movq_A0_im(offset_addr
);
5354 offset_addr
= insn_get(env
, s
, OT_LONG
);
5356 offset_addr
= insn_get(env
, s
, OT_WORD
);
5358 gen_op_movl_A0_im(offset_addr
);
5360 gen_add_A0_ds_seg(s
);
5362 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
5363 gen_op_mov_reg_T0(ot
, R_EAX
);
5365 gen_op_mov_TN_reg(ot
, 0, R_EAX
);
5366 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5370 case 0xd7: /* xlat */
5371 #ifdef TARGET_X86_64
5372 if (s
->aflag
== 2) {
5373 gen_op_movq_A0_reg(R_EBX
);
5374 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
5375 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5376 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5380 gen_op_movl_A0_reg(R_EBX
);
5381 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
5382 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5383 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5385 gen_op_andl_A0_ffff();
5387 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
5389 gen_add_A0_ds_seg(s
);
5390 gen_op_ldu_T0_A0(OT_BYTE
+ s
->mem_index
);
5391 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
5393 case 0xb0 ... 0xb7: /* mov R, Ib */
5394 val
= insn_get(env
, s
, OT_BYTE
);
5395 gen_op_movl_T0_im(val
);
5396 gen_op_mov_reg_T0(OT_BYTE
, (b
& 7) | REX_B(s
));
5398 case 0xb8 ... 0xbf: /* mov R, Iv */
5399 #ifdef TARGET_X86_64
5403 tmp
= cpu_ldq_code(env
, s
->pc
);
5405 reg
= (b
& 7) | REX_B(s
);
5406 gen_movtl_T0_im(tmp
);
5407 gen_op_mov_reg_T0(OT_QUAD
, reg
);
5411 ot
= dflag
? OT_LONG
: OT_WORD
;
5412 val
= insn_get(env
, s
, ot
);
5413 reg
= (b
& 7) | REX_B(s
);
5414 gen_op_movl_T0_im(val
);
5415 gen_op_mov_reg_T0(ot
, reg
);
5419 case 0x91 ... 0x97: /* xchg R, EAX */
5421 ot
= dflag
+ OT_WORD
;
5422 reg
= (b
& 7) | REX_B(s
);
5426 case 0x87: /* xchg Ev, Gv */
5430 ot
= dflag
+ OT_WORD
;
5431 modrm
= cpu_ldub_code(env
, s
->pc
++);
5432 reg
= ((modrm
>> 3) & 7) | rex_r
;
5433 mod
= (modrm
>> 6) & 3;
5435 rm
= (modrm
& 7) | REX_B(s
);
5437 gen_op_mov_TN_reg(ot
, 0, reg
);
5438 gen_op_mov_TN_reg(ot
, 1, rm
);
5439 gen_op_mov_reg_T0(ot
, rm
);
5440 gen_op_mov_reg_T1(ot
, reg
);
5442 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5443 gen_op_mov_TN_reg(ot
, 0, reg
);
5444 /* for xchg, lock is implicit */
5445 if (!(prefixes
& PREFIX_LOCK
))
5447 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5448 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5449 if (!(prefixes
& PREFIX_LOCK
))
5450 gen_helper_unlock();
5451 gen_op_mov_reg_T1(ot
, reg
);
5454 case 0xc4: /* les Gv */
5459 case 0xc5: /* lds Gv */
5464 case 0x1b2: /* lss Gv */
5467 case 0x1b4: /* lfs Gv */
5470 case 0x1b5: /* lgs Gv */
5473 ot
= dflag
? OT_LONG
: OT_WORD
;
5474 modrm
= cpu_ldub_code(env
, s
->pc
++);
5475 reg
= ((modrm
>> 3) & 7) | rex_r
;
5476 mod
= (modrm
>> 6) & 3;
5479 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5480 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5481 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
5482 /* load the segment first to handle exceptions properly */
5483 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
5484 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
5485 /* then put the data */
5486 gen_op_mov_reg_T1(ot
, reg
);
5488 gen_jmp_im(s
->pc
- s
->cs_base
);
5493 /************************/
5504 ot
= dflag
+ OT_WORD
;
5506 modrm
= cpu_ldub_code(env
, s
->pc
++);
5507 mod
= (modrm
>> 6) & 3;
5508 op
= (modrm
>> 3) & 7;
5514 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5517 opreg
= (modrm
& 7) | REX_B(s
);
5522 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
5525 shift
= cpu_ldub_code(env
, s
->pc
++);
5527 gen_shifti(s
, op
, ot
, opreg
, shift
);
5542 case 0x1a4: /* shld imm */
5546 case 0x1a5: /* shld cl */
5550 case 0x1ac: /* shrd imm */
5554 case 0x1ad: /* shrd cl */
5558 ot
= dflag
+ OT_WORD
;
5559 modrm
= cpu_ldub_code(env
, s
->pc
++);
5560 mod
= (modrm
>> 6) & 3;
5561 rm
= (modrm
& 7) | REX_B(s
);
5562 reg
= ((modrm
>> 3) & 7) | rex_r
;
5564 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5569 gen_op_mov_TN_reg(ot
, 1, reg
);
5572 val
= cpu_ldub_code(env
, s
->pc
++);
5573 tcg_gen_movi_tl(cpu_T3
, val
);
5575 tcg_gen_mov_tl(cpu_T3
, cpu_regs
[R_ECX
]);
5577 gen_shiftd_rm_T1_T3(s
, ot
, opreg
, op
);
5580 /************************/
5583 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
5584 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
5585 /* XXX: what to do if illegal op ? */
5586 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5589 modrm
= cpu_ldub_code(env
, s
->pc
++);
5590 mod
= (modrm
>> 6) & 3;
5592 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
5595 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
5597 case 0x00 ... 0x07: /* fxxxs */
5598 case 0x10 ... 0x17: /* fixxxl */
5599 case 0x20 ... 0x27: /* fxxxl */
5600 case 0x30 ... 0x37: /* fixxx */
5607 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5608 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5609 gen_helper_flds_FT0(cpu_env
, cpu_tmp2_i32
);
5612 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5613 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5614 gen_helper_fildl_FT0(cpu_env
, cpu_tmp2_i32
);
5617 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5618 (s
->mem_index
>> 2) - 1);
5619 gen_helper_fldl_FT0(cpu_env
, cpu_tmp1_i64
);
5623 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5624 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5625 gen_helper_fildl_FT0(cpu_env
, cpu_tmp2_i32
);
5629 gen_helper_fp_arith_ST0_FT0(op1
);
5631 /* fcomp needs pop */
5632 gen_helper_fpop(cpu_env
);
5636 case 0x08: /* flds */
5637 case 0x0a: /* fsts */
5638 case 0x0b: /* fstps */
5639 case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
5640 case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
5641 case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
5646 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5647 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5648 gen_helper_flds_ST0(cpu_env
, cpu_tmp2_i32
);
5651 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5652 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5653 gen_helper_fildl_ST0(cpu_env
, cpu_tmp2_i32
);
5656 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5657 (s
->mem_index
>> 2) - 1);
5658 gen_helper_fldl_ST0(cpu_env
, cpu_tmp1_i64
);
5662 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5663 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5664 gen_helper_fildl_ST0(cpu_env
, cpu_tmp2_i32
);
5669 /* XXX: the corresponding CPUID bit must be tested ! */
5672 gen_helper_fisttl_ST0(cpu_tmp2_i32
, cpu_env
);
5673 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5674 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5677 gen_helper_fisttll_ST0(cpu_tmp1_i64
, cpu_env
);
5678 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5679 (s
->mem_index
>> 2) - 1);
5683 gen_helper_fistt_ST0(cpu_tmp2_i32
, cpu_env
);
5684 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5685 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5688 gen_helper_fpop(cpu_env
);
5693 gen_helper_fsts_ST0(cpu_tmp2_i32
, cpu_env
);
5694 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5695 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5698 gen_helper_fistl_ST0(cpu_tmp2_i32
, cpu_env
);
5699 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5700 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5703 gen_helper_fstl_ST0(cpu_tmp1_i64
, cpu_env
);
5704 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5705 (s
->mem_index
>> 2) - 1);
5709 gen_helper_fist_ST0(cpu_tmp2_i32
, cpu_env
);
5710 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5711 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5715 gen_helper_fpop(cpu_env
);
5719 case 0x0c: /* fldenv mem */
5720 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5721 gen_op_set_cc_op(s
->cc_op
);
5722 gen_jmp_im(pc_start
- s
->cs_base
);
5723 gen_helper_fldenv(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5725 case 0x0d: /* fldcw mem */
5726 gen_op_ld_T0_A0(OT_WORD
+ s
->mem_index
);
5727 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5728 gen_helper_fldcw(cpu_env
, cpu_tmp2_i32
);
5730 case 0x0e: /* fnstenv mem */
5731 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5732 gen_op_set_cc_op(s
->cc_op
);
5733 gen_jmp_im(pc_start
- s
->cs_base
);
5734 gen_helper_fstenv(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5736 case 0x0f: /* fnstcw mem */
5737 gen_helper_fnstcw(cpu_tmp2_i32
, cpu_env
);
5738 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5739 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5741 case 0x1d: /* fldt mem */
5742 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5743 gen_op_set_cc_op(s
->cc_op
);
5744 gen_jmp_im(pc_start
- s
->cs_base
);
5745 gen_helper_fldt_ST0(cpu_env
, cpu_A0
);
5747 case 0x1f: /* fstpt mem */
5748 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5749 gen_op_set_cc_op(s
->cc_op
);
5750 gen_jmp_im(pc_start
- s
->cs_base
);
5751 gen_helper_fstt_ST0(cpu_env
, cpu_A0
);
5752 gen_helper_fpop(cpu_env
);
5754 case 0x2c: /* frstor mem */
5755 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5756 gen_op_set_cc_op(s
->cc_op
);
5757 gen_jmp_im(pc_start
- s
->cs_base
);
5758 gen_helper_frstor(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5760 case 0x2e: /* fnsave mem */
5761 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5762 gen_op_set_cc_op(s
->cc_op
);
5763 gen_jmp_im(pc_start
- s
->cs_base
);
5764 gen_helper_fsave(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5766 case 0x2f: /* fnstsw mem */
5767 gen_helper_fnstsw(cpu_tmp2_i32
, cpu_env
);
5768 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5769 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5771 case 0x3c: /* fbld */
5772 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5773 gen_op_set_cc_op(s
->cc_op
);
5774 gen_jmp_im(pc_start
- s
->cs_base
);
5775 gen_helper_fbld_ST0(cpu_env
, cpu_A0
);
5777 case 0x3e: /* fbstp */
5778 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5779 gen_op_set_cc_op(s
->cc_op
);
5780 gen_jmp_im(pc_start
- s
->cs_base
);
5781 gen_helper_fbst_ST0(cpu_env
, cpu_A0
);
5782 gen_helper_fpop(cpu_env
);
5784 case 0x3d: /* fildll */
5785 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5786 (s
->mem_index
>> 2) - 1);
5787 gen_helper_fildll_ST0(cpu_env
, cpu_tmp1_i64
);
5789 case 0x3f: /* fistpll */
5790 gen_helper_fistll_ST0(cpu_tmp1_i64
, cpu_env
);
5791 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5792 (s
->mem_index
>> 2) - 1);
5793 gen_helper_fpop(cpu_env
);
5799 /* register float ops */
5803 case 0x08: /* fld sti */
5804 gen_helper_fpush(cpu_env
);
5805 gen_helper_fmov_ST0_STN(cpu_env
,
5806 tcg_const_i32((opreg
+ 1) & 7));
5808 case 0x09: /* fxchg sti */
5809 case 0x29: /* fxchg4 sti, undocumented op */
5810 case 0x39: /* fxchg7 sti, undocumented op */
5811 gen_helper_fxchg_ST0_STN(cpu_env
, tcg_const_i32(opreg
));
5813 case 0x0a: /* grp d9/2 */
5816 /* check exceptions (FreeBSD FPU probe) */
5817 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5818 gen_op_set_cc_op(s
->cc_op
);
5819 gen_jmp_im(pc_start
- s
->cs_base
);
5820 gen_helper_fwait(cpu_env
);
5826 case 0x0c: /* grp d9/4 */
5829 gen_helper_fchs_ST0(cpu_env
);
5832 gen_helper_fabs_ST0(cpu_env
);
5835 gen_helper_fldz_FT0(cpu_env
);
5836 gen_helper_fcom_ST0_FT0(cpu_env
);
5839 gen_helper_fxam_ST0(cpu_env
);
5845 case 0x0d: /* grp d9/5 */
5849 gen_helper_fpush(cpu_env
);
5850 gen_helper_fld1_ST0(cpu_env
);
5853 gen_helper_fpush(cpu_env
);
5854 gen_helper_fldl2t_ST0(cpu_env
);
5857 gen_helper_fpush(cpu_env
);
5858 gen_helper_fldl2e_ST0(cpu_env
);
5861 gen_helper_fpush(cpu_env
);
5862 gen_helper_fldpi_ST0(cpu_env
);
5865 gen_helper_fpush(cpu_env
);
5866 gen_helper_fldlg2_ST0(cpu_env
);
5869 gen_helper_fpush(cpu_env
);
5870 gen_helper_fldln2_ST0(cpu_env
);
5873 gen_helper_fpush(cpu_env
);
5874 gen_helper_fldz_ST0(cpu_env
);
5881 case 0x0e: /* grp d9/6 */
5884 gen_helper_f2xm1(cpu_env
);
5887 gen_helper_fyl2x(cpu_env
);
5890 gen_helper_fptan(cpu_env
);
5892 case 3: /* fpatan */
5893 gen_helper_fpatan(cpu_env
);
5895 case 4: /* fxtract */
5896 gen_helper_fxtract(cpu_env
);
5898 case 5: /* fprem1 */
5899 gen_helper_fprem1(cpu_env
);
5901 case 6: /* fdecstp */
5902 gen_helper_fdecstp(cpu_env
);
5905 case 7: /* fincstp */
5906 gen_helper_fincstp(cpu_env
);
5910 case 0x0f: /* grp d9/7 */
5913 gen_helper_fprem(cpu_env
);
5915 case 1: /* fyl2xp1 */
5916 gen_helper_fyl2xp1(cpu_env
);
5919 gen_helper_fsqrt(cpu_env
);
5921 case 3: /* fsincos */
5922 gen_helper_fsincos(cpu_env
);
5924 case 5: /* fscale */
5925 gen_helper_fscale(cpu_env
);
5927 case 4: /* frndint */
5928 gen_helper_frndint(cpu_env
);
5931 gen_helper_fsin(cpu_env
);
5935 gen_helper_fcos(cpu_env
);
5939 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
5940 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
5941 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
5947 gen_helper_fp_arith_STN_ST0(op1
, opreg
);
5949 gen_helper_fpop(cpu_env
);
5951 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5952 gen_helper_fp_arith_ST0_FT0(op1
);
5956 case 0x02: /* fcom */
5957 case 0x22: /* fcom2, undocumented op */
5958 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5959 gen_helper_fcom_ST0_FT0(cpu_env
);
5961 case 0x03: /* fcomp */
5962 case 0x23: /* fcomp3, undocumented op */
5963 case 0x32: /* fcomp5, undocumented op */
5964 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5965 gen_helper_fcom_ST0_FT0(cpu_env
);
5966 gen_helper_fpop(cpu_env
);
5968 case 0x15: /* da/5 */
5970 case 1: /* fucompp */
5971 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(1));
5972 gen_helper_fucom_ST0_FT0(cpu_env
);
5973 gen_helper_fpop(cpu_env
);
5974 gen_helper_fpop(cpu_env
);
5982 case 0: /* feni (287 only, just do nop here) */
5984 case 1: /* fdisi (287 only, just do nop here) */
5987 gen_helper_fclex(cpu_env
);
5989 case 3: /* fninit */
5990 gen_helper_fninit(cpu_env
);
5992 case 4: /* fsetpm (287 only, just do nop here) */
5998 case 0x1d: /* fucomi */
5999 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6000 gen_op_set_cc_op(s
->cc_op
);
6001 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6002 gen_helper_fucomi_ST0_FT0(cpu_env
);
6003 s
->cc_op
= CC_OP_EFLAGS
;
6005 case 0x1e: /* fcomi */
6006 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6007 gen_op_set_cc_op(s
->cc_op
);
6008 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6009 gen_helper_fcomi_ST0_FT0(cpu_env
);
6010 s
->cc_op
= CC_OP_EFLAGS
;
6012 case 0x28: /* ffree sti */
6013 gen_helper_ffree_STN(cpu_env
, tcg_const_i32(opreg
));
6015 case 0x2a: /* fst sti */
6016 gen_helper_fmov_STN_ST0(cpu_env
, tcg_const_i32(opreg
));
6018 case 0x2b: /* fstp sti */
6019 case 0x0b: /* fstp1 sti, undocumented op */
6020 case 0x3a: /* fstp8 sti, undocumented op */
6021 case 0x3b: /* fstp9 sti, undocumented op */
6022 gen_helper_fmov_STN_ST0(cpu_env
, tcg_const_i32(opreg
));
6023 gen_helper_fpop(cpu_env
);
6025 case 0x2c: /* fucom st(i) */
6026 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6027 gen_helper_fucom_ST0_FT0(cpu_env
);
6029 case 0x2d: /* fucomp st(i) */
6030 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6031 gen_helper_fucom_ST0_FT0(cpu_env
);
6032 gen_helper_fpop(cpu_env
);
6034 case 0x33: /* de/3 */
6036 case 1: /* fcompp */
6037 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(1));
6038 gen_helper_fcom_ST0_FT0(cpu_env
);
6039 gen_helper_fpop(cpu_env
);
6040 gen_helper_fpop(cpu_env
);
6046 case 0x38: /* ffreep sti, undocumented op */
6047 gen_helper_ffree_STN(cpu_env
, tcg_const_i32(opreg
));
6048 gen_helper_fpop(cpu_env
);
6050 case 0x3c: /* df/4 */
6053 gen_helper_fnstsw(cpu_tmp2_i32
, cpu_env
);
6054 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
6055 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
6061 case 0x3d: /* fucomip */
6062 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6063 gen_op_set_cc_op(s
->cc_op
);
6064 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6065 gen_helper_fucomi_ST0_FT0(cpu_env
);
6066 gen_helper_fpop(cpu_env
);
6067 s
->cc_op
= CC_OP_EFLAGS
;
6069 case 0x3e: /* fcomip */
6070 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6071 gen_op_set_cc_op(s
->cc_op
);
6072 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6073 gen_helper_fcomi_ST0_FT0(cpu_env
);
6074 gen_helper_fpop(cpu_env
);
6075 s
->cc_op
= CC_OP_EFLAGS
;
6077 case 0x10 ... 0x13: /* fcmovxx */
6081 static const uint8_t fcmov_cc
[8] = {
6087 op1
= fcmov_cc
[op
& 3] | (((op
>> 3) & 1) ^ 1);
6088 l1
= gen_new_label();
6089 gen_jcc1(s
, s
->cc_op
, op1
, l1
);
6090 gen_helper_fmov_ST0_STN(cpu_env
, tcg_const_i32(opreg
));
6099 /************************/
6102 case 0xa4: /* movsS */
6107 ot
= dflag
+ OT_WORD
;
6109 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6110 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6116 case 0xaa: /* stosS */
6121 ot
= dflag
+ OT_WORD
;
6123 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6124 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6129 case 0xac: /* lodsS */
6134 ot
= dflag
+ OT_WORD
;
6135 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6136 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6141 case 0xae: /* scasS */
6146 ot
= dflag
+ OT_WORD
;
6147 if (prefixes
& PREFIX_REPNZ
) {
6148 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6149 } else if (prefixes
& PREFIX_REPZ
) {
6150 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6153 s
->cc_op
= CC_OP_SUBB
+ ot
;
6157 case 0xa6: /* cmpsS */
6162 ot
= dflag
+ OT_WORD
;
6163 if (prefixes
& PREFIX_REPNZ
) {
6164 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6165 } else if (prefixes
& PREFIX_REPZ
) {
6166 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6169 s
->cc_op
= CC_OP_SUBB
+ ot
;
6172 case 0x6c: /* insS */
6177 ot
= dflag
? OT_LONG
: OT_WORD
;
6178 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6179 gen_op_andl_T0_ffff();
6180 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6181 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
) | 4);
6182 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6183 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6187 gen_jmp(s
, s
->pc
- s
->cs_base
);
6191 case 0x6e: /* outsS */
6196 ot
= dflag
? OT_LONG
: OT_WORD
;
6197 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6198 gen_op_andl_T0_ffff();
6199 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6200 svm_is_rep(prefixes
) | 4);
6201 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6202 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6206 gen_jmp(s
, s
->pc
- s
->cs_base
);
6211 /************************/
6219 ot
= dflag
? OT_LONG
: OT_WORD
;
6220 val
= cpu_ldub_code(env
, s
->pc
++);
6221 gen_op_movl_T0_im(val
);
6222 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6223 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6226 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6227 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6228 gen_op_mov_reg_T1(ot
, R_EAX
);
6231 gen_jmp(s
, s
->pc
- s
->cs_base
);
6239 ot
= dflag
? OT_LONG
: OT_WORD
;
6240 val
= cpu_ldub_code(env
, s
->pc
++);
6241 gen_op_movl_T0_im(val
);
6242 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6243 svm_is_rep(prefixes
));
6244 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6248 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6249 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6250 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6253 gen_jmp(s
, s
->pc
- s
->cs_base
);
6261 ot
= dflag
? OT_LONG
: OT_WORD
;
6262 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6263 gen_op_andl_T0_ffff();
6264 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6265 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6268 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6269 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6270 gen_op_mov_reg_T1(ot
, R_EAX
);
6273 gen_jmp(s
, s
->pc
- s
->cs_base
);
6281 ot
= dflag
? OT_LONG
: OT_WORD
;
6282 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6283 gen_op_andl_T0_ffff();
6284 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6285 svm_is_rep(prefixes
));
6286 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6290 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6291 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6292 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6295 gen_jmp(s
, s
->pc
- s
->cs_base
);
6299 /************************/
6301 case 0xc2: /* ret im */
6302 val
= cpu_ldsw_code(env
, s
->pc
);
6305 if (CODE64(s
) && s
->dflag
)
6307 gen_stack_update(s
, val
+ (2 << s
->dflag
));
6309 gen_op_andl_T0_ffff();
6313 case 0xc3: /* ret */
6317 gen_op_andl_T0_ffff();
6321 case 0xca: /* lret im */
6322 val
= cpu_ldsw_code(env
, s
->pc
);
6325 if (s
->pe
&& !s
->vm86
) {
6326 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6327 gen_op_set_cc_op(s
->cc_op
);
6328 gen_jmp_im(pc_start
- s
->cs_base
);
6329 gen_helper_lret_protected(cpu_env
, tcg_const_i32(s
->dflag
),
6330 tcg_const_i32(val
));
6334 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6336 gen_op_andl_T0_ffff();
6337 /* NOTE: keeping EIP updated is not a problem in case of
6341 gen_op_addl_A0_im(2 << s
->dflag
);
6342 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6343 gen_op_movl_seg_T0_vm(R_CS
);
6344 /* add stack offset */
6345 gen_stack_update(s
, val
+ (4 << s
->dflag
));
6349 case 0xcb: /* lret */
6352 case 0xcf: /* iret */
6353 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IRET
);
6356 gen_helper_iret_real(cpu_env
, tcg_const_i32(s
->dflag
));
6357 s
->cc_op
= CC_OP_EFLAGS
;
6358 } else if (s
->vm86
) {
6360 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6362 gen_helper_iret_real(cpu_env
, tcg_const_i32(s
->dflag
));
6363 s
->cc_op
= CC_OP_EFLAGS
;
6366 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6367 gen_op_set_cc_op(s
->cc_op
);
6368 gen_jmp_im(pc_start
- s
->cs_base
);
6369 gen_helper_iret_protected(cpu_env
, tcg_const_i32(s
->dflag
),
6370 tcg_const_i32(s
->pc
- s
->cs_base
));
6371 s
->cc_op
= CC_OP_EFLAGS
;
6375 case 0xe8: /* call im */
6378 tval
= (int32_t)insn_get(env
, s
, OT_LONG
);
6380 tval
= (int16_t)insn_get(env
, s
, OT_WORD
);
6381 next_eip
= s
->pc
- s
->cs_base
;
6387 gen_movtl_T0_im(next_eip
);
6392 case 0x9a: /* lcall im */
6394 unsigned int selector
, offset
;
6398 ot
= dflag
? OT_LONG
: OT_WORD
;
6399 offset
= insn_get(env
, s
, ot
);
6400 selector
= insn_get(env
, s
, OT_WORD
);
6402 gen_op_movl_T0_im(selector
);
6403 gen_op_movl_T1_imu(offset
);
6406 case 0xe9: /* jmp im */
6408 tval
= (int32_t)insn_get(env
, s
, OT_LONG
);
6410 tval
= (int16_t)insn_get(env
, s
, OT_WORD
);
6411 tval
+= s
->pc
- s
->cs_base
;
6418 case 0xea: /* ljmp im */
6420 unsigned int selector
, offset
;
6424 ot
= dflag
? OT_LONG
: OT_WORD
;
6425 offset
= insn_get(env
, s
, ot
);
6426 selector
= insn_get(env
, s
, OT_WORD
);
6428 gen_op_movl_T0_im(selector
);
6429 gen_op_movl_T1_imu(offset
);
6432 case 0xeb: /* jmp Jb */
6433 tval
= (int8_t)insn_get(env
, s
, OT_BYTE
);
6434 tval
+= s
->pc
- s
->cs_base
;
6439 case 0x70 ... 0x7f: /* jcc Jb */
6440 tval
= (int8_t)insn_get(env
, s
, OT_BYTE
);
6442 case 0x180 ... 0x18f: /* jcc Jv */
6444 tval
= (int32_t)insn_get(env
, s
, OT_LONG
);
6446 tval
= (int16_t)insn_get(env
, s
, OT_WORD
);
6449 next_eip
= s
->pc
- s
->cs_base
;
6453 gen_jcc(s
, b
, tval
, next_eip
);
6456 case 0x190 ... 0x19f: /* setcc Gv */
6457 modrm
= cpu_ldub_code(env
, s
->pc
++);
6459 gen_ldst_modrm(env
, s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
6461 case 0x140 ... 0x14f: /* cmov Gv, Ev */
6466 ot
= dflag
+ OT_WORD
;
6467 modrm
= cpu_ldub_code(env
, s
->pc
++);
6468 reg
= ((modrm
>> 3) & 7) | rex_r
;
6469 mod
= (modrm
>> 6) & 3;
6470 t0
= tcg_temp_local_new();
6472 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
6473 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
6475 rm
= (modrm
& 7) | REX_B(s
);
6476 gen_op_mov_v_reg(ot
, t0
, rm
);
6478 #ifdef TARGET_X86_64
6479 if (ot
== OT_LONG
) {
6480 /* XXX: specific Intel behaviour ? */
6481 l1
= gen_new_label();
6482 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6483 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
6485 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_regs
[reg
]);
6489 l1
= gen_new_label();
6490 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6491 gen_op_mov_reg_v(ot
, reg
, t0
);
6498 /************************/
6500 case 0x9c: /* pushf */
6501 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PUSHF
);
6502 if (s
->vm86
&& s
->iopl
!= 3) {
6503 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6505 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6506 gen_op_set_cc_op(s
->cc_op
);
6507 gen_helper_read_eflags(cpu_T
[0], cpu_env
);
6511 case 0x9d: /* popf */
6512 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_POPF
);
6513 if (s
->vm86
&& s
->iopl
!= 3) {
6514 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6519 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6520 tcg_const_i32((TF_MASK
| AC_MASK
|
6525 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6526 tcg_const_i32((TF_MASK
| AC_MASK
|
6528 IF_MASK
| IOPL_MASK
)
6532 if (s
->cpl
<= s
->iopl
) {
6534 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6535 tcg_const_i32((TF_MASK
|
6541 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6542 tcg_const_i32((TF_MASK
|
6551 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6552 tcg_const_i32((TF_MASK
| AC_MASK
|
6553 ID_MASK
| NT_MASK
)));
6555 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6556 tcg_const_i32((TF_MASK
| AC_MASK
|
6563 s
->cc_op
= CC_OP_EFLAGS
;
6564 /* abort translation because TF/AC flag may change */
6565 gen_jmp_im(s
->pc
- s
->cs_base
);
6569 case 0x9e: /* sahf */
6570 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6572 gen_op_mov_TN_reg(OT_BYTE
, 0, R_AH
);
6573 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6574 gen_op_set_cc_op(s
->cc_op
);
6575 gen_compute_eflags(cpu_cc_src
);
6576 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, CC_O
);
6577 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
6578 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_T
[0]);
6579 s
->cc_op
= CC_OP_EFLAGS
;
6581 case 0x9f: /* lahf */
6582 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6584 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6585 gen_op_set_cc_op(s
->cc_op
);
6586 gen_compute_eflags(cpu_T
[0]);
6587 /* Note: gen_compute_eflags() only gives the condition codes */
6588 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], 0x02);
6589 gen_op_mov_reg_T0(OT_BYTE
, R_AH
);
6591 case 0xf5: /* cmc */
6592 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6593 gen_op_set_cc_op(s
->cc_op
);
6594 gen_compute_eflags(cpu_cc_src
);
6595 tcg_gen_xori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6596 s
->cc_op
= CC_OP_EFLAGS
;
6598 case 0xf8: /* clc */
6599 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6600 gen_op_set_cc_op(s
->cc_op
);
6601 gen_compute_eflags(cpu_cc_src
);
6602 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_C
);
6603 s
->cc_op
= CC_OP_EFLAGS
;
6605 case 0xf9: /* stc */
6606 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6607 gen_op_set_cc_op(s
->cc_op
);
6608 gen_compute_eflags(cpu_cc_src
);
6609 tcg_gen_ori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6610 s
->cc_op
= CC_OP_EFLAGS
;
6612 case 0xfc: /* cld */
6613 tcg_gen_movi_i32(cpu_tmp2_i32
, 1);
6614 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUX86State
, df
));
6616 case 0xfd: /* std */
6617 tcg_gen_movi_i32(cpu_tmp2_i32
, -1);
6618 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUX86State
, df
));
6621 /************************/
6622 /* bit operations */
6623 case 0x1ba: /* bt/bts/btr/btc Gv, im */
6624 ot
= dflag
+ OT_WORD
;
6625 modrm
= cpu_ldub_code(env
, s
->pc
++);
6626 op
= (modrm
>> 3) & 7;
6627 mod
= (modrm
>> 6) & 3;
6628 rm
= (modrm
& 7) | REX_B(s
);
6631 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
6632 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6634 gen_op_mov_TN_reg(ot
, 0, rm
);
6637 val
= cpu_ldub_code(env
, s
->pc
++);
6638 gen_op_movl_T1_im(val
);
6643 case 0x1a3: /* bt Gv, Ev */
6646 case 0x1ab: /* bts */
6649 case 0x1b3: /* btr */
6652 case 0x1bb: /* btc */
6655 ot
= dflag
+ OT_WORD
;
6656 modrm
= cpu_ldub_code(env
, s
->pc
++);
6657 reg
= ((modrm
>> 3) & 7) | rex_r
;
6658 mod
= (modrm
>> 6) & 3;
6659 rm
= (modrm
& 7) | REX_B(s
);
6660 gen_op_mov_TN_reg(OT_LONG
, 1, reg
);
6662 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
6663 /* specific case: we need to add a displacement */
6664 gen_exts(ot
, cpu_T
[1]);
6665 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[1], 3 + ot
);
6666 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, ot
);
6667 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
6668 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6670 gen_op_mov_TN_reg(ot
, 0, rm
);
6673 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], (1 << (3 + ot
)) - 1);
6676 tcg_gen_shr_tl(cpu_cc_src
, cpu_T
[0], cpu_T
[1]);
6677 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6680 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6681 tcg_gen_movi_tl(cpu_tmp0
, 1);
6682 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6683 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6686 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6687 tcg_gen_movi_tl(cpu_tmp0
, 1);
6688 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6689 tcg_gen_not_tl(cpu_tmp0
, cpu_tmp0
);
6690 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6694 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6695 tcg_gen_movi_tl(cpu_tmp0
, 1);
6696 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6697 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6700 s
->cc_op
= CC_OP_SARB
+ ot
;
6703 gen_op_st_T0_A0(ot
+ s
->mem_index
);
6705 gen_op_mov_reg_T0(ot
, rm
);
6706 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
6707 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6710 case 0x1bc: /* bsf */
6711 case 0x1bd: /* bsr */
6716 ot
= dflag
+ OT_WORD
;
6717 modrm
= cpu_ldub_code(env
, s
->pc
++);
6718 reg
= ((modrm
>> 3) & 7) | rex_r
;
6719 gen_ldst_modrm(env
, s
,modrm
, ot
, OR_TMP0
, 0);
6720 gen_extu(ot
, cpu_T
[0]);
6721 t0
= tcg_temp_local_new();
6722 tcg_gen_mov_tl(t0
, cpu_T
[0]);
6723 if ((b
& 1) && (prefixes
& PREFIX_REPZ
) &&
6724 (s
->cpuid_ext3_features
& CPUID_EXT3_ABM
)) {
6726 case OT_WORD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6727 tcg_const_i32(16)); break;
6728 case OT_LONG
: gen_helper_lzcnt(cpu_T
[0], t0
,
6729 tcg_const_i32(32)); break;
6730 case OT_QUAD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6731 tcg_const_i32(64)); break;
6733 gen_op_mov_reg_T0(ot
, reg
);
6735 label1
= gen_new_label();
6736 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6737 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, label1
);
6739 gen_helper_bsr(cpu_T
[0], t0
);
6741 gen_helper_bsf(cpu_T
[0], t0
);
6743 gen_op_mov_reg_T0(ot
, reg
);
6744 tcg_gen_movi_tl(cpu_cc_dst
, 1);
6745 gen_set_label(label1
);
6746 tcg_gen_discard_tl(cpu_cc_src
);
6747 s
->cc_op
= CC_OP_LOGICB
+ ot
;
6752 /************************/
6754 case 0x27: /* daa */
6757 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6758 gen_op_set_cc_op(s
->cc_op
);
6759 gen_helper_daa(cpu_env
);
6760 s
->cc_op
= CC_OP_EFLAGS
;
6762 case 0x2f: /* das */
6765 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6766 gen_op_set_cc_op(s
->cc_op
);
6767 gen_helper_das(cpu_env
);
6768 s
->cc_op
= CC_OP_EFLAGS
;
6770 case 0x37: /* aaa */
6773 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6774 gen_op_set_cc_op(s
->cc_op
);
6775 gen_helper_aaa(cpu_env
);
6776 s
->cc_op
= CC_OP_EFLAGS
;
6778 case 0x3f: /* aas */
6781 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6782 gen_op_set_cc_op(s
->cc_op
);
6783 gen_helper_aas(cpu_env
);
6784 s
->cc_op
= CC_OP_EFLAGS
;
6786 case 0xd4: /* aam */
6789 val
= cpu_ldub_code(env
, s
->pc
++);
6791 gen_exception(s
, EXCP00_DIVZ
, pc_start
- s
->cs_base
);
6793 gen_helper_aam(cpu_env
, tcg_const_i32(val
));
6794 s
->cc_op
= CC_OP_LOGICB
;
6797 case 0xd5: /* aad */
6800 val
= cpu_ldub_code(env
, s
->pc
++);
6801 gen_helper_aad(cpu_env
, tcg_const_i32(val
));
6802 s
->cc_op
= CC_OP_LOGICB
;
6804 /************************/
6806 case 0x90: /* nop */
6807 /* XXX: correct lock test for all insn */
6808 if (prefixes
& PREFIX_LOCK
) {
6811 /* If REX_B is set, then this is xchg eax, r8d, not a nop. */
6813 goto do_xchg_reg_eax
;
6815 if (prefixes
& PREFIX_REPZ
) {
6816 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PAUSE
);
6819 case 0x9b: /* fwait */
6820 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
6821 (HF_MP_MASK
| HF_TS_MASK
)) {
6822 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
6824 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6825 gen_op_set_cc_op(s
->cc_op
);
6826 gen_jmp_im(pc_start
- s
->cs_base
);
6827 gen_helper_fwait(cpu_env
);
6830 case 0xcc: /* int3 */
6831 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6833 case 0xcd: /* int N */
6834 val
= cpu_ldub_code(env
, s
->pc
++);
6835 if (s
->vm86
&& s
->iopl
!= 3) {
6836 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6838 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6841 case 0xce: /* into */
6844 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6845 gen_op_set_cc_op(s
->cc_op
);
6846 gen_jmp_im(pc_start
- s
->cs_base
);
6847 gen_helper_into(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
6850 case 0xf1: /* icebp (undocumented, exits to external debugger) */
6851 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_ICEBP
);
6853 gen_debug(s
, pc_start
- s
->cs_base
);
6857 qemu_set_log(CPU_LOG_INT
| CPU_LOG_TB_IN_ASM
);
6861 case 0xfa: /* cli */
6863 if (s
->cpl
<= s
->iopl
) {
6864 gen_helper_cli(cpu_env
);
6866 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6870 gen_helper_cli(cpu_env
);
6872 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6876 case 0xfb: /* sti */
6878 if (s
->cpl
<= s
->iopl
) {
6880 gen_helper_sti(cpu_env
);
6881 /* interruptions are enabled only the first insn after sti */
6882 /* If several instructions disable interrupts, only the
6884 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
6885 gen_helper_set_inhibit_irq(cpu_env
);
6886 /* give a chance to handle pending irqs */
6887 gen_jmp_im(s
->pc
- s
->cs_base
);
6890 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6896 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6900 case 0x62: /* bound */
6903 ot
= dflag
? OT_LONG
: OT_WORD
;
6904 modrm
= cpu_ldub_code(env
, s
->pc
++);
6905 reg
= (modrm
>> 3) & 7;
6906 mod
= (modrm
>> 6) & 3;
6909 gen_op_mov_TN_reg(ot
, 0, reg
);
6910 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
6911 gen_jmp_im(pc_start
- s
->cs_base
);
6912 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6913 if (ot
== OT_WORD
) {
6914 gen_helper_boundw(cpu_env
, cpu_A0
, cpu_tmp2_i32
);
6916 gen_helper_boundl(cpu_env
, cpu_A0
, cpu_tmp2_i32
);
6919 case 0x1c8 ... 0x1cf: /* bswap reg */
6920 reg
= (b
& 7) | REX_B(s
);
6921 #ifdef TARGET_X86_64
6923 gen_op_mov_TN_reg(OT_QUAD
, 0, reg
);
6924 tcg_gen_bswap64_i64(cpu_T
[0], cpu_T
[0]);
6925 gen_op_mov_reg_T0(OT_QUAD
, reg
);
6929 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
6930 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
6931 tcg_gen_bswap32_tl(cpu_T
[0], cpu_T
[0]);
6932 gen_op_mov_reg_T0(OT_LONG
, reg
);
6935 case 0xd6: /* salc */
6938 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6939 gen_op_set_cc_op(s
->cc_op
);
6940 gen_compute_eflags_c(cpu_T
[0]);
6941 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
6942 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
6944 case 0xe0: /* loopnz */
6945 case 0xe1: /* loopz */
6946 case 0xe2: /* loop */
6947 case 0xe3: /* jecxz */
6951 tval
= (int8_t)insn_get(env
, s
, OT_BYTE
);
6952 next_eip
= s
->pc
- s
->cs_base
;
6957 l1
= gen_new_label();
6958 l2
= gen_new_label();
6959 l3
= gen_new_label();
6962 case 0: /* loopnz */
6964 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6965 gen_op_set_cc_op(s
->cc_op
);
6966 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6967 gen_op_jz_ecx(s
->aflag
, l3
);
6968 gen_compute_eflags(cpu_tmp0
);
6969 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_Z
);
6971 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, l1
);
6973 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, l1
);
6977 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6978 gen_op_jnz_ecx(s
->aflag
, l1
);
6982 gen_op_jz_ecx(s
->aflag
, l1
);
6987 gen_jmp_im(next_eip
);
6996 case 0x130: /* wrmsr */
6997 case 0x132: /* rdmsr */
6999 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7001 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7002 gen_op_set_cc_op(s
->cc_op
);
7003 gen_jmp_im(pc_start
- s
->cs_base
);
7005 gen_helper_rdmsr(cpu_env
);
7007 gen_helper_wrmsr(cpu_env
);
7011 case 0x131: /* rdtsc */
7012 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7013 gen_op_set_cc_op(s
->cc_op
);
7014 gen_jmp_im(pc_start
- s
->cs_base
);
7017 gen_helper_rdtsc(cpu_env
);
7020 gen_jmp(s
, s
->pc
- s
->cs_base
);
7023 case 0x133: /* rdpmc */
7024 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7025 gen_op_set_cc_op(s
->cc_op
);
7026 gen_jmp_im(pc_start
- s
->cs_base
);
7027 gen_helper_rdpmc(cpu_env
);
7029 case 0x134: /* sysenter */
7030 /* For Intel SYSENTER is valid on 64-bit */
7031 if (CODE64(s
) && env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
7034 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7036 gen_update_cc_op(s
);
7037 gen_jmp_im(pc_start
- s
->cs_base
);
7038 gen_helper_sysenter(cpu_env
);
7042 case 0x135: /* sysexit */
7043 /* For Intel SYSEXIT is valid on 64-bit */
7044 if (CODE64(s
) && env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
7047 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7049 gen_update_cc_op(s
);
7050 gen_jmp_im(pc_start
- s
->cs_base
);
7051 gen_helper_sysexit(cpu_env
, tcg_const_i32(dflag
));
7055 #ifdef TARGET_X86_64
7056 case 0x105: /* syscall */
7057 /* XXX: is it usable in real mode ? */
7058 gen_update_cc_op(s
);
7059 gen_jmp_im(pc_start
- s
->cs_base
);
7060 gen_helper_syscall(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7063 case 0x107: /* sysret */
7065 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7067 gen_update_cc_op(s
);
7068 gen_jmp_im(pc_start
- s
->cs_base
);
7069 gen_helper_sysret(cpu_env
, tcg_const_i32(s
->dflag
));
7070 /* condition codes are modified only in long mode */
7072 s
->cc_op
= CC_OP_EFLAGS
;
7077 case 0x1a2: /* cpuid */
7078 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7079 gen_op_set_cc_op(s
->cc_op
);
7080 gen_jmp_im(pc_start
- s
->cs_base
);
7081 gen_helper_cpuid(cpu_env
);
7083 case 0xf4: /* hlt */
7085 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7087 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7088 gen_op_set_cc_op(s
->cc_op
);
7089 gen_jmp_im(pc_start
- s
->cs_base
);
7090 gen_helper_hlt(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7091 s
->is_jmp
= DISAS_TB_JUMP
;
7095 modrm
= cpu_ldub_code(env
, s
->pc
++);
7096 mod
= (modrm
>> 6) & 3;
7097 op
= (modrm
>> 3) & 7;
7100 if (!s
->pe
|| s
->vm86
)
7102 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_READ
);
7103 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,ldt
.selector
));
7107 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 1);
7110 if (!s
->pe
|| s
->vm86
)
7113 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7115 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_WRITE
);
7116 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7117 gen_jmp_im(pc_start
- s
->cs_base
);
7118 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7119 gen_helper_lldt(cpu_env
, cpu_tmp2_i32
);
7123 if (!s
->pe
|| s
->vm86
)
7125 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_READ
);
7126 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,tr
.selector
));
7130 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 1);
7133 if (!s
->pe
|| s
->vm86
)
7136 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7138 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_WRITE
);
7139 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7140 gen_jmp_im(pc_start
- s
->cs_base
);
7141 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7142 gen_helper_ltr(cpu_env
, cpu_tmp2_i32
);
7147 if (!s
->pe
|| s
->vm86
)
7149 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7150 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7151 gen_op_set_cc_op(s
->cc_op
);
7153 gen_helper_verr(cpu_env
, cpu_T
[0]);
7155 gen_helper_verw(cpu_env
, cpu_T
[0]);
7157 s
->cc_op
= CC_OP_EFLAGS
;
7164 modrm
= cpu_ldub_code(env
, s
->pc
++);
7165 mod
= (modrm
>> 6) & 3;
7166 op
= (modrm
>> 3) & 7;
7172 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_GDTR_READ
);
7173 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7174 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.limit
));
7175 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7176 gen_add_A0_im(s
, 2);
7177 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.base
));
7179 gen_op_andl_T0_im(0xffffff);
7180 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7185 case 0: /* monitor */
7186 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7189 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7190 gen_op_set_cc_op(s
->cc_op
);
7191 gen_jmp_im(pc_start
- s
->cs_base
);
7192 #ifdef TARGET_X86_64
7193 if (s
->aflag
== 2) {
7194 gen_op_movq_A0_reg(R_EAX
);
7198 gen_op_movl_A0_reg(R_EAX
);
7200 gen_op_andl_A0_ffff();
7202 gen_add_A0_ds_seg(s
);
7203 gen_helper_monitor(cpu_env
, cpu_A0
);
7206 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7209 gen_update_cc_op(s
);
7210 gen_jmp_im(pc_start
- s
->cs_base
);
7211 gen_helper_mwait(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7215 if (!(s
->cpuid_7_0_ebx_features
& CPUID_7_0_EBX_SMAP
) ||
7219 gen_helper_clac(cpu_env
);
7220 gen_jmp_im(s
->pc
- s
->cs_base
);
7224 if (!(s
->cpuid_7_0_ebx_features
& CPUID_7_0_EBX_SMAP
) ||
7228 gen_helper_stac(cpu_env
);
7229 gen_jmp_im(s
->pc
- s
->cs_base
);
7236 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IDTR_READ
);
7237 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7238 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.limit
));
7239 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7240 gen_add_A0_im(s
, 2);
7241 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.base
));
7243 gen_op_andl_T0_im(0xffffff);
7244 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7250 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7251 gen_op_set_cc_op(s
->cc_op
);
7252 gen_jmp_im(pc_start
- s
->cs_base
);
7255 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7258 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7261 gen_helper_vmrun(cpu_env
, tcg_const_i32(s
->aflag
),
7262 tcg_const_i32(s
->pc
- pc_start
));
7264 s
->is_jmp
= DISAS_TB_JUMP
;
7267 case 1: /* VMMCALL */
7268 if (!(s
->flags
& HF_SVME_MASK
))
7270 gen_helper_vmmcall(cpu_env
);
7272 case 2: /* VMLOAD */
7273 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7276 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7279 gen_helper_vmload(cpu_env
, tcg_const_i32(s
->aflag
));
7282 case 3: /* VMSAVE */
7283 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7286 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7289 gen_helper_vmsave(cpu_env
, tcg_const_i32(s
->aflag
));
7293 if ((!(s
->flags
& HF_SVME_MASK
) &&
7294 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7298 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7301 gen_helper_stgi(cpu_env
);
7305 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7308 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7311 gen_helper_clgi(cpu_env
);
7314 case 6: /* SKINIT */
7315 if ((!(s
->flags
& HF_SVME_MASK
) &&
7316 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7319 gen_helper_skinit(cpu_env
);
7321 case 7: /* INVLPGA */
7322 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7325 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7328 gen_helper_invlpga(cpu_env
, tcg_const_i32(s
->aflag
));
7334 } else if (s
->cpl
!= 0) {
7335 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7337 gen_svm_check_intercept(s
, pc_start
,
7338 op
==2 ? SVM_EXIT_GDTR_WRITE
: SVM_EXIT_IDTR_WRITE
);
7339 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7340 gen_op_ld_T1_A0(OT_WORD
+ s
->mem_index
);
7341 gen_add_A0_im(s
, 2);
7342 gen_op_ld_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7344 gen_op_andl_T0_im(0xffffff);
7346 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,gdt
.base
));
7347 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,gdt
.limit
));
7349 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,idt
.base
));
7350 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,idt
.limit
));
7355 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_CR0
);
7356 #if defined TARGET_X86_64 && defined HOST_WORDS_BIGENDIAN
7357 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]) + 4);
7359 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]));
7361 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 1);
7365 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7367 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7368 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7369 gen_helper_lmsw(cpu_env
, cpu_T
[0]);
7370 gen_jmp_im(s
->pc
- s
->cs_base
);
7375 if (mod
!= 3) { /* invlpg */
7377 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7379 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7380 gen_op_set_cc_op(s
->cc_op
);
7381 gen_jmp_im(pc_start
- s
->cs_base
);
7382 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7383 gen_helper_invlpg(cpu_env
, cpu_A0
);
7384 gen_jmp_im(s
->pc
- s
->cs_base
);
7389 case 0: /* swapgs */
7390 #ifdef TARGET_X86_64
7393 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7395 tcg_gen_ld_tl(cpu_T
[0], cpu_env
,
7396 offsetof(CPUX86State
,segs
[R_GS
].base
));
7397 tcg_gen_ld_tl(cpu_T
[1], cpu_env
,
7398 offsetof(CPUX86State
,kernelgsbase
));
7399 tcg_gen_st_tl(cpu_T
[1], cpu_env
,
7400 offsetof(CPUX86State
,segs
[R_GS
].base
));
7401 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
7402 offsetof(CPUX86State
,kernelgsbase
));
7410 case 1: /* rdtscp */
7411 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_RDTSCP
))
7413 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7414 gen_op_set_cc_op(s
->cc_op
);
7415 gen_jmp_im(pc_start
- s
->cs_base
);
7418 gen_helper_rdtscp(cpu_env
);
7421 gen_jmp(s
, s
->pc
- s
->cs_base
);
7433 case 0x108: /* invd */
7434 case 0x109: /* wbinvd */
7436 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7438 gen_svm_check_intercept(s
, pc_start
, (b
& 2) ? SVM_EXIT_INVD
: SVM_EXIT_WBINVD
);
7442 case 0x63: /* arpl or movslS (x86_64) */
7443 #ifdef TARGET_X86_64
7446 /* d_ot is the size of destination */
7447 d_ot
= dflag
+ OT_WORD
;
7449 modrm
= cpu_ldub_code(env
, s
->pc
++);
7450 reg
= ((modrm
>> 3) & 7) | rex_r
;
7451 mod
= (modrm
>> 6) & 3;
7452 rm
= (modrm
& 7) | REX_B(s
);
7455 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
7457 if (d_ot
== OT_QUAD
)
7458 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
7459 gen_op_mov_reg_T0(d_ot
, reg
);
7461 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7462 if (d_ot
== OT_QUAD
) {
7463 gen_op_lds_T0_A0(OT_LONG
+ s
->mem_index
);
7465 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7467 gen_op_mov_reg_T0(d_ot
, reg
);
7473 TCGv t0
, t1
, t2
, a0
;
7475 if (!s
->pe
|| s
->vm86
)
7477 t0
= tcg_temp_local_new();
7478 t1
= tcg_temp_local_new();
7479 t2
= tcg_temp_local_new();
7481 modrm
= cpu_ldub_code(env
, s
->pc
++);
7482 reg
= (modrm
>> 3) & 7;
7483 mod
= (modrm
>> 6) & 3;
7486 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7487 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7488 a0
= tcg_temp_local_new();
7489 tcg_gen_mov_tl(a0
, cpu_A0
);
7491 gen_op_mov_v_reg(ot
, t0
, rm
);
7494 gen_op_mov_v_reg(ot
, t1
, reg
);
7495 tcg_gen_andi_tl(cpu_tmp0
, t0
, 3);
7496 tcg_gen_andi_tl(t1
, t1
, 3);
7497 tcg_gen_movi_tl(t2
, 0);
7498 label1
= gen_new_label();
7499 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_tmp0
, t1
, label1
);
7500 tcg_gen_andi_tl(t0
, t0
, ~3);
7501 tcg_gen_or_tl(t0
, t0
, t1
);
7502 tcg_gen_movi_tl(t2
, CC_Z
);
7503 gen_set_label(label1
);
7505 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
7508 gen_op_mov_reg_v(ot
, rm
, t0
);
7510 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7511 gen_op_set_cc_op(s
->cc_op
);
7512 gen_compute_eflags(cpu_cc_src
);
7513 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_Z
);
7514 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t2
);
7515 s
->cc_op
= CC_OP_EFLAGS
;
7521 case 0x102: /* lar */
7522 case 0x103: /* lsl */
7526 if (!s
->pe
|| s
->vm86
)
7528 ot
= dflag
? OT_LONG
: OT_WORD
;
7529 modrm
= cpu_ldub_code(env
, s
->pc
++);
7530 reg
= ((modrm
>> 3) & 7) | rex_r
;
7531 gen_ldst_modrm(env
, s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7532 t0
= tcg_temp_local_new();
7533 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7534 gen_op_set_cc_op(s
->cc_op
);
7536 gen_helper_lar(t0
, cpu_env
, cpu_T
[0]);
7538 gen_helper_lsl(t0
, cpu_env
, cpu_T
[0]);
7540 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_src
, CC_Z
);
7541 label1
= gen_new_label();
7542 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
7543 gen_op_mov_reg_v(ot
, reg
, t0
);
7544 gen_set_label(label1
);
7545 s
->cc_op
= CC_OP_EFLAGS
;
7550 modrm
= cpu_ldub_code(env
, s
->pc
++);
7551 mod
= (modrm
>> 6) & 3;
7552 op
= (modrm
>> 3) & 7;
7554 case 0: /* prefetchnta */
7555 case 1: /* prefetchnt0 */
7556 case 2: /* prefetchnt0 */
7557 case 3: /* prefetchnt0 */
7560 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7561 /* nothing more to do */
7563 default: /* nop (multi byte) */
7564 gen_nop_modrm(env
, s
, modrm
);
7568 case 0x119 ... 0x11f: /* nop (multi byte) */
7569 modrm
= cpu_ldub_code(env
, s
->pc
++);
7570 gen_nop_modrm(env
, s
, modrm
);
7572 case 0x120: /* mov reg, crN */
7573 case 0x122: /* mov crN, reg */
7575 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7577 modrm
= cpu_ldub_code(env
, s
->pc
++);
7578 /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
7579 * AMD documentation (24594.pdf) and testing of
7580 * intel 386 and 486 processors all show that the mod bits
7581 * are assumed to be 1's, regardless of actual values.
7583 rm
= (modrm
& 7) | REX_B(s
);
7584 reg
= ((modrm
>> 3) & 7) | rex_r
;
7589 if ((prefixes
& PREFIX_LOCK
) && (reg
== 0) &&
7590 (s
->cpuid_ext3_features
& CPUID_EXT3_CR8LEG
)) {
7599 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7600 gen_op_set_cc_op(s
->cc_op
);
7601 gen_jmp_im(pc_start
- s
->cs_base
);
7603 gen_op_mov_TN_reg(ot
, 0, rm
);
7604 gen_helper_write_crN(cpu_env
, tcg_const_i32(reg
),
7606 gen_jmp_im(s
->pc
- s
->cs_base
);
7609 gen_helper_read_crN(cpu_T
[0], cpu_env
, tcg_const_i32(reg
));
7610 gen_op_mov_reg_T0(ot
, rm
);
7618 case 0x121: /* mov reg, drN */
7619 case 0x123: /* mov drN, reg */
7621 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7623 modrm
= cpu_ldub_code(env
, s
->pc
++);
7624 /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
7625 * AMD documentation (24594.pdf) and testing of
7626 * intel 386 and 486 processors all show that the mod bits
7627 * are assumed to be 1's, regardless of actual values.
7629 rm
= (modrm
& 7) | REX_B(s
);
7630 reg
= ((modrm
>> 3) & 7) | rex_r
;
7635 /* XXX: do it dynamically with CR4.DE bit */
7636 if (reg
== 4 || reg
== 5 || reg
>= 8)
7639 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_DR0
+ reg
);
7640 gen_op_mov_TN_reg(ot
, 0, rm
);
7641 gen_helper_movl_drN_T0(cpu_env
, tcg_const_i32(reg
), cpu_T
[0]);
7642 gen_jmp_im(s
->pc
- s
->cs_base
);
7645 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_DR0
+ reg
);
7646 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,dr
[reg
]));
7647 gen_op_mov_reg_T0(ot
, rm
);
7651 case 0x106: /* clts */
7653 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7655 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7656 gen_helper_clts(cpu_env
);
7657 /* abort block because static cpu state changed */
7658 gen_jmp_im(s
->pc
- s
->cs_base
);
7662 /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
7663 case 0x1c3: /* MOVNTI reg, mem */
7664 if (!(s
->cpuid_features
& CPUID_SSE2
))
7666 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
7667 modrm
= cpu_ldub_code(env
, s
->pc
++);
7668 mod
= (modrm
>> 6) & 3;
7671 reg
= ((modrm
>> 3) & 7) | rex_r
;
7672 /* generate a generic store */
7673 gen_ldst_modrm(env
, s
, modrm
, ot
, reg
, 1);
7676 modrm
= cpu_ldub_code(env
, s
->pc
++);
7677 mod
= (modrm
>> 6) & 3;
7678 op
= (modrm
>> 3) & 7;
7680 case 0: /* fxsave */
7681 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7682 (s
->prefix
& PREFIX_LOCK
))
7684 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7685 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7688 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7689 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7690 gen_op_set_cc_op(s
->cc_op
);
7691 gen_jmp_im(pc_start
- s
->cs_base
);
7692 gen_helper_fxsave(cpu_env
, cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7694 case 1: /* fxrstor */
7695 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7696 (s
->prefix
& PREFIX_LOCK
))
7698 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7699 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7702 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7703 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7704 gen_op_set_cc_op(s
->cc_op
);
7705 gen_jmp_im(pc_start
- s
->cs_base
);
7706 gen_helper_fxrstor(cpu_env
, cpu_A0
,
7707 tcg_const_i32((s
->dflag
== 2)));
7709 case 2: /* ldmxcsr */
7710 case 3: /* stmxcsr */
7711 if (s
->flags
& HF_TS_MASK
) {
7712 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7715 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
7718 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7720 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7721 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7722 gen_helper_ldmxcsr(cpu_env
, cpu_tmp2_i32
);
7724 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7725 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
7728 case 5: /* lfence */
7729 case 6: /* mfence */
7730 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE2
))
7733 case 7: /* sfence / clflush */
7734 if ((modrm
& 0xc7) == 0xc0) {
7736 /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
7737 if (!(s
->cpuid_features
& CPUID_SSE
))
7741 if (!(s
->cpuid_features
& CPUID_CLFLUSH
))
7743 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7750 case 0x10d: /* 3DNow! prefetch(w) */
7751 modrm
= cpu_ldub_code(env
, s
->pc
++);
7752 mod
= (modrm
>> 6) & 3;
7755 gen_lea_modrm(env
, s
, modrm
, ®_addr
, &offset_addr
);
7756 /* ignore for now */
7758 case 0x1aa: /* rsm */
7759 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_RSM
);
7760 if (!(s
->flags
& HF_SMM_MASK
))
7762 gen_update_cc_op(s
);
7763 gen_jmp_im(s
->pc
- s
->cs_base
);
7764 gen_helper_rsm(cpu_env
);
7767 case 0x1b8: /* SSE4.2 popcnt */
7768 if ((prefixes
& (PREFIX_REPZ
| PREFIX_LOCK
| PREFIX_REPNZ
)) !=
7771 if (!(s
->cpuid_ext_features
& CPUID_EXT_POPCNT
))
7774 modrm
= cpu_ldub_code(env
, s
->pc
++);
7775 reg
= ((modrm
>> 3) & 7) | rex_r
;
7777 if (s
->prefix
& PREFIX_DATA
)
7779 else if (s
->dflag
!= 2)
7784 gen_ldst_modrm(env
, s
, modrm
, ot
, OR_TMP0
, 0);
7785 gen_helper_popcnt(cpu_T
[0], cpu_env
, cpu_T
[0], tcg_const_i32(ot
));
7786 gen_op_mov_reg_T0(ot
, reg
);
7788 s
->cc_op
= CC_OP_EFLAGS
;
7790 case 0x10e ... 0x10f:
7791 /* 3DNow! instructions, ignore prefixes */
7792 s
->prefix
&= ~(PREFIX_REPZ
| PREFIX_REPNZ
| PREFIX_DATA
);
7793 case 0x110 ... 0x117:
7794 case 0x128 ... 0x12f:
7795 case 0x138 ... 0x13a:
7796 case 0x150 ... 0x179:
7797 case 0x17c ... 0x17f:
7799 case 0x1c4 ... 0x1c6:
7800 case 0x1d0 ... 0x1fe:
7801 gen_sse(env
, s
, b
, pc_start
, rex_r
);
7806 /* lock generation */
7807 if (s
->prefix
& PREFIX_LOCK
)
7808 gen_helper_unlock();
7811 if (s
->prefix
& PREFIX_LOCK
)
7812 gen_helper_unlock();
7813 /* XXX: ensure that no lock was generated */
7814 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
7818 void optimize_flags_init(void)
7820 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
7821 cpu_cc_op
= tcg_global_mem_new_i32(TCG_AREG0
,
7822 offsetof(CPUX86State
, cc_op
), "cc_op");
7823 cpu_cc_src
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_src
),
7825 cpu_cc_dst
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_dst
),
7827 cpu_cc_tmp
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_tmp
),
7830 #ifdef TARGET_X86_64
7831 cpu_regs
[R_EAX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7832 offsetof(CPUX86State
, regs
[R_EAX
]), "rax");
7833 cpu_regs
[R_ECX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7834 offsetof(CPUX86State
, regs
[R_ECX
]), "rcx");
7835 cpu_regs
[R_EDX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7836 offsetof(CPUX86State
, regs
[R_EDX
]), "rdx");
7837 cpu_regs
[R_EBX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7838 offsetof(CPUX86State
, regs
[R_EBX
]), "rbx");
7839 cpu_regs
[R_ESP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7840 offsetof(CPUX86State
, regs
[R_ESP
]), "rsp");
7841 cpu_regs
[R_EBP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7842 offsetof(CPUX86State
, regs
[R_EBP
]), "rbp");
7843 cpu_regs
[R_ESI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7844 offsetof(CPUX86State
, regs
[R_ESI
]), "rsi");
7845 cpu_regs
[R_EDI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7846 offsetof(CPUX86State
, regs
[R_EDI
]), "rdi");
7847 cpu_regs
[8] = tcg_global_mem_new_i64(TCG_AREG0
,
7848 offsetof(CPUX86State
, regs
[8]), "r8");
7849 cpu_regs
[9] = tcg_global_mem_new_i64(TCG_AREG0
,
7850 offsetof(CPUX86State
, regs
[9]), "r9");
7851 cpu_regs
[10] = tcg_global_mem_new_i64(TCG_AREG0
,
7852 offsetof(CPUX86State
, regs
[10]), "r10");
7853 cpu_regs
[11] = tcg_global_mem_new_i64(TCG_AREG0
,
7854 offsetof(CPUX86State
, regs
[11]), "r11");
7855 cpu_regs
[12] = tcg_global_mem_new_i64(TCG_AREG0
,
7856 offsetof(CPUX86State
, regs
[12]), "r12");
7857 cpu_regs
[13] = tcg_global_mem_new_i64(TCG_AREG0
,
7858 offsetof(CPUX86State
, regs
[13]), "r13");
7859 cpu_regs
[14] = tcg_global_mem_new_i64(TCG_AREG0
,
7860 offsetof(CPUX86State
, regs
[14]), "r14");
7861 cpu_regs
[15] = tcg_global_mem_new_i64(TCG_AREG0
,
7862 offsetof(CPUX86State
, regs
[15]), "r15");
7864 cpu_regs
[R_EAX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7865 offsetof(CPUX86State
, regs
[R_EAX
]), "eax");
7866 cpu_regs
[R_ECX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7867 offsetof(CPUX86State
, regs
[R_ECX
]), "ecx");
7868 cpu_regs
[R_EDX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7869 offsetof(CPUX86State
, regs
[R_EDX
]), "edx");
7870 cpu_regs
[R_EBX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7871 offsetof(CPUX86State
, regs
[R_EBX
]), "ebx");
7872 cpu_regs
[R_ESP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7873 offsetof(CPUX86State
, regs
[R_ESP
]), "esp");
7874 cpu_regs
[R_EBP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7875 offsetof(CPUX86State
, regs
[R_EBP
]), "ebp");
7876 cpu_regs
[R_ESI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7877 offsetof(CPUX86State
, regs
[R_ESI
]), "esi");
7878 cpu_regs
[R_EDI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7879 offsetof(CPUX86State
, regs
[R_EDI
]), "edi");
7882 /* register helpers */
7883 #define GEN_HELPER 2
7887 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
7888 basic block 'tb'. If search_pc is TRUE, also generate PC
7889 information for each intermediate instruction. */
7890 static inline void gen_intermediate_code_internal(CPUX86State
*env
,
7891 TranslationBlock
*tb
,
7894 DisasContext dc1
, *dc
= &dc1
;
7895 target_ulong pc_ptr
;
7896 uint16_t *gen_opc_end
;
7900 target_ulong pc_start
;
7901 target_ulong cs_base
;
7905 /* generate intermediate code */
7907 cs_base
= tb
->cs_base
;
7910 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
7911 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
7912 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
7913 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
7915 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
7916 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
7917 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
7918 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
7919 dc
->singlestep_enabled
= env
->singlestep_enabled
;
7920 dc
->cc_op
= CC_OP_DYNAMIC
;
7921 dc
->cs_base
= cs_base
;
7923 dc
->popl_esp_hack
= 0;
7924 /* select memory access functions */
7926 if (flags
& HF_SOFTMMU_MASK
) {
7927 dc
->mem_index
= (cpu_mmu_index(env
) + 1) << 2;
7929 dc
->cpuid_features
= env
->cpuid_features
;
7930 dc
->cpuid_ext_features
= env
->cpuid_ext_features
;
7931 dc
->cpuid_ext2_features
= env
->cpuid_ext2_features
;
7932 dc
->cpuid_ext3_features
= env
->cpuid_ext3_features
;
7933 dc
->cpuid_7_0_ebx_features
= env
->cpuid_7_0_ebx_features
;
7934 #ifdef TARGET_X86_64
7935 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
7936 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
7939 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
7940 (flags
& HF_INHIBIT_IRQ_MASK
)
7941 #ifndef CONFIG_SOFTMMU
7942 || (flags
& HF_SOFTMMU_MASK
)
7946 /* check addseg logic */
7947 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
7948 printf("ERROR addseg\n");
7951 cpu_T
[0] = tcg_temp_new();
7952 cpu_T
[1] = tcg_temp_new();
7953 cpu_A0
= tcg_temp_new();
7954 cpu_T3
= tcg_temp_new();
7956 cpu_tmp0
= tcg_temp_new();
7957 cpu_tmp1_i64
= tcg_temp_new_i64();
7958 cpu_tmp2_i32
= tcg_temp_new_i32();
7959 cpu_tmp3_i32
= tcg_temp_new_i32();
7960 cpu_tmp4
= tcg_temp_new();
7961 cpu_tmp5
= tcg_temp_new();
7962 cpu_ptr0
= tcg_temp_new_ptr();
7963 cpu_ptr1
= tcg_temp_new_ptr();
7965 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
7967 dc
->is_jmp
= DISAS_NEXT
;
7971 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7973 max_insns
= CF_COUNT_MASK
;
7977 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
7978 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7979 if (bp
->pc
== pc_ptr
&&
7980 !((bp
->flags
& BP_CPU
) && (tb
->flags
& HF_RF_MASK
))) {
7981 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
7987 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
7991 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
7993 tcg_ctx
.gen_opc_pc
[lj
] = pc_ptr
;
7994 gen_opc_cc_op
[lj
] = dc
->cc_op
;
7995 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
7996 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
7998 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8001 pc_ptr
= disas_insn(env
, dc
, pc_ptr
);
8003 /* stop translation if indicated */
8006 /* if single step mode, we generate only one instruction and
8007 generate an exception */
8008 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
8009 the flag and abort the translation to give the irqs a
8010 change to be happen */
8011 if (dc
->tf
|| dc
->singlestep_enabled
||
8012 (flags
& HF_INHIBIT_IRQ_MASK
)) {
8013 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8017 /* if too long translation, stop generation too */
8018 if (tcg_ctx
.gen_opc_ptr
>= gen_opc_end
||
8019 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32) ||
8020 num_insns
>= max_insns
) {
8021 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8026 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8031 if (tb
->cflags
& CF_LAST_IO
)
8033 gen_icount_end(tb
, num_insns
);
8034 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
8035 /* we don't forget to fill the last values */
8037 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
8040 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
8044 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8046 qemu_log("----------------\n");
8047 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8048 #ifdef TARGET_X86_64
8053 disas_flags
= !dc
->code32
;
8054 log_target_disas(env
, pc_start
, pc_ptr
- pc_start
, disas_flags
);
8060 tb
->size
= pc_ptr
- pc_start
;
8061 tb
->icount
= num_insns
;
8065 void gen_intermediate_code(CPUX86State
*env
, TranslationBlock
*tb
)
8067 gen_intermediate_code_internal(env
, tb
, 0);
8070 void gen_intermediate_code_pc(CPUX86State
*env
, TranslationBlock
*tb
)
8072 gen_intermediate_code_internal(env
, tb
, 1);
8075 void restore_state_to_opc(CPUX86State
*env
, TranslationBlock
*tb
, int pc_pos
)
8079 if (qemu_loglevel_mask(CPU_LOG_TB_OP
)) {
8081 qemu_log("RESTORE:\n");
8082 for(i
= 0;i
<= pc_pos
; i
++) {
8083 if (tcg_ctx
.gen_opc_instr_start
[i
]) {
8084 qemu_log("0x%04x: " TARGET_FMT_lx
"\n", i
,
8085 tcg_ctx
.gen_opc_pc
[i
]);
8088 qemu_log("pc_pos=0x%x eip=" TARGET_FMT_lx
" cs_base=%x\n",
8089 pc_pos
, tcg_ctx
.gen_opc_pc
[pc_pos
] - tb
->cs_base
,
8090 (uint32_t)tb
->cs_base
);
8093 env
->eip
= tcg_ctx
.gen_opc_pc
[pc_pos
] - tb
->cs_base
;
8094 cc_op
= gen_opc_cc_op
[pc_pos
];
8095 if (cc_op
!= CC_OP_DYNAMIC
)