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/>.
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 "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(DisasContext
*s
, int modrm
, int *reg_ptr
, int *offset_ptr
)
2029 int mod
, rm
, code
, override
, must_add_seg
;
2031 override
= s
->override
;
2032 must_add_seg
= s
->addseg
;
2035 mod
= (modrm
>> 6) & 3;
2047 code
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
2048 scale
= (code
>> 6) & 3;
2049 index
= ((code
>> 3) & 7) | REX_X(s
);
2056 if ((base
& 7) == 5) {
2058 disp
= (int32_t)cpu_ldl_code(cpu_single_env
, s
->pc
);
2060 if (CODE64(s
) && !havesib
) {
2061 disp
+= s
->pc
+ s
->rip_offset
;
2068 disp
= (int8_t)cpu_ldub_code(cpu_single_env
, s
->pc
++);
2072 disp
= (int32_t)cpu_ldl_code(cpu_single_env
, s
->pc
);
2078 /* for correct popl handling with esp */
2079 if (base
== 4 && s
->popl_esp_hack
)
2080 disp
+= s
->popl_esp_hack
;
2081 #ifdef TARGET_X86_64
2082 if (s
->aflag
== 2) {
2083 gen_op_movq_A0_reg(base
);
2085 gen_op_addq_A0_im(disp
);
2090 gen_op_movl_A0_reg(base
);
2092 gen_op_addl_A0_im(disp
);
2095 #ifdef TARGET_X86_64
2096 if (s
->aflag
== 2) {
2097 gen_op_movq_A0_im(disp
);
2101 gen_op_movl_A0_im(disp
);
2104 /* index == 4 means no index */
2105 if (havesib
&& (index
!= 4)) {
2106 #ifdef TARGET_X86_64
2107 if (s
->aflag
== 2) {
2108 gen_op_addq_A0_reg_sN(scale
, index
);
2112 gen_op_addl_A0_reg_sN(scale
, index
);
2117 if (base
== R_EBP
|| base
== R_ESP
)
2122 #ifdef TARGET_X86_64
2123 if (s
->aflag
== 2) {
2124 gen_op_addq_A0_seg(override
);
2128 gen_op_addl_A0_seg(s
, override
);
2135 disp
= cpu_lduw_code(cpu_single_env
, s
->pc
);
2137 gen_op_movl_A0_im(disp
);
2138 rm
= 0; /* avoid SS override */
2145 disp
= (int8_t)cpu_ldub_code(cpu_single_env
, s
->pc
++);
2149 disp
= cpu_lduw_code(cpu_single_env
, s
->pc
);
2155 gen_op_movl_A0_reg(R_EBX
);
2156 gen_op_addl_A0_reg_sN(0, R_ESI
);
2159 gen_op_movl_A0_reg(R_EBX
);
2160 gen_op_addl_A0_reg_sN(0, R_EDI
);
2163 gen_op_movl_A0_reg(R_EBP
);
2164 gen_op_addl_A0_reg_sN(0, R_ESI
);
2167 gen_op_movl_A0_reg(R_EBP
);
2168 gen_op_addl_A0_reg_sN(0, R_EDI
);
2171 gen_op_movl_A0_reg(R_ESI
);
2174 gen_op_movl_A0_reg(R_EDI
);
2177 gen_op_movl_A0_reg(R_EBP
);
2181 gen_op_movl_A0_reg(R_EBX
);
2185 gen_op_addl_A0_im(disp
);
2186 gen_op_andl_A0_ffff();
2190 if (rm
== 2 || rm
== 3 || rm
== 6)
2195 gen_op_addl_A0_seg(s
, override
);
2205 static void gen_nop_modrm(DisasContext
*s
, int modrm
)
2207 int mod
, rm
, base
, code
;
2209 mod
= (modrm
>> 6) & 3;
2219 code
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
2255 /* used for LEA and MOV AX, mem */
2256 static void gen_add_A0_ds_seg(DisasContext
*s
)
2258 int override
, must_add_seg
;
2259 must_add_seg
= s
->addseg
;
2261 if (s
->override
>= 0) {
2262 override
= s
->override
;
2266 #ifdef TARGET_X86_64
2268 gen_op_addq_A0_seg(override
);
2272 gen_op_addl_A0_seg(s
, override
);
2277 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
2279 static void gen_ldst_modrm(DisasContext
*s
, int modrm
, int ot
, int reg
, int is_store
)
2281 int mod
, rm
, opreg
, disp
;
2283 mod
= (modrm
>> 6) & 3;
2284 rm
= (modrm
& 7) | REX_B(s
);
2288 gen_op_mov_TN_reg(ot
, 0, reg
);
2289 gen_op_mov_reg_T0(ot
, rm
);
2291 gen_op_mov_TN_reg(ot
, 0, rm
);
2293 gen_op_mov_reg_T0(ot
, reg
);
2296 gen_lea_modrm(s
, modrm
, &opreg
, &disp
);
2299 gen_op_mov_TN_reg(ot
, 0, reg
);
2300 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2302 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
2304 gen_op_mov_reg_T0(ot
, reg
);
2309 static inline uint32_t insn_get(DisasContext
*s
, int ot
)
2315 ret
= cpu_ldub_code(cpu_single_env
, s
->pc
);
2319 ret
= cpu_lduw_code(cpu_single_env
, s
->pc
);
2324 ret
= cpu_ldl_code(cpu_single_env
, s
->pc
);
2331 static inline int insn_const_size(unsigned int ot
)
2339 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong eip
)
2341 TranslationBlock
*tb
;
2344 pc
= s
->cs_base
+ eip
;
2346 /* NOTE: we handle the case where the TB spans two pages here */
2347 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) ||
2348 (pc
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
)) {
2349 /* jump to same page: we can use a direct jump */
2350 tcg_gen_goto_tb(tb_num
);
2352 tcg_gen_exit_tb((tcg_target_long
)tb
+ tb_num
);
2354 /* jump to another page: currently not optimized */
2360 static inline void gen_jcc(DisasContext
*s
, int b
,
2361 target_ulong val
, target_ulong next_eip
)
2366 gen_update_cc_op(s
);
2368 l1
= gen_new_label();
2369 gen_jcc1(s
, cc_op
, b
, l1
);
2371 gen_goto_tb(s
, 0, next_eip
);
2374 gen_goto_tb(s
, 1, val
);
2375 s
->is_jmp
= DISAS_TB_JUMP
;
2378 l1
= gen_new_label();
2379 l2
= gen_new_label();
2380 gen_jcc1(s
, cc_op
, b
, l1
);
2382 gen_jmp_im(next_eip
);
2392 static void gen_setcc(DisasContext
*s
, int b
)
2394 int inv
, jcc_op
, l1
;
2397 if (is_fast_jcc_case(s
, b
)) {
2398 /* nominal case: we use a jump */
2399 /* XXX: make it faster by adding new instructions in TCG */
2400 t0
= tcg_temp_local_new();
2401 tcg_gen_movi_tl(t0
, 0);
2402 l1
= gen_new_label();
2403 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
2404 tcg_gen_movi_tl(t0
, 1);
2406 tcg_gen_mov_tl(cpu_T
[0], t0
);
2409 /* slow case: it is more efficient not to generate a jump,
2410 although it is questionnable whether this optimization is
2413 jcc_op
= (b
>> 1) & 7;
2414 gen_setcc_slow_T0(s
, jcc_op
);
2416 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
2421 static inline void gen_op_movl_T0_seg(int seg_reg
)
2423 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
2424 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2427 static inline void gen_op_movl_seg_T0_vm(int seg_reg
)
2429 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
2430 tcg_gen_st32_tl(cpu_T
[0], cpu_env
,
2431 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2432 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], 4);
2433 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
2434 offsetof(CPUX86State
,segs
[seg_reg
].base
));
2437 /* move T0 to seg_reg and compute if the CPU state may change. Never
2438 call this function with seg_reg == R_CS */
2439 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
2441 if (s
->pe
&& !s
->vm86
) {
2442 /* XXX: optimize by finding processor state dynamically */
2443 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2444 gen_op_set_cc_op(s
->cc_op
);
2445 gen_jmp_im(cur_eip
);
2446 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
2447 gen_helper_load_seg(cpu_env
, tcg_const_i32(seg_reg
), cpu_tmp2_i32
);
2448 /* abort translation because the addseg value may change or
2449 because ss32 may change. For R_SS, translation must always
2450 stop as a special handling must be done to disable hardware
2451 interrupts for the next instruction */
2452 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
2453 s
->is_jmp
= DISAS_TB_JUMP
;
2455 gen_op_movl_seg_T0_vm(seg_reg
);
2456 if (seg_reg
== R_SS
)
2457 s
->is_jmp
= DISAS_TB_JUMP
;
2461 static inline int svm_is_rep(int prefixes
)
2463 return ((prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) ? 8 : 0);
2467 gen_svm_check_intercept_param(DisasContext
*s
, target_ulong pc_start
,
2468 uint32_t type
, uint64_t param
)
2470 /* no SVM activated; fast case */
2471 if (likely(!(s
->flags
& HF_SVMI_MASK
)))
2473 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2474 gen_op_set_cc_op(s
->cc_op
);
2475 gen_jmp_im(pc_start
- s
->cs_base
);
2476 gen_helper_svm_check_intercept_param(cpu_env
, tcg_const_i32(type
),
2477 tcg_const_i64(param
));
2481 gen_svm_check_intercept(DisasContext
*s
, target_ulong pc_start
, uint64_t type
)
2483 gen_svm_check_intercept_param(s
, pc_start
, type
, 0);
2486 static inline void gen_stack_update(DisasContext
*s
, int addend
)
2488 #ifdef TARGET_X86_64
2490 gen_op_add_reg_im(2, R_ESP
, addend
);
2494 gen_op_add_reg_im(1, R_ESP
, addend
);
2496 gen_op_add_reg_im(0, R_ESP
, addend
);
2500 /* generate a push. It depends on ss32, addseg and dflag */
2501 static void gen_push_T0(DisasContext
*s
)
2503 #ifdef TARGET_X86_64
2505 gen_op_movq_A0_reg(R_ESP
);
2507 gen_op_addq_A0_im(-8);
2508 gen_op_st_T0_A0(OT_QUAD
+ s
->mem_index
);
2510 gen_op_addq_A0_im(-2);
2511 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2513 gen_op_mov_reg_A0(2, R_ESP
);
2517 gen_op_movl_A0_reg(R_ESP
);
2519 gen_op_addl_A0_im(-2);
2521 gen_op_addl_A0_im(-4);
2524 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2525 gen_op_addl_A0_seg(s
, R_SS
);
2528 gen_op_andl_A0_ffff();
2529 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2530 gen_op_addl_A0_seg(s
, R_SS
);
2532 gen_op_st_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2533 if (s
->ss32
&& !s
->addseg
)
2534 gen_op_mov_reg_A0(1, R_ESP
);
2536 gen_op_mov_reg_T1(s
->ss32
+ 1, R_ESP
);
2540 /* generate a push. It depends on ss32, addseg and dflag */
2541 /* slower version for T1, only used for call Ev */
2542 static void gen_push_T1(DisasContext
*s
)
2544 #ifdef TARGET_X86_64
2546 gen_op_movq_A0_reg(R_ESP
);
2548 gen_op_addq_A0_im(-8);
2549 gen_op_st_T1_A0(OT_QUAD
+ s
->mem_index
);
2551 gen_op_addq_A0_im(-2);
2552 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2554 gen_op_mov_reg_A0(2, R_ESP
);
2558 gen_op_movl_A0_reg(R_ESP
);
2560 gen_op_addl_A0_im(-2);
2562 gen_op_addl_A0_im(-4);
2565 gen_op_addl_A0_seg(s
, R_SS
);
2568 gen_op_andl_A0_ffff();
2569 gen_op_addl_A0_seg(s
, R_SS
);
2571 gen_op_st_T1_A0(s
->dflag
+ 1 + s
->mem_index
);
2573 if (s
->ss32
&& !s
->addseg
)
2574 gen_op_mov_reg_A0(1, R_ESP
);
2576 gen_stack_update(s
, (-2) << s
->dflag
);
2580 /* two step pop is necessary for precise exceptions */
2581 static void gen_pop_T0(DisasContext
*s
)
2583 #ifdef TARGET_X86_64
2585 gen_op_movq_A0_reg(R_ESP
);
2586 gen_op_ld_T0_A0((s
->dflag
? OT_QUAD
: OT_WORD
) + s
->mem_index
);
2590 gen_op_movl_A0_reg(R_ESP
);
2593 gen_op_addl_A0_seg(s
, R_SS
);
2595 gen_op_andl_A0_ffff();
2596 gen_op_addl_A0_seg(s
, R_SS
);
2598 gen_op_ld_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2602 static void gen_pop_update(DisasContext
*s
)
2604 #ifdef TARGET_X86_64
2605 if (CODE64(s
) && s
->dflag
) {
2606 gen_stack_update(s
, 8);
2610 gen_stack_update(s
, 2 << s
->dflag
);
2614 static void gen_stack_A0(DisasContext
*s
)
2616 gen_op_movl_A0_reg(R_ESP
);
2618 gen_op_andl_A0_ffff();
2619 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2621 gen_op_addl_A0_seg(s
, R_SS
);
2624 /* NOTE: wrap around in 16 bit not fully handled */
2625 static void gen_pusha(DisasContext
*s
)
2628 gen_op_movl_A0_reg(R_ESP
);
2629 gen_op_addl_A0_im(-16 << s
->dflag
);
2631 gen_op_andl_A0_ffff();
2632 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2634 gen_op_addl_A0_seg(s
, R_SS
);
2635 for(i
= 0;i
< 8; i
++) {
2636 gen_op_mov_TN_reg(OT_LONG
, 0, 7 - i
);
2637 gen_op_st_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2638 gen_op_addl_A0_im(2 << s
->dflag
);
2640 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2643 /* NOTE: wrap around in 16 bit not fully handled */
2644 static void gen_popa(DisasContext
*s
)
2647 gen_op_movl_A0_reg(R_ESP
);
2649 gen_op_andl_A0_ffff();
2650 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2651 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], 16 << s
->dflag
);
2653 gen_op_addl_A0_seg(s
, R_SS
);
2654 for(i
= 0;i
< 8; i
++) {
2655 /* ESP is not reloaded */
2657 gen_op_ld_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2658 gen_op_mov_reg_T0(OT_WORD
+ s
->dflag
, 7 - i
);
2660 gen_op_addl_A0_im(2 << s
->dflag
);
2662 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2665 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2670 #ifdef TARGET_X86_64
2672 ot
= s
->dflag
? OT_QUAD
: OT_WORD
;
2675 gen_op_movl_A0_reg(R_ESP
);
2676 gen_op_addq_A0_im(-opsize
);
2677 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2680 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2681 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2683 /* XXX: must save state */
2684 gen_helper_enter64_level(cpu_env
, tcg_const_i32(level
),
2685 tcg_const_i32((ot
== OT_QUAD
)),
2688 gen_op_mov_reg_T1(ot
, R_EBP
);
2689 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2690 gen_op_mov_reg_T1(OT_QUAD
, R_ESP
);
2694 ot
= s
->dflag
+ OT_WORD
;
2695 opsize
= 2 << s
->dflag
;
2697 gen_op_movl_A0_reg(R_ESP
);
2698 gen_op_addl_A0_im(-opsize
);
2700 gen_op_andl_A0_ffff();
2701 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2703 gen_op_addl_A0_seg(s
, R_SS
);
2705 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2706 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2708 /* XXX: must save state */
2709 gen_helper_enter_level(cpu_env
, tcg_const_i32(level
),
2710 tcg_const_i32(s
->dflag
),
2713 gen_op_mov_reg_T1(ot
, R_EBP
);
2714 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2715 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2719 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2721 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2722 gen_op_set_cc_op(s
->cc_op
);
2723 gen_jmp_im(cur_eip
);
2724 gen_helper_raise_exception(cpu_env
, tcg_const_i32(trapno
));
2725 s
->is_jmp
= DISAS_TB_JUMP
;
2728 /* an interrupt is different from an exception because of the
2730 static void gen_interrupt(DisasContext
*s
, int intno
,
2731 target_ulong cur_eip
, target_ulong next_eip
)
2733 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2734 gen_op_set_cc_op(s
->cc_op
);
2735 gen_jmp_im(cur_eip
);
2736 gen_helper_raise_interrupt(cpu_env
, tcg_const_i32(intno
),
2737 tcg_const_i32(next_eip
- cur_eip
));
2738 s
->is_jmp
= DISAS_TB_JUMP
;
2741 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2743 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2744 gen_op_set_cc_op(s
->cc_op
);
2745 gen_jmp_im(cur_eip
);
2746 gen_helper_debug(cpu_env
);
2747 s
->is_jmp
= DISAS_TB_JUMP
;
2750 /* generate a generic end of block. Trace exception is also generated
2752 static void gen_eob(DisasContext
*s
)
2754 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2755 gen_op_set_cc_op(s
->cc_op
);
2756 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2757 gen_helper_reset_inhibit_irq(cpu_env
);
2759 if (s
->tb
->flags
& HF_RF_MASK
) {
2760 gen_helper_reset_rf(cpu_env
);
2762 if (s
->singlestep_enabled
) {
2763 gen_helper_debug(cpu_env
);
2765 gen_helper_single_step(cpu_env
);
2769 s
->is_jmp
= DISAS_TB_JUMP
;
2772 /* generate a jump to eip. No segment change must happen before as a
2773 direct call to the next block may occur */
2774 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2777 gen_update_cc_op(s
);
2778 gen_goto_tb(s
, tb_num
, eip
);
2779 s
->is_jmp
= DISAS_TB_JUMP
;
2786 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2788 gen_jmp_tb(s
, eip
, 0);
2791 static inline void gen_ldq_env_A0(int idx
, int offset
)
2793 int mem_index
= (idx
>> 2) - 1;
2794 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2795 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2798 static inline void gen_stq_env_A0(int idx
, int offset
)
2800 int mem_index
= (idx
>> 2) - 1;
2801 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2802 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2805 static inline void gen_ldo_env_A0(int idx
, int offset
)
2807 int mem_index
= (idx
>> 2) - 1;
2808 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2809 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2810 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2811 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2812 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2815 static inline void gen_sto_env_A0(int idx
, int offset
)
2817 int mem_index
= (idx
>> 2) - 1;
2818 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2819 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2820 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2821 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2822 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2825 static inline void gen_op_movo(int d_offset
, int s_offset
)
2827 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2828 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2829 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
+ 8);
2830 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
+ 8);
2833 static inline void gen_op_movq(int d_offset
, int s_offset
)
2835 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2836 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2839 static inline void gen_op_movl(int d_offset
, int s_offset
)
2841 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
, s_offset
);
2842 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, d_offset
);
2845 static inline void gen_op_movq_env_0(int d_offset
)
2847 tcg_gen_movi_i64(cpu_tmp1_i64
, 0);
2848 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2851 typedef void (*SSEFunc_i_ep
)(TCGv_i32 val
, TCGv_ptr env
, TCGv_ptr reg
);
2852 typedef void (*SSEFunc_l_ep
)(TCGv_i64 val
, TCGv_ptr env
, TCGv_ptr reg
);
2853 typedef void (*SSEFunc_0_epi
)(TCGv_ptr env
, TCGv_ptr reg
, TCGv_i32 val
);
2854 typedef void (*SSEFunc_0_epl
)(TCGv_ptr env
, TCGv_ptr reg
, TCGv_i64 val
);
2855 typedef void (*SSEFunc_0_epp
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
);
2856 typedef void (*SSEFunc_0_eppi
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
,
2858 typedef void (*SSEFunc_0_ppi
)(TCGv_ptr reg_a
, TCGv_ptr reg_b
, TCGv_i32 val
);
2859 typedef void (*SSEFunc_0_eppt
)(TCGv_ptr env
, TCGv_ptr reg_a
, TCGv_ptr reg_b
,
2862 #define SSE_SPECIAL ((void *)1)
2863 #define SSE_DUMMY ((void *)2)
2865 #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm }
2866 #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \
2867 gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, }
2869 static const SSEFunc_0_epp sse_op_table1
[256][4] = {
2870 /* 3DNow! extensions */
2871 [0x0e] = { SSE_DUMMY
}, /* femms */
2872 [0x0f] = { SSE_DUMMY
}, /* pf... */
2873 /* pure SSE operations */
2874 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2875 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2876 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd, movsldup, movddup */
2877 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2878 [0x14] = { gen_helper_punpckldq_xmm
, gen_helper_punpcklqdq_xmm
},
2879 [0x15] = { gen_helper_punpckhdq_xmm
, gen_helper_punpckhqdq_xmm
},
2880 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2881 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2883 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2884 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2885 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2886 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd, movntss, movntsd */
2887 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2888 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2889 [0x2e] = { gen_helper_ucomiss
, gen_helper_ucomisd
},
2890 [0x2f] = { gen_helper_comiss
, gen_helper_comisd
},
2891 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2892 [0x51] = SSE_FOP(sqrt
),
2893 [0x52] = { gen_helper_rsqrtps
, NULL
, gen_helper_rsqrtss
, NULL
},
2894 [0x53] = { gen_helper_rcpps
, NULL
, gen_helper_rcpss
, NULL
},
2895 [0x54] = { gen_helper_pand_xmm
, gen_helper_pand_xmm
}, /* andps, andpd */
2896 [0x55] = { gen_helper_pandn_xmm
, gen_helper_pandn_xmm
}, /* andnps, andnpd */
2897 [0x56] = { gen_helper_por_xmm
, gen_helper_por_xmm
}, /* orps, orpd */
2898 [0x57] = { gen_helper_pxor_xmm
, gen_helper_pxor_xmm
}, /* xorps, xorpd */
2899 [0x58] = SSE_FOP(add
),
2900 [0x59] = SSE_FOP(mul
),
2901 [0x5a] = { gen_helper_cvtps2pd
, gen_helper_cvtpd2ps
,
2902 gen_helper_cvtss2sd
, gen_helper_cvtsd2ss
},
2903 [0x5b] = { gen_helper_cvtdq2ps
, gen_helper_cvtps2dq
, gen_helper_cvttps2dq
},
2904 [0x5c] = SSE_FOP(sub
),
2905 [0x5d] = SSE_FOP(min
),
2906 [0x5e] = SSE_FOP(div
),
2907 [0x5f] = SSE_FOP(max
),
2909 [0xc2] = SSE_FOP(cmpeq
),
2910 [0xc6] = { (SSEFunc_0_epp
)gen_helper_shufps
,
2911 (SSEFunc_0_epp
)gen_helper_shufpd
}, /* XXX: casts */
2913 [0x38] = { SSE_SPECIAL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2914 [0x3a] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2916 /* MMX ops and their SSE extensions */
2917 [0x60] = MMX_OP2(punpcklbw
),
2918 [0x61] = MMX_OP2(punpcklwd
),
2919 [0x62] = MMX_OP2(punpckldq
),
2920 [0x63] = MMX_OP2(packsswb
),
2921 [0x64] = MMX_OP2(pcmpgtb
),
2922 [0x65] = MMX_OP2(pcmpgtw
),
2923 [0x66] = MMX_OP2(pcmpgtl
),
2924 [0x67] = MMX_OP2(packuswb
),
2925 [0x68] = MMX_OP2(punpckhbw
),
2926 [0x69] = MMX_OP2(punpckhwd
),
2927 [0x6a] = MMX_OP2(punpckhdq
),
2928 [0x6b] = MMX_OP2(packssdw
),
2929 [0x6c] = { NULL
, gen_helper_punpcklqdq_xmm
},
2930 [0x6d] = { NULL
, gen_helper_punpckhqdq_xmm
},
2931 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2932 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2933 [0x70] = { (SSEFunc_0_epp
)gen_helper_pshufw_mmx
,
2934 (SSEFunc_0_epp
)gen_helper_pshufd_xmm
,
2935 (SSEFunc_0_epp
)gen_helper_pshufhw_xmm
,
2936 (SSEFunc_0_epp
)gen_helper_pshuflw_xmm
}, /* XXX: casts */
2937 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2938 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2939 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2940 [0x74] = MMX_OP2(pcmpeqb
),
2941 [0x75] = MMX_OP2(pcmpeqw
),
2942 [0x76] = MMX_OP2(pcmpeql
),
2943 [0x77] = { SSE_DUMMY
}, /* emms */
2944 [0x78] = { NULL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* extrq_i, insertq_i */
2945 [0x79] = { NULL
, gen_helper_extrq_r
, NULL
, gen_helper_insertq_r
},
2946 [0x7c] = { NULL
, gen_helper_haddpd
, NULL
, gen_helper_haddps
},
2947 [0x7d] = { NULL
, gen_helper_hsubpd
, NULL
, gen_helper_hsubps
},
2948 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2949 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2950 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2951 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2952 [0xd0] = { NULL
, gen_helper_addsubpd
, NULL
, gen_helper_addsubps
},
2953 [0xd1] = MMX_OP2(psrlw
),
2954 [0xd2] = MMX_OP2(psrld
),
2955 [0xd3] = MMX_OP2(psrlq
),
2956 [0xd4] = MMX_OP2(paddq
),
2957 [0xd5] = MMX_OP2(pmullw
),
2958 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2959 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2960 [0xd8] = MMX_OP2(psubusb
),
2961 [0xd9] = MMX_OP2(psubusw
),
2962 [0xda] = MMX_OP2(pminub
),
2963 [0xdb] = MMX_OP2(pand
),
2964 [0xdc] = MMX_OP2(paddusb
),
2965 [0xdd] = MMX_OP2(paddusw
),
2966 [0xde] = MMX_OP2(pmaxub
),
2967 [0xdf] = MMX_OP2(pandn
),
2968 [0xe0] = MMX_OP2(pavgb
),
2969 [0xe1] = MMX_OP2(psraw
),
2970 [0xe2] = MMX_OP2(psrad
),
2971 [0xe3] = MMX_OP2(pavgw
),
2972 [0xe4] = MMX_OP2(pmulhuw
),
2973 [0xe5] = MMX_OP2(pmulhw
),
2974 [0xe6] = { NULL
, gen_helper_cvttpd2dq
, gen_helper_cvtdq2pd
, gen_helper_cvtpd2dq
},
2975 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2976 [0xe8] = MMX_OP2(psubsb
),
2977 [0xe9] = MMX_OP2(psubsw
),
2978 [0xea] = MMX_OP2(pminsw
),
2979 [0xeb] = MMX_OP2(por
),
2980 [0xec] = MMX_OP2(paddsb
),
2981 [0xed] = MMX_OP2(paddsw
),
2982 [0xee] = MMX_OP2(pmaxsw
),
2983 [0xef] = MMX_OP2(pxor
),
2984 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu */
2985 [0xf1] = MMX_OP2(psllw
),
2986 [0xf2] = MMX_OP2(pslld
),
2987 [0xf3] = MMX_OP2(psllq
),
2988 [0xf4] = MMX_OP2(pmuludq
),
2989 [0xf5] = MMX_OP2(pmaddwd
),
2990 [0xf6] = MMX_OP2(psadbw
),
2991 [0xf7] = { (SSEFunc_0_epp
)gen_helper_maskmov_mmx
,
2992 (SSEFunc_0_epp
)gen_helper_maskmov_xmm
}, /* XXX: casts */
2993 [0xf8] = MMX_OP2(psubb
),
2994 [0xf9] = MMX_OP2(psubw
),
2995 [0xfa] = MMX_OP2(psubl
),
2996 [0xfb] = MMX_OP2(psubq
),
2997 [0xfc] = MMX_OP2(paddb
),
2998 [0xfd] = MMX_OP2(paddw
),
2999 [0xfe] = MMX_OP2(paddl
),
3002 static const SSEFunc_0_epp sse_op_table2
[3 * 8][2] = {
3003 [0 + 2] = MMX_OP2(psrlw
),
3004 [0 + 4] = MMX_OP2(psraw
),
3005 [0 + 6] = MMX_OP2(psllw
),
3006 [8 + 2] = MMX_OP2(psrld
),
3007 [8 + 4] = MMX_OP2(psrad
),
3008 [8 + 6] = MMX_OP2(pslld
),
3009 [16 + 2] = MMX_OP2(psrlq
),
3010 [16 + 3] = { NULL
, gen_helper_psrldq_xmm
},
3011 [16 + 6] = MMX_OP2(psllq
),
3012 [16 + 7] = { NULL
, gen_helper_pslldq_xmm
},
3015 static const SSEFunc_0_epi sse_op_table3ai
[] = {
3016 gen_helper_cvtsi2ss
,
3020 #ifdef TARGET_X86_64
3021 static const SSEFunc_0_epl sse_op_table3aq
[] = {
3022 gen_helper_cvtsq2ss
,
3027 static const SSEFunc_i_ep sse_op_table3bi
[] = {
3028 gen_helper_cvttss2si
,
3029 gen_helper_cvtss2si
,
3030 gen_helper_cvttsd2si
,
3034 #ifdef TARGET_X86_64
3035 static const SSEFunc_l_ep sse_op_table3bq
[] = {
3036 gen_helper_cvttss2sq
,
3037 gen_helper_cvtss2sq
,
3038 gen_helper_cvttsd2sq
,
3043 static const SSEFunc_0_epp sse_op_table4
[8][4] = {
3054 static const SSEFunc_0_epp sse_op_table5
[256] = {
3055 [0x0c] = gen_helper_pi2fw
,
3056 [0x0d] = gen_helper_pi2fd
,
3057 [0x1c] = gen_helper_pf2iw
,
3058 [0x1d] = gen_helper_pf2id
,
3059 [0x8a] = gen_helper_pfnacc
,
3060 [0x8e] = gen_helper_pfpnacc
,
3061 [0x90] = gen_helper_pfcmpge
,
3062 [0x94] = gen_helper_pfmin
,
3063 [0x96] = gen_helper_pfrcp
,
3064 [0x97] = gen_helper_pfrsqrt
,
3065 [0x9a] = gen_helper_pfsub
,
3066 [0x9e] = gen_helper_pfadd
,
3067 [0xa0] = gen_helper_pfcmpgt
,
3068 [0xa4] = gen_helper_pfmax
,
3069 [0xa6] = gen_helper_movq
, /* pfrcpit1; no need to actually increase precision */
3070 [0xa7] = gen_helper_movq
, /* pfrsqit1 */
3071 [0xaa] = gen_helper_pfsubr
,
3072 [0xae] = gen_helper_pfacc
,
3073 [0xb0] = gen_helper_pfcmpeq
,
3074 [0xb4] = gen_helper_pfmul
,
3075 [0xb6] = gen_helper_movq
, /* pfrcpit2 */
3076 [0xb7] = gen_helper_pmulhrw_mmx
,
3077 [0xbb] = gen_helper_pswapd
,
3078 [0xbf] = gen_helper_pavgb_mmx
/* pavgusb */
3081 struct SSEOpHelper_epp
{
3082 SSEFunc_0_epp op
[2];
3086 struct SSEOpHelper_eppi
{
3087 SSEFunc_0_eppi op
[2];
3091 #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
3092 #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 }
3093 #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 }
3094 #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 }
3096 static const struct SSEOpHelper_epp sse_op_table6
[256] = {
3097 [0x00] = SSSE3_OP(pshufb
),
3098 [0x01] = SSSE3_OP(phaddw
),
3099 [0x02] = SSSE3_OP(phaddd
),
3100 [0x03] = SSSE3_OP(phaddsw
),
3101 [0x04] = SSSE3_OP(pmaddubsw
),
3102 [0x05] = SSSE3_OP(phsubw
),
3103 [0x06] = SSSE3_OP(phsubd
),
3104 [0x07] = SSSE3_OP(phsubsw
),
3105 [0x08] = SSSE3_OP(psignb
),
3106 [0x09] = SSSE3_OP(psignw
),
3107 [0x0a] = SSSE3_OP(psignd
),
3108 [0x0b] = SSSE3_OP(pmulhrsw
),
3109 [0x10] = SSE41_OP(pblendvb
),
3110 [0x14] = SSE41_OP(blendvps
),
3111 [0x15] = SSE41_OP(blendvpd
),
3112 [0x17] = SSE41_OP(ptest
),
3113 [0x1c] = SSSE3_OP(pabsb
),
3114 [0x1d] = SSSE3_OP(pabsw
),
3115 [0x1e] = SSSE3_OP(pabsd
),
3116 [0x20] = SSE41_OP(pmovsxbw
),
3117 [0x21] = SSE41_OP(pmovsxbd
),
3118 [0x22] = SSE41_OP(pmovsxbq
),
3119 [0x23] = SSE41_OP(pmovsxwd
),
3120 [0x24] = SSE41_OP(pmovsxwq
),
3121 [0x25] = SSE41_OP(pmovsxdq
),
3122 [0x28] = SSE41_OP(pmuldq
),
3123 [0x29] = SSE41_OP(pcmpeqq
),
3124 [0x2a] = SSE41_SPECIAL
, /* movntqda */
3125 [0x2b] = SSE41_OP(packusdw
),
3126 [0x30] = SSE41_OP(pmovzxbw
),
3127 [0x31] = SSE41_OP(pmovzxbd
),
3128 [0x32] = SSE41_OP(pmovzxbq
),
3129 [0x33] = SSE41_OP(pmovzxwd
),
3130 [0x34] = SSE41_OP(pmovzxwq
),
3131 [0x35] = SSE41_OP(pmovzxdq
),
3132 [0x37] = SSE42_OP(pcmpgtq
),
3133 [0x38] = SSE41_OP(pminsb
),
3134 [0x39] = SSE41_OP(pminsd
),
3135 [0x3a] = SSE41_OP(pminuw
),
3136 [0x3b] = SSE41_OP(pminud
),
3137 [0x3c] = SSE41_OP(pmaxsb
),
3138 [0x3d] = SSE41_OP(pmaxsd
),
3139 [0x3e] = SSE41_OP(pmaxuw
),
3140 [0x3f] = SSE41_OP(pmaxud
),
3141 [0x40] = SSE41_OP(pmulld
),
3142 [0x41] = SSE41_OP(phminposuw
),
3145 static const struct SSEOpHelper_eppi sse_op_table7
[256] = {
3146 [0x08] = SSE41_OP(roundps
),
3147 [0x09] = SSE41_OP(roundpd
),
3148 [0x0a] = SSE41_OP(roundss
),
3149 [0x0b] = SSE41_OP(roundsd
),
3150 [0x0c] = SSE41_OP(blendps
),
3151 [0x0d] = SSE41_OP(blendpd
),
3152 [0x0e] = SSE41_OP(pblendw
),
3153 [0x0f] = SSSE3_OP(palignr
),
3154 [0x14] = SSE41_SPECIAL
, /* pextrb */
3155 [0x15] = SSE41_SPECIAL
, /* pextrw */
3156 [0x16] = SSE41_SPECIAL
, /* pextrd/pextrq */
3157 [0x17] = SSE41_SPECIAL
, /* extractps */
3158 [0x20] = SSE41_SPECIAL
, /* pinsrb */
3159 [0x21] = SSE41_SPECIAL
, /* insertps */
3160 [0x22] = SSE41_SPECIAL
, /* pinsrd/pinsrq */
3161 [0x40] = SSE41_OP(dpps
),
3162 [0x41] = SSE41_OP(dppd
),
3163 [0x42] = SSE41_OP(mpsadbw
),
3164 [0x60] = SSE42_OP(pcmpestrm
),
3165 [0x61] = SSE42_OP(pcmpestri
),
3166 [0x62] = SSE42_OP(pcmpistrm
),
3167 [0x63] = SSE42_OP(pcmpistri
),
3170 static void gen_sse(DisasContext
*s
, int b
, target_ulong pc_start
, int rex_r
)
3172 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
3173 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
3174 SSEFunc_0_epp sse_fn_epp
;
3175 SSEFunc_0_eppi sse_fn_eppi
;
3176 SSEFunc_0_ppi sse_fn_ppi
;
3177 SSEFunc_0_eppt sse_fn_eppt
;
3180 if (s
->prefix
& PREFIX_DATA
)
3182 else if (s
->prefix
& PREFIX_REPZ
)
3184 else if (s
->prefix
& PREFIX_REPNZ
)
3188 sse_fn_epp
= sse_op_table1
[b
][b1
];
3192 if ((b
<= 0x5f && b
>= 0x10) || b
== 0xc6 || b
== 0xc2) {
3202 /* simple MMX/SSE operation */
3203 if (s
->flags
& HF_TS_MASK
) {
3204 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
3207 if (s
->flags
& HF_EM_MASK
) {
3209 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
3212 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
3213 if ((b
!= 0x38 && b
!= 0x3a) || (s
->prefix
& PREFIX_DATA
))
3216 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3219 gen_helper_emms(cpu_env
);
3224 gen_helper_emms(cpu_env
);
3227 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
3228 the static cpu state) */
3230 gen_helper_enter_mmx(cpu_env
);
3233 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3234 reg
= ((modrm
>> 3) & 7);
3237 mod
= (modrm
>> 6) & 3;
3238 if (sse_fn_epp
== SSE_SPECIAL
) {
3241 case 0x0e7: /* movntq */
3244 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3245 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3247 case 0x1e7: /* movntdq */
3248 case 0x02b: /* movntps */
3249 case 0x12b: /* movntps */
3252 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3253 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3255 case 0x3f0: /* lddqu */
3258 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3259 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3261 case 0x22b: /* movntss */
3262 case 0x32b: /* movntsd */
3265 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3267 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,
3270 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3271 xmm_regs
[reg
].XMM_L(0)));
3272 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3275 case 0x6e: /* movd mm, ea */
3276 #ifdef TARGET_X86_64
3277 if (s
->dflag
== 2) {
3278 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3279 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3283 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3284 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3285 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3286 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3287 gen_helper_movl_mm_T0_mmx(cpu_ptr0
, cpu_tmp2_i32
);
3290 case 0x16e: /* movd xmm, ea */
3291 #ifdef TARGET_X86_64
3292 if (s
->dflag
== 2) {
3293 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3294 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3295 offsetof(CPUX86State
,xmm_regs
[reg
]));
3296 gen_helper_movq_mm_T0_xmm(cpu_ptr0
, cpu_T
[0]);
3300 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3301 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3302 offsetof(CPUX86State
,xmm_regs
[reg
]));
3303 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3304 gen_helper_movl_mm_T0_xmm(cpu_ptr0
, cpu_tmp2_i32
);
3307 case 0x6f: /* movq mm, ea */
3309 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3310 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3313 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3314 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3315 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3316 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3319 case 0x010: /* movups */
3320 case 0x110: /* movupd */
3321 case 0x028: /* movaps */
3322 case 0x128: /* movapd */
3323 case 0x16f: /* movdqa xmm, ea */
3324 case 0x26f: /* movdqu xmm, ea */
3326 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3327 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3329 rm
= (modrm
& 7) | REX_B(s
);
3330 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
3331 offsetof(CPUX86State
,xmm_regs
[rm
]));
3334 case 0x210: /* movss xmm, ea */
3336 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3337 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3338 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3340 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3341 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3342 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3344 rm
= (modrm
& 7) | REX_B(s
);
3345 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3346 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3349 case 0x310: /* movsd xmm, ea */
3351 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3352 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3354 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3355 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3357 rm
= (modrm
& 7) | REX_B(s
);
3358 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3359 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3362 case 0x012: /* movlps */
3363 case 0x112: /* movlpd */
3365 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3366 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3369 rm
= (modrm
& 7) | REX_B(s
);
3370 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3371 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3374 case 0x212: /* movsldup */
3376 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3377 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3379 rm
= (modrm
& 7) | REX_B(s
);
3380 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3381 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3382 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3383 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(2)));
3385 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3386 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3387 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3388 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3390 case 0x312: /* movddup */
3392 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3393 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3395 rm
= (modrm
& 7) | REX_B(s
);
3396 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3397 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3399 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3400 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3402 case 0x016: /* movhps */
3403 case 0x116: /* movhpd */
3405 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3406 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3409 rm
= (modrm
& 7) | REX_B(s
);
3410 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3411 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3414 case 0x216: /* movshdup */
3416 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3417 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3419 rm
= (modrm
& 7) | REX_B(s
);
3420 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3421 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
3422 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3423 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
3425 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3426 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3427 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3428 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3433 int bit_index
, field_length
;
3435 if (b1
== 1 && reg
!= 0)
3437 field_length
= cpu_ldub_code(cpu_single_env
, s
->pc
++) & 0x3F;
3438 bit_index
= cpu_ldub_code(cpu_single_env
, s
->pc
++) & 0x3F;
3439 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3440 offsetof(CPUX86State
,xmm_regs
[reg
]));
3442 gen_helper_extrq_i(cpu_env
, cpu_ptr0
,
3443 tcg_const_i32(bit_index
),
3444 tcg_const_i32(field_length
));
3446 gen_helper_insertq_i(cpu_env
, cpu_ptr0
,
3447 tcg_const_i32(bit_index
),
3448 tcg_const_i32(field_length
));
3451 case 0x7e: /* movd ea, mm */
3452 #ifdef TARGET_X86_64
3453 if (s
->dflag
== 2) {
3454 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3455 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3456 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3460 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3461 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_L(0)));
3462 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3465 case 0x17e: /* movd ea, xmm */
3466 #ifdef TARGET_X86_64
3467 if (s
->dflag
== 2) {
3468 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3469 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3470 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3474 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3475 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3476 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3479 case 0x27e: /* movq xmm, ea */
3481 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3482 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3484 rm
= (modrm
& 7) | REX_B(s
);
3485 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3486 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3488 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3490 case 0x7f: /* movq ea, mm */
3492 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3493 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3496 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
3497 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3500 case 0x011: /* movups */
3501 case 0x111: /* movupd */
3502 case 0x029: /* movaps */
3503 case 0x129: /* movapd */
3504 case 0x17f: /* movdqa ea, xmm */
3505 case 0x27f: /* movdqu ea, xmm */
3507 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3508 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3510 rm
= (modrm
& 7) | REX_B(s
);
3511 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
3512 offsetof(CPUX86State
,xmm_regs
[reg
]));
3515 case 0x211: /* movss ea, xmm */
3517 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3518 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3519 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3521 rm
= (modrm
& 7) | REX_B(s
);
3522 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
3523 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3526 case 0x311: /* movsd ea, xmm */
3528 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3529 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3531 rm
= (modrm
& 7) | REX_B(s
);
3532 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3533 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3536 case 0x013: /* movlps */
3537 case 0x113: /* movlpd */
3539 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3540 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3545 case 0x017: /* movhps */
3546 case 0x117: /* movhpd */
3548 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3549 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3554 case 0x71: /* shift mm, im */
3557 case 0x171: /* shift xmm, im */
3563 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3565 gen_op_movl_T0_im(val
);
3566 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3568 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
3569 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
3571 gen_op_movl_T0_im(val
);
3572 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
3574 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
3575 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
3577 sse_fn_epp
= sse_op_table2
[((b
- 1) & 3) * 8 +
3578 (((modrm
>> 3)) & 7)][b1
];
3583 rm
= (modrm
& 7) | REX_B(s
);
3584 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3587 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3589 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3590 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op1_offset
);
3591 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3593 case 0x050: /* movmskps */
3594 rm
= (modrm
& 7) | REX_B(s
);
3595 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3596 offsetof(CPUX86State
,xmm_regs
[rm
]));
3597 gen_helper_movmskps(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3598 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3599 gen_op_mov_reg_T0(OT_LONG
, reg
);
3601 case 0x150: /* movmskpd */
3602 rm
= (modrm
& 7) | REX_B(s
);
3603 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3604 offsetof(CPUX86State
,xmm_regs
[rm
]));
3605 gen_helper_movmskpd(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3606 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3607 gen_op_mov_reg_T0(OT_LONG
, reg
);
3609 case 0x02a: /* cvtpi2ps */
3610 case 0x12a: /* cvtpi2pd */
3611 gen_helper_enter_mmx(cpu_env
);
3613 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3614 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3615 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3618 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3620 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3621 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3622 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3625 gen_helper_cvtpi2ps(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3629 gen_helper_cvtpi2pd(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3633 case 0x22a: /* cvtsi2ss */
3634 case 0x32a: /* cvtsi2sd */
3635 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3636 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3637 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3638 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3639 if (ot
== OT_LONG
) {
3640 SSEFunc_0_epi sse_fn_epi
= sse_op_table3ai
[(b
>> 8) & 1];
3641 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3642 sse_fn_epi(cpu_env
, cpu_ptr0
, cpu_tmp2_i32
);
3644 #ifdef TARGET_X86_64
3645 SSEFunc_0_epl sse_fn_epl
= sse_op_table3aq
[(b
>> 8) & 1];
3646 sse_fn_epl(cpu_env
, cpu_ptr0
, cpu_T
[0]);
3652 case 0x02c: /* cvttps2pi */
3653 case 0x12c: /* cvttpd2pi */
3654 case 0x02d: /* cvtps2pi */
3655 case 0x12d: /* cvtpd2pi */
3656 gen_helper_enter_mmx(cpu_env
);
3658 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3659 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3660 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3662 rm
= (modrm
& 7) | REX_B(s
);
3663 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3665 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
3666 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3667 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3670 gen_helper_cvttps2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3673 gen_helper_cvttpd2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3676 gen_helper_cvtps2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3679 gen_helper_cvtpd2pi(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3683 case 0x22c: /* cvttss2si */
3684 case 0x32c: /* cvttsd2si */
3685 case 0x22d: /* cvtss2si */
3686 case 0x32d: /* cvtsd2si */
3687 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3689 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3691 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
3693 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3694 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3696 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3698 rm
= (modrm
& 7) | REX_B(s
);
3699 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3701 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3702 if (ot
== OT_LONG
) {
3703 SSEFunc_i_ep sse_fn_i_ep
=
3704 sse_op_table3bi
[((b
>> 7) & 2) | (b
& 1)];
3705 sse_fn_i_ep(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3706 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3708 #ifdef TARGET_X86_64
3709 SSEFunc_l_ep sse_fn_l_ep
=
3710 sse_op_table3bq
[((b
>> 7) & 2) | (b
& 1)];
3711 sse_fn_l_ep(cpu_T
[0], cpu_env
, cpu_ptr0
);
3716 gen_op_mov_reg_T0(ot
, reg
);
3718 case 0xc4: /* pinsrw */
3721 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3722 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3725 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3726 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_W(val
)));
3729 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3730 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_W(val
)));
3733 case 0xc5: /* pextrw */
3737 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3738 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3741 rm
= (modrm
& 7) | REX_B(s
);
3742 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3743 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_W(val
)));
3747 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3748 offsetof(CPUX86State
,fpregs
[rm
].mmx
.MMX_W(val
)));
3750 reg
= ((modrm
>> 3) & 7) | rex_r
;
3751 gen_op_mov_reg_T0(ot
, reg
);
3753 case 0x1d6: /* movq ea, xmm */
3755 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3756 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3758 rm
= (modrm
& 7) | REX_B(s
);
3759 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3760 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3761 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3764 case 0x2d6: /* movq2dq */
3765 gen_helper_enter_mmx(cpu_env
);
3767 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3768 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3769 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3771 case 0x3d6: /* movdq2q */
3772 gen_helper_enter_mmx(cpu_env
);
3773 rm
= (modrm
& 7) | REX_B(s
);
3774 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
),
3775 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3777 case 0xd7: /* pmovmskb */
3782 rm
= (modrm
& 7) | REX_B(s
);
3783 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,xmm_regs
[rm
]));
3784 gen_helper_pmovmskb_xmm(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3787 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3788 gen_helper_pmovmskb_mmx(cpu_tmp2_i32
, cpu_env
, cpu_ptr0
);
3790 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3791 reg
= ((modrm
>> 3) & 7) | rex_r
;
3792 gen_op_mov_reg_T0(OT_LONG
, reg
);
3795 if (s
->prefix
& PREFIX_REPNZ
)
3799 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3801 reg
= ((modrm
>> 3) & 7) | rex_r
;
3802 mod
= (modrm
>> 6) & 3;
3807 sse_fn_epp
= sse_op_table6
[b
].op
[b1
];
3811 if (!(s
->cpuid_ext_features
& sse_op_table6
[b
].ext_mask
))
3815 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3817 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3819 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3820 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3822 case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */
3823 case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */
3824 case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */
3825 gen_ldq_env_A0(s
->mem_index
, op2_offset
+
3826 offsetof(XMMReg
, XMM_Q(0)));
3828 case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */
3829 case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */
3830 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3831 (s
->mem_index
>> 2) - 1);
3832 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3833 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, op2_offset
+
3834 offsetof(XMMReg
, XMM_L(0)));
3836 case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */
3837 tcg_gen_qemu_ld16u(cpu_tmp0
, cpu_A0
,
3838 (s
->mem_index
>> 2) - 1);
3839 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, op2_offset
+
3840 offsetof(XMMReg
, XMM_W(0)));
3842 case 0x2a: /* movntqda */
3843 gen_ldo_env_A0(s
->mem_index
, op1_offset
);
3846 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3850 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3852 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3854 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3855 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3856 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3859 if (sse_fn_epp
== SSE_SPECIAL
) {
3863 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3864 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3865 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
3868 s
->cc_op
= CC_OP_EFLAGS
;
3870 case 0x338: /* crc32 */
3873 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3874 reg
= ((modrm
>> 3) & 7) | rex_r
;
3876 if (b
!= 0xf0 && b
!= 0xf1)
3878 if (!(s
->cpuid_ext_features
& CPUID_EXT_SSE42
))
3883 else if (b
== 0xf1 && s
->dflag
!= 2)
3884 if (s
->prefix
& PREFIX_DATA
)
3891 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
3892 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3893 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3894 gen_helper_crc32(cpu_T
[0], cpu_tmp2_i32
,
3895 cpu_T
[0], tcg_const_i32(8 << ot
));
3897 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3898 gen_op_mov_reg_T0(ot
, reg
);
3903 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3905 reg
= ((modrm
>> 3) & 7) | rex_r
;
3906 mod
= (modrm
>> 6) & 3;
3911 sse_fn_eppi
= sse_op_table7
[b
].op
[b1
];
3915 if (!(s
->cpuid_ext_features
& sse_op_table7
[b
].ext_mask
))
3918 if (sse_fn_eppi
== SSE_SPECIAL
) {
3919 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3920 rm
= (modrm
& 7) | REX_B(s
);
3922 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3923 reg
= ((modrm
>> 3) & 7) | rex_r
;
3924 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
3926 case 0x14: /* pextrb */
3927 tcg_gen_ld8u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3928 xmm_regs
[reg
].XMM_B(val
& 15)));
3930 gen_op_mov_reg_T0(ot
, rm
);
3932 tcg_gen_qemu_st8(cpu_T
[0], cpu_A0
,
3933 (s
->mem_index
>> 2) - 1);
3935 case 0x15: /* pextrw */
3936 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3937 xmm_regs
[reg
].XMM_W(val
& 7)));
3939 gen_op_mov_reg_T0(ot
, rm
);
3941 tcg_gen_qemu_st16(cpu_T
[0], cpu_A0
,
3942 (s
->mem_index
>> 2) - 1);
3945 if (ot
== OT_LONG
) { /* pextrd */
3946 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3947 offsetof(CPUX86State
,
3948 xmm_regs
[reg
].XMM_L(val
& 3)));
3949 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3951 gen_op_mov_reg_v(ot
, rm
, cpu_T
[0]);
3953 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3954 (s
->mem_index
>> 2) - 1);
3955 } else { /* pextrq */
3956 #ifdef TARGET_X86_64
3957 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3958 offsetof(CPUX86State
,
3959 xmm_regs
[reg
].XMM_Q(val
& 1)));
3961 gen_op_mov_reg_v(ot
, rm
, cpu_tmp1_i64
);
3963 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
3964 (s
->mem_index
>> 2) - 1);
3970 case 0x17: /* extractps */
3971 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3972 xmm_regs
[reg
].XMM_L(val
& 3)));
3974 gen_op_mov_reg_T0(ot
, rm
);
3976 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3977 (s
->mem_index
>> 2) - 1);
3979 case 0x20: /* pinsrb */
3981 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
3983 tcg_gen_qemu_ld8u(cpu_tmp0
, cpu_A0
,
3984 (s
->mem_index
>> 2) - 1);
3985 tcg_gen_st8_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
,
3986 xmm_regs
[reg
].XMM_B(val
& 15)));
3988 case 0x21: /* insertps */
3990 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3991 offsetof(CPUX86State
,xmm_regs
[rm
]
3992 .XMM_L((val
>> 6) & 3)));
3994 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3995 (s
->mem_index
>> 2) - 1);
3996 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3998 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3999 offsetof(CPUX86State
,xmm_regs
[reg
]
4000 .XMM_L((val
>> 4) & 3)));
4002 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4003 cpu_env
, offsetof(CPUX86State
,
4004 xmm_regs
[reg
].XMM_L(0)));
4006 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4007 cpu_env
, offsetof(CPUX86State
,
4008 xmm_regs
[reg
].XMM_L(1)));
4010 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4011 cpu_env
, offsetof(CPUX86State
,
4012 xmm_regs
[reg
].XMM_L(2)));
4014 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
4015 cpu_env
, offsetof(CPUX86State
,
4016 xmm_regs
[reg
].XMM_L(3)));
4019 if (ot
== OT_LONG
) { /* pinsrd */
4021 gen_op_mov_v_reg(ot
, cpu_tmp0
, rm
);
4023 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
4024 (s
->mem_index
>> 2) - 1);
4025 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
4026 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
4027 offsetof(CPUX86State
,
4028 xmm_regs
[reg
].XMM_L(val
& 3)));
4029 } else { /* pinsrq */
4030 #ifdef TARGET_X86_64
4032 gen_op_mov_v_reg(ot
, cpu_tmp1_i64
, rm
);
4034 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
4035 (s
->mem_index
>> 2) - 1);
4036 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
4037 offsetof(CPUX86State
,
4038 xmm_regs
[reg
].XMM_Q(val
& 1)));
4049 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
4051 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
4053 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
4054 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4055 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4058 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4060 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4062 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4063 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4064 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4067 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4069 if ((b
& 0xfc) == 0x60) { /* pcmpXstrX */
4070 s
->cc_op
= CC_OP_EFLAGS
;
4073 /* The helper must use entire 64-bit gp registers */
4077 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4078 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4079 sse_fn_eppi(cpu_env
, cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4085 /* generic MMX or SSE operation */
4087 case 0x70: /* pshufx insn */
4088 case 0xc6: /* pshufx insn */
4089 case 0xc2: /* compare insns */
4096 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
4098 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4099 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
4100 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f && b
!= 0x5b) ||
4102 /* specific case for SSE single instructions */
4105 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
4106 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
4109 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
4112 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4115 rm
= (modrm
& 7) | REX_B(s
);
4116 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
4119 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4121 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4122 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4123 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4126 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4130 case 0x0f: /* 3DNow! data insns */
4131 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
4133 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4134 sse_fn_epp
= sse_op_table5
[val
];
4138 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4139 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4140 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4142 case 0x70: /* pshufx insn */
4143 case 0xc6: /* pshufx insn */
4144 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4145 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4146 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4147 /* XXX: introduce a new table? */
4148 sse_fn_ppi
= (SSEFunc_0_ppi
)sse_fn_epp
;
4149 sse_fn_ppi(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4153 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4156 sse_fn_epp
= sse_op_table4
[val
][b1
];
4158 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4159 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4160 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4163 /* maskmov : we must prepare A0 */
4166 #ifdef TARGET_X86_64
4167 if (s
->aflag
== 2) {
4168 gen_op_movq_A0_reg(R_EDI
);
4172 gen_op_movl_A0_reg(R_EDI
);
4174 gen_op_andl_A0_ffff();
4176 gen_add_A0_ds_seg(s
);
4178 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4179 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4180 /* XXX: introduce a new table? */
4181 sse_fn_eppt
= (SSEFunc_0_eppt
)sse_fn_epp
;
4182 sse_fn_eppt(cpu_env
, cpu_ptr0
, cpu_ptr1
, cpu_A0
);
4185 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4186 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4187 sse_fn_epp(cpu_env
, cpu_ptr0
, cpu_ptr1
);
4190 if (b
== 0x2e || b
== 0x2f) {
4191 s
->cc_op
= CC_OP_EFLAGS
;
4196 /* convert one instruction. s->is_jmp is set if the translation must
4197 be stopped. Return the next pc value */
4198 static target_ulong
disas_insn(DisasContext
*s
, target_ulong pc_start
)
4200 int b
, prefixes
, aflag
, dflag
;
4202 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
4203 target_ulong next_eip
, tval
;
4206 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
4207 tcg_gen_debug_insn_start(pc_start
);
4216 #ifdef TARGET_X86_64
4221 s
->rip_offset
= 0; /* for relative ip address */
4223 b
= cpu_ldub_code(cpu_single_env
, s
->pc
);
4225 /* check prefixes */
4226 #ifdef TARGET_X86_64
4230 prefixes
|= PREFIX_REPZ
;
4233 prefixes
|= PREFIX_REPNZ
;
4236 prefixes
|= PREFIX_LOCK
;
4257 prefixes
|= PREFIX_DATA
;
4260 prefixes
|= PREFIX_ADR
;
4264 rex_w
= (b
>> 3) & 1;
4265 rex_r
= (b
& 0x4) << 1;
4266 s
->rex_x
= (b
& 0x2) << 2;
4267 REX_B(s
) = (b
& 0x1) << 3;
4268 x86_64_hregs
= 1; /* select uniform byte register addressing */
4272 /* 0x66 is ignored if rex.w is set */
4275 if (prefixes
& PREFIX_DATA
)
4278 if (!(prefixes
& PREFIX_ADR
))
4285 prefixes
|= PREFIX_REPZ
;
4288 prefixes
|= PREFIX_REPNZ
;
4291 prefixes
|= PREFIX_LOCK
;
4312 prefixes
|= PREFIX_DATA
;
4315 prefixes
|= PREFIX_ADR
;
4318 if (prefixes
& PREFIX_DATA
)
4320 if (prefixes
& PREFIX_ADR
)
4324 s
->prefix
= prefixes
;
4328 /* lock generation */
4329 if (prefixes
& PREFIX_LOCK
)
4332 /* now check op code */
4336 /**************************/
4337 /* extended op code */
4338 b
= cpu_ldub_code(cpu_single_env
, s
->pc
++) | 0x100;
4341 /**************************/
4359 ot
= dflag
+ OT_WORD
;
4362 case 0: /* OP Ev, Gv */
4363 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4364 reg
= ((modrm
>> 3) & 7) | rex_r
;
4365 mod
= (modrm
>> 6) & 3;
4366 rm
= (modrm
& 7) | REX_B(s
);
4368 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4370 } else if (op
== OP_XORL
&& rm
== reg
) {
4372 /* xor reg, reg optimisation */
4374 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4375 gen_op_mov_reg_T0(ot
, reg
);
4376 gen_op_update1_cc();
4381 gen_op_mov_TN_reg(ot
, 1, reg
);
4382 gen_op(s
, op
, ot
, opreg
);
4384 case 1: /* OP Gv, Ev */
4385 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4386 mod
= (modrm
>> 6) & 3;
4387 reg
= ((modrm
>> 3) & 7) | rex_r
;
4388 rm
= (modrm
& 7) | REX_B(s
);
4390 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4391 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4392 } else if (op
== OP_XORL
&& rm
== reg
) {
4395 gen_op_mov_TN_reg(ot
, 1, rm
);
4397 gen_op(s
, op
, ot
, reg
);
4399 case 2: /* OP A, Iv */
4400 val
= insn_get(s
, ot
);
4401 gen_op_movl_T1_im(val
);
4402 gen_op(s
, op
, ot
, OR_EAX
);
4411 case 0x80: /* GRP1 */
4420 ot
= dflag
+ OT_WORD
;
4422 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4423 mod
= (modrm
>> 6) & 3;
4424 rm
= (modrm
& 7) | REX_B(s
);
4425 op
= (modrm
>> 3) & 7;
4431 s
->rip_offset
= insn_const_size(ot
);
4432 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4443 val
= insn_get(s
, ot
);
4446 val
= (int8_t)insn_get(s
, OT_BYTE
);
4449 gen_op_movl_T1_im(val
);
4450 gen_op(s
, op
, ot
, opreg
);
4454 /**************************/
4455 /* inc, dec, and other misc arith */
4456 case 0x40 ... 0x47: /* inc Gv */
4457 ot
= dflag
? OT_LONG
: OT_WORD
;
4458 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
4460 case 0x48 ... 0x4f: /* dec Gv */
4461 ot
= dflag
? OT_LONG
: OT_WORD
;
4462 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
4464 case 0xf6: /* GRP3 */
4469 ot
= dflag
+ OT_WORD
;
4471 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4472 mod
= (modrm
>> 6) & 3;
4473 rm
= (modrm
& 7) | REX_B(s
);
4474 op
= (modrm
>> 3) & 7;
4477 s
->rip_offset
= insn_const_size(ot
);
4478 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4479 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4481 gen_op_mov_TN_reg(ot
, 0, rm
);
4486 val
= insn_get(s
, ot
);
4487 gen_op_movl_T1_im(val
);
4488 gen_op_testl_T0_T1_cc();
4489 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4492 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
4494 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4496 gen_op_mov_reg_T0(ot
, rm
);
4500 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
4502 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4504 gen_op_mov_reg_T0(ot
, rm
);
4506 gen_op_update_neg_cc();
4507 s
->cc_op
= CC_OP_SUBB
+ ot
;
4512 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4513 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
4514 tcg_gen_ext8u_tl(cpu_T
[1], cpu_T
[1]);
4515 /* XXX: use 32 bit mul which could be faster */
4516 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4517 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4518 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4519 tcg_gen_andi_tl(cpu_cc_src
, cpu_T
[0], 0xff00);
4520 s
->cc_op
= CC_OP_MULB
;
4523 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4524 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
4525 tcg_gen_ext16u_tl(cpu_T
[1], cpu_T
[1]);
4526 /* XXX: use 32 bit mul which could be faster */
4527 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4528 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4529 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4530 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4531 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4532 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4533 s
->cc_op
= CC_OP_MULW
;
4537 #ifdef TARGET_X86_64
4538 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4539 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
4540 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
4541 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4542 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4543 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4544 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4545 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4546 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4550 t0
= tcg_temp_new_i64();
4551 t1
= tcg_temp_new_i64();
4552 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4553 tcg_gen_extu_i32_i64(t0
, cpu_T
[0]);
4554 tcg_gen_extu_i32_i64(t1
, cpu_T
[1]);
4555 tcg_gen_mul_i64(t0
, t0
, t1
);
4556 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4557 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4558 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4559 tcg_gen_shri_i64(t0
, t0
, 32);
4560 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4561 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4562 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4565 s
->cc_op
= CC_OP_MULL
;
4567 #ifdef TARGET_X86_64
4569 gen_helper_mulq_EAX_T0(cpu_env
, cpu_T
[0]);
4570 s
->cc_op
= CC_OP_MULQ
;
4578 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4579 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4580 tcg_gen_ext8s_tl(cpu_T
[1], cpu_T
[1]);
4581 /* XXX: use 32 bit mul which could be faster */
4582 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4583 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4584 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4585 tcg_gen_ext8s_tl(cpu_tmp0
, cpu_T
[0]);
4586 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4587 s
->cc_op
= CC_OP_MULB
;
4590 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4591 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4592 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4593 /* XXX: use 32 bit mul which could be faster */
4594 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4595 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4596 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4597 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4598 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4599 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4600 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4601 s
->cc_op
= CC_OP_MULW
;
4605 #ifdef TARGET_X86_64
4606 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4607 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4608 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4609 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4610 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4611 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4612 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4613 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4614 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4615 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4619 t0
= tcg_temp_new_i64();
4620 t1
= tcg_temp_new_i64();
4621 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4622 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4623 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4624 tcg_gen_mul_i64(t0
, t0
, t1
);
4625 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4626 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4627 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4628 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4629 tcg_gen_shri_i64(t0
, t0
, 32);
4630 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4631 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4632 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4635 s
->cc_op
= CC_OP_MULL
;
4637 #ifdef TARGET_X86_64
4639 gen_helper_imulq_EAX_T0(cpu_env
, cpu_T
[0]);
4640 s
->cc_op
= CC_OP_MULQ
;
4648 gen_jmp_im(pc_start
- s
->cs_base
);
4649 gen_helper_divb_AL(cpu_env
, cpu_T
[0]);
4652 gen_jmp_im(pc_start
- s
->cs_base
);
4653 gen_helper_divw_AX(cpu_env
, cpu_T
[0]);
4657 gen_jmp_im(pc_start
- s
->cs_base
);
4658 gen_helper_divl_EAX(cpu_env
, cpu_T
[0]);
4660 #ifdef TARGET_X86_64
4662 gen_jmp_im(pc_start
- s
->cs_base
);
4663 gen_helper_divq_EAX(cpu_env
, cpu_T
[0]);
4671 gen_jmp_im(pc_start
- s
->cs_base
);
4672 gen_helper_idivb_AL(cpu_env
, cpu_T
[0]);
4675 gen_jmp_im(pc_start
- s
->cs_base
);
4676 gen_helper_idivw_AX(cpu_env
, cpu_T
[0]);
4680 gen_jmp_im(pc_start
- s
->cs_base
);
4681 gen_helper_idivl_EAX(cpu_env
, cpu_T
[0]);
4683 #ifdef TARGET_X86_64
4685 gen_jmp_im(pc_start
- s
->cs_base
);
4686 gen_helper_idivq_EAX(cpu_env
, cpu_T
[0]);
4696 case 0xfe: /* GRP4 */
4697 case 0xff: /* GRP5 */
4701 ot
= dflag
+ OT_WORD
;
4703 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4704 mod
= (modrm
>> 6) & 3;
4705 rm
= (modrm
& 7) | REX_B(s
);
4706 op
= (modrm
>> 3) & 7;
4707 if (op
>= 2 && b
== 0xfe) {
4711 if (op
== 2 || op
== 4) {
4712 /* operand size for jumps is 64 bit */
4714 } else if (op
== 3 || op
== 5) {
4715 ot
= dflag
? OT_LONG
+ (rex_w
== 1) : OT_WORD
;
4716 } else if (op
== 6) {
4717 /* default push size is 64 bit */
4718 ot
= dflag
? OT_QUAD
: OT_WORD
;
4722 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4723 if (op
>= 2 && op
!= 3 && op
!= 5)
4724 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4726 gen_op_mov_TN_reg(ot
, 0, rm
);
4730 case 0: /* inc Ev */
4735 gen_inc(s
, ot
, opreg
, 1);
4737 case 1: /* dec Ev */
4742 gen_inc(s
, ot
, opreg
, -1);
4744 case 2: /* call Ev */
4745 /* XXX: optimize if memory (no 'and' is necessary) */
4747 gen_op_andl_T0_ffff();
4748 next_eip
= s
->pc
- s
->cs_base
;
4749 gen_movtl_T1_im(next_eip
);
4754 case 3: /* lcall Ev */
4755 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4756 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4757 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4759 if (s
->pe
&& !s
->vm86
) {
4760 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4761 gen_op_set_cc_op(s
->cc_op
);
4762 gen_jmp_im(pc_start
- s
->cs_base
);
4763 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4764 gen_helper_lcall_protected(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4765 tcg_const_i32(dflag
),
4766 tcg_const_i32(s
->pc
- pc_start
));
4768 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4769 gen_helper_lcall_real(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4770 tcg_const_i32(dflag
),
4771 tcg_const_i32(s
->pc
- s
->cs_base
));
4775 case 4: /* jmp Ev */
4777 gen_op_andl_T0_ffff();
4781 case 5: /* ljmp Ev */
4782 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4783 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4784 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4786 if (s
->pe
&& !s
->vm86
) {
4787 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4788 gen_op_set_cc_op(s
->cc_op
);
4789 gen_jmp_im(pc_start
- s
->cs_base
);
4790 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4791 gen_helper_ljmp_protected(cpu_env
, cpu_tmp2_i32
, cpu_T
[1],
4792 tcg_const_i32(s
->pc
- pc_start
));
4794 gen_op_movl_seg_T0_vm(R_CS
);
4795 gen_op_movl_T0_T1();
4800 case 6: /* push Ev */
4808 case 0x84: /* test Ev, Gv */
4813 ot
= dflag
+ OT_WORD
;
4815 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4816 reg
= ((modrm
>> 3) & 7) | rex_r
;
4818 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4819 gen_op_mov_TN_reg(ot
, 1, reg
);
4820 gen_op_testl_T0_T1_cc();
4821 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4824 case 0xa8: /* test eAX, Iv */
4829 ot
= dflag
+ OT_WORD
;
4830 val
= insn_get(s
, ot
);
4832 gen_op_mov_TN_reg(ot
, 0, OR_EAX
);
4833 gen_op_movl_T1_im(val
);
4834 gen_op_testl_T0_T1_cc();
4835 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4838 case 0x98: /* CWDE/CBW */
4839 #ifdef TARGET_X86_64
4841 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4842 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4843 gen_op_mov_reg_T0(OT_QUAD
, R_EAX
);
4847 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4848 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4849 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4851 gen_op_mov_TN_reg(OT_BYTE
, 0, R_EAX
);
4852 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4853 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4856 case 0x99: /* CDQ/CWD */
4857 #ifdef TARGET_X86_64
4859 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
4860 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 63);
4861 gen_op_mov_reg_T0(OT_QUAD
, R_EDX
);
4865 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4866 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4867 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 31);
4868 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4870 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4871 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4872 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 15);
4873 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4876 case 0x1af: /* imul Gv, Ev */
4877 case 0x69: /* imul Gv, Ev, I */
4879 ot
= dflag
+ OT_WORD
;
4880 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4881 reg
= ((modrm
>> 3) & 7) | rex_r
;
4883 s
->rip_offset
= insn_const_size(ot
);
4886 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4888 val
= insn_get(s
, ot
);
4889 gen_op_movl_T1_im(val
);
4890 } else if (b
== 0x6b) {
4891 val
= (int8_t)insn_get(s
, OT_BYTE
);
4892 gen_op_movl_T1_im(val
);
4894 gen_op_mov_TN_reg(ot
, 1, reg
);
4897 #ifdef TARGET_X86_64
4898 if (ot
== OT_QUAD
) {
4899 gen_helper_imulq_T0_T1(cpu_T
[0], cpu_env
, cpu_T
[0], cpu_T
[1]);
4902 if (ot
== OT_LONG
) {
4903 #ifdef TARGET_X86_64
4904 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4905 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4906 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4907 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4908 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4909 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4913 t0
= tcg_temp_new_i64();
4914 t1
= tcg_temp_new_i64();
4915 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4916 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4917 tcg_gen_mul_i64(t0
, t0
, t1
);
4918 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4919 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4920 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4921 tcg_gen_shri_i64(t0
, t0
, 32);
4922 tcg_gen_trunc_i64_i32(cpu_T
[1], t0
);
4923 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[1], cpu_tmp0
);
4927 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4928 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4929 /* XXX: use 32 bit mul which could be faster */
4930 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4931 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4932 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4933 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4935 gen_op_mov_reg_T0(ot
, reg
);
4936 s
->cc_op
= CC_OP_MULB
+ ot
;
4939 case 0x1c1: /* xadd Ev, Gv */
4943 ot
= dflag
+ OT_WORD
;
4944 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4945 reg
= ((modrm
>> 3) & 7) | rex_r
;
4946 mod
= (modrm
>> 6) & 3;
4948 rm
= (modrm
& 7) | REX_B(s
);
4949 gen_op_mov_TN_reg(ot
, 0, reg
);
4950 gen_op_mov_TN_reg(ot
, 1, rm
);
4951 gen_op_addl_T0_T1();
4952 gen_op_mov_reg_T1(ot
, reg
);
4953 gen_op_mov_reg_T0(ot
, rm
);
4955 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4956 gen_op_mov_TN_reg(ot
, 0, reg
);
4957 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4958 gen_op_addl_T0_T1();
4959 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4960 gen_op_mov_reg_T1(ot
, reg
);
4962 gen_op_update2_cc();
4963 s
->cc_op
= CC_OP_ADDB
+ ot
;
4966 case 0x1b1: /* cmpxchg Ev, Gv */
4969 TCGv t0
, t1
, t2
, a0
;
4974 ot
= dflag
+ OT_WORD
;
4975 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
4976 reg
= ((modrm
>> 3) & 7) | rex_r
;
4977 mod
= (modrm
>> 6) & 3;
4978 t0
= tcg_temp_local_new();
4979 t1
= tcg_temp_local_new();
4980 t2
= tcg_temp_local_new();
4981 a0
= tcg_temp_local_new();
4982 gen_op_mov_v_reg(ot
, t1
, reg
);
4984 rm
= (modrm
& 7) | REX_B(s
);
4985 gen_op_mov_v_reg(ot
, t0
, rm
);
4987 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4988 tcg_gen_mov_tl(a0
, cpu_A0
);
4989 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
4990 rm
= 0; /* avoid warning */
4992 label1
= gen_new_label();
4993 tcg_gen_sub_tl(t2
, cpu_regs
[R_EAX
], t0
);
4995 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
4996 label2
= gen_new_label();
4998 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
5000 gen_set_label(label1
);
5001 gen_op_mov_reg_v(ot
, rm
, t1
);
5003 /* perform no-op store cycle like physical cpu; must be
5004 before changing accumulator to ensure idempotency if
5005 the store faults and the instruction is restarted */
5006 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
5007 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
5009 gen_set_label(label1
);
5010 gen_op_st_v(ot
+ s
->mem_index
, t1
, a0
);
5012 gen_set_label(label2
);
5013 tcg_gen_mov_tl(cpu_cc_src
, t0
);
5014 tcg_gen_mov_tl(cpu_cc_dst
, t2
);
5015 s
->cc_op
= CC_OP_SUBB
+ ot
;
5022 case 0x1c7: /* cmpxchg8b */
5023 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5024 mod
= (modrm
>> 6) & 3;
5025 if ((mod
== 3) || ((modrm
& 0x38) != 0x8))
5027 #ifdef TARGET_X86_64
5029 if (!(s
->cpuid_ext_features
& CPUID_EXT_CX16
))
5031 gen_jmp_im(pc_start
- s
->cs_base
);
5032 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5033 gen_op_set_cc_op(s
->cc_op
);
5034 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5035 gen_helper_cmpxchg16b(cpu_env
, cpu_A0
);
5039 if (!(s
->cpuid_features
& CPUID_CX8
))
5041 gen_jmp_im(pc_start
- s
->cs_base
);
5042 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5043 gen_op_set_cc_op(s
->cc_op
);
5044 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5045 gen_helper_cmpxchg8b(cpu_env
, cpu_A0
);
5047 s
->cc_op
= CC_OP_EFLAGS
;
5050 /**************************/
5052 case 0x50 ... 0x57: /* push */
5053 gen_op_mov_TN_reg(OT_LONG
, 0, (b
& 7) | REX_B(s
));
5056 case 0x58 ... 0x5f: /* pop */
5058 ot
= dflag
? OT_QUAD
: OT_WORD
;
5060 ot
= dflag
+ OT_WORD
;
5063 /* NOTE: order is important for pop %sp */
5065 gen_op_mov_reg_T0(ot
, (b
& 7) | REX_B(s
));
5067 case 0x60: /* pusha */
5072 case 0x61: /* popa */
5077 case 0x68: /* push Iv */
5080 ot
= dflag
? OT_QUAD
: OT_WORD
;
5082 ot
= dflag
+ OT_WORD
;
5085 val
= insn_get(s
, ot
);
5087 val
= (int8_t)insn_get(s
, OT_BYTE
);
5088 gen_op_movl_T0_im(val
);
5091 case 0x8f: /* pop Ev */
5093 ot
= dflag
? OT_QUAD
: OT_WORD
;
5095 ot
= dflag
+ OT_WORD
;
5097 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5098 mod
= (modrm
>> 6) & 3;
5101 /* NOTE: order is important for pop %sp */
5103 rm
= (modrm
& 7) | REX_B(s
);
5104 gen_op_mov_reg_T0(ot
, rm
);
5106 /* NOTE: order is important too for MMU exceptions */
5107 s
->popl_esp_hack
= 1 << ot
;
5108 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5109 s
->popl_esp_hack
= 0;
5113 case 0xc8: /* enter */
5116 val
= cpu_lduw_code(cpu_single_env
, s
->pc
);
5118 level
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5119 gen_enter(s
, val
, level
);
5122 case 0xc9: /* leave */
5123 /* XXX: exception not precise (ESP is updated before potential exception) */
5125 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EBP
);
5126 gen_op_mov_reg_T0(OT_QUAD
, R_ESP
);
5127 } else if (s
->ss32
) {
5128 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
5129 gen_op_mov_reg_T0(OT_LONG
, R_ESP
);
5131 gen_op_mov_TN_reg(OT_WORD
, 0, R_EBP
);
5132 gen_op_mov_reg_T0(OT_WORD
, R_ESP
);
5136 ot
= dflag
? OT_QUAD
: OT_WORD
;
5138 ot
= dflag
+ OT_WORD
;
5140 gen_op_mov_reg_T0(ot
, R_EBP
);
5143 case 0x06: /* push es */
5144 case 0x0e: /* push cs */
5145 case 0x16: /* push ss */
5146 case 0x1e: /* push ds */
5149 gen_op_movl_T0_seg(b
>> 3);
5152 case 0x1a0: /* push fs */
5153 case 0x1a8: /* push gs */
5154 gen_op_movl_T0_seg((b
>> 3) & 7);
5157 case 0x07: /* pop es */
5158 case 0x17: /* pop ss */
5159 case 0x1f: /* pop ds */
5164 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5167 /* if reg == SS, inhibit interrupts/trace. */
5168 /* If several instructions disable interrupts, only the
5170 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5171 gen_helper_set_inhibit_irq(cpu_env
);
5175 gen_jmp_im(s
->pc
- s
->cs_base
);
5179 case 0x1a1: /* pop fs */
5180 case 0x1a9: /* pop gs */
5182 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
5185 gen_jmp_im(s
->pc
- s
->cs_base
);
5190 /**************************/
5193 case 0x89: /* mov Gv, Ev */
5197 ot
= dflag
+ OT_WORD
;
5198 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5199 reg
= ((modrm
>> 3) & 7) | rex_r
;
5201 /* generate a generic store */
5202 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
5205 case 0xc7: /* mov Ev, Iv */
5209 ot
= dflag
+ OT_WORD
;
5210 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5211 mod
= (modrm
>> 6) & 3;
5213 s
->rip_offset
= insn_const_size(ot
);
5214 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5216 val
= insn_get(s
, ot
);
5217 gen_op_movl_T0_im(val
);
5219 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5221 gen_op_mov_reg_T0(ot
, (modrm
& 7) | REX_B(s
));
5224 case 0x8b: /* mov Ev, Gv */
5228 ot
= OT_WORD
+ dflag
;
5229 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5230 reg
= ((modrm
>> 3) & 7) | rex_r
;
5232 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5233 gen_op_mov_reg_T0(ot
, reg
);
5235 case 0x8e: /* mov seg, Gv */
5236 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5237 reg
= (modrm
>> 3) & 7;
5238 if (reg
>= 6 || reg
== R_CS
)
5240 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5241 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5243 /* if reg == SS, inhibit interrupts/trace */
5244 /* If several instructions disable interrupts, only the
5246 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5247 gen_helper_set_inhibit_irq(cpu_env
);
5251 gen_jmp_im(s
->pc
- s
->cs_base
);
5255 case 0x8c: /* mov Gv, seg */
5256 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5257 reg
= (modrm
>> 3) & 7;
5258 mod
= (modrm
>> 6) & 3;
5261 gen_op_movl_T0_seg(reg
);
5263 ot
= OT_WORD
+ dflag
;
5266 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5269 case 0x1b6: /* movzbS Gv, Eb */
5270 case 0x1b7: /* movzwS Gv, Eb */
5271 case 0x1be: /* movsbS Gv, Eb */
5272 case 0x1bf: /* movswS Gv, Eb */
5275 /* d_ot is the size of destination */
5276 d_ot
= dflag
+ OT_WORD
;
5277 /* ot is the size of source */
5278 ot
= (b
& 1) + OT_BYTE
;
5279 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5280 reg
= ((modrm
>> 3) & 7) | rex_r
;
5281 mod
= (modrm
>> 6) & 3;
5282 rm
= (modrm
& 7) | REX_B(s
);
5285 gen_op_mov_TN_reg(ot
, 0, rm
);
5286 switch(ot
| (b
& 8)) {
5288 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
5291 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
5294 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
5298 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
5301 gen_op_mov_reg_T0(d_ot
, reg
);
5303 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5305 gen_op_lds_T0_A0(ot
+ s
->mem_index
);
5307 gen_op_ldu_T0_A0(ot
+ s
->mem_index
);
5309 gen_op_mov_reg_T0(d_ot
, reg
);
5314 case 0x8d: /* lea */
5315 ot
= dflag
+ OT_WORD
;
5316 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5317 mod
= (modrm
>> 6) & 3;
5320 reg
= ((modrm
>> 3) & 7) | rex_r
;
5321 /* we must ensure that no segment is added */
5325 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5327 gen_op_mov_reg_A0(ot
- OT_WORD
, reg
);
5330 case 0xa0: /* mov EAX, Ov */
5332 case 0xa2: /* mov Ov, EAX */
5335 target_ulong offset_addr
;
5340 ot
= dflag
+ OT_WORD
;
5341 #ifdef TARGET_X86_64
5342 if (s
->aflag
== 2) {
5343 offset_addr
= cpu_ldq_code(cpu_single_env
, s
->pc
);
5345 gen_op_movq_A0_im(offset_addr
);
5350 offset_addr
= insn_get(s
, OT_LONG
);
5352 offset_addr
= insn_get(s
, OT_WORD
);
5354 gen_op_movl_A0_im(offset_addr
);
5356 gen_add_A0_ds_seg(s
);
5358 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
5359 gen_op_mov_reg_T0(ot
, R_EAX
);
5361 gen_op_mov_TN_reg(ot
, 0, R_EAX
);
5362 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5366 case 0xd7: /* xlat */
5367 #ifdef TARGET_X86_64
5368 if (s
->aflag
== 2) {
5369 gen_op_movq_A0_reg(R_EBX
);
5370 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
5371 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5372 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5376 gen_op_movl_A0_reg(R_EBX
);
5377 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
5378 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5379 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5381 gen_op_andl_A0_ffff();
5383 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
5385 gen_add_A0_ds_seg(s
);
5386 gen_op_ldu_T0_A0(OT_BYTE
+ s
->mem_index
);
5387 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
5389 case 0xb0 ... 0xb7: /* mov R, Ib */
5390 val
= insn_get(s
, OT_BYTE
);
5391 gen_op_movl_T0_im(val
);
5392 gen_op_mov_reg_T0(OT_BYTE
, (b
& 7) | REX_B(s
));
5394 case 0xb8 ... 0xbf: /* mov R, Iv */
5395 #ifdef TARGET_X86_64
5399 tmp
= cpu_ldq_code(cpu_single_env
, s
->pc
);
5401 reg
= (b
& 7) | REX_B(s
);
5402 gen_movtl_T0_im(tmp
);
5403 gen_op_mov_reg_T0(OT_QUAD
, reg
);
5407 ot
= dflag
? OT_LONG
: OT_WORD
;
5408 val
= insn_get(s
, ot
);
5409 reg
= (b
& 7) | REX_B(s
);
5410 gen_op_movl_T0_im(val
);
5411 gen_op_mov_reg_T0(ot
, reg
);
5415 case 0x91 ... 0x97: /* xchg R, EAX */
5417 ot
= dflag
+ OT_WORD
;
5418 reg
= (b
& 7) | REX_B(s
);
5422 case 0x87: /* xchg Ev, Gv */
5426 ot
= dflag
+ OT_WORD
;
5427 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5428 reg
= ((modrm
>> 3) & 7) | rex_r
;
5429 mod
= (modrm
>> 6) & 3;
5431 rm
= (modrm
& 7) | REX_B(s
);
5433 gen_op_mov_TN_reg(ot
, 0, reg
);
5434 gen_op_mov_TN_reg(ot
, 1, rm
);
5435 gen_op_mov_reg_T0(ot
, rm
);
5436 gen_op_mov_reg_T1(ot
, reg
);
5438 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5439 gen_op_mov_TN_reg(ot
, 0, reg
);
5440 /* for xchg, lock is implicit */
5441 if (!(prefixes
& PREFIX_LOCK
))
5443 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5444 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5445 if (!(prefixes
& PREFIX_LOCK
))
5446 gen_helper_unlock();
5447 gen_op_mov_reg_T1(ot
, reg
);
5450 case 0xc4: /* les Gv */
5455 case 0xc5: /* lds Gv */
5460 case 0x1b2: /* lss Gv */
5463 case 0x1b4: /* lfs Gv */
5466 case 0x1b5: /* lgs Gv */
5469 ot
= dflag
? OT_LONG
: OT_WORD
;
5470 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5471 reg
= ((modrm
>> 3) & 7) | rex_r
;
5472 mod
= (modrm
>> 6) & 3;
5475 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5476 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5477 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
5478 /* load the segment first to handle exceptions properly */
5479 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
5480 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
5481 /* then put the data */
5482 gen_op_mov_reg_T1(ot
, reg
);
5484 gen_jmp_im(s
->pc
- s
->cs_base
);
5489 /************************/
5500 ot
= dflag
+ OT_WORD
;
5502 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5503 mod
= (modrm
>> 6) & 3;
5504 op
= (modrm
>> 3) & 7;
5510 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5513 opreg
= (modrm
& 7) | REX_B(s
);
5518 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
5521 shift
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5523 gen_shifti(s
, op
, ot
, opreg
, shift
);
5538 case 0x1a4: /* shld imm */
5542 case 0x1a5: /* shld cl */
5546 case 0x1ac: /* shrd imm */
5550 case 0x1ad: /* shrd cl */
5554 ot
= dflag
+ OT_WORD
;
5555 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5556 mod
= (modrm
>> 6) & 3;
5557 rm
= (modrm
& 7) | REX_B(s
);
5558 reg
= ((modrm
>> 3) & 7) | rex_r
;
5560 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5565 gen_op_mov_TN_reg(ot
, 1, reg
);
5568 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5569 tcg_gen_movi_tl(cpu_T3
, val
);
5571 tcg_gen_mov_tl(cpu_T3
, cpu_regs
[R_ECX
]);
5573 gen_shiftd_rm_T1_T3(s
, ot
, opreg
, op
);
5576 /************************/
5579 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
5580 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
5581 /* XXX: what to do if illegal op ? */
5582 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5585 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
5586 mod
= (modrm
>> 6) & 3;
5588 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
5591 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5593 case 0x00 ... 0x07: /* fxxxs */
5594 case 0x10 ... 0x17: /* fixxxl */
5595 case 0x20 ... 0x27: /* fxxxl */
5596 case 0x30 ... 0x37: /* fixxx */
5603 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5604 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5605 gen_helper_flds_FT0(cpu_env
, cpu_tmp2_i32
);
5608 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5609 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5610 gen_helper_fildl_FT0(cpu_env
, cpu_tmp2_i32
);
5613 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5614 (s
->mem_index
>> 2) - 1);
5615 gen_helper_fldl_FT0(cpu_env
, cpu_tmp1_i64
);
5619 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5620 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5621 gen_helper_fildl_FT0(cpu_env
, cpu_tmp2_i32
);
5625 gen_helper_fp_arith_ST0_FT0(op1
);
5627 /* fcomp needs pop */
5628 gen_helper_fpop(cpu_env
);
5632 case 0x08: /* flds */
5633 case 0x0a: /* fsts */
5634 case 0x0b: /* fstps */
5635 case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
5636 case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
5637 case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
5642 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5643 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5644 gen_helper_flds_ST0(cpu_env
, cpu_tmp2_i32
);
5647 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5648 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5649 gen_helper_fildl_ST0(cpu_env
, cpu_tmp2_i32
);
5652 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5653 (s
->mem_index
>> 2) - 1);
5654 gen_helper_fldl_ST0(cpu_env
, cpu_tmp1_i64
);
5658 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5659 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5660 gen_helper_fildl_ST0(cpu_env
, cpu_tmp2_i32
);
5665 /* XXX: the corresponding CPUID bit must be tested ! */
5668 gen_helper_fisttl_ST0(cpu_tmp2_i32
, cpu_env
);
5669 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5670 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5673 gen_helper_fisttll_ST0(cpu_tmp1_i64
, cpu_env
);
5674 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5675 (s
->mem_index
>> 2) - 1);
5679 gen_helper_fistt_ST0(cpu_tmp2_i32
, cpu_env
);
5680 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5681 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5684 gen_helper_fpop(cpu_env
);
5689 gen_helper_fsts_ST0(cpu_tmp2_i32
, cpu_env
);
5690 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5691 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5694 gen_helper_fistl_ST0(cpu_tmp2_i32
, cpu_env
);
5695 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5696 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5699 gen_helper_fstl_ST0(cpu_tmp1_i64
, cpu_env
);
5700 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5701 (s
->mem_index
>> 2) - 1);
5705 gen_helper_fist_ST0(cpu_tmp2_i32
, cpu_env
);
5706 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5707 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5711 gen_helper_fpop(cpu_env
);
5715 case 0x0c: /* fldenv mem */
5716 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5717 gen_op_set_cc_op(s
->cc_op
);
5718 gen_jmp_im(pc_start
- s
->cs_base
);
5719 gen_helper_fldenv(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5721 case 0x0d: /* fldcw mem */
5722 gen_op_ld_T0_A0(OT_WORD
+ s
->mem_index
);
5723 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5724 gen_helper_fldcw(cpu_env
, cpu_tmp2_i32
);
5726 case 0x0e: /* fnstenv mem */
5727 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5728 gen_op_set_cc_op(s
->cc_op
);
5729 gen_jmp_im(pc_start
- s
->cs_base
);
5730 gen_helper_fstenv(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5732 case 0x0f: /* fnstcw mem */
5733 gen_helper_fnstcw(cpu_tmp2_i32
, cpu_env
);
5734 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5735 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5737 case 0x1d: /* fldt mem */
5738 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5739 gen_op_set_cc_op(s
->cc_op
);
5740 gen_jmp_im(pc_start
- s
->cs_base
);
5741 gen_helper_fldt_ST0(cpu_env
, cpu_A0
);
5743 case 0x1f: /* fstpt mem */
5744 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5745 gen_op_set_cc_op(s
->cc_op
);
5746 gen_jmp_im(pc_start
- s
->cs_base
);
5747 gen_helper_fstt_ST0(cpu_env
, cpu_A0
);
5748 gen_helper_fpop(cpu_env
);
5750 case 0x2c: /* frstor mem */
5751 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5752 gen_op_set_cc_op(s
->cc_op
);
5753 gen_jmp_im(pc_start
- s
->cs_base
);
5754 gen_helper_frstor(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5756 case 0x2e: /* fnsave mem */
5757 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5758 gen_op_set_cc_op(s
->cc_op
);
5759 gen_jmp_im(pc_start
- s
->cs_base
);
5760 gen_helper_fsave(cpu_env
, cpu_A0
, tcg_const_i32(s
->dflag
));
5762 case 0x2f: /* fnstsw mem */
5763 gen_helper_fnstsw(cpu_tmp2_i32
, cpu_env
);
5764 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5765 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5767 case 0x3c: /* fbld */
5768 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5769 gen_op_set_cc_op(s
->cc_op
);
5770 gen_jmp_im(pc_start
- s
->cs_base
);
5771 gen_helper_fbld_ST0(cpu_env
, cpu_A0
);
5773 case 0x3e: /* fbstp */
5774 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5775 gen_op_set_cc_op(s
->cc_op
);
5776 gen_jmp_im(pc_start
- s
->cs_base
);
5777 gen_helper_fbst_ST0(cpu_env
, cpu_A0
);
5778 gen_helper_fpop(cpu_env
);
5780 case 0x3d: /* fildll */
5781 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5782 (s
->mem_index
>> 2) - 1);
5783 gen_helper_fildll_ST0(cpu_env
, cpu_tmp1_i64
);
5785 case 0x3f: /* fistpll */
5786 gen_helper_fistll_ST0(cpu_tmp1_i64
, cpu_env
);
5787 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5788 (s
->mem_index
>> 2) - 1);
5789 gen_helper_fpop(cpu_env
);
5795 /* register float ops */
5799 case 0x08: /* fld sti */
5800 gen_helper_fpush(cpu_env
);
5801 gen_helper_fmov_ST0_STN(cpu_env
,
5802 tcg_const_i32((opreg
+ 1) & 7));
5804 case 0x09: /* fxchg sti */
5805 case 0x29: /* fxchg4 sti, undocumented op */
5806 case 0x39: /* fxchg7 sti, undocumented op */
5807 gen_helper_fxchg_ST0_STN(cpu_env
, tcg_const_i32(opreg
));
5809 case 0x0a: /* grp d9/2 */
5812 /* check exceptions (FreeBSD FPU probe) */
5813 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5814 gen_op_set_cc_op(s
->cc_op
);
5815 gen_jmp_im(pc_start
- s
->cs_base
);
5816 gen_helper_fwait(cpu_env
);
5822 case 0x0c: /* grp d9/4 */
5825 gen_helper_fchs_ST0(cpu_env
);
5828 gen_helper_fabs_ST0(cpu_env
);
5831 gen_helper_fldz_FT0(cpu_env
);
5832 gen_helper_fcom_ST0_FT0(cpu_env
);
5835 gen_helper_fxam_ST0(cpu_env
);
5841 case 0x0d: /* grp d9/5 */
5845 gen_helper_fpush(cpu_env
);
5846 gen_helper_fld1_ST0(cpu_env
);
5849 gen_helper_fpush(cpu_env
);
5850 gen_helper_fldl2t_ST0(cpu_env
);
5853 gen_helper_fpush(cpu_env
);
5854 gen_helper_fldl2e_ST0(cpu_env
);
5857 gen_helper_fpush(cpu_env
);
5858 gen_helper_fldpi_ST0(cpu_env
);
5861 gen_helper_fpush(cpu_env
);
5862 gen_helper_fldlg2_ST0(cpu_env
);
5865 gen_helper_fpush(cpu_env
);
5866 gen_helper_fldln2_ST0(cpu_env
);
5869 gen_helper_fpush(cpu_env
);
5870 gen_helper_fldz_ST0(cpu_env
);
5877 case 0x0e: /* grp d9/6 */
5880 gen_helper_f2xm1(cpu_env
);
5883 gen_helper_fyl2x(cpu_env
);
5886 gen_helper_fptan(cpu_env
);
5888 case 3: /* fpatan */
5889 gen_helper_fpatan(cpu_env
);
5891 case 4: /* fxtract */
5892 gen_helper_fxtract(cpu_env
);
5894 case 5: /* fprem1 */
5895 gen_helper_fprem1(cpu_env
);
5897 case 6: /* fdecstp */
5898 gen_helper_fdecstp(cpu_env
);
5901 case 7: /* fincstp */
5902 gen_helper_fincstp(cpu_env
);
5906 case 0x0f: /* grp d9/7 */
5909 gen_helper_fprem(cpu_env
);
5911 case 1: /* fyl2xp1 */
5912 gen_helper_fyl2xp1(cpu_env
);
5915 gen_helper_fsqrt(cpu_env
);
5917 case 3: /* fsincos */
5918 gen_helper_fsincos(cpu_env
);
5920 case 5: /* fscale */
5921 gen_helper_fscale(cpu_env
);
5923 case 4: /* frndint */
5924 gen_helper_frndint(cpu_env
);
5927 gen_helper_fsin(cpu_env
);
5931 gen_helper_fcos(cpu_env
);
5935 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
5936 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
5937 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
5943 gen_helper_fp_arith_STN_ST0(op1
, opreg
);
5945 gen_helper_fpop(cpu_env
);
5947 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5948 gen_helper_fp_arith_ST0_FT0(op1
);
5952 case 0x02: /* fcom */
5953 case 0x22: /* fcom2, undocumented op */
5954 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5955 gen_helper_fcom_ST0_FT0(cpu_env
);
5957 case 0x03: /* fcomp */
5958 case 0x23: /* fcomp3, undocumented op */
5959 case 0x32: /* fcomp5, undocumented op */
5960 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5961 gen_helper_fcom_ST0_FT0(cpu_env
);
5962 gen_helper_fpop(cpu_env
);
5964 case 0x15: /* da/5 */
5966 case 1: /* fucompp */
5967 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(1));
5968 gen_helper_fucom_ST0_FT0(cpu_env
);
5969 gen_helper_fpop(cpu_env
);
5970 gen_helper_fpop(cpu_env
);
5978 case 0: /* feni (287 only, just do nop here) */
5980 case 1: /* fdisi (287 only, just do nop here) */
5983 gen_helper_fclex(cpu_env
);
5985 case 3: /* fninit */
5986 gen_helper_fninit(cpu_env
);
5988 case 4: /* fsetpm (287 only, just do nop here) */
5994 case 0x1d: /* fucomi */
5995 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5996 gen_op_set_cc_op(s
->cc_op
);
5997 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
5998 gen_helper_fucomi_ST0_FT0(cpu_env
);
5999 s
->cc_op
= CC_OP_EFLAGS
;
6001 case 0x1e: /* fcomi */
6002 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6003 gen_op_set_cc_op(s
->cc_op
);
6004 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6005 gen_helper_fcomi_ST0_FT0(cpu_env
);
6006 s
->cc_op
= CC_OP_EFLAGS
;
6008 case 0x28: /* ffree sti */
6009 gen_helper_ffree_STN(cpu_env
, tcg_const_i32(opreg
));
6011 case 0x2a: /* fst sti */
6012 gen_helper_fmov_STN_ST0(cpu_env
, tcg_const_i32(opreg
));
6014 case 0x2b: /* fstp sti */
6015 case 0x0b: /* fstp1 sti, undocumented op */
6016 case 0x3a: /* fstp8 sti, undocumented op */
6017 case 0x3b: /* fstp9 sti, undocumented op */
6018 gen_helper_fmov_STN_ST0(cpu_env
, tcg_const_i32(opreg
));
6019 gen_helper_fpop(cpu_env
);
6021 case 0x2c: /* fucom st(i) */
6022 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6023 gen_helper_fucom_ST0_FT0(cpu_env
);
6025 case 0x2d: /* fucomp st(i) */
6026 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6027 gen_helper_fucom_ST0_FT0(cpu_env
);
6028 gen_helper_fpop(cpu_env
);
6030 case 0x33: /* de/3 */
6032 case 1: /* fcompp */
6033 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(1));
6034 gen_helper_fcom_ST0_FT0(cpu_env
);
6035 gen_helper_fpop(cpu_env
);
6036 gen_helper_fpop(cpu_env
);
6042 case 0x38: /* ffreep sti, undocumented op */
6043 gen_helper_ffree_STN(cpu_env
, tcg_const_i32(opreg
));
6044 gen_helper_fpop(cpu_env
);
6046 case 0x3c: /* df/4 */
6049 gen_helper_fnstsw(cpu_tmp2_i32
, cpu_env
);
6050 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
6051 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
6057 case 0x3d: /* fucomip */
6058 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6059 gen_op_set_cc_op(s
->cc_op
);
6060 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6061 gen_helper_fucomi_ST0_FT0(cpu_env
);
6062 gen_helper_fpop(cpu_env
);
6063 s
->cc_op
= CC_OP_EFLAGS
;
6065 case 0x3e: /* fcomip */
6066 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6067 gen_op_set_cc_op(s
->cc_op
);
6068 gen_helper_fmov_FT0_STN(cpu_env
, tcg_const_i32(opreg
));
6069 gen_helper_fcomi_ST0_FT0(cpu_env
);
6070 gen_helper_fpop(cpu_env
);
6071 s
->cc_op
= CC_OP_EFLAGS
;
6073 case 0x10 ... 0x13: /* fcmovxx */
6077 static const uint8_t fcmov_cc
[8] = {
6083 op1
= fcmov_cc
[op
& 3] | (((op
>> 3) & 1) ^ 1);
6084 l1
= gen_new_label();
6085 gen_jcc1(s
, s
->cc_op
, op1
, l1
);
6086 gen_helper_fmov_ST0_STN(cpu_env
, tcg_const_i32(opreg
));
6095 /************************/
6098 case 0xa4: /* movsS */
6103 ot
= dflag
+ OT_WORD
;
6105 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6106 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6112 case 0xaa: /* stosS */
6117 ot
= dflag
+ OT_WORD
;
6119 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6120 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6125 case 0xac: /* lodsS */
6130 ot
= dflag
+ OT_WORD
;
6131 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6132 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6137 case 0xae: /* scasS */
6142 ot
= dflag
+ OT_WORD
;
6143 if (prefixes
& PREFIX_REPNZ
) {
6144 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6145 } else if (prefixes
& PREFIX_REPZ
) {
6146 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6149 s
->cc_op
= CC_OP_SUBB
+ ot
;
6153 case 0xa6: /* cmpsS */
6158 ot
= dflag
+ OT_WORD
;
6159 if (prefixes
& PREFIX_REPNZ
) {
6160 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6161 } else if (prefixes
& PREFIX_REPZ
) {
6162 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6165 s
->cc_op
= CC_OP_SUBB
+ ot
;
6168 case 0x6c: /* insS */
6173 ot
= dflag
? OT_LONG
: OT_WORD
;
6174 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6175 gen_op_andl_T0_ffff();
6176 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6177 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
) | 4);
6178 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6179 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6183 gen_jmp(s
, s
->pc
- s
->cs_base
);
6187 case 0x6e: /* outsS */
6192 ot
= dflag
? OT_LONG
: OT_WORD
;
6193 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6194 gen_op_andl_T0_ffff();
6195 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6196 svm_is_rep(prefixes
) | 4);
6197 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6198 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6202 gen_jmp(s
, s
->pc
- s
->cs_base
);
6207 /************************/
6215 ot
= dflag
? OT_LONG
: OT_WORD
;
6216 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6217 gen_op_movl_T0_im(val
);
6218 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6219 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6222 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6223 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6224 gen_op_mov_reg_T1(ot
, R_EAX
);
6227 gen_jmp(s
, s
->pc
- s
->cs_base
);
6235 ot
= dflag
? OT_LONG
: OT_WORD
;
6236 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6237 gen_op_movl_T0_im(val
);
6238 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6239 svm_is_rep(prefixes
));
6240 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6244 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6245 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6246 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6249 gen_jmp(s
, s
->pc
- s
->cs_base
);
6257 ot
= dflag
? OT_LONG
: OT_WORD
;
6258 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6259 gen_op_andl_T0_ffff();
6260 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6261 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6264 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6265 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6266 gen_op_mov_reg_T1(ot
, R_EAX
);
6269 gen_jmp(s
, s
->pc
- s
->cs_base
);
6277 ot
= dflag
? OT_LONG
: OT_WORD
;
6278 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6279 gen_op_andl_T0_ffff();
6280 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6281 svm_is_rep(prefixes
));
6282 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6286 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6287 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6288 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6291 gen_jmp(s
, s
->pc
- s
->cs_base
);
6295 /************************/
6297 case 0xc2: /* ret im */
6298 val
= cpu_ldsw_code(cpu_single_env
, s
->pc
);
6301 if (CODE64(s
) && s
->dflag
)
6303 gen_stack_update(s
, val
+ (2 << s
->dflag
));
6305 gen_op_andl_T0_ffff();
6309 case 0xc3: /* ret */
6313 gen_op_andl_T0_ffff();
6317 case 0xca: /* lret im */
6318 val
= cpu_ldsw_code(cpu_single_env
, s
->pc
);
6321 if (s
->pe
&& !s
->vm86
) {
6322 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6323 gen_op_set_cc_op(s
->cc_op
);
6324 gen_jmp_im(pc_start
- s
->cs_base
);
6325 gen_helper_lret_protected(cpu_env
, tcg_const_i32(s
->dflag
),
6326 tcg_const_i32(val
));
6330 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6332 gen_op_andl_T0_ffff();
6333 /* NOTE: keeping EIP updated is not a problem in case of
6337 gen_op_addl_A0_im(2 << s
->dflag
);
6338 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6339 gen_op_movl_seg_T0_vm(R_CS
);
6340 /* add stack offset */
6341 gen_stack_update(s
, val
+ (4 << s
->dflag
));
6345 case 0xcb: /* lret */
6348 case 0xcf: /* iret */
6349 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IRET
);
6352 gen_helper_iret_real(cpu_env
, tcg_const_i32(s
->dflag
));
6353 s
->cc_op
= CC_OP_EFLAGS
;
6354 } else if (s
->vm86
) {
6356 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6358 gen_helper_iret_real(cpu_env
, tcg_const_i32(s
->dflag
));
6359 s
->cc_op
= CC_OP_EFLAGS
;
6362 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6363 gen_op_set_cc_op(s
->cc_op
);
6364 gen_jmp_im(pc_start
- s
->cs_base
);
6365 gen_helper_iret_protected(cpu_env
, tcg_const_i32(s
->dflag
),
6366 tcg_const_i32(s
->pc
- s
->cs_base
));
6367 s
->cc_op
= CC_OP_EFLAGS
;
6371 case 0xe8: /* call im */
6374 tval
= (int32_t)insn_get(s
, OT_LONG
);
6376 tval
= (int16_t)insn_get(s
, OT_WORD
);
6377 next_eip
= s
->pc
- s
->cs_base
;
6383 gen_movtl_T0_im(next_eip
);
6388 case 0x9a: /* lcall im */
6390 unsigned int selector
, offset
;
6394 ot
= dflag
? OT_LONG
: OT_WORD
;
6395 offset
= insn_get(s
, ot
);
6396 selector
= insn_get(s
, OT_WORD
);
6398 gen_op_movl_T0_im(selector
);
6399 gen_op_movl_T1_imu(offset
);
6402 case 0xe9: /* jmp im */
6404 tval
= (int32_t)insn_get(s
, OT_LONG
);
6406 tval
= (int16_t)insn_get(s
, OT_WORD
);
6407 tval
+= s
->pc
- s
->cs_base
;
6414 case 0xea: /* ljmp im */
6416 unsigned int selector
, offset
;
6420 ot
= dflag
? OT_LONG
: OT_WORD
;
6421 offset
= insn_get(s
, ot
);
6422 selector
= insn_get(s
, OT_WORD
);
6424 gen_op_movl_T0_im(selector
);
6425 gen_op_movl_T1_imu(offset
);
6428 case 0xeb: /* jmp Jb */
6429 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6430 tval
+= s
->pc
- s
->cs_base
;
6435 case 0x70 ... 0x7f: /* jcc Jb */
6436 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6438 case 0x180 ... 0x18f: /* jcc Jv */
6440 tval
= (int32_t)insn_get(s
, OT_LONG
);
6442 tval
= (int16_t)insn_get(s
, OT_WORD
);
6445 next_eip
= s
->pc
- s
->cs_base
;
6449 gen_jcc(s
, b
, tval
, next_eip
);
6452 case 0x190 ... 0x19f: /* setcc Gv */
6453 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6455 gen_ldst_modrm(s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
6457 case 0x140 ... 0x14f: /* cmov Gv, Ev */
6462 ot
= dflag
+ OT_WORD
;
6463 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6464 reg
= ((modrm
>> 3) & 7) | rex_r
;
6465 mod
= (modrm
>> 6) & 3;
6466 t0
= tcg_temp_local_new();
6468 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6469 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
6471 rm
= (modrm
& 7) | REX_B(s
);
6472 gen_op_mov_v_reg(ot
, t0
, rm
);
6474 #ifdef TARGET_X86_64
6475 if (ot
== OT_LONG
) {
6476 /* XXX: specific Intel behaviour ? */
6477 l1
= gen_new_label();
6478 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6479 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
6481 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_regs
[reg
]);
6485 l1
= gen_new_label();
6486 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6487 gen_op_mov_reg_v(ot
, reg
, t0
);
6494 /************************/
6496 case 0x9c: /* pushf */
6497 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PUSHF
);
6498 if (s
->vm86
&& s
->iopl
!= 3) {
6499 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6501 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6502 gen_op_set_cc_op(s
->cc_op
);
6503 gen_helper_read_eflags(cpu_T
[0], cpu_env
);
6507 case 0x9d: /* popf */
6508 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_POPF
);
6509 if (s
->vm86
&& s
->iopl
!= 3) {
6510 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6515 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6516 tcg_const_i32((TF_MASK
| AC_MASK
|
6521 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6522 tcg_const_i32((TF_MASK
| AC_MASK
|
6524 IF_MASK
| IOPL_MASK
)
6528 if (s
->cpl
<= s
->iopl
) {
6530 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6531 tcg_const_i32((TF_MASK
|
6537 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6538 tcg_const_i32((TF_MASK
|
6547 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6548 tcg_const_i32((TF_MASK
| AC_MASK
|
6549 ID_MASK
| NT_MASK
)));
6551 gen_helper_write_eflags(cpu_env
, cpu_T
[0],
6552 tcg_const_i32((TF_MASK
| AC_MASK
|
6559 s
->cc_op
= CC_OP_EFLAGS
;
6560 /* abort translation because TF/AC flag may change */
6561 gen_jmp_im(s
->pc
- s
->cs_base
);
6565 case 0x9e: /* sahf */
6566 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6568 gen_op_mov_TN_reg(OT_BYTE
, 0, R_AH
);
6569 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6570 gen_op_set_cc_op(s
->cc_op
);
6571 gen_compute_eflags(cpu_cc_src
);
6572 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, CC_O
);
6573 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
6574 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_T
[0]);
6575 s
->cc_op
= CC_OP_EFLAGS
;
6577 case 0x9f: /* lahf */
6578 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6580 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6581 gen_op_set_cc_op(s
->cc_op
);
6582 gen_compute_eflags(cpu_T
[0]);
6583 /* Note: gen_compute_eflags() only gives the condition codes */
6584 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], 0x02);
6585 gen_op_mov_reg_T0(OT_BYTE
, R_AH
);
6587 case 0xf5: /* cmc */
6588 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6589 gen_op_set_cc_op(s
->cc_op
);
6590 gen_compute_eflags(cpu_cc_src
);
6591 tcg_gen_xori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6592 s
->cc_op
= CC_OP_EFLAGS
;
6594 case 0xf8: /* clc */
6595 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6596 gen_op_set_cc_op(s
->cc_op
);
6597 gen_compute_eflags(cpu_cc_src
);
6598 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_C
);
6599 s
->cc_op
= CC_OP_EFLAGS
;
6601 case 0xf9: /* stc */
6602 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6603 gen_op_set_cc_op(s
->cc_op
);
6604 gen_compute_eflags(cpu_cc_src
);
6605 tcg_gen_ori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6606 s
->cc_op
= CC_OP_EFLAGS
;
6608 case 0xfc: /* cld */
6609 tcg_gen_movi_i32(cpu_tmp2_i32
, 1);
6610 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUX86State
, df
));
6612 case 0xfd: /* std */
6613 tcg_gen_movi_i32(cpu_tmp2_i32
, -1);
6614 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUX86State
, df
));
6617 /************************/
6618 /* bit operations */
6619 case 0x1ba: /* bt/bts/btr/btc Gv, im */
6620 ot
= dflag
+ OT_WORD
;
6621 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6622 op
= (modrm
>> 3) & 7;
6623 mod
= (modrm
>> 6) & 3;
6624 rm
= (modrm
& 7) | REX_B(s
);
6627 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6628 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6630 gen_op_mov_TN_reg(ot
, 0, rm
);
6633 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6634 gen_op_movl_T1_im(val
);
6639 case 0x1a3: /* bt Gv, Ev */
6642 case 0x1ab: /* bts */
6645 case 0x1b3: /* btr */
6648 case 0x1bb: /* btc */
6651 ot
= dflag
+ OT_WORD
;
6652 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6653 reg
= ((modrm
>> 3) & 7) | rex_r
;
6654 mod
= (modrm
>> 6) & 3;
6655 rm
= (modrm
& 7) | REX_B(s
);
6656 gen_op_mov_TN_reg(OT_LONG
, 1, reg
);
6658 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6659 /* specific case: we need to add a displacement */
6660 gen_exts(ot
, cpu_T
[1]);
6661 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[1], 3 + ot
);
6662 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, ot
);
6663 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
6664 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6666 gen_op_mov_TN_reg(ot
, 0, rm
);
6669 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], (1 << (3 + ot
)) - 1);
6672 tcg_gen_shr_tl(cpu_cc_src
, cpu_T
[0], cpu_T
[1]);
6673 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6676 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6677 tcg_gen_movi_tl(cpu_tmp0
, 1);
6678 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6679 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6682 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6683 tcg_gen_movi_tl(cpu_tmp0
, 1);
6684 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6685 tcg_gen_not_tl(cpu_tmp0
, cpu_tmp0
);
6686 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6690 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6691 tcg_gen_movi_tl(cpu_tmp0
, 1);
6692 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6693 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6696 s
->cc_op
= CC_OP_SARB
+ ot
;
6699 gen_op_st_T0_A0(ot
+ s
->mem_index
);
6701 gen_op_mov_reg_T0(ot
, rm
);
6702 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
6703 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6706 case 0x1bc: /* bsf */
6707 case 0x1bd: /* bsr */
6712 ot
= dflag
+ OT_WORD
;
6713 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6714 reg
= ((modrm
>> 3) & 7) | rex_r
;
6715 gen_ldst_modrm(s
,modrm
, ot
, OR_TMP0
, 0);
6716 gen_extu(ot
, cpu_T
[0]);
6717 t0
= tcg_temp_local_new();
6718 tcg_gen_mov_tl(t0
, cpu_T
[0]);
6719 if ((b
& 1) && (prefixes
& PREFIX_REPZ
) &&
6720 (s
->cpuid_ext3_features
& CPUID_EXT3_ABM
)) {
6722 case OT_WORD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6723 tcg_const_i32(16)); break;
6724 case OT_LONG
: gen_helper_lzcnt(cpu_T
[0], t0
,
6725 tcg_const_i32(32)); break;
6726 case OT_QUAD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6727 tcg_const_i32(64)); break;
6729 gen_op_mov_reg_T0(ot
, reg
);
6731 label1
= gen_new_label();
6732 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6733 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, label1
);
6735 gen_helper_bsr(cpu_T
[0], t0
);
6737 gen_helper_bsf(cpu_T
[0], t0
);
6739 gen_op_mov_reg_T0(ot
, reg
);
6740 tcg_gen_movi_tl(cpu_cc_dst
, 1);
6741 gen_set_label(label1
);
6742 tcg_gen_discard_tl(cpu_cc_src
);
6743 s
->cc_op
= CC_OP_LOGICB
+ ot
;
6748 /************************/
6750 case 0x27: /* daa */
6753 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6754 gen_op_set_cc_op(s
->cc_op
);
6755 gen_helper_daa(cpu_env
);
6756 s
->cc_op
= CC_OP_EFLAGS
;
6758 case 0x2f: /* das */
6761 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6762 gen_op_set_cc_op(s
->cc_op
);
6763 gen_helper_das(cpu_env
);
6764 s
->cc_op
= CC_OP_EFLAGS
;
6766 case 0x37: /* aaa */
6769 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6770 gen_op_set_cc_op(s
->cc_op
);
6771 gen_helper_aaa(cpu_env
);
6772 s
->cc_op
= CC_OP_EFLAGS
;
6774 case 0x3f: /* aas */
6777 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6778 gen_op_set_cc_op(s
->cc_op
);
6779 gen_helper_aas(cpu_env
);
6780 s
->cc_op
= CC_OP_EFLAGS
;
6782 case 0xd4: /* aam */
6785 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6787 gen_exception(s
, EXCP00_DIVZ
, pc_start
- s
->cs_base
);
6789 gen_helper_aam(cpu_env
, tcg_const_i32(val
));
6790 s
->cc_op
= CC_OP_LOGICB
;
6793 case 0xd5: /* aad */
6796 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6797 gen_helper_aad(cpu_env
, tcg_const_i32(val
));
6798 s
->cc_op
= CC_OP_LOGICB
;
6800 /************************/
6802 case 0x90: /* nop */
6803 /* XXX: correct lock test for all insn */
6804 if (prefixes
& PREFIX_LOCK
) {
6807 /* If REX_B is set, then this is xchg eax, r8d, not a nop. */
6809 goto do_xchg_reg_eax
;
6811 if (prefixes
& PREFIX_REPZ
) {
6812 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PAUSE
);
6815 case 0x9b: /* fwait */
6816 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
6817 (HF_MP_MASK
| HF_TS_MASK
)) {
6818 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
6820 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6821 gen_op_set_cc_op(s
->cc_op
);
6822 gen_jmp_im(pc_start
- s
->cs_base
);
6823 gen_helper_fwait(cpu_env
);
6826 case 0xcc: /* int3 */
6827 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6829 case 0xcd: /* int N */
6830 val
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6831 if (s
->vm86
&& s
->iopl
!= 3) {
6832 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6834 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6837 case 0xce: /* into */
6840 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6841 gen_op_set_cc_op(s
->cc_op
);
6842 gen_jmp_im(pc_start
- s
->cs_base
);
6843 gen_helper_into(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
6846 case 0xf1: /* icebp (undocumented, exits to external debugger) */
6847 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_ICEBP
);
6849 gen_debug(s
, pc_start
- s
->cs_base
);
6852 tb_flush(cpu_single_env
);
6853 cpu_set_log(CPU_LOG_INT
| CPU_LOG_TB_IN_ASM
);
6857 case 0xfa: /* cli */
6859 if (s
->cpl
<= s
->iopl
) {
6860 gen_helper_cli(cpu_env
);
6862 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6866 gen_helper_cli(cpu_env
);
6868 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6872 case 0xfb: /* sti */
6874 if (s
->cpl
<= s
->iopl
) {
6876 gen_helper_sti(cpu_env
);
6877 /* interruptions are enabled only the first insn after sti */
6878 /* If several instructions disable interrupts, only the
6880 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
6881 gen_helper_set_inhibit_irq(cpu_env
);
6882 /* give a chance to handle pending irqs */
6883 gen_jmp_im(s
->pc
- s
->cs_base
);
6886 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6892 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6896 case 0x62: /* bound */
6899 ot
= dflag
? OT_LONG
: OT_WORD
;
6900 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
6901 reg
= (modrm
>> 3) & 7;
6902 mod
= (modrm
>> 6) & 3;
6905 gen_op_mov_TN_reg(ot
, 0, reg
);
6906 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6907 gen_jmp_im(pc_start
- s
->cs_base
);
6908 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6909 if (ot
== OT_WORD
) {
6910 gen_helper_boundw(cpu_env
, cpu_A0
, cpu_tmp2_i32
);
6912 gen_helper_boundl(cpu_env
, cpu_A0
, cpu_tmp2_i32
);
6915 case 0x1c8 ... 0x1cf: /* bswap reg */
6916 reg
= (b
& 7) | REX_B(s
);
6917 #ifdef TARGET_X86_64
6919 gen_op_mov_TN_reg(OT_QUAD
, 0, reg
);
6920 tcg_gen_bswap64_i64(cpu_T
[0], cpu_T
[0]);
6921 gen_op_mov_reg_T0(OT_QUAD
, reg
);
6925 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
6926 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
6927 tcg_gen_bswap32_tl(cpu_T
[0], cpu_T
[0]);
6928 gen_op_mov_reg_T0(OT_LONG
, reg
);
6931 case 0xd6: /* salc */
6934 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6935 gen_op_set_cc_op(s
->cc_op
);
6936 gen_compute_eflags_c(cpu_T
[0]);
6937 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
6938 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
6940 case 0xe0: /* loopnz */
6941 case 0xe1: /* loopz */
6942 case 0xe2: /* loop */
6943 case 0xe3: /* jecxz */
6947 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6948 next_eip
= s
->pc
- s
->cs_base
;
6953 l1
= gen_new_label();
6954 l2
= gen_new_label();
6955 l3
= gen_new_label();
6958 case 0: /* loopnz */
6960 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6961 gen_op_set_cc_op(s
->cc_op
);
6962 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6963 gen_op_jz_ecx(s
->aflag
, l3
);
6964 gen_compute_eflags(cpu_tmp0
);
6965 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_Z
);
6967 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, l1
);
6969 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, l1
);
6973 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6974 gen_op_jnz_ecx(s
->aflag
, l1
);
6978 gen_op_jz_ecx(s
->aflag
, l1
);
6983 gen_jmp_im(next_eip
);
6992 case 0x130: /* wrmsr */
6993 case 0x132: /* rdmsr */
6995 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6997 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6998 gen_op_set_cc_op(s
->cc_op
);
6999 gen_jmp_im(pc_start
- s
->cs_base
);
7001 gen_helper_rdmsr(cpu_env
);
7003 gen_helper_wrmsr(cpu_env
);
7007 case 0x131: /* rdtsc */
7008 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7009 gen_op_set_cc_op(s
->cc_op
);
7010 gen_jmp_im(pc_start
- s
->cs_base
);
7013 gen_helper_rdtsc(cpu_env
);
7016 gen_jmp(s
, s
->pc
- s
->cs_base
);
7019 case 0x133: /* rdpmc */
7020 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7021 gen_op_set_cc_op(s
->cc_op
);
7022 gen_jmp_im(pc_start
- s
->cs_base
);
7023 gen_helper_rdpmc(cpu_env
);
7025 case 0x134: /* sysenter */
7026 /* For Intel SYSENTER is valid on 64-bit */
7027 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
7030 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7032 gen_update_cc_op(s
);
7033 gen_jmp_im(pc_start
- s
->cs_base
);
7034 gen_helper_sysenter(cpu_env
);
7038 case 0x135: /* sysexit */
7039 /* For Intel SYSEXIT is valid on 64-bit */
7040 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
7043 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7045 gen_update_cc_op(s
);
7046 gen_jmp_im(pc_start
- s
->cs_base
);
7047 gen_helper_sysexit(cpu_env
, tcg_const_i32(dflag
));
7051 #ifdef TARGET_X86_64
7052 case 0x105: /* syscall */
7053 /* XXX: is it usable in real mode ? */
7054 gen_update_cc_op(s
);
7055 gen_jmp_im(pc_start
- s
->cs_base
);
7056 gen_helper_syscall(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7059 case 0x107: /* sysret */
7061 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7063 gen_update_cc_op(s
);
7064 gen_jmp_im(pc_start
- s
->cs_base
);
7065 gen_helper_sysret(cpu_env
, tcg_const_i32(s
->dflag
));
7066 /* condition codes are modified only in long mode */
7068 s
->cc_op
= CC_OP_EFLAGS
;
7073 case 0x1a2: /* cpuid */
7074 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7075 gen_op_set_cc_op(s
->cc_op
);
7076 gen_jmp_im(pc_start
- s
->cs_base
);
7077 gen_helper_cpuid(cpu_env
);
7079 case 0xf4: /* hlt */
7081 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7083 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7084 gen_op_set_cc_op(s
->cc_op
);
7085 gen_jmp_im(pc_start
- s
->cs_base
);
7086 gen_helper_hlt(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7087 s
->is_jmp
= DISAS_TB_JUMP
;
7091 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7092 mod
= (modrm
>> 6) & 3;
7093 op
= (modrm
>> 3) & 7;
7096 if (!s
->pe
|| s
->vm86
)
7098 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_READ
);
7099 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,ldt
.selector
));
7103 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
7106 if (!s
->pe
|| s
->vm86
)
7109 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7111 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_WRITE
);
7112 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7113 gen_jmp_im(pc_start
- s
->cs_base
);
7114 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7115 gen_helper_lldt(cpu_env
, cpu_tmp2_i32
);
7119 if (!s
->pe
|| s
->vm86
)
7121 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_READ
);
7122 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,tr
.selector
));
7126 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
7129 if (!s
->pe
|| s
->vm86
)
7132 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7134 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_WRITE
);
7135 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7136 gen_jmp_im(pc_start
- s
->cs_base
);
7137 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7138 gen_helper_ltr(cpu_env
, cpu_tmp2_i32
);
7143 if (!s
->pe
|| s
->vm86
)
7145 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7146 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7147 gen_op_set_cc_op(s
->cc_op
);
7149 gen_helper_verr(cpu_env
, cpu_T
[0]);
7151 gen_helper_verw(cpu_env
, cpu_T
[0]);
7153 s
->cc_op
= CC_OP_EFLAGS
;
7160 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7161 mod
= (modrm
>> 6) & 3;
7162 op
= (modrm
>> 3) & 7;
7168 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_GDTR_READ
);
7169 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7170 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.limit
));
7171 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7172 gen_add_A0_im(s
, 2);
7173 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.base
));
7175 gen_op_andl_T0_im(0xffffff);
7176 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7181 case 0: /* monitor */
7182 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7185 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7186 gen_op_set_cc_op(s
->cc_op
);
7187 gen_jmp_im(pc_start
- s
->cs_base
);
7188 #ifdef TARGET_X86_64
7189 if (s
->aflag
== 2) {
7190 gen_op_movq_A0_reg(R_EAX
);
7194 gen_op_movl_A0_reg(R_EAX
);
7196 gen_op_andl_A0_ffff();
7198 gen_add_A0_ds_seg(s
);
7199 gen_helper_monitor(cpu_env
, cpu_A0
);
7202 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7205 gen_update_cc_op(s
);
7206 gen_jmp_im(pc_start
- s
->cs_base
);
7207 gen_helper_mwait(cpu_env
, tcg_const_i32(s
->pc
- pc_start
));
7211 if (!(s
->cpuid_7_0_ebx_features
& CPUID_7_0_EBX_SMAP
) ||
7215 gen_helper_clac(cpu_env
);
7216 gen_jmp_im(s
->pc
- s
->cs_base
);
7220 if (!(s
->cpuid_7_0_ebx_features
& CPUID_7_0_EBX_SMAP
) ||
7224 gen_helper_stac(cpu_env
);
7225 gen_jmp_im(s
->pc
- s
->cs_base
);
7232 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IDTR_READ
);
7233 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7234 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.limit
));
7235 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7236 gen_add_A0_im(s
, 2);
7237 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.base
));
7239 gen_op_andl_T0_im(0xffffff);
7240 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7246 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7247 gen_op_set_cc_op(s
->cc_op
);
7248 gen_jmp_im(pc_start
- s
->cs_base
);
7251 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7254 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7257 gen_helper_vmrun(cpu_env
, tcg_const_i32(s
->aflag
),
7258 tcg_const_i32(s
->pc
- pc_start
));
7260 s
->is_jmp
= DISAS_TB_JUMP
;
7263 case 1: /* VMMCALL */
7264 if (!(s
->flags
& HF_SVME_MASK
))
7266 gen_helper_vmmcall(cpu_env
);
7268 case 2: /* VMLOAD */
7269 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7272 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7275 gen_helper_vmload(cpu_env
, tcg_const_i32(s
->aflag
));
7278 case 3: /* VMSAVE */
7279 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7282 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7285 gen_helper_vmsave(cpu_env
, tcg_const_i32(s
->aflag
));
7289 if ((!(s
->flags
& HF_SVME_MASK
) &&
7290 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7294 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7297 gen_helper_stgi(cpu_env
);
7301 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7304 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7307 gen_helper_clgi(cpu_env
);
7310 case 6: /* SKINIT */
7311 if ((!(s
->flags
& HF_SVME_MASK
) &&
7312 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7315 gen_helper_skinit(cpu_env
);
7317 case 7: /* INVLPGA */
7318 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7321 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7324 gen_helper_invlpga(cpu_env
, tcg_const_i32(s
->aflag
));
7330 } else if (s
->cpl
!= 0) {
7331 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7333 gen_svm_check_intercept(s
, pc_start
,
7334 op
==2 ? SVM_EXIT_GDTR_WRITE
: SVM_EXIT_IDTR_WRITE
);
7335 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7336 gen_op_ld_T1_A0(OT_WORD
+ s
->mem_index
);
7337 gen_add_A0_im(s
, 2);
7338 gen_op_ld_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7340 gen_op_andl_T0_im(0xffffff);
7342 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,gdt
.base
));
7343 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,gdt
.limit
));
7345 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,idt
.base
));
7346 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,idt
.limit
));
7351 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_CR0
);
7352 #if defined TARGET_X86_64 && defined HOST_WORDS_BIGENDIAN
7353 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]) + 4);
7355 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]));
7357 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 1);
7361 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7363 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7364 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7365 gen_helper_lmsw(cpu_env
, cpu_T
[0]);
7366 gen_jmp_im(s
->pc
- s
->cs_base
);
7371 if (mod
!= 3) { /* invlpg */
7373 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7375 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7376 gen_op_set_cc_op(s
->cc_op
);
7377 gen_jmp_im(pc_start
- s
->cs_base
);
7378 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7379 gen_helper_invlpg(cpu_env
, cpu_A0
);
7380 gen_jmp_im(s
->pc
- s
->cs_base
);
7385 case 0: /* swapgs */
7386 #ifdef TARGET_X86_64
7389 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7391 tcg_gen_ld_tl(cpu_T
[0], cpu_env
,
7392 offsetof(CPUX86State
,segs
[R_GS
].base
));
7393 tcg_gen_ld_tl(cpu_T
[1], cpu_env
,
7394 offsetof(CPUX86State
,kernelgsbase
));
7395 tcg_gen_st_tl(cpu_T
[1], cpu_env
,
7396 offsetof(CPUX86State
,segs
[R_GS
].base
));
7397 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
7398 offsetof(CPUX86State
,kernelgsbase
));
7406 case 1: /* rdtscp */
7407 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_RDTSCP
))
7409 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7410 gen_op_set_cc_op(s
->cc_op
);
7411 gen_jmp_im(pc_start
- s
->cs_base
);
7414 gen_helper_rdtscp(cpu_env
);
7417 gen_jmp(s
, s
->pc
- s
->cs_base
);
7429 case 0x108: /* invd */
7430 case 0x109: /* wbinvd */
7432 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7434 gen_svm_check_intercept(s
, pc_start
, (b
& 2) ? SVM_EXIT_INVD
: SVM_EXIT_WBINVD
);
7438 case 0x63: /* arpl or movslS (x86_64) */
7439 #ifdef TARGET_X86_64
7442 /* d_ot is the size of destination */
7443 d_ot
= dflag
+ OT_WORD
;
7445 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7446 reg
= ((modrm
>> 3) & 7) | rex_r
;
7447 mod
= (modrm
>> 6) & 3;
7448 rm
= (modrm
& 7) | REX_B(s
);
7451 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
7453 if (d_ot
== OT_QUAD
)
7454 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
7455 gen_op_mov_reg_T0(d_ot
, reg
);
7457 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7458 if (d_ot
== OT_QUAD
) {
7459 gen_op_lds_T0_A0(OT_LONG
+ s
->mem_index
);
7461 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7463 gen_op_mov_reg_T0(d_ot
, reg
);
7469 TCGv t0
, t1
, t2
, a0
;
7471 if (!s
->pe
|| s
->vm86
)
7473 t0
= tcg_temp_local_new();
7474 t1
= tcg_temp_local_new();
7475 t2
= tcg_temp_local_new();
7477 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7478 reg
= (modrm
>> 3) & 7;
7479 mod
= (modrm
>> 6) & 3;
7482 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7483 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7484 a0
= tcg_temp_local_new();
7485 tcg_gen_mov_tl(a0
, cpu_A0
);
7487 gen_op_mov_v_reg(ot
, t0
, rm
);
7490 gen_op_mov_v_reg(ot
, t1
, reg
);
7491 tcg_gen_andi_tl(cpu_tmp0
, t0
, 3);
7492 tcg_gen_andi_tl(t1
, t1
, 3);
7493 tcg_gen_movi_tl(t2
, 0);
7494 label1
= gen_new_label();
7495 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_tmp0
, t1
, label1
);
7496 tcg_gen_andi_tl(t0
, t0
, ~3);
7497 tcg_gen_or_tl(t0
, t0
, t1
);
7498 tcg_gen_movi_tl(t2
, CC_Z
);
7499 gen_set_label(label1
);
7501 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
7504 gen_op_mov_reg_v(ot
, rm
, t0
);
7506 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7507 gen_op_set_cc_op(s
->cc_op
);
7508 gen_compute_eflags(cpu_cc_src
);
7509 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_Z
);
7510 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t2
);
7511 s
->cc_op
= CC_OP_EFLAGS
;
7517 case 0x102: /* lar */
7518 case 0x103: /* lsl */
7522 if (!s
->pe
|| s
->vm86
)
7524 ot
= dflag
? OT_LONG
: OT_WORD
;
7525 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7526 reg
= ((modrm
>> 3) & 7) | rex_r
;
7527 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7528 t0
= tcg_temp_local_new();
7529 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7530 gen_op_set_cc_op(s
->cc_op
);
7532 gen_helper_lar(t0
, cpu_env
, cpu_T
[0]);
7534 gen_helper_lsl(t0
, cpu_env
, cpu_T
[0]);
7536 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_src
, CC_Z
);
7537 label1
= gen_new_label();
7538 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
7539 gen_op_mov_reg_v(ot
, reg
, t0
);
7540 gen_set_label(label1
);
7541 s
->cc_op
= CC_OP_EFLAGS
;
7546 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7547 mod
= (modrm
>> 6) & 3;
7548 op
= (modrm
>> 3) & 7;
7550 case 0: /* prefetchnta */
7551 case 1: /* prefetchnt0 */
7552 case 2: /* prefetchnt0 */
7553 case 3: /* prefetchnt0 */
7556 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7557 /* nothing more to do */
7559 default: /* nop (multi byte) */
7560 gen_nop_modrm(s
, modrm
);
7564 case 0x119 ... 0x11f: /* nop (multi byte) */
7565 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7566 gen_nop_modrm(s
, modrm
);
7568 case 0x120: /* mov reg, crN */
7569 case 0x122: /* mov crN, reg */
7571 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7573 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7574 /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
7575 * AMD documentation (24594.pdf) and testing of
7576 * intel 386 and 486 processors all show that the mod bits
7577 * are assumed to be 1's, regardless of actual values.
7579 rm
= (modrm
& 7) | REX_B(s
);
7580 reg
= ((modrm
>> 3) & 7) | rex_r
;
7585 if ((prefixes
& PREFIX_LOCK
) && (reg
== 0) &&
7586 (s
->cpuid_ext3_features
& CPUID_EXT3_CR8LEG
)) {
7595 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7596 gen_op_set_cc_op(s
->cc_op
);
7597 gen_jmp_im(pc_start
- s
->cs_base
);
7599 gen_op_mov_TN_reg(ot
, 0, rm
);
7600 gen_helper_write_crN(cpu_env
, tcg_const_i32(reg
),
7602 gen_jmp_im(s
->pc
- s
->cs_base
);
7605 gen_helper_read_crN(cpu_T
[0], cpu_env
, tcg_const_i32(reg
));
7606 gen_op_mov_reg_T0(ot
, rm
);
7614 case 0x121: /* mov reg, drN */
7615 case 0x123: /* mov drN, reg */
7617 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7619 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7620 /* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
7621 * AMD documentation (24594.pdf) and testing of
7622 * intel 386 and 486 processors all show that the mod bits
7623 * are assumed to be 1's, regardless of actual values.
7625 rm
= (modrm
& 7) | REX_B(s
);
7626 reg
= ((modrm
>> 3) & 7) | rex_r
;
7631 /* XXX: do it dynamically with CR4.DE bit */
7632 if (reg
== 4 || reg
== 5 || reg
>= 8)
7635 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_DR0
+ reg
);
7636 gen_op_mov_TN_reg(ot
, 0, rm
);
7637 gen_helper_movl_drN_T0(cpu_env
, tcg_const_i32(reg
), cpu_T
[0]);
7638 gen_jmp_im(s
->pc
- s
->cs_base
);
7641 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_DR0
+ reg
);
7642 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,dr
[reg
]));
7643 gen_op_mov_reg_T0(ot
, rm
);
7647 case 0x106: /* clts */
7649 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7651 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7652 gen_helper_clts(cpu_env
);
7653 /* abort block because static cpu state changed */
7654 gen_jmp_im(s
->pc
- s
->cs_base
);
7658 /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
7659 case 0x1c3: /* MOVNTI reg, mem */
7660 if (!(s
->cpuid_features
& CPUID_SSE2
))
7662 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
7663 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7664 mod
= (modrm
>> 6) & 3;
7667 reg
= ((modrm
>> 3) & 7) | rex_r
;
7668 /* generate a generic store */
7669 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
7672 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7673 mod
= (modrm
>> 6) & 3;
7674 op
= (modrm
>> 3) & 7;
7676 case 0: /* fxsave */
7677 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7678 (s
->prefix
& PREFIX_LOCK
))
7680 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7681 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7684 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7685 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7686 gen_op_set_cc_op(s
->cc_op
);
7687 gen_jmp_im(pc_start
- s
->cs_base
);
7688 gen_helper_fxsave(cpu_env
, cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7690 case 1: /* fxrstor */
7691 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7692 (s
->prefix
& PREFIX_LOCK
))
7694 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7695 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7698 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7699 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7700 gen_op_set_cc_op(s
->cc_op
);
7701 gen_jmp_im(pc_start
- s
->cs_base
);
7702 gen_helper_fxrstor(cpu_env
, cpu_A0
,
7703 tcg_const_i32((s
->dflag
== 2)));
7705 case 2: /* ldmxcsr */
7706 case 3: /* stmxcsr */
7707 if (s
->flags
& HF_TS_MASK
) {
7708 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7711 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
7714 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7716 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7717 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7718 gen_helper_ldmxcsr(cpu_env
, cpu_tmp2_i32
);
7720 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7721 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
7724 case 5: /* lfence */
7725 case 6: /* mfence */
7726 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE2
))
7729 case 7: /* sfence / clflush */
7730 if ((modrm
& 0xc7) == 0xc0) {
7732 /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
7733 if (!(s
->cpuid_features
& CPUID_SSE
))
7737 if (!(s
->cpuid_features
& CPUID_CLFLUSH
))
7739 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7746 case 0x10d: /* 3DNow! prefetch(w) */
7747 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7748 mod
= (modrm
>> 6) & 3;
7751 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7752 /* ignore for now */
7754 case 0x1aa: /* rsm */
7755 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_RSM
);
7756 if (!(s
->flags
& HF_SMM_MASK
))
7758 gen_update_cc_op(s
);
7759 gen_jmp_im(s
->pc
- s
->cs_base
);
7760 gen_helper_rsm(cpu_env
);
7763 case 0x1b8: /* SSE4.2 popcnt */
7764 if ((prefixes
& (PREFIX_REPZ
| PREFIX_LOCK
| PREFIX_REPNZ
)) !=
7767 if (!(s
->cpuid_ext_features
& CPUID_EXT_POPCNT
))
7770 modrm
= cpu_ldub_code(cpu_single_env
, s
->pc
++);
7771 reg
= ((modrm
>> 3) & 7);
7773 if (s
->prefix
& PREFIX_DATA
)
7775 else if (s
->dflag
!= 2)
7780 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
7781 gen_helper_popcnt(cpu_T
[0], cpu_env
, cpu_T
[0], tcg_const_i32(ot
));
7782 gen_op_mov_reg_T0(ot
, reg
);
7784 s
->cc_op
= CC_OP_EFLAGS
;
7786 case 0x10e ... 0x10f:
7787 /* 3DNow! instructions, ignore prefixes */
7788 s
->prefix
&= ~(PREFIX_REPZ
| PREFIX_REPNZ
| PREFIX_DATA
);
7789 case 0x110 ... 0x117:
7790 case 0x128 ... 0x12f:
7791 case 0x138 ... 0x13a:
7792 case 0x150 ... 0x179:
7793 case 0x17c ... 0x17f:
7795 case 0x1c4 ... 0x1c6:
7796 case 0x1d0 ... 0x1fe:
7797 gen_sse(s
, b
, pc_start
, rex_r
);
7802 /* lock generation */
7803 if (s
->prefix
& PREFIX_LOCK
)
7804 gen_helper_unlock();
7807 if (s
->prefix
& PREFIX_LOCK
)
7808 gen_helper_unlock();
7809 /* XXX: ensure that no lock was generated */
7810 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
7814 void optimize_flags_init(void)
7816 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
7817 cpu_cc_op
= tcg_global_mem_new_i32(TCG_AREG0
,
7818 offsetof(CPUX86State
, cc_op
), "cc_op");
7819 cpu_cc_src
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_src
),
7821 cpu_cc_dst
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_dst
),
7823 cpu_cc_tmp
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUX86State
, cc_tmp
),
7826 #ifdef TARGET_X86_64
7827 cpu_regs
[R_EAX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7828 offsetof(CPUX86State
, regs
[R_EAX
]), "rax");
7829 cpu_regs
[R_ECX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7830 offsetof(CPUX86State
, regs
[R_ECX
]), "rcx");
7831 cpu_regs
[R_EDX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7832 offsetof(CPUX86State
, regs
[R_EDX
]), "rdx");
7833 cpu_regs
[R_EBX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7834 offsetof(CPUX86State
, regs
[R_EBX
]), "rbx");
7835 cpu_regs
[R_ESP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7836 offsetof(CPUX86State
, regs
[R_ESP
]), "rsp");
7837 cpu_regs
[R_EBP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7838 offsetof(CPUX86State
, regs
[R_EBP
]), "rbp");
7839 cpu_regs
[R_ESI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7840 offsetof(CPUX86State
, regs
[R_ESI
]), "rsi");
7841 cpu_regs
[R_EDI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7842 offsetof(CPUX86State
, regs
[R_EDI
]), "rdi");
7843 cpu_regs
[8] = tcg_global_mem_new_i64(TCG_AREG0
,
7844 offsetof(CPUX86State
, regs
[8]), "r8");
7845 cpu_regs
[9] = tcg_global_mem_new_i64(TCG_AREG0
,
7846 offsetof(CPUX86State
, regs
[9]), "r9");
7847 cpu_regs
[10] = tcg_global_mem_new_i64(TCG_AREG0
,
7848 offsetof(CPUX86State
, regs
[10]), "r10");
7849 cpu_regs
[11] = tcg_global_mem_new_i64(TCG_AREG0
,
7850 offsetof(CPUX86State
, regs
[11]), "r11");
7851 cpu_regs
[12] = tcg_global_mem_new_i64(TCG_AREG0
,
7852 offsetof(CPUX86State
, regs
[12]), "r12");
7853 cpu_regs
[13] = tcg_global_mem_new_i64(TCG_AREG0
,
7854 offsetof(CPUX86State
, regs
[13]), "r13");
7855 cpu_regs
[14] = tcg_global_mem_new_i64(TCG_AREG0
,
7856 offsetof(CPUX86State
, regs
[14]), "r14");
7857 cpu_regs
[15] = tcg_global_mem_new_i64(TCG_AREG0
,
7858 offsetof(CPUX86State
, regs
[15]), "r15");
7860 cpu_regs
[R_EAX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7861 offsetof(CPUX86State
, regs
[R_EAX
]), "eax");
7862 cpu_regs
[R_ECX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7863 offsetof(CPUX86State
, regs
[R_ECX
]), "ecx");
7864 cpu_regs
[R_EDX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7865 offsetof(CPUX86State
, regs
[R_EDX
]), "edx");
7866 cpu_regs
[R_EBX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7867 offsetof(CPUX86State
, regs
[R_EBX
]), "ebx");
7868 cpu_regs
[R_ESP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7869 offsetof(CPUX86State
, regs
[R_ESP
]), "esp");
7870 cpu_regs
[R_EBP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7871 offsetof(CPUX86State
, regs
[R_EBP
]), "ebp");
7872 cpu_regs
[R_ESI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7873 offsetof(CPUX86State
, regs
[R_ESI
]), "esi");
7874 cpu_regs
[R_EDI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7875 offsetof(CPUX86State
, regs
[R_EDI
]), "edi");
7878 /* register helpers */
7879 #define GEN_HELPER 2
7883 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
7884 basic block 'tb'. If search_pc is TRUE, also generate PC
7885 information for each intermediate instruction. */
7886 static inline void gen_intermediate_code_internal(CPUX86State
*env
,
7887 TranslationBlock
*tb
,
7890 DisasContext dc1
, *dc
= &dc1
;
7891 target_ulong pc_ptr
;
7892 uint16_t *gen_opc_end
;
7896 target_ulong pc_start
;
7897 target_ulong cs_base
;
7901 /* generate intermediate code */
7903 cs_base
= tb
->cs_base
;
7906 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
7907 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
7908 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
7909 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
7911 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
7912 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
7913 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
7914 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
7915 dc
->singlestep_enabled
= env
->singlestep_enabled
;
7916 dc
->cc_op
= CC_OP_DYNAMIC
;
7917 dc
->cs_base
= cs_base
;
7919 dc
->popl_esp_hack
= 0;
7920 /* select memory access functions */
7922 if (flags
& HF_SOFTMMU_MASK
) {
7923 dc
->mem_index
= (cpu_mmu_index(env
) + 1) << 2;
7925 dc
->cpuid_features
= env
->cpuid_features
;
7926 dc
->cpuid_ext_features
= env
->cpuid_ext_features
;
7927 dc
->cpuid_ext2_features
= env
->cpuid_ext2_features
;
7928 dc
->cpuid_ext3_features
= env
->cpuid_ext3_features
;
7929 dc
->cpuid_7_0_ebx_features
= env
->cpuid_7_0_ebx_features
;
7930 #ifdef TARGET_X86_64
7931 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
7932 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
7935 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
7936 (flags
& HF_INHIBIT_IRQ_MASK
)
7937 #ifndef CONFIG_SOFTMMU
7938 || (flags
& HF_SOFTMMU_MASK
)
7942 /* check addseg logic */
7943 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
7944 printf("ERROR addseg\n");
7947 cpu_T
[0] = tcg_temp_new();
7948 cpu_T
[1] = tcg_temp_new();
7949 cpu_A0
= tcg_temp_new();
7950 cpu_T3
= tcg_temp_new();
7952 cpu_tmp0
= tcg_temp_new();
7953 cpu_tmp1_i64
= tcg_temp_new_i64();
7954 cpu_tmp2_i32
= tcg_temp_new_i32();
7955 cpu_tmp3_i32
= tcg_temp_new_i32();
7956 cpu_tmp4
= tcg_temp_new();
7957 cpu_tmp5
= tcg_temp_new();
7958 cpu_ptr0
= tcg_temp_new_ptr();
7959 cpu_ptr1
= tcg_temp_new_ptr();
7961 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7963 dc
->is_jmp
= DISAS_NEXT
;
7967 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7969 max_insns
= CF_COUNT_MASK
;
7973 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
7974 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7975 if (bp
->pc
== pc_ptr
&&
7976 !((bp
->flags
& BP_CPU
) && (tb
->flags
& HF_RF_MASK
))) {
7977 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
7983 j
= gen_opc_ptr
- gen_opc_buf
;
7987 gen_opc_instr_start
[lj
++] = 0;
7989 gen_opc_pc
[lj
] = pc_ptr
;
7990 gen_opc_cc_op
[lj
] = dc
->cc_op
;
7991 gen_opc_instr_start
[lj
] = 1;
7992 gen_opc_icount
[lj
] = num_insns
;
7994 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7997 pc_ptr
= disas_insn(dc
, pc_ptr
);
7999 /* stop translation if indicated */
8002 /* if single step mode, we generate only one instruction and
8003 generate an exception */
8004 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
8005 the flag and abort the translation to give the irqs a
8006 change to be happen */
8007 if (dc
->tf
|| dc
->singlestep_enabled
||
8008 (flags
& HF_INHIBIT_IRQ_MASK
)) {
8009 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8013 /* if too long translation, stop generation too */
8014 if (gen_opc_ptr
>= gen_opc_end
||
8015 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32) ||
8016 num_insns
>= max_insns
) {
8017 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8022 gen_jmp_im(pc_ptr
- dc
->cs_base
);
8027 if (tb
->cflags
& CF_LAST_IO
)
8029 gen_icount_end(tb
, num_insns
);
8030 *gen_opc_ptr
= INDEX_op_end
;
8031 /* we don't forget to fill the last values */
8033 j
= gen_opc_ptr
- gen_opc_buf
;
8036 gen_opc_instr_start
[lj
++] = 0;
8040 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8042 qemu_log("----------------\n");
8043 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8044 #ifdef TARGET_X86_64
8049 disas_flags
= !dc
->code32
;
8050 log_target_disas(pc_start
, pc_ptr
- pc_start
, disas_flags
);
8056 tb
->size
= pc_ptr
- pc_start
;
8057 tb
->icount
= num_insns
;
8061 void gen_intermediate_code(CPUX86State
*env
, TranslationBlock
*tb
)
8063 gen_intermediate_code_internal(env
, tb
, 0);
8066 void gen_intermediate_code_pc(CPUX86State
*env
, TranslationBlock
*tb
)
8068 gen_intermediate_code_internal(env
, tb
, 1);
8071 void restore_state_to_opc(CPUX86State
*env
, TranslationBlock
*tb
, int pc_pos
)
8075 if (qemu_loglevel_mask(CPU_LOG_TB_OP
)) {
8077 qemu_log("RESTORE:\n");
8078 for(i
= 0;i
<= pc_pos
; i
++) {
8079 if (gen_opc_instr_start
[i
]) {
8080 qemu_log("0x%04x: " TARGET_FMT_lx
"\n", i
, gen_opc_pc
[i
]);
8083 qemu_log("pc_pos=0x%x eip=" TARGET_FMT_lx
" cs_base=%x\n",
8084 pc_pos
, gen_opc_pc
[pc_pos
] - tb
->cs_base
,
8085 (uint32_t)tb
->cs_base
);
8088 env
->eip
= gen_opc_pc
[pc_pos
] - tb
->cs_base
;
8089 cc_op
= gen_opc_cc_op
[pc_pos
];
8090 if (cc_op
!= CC_OP_DYNAMIC
)