4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
35 #define PREFIX_REPZ 0x01
36 #define PREFIX_REPNZ 0x02
37 #define PREFIX_LOCK 0x04
38 #define PREFIX_DATA 0x08
39 #define PREFIX_ADR 0x10
42 #define X86_64_ONLY(x) x
43 #define X86_64_DEF(...) __VA_ARGS__
44 #define CODE64(s) ((s)->code64)
45 #define REX_X(s) ((s)->rex_x)
46 #define REX_B(s) ((s)->rex_b)
47 /* XXX: gcc generates push/pop in some opcodes, so we cannot use them */
49 #define BUGGY_64(x) NULL
52 #define X86_64_ONLY(x) NULL
53 #define X86_64_DEF(...)
59 //#define MACRO_TEST 1
61 /* global register indexes */
62 static TCGv_ptr cpu_env
;
63 static TCGv cpu_A0
, cpu_cc_src
, cpu_cc_dst
, cpu_cc_tmp
;
64 static TCGv_i32 cpu_cc_op
;
65 static TCGv cpu_regs
[CPU_NB_REGS
];
67 static TCGv cpu_T
[2], cpu_T3
;
68 /* local register indexes (only used inside old micro ops) */
69 static TCGv cpu_tmp0
, cpu_tmp4
;
70 static TCGv_ptr cpu_ptr0
, cpu_ptr1
;
71 static TCGv_i32 cpu_tmp2_i32
, cpu_tmp3_i32
;
72 static TCGv_i64 cpu_tmp1_i64
;
75 static uint8_t gen_opc_cc_op
[OPC_BUF_SIZE
];
77 #include "gen-icount.h"
80 static int x86_64_hregs
;
83 typedef struct DisasContext
{
84 /* current insn context */
85 int override
; /* -1 if no override */
88 target_ulong pc
; /* pc = eip + cs_base */
89 int is_jmp
; /* 1 = means jump (stop translation), 2 means CPU
90 static state change (stop translation) */
91 /* current block context */
92 target_ulong cs_base
; /* base of CS segment */
93 int pe
; /* protected mode */
94 int code32
; /* 32 bit code segment */
96 int lma
; /* long mode active */
97 int code64
; /* 64 bit code segment */
100 int ss32
; /* 32 bit stack segment */
101 int cc_op
; /* current CC operation */
102 int addseg
; /* non zero if either DS/ES/SS have a non zero base */
103 int f_st
; /* currently unused */
104 int vm86
; /* vm86 mode */
107 int tf
; /* TF cpu flag */
108 int singlestep_enabled
; /* "hardware" single step enabled */
109 int jmp_opt
; /* use direct block chaining for direct jumps */
110 int mem_index
; /* select memory access functions */
111 uint64_t flags
; /* all execution flags */
112 struct TranslationBlock
*tb
;
113 int popl_esp_hack
; /* for correct popl with esp base handling */
114 int rip_offset
; /* only used in x86_64, but left for simplicity */
116 int cpuid_ext_features
;
117 int cpuid_ext2_features
;
118 int cpuid_ext3_features
;
121 static void gen_eob(DisasContext
*s
);
122 static void gen_jmp(DisasContext
*s
, target_ulong eip
);
123 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
);
125 /* i386 arith/logic operations */
145 OP_SHL1
, /* undocumented */
169 /* I386 int registers */
170 OR_EAX
, /* MUST be even numbered */
179 OR_TMP0
= 16, /* temporary operand register */
181 OR_A0
, /* temporary register used when doing address evaluation */
184 static inline void gen_op_movl_T0_0(void)
186 tcg_gen_movi_tl(cpu_T
[0], 0);
189 static inline void gen_op_movl_T0_im(int32_t val
)
191 tcg_gen_movi_tl(cpu_T
[0], val
);
194 static inline void gen_op_movl_T0_imu(uint32_t val
)
196 tcg_gen_movi_tl(cpu_T
[0], val
);
199 static inline void gen_op_movl_T1_im(int32_t val
)
201 tcg_gen_movi_tl(cpu_T
[1], val
);
204 static inline void gen_op_movl_T1_imu(uint32_t val
)
206 tcg_gen_movi_tl(cpu_T
[1], val
);
209 static inline void gen_op_movl_A0_im(uint32_t val
)
211 tcg_gen_movi_tl(cpu_A0
, val
);
215 static inline void gen_op_movq_A0_im(int64_t val
)
217 tcg_gen_movi_tl(cpu_A0
, val
);
221 static inline void gen_movtl_T0_im(target_ulong val
)
223 tcg_gen_movi_tl(cpu_T
[0], val
);
226 static inline void gen_movtl_T1_im(target_ulong val
)
228 tcg_gen_movi_tl(cpu_T
[1], val
);
231 static inline void gen_op_andl_T0_ffff(void)
233 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
236 static inline void gen_op_andl_T0_im(uint32_t val
)
238 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], val
);
241 static inline void gen_op_movl_T0_T1(void)
243 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
246 static inline void gen_op_andl_A0_ffff(void)
248 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffff);
253 #define NB_OP_SIZES 4
255 #else /* !TARGET_X86_64 */
257 #define NB_OP_SIZES 3
259 #endif /* !TARGET_X86_64 */
261 #if defined(HOST_WORDS_BIGENDIAN)
262 #define REG_B_OFFSET (sizeof(target_ulong) - 1)
263 #define REG_H_OFFSET (sizeof(target_ulong) - 2)
264 #define REG_W_OFFSET (sizeof(target_ulong) - 2)
265 #define REG_L_OFFSET (sizeof(target_ulong) - 4)
266 #define REG_LH_OFFSET (sizeof(target_ulong) - 8)
268 #define REG_B_OFFSET 0
269 #define REG_H_OFFSET 1
270 #define REG_W_OFFSET 0
271 #define REG_L_OFFSET 0
272 #define REG_LH_OFFSET 4
275 static inline void gen_op_mov_reg_v(int ot
, int reg
, TCGv t0
)
281 tmp
= tcg_temp_new();
282 tcg_gen_ext8u_tl(tmp
, t0
);
283 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
284 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xff);
285 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
287 tcg_gen_shli_tl(tmp
, tmp
, 8);
288 tcg_gen_andi_tl(cpu_regs
[reg
- 4], cpu_regs
[reg
- 4], ~0xff00);
289 tcg_gen_or_tl(cpu_regs
[reg
- 4], cpu_regs
[reg
- 4], tmp
);
294 tmp
= tcg_temp_new();
295 tcg_gen_ext16u_tl(tmp
, t0
);
296 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
297 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
300 default: /* XXX this shouldn't be reached; abort? */
302 /* For x86_64, this sets the higher half of register to zero.
303 For i386, this is equivalent to a mov. */
304 tcg_gen_ext32u_tl(cpu_regs
[reg
], t0
);
308 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
314 static inline void gen_op_mov_reg_T0(int ot
, int reg
)
316 gen_op_mov_reg_v(ot
, reg
, cpu_T
[0]);
319 static inline void gen_op_mov_reg_T1(int ot
, int reg
)
321 gen_op_mov_reg_v(ot
, reg
, cpu_T
[1]);
324 static inline void gen_op_mov_reg_A0(int size
, int reg
)
330 tmp
= tcg_temp_new();
331 tcg_gen_ext16u_tl(tmp
, cpu_A0
);
332 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
333 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], tmp
);
336 default: /* XXX this shouldn't be reached; abort? */
338 /* For x86_64, this sets the higher half of register to zero.
339 For i386, this is equivalent to a mov. */
340 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_A0
);
344 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_A0
);
350 static inline void gen_op_mov_v_reg(int ot
, TCGv t0
, int reg
)
354 if (reg
< 4 X86_64_DEF( || reg
>= 8 || x86_64_hregs
)) {
357 tcg_gen_shri_tl(t0
, cpu_regs
[reg
- 4], 8);
358 tcg_gen_ext8u_tl(t0
, t0
);
363 tcg_gen_mov_tl(t0
, cpu_regs
[reg
]);
368 static inline void gen_op_mov_TN_reg(int ot
, int t_index
, int reg
)
370 gen_op_mov_v_reg(ot
, cpu_T
[t_index
], reg
);
373 static inline void gen_op_movl_A0_reg(int reg
)
375 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
378 static inline void gen_op_addl_A0_im(int32_t val
)
380 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
382 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
387 static inline void gen_op_addq_A0_im(int64_t val
)
389 tcg_gen_addi_tl(cpu_A0
, cpu_A0
, val
);
393 static void gen_add_A0_im(DisasContext
*s
, int val
)
397 gen_op_addq_A0_im(val
);
400 gen_op_addl_A0_im(val
);
403 static inline void gen_op_addl_T0_T1(void)
405 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
408 static inline void gen_op_jmp_T0(void)
410 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, eip
));
413 static inline void gen_op_add_reg_im(int size
, int reg
, int32_t val
)
417 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
418 tcg_gen_ext16u_tl(cpu_tmp0
, cpu_tmp0
);
419 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
420 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
);
423 tcg_gen_addi_tl(cpu_tmp0
, cpu_regs
[reg
], val
);
424 /* For x86_64, this sets the higher half of register to zero.
425 For i386, this is equivalent to a nop. */
426 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
427 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
431 tcg_gen_addi_tl(cpu_regs
[reg
], cpu_regs
[reg
], val
);
437 static inline void gen_op_add_reg_T0(int size
, int reg
)
441 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
442 tcg_gen_ext16u_tl(cpu_tmp0
, cpu_tmp0
);
443 tcg_gen_andi_tl(cpu_regs
[reg
], cpu_regs
[reg
], ~0xffff);
444 tcg_gen_or_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_tmp0
);
447 tcg_gen_add_tl(cpu_tmp0
, cpu_regs
[reg
], cpu_T
[0]);
448 /* For x86_64, this sets the higher half of register to zero.
449 For i386, this is equivalent to a nop. */
450 tcg_gen_ext32u_tl(cpu_tmp0
, cpu_tmp0
);
451 tcg_gen_mov_tl(cpu_regs
[reg
], cpu_tmp0
);
455 tcg_gen_add_tl(cpu_regs
[reg
], cpu_regs
[reg
], cpu_T
[0]);
461 static inline void gen_op_set_cc_op(int32_t val
)
463 tcg_gen_movi_i32(cpu_cc_op
, val
);
466 static inline void gen_op_addl_A0_reg_sN(int shift
, int reg
)
468 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
470 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
471 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
472 /* For x86_64, this sets the higher half of register to zero.
473 For i386, this is equivalent to a nop. */
474 tcg_gen_ext32u_tl(cpu_A0
, cpu_A0
);
477 static inline void gen_op_movl_A0_seg(int reg
)
479 tcg_gen_ld32u_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
) + REG_L_OFFSET
);
482 static inline void gen_op_addl_A0_seg(int reg
)
484 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
485 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
487 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
492 static inline void gen_op_movq_A0_seg(int reg
)
494 tcg_gen_ld_tl(cpu_A0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
497 static inline void gen_op_addq_A0_seg(int reg
)
499 tcg_gen_ld_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, segs
[reg
].base
));
500 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
503 static inline void gen_op_movq_A0_reg(int reg
)
505 tcg_gen_mov_tl(cpu_A0
, cpu_regs
[reg
]);
508 static inline void gen_op_addq_A0_reg_sN(int shift
, int reg
)
510 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[reg
]);
512 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, shift
);
513 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
517 static inline void gen_op_lds_T0_A0(int idx
)
519 int mem_index
= (idx
>> 2) - 1;
522 tcg_gen_qemu_ld8s(cpu_T
[0], cpu_A0
, mem_index
);
525 tcg_gen_qemu_ld16s(cpu_T
[0], cpu_A0
, mem_index
);
529 tcg_gen_qemu_ld32s(cpu_T
[0], cpu_A0
, mem_index
);
534 static inline void gen_op_ld_v(int idx
, TCGv t0
, TCGv a0
)
536 int mem_index
= (idx
>> 2) - 1;
539 tcg_gen_qemu_ld8u(t0
, a0
, mem_index
);
542 tcg_gen_qemu_ld16u(t0
, a0
, mem_index
);
545 tcg_gen_qemu_ld32u(t0
, a0
, mem_index
);
549 /* Should never happen on 32-bit targets. */
551 tcg_gen_qemu_ld64(t0
, a0
, mem_index
);
557 /* XXX: always use ldu or lds */
558 static inline void gen_op_ld_T0_A0(int idx
)
560 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
563 static inline void gen_op_ldu_T0_A0(int idx
)
565 gen_op_ld_v(idx
, cpu_T
[0], cpu_A0
);
568 static inline void gen_op_ld_T1_A0(int idx
)
570 gen_op_ld_v(idx
, cpu_T
[1], cpu_A0
);
573 static inline void gen_op_st_v(int idx
, TCGv t0
, TCGv a0
)
575 int mem_index
= (idx
>> 2) - 1;
578 tcg_gen_qemu_st8(t0
, a0
, mem_index
);
581 tcg_gen_qemu_st16(t0
, a0
, mem_index
);
584 tcg_gen_qemu_st32(t0
, a0
, mem_index
);
588 /* Should never happen on 32-bit targets. */
590 tcg_gen_qemu_st64(t0
, a0
, mem_index
);
596 static inline void gen_op_st_T0_A0(int idx
)
598 gen_op_st_v(idx
, cpu_T
[0], cpu_A0
);
601 static inline void gen_op_st_T1_A0(int idx
)
603 gen_op_st_v(idx
, cpu_T
[1], cpu_A0
);
606 static inline void gen_jmp_im(target_ulong pc
)
608 tcg_gen_movi_tl(cpu_tmp0
, pc
);
609 tcg_gen_st_tl(cpu_tmp0
, cpu_env
, offsetof(CPUState
, eip
));
612 static inline void gen_string_movl_A0_ESI(DisasContext
*s
)
616 override
= s
->override
;
620 gen_op_movq_A0_seg(override
);
621 gen_op_addq_A0_reg_sN(0, R_ESI
);
623 gen_op_movq_A0_reg(R_ESI
);
629 if (s
->addseg
&& override
< 0)
632 gen_op_movl_A0_seg(override
);
633 gen_op_addl_A0_reg_sN(0, R_ESI
);
635 gen_op_movl_A0_reg(R_ESI
);
638 /* 16 address, always override */
641 gen_op_movl_A0_reg(R_ESI
);
642 gen_op_andl_A0_ffff();
643 gen_op_addl_A0_seg(override
);
647 static inline void gen_string_movl_A0_EDI(DisasContext
*s
)
651 gen_op_movq_A0_reg(R_EDI
);
656 gen_op_movl_A0_seg(R_ES
);
657 gen_op_addl_A0_reg_sN(0, R_EDI
);
659 gen_op_movl_A0_reg(R_EDI
);
662 gen_op_movl_A0_reg(R_EDI
);
663 gen_op_andl_A0_ffff();
664 gen_op_addl_A0_seg(R_ES
);
668 static inline void gen_op_movl_T0_Dshift(int ot
)
670 tcg_gen_ld32s_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, df
));
671 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], ot
);
674 static void gen_extu(int ot
, TCGv reg
)
678 tcg_gen_ext8u_tl(reg
, reg
);
681 tcg_gen_ext16u_tl(reg
, reg
);
684 tcg_gen_ext32u_tl(reg
, reg
);
691 static void gen_exts(int ot
, TCGv reg
)
695 tcg_gen_ext8s_tl(reg
, reg
);
698 tcg_gen_ext16s_tl(reg
, reg
);
701 tcg_gen_ext32s_tl(reg
, reg
);
708 static inline void gen_op_jnz_ecx(int size
, int label1
)
710 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
711 gen_extu(size
+ 1, cpu_tmp0
);
712 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, label1
);
715 static inline void gen_op_jz_ecx(int size
, int label1
)
717 tcg_gen_mov_tl(cpu_tmp0
, cpu_regs
[R_ECX
]);
718 gen_extu(size
+ 1, cpu_tmp0
);
719 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
722 static void gen_helper_in_func(int ot
, TCGv v
, TCGv_i32 n
)
725 case 0: gen_helper_inb(v
, n
); break;
726 case 1: gen_helper_inw(v
, n
); break;
727 case 2: gen_helper_inl(v
, n
); break;
732 static void gen_helper_out_func(int ot
, TCGv_i32 v
, TCGv_i32 n
)
735 case 0: gen_helper_outb(v
, n
); break;
736 case 1: gen_helper_outw(v
, n
); break;
737 case 2: gen_helper_outl(v
, n
); break;
742 static void gen_check_io(DisasContext
*s
, int ot
, target_ulong cur_eip
,
746 target_ulong next_eip
;
749 if (s
->pe
&& (s
->cpl
> s
->iopl
|| s
->vm86
)) {
750 if (s
->cc_op
!= CC_OP_DYNAMIC
)
751 gen_op_set_cc_op(s
->cc_op
);
754 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
756 case 0: gen_helper_check_iob(cpu_tmp2_i32
); break;
757 case 1: gen_helper_check_iow(cpu_tmp2_i32
); break;
758 case 2: gen_helper_check_iol(cpu_tmp2_i32
); break;
761 if(s
->flags
& HF_SVMI_MASK
) {
763 if (s
->cc_op
!= CC_OP_DYNAMIC
)
764 gen_op_set_cc_op(s
->cc_op
);
767 svm_flags
|= (1 << (4 + ot
));
768 next_eip
= s
->pc
- s
->cs_base
;
769 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
770 gen_helper_svm_check_io(cpu_tmp2_i32
, tcg_const_i32(svm_flags
),
771 tcg_const_i32(next_eip
- cur_eip
));
775 static inline void gen_movs(DisasContext
*s
, int ot
)
777 gen_string_movl_A0_ESI(s
);
778 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
779 gen_string_movl_A0_EDI(s
);
780 gen_op_st_T0_A0(ot
+ s
->mem_index
);
781 gen_op_movl_T0_Dshift(ot
);
782 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
783 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
786 static inline void gen_update_cc_op(DisasContext
*s
)
788 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
789 gen_op_set_cc_op(s
->cc_op
);
790 s
->cc_op
= CC_OP_DYNAMIC
;
794 static void gen_op_update1_cc(void)
796 tcg_gen_discard_tl(cpu_cc_src
);
797 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
800 static void gen_op_update2_cc(void)
802 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
803 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
806 static inline void gen_op_cmpl_T0_T1_cc(void)
808 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
809 tcg_gen_sub_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
812 static inline void gen_op_testl_T0_T1_cc(void)
814 tcg_gen_discard_tl(cpu_cc_src
);
815 tcg_gen_and_tl(cpu_cc_dst
, cpu_T
[0], cpu_T
[1]);
818 static void gen_op_update_neg_cc(void)
820 tcg_gen_neg_tl(cpu_cc_src
, cpu_T
[0]);
821 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
824 /* compute eflags.C to reg */
825 static void gen_compute_eflags_c(TCGv reg
)
827 gen_helper_cc_compute_c(cpu_tmp2_i32
, cpu_cc_op
);
828 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
831 /* compute all eflags to cc_src */
832 static void gen_compute_eflags(TCGv reg
)
834 gen_helper_cc_compute_all(cpu_tmp2_i32
, cpu_cc_op
);
835 tcg_gen_extu_i32_tl(reg
, cpu_tmp2_i32
);
838 static inline void gen_setcc_slow_T0(DisasContext
*s
, int jcc_op
)
840 if (s
->cc_op
!= CC_OP_DYNAMIC
)
841 gen_op_set_cc_op(s
->cc_op
);
844 gen_compute_eflags(cpu_T
[0]);
845 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 11);
846 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
849 gen_compute_eflags_c(cpu_T
[0]);
852 gen_compute_eflags(cpu_T
[0]);
853 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 6);
854 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
857 gen_compute_eflags(cpu_tmp0
);
858 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 6);
859 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
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], 7);
865 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
868 gen_compute_eflags(cpu_T
[0]);
869 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 2);
870 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
873 gen_compute_eflags(cpu_tmp0
);
874 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
875 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 7); /* CC_S */
876 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
877 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
881 gen_compute_eflags(cpu_tmp0
);
882 tcg_gen_shri_tl(cpu_T
[0], cpu_tmp0
, 11); /* CC_O */
883 tcg_gen_shri_tl(cpu_tmp4
, cpu_tmp0
, 7); /* CC_S */
884 tcg_gen_shri_tl(cpu_tmp0
, cpu_tmp0
, 6); /* CC_Z */
885 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
886 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
887 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 1);
892 /* return true if setcc_slow is not needed (WARNING: must be kept in
893 sync with gen_jcc1) */
894 static int is_fast_jcc_case(DisasContext
*s
, int b
)
897 jcc_op
= (b
>> 1) & 7;
899 /* we optimize the cmp/jcc case */
904 if (jcc_op
== JCC_O
|| jcc_op
== JCC_P
)
908 /* some jumps are easy to compute */
933 if (jcc_op
!= JCC_Z
&& jcc_op
!= JCC_S
)
943 /* generate a conditional jump to label 'l1' according to jump opcode
944 value 'b'. In the fast case, T0 is guaranted not to be used. */
945 static inline void gen_jcc1(DisasContext
*s
, int cc_op
, int b
, int l1
)
947 int inv
, jcc_op
, size
, cond
;
951 jcc_op
= (b
>> 1) & 7;
954 /* we optimize the cmp/jcc case */
960 size
= cc_op
- CC_OP_SUBB
;
966 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xff);
970 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffff);
975 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0xffffffff);
983 tcg_gen_brcondi_tl(inv
? TCG_COND_NE
: TCG_COND_EQ
, t0
, 0, l1
);
989 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80);
990 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
994 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x8000);
995 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
1000 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_dst
, 0x80000000);
1001 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
, cpu_tmp0
,
1006 tcg_gen_brcondi_tl(inv
? TCG_COND_GE
: TCG_COND_LT
, cpu_cc_dst
,
1013 cond
= inv
? TCG_COND_GEU
: TCG_COND_LTU
;
1016 cond
= inv
? TCG_COND_GTU
: TCG_COND_LEU
;
1018 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1022 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xff);
1023 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xff);
1027 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffff);
1028 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffff);
1030 #ifdef TARGET_X86_64
1033 tcg_gen_andi_tl(cpu_tmp4
, cpu_tmp4
, 0xffffffff);
1034 tcg_gen_andi_tl(t0
, cpu_cc_src
, 0xffffffff);
1041 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1045 cond
= inv
? TCG_COND_GE
: TCG_COND_LT
;
1048 cond
= inv
? TCG_COND_GT
: TCG_COND_LE
;
1050 tcg_gen_add_tl(cpu_tmp4
, cpu_cc_dst
, cpu_cc_src
);
1054 tcg_gen_ext8s_tl(cpu_tmp4
, cpu_tmp4
);
1055 tcg_gen_ext8s_tl(t0
, cpu_cc_src
);
1059 tcg_gen_ext16s_tl(cpu_tmp4
, cpu_tmp4
);
1060 tcg_gen_ext16s_tl(t0
, cpu_cc_src
);
1062 #ifdef TARGET_X86_64
1065 tcg_gen_ext32s_tl(cpu_tmp4
, cpu_tmp4
);
1066 tcg_gen_ext32s_tl(t0
, cpu_cc_src
);
1073 tcg_gen_brcond_tl(cond
, cpu_tmp4
, t0
, l1
);
1081 /* some jumps are easy to compute */
1123 size
= (cc_op
- CC_OP_ADDB
) & 3;
1126 size
= (cc_op
- CC_OP_ADDB
) & 3;
1134 gen_setcc_slow_T0(s
, jcc_op
);
1135 tcg_gen_brcondi_tl(inv
? TCG_COND_EQ
: TCG_COND_NE
,
1141 /* XXX: does not work with gdbstub "ice" single step - not a
1143 static int gen_jz_ecx_string(DisasContext
*s
, target_ulong next_eip
)
1147 l1
= gen_new_label();
1148 l2
= gen_new_label();
1149 gen_op_jnz_ecx(s
->aflag
, l1
);
1151 gen_jmp_tb(s
, next_eip
, 1);
1156 static inline void gen_stos(DisasContext
*s
, int ot
)
1158 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1159 gen_string_movl_A0_EDI(s
);
1160 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1161 gen_op_movl_T0_Dshift(ot
);
1162 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1165 static inline void gen_lods(DisasContext
*s
, int ot
)
1167 gen_string_movl_A0_ESI(s
);
1168 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1169 gen_op_mov_reg_T0(ot
, R_EAX
);
1170 gen_op_movl_T0_Dshift(ot
);
1171 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1174 static inline void gen_scas(DisasContext
*s
, int ot
)
1176 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
1177 gen_string_movl_A0_EDI(s
);
1178 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1179 gen_op_cmpl_T0_T1_cc();
1180 gen_op_movl_T0_Dshift(ot
);
1181 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1184 static inline void gen_cmps(DisasContext
*s
, int ot
)
1186 gen_string_movl_A0_ESI(s
);
1187 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1188 gen_string_movl_A0_EDI(s
);
1189 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
1190 gen_op_cmpl_T0_T1_cc();
1191 gen_op_movl_T0_Dshift(ot
);
1192 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1193 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1196 static inline void gen_ins(DisasContext
*s
, int ot
)
1200 gen_string_movl_A0_EDI(s
);
1201 /* Note: we must do this dummy write first to be restartable in
1202 case of page fault. */
1204 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1205 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1206 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1207 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1208 gen_helper_in_func(ot
, cpu_T
[0], cpu_tmp2_i32
);
1209 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1210 gen_op_movl_T0_Dshift(ot
);
1211 gen_op_add_reg_T0(s
->aflag
, R_EDI
);
1216 static inline void gen_outs(DisasContext
*s
, int ot
)
1220 gen_string_movl_A0_ESI(s
);
1221 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1223 gen_op_mov_TN_reg(OT_WORD
, 1, R_EDX
);
1224 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[1]);
1225 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
1226 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[0]);
1227 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
1229 gen_op_movl_T0_Dshift(ot
);
1230 gen_op_add_reg_T0(s
->aflag
, R_ESI
);
1235 /* same method as Valgrind : we generate jumps to current or next
1237 #define GEN_REPZ(op) \
1238 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1239 target_ulong cur_eip, target_ulong next_eip) \
1242 gen_update_cc_op(s); \
1243 l2 = gen_jz_ecx_string(s, next_eip); \
1244 gen_ ## op(s, ot); \
1245 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1246 /* a loop would cause two single step exceptions if ECX = 1 \
1247 before rep string_insn */ \
1249 gen_op_jz_ecx(s->aflag, l2); \
1250 gen_jmp(s, cur_eip); \
1253 #define GEN_REPZ2(op) \
1254 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1255 target_ulong cur_eip, \
1256 target_ulong next_eip, \
1260 gen_update_cc_op(s); \
1261 l2 = gen_jz_ecx_string(s, next_eip); \
1262 gen_ ## op(s, ot); \
1263 gen_op_add_reg_im(s->aflag, R_ECX, -1); \
1264 gen_op_set_cc_op(CC_OP_SUBB + ot); \
1265 gen_jcc1(s, CC_OP_SUBB + ot, (JCC_Z << 1) | (nz ^ 1), l2); \
1267 gen_op_jz_ecx(s->aflag, l2); \
1268 gen_jmp(s, cur_eip); \
1279 static void gen_helper_fp_arith_ST0_FT0(int op
)
1282 case 0: gen_helper_fadd_ST0_FT0(); break;
1283 case 1: gen_helper_fmul_ST0_FT0(); break;
1284 case 2: gen_helper_fcom_ST0_FT0(); break;
1285 case 3: gen_helper_fcom_ST0_FT0(); break;
1286 case 4: gen_helper_fsub_ST0_FT0(); break;
1287 case 5: gen_helper_fsubr_ST0_FT0(); break;
1288 case 6: gen_helper_fdiv_ST0_FT0(); break;
1289 case 7: gen_helper_fdivr_ST0_FT0(); break;
1293 /* NOTE the exception in "r" op ordering */
1294 static void gen_helper_fp_arith_STN_ST0(int op
, int opreg
)
1296 TCGv_i32 tmp
= tcg_const_i32(opreg
);
1298 case 0: gen_helper_fadd_STN_ST0(tmp
); break;
1299 case 1: gen_helper_fmul_STN_ST0(tmp
); break;
1300 case 4: gen_helper_fsubr_STN_ST0(tmp
); break;
1301 case 5: gen_helper_fsub_STN_ST0(tmp
); break;
1302 case 6: gen_helper_fdivr_STN_ST0(tmp
); break;
1303 case 7: gen_helper_fdiv_STN_ST0(tmp
); break;
1307 /* if d == OR_TMP0, it means memory operand (address in A0) */
1308 static void gen_op(DisasContext
*s1
, int op
, int ot
, int d
)
1311 gen_op_mov_TN_reg(ot
, 0, d
);
1313 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1317 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1318 gen_op_set_cc_op(s1
->cc_op
);
1319 gen_compute_eflags_c(cpu_tmp4
);
1320 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1321 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1323 gen_op_mov_reg_T0(ot
, d
);
1325 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1326 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1327 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1328 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1329 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1330 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_ADDB
+ ot
);
1331 s1
->cc_op
= CC_OP_DYNAMIC
;
1334 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1335 gen_op_set_cc_op(s1
->cc_op
);
1336 gen_compute_eflags_c(cpu_tmp4
);
1337 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1338 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_tmp4
);
1340 gen_op_mov_reg_T0(ot
, d
);
1342 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1343 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[1]);
1344 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1345 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp4
);
1346 tcg_gen_shli_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 2);
1347 tcg_gen_addi_i32(cpu_cc_op
, cpu_tmp2_i32
, CC_OP_SUBB
+ ot
);
1348 s1
->cc_op
= CC_OP_DYNAMIC
;
1351 gen_op_addl_T0_T1();
1353 gen_op_mov_reg_T0(ot
, d
);
1355 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1356 gen_op_update2_cc();
1357 s1
->cc_op
= CC_OP_ADDB
+ ot
;
1360 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1362 gen_op_mov_reg_T0(ot
, d
);
1364 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1365 gen_op_update2_cc();
1366 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1370 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1372 gen_op_mov_reg_T0(ot
, d
);
1374 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1375 gen_op_update1_cc();
1376 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1379 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1381 gen_op_mov_reg_T0(ot
, d
);
1383 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1384 gen_op_update1_cc();
1385 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1388 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1390 gen_op_mov_reg_T0(ot
, d
);
1392 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1393 gen_op_update1_cc();
1394 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1397 gen_op_cmpl_T0_T1_cc();
1398 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1403 /* if d == OR_TMP0, it means memory operand (address in A0) */
1404 static void gen_inc(DisasContext
*s1
, int ot
, int d
, int c
)
1407 gen_op_mov_TN_reg(ot
, 0, d
);
1409 gen_op_ld_T0_A0(ot
+ s1
->mem_index
);
1410 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1411 gen_op_set_cc_op(s1
->cc_op
);
1413 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], 1);
1414 s1
->cc_op
= CC_OP_INCB
+ ot
;
1416 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], -1);
1417 s1
->cc_op
= CC_OP_DECB
+ ot
;
1420 gen_op_mov_reg_T0(ot
, d
);
1422 gen_op_st_T0_A0(ot
+ s1
->mem_index
);
1423 gen_compute_eflags_c(cpu_cc_src
);
1424 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1427 static void gen_shift_rm_T1(DisasContext
*s
, int ot
, int op1
,
1428 int is_right
, int is_arith
)
1441 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1443 gen_op_mov_TN_reg(ot
, 0, op1
);
1445 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], mask
);
1447 tcg_gen_addi_tl(cpu_tmp5
, cpu_T
[1], -1);
1451 gen_exts(ot
, cpu_T
[0]);
1452 tcg_gen_sar_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1453 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1455 gen_extu(ot
, cpu_T
[0]);
1456 tcg_gen_shr_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1457 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1460 tcg_gen_shl_tl(cpu_T3
, cpu_T
[0], cpu_tmp5
);
1461 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1466 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1468 gen_op_mov_reg_T0(ot
, op1
);
1470 /* update eflags if non zero shift */
1471 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1472 gen_op_set_cc_op(s
->cc_op
);
1474 /* XXX: inefficient */
1475 t0
= tcg_temp_local_new();
1476 t1
= tcg_temp_local_new();
1478 tcg_gen_mov_tl(t0
, cpu_T
[0]);
1479 tcg_gen_mov_tl(t1
, cpu_T3
);
1481 shift_label
= gen_new_label();
1482 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, shift_label
);
1484 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1485 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1487 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1489 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1491 gen_set_label(shift_label
);
1492 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1498 static void gen_shift_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1499 int is_right
, int is_arith
)
1510 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1512 gen_op_mov_TN_reg(ot
, 0, op1
);
1518 gen_exts(ot
, cpu_T
[0]);
1519 tcg_gen_sari_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1520 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], op2
);
1522 gen_extu(ot
, cpu_T
[0]);
1523 tcg_gen_shri_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1524 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], op2
);
1527 tcg_gen_shli_tl(cpu_tmp4
, cpu_T
[0], op2
- 1);
1528 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], op2
);
1534 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1536 gen_op_mov_reg_T0(ot
, op1
);
1538 /* update eflags if non zero shift */
1540 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
1541 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
1543 s
->cc_op
= CC_OP_SARB
+ ot
;
1545 s
->cc_op
= CC_OP_SHLB
+ ot
;
1549 static inline void tcg_gen_lshift(TCGv ret
, TCGv arg1
, target_long arg2
)
1552 tcg_gen_shli_tl(ret
, arg1
, arg2
);
1554 tcg_gen_shri_tl(ret
, arg1
, -arg2
);
1557 static void gen_rot_rm_T1(DisasContext
*s
, int ot
, int op1
,
1561 int label1
, label2
, data_bits
;
1562 TCGv t0
, t1
, t2
, a0
;
1564 /* XXX: inefficient, but we must use local temps */
1565 t0
= tcg_temp_local_new();
1566 t1
= tcg_temp_local_new();
1567 t2
= tcg_temp_local_new();
1568 a0
= tcg_temp_local_new();
1576 if (op1
== OR_TMP0
) {
1577 tcg_gen_mov_tl(a0
, cpu_A0
);
1578 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1580 gen_op_mov_v_reg(ot
, t0
, op1
);
1583 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1585 tcg_gen_andi_tl(t1
, t1
, mask
);
1587 /* Must test zero case to avoid using undefined behaviour in TCG
1589 label1
= gen_new_label();
1590 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label1
);
1593 tcg_gen_andi_tl(cpu_tmp0
, t1
, (1 << (3 + ot
)) - 1);
1595 tcg_gen_mov_tl(cpu_tmp0
, t1
);
1598 tcg_gen_mov_tl(t2
, t0
);
1600 data_bits
= 8 << ot
;
1601 /* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
1602 fix TCG definition) */
1604 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1605 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1606 tcg_gen_shl_tl(t0
, t0
, cpu_tmp0
);
1608 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp0
);
1609 tcg_gen_subfi_tl(cpu_tmp0
, data_bits
, cpu_tmp0
);
1610 tcg_gen_shr_tl(t0
, t0
, cpu_tmp0
);
1612 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1614 gen_set_label(label1
);
1616 if (op1
== OR_TMP0
) {
1617 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1619 gen_op_mov_reg_v(ot
, op1
, t0
);
1623 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1624 gen_op_set_cc_op(s
->cc_op
);
1626 label2
= gen_new_label();
1627 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, label2
);
1629 gen_compute_eflags(cpu_cc_src
);
1630 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1631 tcg_gen_xor_tl(cpu_tmp0
, t2
, t0
);
1632 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1633 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1634 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1636 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1638 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1639 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1641 tcg_gen_discard_tl(cpu_cc_dst
);
1642 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1644 gen_set_label(label2
);
1645 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1653 static void gen_rot_rm_im(DisasContext
*s
, int ot
, int op1
, int op2
,
1660 /* XXX: inefficient, but we must use local temps */
1661 t0
= tcg_temp_local_new();
1662 t1
= tcg_temp_local_new();
1663 a0
= tcg_temp_local_new();
1671 if (op1
== OR_TMP0
) {
1672 tcg_gen_mov_tl(a0
, cpu_A0
);
1673 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1675 gen_op_mov_v_reg(ot
, t0
, op1
);
1679 tcg_gen_mov_tl(t1
, t0
);
1682 data_bits
= 8 << ot
;
1684 int shift
= op2
& ((1 << (3 + ot
)) - 1);
1686 tcg_gen_shri_tl(cpu_tmp4
, t0
, shift
);
1687 tcg_gen_shli_tl(t0
, t0
, data_bits
- shift
);
1690 tcg_gen_shli_tl(cpu_tmp4
, t0
, shift
);
1691 tcg_gen_shri_tl(t0
, t0
, data_bits
- shift
);
1693 tcg_gen_or_tl(t0
, t0
, cpu_tmp4
);
1697 if (op1
== OR_TMP0
) {
1698 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1700 gen_op_mov_reg_v(ot
, op1
, t0
);
1705 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1706 gen_op_set_cc_op(s
->cc_op
);
1708 gen_compute_eflags(cpu_cc_src
);
1709 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~(CC_O
| CC_C
));
1710 tcg_gen_xor_tl(cpu_tmp0
, t1
, t0
);
1711 tcg_gen_lshift(cpu_tmp0
, cpu_tmp0
, 11 - (data_bits
- 1));
1712 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_O
);
1713 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_tmp0
);
1715 tcg_gen_shri_tl(t0
, t0
, data_bits
- 1);
1717 tcg_gen_andi_tl(t0
, t0
, CC_C
);
1718 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t0
);
1720 tcg_gen_discard_tl(cpu_cc_dst
);
1721 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1722 s
->cc_op
= CC_OP_EFLAGS
;
1730 /* XXX: add faster immediate = 1 case */
1731 static void gen_rotc_rm_T1(DisasContext
*s
, int ot
, int op1
,
1736 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1737 gen_op_set_cc_op(s
->cc_op
);
1741 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
1743 gen_op_mov_TN_reg(ot
, 0, op1
);
1747 case 0: gen_helper_rcrb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1748 case 1: gen_helper_rcrw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1749 case 2: gen_helper_rcrl(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1750 #ifdef TARGET_X86_64
1751 case 3: gen_helper_rcrq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1756 case 0: gen_helper_rclb(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1757 case 1: gen_helper_rclw(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1758 case 2: gen_helper_rcll(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1759 #ifdef TARGET_X86_64
1760 case 3: gen_helper_rclq(cpu_T
[0], cpu_T
[0], cpu_T
[1]); break;
1766 gen_op_st_T0_A0(ot
+ s
->mem_index
);
1768 gen_op_mov_reg_T0(ot
, op1
);
1771 label1
= gen_new_label();
1772 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_cc_tmp
, -1, label1
);
1774 tcg_gen_mov_tl(cpu_cc_src
, cpu_cc_tmp
);
1775 tcg_gen_discard_tl(cpu_cc_dst
);
1776 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_EFLAGS
);
1778 gen_set_label(label1
);
1779 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1782 /* XXX: add faster immediate case */
1783 static void gen_shiftd_rm_T1_T3(DisasContext
*s
, int ot
, int op1
,
1786 int label1
, label2
, data_bits
;
1788 TCGv t0
, t1
, t2
, a0
;
1790 t0
= tcg_temp_local_new();
1791 t1
= tcg_temp_local_new();
1792 t2
= tcg_temp_local_new();
1793 a0
= tcg_temp_local_new();
1801 if (op1
== OR_TMP0
) {
1802 tcg_gen_mov_tl(a0
, cpu_A0
);
1803 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
1805 gen_op_mov_v_reg(ot
, t0
, op1
);
1808 tcg_gen_andi_tl(cpu_T3
, cpu_T3
, mask
);
1810 tcg_gen_mov_tl(t1
, cpu_T
[1]);
1811 tcg_gen_mov_tl(t2
, cpu_T3
);
1813 /* Must test zero case to avoid using undefined behaviour in TCG
1815 label1
= gen_new_label();
1816 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
1818 tcg_gen_addi_tl(cpu_tmp5
, t2
, -1);
1819 if (ot
== OT_WORD
) {
1820 /* Note: we implement the Intel behaviour for shift count > 16 */
1822 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1823 tcg_gen_shli_tl(cpu_tmp0
, t1
, 16);
1824 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1825 tcg_gen_ext32u_tl(t0
, t0
);
1827 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1829 /* only needed if count > 16, but a test would complicate */
1830 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1831 tcg_gen_shl_tl(cpu_tmp0
, t0
, cpu_tmp5
);
1833 tcg_gen_shr_tl(t0
, t0
, t2
);
1835 tcg_gen_or_tl(t0
, t0
, cpu_tmp0
);
1837 /* XXX: not optimal */
1838 tcg_gen_andi_tl(t0
, t0
, 0xffff);
1839 tcg_gen_shli_tl(t1
, t1
, 16);
1840 tcg_gen_or_tl(t1
, t1
, t0
);
1841 tcg_gen_ext32u_tl(t1
, t1
);
1843 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1844 tcg_gen_subfi_tl(cpu_tmp0
, 32, cpu_tmp5
);
1845 tcg_gen_shr_tl(cpu_tmp5
, t1
, cpu_tmp0
);
1846 tcg_gen_or_tl(cpu_tmp4
, cpu_tmp4
, cpu_tmp5
);
1848 tcg_gen_shl_tl(t0
, t0
, t2
);
1849 tcg_gen_subfi_tl(cpu_tmp5
, 32, t2
);
1850 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1851 tcg_gen_or_tl(t0
, t0
, t1
);
1854 data_bits
= 8 << ot
;
1857 tcg_gen_ext32u_tl(t0
, t0
);
1859 tcg_gen_shr_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1861 tcg_gen_shr_tl(t0
, t0
, t2
);
1862 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1863 tcg_gen_shl_tl(t1
, t1
, cpu_tmp5
);
1864 tcg_gen_or_tl(t0
, t0
, t1
);
1868 tcg_gen_ext32u_tl(t1
, t1
);
1870 tcg_gen_shl_tl(cpu_tmp4
, t0
, cpu_tmp5
);
1872 tcg_gen_shl_tl(t0
, t0
, t2
);
1873 tcg_gen_subfi_tl(cpu_tmp5
, data_bits
, t2
);
1874 tcg_gen_shr_tl(t1
, t1
, cpu_tmp5
);
1875 tcg_gen_or_tl(t0
, t0
, t1
);
1878 tcg_gen_mov_tl(t1
, cpu_tmp4
);
1880 gen_set_label(label1
);
1882 if (op1
== OR_TMP0
) {
1883 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
1885 gen_op_mov_reg_v(ot
, op1
, t0
);
1889 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1890 gen_op_set_cc_op(s
->cc_op
);
1892 label2
= gen_new_label();
1893 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label2
);
1895 tcg_gen_mov_tl(cpu_cc_src
, t1
);
1896 tcg_gen_mov_tl(cpu_cc_dst
, t0
);
1898 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SARB
+ ot
);
1900 tcg_gen_movi_i32(cpu_cc_op
, CC_OP_SHLB
+ ot
);
1902 gen_set_label(label2
);
1903 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1911 static void gen_shift(DisasContext
*s1
, int op
, int ot
, int d
, int s
)
1914 gen_op_mov_TN_reg(ot
, 1, s
);
1917 gen_rot_rm_T1(s1
, ot
, d
, 0);
1920 gen_rot_rm_T1(s1
, ot
, d
, 1);
1924 gen_shift_rm_T1(s1
, ot
, d
, 0, 0);
1927 gen_shift_rm_T1(s1
, ot
, d
, 1, 0);
1930 gen_shift_rm_T1(s1
, ot
, d
, 1, 1);
1933 gen_rotc_rm_T1(s1
, ot
, d
, 0);
1936 gen_rotc_rm_T1(s1
, ot
, d
, 1);
1941 static void gen_shifti(DisasContext
*s1
, int op
, int ot
, int d
, int c
)
1945 gen_rot_rm_im(s1
, ot
, d
, c
, 0);
1948 gen_rot_rm_im(s1
, ot
, d
, c
, 1);
1952 gen_shift_rm_im(s1
, ot
, d
, c
, 0, 0);
1955 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 0);
1958 gen_shift_rm_im(s1
, ot
, d
, c
, 1, 1);
1961 /* currently not optimized */
1962 gen_op_movl_T1_im(c
);
1963 gen_shift(s1
, op
, ot
, d
, OR_TMP1
);
1968 static void gen_lea_modrm(DisasContext
*s
, int modrm
, int *reg_ptr
, int *offset_ptr
)
1976 int mod
, rm
, code
, override
, must_add_seg
;
1978 override
= s
->override
;
1979 must_add_seg
= s
->addseg
;
1982 mod
= (modrm
>> 6) & 3;
1994 code
= ldub_code(s
->pc
++);
1995 scale
= (code
>> 6) & 3;
1996 index
= ((code
>> 3) & 7) | REX_X(s
);
2003 if ((base
& 7) == 5) {
2005 disp
= (int32_t)ldl_code(s
->pc
);
2007 if (CODE64(s
) && !havesib
) {
2008 disp
+= s
->pc
+ s
->rip_offset
;
2015 disp
= (int8_t)ldub_code(s
->pc
++);
2019 disp
= ldl_code(s
->pc
);
2025 /* for correct popl handling with esp */
2026 if (base
== 4 && s
->popl_esp_hack
)
2027 disp
+= s
->popl_esp_hack
;
2028 #ifdef TARGET_X86_64
2029 if (s
->aflag
== 2) {
2030 gen_op_movq_A0_reg(base
);
2032 gen_op_addq_A0_im(disp
);
2037 gen_op_movl_A0_reg(base
);
2039 gen_op_addl_A0_im(disp
);
2042 #ifdef TARGET_X86_64
2043 if (s
->aflag
== 2) {
2044 gen_op_movq_A0_im(disp
);
2048 gen_op_movl_A0_im(disp
);
2051 /* index == 4 means no index */
2052 if (havesib
&& (index
!= 4)) {
2053 #ifdef TARGET_X86_64
2054 if (s
->aflag
== 2) {
2055 gen_op_addq_A0_reg_sN(scale
, index
);
2059 gen_op_addl_A0_reg_sN(scale
, index
);
2064 if (base
== R_EBP
|| base
== R_ESP
)
2069 #ifdef TARGET_X86_64
2070 if (s
->aflag
== 2) {
2071 gen_op_addq_A0_seg(override
);
2075 gen_op_addl_A0_seg(override
);
2082 disp
= lduw_code(s
->pc
);
2084 gen_op_movl_A0_im(disp
);
2085 rm
= 0; /* avoid SS override */
2092 disp
= (int8_t)ldub_code(s
->pc
++);
2096 disp
= lduw_code(s
->pc
);
2102 gen_op_movl_A0_reg(R_EBX
);
2103 gen_op_addl_A0_reg_sN(0, R_ESI
);
2106 gen_op_movl_A0_reg(R_EBX
);
2107 gen_op_addl_A0_reg_sN(0, R_EDI
);
2110 gen_op_movl_A0_reg(R_EBP
);
2111 gen_op_addl_A0_reg_sN(0, R_ESI
);
2114 gen_op_movl_A0_reg(R_EBP
);
2115 gen_op_addl_A0_reg_sN(0, R_EDI
);
2118 gen_op_movl_A0_reg(R_ESI
);
2121 gen_op_movl_A0_reg(R_EDI
);
2124 gen_op_movl_A0_reg(R_EBP
);
2128 gen_op_movl_A0_reg(R_EBX
);
2132 gen_op_addl_A0_im(disp
);
2133 gen_op_andl_A0_ffff();
2137 if (rm
== 2 || rm
== 3 || rm
== 6)
2142 gen_op_addl_A0_seg(override
);
2152 static void gen_nop_modrm(DisasContext
*s
, int modrm
)
2154 int mod
, rm
, base
, code
;
2156 mod
= (modrm
>> 6) & 3;
2166 code
= ldub_code(s
->pc
++);
2202 /* used for LEA and MOV AX, mem */
2203 static void gen_add_A0_ds_seg(DisasContext
*s
)
2205 int override
, must_add_seg
;
2206 must_add_seg
= s
->addseg
;
2208 if (s
->override
>= 0) {
2209 override
= s
->override
;
2213 #ifdef TARGET_X86_64
2215 gen_op_addq_A0_seg(override
);
2219 gen_op_addl_A0_seg(override
);
2224 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
2226 static void gen_ldst_modrm(DisasContext
*s
, int modrm
, int ot
, int reg
, int is_store
)
2228 int mod
, rm
, opreg
, disp
;
2230 mod
= (modrm
>> 6) & 3;
2231 rm
= (modrm
& 7) | REX_B(s
);
2235 gen_op_mov_TN_reg(ot
, 0, reg
);
2236 gen_op_mov_reg_T0(ot
, rm
);
2238 gen_op_mov_TN_reg(ot
, 0, rm
);
2240 gen_op_mov_reg_T0(ot
, reg
);
2243 gen_lea_modrm(s
, modrm
, &opreg
, &disp
);
2246 gen_op_mov_TN_reg(ot
, 0, reg
);
2247 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2249 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
2251 gen_op_mov_reg_T0(ot
, reg
);
2256 static inline uint32_t insn_get(DisasContext
*s
, int ot
)
2262 ret
= ldub_code(s
->pc
);
2266 ret
= lduw_code(s
->pc
);
2271 ret
= ldl_code(s
->pc
);
2278 static inline int insn_const_size(unsigned int ot
)
2286 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong eip
)
2288 TranslationBlock
*tb
;
2291 pc
= s
->cs_base
+ eip
;
2293 /* NOTE: we handle the case where the TB spans two pages here */
2294 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) ||
2295 (pc
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
)) {
2296 /* jump to same page: we can use a direct jump */
2297 tcg_gen_goto_tb(tb_num
);
2299 tcg_gen_exit_tb((long)tb
+ tb_num
);
2301 /* jump to another page: currently not optimized */
2307 static inline void gen_jcc(DisasContext
*s
, int b
,
2308 target_ulong val
, target_ulong next_eip
)
2313 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2314 gen_op_set_cc_op(s
->cc_op
);
2315 s
->cc_op
= CC_OP_DYNAMIC
;
2318 l1
= gen_new_label();
2319 gen_jcc1(s
, cc_op
, b
, l1
);
2321 gen_goto_tb(s
, 0, next_eip
);
2324 gen_goto_tb(s
, 1, val
);
2328 l1
= gen_new_label();
2329 l2
= gen_new_label();
2330 gen_jcc1(s
, cc_op
, b
, l1
);
2332 gen_jmp_im(next_eip
);
2342 static void gen_setcc(DisasContext
*s
, int b
)
2344 int inv
, jcc_op
, l1
;
2347 if (is_fast_jcc_case(s
, b
)) {
2348 /* nominal case: we use a jump */
2349 /* XXX: make it faster by adding new instructions in TCG */
2350 t0
= tcg_temp_local_new();
2351 tcg_gen_movi_tl(t0
, 0);
2352 l1
= gen_new_label();
2353 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
2354 tcg_gen_movi_tl(t0
, 1);
2356 tcg_gen_mov_tl(cpu_T
[0], t0
);
2359 /* slow case: it is more efficient not to generate a jump,
2360 although it is questionnable whether this optimization is
2363 jcc_op
= (b
>> 1) & 7;
2364 gen_setcc_slow_T0(s
, jcc_op
);
2366 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
2371 static inline void gen_op_movl_T0_seg(int seg_reg
)
2373 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
2374 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2377 static inline void gen_op_movl_seg_T0_vm(int seg_reg
)
2379 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
2380 tcg_gen_st32_tl(cpu_T
[0], cpu_env
,
2381 offsetof(CPUX86State
,segs
[seg_reg
].selector
));
2382 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], 4);
2383 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
2384 offsetof(CPUX86State
,segs
[seg_reg
].base
));
2387 /* move T0 to seg_reg and compute if the CPU state may change. Never
2388 call this function with seg_reg == R_CS */
2389 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
2391 if (s
->pe
&& !s
->vm86
) {
2392 /* XXX: optimize by finding processor state dynamically */
2393 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2394 gen_op_set_cc_op(s
->cc_op
);
2395 gen_jmp_im(cur_eip
);
2396 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
2397 gen_helper_load_seg(tcg_const_i32(seg_reg
), cpu_tmp2_i32
);
2398 /* abort translation because the addseg value may change or
2399 because ss32 may change. For R_SS, translation must always
2400 stop as a special handling must be done to disable hardware
2401 interrupts for the next instruction */
2402 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
2405 gen_op_movl_seg_T0_vm(seg_reg
);
2406 if (seg_reg
== R_SS
)
2411 static inline int svm_is_rep(int prefixes
)
2413 return ((prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) ? 8 : 0);
2417 gen_svm_check_intercept_param(DisasContext
*s
, target_ulong pc_start
,
2418 uint32_t type
, uint64_t param
)
2420 /* no SVM activated; fast case */
2421 if (likely(!(s
->flags
& HF_SVMI_MASK
)))
2423 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2424 gen_op_set_cc_op(s
->cc_op
);
2425 gen_jmp_im(pc_start
- s
->cs_base
);
2426 gen_helper_svm_check_intercept_param(tcg_const_i32(type
),
2427 tcg_const_i64(param
));
2431 gen_svm_check_intercept(DisasContext
*s
, target_ulong pc_start
, uint64_t type
)
2433 gen_svm_check_intercept_param(s
, pc_start
, type
, 0);
2436 static inline void gen_stack_update(DisasContext
*s
, int addend
)
2438 #ifdef TARGET_X86_64
2440 gen_op_add_reg_im(2, R_ESP
, addend
);
2444 gen_op_add_reg_im(1, R_ESP
, addend
);
2446 gen_op_add_reg_im(0, R_ESP
, addend
);
2450 /* generate a push. It depends on ss32, addseg and dflag */
2451 static void gen_push_T0(DisasContext
*s
)
2453 #ifdef TARGET_X86_64
2455 gen_op_movq_A0_reg(R_ESP
);
2457 gen_op_addq_A0_im(-8);
2458 gen_op_st_T0_A0(OT_QUAD
+ s
->mem_index
);
2460 gen_op_addq_A0_im(-2);
2461 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2463 gen_op_mov_reg_A0(2, R_ESP
);
2467 gen_op_movl_A0_reg(R_ESP
);
2469 gen_op_addl_A0_im(-2);
2471 gen_op_addl_A0_im(-4);
2474 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2475 gen_op_addl_A0_seg(R_SS
);
2478 gen_op_andl_A0_ffff();
2479 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2480 gen_op_addl_A0_seg(R_SS
);
2482 gen_op_st_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2483 if (s
->ss32
&& !s
->addseg
)
2484 gen_op_mov_reg_A0(1, R_ESP
);
2486 gen_op_mov_reg_T1(s
->ss32
+ 1, R_ESP
);
2490 /* generate a push. It depends on ss32, addseg and dflag */
2491 /* slower version for T1, only used for call Ev */
2492 static void gen_push_T1(DisasContext
*s
)
2494 #ifdef TARGET_X86_64
2496 gen_op_movq_A0_reg(R_ESP
);
2498 gen_op_addq_A0_im(-8);
2499 gen_op_st_T1_A0(OT_QUAD
+ s
->mem_index
);
2501 gen_op_addq_A0_im(-2);
2502 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
2504 gen_op_mov_reg_A0(2, R_ESP
);
2508 gen_op_movl_A0_reg(R_ESP
);
2510 gen_op_addl_A0_im(-2);
2512 gen_op_addl_A0_im(-4);
2515 gen_op_addl_A0_seg(R_SS
);
2518 gen_op_andl_A0_ffff();
2519 gen_op_addl_A0_seg(R_SS
);
2521 gen_op_st_T1_A0(s
->dflag
+ 1 + s
->mem_index
);
2523 if (s
->ss32
&& !s
->addseg
)
2524 gen_op_mov_reg_A0(1, R_ESP
);
2526 gen_stack_update(s
, (-2) << s
->dflag
);
2530 /* two step pop is necessary for precise exceptions */
2531 static void gen_pop_T0(DisasContext
*s
)
2533 #ifdef TARGET_X86_64
2535 gen_op_movq_A0_reg(R_ESP
);
2536 gen_op_ld_T0_A0((s
->dflag
? OT_QUAD
: OT_WORD
) + s
->mem_index
);
2540 gen_op_movl_A0_reg(R_ESP
);
2543 gen_op_addl_A0_seg(R_SS
);
2545 gen_op_andl_A0_ffff();
2546 gen_op_addl_A0_seg(R_SS
);
2548 gen_op_ld_T0_A0(s
->dflag
+ 1 + s
->mem_index
);
2552 static void gen_pop_update(DisasContext
*s
)
2554 #ifdef TARGET_X86_64
2555 if (CODE64(s
) && s
->dflag
) {
2556 gen_stack_update(s
, 8);
2560 gen_stack_update(s
, 2 << s
->dflag
);
2564 static void gen_stack_A0(DisasContext
*s
)
2566 gen_op_movl_A0_reg(R_ESP
);
2568 gen_op_andl_A0_ffff();
2569 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2571 gen_op_addl_A0_seg(R_SS
);
2574 /* NOTE: wrap around in 16 bit not fully handled */
2575 static void gen_pusha(DisasContext
*s
)
2578 gen_op_movl_A0_reg(R_ESP
);
2579 gen_op_addl_A0_im(-16 << s
->dflag
);
2581 gen_op_andl_A0_ffff();
2582 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2584 gen_op_addl_A0_seg(R_SS
);
2585 for(i
= 0;i
< 8; i
++) {
2586 gen_op_mov_TN_reg(OT_LONG
, 0, 7 - i
);
2587 gen_op_st_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2588 gen_op_addl_A0_im(2 << s
->dflag
);
2590 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2593 /* NOTE: wrap around in 16 bit not fully handled */
2594 static void gen_popa(DisasContext
*s
)
2597 gen_op_movl_A0_reg(R_ESP
);
2599 gen_op_andl_A0_ffff();
2600 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2601 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], 16 << s
->dflag
);
2603 gen_op_addl_A0_seg(R_SS
);
2604 for(i
= 0;i
< 8; i
++) {
2605 /* ESP is not reloaded */
2607 gen_op_ld_T0_A0(OT_WORD
+ s
->dflag
+ s
->mem_index
);
2608 gen_op_mov_reg_T0(OT_WORD
+ s
->dflag
, 7 - i
);
2610 gen_op_addl_A0_im(2 << s
->dflag
);
2612 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2615 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2620 #ifdef TARGET_X86_64
2622 ot
= s
->dflag
? OT_QUAD
: OT_WORD
;
2625 gen_op_movl_A0_reg(R_ESP
);
2626 gen_op_addq_A0_im(-opsize
);
2627 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2630 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2631 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2633 /* XXX: must save state */
2634 gen_helper_enter64_level(tcg_const_i32(level
),
2635 tcg_const_i32((ot
== OT_QUAD
)),
2638 gen_op_mov_reg_T1(ot
, R_EBP
);
2639 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2640 gen_op_mov_reg_T1(OT_QUAD
, R_ESP
);
2644 ot
= s
->dflag
+ OT_WORD
;
2645 opsize
= 2 << s
->dflag
;
2647 gen_op_movl_A0_reg(R_ESP
);
2648 gen_op_addl_A0_im(-opsize
);
2650 gen_op_andl_A0_ffff();
2651 tcg_gen_mov_tl(cpu_T
[1], cpu_A0
);
2653 gen_op_addl_A0_seg(R_SS
);
2655 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
2656 gen_op_st_T0_A0(ot
+ s
->mem_index
);
2658 /* XXX: must save state */
2659 gen_helper_enter_level(tcg_const_i32(level
),
2660 tcg_const_i32(s
->dflag
),
2663 gen_op_mov_reg_T1(ot
, R_EBP
);
2664 tcg_gen_addi_tl(cpu_T
[1], cpu_T
[1], -esp_addend
+ (-opsize
* level
));
2665 gen_op_mov_reg_T1(OT_WORD
+ s
->ss32
, R_ESP
);
2669 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2671 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2672 gen_op_set_cc_op(s
->cc_op
);
2673 gen_jmp_im(cur_eip
);
2674 gen_helper_raise_exception(tcg_const_i32(trapno
));
2678 /* an interrupt is different from an exception because of the
2680 static void gen_interrupt(DisasContext
*s
, int intno
,
2681 target_ulong cur_eip
, target_ulong next_eip
)
2683 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2684 gen_op_set_cc_op(s
->cc_op
);
2685 gen_jmp_im(cur_eip
);
2686 gen_helper_raise_interrupt(tcg_const_i32(intno
),
2687 tcg_const_i32(next_eip
- cur_eip
));
2691 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2693 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2694 gen_op_set_cc_op(s
->cc_op
);
2695 gen_jmp_im(cur_eip
);
2700 /* generate a generic end of block. Trace exception is also generated
2702 static void gen_eob(DisasContext
*s
)
2704 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2705 gen_op_set_cc_op(s
->cc_op
);
2706 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2707 gen_helper_reset_inhibit_irq();
2709 if (s
->tb
->flags
& HF_RF_MASK
) {
2710 gen_helper_reset_rf();
2712 if (s
->singlestep_enabled
) {
2715 gen_helper_single_step();
2722 /* generate a jump to eip. No segment change must happen before as a
2723 direct call to the next block may occur */
2724 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2727 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
2728 gen_op_set_cc_op(s
->cc_op
);
2729 s
->cc_op
= CC_OP_DYNAMIC
;
2731 gen_goto_tb(s
, tb_num
, eip
);
2739 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2741 gen_jmp_tb(s
, eip
, 0);
2744 static inline void gen_ldq_env_A0(int idx
, int offset
)
2746 int mem_index
= (idx
>> 2) - 1;
2747 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2748 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2751 static inline void gen_stq_env_A0(int idx
, int offset
)
2753 int mem_index
= (idx
>> 2) - 1;
2754 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
);
2755 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2758 static inline void gen_ldo_env_A0(int idx
, int offset
)
2760 int mem_index
= (idx
>> 2) - 1;
2761 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2762 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2763 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2764 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2765 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2768 static inline void gen_sto_env_A0(int idx
, int offset
)
2770 int mem_index
= (idx
>> 2) - 1;
2771 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(0)));
2772 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
, mem_index
);
2773 tcg_gen_addi_tl(cpu_tmp0
, cpu_A0
, 8);
2774 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, offset
+ offsetof(XMMReg
, XMM_Q(1)));
2775 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_tmp0
, mem_index
);
2778 static inline void gen_op_movo(int d_offset
, int s_offset
)
2780 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2781 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2782 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
+ 8);
2783 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
+ 8);
2786 static inline void gen_op_movq(int d_offset
, int s_offset
)
2788 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
, s_offset
);
2789 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2792 static inline void gen_op_movl(int d_offset
, int s_offset
)
2794 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
, s_offset
);
2795 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, d_offset
);
2798 static inline void gen_op_movq_env_0(int d_offset
)
2800 tcg_gen_movi_i64(cpu_tmp1_i64
, 0);
2801 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
, d_offset
);
2804 #define SSE_SPECIAL ((void *)1)
2805 #define SSE_DUMMY ((void *)2)
2807 #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm }
2808 #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \
2809 gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, }
2811 static void *sse_op_table1
[256][4] = {
2812 /* 3DNow! extensions */
2813 [0x0e] = { SSE_DUMMY
}, /* femms */
2814 [0x0f] = { SSE_DUMMY
}, /* pf... */
2815 /* pure SSE operations */
2816 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2817 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2818 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd, movsldup, movddup */
2819 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2820 [0x14] = { gen_helper_punpckldq_xmm
, gen_helper_punpcklqdq_xmm
},
2821 [0x15] = { gen_helper_punpckhdq_xmm
, gen_helper_punpckhqdq_xmm
},
2822 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2823 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2825 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2826 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2827 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2828 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd, movntss, movntsd */
2829 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2830 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2831 [0x2e] = { gen_helper_ucomiss
, gen_helper_ucomisd
},
2832 [0x2f] = { gen_helper_comiss
, gen_helper_comisd
},
2833 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2834 [0x51] = SSE_FOP(sqrt
),
2835 [0x52] = { gen_helper_rsqrtps
, NULL
, gen_helper_rsqrtss
, NULL
},
2836 [0x53] = { gen_helper_rcpps
, NULL
, gen_helper_rcpss
, NULL
},
2837 [0x54] = { gen_helper_pand_xmm
, gen_helper_pand_xmm
}, /* andps, andpd */
2838 [0x55] = { gen_helper_pandn_xmm
, gen_helper_pandn_xmm
}, /* andnps, andnpd */
2839 [0x56] = { gen_helper_por_xmm
, gen_helper_por_xmm
}, /* orps, orpd */
2840 [0x57] = { gen_helper_pxor_xmm
, gen_helper_pxor_xmm
}, /* xorps, xorpd */
2841 [0x58] = SSE_FOP(add
),
2842 [0x59] = SSE_FOP(mul
),
2843 [0x5a] = { gen_helper_cvtps2pd
, gen_helper_cvtpd2ps
,
2844 gen_helper_cvtss2sd
, gen_helper_cvtsd2ss
},
2845 [0x5b] = { gen_helper_cvtdq2ps
, gen_helper_cvtps2dq
, gen_helper_cvttps2dq
},
2846 [0x5c] = SSE_FOP(sub
),
2847 [0x5d] = SSE_FOP(min
),
2848 [0x5e] = SSE_FOP(div
),
2849 [0x5f] = SSE_FOP(max
),
2851 [0xc2] = SSE_FOP(cmpeq
),
2852 [0xc6] = { gen_helper_shufps
, gen_helper_shufpd
},
2854 [0x38] = { SSE_SPECIAL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2855 [0x3a] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* SSSE3/SSE4 */
2857 /* MMX ops and their SSE extensions */
2858 [0x60] = MMX_OP2(punpcklbw
),
2859 [0x61] = MMX_OP2(punpcklwd
),
2860 [0x62] = MMX_OP2(punpckldq
),
2861 [0x63] = MMX_OP2(packsswb
),
2862 [0x64] = MMX_OP2(pcmpgtb
),
2863 [0x65] = MMX_OP2(pcmpgtw
),
2864 [0x66] = MMX_OP2(pcmpgtl
),
2865 [0x67] = MMX_OP2(packuswb
),
2866 [0x68] = MMX_OP2(punpckhbw
),
2867 [0x69] = MMX_OP2(punpckhwd
),
2868 [0x6a] = MMX_OP2(punpckhdq
),
2869 [0x6b] = MMX_OP2(packssdw
),
2870 [0x6c] = { NULL
, gen_helper_punpcklqdq_xmm
},
2871 [0x6d] = { NULL
, gen_helper_punpckhqdq_xmm
},
2872 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2873 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2874 [0x70] = { gen_helper_pshufw_mmx
,
2875 gen_helper_pshufd_xmm
,
2876 gen_helper_pshufhw_xmm
,
2877 gen_helper_pshuflw_xmm
},
2878 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2879 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2880 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2881 [0x74] = MMX_OP2(pcmpeqb
),
2882 [0x75] = MMX_OP2(pcmpeqw
),
2883 [0x76] = MMX_OP2(pcmpeql
),
2884 [0x77] = { SSE_DUMMY
}, /* emms */
2885 [0x78] = { NULL
, SSE_SPECIAL
, NULL
, SSE_SPECIAL
}, /* extrq_i, insertq_i */
2886 [0x79] = { NULL
, gen_helper_extrq_r
, NULL
, gen_helper_insertq_r
},
2887 [0x7c] = { NULL
, gen_helper_haddpd
, NULL
, gen_helper_haddps
},
2888 [0x7d] = { NULL
, gen_helper_hsubpd
, NULL
, gen_helper_hsubps
},
2889 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2890 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2891 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2892 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2893 [0xd0] = { NULL
, gen_helper_addsubpd
, NULL
, gen_helper_addsubps
},
2894 [0xd1] = MMX_OP2(psrlw
),
2895 [0xd2] = MMX_OP2(psrld
),
2896 [0xd3] = MMX_OP2(psrlq
),
2897 [0xd4] = MMX_OP2(paddq
),
2898 [0xd5] = MMX_OP2(pmullw
),
2899 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2900 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2901 [0xd8] = MMX_OP2(psubusb
),
2902 [0xd9] = MMX_OP2(psubusw
),
2903 [0xda] = MMX_OP2(pminub
),
2904 [0xdb] = MMX_OP2(pand
),
2905 [0xdc] = MMX_OP2(paddusb
),
2906 [0xdd] = MMX_OP2(paddusw
),
2907 [0xde] = MMX_OP2(pmaxub
),
2908 [0xdf] = MMX_OP2(pandn
),
2909 [0xe0] = MMX_OP2(pavgb
),
2910 [0xe1] = MMX_OP2(psraw
),
2911 [0xe2] = MMX_OP2(psrad
),
2912 [0xe3] = MMX_OP2(pavgw
),
2913 [0xe4] = MMX_OP2(pmulhuw
),
2914 [0xe5] = MMX_OP2(pmulhw
),
2915 [0xe6] = { NULL
, gen_helper_cvttpd2dq
, gen_helper_cvtdq2pd
, gen_helper_cvtpd2dq
},
2916 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2917 [0xe8] = MMX_OP2(psubsb
),
2918 [0xe9] = MMX_OP2(psubsw
),
2919 [0xea] = MMX_OP2(pminsw
),
2920 [0xeb] = MMX_OP2(por
),
2921 [0xec] = MMX_OP2(paddsb
),
2922 [0xed] = MMX_OP2(paddsw
),
2923 [0xee] = MMX_OP2(pmaxsw
),
2924 [0xef] = MMX_OP2(pxor
),
2925 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu */
2926 [0xf1] = MMX_OP2(psllw
),
2927 [0xf2] = MMX_OP2(pslld
),
2928 [0xf3] = MMX_OP2(psllq
),
2929 [0xf4] = MMX_OP2(pmuludq
),
2930 [0xf5] = MMX_OP2(pmaddwd
),
2931 [0xf6] = MMX_OP2(psadbw
),
2932 [0xf7] = MMX_OP2(maskmov
),
2933 [0xf8] = MMX_OP2(psubb
),
2934 [0xf9] = MMX_OP2(psubw
),
2935 [0xfa] = MMX_OP2(psubl
),
2936 [0xfb] = MMX_OP2(psubq
),
2937 [0xfc] = MMX_OP2(paddb
),
2938 [0xfd] = MMX_OP2(paddw
),
2939 [0xfe] = MMX_OP2(paddl
),
2942 static void *sse_op_table2
[3 * 8][2] = {
2943 [0 + 2] = MMX_OP2(psrlw
),
2944 [0 + 4] = MMX_OP2(psraw
),
2945 [0 + 6] = MMX_OP2(psllw
),
2946 [8 + 2] = MMX_OP2(psrld
),
2947 [8 + 4] = MMX_OP2(psrad
),
2948 [8 + 6] = MMX_OP2(pslld
),
2949 [16 + 2] = MMX_OP2(psrlq
),
2950 [16 + 3] = { NULL
, gen_helper_psrldq_xmm
},
2951 [16 + 6] = MMX_OP2(psllq
),
2952 [16 + 7] = { NULL
, gen_helper_pslldq_xmm
},
2955 static void *sse_op_table3
[4 * 3] = {
2956 gen_helper_cvtsi2ss
,
2957 gen_helper_cvtsi2sd
,
2958 X86_64_ONLY(gen_helper_cvtsq2ss
),
2959 X86_64_ONLY(gen_helper_cvtsq2sd
),
2961 gen_helper_cvttss2si
,
2962 gen_helper_cvttsd2si
,
2963 X86_64_ONLY(gen_helper_cvttss2sq
),
2964 X86_64_ONLY(gen_helper_cvttsd2sq
),
2966 gen_helper_cvtss2si
,
2967 gen_helper_cvtsd2si
,
2968 X86_64_ONLY(gen_helper_cvtss2sq
),
2969 X86_64_ONLY(gen_helper_cvtsd2sq
),
2972 static void *sse_op_table4
[8][4] = {
2983 static void *sse_op_table5
[256] = {
2984 [0x0c] = gen_helper_pi2fw
,
2985 [0x0d] = gen_helper_pi2fd
,
2986 [0x1c] = gen_helper_pf2iw
,
2987 [0x1d] = gen_helper_pf2id
,
2988 [0x8a] = gen_helper_pfnacc
,
2989 [0x8e] = gen_helper_pfpnacc
,
2990 [0x90] = gen_helper_pfcmpge
,
2991 [0x94] = gen_helper_pfmin
,
2992 [0x96] = gen_helper_pfrcp
,
2993 [0x97] = gen_helper_pfrsqrt
,
2994 [0x9a] = gen_helper_pfsub
,
2995 [0x9e] = gen_helper_pfadd
,
2996 [0xa0] = gen_helper_pfcmpgt
,
2997 [0xa4] = gen_helper_pfmax
,
2998 [0xa6] = gen_helper_movq
, /* pfrcpit1; no need to actually increase precision */
2999 [0xa7] = gen_helper_movq
, /* pfrsqit1 */
3000 [0xaa] = gen_helper_pfsubr
,
3001 [0xae] = gen_helper_pfacc
,
3002 [0xb0] = gen_helper_pfcmpeq
,
3003 [0xb4] = gen_helper_pfmul
,
3004 [0xb6] = gen_helper_movq
, /* pfrcpit2 */
3005 [0xb7] = gen_helper_pmulhrw_mmx
,
3006 [0xbb] = gen_helper_pswapd
,
3007 [0xbf] = gen_helper_pavgb_mmx
/* pavgusb */
3010 struct sse_op_helper_s
{
3011 void *op
[2]; uint32_t ext_mask
;
3013 #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
3014 #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 }
3015 #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 }
3016 #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 }
3017 static struct sse_op_helper_s sse_op_table6
[256] = {
3018 [0x00] = SSSE3_OP(pshufb
),
3019 [0x01] = SSSE3_OP(phaddw
),
3020 [0x02] = SSSE3_OP(phaddd
),
3021 [0x03] = SSSE3_OP(phaddsw
),
3022 [0x04] = SSSE3_OP(pmaddubsw
),
3023 [0x05] = SSSE3_OP(phsubw
),
3024 [0x06] = SSSE3_OP(phsubd
),
3025 [0x07] = SSSE3_OP(phsubsw
),
3026 [0x08] = SSSE3_OP(psignb
),
3027 [0x09] = SSSE3_OP(psignw
),
3028 [0x0a] = SSSE3_OP(psignd
),
3029 [0x0b] = SSSE3_OP(pmulhrsw
),
3030 [0x10] = SSE41_OP(pblendvb
),
3031 [0x14] = SSE41_OP(blendvps
),
3032 [0x15] = SSE41_OP(blendvpd
),
3033 [0x17] = SSE41_OP(ptest
),
3034 [0x1c] = SSSE3_OP(pabsb
),
3035 [0x1d] = SSSE3_OP(pabsw
),
3036 [0x1e] = SSSE3_OP(pabsd
),
3037 [0x20] = SSE41_OP(pmovsxbw
),
3038 [0x21] = SSE41_OP(pmovsxbd
),
3039 [0x22] = SSE41_OP(pmovsxbq
),
3040 [0x23] = SSE41_OP(pmovsxwd
),
3041 [0x24] = SSE41_OP(pmovsxwq
),
3042 [0x25] = SSE41_OP(pmovsxdq
),
3043 [0x28] = SSE41_OP(pmuldq
),
3044 [0x29] = SSE41_OP(pcmpeqq
),
3045 [0x2a] = SSE41_SPECIAL
, /* movntqda */
3046 [0x2b] = SSE41_OP(packusdw
),
3047 [0x30] = SSE41_OP(pmovzxbw
),
3048 [0x31] = SSE41_OP(pmovzxbd
),
3049 [0x32] = SSE41_OP(pmovzxbq
),
3050 [0x33] = SSE41_OP(pmovzxwd
),
3051 [0x34] = SSE41_OP(pmovzxwq
),
3052 [0x35] = SSE41_OP(pmovzxdq
),
3053 [0x37] = SSE42_OP(pcmpgtq
),
3054 [0x38] = SSE41_OP(pminsb
),
3055 [0x39] = SSE41_OP(pminsd
),
3056 [0x3a] = SSE41_OP(pminuw
),
3057 [0x3b] = SSE41_OP(pminud
),
3058 [0x3c] = SSE41_OP(pmaxsb
),
3059 [0x3d] = SSE41_OP(pmaxsd
),
3060 [0x3e] = SSE41_OP(pmaxuw
),
3061 [0x3f] = SSE41_OP(pmaxud
),
3062 [0x40] = SSE41_OP(pmulld
),
3063 [0x41] = SSE41_OP(phminposuw
),
3066 static struct sse_op_helper_s sse_op_table7
[256] = {
3067 [0x08] = SSE41_OP(roundps
),
3068 [0x09] = SSE41_OP(roundpd
),
3069 [0x0a] = SSE41_OP(roundss
),
3070 [0x0b] = SSE41_OP(roundsd
),
3071 [0x0c] = SSE41_OP(blendps
),
3072 [0x0d] = SSE41_OP(blendpd
),
3073 [0x0e] = SSE41_OP(pblendw
),
3074 [0x0f] = SSSE3_OP(palignr
),
3075 [0x14] = SSE41_SPECIAL
, /* pextrb */
3076 [0x15] = SSE41_SPECIAL
, /* pextrw */
3077 [0x16] = SSE41_SPECIAL
, /* pextrd/pextrq */
3078 [0x17] = SSE41_SPECIAL
, /* extractps */
3079 [0x20] = SSE41_SPECIAL
, /* pinsrb */
3080 [0x21] = SSE41_SPECIAL
, /* insertps */
3081 [0x22] = SSE41_SPECIAL
, /* pinsrd/pinsrq */
3082 [0x40] = SSE41_OP(dpps
),
3083 [0x41] = SSE41_OP(dppd
),
3084 [0x42] = SSE41_OP(mpsadbw
),
3085 [0x60] = SSE42_OP(pcmpestrm
),
3086 [0x61] = SSE42_OP(pcmpestri
),
3087 [0x62] = SSE42_OP(pcmpistrm
),
3088 [0x63] = SSE42_OP(pcmpistri
),
3091 static void gen_sse(DisasContext
*s
, int b
, target_ulong pc_start
, int rex_r
)
3093 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
3094 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
3098 if (s
->prefix
& PREFIX_DATA
)
3100 else if (s
->prefix
& PREFIX_REPZ
)
3102 else if (s
->prefix
& PREFIX_REPNZ
)
3106 sse_op2
= sse_op_table1
[b
][b1
];
3109 if ((b
<= 0x5f && b
>= 0x10) || b
== 0xc6 || b
== 0xc2) {
3119 /* simple MMX/SSE operation */
3120 if (s
->flags
& HF_TS_MASK
) {
3121 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
3124 if (s
->flags
& HF_EM_MASK
) {
3126 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
3129 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
3130 if ((b
!= 0x38 && b
!= 0x3a) || (s
->prefix
& PREFIX_DATA
))
3133 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
3144 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
3145 the static cpu state) */
3147 gen_helper_enter_mmx();
3150 modrm
= ldub_code(s
->pc
++);
3151 reg
= ((modrm
>> 3) & 7);
3154 mod
= (modrm
>> 6) & 3;
3155 if (sse_op2
== SSE_SPECIAL
) {
3158 case 0x0e7: /* movntq */
3161 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3162 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3164 case 0x1e7: /* movntdq */
3165 case 0x02b: /* movntps */
3166 case 0x12b: /* movntps */
3169 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3170 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3172 case 0x3f0: /* lddqu */
3175 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3176 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3178 case 0x22b: /* movntss */
3179 case 0x32b: /* movntsd */
3182 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3184 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,
3187 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3188 xmm_regs
[reg
].XMM_L(0)));
3189 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3192 case 0x6e: /* movd mm, ea */
3193 #ifdef TARGET_X86_64
3194 if (s
->dflag
== 2) {
3195 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3196 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3200 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3201 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3202 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3203 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3204 gen_helper_movl_mm_T0_mmx(cpu_ptr0
, cpu_tmp2_i32
);
3207 case 0x16e: /* movd xmm, ea */
3208 #ifdef TARGET_X86_64
3209 if (s
->dflag
== 2) {
3210 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 0);
3211 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3212 offsetof(CPUX86State
,xmm_regs
[reg
]));
3213 gen_helper_movq_mm_T0_xmm(cpu_ptr0
, cpu_T
[0]);
3217 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
3218 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3219 offsetof(CPUX86State
,xmm_regs
[reg
]));
3220 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3221 gen_helper_movl_mm_T0_xmm(cpu_ptr0
, cpu_tmp2_i32
);
3224 case 0x6f: /* movq mm, ea */
3226 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3227 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3230 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3231 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3232 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3233 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3236 case 0x010: /* movups */
3237 case 0x110: /* movupd */
3238 case 0x028: /* movaps */
3239 case 0x128: /* movapd */
3240 case 0x16f: /* movdqa xmm, ea */
3241 case 0x26f: /* movdqu xmm, ea */
3243 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3244 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3246 rm
= (modrm
& 7) | REX_B(s
);
3247 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
3248 offsetof(CPUX86State
,xmm_regs
[rm
]));
3251 case 0x210: /* movss xmm, ea */
3253 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3254 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3255 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3257 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3258 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3259 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3261 rm
= (modrm
& 7) | REX_B(s
);
3262 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3263 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3266 case 0x310: /* movsd xmm, ea */
3268 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3269 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3271 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3272 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3274 rm
= (modrm
& 7) | REX_B(s
);
3275 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3276 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3279 case 0x012: /* movlps */
3280 case 0x112: /* movlpd */
3282 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3283 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3286 rm
= (modrm
& 7) | REX_B(s
);
3287 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3288 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3291 case 0x212: /* movsldup */
3293 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3294 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3296 rm
= (modrm
& 7) | REX_B(s
);
3297 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3298 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
3299 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3300 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(2)));
3302 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3303 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3304 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3305 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
3307 case 0x312: /* movddup */
3309 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3310 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3312 rm
= (modrm
& 7) | REX_B(s
);
3313 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3314 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3316 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3317 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3319 case 0x016: /* movhps */
3320 case 0x116: /* movhpd */
3322 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3323 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3326 rm
= (modrm
& 7) | REX_B(s
);
3327 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
3328 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3331 case 0x216: /* movshdup */
3333 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3334 gen_ldo_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3336 rm
= (modrm
& 7) | REX_B(s
);
3337 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
3338 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
3339 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
3340 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
3342 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
3343 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
3344 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
3345 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
3350 int bit_index
, field_length
;
3352 if (b1
== 1 && reg
!= 0)
3354 field_length
= ldub_code(s
->pc
++) & 0x3F;
3355 bit_index
= ldub_code(s
->pc
++) & 0x3F;
3356 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3357 offsetof(CPUX86State
,xmm_regs
[reg
]));
3359 gen_helper_extrq_i(cpu_ptr0
, tcg_const_i32(bit_index
),
3360 tcg_const_i32(field_length
));
3362 gen_helper_insertq_i(cpu_ptr0
, tcg_const_i32(bit_index
),
3363 tcg_const_i32(field_length
));
3366 case 0x7e: /* movd ea, mm */
3367 #ifdef TARGET_X86_64
3368 if (s
->dflag
== 2) {
3369 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3370 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3371 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3375 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3376 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_L(0)));
3377 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3380 case 0x17e: /* movd ea, xmm */
3381 #ifdef TARGET_X86_64
3382 if (s
->dflag
== 2) {
3383 tcg_gen_ld_i64(cpu_T
[0], cpu_env
,
3384 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3385 gen_ldst_modrm(s
, modrm
, OT_QUAD
, OR_TMP0
, 1);
3389 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
,
3390 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3391 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
3394 case 0x27e: /* movq xmm, ea */
3396 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3397 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3399 rm
= (modrm
& 7) | REX_B(s
);
3400 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3401 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3403 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3405 case 0x7f: /* movq ea, mm */
3407 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3408 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3411 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
3412 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
3415 case 0x011: /* movups */
3416 case 0x111: /* movupd */
3417 case 0x029: /* movaps */
3418 case 0x129: /* movapd */
3419 case 0x17f: /* movdqa ea, xmm */
3420 case 0x27f: /* movdqu ea, xmm */
3422 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3423 gen_sto_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
]));
3425 rm
= (modrm
& 7) | REX_B(s
);
3426 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
3427 offsetof(CPUX86State
,xmm_regs
[reg
]));
3430 case 0x211: /* movss ea, xmm */
3432 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3433 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3434 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
3436 rm
= (modrm
& 7) | REX_B(s
);
3437 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
3438 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
3441 case 0x311: /* movsd ea, xmm */
3443 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3444 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3446 rm
= (modrm
& 7) | REX_B(s
);
3447 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3448 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3451 case 0x013: /* movlps */
3452 case 0x113: /* movlpd */
3454 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3455 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3460 case 0x017: /* movhps */
3461 case 0x117: /* movhpd */
3463 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3464 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3469 case 0x71: /* shift mm, im */
3472 case 0x171: /* shift xmm, im */
3475 val
= ldub_code(s
->pc
++);
3477 gen_op_movl_T0_im(val
);
3478 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3480 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
3481 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
3483 gen_op_movl_T0_im(val
);
3484 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
3486 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
3487 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
3489 sse_op2
= sse_op_table2
[((b
- 1) & 3) * 8 + (((modrm
>> 3)) & 7)][b1
];
3493 rm
= (modrm
& 7) | REX_B(s
);
3494 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3497 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3499 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3500 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op1_offset
);
3501 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3503 case 0x050: /* movmskps */
3504 rm
= (modrm
& 7) | REX_B(s
);
3505 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3506 offsetof(CPUX86State
,xmm_regs
[rm
]));
3507 gen_helper_movmskps(cpu_tmp2_i32
, cpu_ptr0
);
3508 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3509 gen_op_mov_reg_T0(OT_LONG
, reg
);
3511 case 0x150: /* movmskpd */
3512 rm
= (modrm
& 7) | REX_B(s
);
3513 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
,
3514 offsetof(CPUX86State
,xmm_regs
[rm
]));
3515 gen_helper_movmskpd(cpu_tmp2_i32
, cpu_ptr0
);
3516 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3517 gen_op_mov_reg_T0(OT_LONG
, reg
);
3519 case 0x02a: /* cvtpi2ps */
3520 case 0x12a: /* cvtpi2pd */
3521 gen_helper_enter_mmx();
3523 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3524 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3525 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3528 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3530 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3531 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3532 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3535 gen_helper_cvtpi2ps(cpu_ptr0
, cpu_ptr1
);
3539 gen_helper_cvtpi2pd(cpu_ptr0
, cpu_ptr1
);
3543 case 0x22a: /* cvtsi2ss */
3544 case 0x32a: /* cvtsi2sd */
3545 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3546 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3547 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3548 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3549 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2)];
3550 if (ot
== OT_LONG
) {
3551 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3552 ((void (*)(TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_tmp2_i32
);
3554 ((void (*)(TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_T
[0]);
3557 case 0x02c: /* cvttps2pi */
3558 case 0x12c: /* cvttpd2pi */
3559 case 0x02d: /* cvtps2pi */
3560 case 0x12d: /* cvtpd2pi */
3561 gen_helper_enter_mmx();
3563 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3564 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3565 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3567 rm
= (modrm
& 7) | REX_B(s
);
3568 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3570 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
3571 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3572 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3575 gen_helper_cvttps2pi(cpu_ptr0
, cpu_ptr1
);
3578 gen_helper_cvttpd2pi(cpu_ptr0
, cpu_ptr1
);
3581 gen_helper_cvtps2pi(cpu_ptr0
, cpu_ptr1
);
3584 gen_helper_cvtpd2pi(cpu_ptr0
, cpu_ptr1
);
3588 case 0x22c: /* cvttss2si */
3589 case 0x32c: /* cvttsd2si */
3590 case 0x22d: /* cvtss2si */
3591 case 0x32d: /* cvtsd2si */
3592 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3594 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3596 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
3598 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3599 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3601 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3603 rm
= (modrm
& 7) | REX_B(s
);
3604 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
3606 sse_op2
= sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2) + 4 +
3608 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op2_offset
);
3609 if (ot
== OT_LONG
) {
3610 ((void (*)(TCGv_i32
, TCGv_ptr
))sse_op2
)(cpu_tmp2_i32
, cpu_ptr0
);
3611 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3613 ((void (*)(TCGv
, TCGv_ptr
))sse_op2
)(cpu_T
[0], cpu_ptr0
);
3615 gen_op_mov_reg_T0(ot
, reg
);
3617 case 0xc4: /* pinsrw */
3620 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3621 val
= ldub_code(s
->pc
++);
3624 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3625 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_W(val
)));
3628 tcg_gen_st16_tl(cpu_T
[0], cpu_env
,
3629 offsetof(CPUX86State
,fpregs
[reg
].mmx
.MMX_W(val
)));
3632 case 0xc5: /* pextrw */
3636 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3637 val
= ldub_code(s
->pc
++);
3640 rm
= (modrm
& 7) | REX_B(s
);
3641 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3642 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_W(val
)));
3646 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
,
3647 offsetof(CPUX86State
,fpregs
[rm
].mmx
.MMX_W(val
)));
3649 reg
= ((modrm
>> 3) & 7) | rex_r
;
3650 gen_op_mov_reg_T0(ot
, reg
);
3652 case 0x1d6: /* movq ea, xmm */
3654 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3655 gen_stq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3657 rm
= (modrm
& 7) | REX_B(s
);
3658 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
3659 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
3660 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
3663 case 0x2d6: /* movq2dq */
3664 gen_helper_enter_mmx();
3666 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
3667 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3668 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
3670 case 0x3d6: /* movdq2q */
3671 gen_helper_enter_mmx();
3672 rm
= (modrm
& 7) | REX_B(s
);
3673 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
),
3674 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
3676 case 0xd7: /* pmovmskb */
3681 rm
= (modrm
& 7) | REX_B(s
);
3682 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,xmm_regs
[rm
]));
3683 gen_helper_pmovmskb_xmm(cpu_tmp2_i32
, cpu_ptr0
);
3686 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, offsetof(CPUX86State
,fpregs
[rm
].mmx
));
3687 gen_helper_pmovmskb_mmx(cpu_tmp2_i32
, cpu_ptr0
);
3689 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3690 reg
= ((modrm
>> 3) & 7) | rex_r
;
3691 gen_op_mov_reg_T0(OT_LONG
, reg
);
3694 if (s
->prefix
& PREFIX_REPNZ
)
3698 modrm
= ldub_code(s
->pc
++);
3700 reg
= ((modrm
>> 3) & 7) | rex_r
;
3701 mod
= (modrm
>> 6) & 3;
3703 sse_op2
= sse_op_table6
[b
].op
[b1
];
3706 if (!(s
->cpuid_ext_features
& sse_op_table6
[b
].ext_mask
))
3710 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3712 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3714 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3715 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3717 case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */
3718 case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */
3719 case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */
3720 gen_ldq_env_A0(s
->mem_index
, op2_offset
+
3721 offsetof(XMMReg
, XMM_Q(0)));
3723 case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */
3724 case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */
3725 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3726 (s
->mem_index
>> 2) - 1);
3727 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3728 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, op2_offset
+
3729 offsetof(XMMReg
, XMM_L(0)));
3731 case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */
3732 tcg_gen_qemu_ld16u(cpu_tmp0
, cpu_A0
,
3733 (s
->mem_index
>> 2) - 1);
3734 tcg_gen_st16_tl(cpu_tmp0
, cpu_env
, op2_offset
+
3735 offsetof(XMMReg
, XMM_W(0)));
3737 case 0x2a: /* movntqda */
3738 gen_ldo_env_A0(s
->mem_index
, op1_offset
);
3741 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3745 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3747 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3749 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3750 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3751 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3754 if (sse_op2
== SSE_SPECIAL
)
3757 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3758 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3759 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
3762 s
->cc_op
= CC_OP_EFLAGS
;
3764 case 0x338: /* crc32 */
3767 modrm
= ldub_code(s
->pc
++);
3768 reg
= ((modrm
>> 3) & 7) | rex_r
;
3770 if (b
!= 0xf0 && b
!= 0xf1)
3772 if (!(s
->cpuid_ext_features
& CPUID_EXT_SSE42
))
3777 else if (b
== 0xf1 && s
->dflag
!= 2)
3778 if (s
->prefix
& PREFIX_DATA
)
3785 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
3786 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
3787 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3788 gen_helper_crc32(cpu_T
[0], cpu_tmp2_i32
,
3789 cpu_T
[0], tcg_const_i32(8 << ot
));
3791 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3792 gen_op_mov_reg_T0(ot
, reg
);
3797 modrm
= ldub_code(s
->pc
++);
3799 reg
= ((modrm
>> 3) & 7) | rex_r
;
3800 mod
= (modrm
>> 6) & 3;
3802 sse_op2
= sse_op_table7
[b
].op
[b1
];
3805 if (!(s
->cpuid_ext_features
& sse_op_table7
[b
].ext_mask
))
3808 if (sse_op2
== SSE_SPECIAL
) {
3809 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
3810 rm
= (modrm
& 7) | REX_B(s
);
3812 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3813 reg
= ((modrm
>> 3) & 7) | rex_r
;
3814 val
= ldub_code(s
->pc
++);
3816 case 0x14: /* pextrb */
3817 tcg_gen_ld8u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3818 xmm_regs
[reg
].XMM_B(val
& 15)));
3820 gen_op_mov_reg_T0(ot
, rm
);
3822 tcg_gen_qemu_st8(cpu_T
[0], cpu_A0
,
3823 (s
->mem_index
>> 2) - 1);
3825 case 0x15: /* pextrw */
3826 tcg_gen_ld16u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3827 xmm_regs
[reg
].XMM_W(val
& 7)));
3829 gen_op_mov_reg_T0(ot
, rm
);
3831 tcg_gen_qemu_st16(cpu_T
[0], cpu_A0
,
3832 (s
->mem_index
>> 2) - 1);
3835 if (ot
== OT_LONG
) { /* pextrd */
3836 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3837 offsetof(CPUX86State
,
3838 xmm_regs
[reg
].XMM_L(val
& 3)));
3839 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
3841 gen_op_mov_reg_v(ot
, rm
, cpu_T
[0]);
3843 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3844 (s
->mem_index
>> 2) - 1);
3845 } else { /* pextrq */
3846 #ifdef TARGET_X86_64
3847 tcg_gen_ld_i64(cpu_tmp1_i64
, cpu_env
,
3848 offsetof(CPUX86State
,
3849 xmm_regs
[reg
].XMM_Q(val
& 1)));
3851 gen_op_mov_reg_v(ot
, rm
, cpu_tmp1_i64
);
3853 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
3854 (s
->mem_index
>> 2) - 1);
3860 case 0x17: /* extractps */
3861 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,
3862 xmm_regs
[reg
].XMM_L(val
& 3)));
3864 gen_op_mov_reg_T0(ot
, rm
);
3866 tcg_gen_qemu_st32(cpu_T
[0], cpu_A0
,
3867 (s
->mem_index
>> 2) - 1);
3869 case 0x20: /* pinsrb */
3871 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
3873 tcg_gen_qemu_ld8u(cpu_tmp0
, cpu_A0
,
3874 (s
->mem_index
>> 2) - 1);
3875 tcg_gen_st8_tl(cpu_tmp0
, cpu_env
, offsetof(CPUX86State
,
3876 xmm_regs
[reg
].XMM_B(val
& 15)));
3878 case 0x21: /* insertps */
3880 tcg_gen_ld_i32(cpu_tmp2_i32
, cpu_env
,
3881 offsetof(CPUX86State
,xmm_regs
[rm
]
3882 .XMM_L((val
>> 6) & 3)));
3884 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3885 (s
->mem_index
>> 2) - 1);
3886 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3888 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3889 offsetof(CPUX86State
,xmm_regs
[reg
]
3890 .XMM_L((val
>> 4) & 3)));
3892 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3893 cpu_env
, offsetof(CPUX86State
,
3894 xmm_regs
[reg
].XMM_L(0)));
3896 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3897 cpu_env
, offsetof(CPUX86State
,
3898 xmm_regs
[reg
].XMM_L(1)));
3900 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3901 cpu_env
, offsetof(CPUX86State
,
3902 xmm_regs
[reg
].XMM_L(2)));
3904 tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/),
3905 cpu_env
, offsetof(CPUX86State
,
3906 xmm_regs
[reg
].XMM_L(3)));
3909 if (ot
== OT_LONG
) { /* pinsrd */
3911 gen_op_mov_v_reg(ot
, cpu_tmp0
, rm
);
3913 tcg_gen_qemu_ld32u(cpu_tmp0
, cpu_A0
,
3914 (s
->mem_index
>> 2) - 1);
3915 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_tmp0
);
3916 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
,
3917 offsetof(CPUX86State
,
3918 xmm_regs
[reg
].XMM_L(val
& 3)));
3919 } else { /* pinsrq */
3920 #ifdef TARGET_X86_64
3922 gen_op_mov_v_reg(ot
, cpu_tmp1_i64
, rm
);
3924 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
3925 (s
->mem_index
>> 2) - 1);
3926 tcg_gen_st_i64(cpu_tmp1_i64
, cpu_env
,
3927 offsetof(CPUX86State
,
3928 xmm_regs
[reg
].XMM_Q(val
& 1)));
3939 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3941 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
| REX_B(s
)]);
3943 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3944 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3945 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
3948 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
3950 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
3952 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
3953 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3954 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
3957 val
= ldub_code(s
->pc
++);
3959 if ((b
& 0xfc) == 0x60) { /* pcmpXstrX */
3960 s
->cc_op
= CC_OP_EFLAGS
;
3963 /* The helper must use entire 64-bit gp registers */
3967 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
3968 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
3969 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
3975 /* generic MMX or SSE operation */
3977 case 0x70: /* pshufx insn */
3978 case 0xc6: /* pshufx insn */
3979 case 0xc2: /* compare insns */
3986 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
3988 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3989 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
3990 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f && b
!= 0x5b) ||
3992 /* specific case for SSE single instructions */
3995 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
3996 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
3999 gen_ldq_env_A0(s
->mem_index
, offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
4002 gen_ldo_env_A0(s
->mem_index
, op2_offset
);
4005 rm
= (modrm
& 7) | REX_B(s
);
4006 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
4009 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
4011 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4012 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
4013 gen_ldq_env_A0(s
->mem_index
, op2_offset
);
4016 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
4020 case 0x0f: /* 3DNow! data insns */
4021 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_3DNOW
))
4023 val
= ldub_code(s
->pc
++);
4024 sse_op2
= sse_op_table5
[val
];
4027 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4028 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4029 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4031 case 0x70: /* pshufx insn */
4032 case 0xc6: /* pshufx insn */
4033 val
= ldub_code(s
->pc
++);
4034 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4035 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4036 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv_i32
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, tcg_const_i32(val
));
4040 val
= ldub_code(s
->pc
++);
4043 sse_op2
= sse_op_table4
[val
][b1
];
4044 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4045 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4046 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4049 /* maskmov : we must prepare A0 */
4052 #ifdef TARGET_X86_64
4053 if (s
->aflag
== 2) {
4054 gen_op_movq_A0_reg(R_EDI
);
4058 gen_op_movl_A0_reg(R_EDI
);
4060 gen_op_andl_A0_ffff();
4062 gen_add_A0_ds_seg(s
);
4064 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4065 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4066 ((void (*)(TCGv_ptr
, TCGv_ptr
, TCGv
))sse_op2
)(cpu_ptr0
, cpu_ptr1
, cpu_A0
);
4069 tcg_gen_addi_ptr(cpu_ptr0
, cpu_env
, op1_offset
);
4070 tcg_gen_addi_ptr(cpu_ptr1
, cpu_env
, op2_offset
);
4071 ((void (*)(TCGv_ptr
, TCGv_ptr
))sse_op2
)(cpu_ptr0
, cpu_ptr1
);
4074 if (b
== 0x2e || b
== 0x2f) {
4075 s
->cc_op
= CC_OP_EFLAGS
;
4080 /* convert one instruction. s->is_jmp is set if the translation must
4081 be stopped. Return the next pc value */
4082 static target_ulong
disas_insn(DisasContext
*s
, target_ulong pc_start
)
4084 int b
, prefixes
, aflag
, dflag
;
4086 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
4087 target_ulong next_eip
, tval
;
4090 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
4091 tcg_gen_debug_insn_start(pc_start
);
4099 #ifdef TARGET_X86_64
4104 s
->rip_offset
= 0; /* for relative ip address */
4106 b
= ldub_code(s
->pc
);
4108 /* check prefixes */
4109 #ifdef TARGET_X86_64
4113 prefixes
|= PREFIX_REPZ
;
4116 prefixes
|= PREFIX_REPNZ
;
4119 prefixes
|= PREFIX_LOCK
;
4140 prefixes
|= PREFIX_DATA
;
4143 prefixes
|= PREFIX_ADR
;
4147 rex_w
= (b
>> 3) & 1;
4148 rex_r
= (b
& 0x4) << 1;
4149 s
->rex_x
= (b
& 0x2) << 2;
4150 REX_B(s
) = (b
& 0x1) << 3;
4151 x86_64_hregs
= 1; /* select uniform byte register addressing */
4155 /* 0x66 is ignored if rex.w is set */
4158 if (prefixes
& PREFIX_DATA
)
4161 if (!(prefixes
& PREFIX_ADR
))
4168 prefixes
|= PREFIX_REPZ
;
4171 prefixes
|= PREFIX_REPNZ
;
4174 prefixes
|= PREFIX_LOCK
;
4195 prefixes
|= PREFIX_DATA
;
4198 prefixes
|= PREFIX_ADR
;
4201 if (prefixes
& PREFIX_DATA
)
4203 if (prefixes
& PREFIX_ADR
)
4207 s
->prefix
= prefixes
;
4211 /* lock generation */
4212 if (prefixes
& PREFIX_LOCK
)
4215 /* now check op code */
4219 /**************************/
4220 /* extended op code */
4221 b
= ldub_code(s
->pc
++) | 0x100;
4224 /**************************/
4242 ot
= dflag
+ OT_WORD
;
4245 case 0: /* OP Ev, Gv */
4246 modrm
= ldub_code(s
->pc
++);
4247 reg
= ((modrm
>> 3) & 7) | rex_r
;
4248 mod
= (modrm
>> 6) & 3;
4249 rm
= (modrm
& 7) | REX_B(s
);
4251 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4253 } else if (op
== OP_XORL
&& rm
== reg
) {
4255 /* xor reg, reg optimisation */
4257 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4258 gen_op_mov_reg_T0(ot
, reg
);
4259 gen_op_update1_cc();
4264 gen_op_mov_TN_reg(ot
, 1, reg
);
4265 gen_op(s
, op
, ot
, opreg
);
4267 case 1: /* OP Gv, Ev */
4268 modrm
= ldub_code(s
->pc
++);
4269 mod
= (modrm
>> 6) & 3;
4270 reg
= ((modrm
>> 3) & 7) | rex_r
;
4271 rm
= (modrm
& 7) | REX_B(s
);
4273 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4274 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4275 } else if (op
== OP_XORL
&& rm
== reg
) {
4278 gen_op_mov_TN_reg(ot
, 1, rm
);
4280 gen_op(s
, op
, ot
, reg
);
4282 case 2: /* OP A, Iv */
4283 val
= insn_get(s
, ot
);
4284 gen_op_movl_T1_im(val
);
4285 gen_op(s
, op
, ot
, OR_EAX
);
4294 case 0x80: /* GRP1 */
4303 ot
= dflag
+ OT_WORD
;
4305 modrm
= ldub_code(s
->pc
++);
4306 mod
= (modrm
>> 6) & 3;
4307 rm
= (modrm
& 7) | REX_B(s
);
4308 op
= (modrm
>> 3) & 7;
4314 s
->rip_offset
= insn_const_size(ot
);
4315 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4326 val
= insn_get(s
, ot
);
4329 val
= (int8_t)insn_get(s
, OT_BYTE
);
4332 gen_op_movl_T1_im(val
);
4333 gen_op(s
, op
, ot
, opreg
);
4337 /**************************/
4338 /* inc, dec, and other misc arith */
4339 case 0x40 ... 0x47: /* inc Gv */
4340 ot
= dflag
? OT_LONG
: OT_WORD
;
4341 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
4343 case 0x48 ... 0x4f: /* dec Gv */
4344 ot
= dflag
? OT_LONG
: OT_WORD
;
4345 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
4347 case 0xf6: /* GRP3 */
4352 ot
= dflag
+ OT_WORD
;
4354 modrm
= ldub_code(s
->pc
++);
4355 mod
= (modrm
>> 6) & 3;
4356 rm
= (modrm
& 7) | REX_B(s
);
4357 op
= (modrm
>> 3) & 7;
4360 s
->rip_offset
= insn_const_size(ot
);
4361 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4362 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4364 gen_op_mov_TN_reg(ot
, 0, rm
);
4369 val
= insn_get(s
, ot
);
4370 gen_op_movl_T1_im(val
);
4371 gen_op_testl_T0_T1_cc();
4372 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4375 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
4377 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4379 gen_op_mov_reg_T0(ot
, rm
);
4383 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
4385 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4387 gen_op_mov_reg_T0(ot
, rm
);
4389 gen_op_update_neg_cc();
4390 s
->cc_op
= CC_OP_SUBB
+ ot
;
4395 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4396 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
4397 tcg_gen_ext8u_tl(cpu_T
[1], cpu_T
[1]);
4398 /* XXX: use 32 bit mul which could be faster */
4399 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4400 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4401 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4402 tcg_gen_andi_tl(cpu_cc_src
, cpu_T
[0], 0xff00);
4403 s
->cc_op
= CC_OP_MULB
;
4406 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4407 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
4408 tcg_gen_ext16u_tl(cpu_T
[1], cpu_T
[1]);
4409 /* XXX: use 32 bit mul which could be faster */
4410 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4411 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4412 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4413 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4414 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4415 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4416 s
->cc_op
= CC_OP_MULW
;
4420 #ifdef TARGET_X86_64
4421 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4422 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
4423 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
4424 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4425 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4426 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4427 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4428 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4429 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4433 t0
= tcg_temp_new_i64();
4434 t1
= tcg_temp_new_i64();
4435 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4436 tcg_gen_extu_i32_i64(t0
, cpu_T
[0]);
4437 tcg_gen_extu_i32_i64(t1
, cpu_T
[1]);
4438 tcg_gen_mul_i64(t0
, t0
, t1
);
4439 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4440 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4441 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4442 tcg_gen_shri_i64(t0
, t0
, 32);
4443 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4444 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4445 tcg_gen_mov_tl(cpu_cc_src
, cpu_T
[0]);
4448 s
->cc_op
= CC_OP_MULL
;
4450 #ifdef TARGET_X86_64
4452 gen_helper_mulq_EAX_T0(cpu_T
[0]);
4453 s
->cc_op
= CC_OP_MULQ
;
4461 gen_op_mov_TN_reg(OT_BYTE
, 1, R_EAX
);
4462 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4463 tcg_gen_ext8s_tl(cpu_T
[1], cpu_T
[1]);
4464 /* XXX: use 32 bit mul which could be faster */
4465 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4466 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4467 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4468 tcg_gen_ext8s_tl(cpu_tmp0
, cpu_T
[0]);
4469 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4470 s
->cc_op
= CC_OP_MULB
;
4473 gen_op_mov_TN_reg(OT_WORD
, 1, R_EAX
);
4474 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4475 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4476 /* XXX: use 32 bit mul which could be faster */
4477 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4478 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4479 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4480 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4481 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4482 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 16);
4483 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4484 s
->cc_op
= CC_OP_MULW
;
4488 #ifdef TARGET_X86_64
4489 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4490 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4491 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4492 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4493 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4494 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4495 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4496 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4497 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], 32);
4498 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4502 t0
= tcg_temp_new_i64();
4503 t1
= tcg_temp_new_i64();
4504 gen_op_mov_TN_reg(OT_LONG
, 1, R_EAX
);
4505 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4506 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4507 tcg_gen_mul_i64(t0
, t0
, t1
);
4508 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4509 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4510 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4511 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4512 tcg_gen_shri_i64(t0
, t0
, 32);
4513 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4514 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4515 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4518 s
->cc_op
= CC_OP_MULL
;
4520 #ifdef TARGET_X86_64
4522 gen_helper_imulq_EAX_T0(cpu_T
[0]);
4523 s
->cc_op
= CC_OP_MULQ
;
4531 gen_jmp_im(pc_start
- s
->cs_base
);
4532 gen_helper_divb_AL(cpu_T
[0]);
4535 gen_jmp_im(pc_start
- s
->cs_base
);
4536 gen_helper_divw_AX(cpu_T
[0]);
4540 gen_jmp_im(pc_start
- s
->cs_base
);
4541 gen_helper_divl_EAX(cpu_T
[0]);
4543 #ifdef TARGET_X86_64
4545 gen_jmp_im(pc_start
- s
->cs_base
);
4546 gen_helper_divq_EAX(cpu_T
[0]);
4554 gen_jmp_im(pc_start
- s
->cs_base
);
4555 gen_helper_idivb_AL(cpu_T
[0]);
4558 gen_jmp_im(pc_start
- s
->cs_base
);
4559 gen_helper_idivw_AX(cpu_T
[0]);
4563 gen_jmp_im(pc_start
- s
->cs_base
);
4564 gen_helper_idivl_EAX(cpu_T
[0]);
4566 #ifdef TARGET_X86_64
4568 gen_jmp_im(pc_start
- s
->cs_base
);
4569 gen_helper_idivq_EAX(cpu_T
[0]);
4579 case 0xfe: /* GRP4 */
4580 case 0xff: /* GRP5 */
4584 ot
= dflag
+ OT_WORD
;
4586 modrm
= ldub_code(s
->pc
++);
4587 mod
= (modrm
>> 6) & 3;
4588 rm
= (modrm
& 7) | REX_B(s
);
4589 op
= (modrm
>> 3) & 7;
4590 if (op
>= 2 && b
== 0xfe) {
4594 if (op
== 2 || op
== 4) {
4595 /* operand size for jumps is 64 bit */
4597 } else if (op
== 3 || op
== 5) {
4598 ot
= dflag
? OT_LONG
+ (rex_w
== 1) : OT_WORD
;
4599 } else if (op
== 6) {
4600 /* default push size is 64 bit */
4601 ot
= dflag
? OT_QUAD
: OT_WORD
;
4605 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4606 if (op
>= 2 && op
!= 3 && op
!= 5)
4607 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
4609 gen_op_mov_TN_reg(ot
, 0, rm
);
4613 case 0: /* inc Ev */
4618 gen_inc(s
, ot
, opreg
, 1);
4620 case 1: /* dec Ev */
4625 gen_inc(s
, ot
, opreg
, -1);
4627 case 2: /* call Ev */
4628 /* XXX: optimize if memory (no 'and' is necessary) */
4630 gen_op_andl_T0_ffff();
4631 next_eip
= s
->pc
- s
->cs_base
;
4632 gen_movtl_T1_im(next_eip
);
4637 case 3: /* lcall Ev */
4638 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4639 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4640 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4642 if (s
->pe
&& !s
->vm86
) {
4643 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4644 gen_op_set_cc_op(s
->cc_op
);
4645 gen_jmp_im(pc_start
- s
->cs_base
);
4646 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4647 gen_helper_lcall_protected(cpu_tmp2_i32
, cpu_T
[1],
4648 tcg_const_i32(dflag
),
4649 tcg_const_i32(s
->pc
- pc_start
));
4651 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4652 gen_helper_lcall_real(cpu_tmp2_i32
, cpu_T
[1],
4653 tcg_const_i32(dflag
),
4654 tcg_const_i32(s
->pc
- s
->cs_base
));
4658 case 4: /* jmp Ev */
4660 gen_op_andl_T0_ffff();
4664 case 5: /* ljmp Ev */
4665 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4666 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
4667 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
4669 if (s
->pe
&& !s
->vm86
) {
4670 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4671 gen_op_set_cc_op(s
->cc_op
);
4672 gen_jmp_im(pc_start
- s
->cs_base
);
4673 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
4674 gen_helper_ljmp_protected(cpu_tmp2_i32
, cpu_T
[1],
4675 tcg_const_i32(s
->pc
- pc_start
));
4677 gen_op_movl_seg_T0_vm(R_CS
);
4678 gen_op_movl_T0_T1();
4683 case 6: /* push Ev */
4691 case 0x84: /* test Ev, Gv */
4696 ot
= dflag
+ OT_WORD
;
4698 modrm
= ldub_code(s
->pc
++);
4699 reg
= ((modrm
>> 3) & 7) | rex_r
;
4701 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4702 gen_op_mov_TN_reg(ot
, 1, reg
);
4703 gen_op_testl_T0_T1_cc();
4704 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4707 case 0xa8: /* test eAX, Iv */
4712 ot
= dflag
+ OT_WORD
;
4713 val
= insn_get(s
, ot
);
4715 gen_op_mov_TN_reg(ot
, 0, OR_EAX
);
4716 gen_op_movl_T1_im(val
);
4717 gen_op_testl_T0_T1_cc();
4718 s
->cc_op
= CC_OP_LOGICB
+ ot
;
4721 case 0x98: /* CWDE/CBW */
4722 #ifdef TARGET_X86_64
4724 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4725 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4726 gen_op_mov_reg_T0(OT_QUAD
, R_EAX
);
4730 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4731 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4732 gen_op_mov_reg_T0(OT_LONG
, R_EAX
);
4734 gen_op_mov_TN_reg(OT_BYTE
, 0, R_EAX
);
4735 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
4736 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
4739 case 0x99: /* CDQ/CWD */
4740 #ifdef TARGET_X86_64
4742 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
4743 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 63);
4744 gen_op_mov_reg_T0(OT_QUAD
, R_EDX
);
4748 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
4749 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4750 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 31);
4751 gen_op_mov_reg_T0(OT_LONG
, R_EDX
);
4753 gen_op_mov_TN_reg(OT_WORD
, 0, R_EAX
);
4754 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4755 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], 15);
4756 gen_op_mov_reg_T0(OT_WORD
, R_EDX
);
4759 case 0x1af: /* imul Gv, Ev */
4760 case 0x69: /* imul Gv, Ev, I */
4762 ot
= dflag
+ OT_WORD
;
4763 modrm
= ldub_code(s
->pc
++);
4764 reg
= ((modrm
>> 3) & 7) | rex_r
;
4766 s
->rip_offset
= insn_const_size(ot
);
4769 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
4771 val
= insn_get(s
, ot
);
4772 gen_op_movl_T1_im(val
);
4773 } else if (b
== 0x6b) {
4774 val
= (int8_t)insn_get(s
, OT_BYTE
);
4775 gen_op_movl_T1_im(val
);
4777 gen_op_mov_TN_reg(ot
, 1, reg
);
4780 #ifdef TARGET_X86_64
4781 if (ot
== OT_QUAD
) {
4782 gen_helper_imulq_T0_T1(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4785 if (ot
== OT_LONG
) {
4786 #ifdef TARGET_X86_64
4787 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
4788 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
4789 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4790 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4791 tcg_gen_ext32s_tl(cpu_tmp0
, cpu_T
[0]);
4792 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4796 t0
= tcg_temp_new_i64();
4797 t1
= tcg_temp_new_i64();
4798 tcg_gen_ext_i32_i64(t0
, cpu_T
[0]);
4799 tcg_gen_ext_i32_i64(t1
, cpu_T
[1]);
4800 tcg_gen_mul_i64(t0
, t0
, t1
);
4801 tcg_gen_trunc_i64_i32(cpu_T
[0], t0
);
4802 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4803 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[0], 31);
4804 tcg_gen_shri_i64(t0
, t0
, 32);
4805 tcg_gen_trunc_i64_i32(cpu_T
[1], t0
);
4806 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[1], cpu_tmp0
);
4810 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
4811 tcg_gen_ext16s_tl(cpu_T
[1], cpu_T
[1]);
4812 /* XXX: use 32 bit mul which could be faster */
4813 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
4814 tcg_gen_mov_tl(cpu_cc_dst
, cpu_T
[0]);
4815 tcg_gen_ext16s_tl(cpu_tmp0
, cpu_T
[0]);
4816 tcg_gen_sub_tl(cpu_cc_src
, cpu_T
[0], cpu_tmp0
);
4818 gen_op_mov_reg_T0(ot
, reg
);
4819 s
->cc_op
= CC_OP_MULB
+ ot
;
4822 case 0x1c1: /* xadd Ev, Gv */
4826 ot
= dflag
+ OT_WORD
;
4827 modrm
= ldub_code(s
->pc
++);
4828 reg
= ((modrm
>> 3) & 7) | rex_r
;
4829 mod
= (modrm
>> 6) & 3;
4831 rm
= (modrm
& 7) | REX_B(s
);
4832 gen_op_mov_TN_reg(ot
, 0, reg
);
4833 gen_op_mov_TN_reg(ot
, 1, rm
);
4834 gen_op_addl_T0_T1();
4835 gen_op_mov_reg_T1(ot
, reg
);
4836 gen_op_mov_reg_T0(ot
, rm
);
4838 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4839 gen_op_mov_TN_reg(ot
, 0, reg
);
4840 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
4841 gen_op_addl_T0_T1();
4842 gen_op_st_T0_A0(ot
+ s
->mem_index
);
4843 gen_op_mov_reg_T1(ot
, reg
);
4845 gen_op_update2_cc();
4846 s
->cc_op
= CC_OP_ADDB
+ ot
;
4849 case 0x1b1: /* cmpxchg Ev, Gv */
4852 TCGv t0
, t1
, t2
, a0
;
4857 ot
= dflag
+ OT_WORD
;
4858 modrm
= ldub_code(s
->pc
++);
4859 reg
= ((modrm
>> 3) & 7) | rex_r
;
4860 mod
= (modrm
>> 6) & 3;
4861 t0
= tcg_temp_local_new();
4862 t1
= tcg_temp_local_new();
4863 t2
= tcg_temp_local_new();
4864 a0
= tcg_temp_local_new();
4865 gen_op_mov_v_reg(ot
, t1
, reg
);
4867 rm
= (modrm
& 7) | REX_B(s
);
4868 gen_op_mov_v_reg(ot
, t0
, rm
);
4870 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4871 tcg_gen_mov_tl(a0
, cpu_A0
);
4872 gen_op_ld_v(ot
+ s
->mem_index
, t0
, a0
);
4873 rm
= 0; /* avoid warning */
4875 label1
= gen_new_label();
4876 tcg_gen_sub_tl(t2
, cpu_regs
[R_EAX
], t0
);
4878 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, label1
);
4880 label2
= gen_new_label();
4881 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4883 gen_set_label(label1
);
4884 gen_op_mov_reg_v(ot
, rm
, t1
);
4885 gen_set_label(label2
);
4887 tcg_gen_mov_tl(t1
, t0
);
4888 gen_op_mov_reg_v(ot
, R_EAX
, t0
);
4889 gen_set_label(label1
);
4891 gen_op_st_v(ot
+ s
->mem_index
, t1
, a0
);
4893 tcg_gen_mov_tl(cpu_cc_src
, t0
);
4894 tcg_gen_mov_tl(cpu_cc_dst
, t2
);
4895 s
->cc_op
= CC_OP_SUBB
+ ot
;
4902 case 0x1c7: /* cmpxchg8b */
4903 modrm
= ldub_code(s
->pc
++);
4904 mod
= (modrm
>> 6) & 3;
4905 if ((mod
== 3) || ((modrm
& 0x38) != 0x8))
4907 #ifdef TARGET_X86_64
4909 if (!(s
->cpuid_ext_features
& CPUID_EXT_CX16
))
4911 gen_jmp_im(pc_start
- s
->cs_base
);
4912 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4913 gen_op_set_cc_op(s
->cc_op
);
4914 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4915 gen_helper_cmpxchg16b(cpu_A0
);
4919 if (!(s
->cpuid_features
& CPUID_CX8
))
4921 gen_jmp_im(pc_start
- s
->cs_base
);
4922 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4923 gen_op_set_cc_op(s
->cc_op
);
4924 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4925 gen_helper_cmpxchg8b(cpu_A0
);
4927 s
->cc_op
= CC_OP_EFLAGS
;
4930 /**************************/
4932 case 0x50 ... 0x57: /* push */
4933 gen_op_mov_TN_reg(OT_LONG
, 0, (b
& 7) | REX_B(s
));
4936 case 0x58 ... 0x5f: /* pop */
4938 ot
= dflag
? OT_QUAD
: OT_WORD
;
4940 ot
= dflag
+ OT_WORD
;
4943 /* NOTE: order is important for pop %sp */
4945 gen_op_mov_reg_T0(ot
, (b
& 7) | REX_B(s
));
4947 case 0x60: /* pusha */
4952 case 0x61: /* popa */
4957 case 0x68: /* push Iv */
4960 ot
= dflag
? OT_QUAD
: OT_WORD
;
4962 ot
= dflag
+ OT_WORD
;
4965 val
= insn_get(s
, ot
);
4967 val
= (int8_t)insn_get(s
, OT_BYTE
);
4968 gen_op_movl_T0_im(val
);
4971 case 0x8f: /* pop Ev */
4973 ot
= dflag
? OT_QUAD
: OT_WORD
;
4975 ot
= dflag
+ OT_WORD
;
4977 modrm
= ldub_code(s
->pc
++);
4978 mod
= (modrm
>> 6) & 3;
4981 /* NOTE: order is important for pop %sp */
4983 rm
= (modrm
& 7) | REX_B(s
);
4984 gen_op_mov_reg_T0(ot
, rm
);
4986 /* NOTE: order is important too for MMU exceptions */
4987 s
->popl_esp_hack
= 1 << ot
;
4988 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
4989 s
->popl_esp_hack
= 0;
4993 case 0xc8: /* enter */
4996 val
= lduw_code(s
->pc
);
4998 level
= ldub_code(s
->pc
++);
4999 gen_enter(s
, val
, level
);
5002 case 0xc9: /* leave */
5003 /* XXX: exception not precise (ESP is updated before potential exception) */
5005 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EBP
);
5006 gen_op_mov_reg_T0(OT_QUAD
, R_ESP
);
5007 } else if (s
->ss32
) {
5008 gen_op_mov_TN_reg(OT_LONG
, 0, R_EBP
);
5009 gen_op_mov_reg_T0(OT_LONG
, R_ESP
);
5011 gen_op_mov_TN_reg(OT_WORD
, 0, R_EBP
);
5012 gen_op_mov_reg_T0(OT_WORD
, R_ESP
);
5016 ot
= dflag
? OT_QUAD
: OT_WORD
;
5018 ot
= dflag
+ OT_WORD
;
5020 gen_op_mov_reg_T0(ot
, R_EBP
);
5023 case 0x06: /* push es */
5024 case 0x0e: /* push cs */
5025 case 0x16: /* push ss */
5026 case 0x1e: /* push ds */
5029 gen_op_movl_T0_seg(b
>> 3);
5032 case 0x1a0: /* push fs */
5033 case 0x1a8: /* push gs */
5034 gen_op_movl_T0_seg((b
>> 3) & 7);
5037 case 0x07: /* pop es */
5038 case 0x17: /* pop ss */
5039 case 0x1f: /* pop ds */
5044 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5047 /* if reg == SS, inhibit interrupts/trace. */
5048 /* If several instructions disable interrupts, only the
5050 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5051 gen_helper_set_inhibit_irq();
5055 gen_jmp_im(s
->pc
- s
->cs_base
);
5059 case 0x1a1: /* pop fs */
5060 case 0x1a9: /* pop gs */
5062 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
5065 gen_jmp_im(s
->pc
- s
->cs_base
);
5070 /**************************/
5073 case 0x89: /* mov Gv, Ev */
5077 ot
= dflag
+ OT_WORD
;
5078 modrm
= ldub_code(s
->pc
++);
5079 reg
= ((modrm
>> 3) & 7) | rex_r
;
5081 /* generate a generic store */
5082 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
5085 case 0xc7: /* mov Ev, Iv */
5089 ot
= dflag
+ OT_WORD
;
5090 modrm
= ldub_code(s
->pc
++);
5091 mod
= (modrm
>> 6) & 3;
5093 s
->rip_offset
= insn_const_size(ot
);
5094 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5096 val
= insn_get(s
, ot
);
5097 gen_op_movl_T0_im(val
);
5099 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5101 gen_op_mov_reg_T0(ot
, (modrm
& 7) | REX_B(s
));
5104 case 0x8b: /* mov Ev, Gv */
5108 ot
= OT_WORD
+ dflag
;
5109 modrm
= ldub_code(s
->pc
++);
5110 reg
= ((modrm
>> 3) & 7) | rex_r
;
5112 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5113 gen_op_mov_reg_T0(ot
, reg
);
5115 case 0x8e: /* mov seg, Gv */
5116 modrm
= ldub_code(s
->pc
++);
5117 reg
= (modrm
>> 3) & 7;
5118 if (reg
>= 6 || reg
== R_CS
)
5120 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5121 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
5123 /* if reg == SS, inhibit interrupts/trace */
5124 /* If several instructions disable interrupts, only the
5126 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5127 gen_helper_set_inhibit_irq();
5131 gen_jmp_im(s
->pc
- s
->cs_base
);
5135 case 0x8c: /* mov Gv, seg */
5136 modrm
= ldub_code(s
->pc
++);
5137 reg
= (modrm
>> 3) & 7;
5138 mod
= (modrm
>> 6) & 3;
5141 gen_op_movl_T0_seg(reg
);
5143 ot
= OT_WORD
+ dflag
;
5146 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5149 case 0x1b6: /* movzbS Gv, Eb */
5150 case 0x1b7: /* movzwS Gv, Eb */
5151 case 0x1be: /* movsbS Gv, Eb */
5152 case 0x1bf: /* movswS Gv, Eb */
5155 /* d_ot is the size of destination */
5156 d_ot
= dflag
+ OT_WORD
;
5157 /* ot is the size of source */
5158 ot
= (b
& 1) + OT_BYTE
;
5159 modrm
= ldub_code(s
->pc
++);
5160 reg
= ((modrm
>> 3) & 7) | rex_r
;
5161 mod
= (modrm
>> 6) & 3;
5162 rm
= (modrm
& 7) | REX_B(s
);
5165 gen_op_mov_TN_reg(ot
, 0, rm
);
5166 switch(ot
| (b
& 8)) {
5168 tcg_gen_ext8u_tl(cpu_T
[0], cpu_T
[0]);
5171 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[0]);
5174 tcg_gen_ext16u_tl(cpu_T
[0], cpu_T
[0]);
5178 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[0]);
5181 gen_op_mov_reg_T0(d_ot
, reg
);
5183 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5185 gen_op_lds_T0_A0(ot
+ s
->mem_index
);
5187 gen_op_ldu_T0_A0(ot
+ s
->mem_index
);
5189 gen_op_mov_reg_T0(d_ot
, reg
);
5194 case 0x8d: /* lea */
5195 ot
= dflag
+ OT_WORD
;
5196 modrm
= ldub_code(s
->pc
++);
5197 mod
= (modrm
>> 6) & 3;
5200 reg
= ((modrm
>> 3) & 7) | rex_r
;
5201 /* we must ensure that no segment is added */
5205 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5207 gen_op_mov_reg_A0(ot
- OT_WORD
, reg
);
5210 case 0xa0: /* mov EAX, Ov */
5212 case 0xa2: /* mov Ov, EAX */
5215 target_ulong offset_addr
;
5220 ot
= dflag
+ OT_WORD
;
5221 #ifdef TARGET_X86_64
5222 if (s
->aflag
== 2) {
5223 offset_addr
= ldq_code(s
->pc
);
5225 gen_op_movq_A0_im(offset_addr
);
5230 offset_addr
= insn_get(s
, OT_LONG
);
5232 offset_addr
= insn_get(s
, OT_WORD
);
5234 gen_op_movl_A0_im(offset_addr
);
5236 gen_add_A0_ds_seg(s
);
5238 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
5239 gen_op_mov_reg_T0(ot
, R_EAX
);
5241 gen_op_mov_TN_reg(ot
, 0, R_EAX
);
5242 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5246 case 0xd7: /* xlat */
5247 #ifdef TARGET_X86_64
5248 if (s
->aflag
== 2) {
5249 gen_op_movq_A0_reg(R_EBX
);
5250 gen_op_mov_TN_reg(OT_QUAD
, 0, R_EAX
);
5251 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5252 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5256 gen_op_movl_A0_reg(R_EBX
);
5257 gen_op_mov_TN_reg(OT_LONG
, 0, R_EAX
);
5258 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
5259 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_T
[0]);
5261 gen_op_andl_A0_ffff();
5263 tcg_gen_andi_tl(cpu_A0
, cpu_A0
, 0xffffffff);
5265 gen_add_A0_ds_seg(s
);
5266 gen_op_ldu_T0_A0(OT_BYTE
+ s
->mem_index
);
5267 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
5269 case 0xb0 ... 0xb7: /* mov R, Ib */
5270 val
= insn_get(s
, OT_BYTE
);
5271 gen_op_movl_T0_im(val
);
5272 gen_op_mov_reg_T0(OT_BYTE
, (b
& 7) | REX_B(s
));
5274 case 0xb8 ... 0xbf: /* mov R, Iv */
5275 #ifdef TARGET_X86_64
5279 tmp
= ldq_code(s
->pc
);
5281 reg
= (b
& 7) | REX_B(s
);
5282 gen_movtl_T0_im(tmp
);
5283 gen_op_mov_reg_T0(OT_QUAD
, reg
);
5287 ot
= dflag
? OT_LONG
: OT_WORD
;
5288 val
= insn_get(s
, ot
);
5289 reg
= (b
& 7) | REX_B(s
);
5290 gen_op_movl_T0_im(val
);
5291 gen_op_mov_reg_T0(ot
, reg
);
5295 case 0x91 ... 0x97: /* xchg R, EAX */
5296 ot
= dflag
+ OT_WORD
;
5297 reg
= (b
& 7) | REX_B(s
);
5301 case 0x87: /* xchg Ev, Gv */
5305 ot
= dflag
+ OT_WORD
;
5306 modrm
= ldub_code(s
->pc
++);
5307 reg
= ((modrm
>> 3) & 7) | rex_r
;
5308 mod
= (modrm
>> 6) & 3;
5310 rm
= (modrm
& 7) | REX_B(s
);
5312 gen_op_mov_TN_reg(ot
, 0, reg
);
5313 gen_op_mov_TN_reg(ot
, 1, rm
);
5314 gen_op_mov_reg_T0(ot
, rm
);
5315 gen_op_mov_reg_T1(ot
, reg
);
5317 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5318 gen_op_mov_TN_reg(ot
, 0, reg
);
5319 /* for xchg, lock is implicit */
5320 if (!(prefixes
& PREFIX_LOCK
))
5322 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5323 gen_op_st_T0_A0(ot
+ s
->mem_index
);
5324 if (!(prefixes
& PREFIX_LOCK
))
5325 gen_helper_unlock();
5326 gen_op_mov_reg_T1(ot
, reg
);
5329 case 0xc4: /* les Gv */
5334 case 0xc5: /* lds Gv */
5339 case 0x1b2: /* lss Gv */
5342 case 0x1b4: /* lfs Gv */
5345 case 0x1b5: /* lgs Gv */
5348 ot
= dflag
? OT_LONG
: OT_WORD
;
5349 modrm
= ldub_code(s
->pc
++);
5350 reg
= ((modrm
>> 3) & 7) | rex_r
;
5351 mod
= (modrm
>> 6) & 3;
5354 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5355 gen_op_ld_T1_A0(ot
+ s
->mem_index
);
5356 gen_add_A0_im(s
, 1 << (ot
- OT_WORD
+ 1));
5357 /* load the segment first to handle exceptions properly */
5358 gen_op_ldu_T0_A0(OT_WORD
+ s
->mem_index
);
5359 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
5360 /* then put the data */
5361 gen_op_mov_reg_T1(ot
, reg
);
5363 gen_jmp_im(s
->pc
- s
->cs_base
);
5368 /************************/
5379 ot
= dflag
+ OT_WORD
;
5381 modrm
= ldub_code(s
->pc
++);
5382 mod
= (modrm
>> 6) & 3;
5383 op
= (modrm
>> 3) & 7;
5389 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5392 opreg
= (modrm
& 7) | REX_B(s
);
5397 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
5400 shift
= ldub_code(s
->pc
++);
5402 gen_shifti(s
, op
, ot
, opreg
, shift
);
5417 case 0x1a4: /* shld imm */
5421 case 0x1a5: /* shld cl */
5425 case 0x1ac: /* shrd imm */
5429 case 0x1ad: /* shrd cl */
5433 ot
= dflag
+ OT_WORD
;
5434 modrm
= ldub_code(s
->pc
++);
5435 mod
= (modrm
>> 6) & 3;
5436 rm
= (modrm
& 7) | REX_B(s
);
5437 reg
= ((modrm
>> 3) & 7) | rex_r
;
5439 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5444 gen_op_mov_TN_reg(ot
, 1, reg
);
5447 val
= ldub_code(s
->pc
++);
5448 tcg_gen_movi_tl(cpu_T3
, val
);
5450 tcg_gen_mov_tl(cpu_T3
, cpu_regs
[R_ECX
]);
5452 gen_shiftd_rm_T1_T3(s
, ot
, opreg
, op
);
5455 /************************/
5458 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
5459 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
5460 /* XXX: what to do if illegal op ? */
5461 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5464 modrm
= ldub_code(s
->pc
++);
5465 mod
= (modrm
>> 6) & 3;
5467 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
5470 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5472 case 0x00 ... 0x07: /* fxxxs */
5473 case 0x10 ... 0x17: /* fixxxl */
5474 case 0x20 ... 0x27: /* fxxxl */
5475 case 0x30 ... 0x37: /* fixxx */
5482 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5483 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5484 gen_helper_flds_FT0(cpu_tmp2_i32
);
5487 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5488 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5489 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5492 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5493 (s
->mem_index
>> 2) - 1);
5494 gen_helper_fldl_FT0(cpu_tmp1_i64
);
5498 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5499 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5500 gen_helper_fildl_FT0(cpu_tmp2_i32
);
5504 gen_helper_fp_arith_ST0_FT0(op1
);
5506 /* fcomp needs pop */
5511 case 0x08: /* flds */
5512 case 0x0a: /* fsts */
5513 case 0x0b: /* fstps */
5514 case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
5515 case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
5516 case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
5521 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5522 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5523 gen_helper_flds_ST0(cpu_tmp2_i32
);
5526 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
5527 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5528 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5531 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5532 (s
->mem_index
>> 2) - 1);
5533 gen_helper_fldl_ST0(cpu_tmp1_i64
);
5537 gen_op_lds_T0_A0(OT_WORD
+ s
->mem_index
);
5538 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5539 gen_helper_fildl_ST0(cpu_tmp2_i32
);
5544 /* XXX: the corresponding CPUID bit must be tested ! */
5547 gen_helper_fisttl_ST0(cpu_tmp2_i32
);
5548 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5549 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5552 gen_helper_fisttll_ST0(cpu_tmp1_i64
);
5553 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5554 (s
->mem_index
>> 2) - 1);
5558 gen_helper_fistt_ST0(cpu_tmp2_i32
);
5559 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5560 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5568 gen_helper_fsts_ST0(cpu_tmp2_i32
);
5569 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5570 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5573 gen_helper_fistl_ST0(cpu_tmp2_i32
);
5574 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5575 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
5578 gen_helper_fstl_ST0(cpu_tmp1_i64
);
5579 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5580 (s
->mem_index
>> 2) - 1);
5584 gen_helper_fist_ST0(cpu_tmp2_i32
);
5585 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5586 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5594 case 0x0c: /* fldenv mem */
5595 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5596 gen_op_set_cc_op(s
->cc_op
);
5597 gen_jmp_im(pc_start
- s
->cs_base
);
5599 cpu_A0
, tcg_const_i32(s
->dflag
));
5601 case 0x0d: /* fldcw mem */
5602 gen_op_ld_T0_A0(OT_WORD
+ s
->mem_index
);
5603 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
5604 gen_helper_fldcw(cpu_tmp2_i32
);
5606 case 0x0e: /* fnstenv mem */
5607 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5608 gen_op_set_cc_op(s
->cc_op
);
5609 gen_jmp_im(pc_start
- s
->cs_base
);
5610 gen_helper_fstenv(cpu_A0
, tcg_const_i32(s
->dflag
));
5612 case 0x0f: /* fnstcw mem */
5613 gen_helper_fnstcw(cpu_tmp2_i32
);
5614 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5615 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5617 case 0x1d: /* fldt mem */
5618 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5619 gen_op_set_cc_op(s
->cc_op
);
5620 gen_jmp_im(pc_start
- s
->cs_base
);
5621 gen_helper_fldt_ST0(cpu_A0
);
5623 case 0x1f: /* fstpt mem */
5624 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5625 gen_op_set_cc_op(s
->cc_op
);
5626 gen_jmp_im(pc_start
- s
->cs_base
);
5627 gen_helper_fstt_ST0(cpu_A0
);
5630 case 0x2c: /* frstor mem */
5631 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5632 gen_op_set_cc_op(s
->cc_op
);
5633 gen_jmp_im(pc_start
- s
->cs_base
);
5634 gen_helper_frstor(cpu_A0
, tcg_const_i32(s
->dflag
));
5636 case 0x2e: /* fnsave mem */
5637 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5638 gen_op_set_cc_op(s
->cc_op
);
5639 gen_jmp_im(pc_start
- s
->cs_base
);
5640 gen_helper_fsave(cpu_A0
, tcg_const_i32(s
->dflag
));
5642 case 0x2f: /* fnstsw mem */
5643 gen_helper_fnstsw(cpu_tmp2_i32
);
5644 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5645 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
5647 case 0x3c: /* fbld */
5648 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5649 gen_op_set_cc_op(s
->cc_op
);
5650 gen_jmp_im(pc_start
- s
->cs_base
);
5651 gen_helper_fbld_ST0(cpu_A0
);
5653 case 0x3e: /* fbstp */
5654 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5655 gen_op_set_cc_op(s
->cc_op
);
5656 gen_jmp_im(pc_start
- s
->cs_base
);
5657 gen_helper_fbst_ST0(cpu_A0
);
5660 case 0x3d: /* fildll */
5661 tcg_gen_qemu_ld64(cpu_tmp1_i64
, cpu_A0
,
5662 (s
->mem_index
>> 2) - 1);
5663 gen_helper_fildll_ST0(cpu_tmp1_i64
);
5665 case 0x3f: /* fistpll */
5666 gen_helper_fistll_ST0(cpu_tmp1_i64
);
5667 tcg_gen_qemu_st64(cpu_tmp1_i64
, cpu_A0
,
5668 (s
->mem_index
>> 2) - 1);
5675 /* register float ops */
5679 case 0x08: /* fld sti */
5681 gen_helper_fmov_ST0_STN(tcg_const_i32((opreg
+ 1) & 7));
5683 case 0x09: /* fxchg sti */
5684 case 0x29: /* fxchg4 sti, undocumented op */
5685 case 0x39: /* fxchg7 sti, undocumented op */
5686 gen_helper_fxchg_ST0_STN(tcg_const_i32(opreg
));
5688 case 0x0a: /* grp d9/2 */
5691 /* check exceptions (FreeBSD FPU probe) */
5692 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5693 gen_op_set_cc_op(s
->cc_op
);
5694 gen_jmp_im(pc_start
- s
->cs_base
);
5701 case 0x0c: /* grp d9/4 */
5704 gen_helper_fchs_ST0();
5707 gen_helper_fabs_ST0();
5710 gen_helper_fldz_FT0();
5711 gen_helper_fcom_ST0_FT0();
5714 gen_helper_fxam_ST0();
5720 case 0x0d: /* grp d9/5 */
5725 gen_helper_fld1_ST0();
5729 gen_helper_fldl2t_ST0();
5733 gen_helper_fldl2e_ST0();
5737 gen_helper_fldpi_ST0();
5741 gen_helper_fldlg2_ST0();
5745 gen_helper_fldln2_ST0();
5749 gen_helper_fldz_ST0();
5756 case 0x0e: /* grp d9/6 */
5767 case 3: /* fpatan */
5768 gen_helper_fpatan();
5770 case 4: /* fxtract */
5771 gen_helper_fxtract();
5773 case 5: /* fprem1 */
5774 gen_helper_fprem1();
5776 case 6: /* fdecstp */
5777 gen_helper_fdecstp();
5780 case 7: /* fincstp */
5781 gen_helper_fincstp();
5785 case 0x0f: /* grp d9/7 */
5790 case 1: /* fyl2xp1 */
5791 gen_helper_fyl2xp1();
5796 case 3: /* fsincos */
5797 gen_helper_fsincos();
5799 case 5: /* fscale */
5800 gen_helper_fscale();
5802 case 4: /* frndint */
5803 gen_helper_frndint();
5814 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
5815 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
5816 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
5822 gen_helper_fp_arith_STN_ST0(op1
, opreg
);
5826 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5827 gen_helper_fp_arith_ST0_FT0(op1
);
5831 case 0x02: /* fcom */
5832 case 0x22: /* fcom2, undocumented op */
5833 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5834 gen_helper_fcom_ST0_FT0();
5836 case 0x03: /* fcomp */
5837 case 0x23: /* fcomp3, undocumented op */
5838 case 0x32: /* fcomp5, undocumented op */
5839 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5840 gen_helper_fcom_ST0_FT0();
5843 case 0x15: /* da/5 */
5845 case 1: /* fucompp */
5846 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5847 gen_helper_fucom_ST0_FT0();
5857 case 0: /* feni (287 only, just do nop here) */
5859 case 1: /* fdisi (287 only, just do nop here) */
5864 case 3: /* fninit */
5865 gen_helper_fninit();
5867 case 4: /* fsetpm (287 only, just do nop here) */
5873 case 0x1d: /* fucomi */
5874 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5875 gen_op_set_cc_op(s
->cc_op
);
5876 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5877 gen_helper_fucomi_ST0_FT0();
5878 s
->cc_op
= CC_OP_EFLAGS
;
5880 case 0x1e: /* fcomi */
5881 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5882 gen_op_set_cc_op(s
->cc_op
);
5883 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5884 gen_helper_fcomi_ST0_FT0();
5885 s
->cc_op
= CC_OP_EFLAGS
;
5887 case 0x28: /* ffree sti */
5888 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5890 case 0x2a: /* fst sti */
5891 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5893 case 0x2b: /* fstp sti */
5894 case 0x0b: /* fstp1 sti, undocumented op */
5895 case 0x3a: /* fstp8 sti, undocumented op */
5896 case 0x3b: /* fstp9 sti, undocumented op */
5897 gen_helper_fmov_STN_ST0(tcg_const_i32(opreg
));
5900 case 0x2c: /* fucom st(i) */
5901 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5902 gen_helper_fucom_ST0_FT0();
5904 case 0x2d: /* fucomp st(i) */
5905 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5906 gen_helper_fucom_ST0_FT0();
5909 case 0x33: /* de/3 */
5911 case 1: /* fcompp */
5912 gen_helper_fmov_FT0_STN(tcg_const_i32(1));
5913 gen_helper_fcom_ST0_FT0();
5921 case 0x38: /* ffreep sti, undocumented op */
5922 gen_helper_ffree_STN(tcg_const_i32(opreg
));
5925 case 0x3c: /* df/4 */
5928 gen_helper_fnstsw(cpu_tmp2_i32
);
5929 tcg_gen_extu_i32_tl(cpu_T
[0], cpu_tmp2_i32
);
5930 gen_op_mov_reg_T0(OT_WORD
, R_EAX
);
5936 case 0x3d: /* fucomip */
5937 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5938 gen_op_set_cc_op(s
->cc_op
);
5939 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5940 gen_helper_fucomi_ST0_FT0();
5942 s
->cc_op
= CC_OP_EFLAGS
;
5944 case 0x3e: /* fcomip */
5945 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5946 gen_op_set_cc_op(s
->cc_op
);
5947 gen_helper_fmov_FT0_STN(tcg_const_i32(opreg
));
5948 gen_helper_fcomi_ST0_FT0();
5950 s
->cc_op
= CC_OP_EFLAGS
;
5952 case 0x10 ... 0x13: /* fcmovxx */
5956 static const uint8_t fcmov_cc
[8] = {
5962 op1
= fcmov_cc
[op
& 3] | (((op
>> 3) & 1) ^ 1);
5963 l1
= gen_new_label();
5964 gen_jcc1(s
, s
->cc_op
, op1
, l1
);
5965 gen_helper_fmov_ST0_STN(tcg_const_i32(opreg
));
5974 /************************/
5977 case 0xa4: /* movsS */
5982 ot
= dflag
+ OT_WORD
;
5984 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5985 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5991 case 0xaa: /* stosS */
5996 ot
= dflag
+ OT_WORD
;
5998 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
5999 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6004 case 0xac: /* lodsS */
6009 ot
= dflag
+ OT_WORD
;
6010 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6011 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6016 case 0xae: /* scasS */
6021 ot
= dflag
+ OT_WORD
;
6022 if (prefixes
& PREFIX_REPNZ
) {
6023 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6024 } else if (prefixes
& PREFIX_REPZ
) {
6025 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6028 s
->cc_op
= CC_OP_SUBB
+ ot
;
6032 case 0xa6: /* cmpsS */
6037 ot
= dflag
+ OT_WORD
;
6038 if (prefixes
& PREFIX_REPNZ
) {
6039 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
6040 } else if (prefixes
& PREFIX_REPZ
) {
6041 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
6044 s
->cc_op
= CC_OP_SUBB
+ ot
;
6047 case 0x6c: /* insS */
6052 ot
= dflag
? OT_LONG
: OT_WORD
;
6053 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6054 gen_op_andl_T0_ffff();
6055 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6056 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
) | 4);
6057 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6058 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6062 gen_jmp(s
, s
->pc
- s
->cs_base
);
6066 case 0x6e: /* outsS */
6071 ot
= dflag
? OT_LONG
: OT_WORD
;
6072 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6073 gen_op_andl_T0_ffff();
6074 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6075 svm_is_rep(prefixes
) | 4);
6076 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
6077 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6081 gen_jmp(s
, s
->pc
- s
->cs_base
);
6086 /************************/
6094 ot
= dflag
? OT_LONG
: OT_WORD
;
6095 val
= ldub_code(s
->pc
++);
6096 gen_op_movl_T0_im(val
);
6097 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6098 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6101 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6102 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6103 gen_op_mov_reg_T1(ot
, R_EAX
);
6106 gen_jmp(s
, s
->pc
- s
->cs_base
);
6114 ot
= dflag
? OT_LONG
: OT_WORD
;
6115 val
= ldub_code(s
->pc
++);
6116 gen_op_movl_T0_im(val
);
6117 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6118 svm_is_rep(prefixes
));
6119 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6123 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6124 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6125 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6126 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6129 gen_jmp(s
, s
->pc
- s
->cs_base
);
6137 ot
= dflag
? OT_LONG
: OT_WORD
;
6138 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6139 gen_op_andl_T0_ffff();
6140 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6141 SVM_IOIO_TYPE_MASK
| svm_is_rep(prefixes
));
6144 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6145 gen_helper_in_func(ot
, cpu_T
[1], cpu_tmp2_i32
);
6146 gen_op_mov_reg_T1(ot
, R_EAX
);
6149 gen_jmp(s
, s
->pc
- s
->cs_base
);
6157 ot
= dflag
? OT_LONG
: OT_WORD
;
6158 gen_op_mov_TN_reg(OT_WORD
, 0, R_EDX
);
6159 gen_op_andl_T0_ffff();
6160 gen_check_io(s
, ot
, pc_start
- s
->cs_base
,
6161 svm_is_rep(prefixes
));
6162 gen_op_mov_TN_reg(ot
, 1, R_EAX
);
6166 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6167 tcg_gen_andi_i32(cpu_tmp2_i32
, cpu_tmp2_i32
, 0xffff);
6168 tcg_gen_trunc_tl_i32(cpu_tmp3_i32
, cpu_T
[1]);
6169 gen_helper_out_func(ot
, cpu_tmp2_i32
, cpu_tmp3_i32
);
6172 gen_jmp(s
, s
->pc
- s
->cs_base
);
6176 /************************/
6178 case 0xc2: /* ret im */
6179 val
= ldsw_code(s
->pc
);
6182 if (CODE64(s
) && s
->dflag
)
6184 gen_stack_update(s
, val
+ (2 << s
->dflag
));
6186 gen_op_andl_T0_ffff();
6190 case 0xc3: /* ret */
6194 gen_op_andl_T0_ffff();
6198 case 0xca: /* lret im */
6199 val
= ldsw_code(s
->pc
);
6202 if (s
->pe
&& !s
->vm86
) {
6203 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6204 gen_op_set_cc_op(s
->cc_op
);
6205 gen_jmp_im(pc_start
- s
->cs_base
);
6206 gen_helper_lret_protected(tcg_const_i32(s
->dflag
),
6207 tcg_const_i32(val
));
6211 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6213 gen_op_andl_T0_ffff();
6214 /* NOTE: keeping EIP updated is not a problem in case of
6218 gen_op_addl_A0_im(2 << s
->dflag
);
6219 gen_op_ld_T0_A0(1 + s
->dflag
+ s
->mem_index
);
6220 gen_op_movl_seg_T0_vm(R_CS
);
6221 /* add stack offset */
6222 gen_stack_update(s
, val
+ (4 << s
->dflag
));
6226 case 0xcb: /* lret */
6229 case 0xcf: /* iret */
6230 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IRET
);
6233 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6234 s
->cc_op
= CC_OP_EFLAGS
;
6235 } else if (s
->vm86
) {
6237 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6239 gen_helper_iret_real(tcg_const_i32(s
->dflag
));
6240 s
->cc_op
= CC_OP_EFLAGS
;
6243 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6244 gen_op_set_cc_op(s
->cc_op
);
6245 gen_jmp_im(pc_start
- s
->cs_base
);
6246 gen_helper_iret_protected(tcg_const_i32(s
->dflag
),
6247 tcg_const_i32(s
->pc
- s
->cs_base
));
6248 s
->cc_op
= CC_OP_EFLAGS
;
6252 case 0xe8: /* call im */
6255 tval
= (int32_t)insn_get(s
, OT_LONG
);
6257 tval
= (int16_t)insn_get(s
, OT_WORD
);
6258 next_eip
= s
->pc
- s
->cs_base
;
6264 gen_movtl_T0_im(next_eip
);
6269 case 0x9a: /* lcall im */
6271 unsigned int selector
, offset
;
6275 ot
= dflag
? OT_LONG
: OT_WORD
;
6276 offset
= insn_get(s
, ot
);
6277 selector
= insn_get(s
, OT_WORD
);
6279 gen_op_movl_T0_im(selector
);
6280 gen_op_movl_T1_imu(offset
);
6283 case 0xe9: /* jmp im */
6285 tval
= (int32_t)insn_get(s
, OT_LONG
);
6287 tval
= (int16_t)insn_get(s
, OT_WORD
);
6288 tval
+= s
->pc
- s
->cs_base
;
6295 case 0xea: /* ljmp im */
6297 unsigned int selector
, offset
;
6301 ot
= dflag
? OT_LONG
: OT_WORD
;
6302 offset
= insn_get(s
, ot
);
6303 selector
= insn_get(s
, OT_WORD
);
6305 gen_op_movl_T0_im(selector
);
6306 gen_op_movl_T1_imu(offset
);
6309 case 0xeb: /* jmp Jb */
6310 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6311 tval
+= s
->pc
- s
->cs_base
;
6316 case 0x70 ... 0x7f: /* jcc Jb */
6317 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6319 case 0x180 ... 0x18f: /* jcc Jv */
6321 tval
= (int32_t)insn_get(s
, OT_LONG
);
6323 tval
= (int16_t)insn_get(s
, OT_WORD
);
6326 next_eip
= s
->pc
- s
->cs_base
;
6330 gen_jcc(s
, b
, tval
, next_eip
);
6333 case 0x190 ... 0x19f: /* setcc Gv */
6334 modrm
= ldub_code(s
->pc
++);
6336 gen_ldst_modrm(s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
6338 case 0x140 ... 0x14f: /* cmov Gv, Ev */
6343 ot
= dflag
+ OT_WORD
;
6344 modrm
= ldub_code(s
->pc
++);
6345 reg
= ((modrm
>> 3) & 7) | rex_r
;
6346 mod
= (modrm
>> 6) & 3;
6347 t0
= tcg_temp_local_new();
6349 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6350 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
6352 rm
= (modrm
& 7) | REX_B(s
);
6353 gen_op_mov_v_reg(ot
, t0
, rm
);
6355 #ifdef TARGET_X86_64
6356 if (ot
== OT_LONG
) {
6357 /* XXX: specific Intel behaviour ? */
6358 l1
= gen_new_label();
6359 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6360 tcg_gen_mov_tl(cpu_regs
[reg
], t0
);
6362 tcg_gen_ext32u_tl(cpu_regs
[reg
], cpu_regs
[reg
]);
6366 l1
= gen_new_label();
6367 gen_jcc1(s
, s
->cc_op
, b
^ 1, l1
);
6368 gen_op_mov_reg_v(ot
, reg
, t0
);
6375 /************************/
6377 case 0x9c: /* pushf */
6378 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PUSHF
);
6379 if (s
->vm86
&& s
->iopl
!= 3) {
6380 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6382 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6383 gen_op_set_cc_op(s
->cc_op
);
6384 gen_helper_read_eflags(cpu_T
[0]);
6388 case 0x9d: /* popf */
6389 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_POPF
);
6390 if (s
->vm86
&& s
->iopl
!= 3) {
6391 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6396 gen_helper_write_eflags(cpu_T
[0],
6397 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
)));
6399 gen_helper_write_eflags(cpu_T
[0],
6400 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
| IOPL_MASK
) & 0xffff));
6403 if (s
->cpl
<= s
->iopl
) {
6405 gen_helper_write_eflags(cpu_T
[0],
6406 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
)));
6408 gen_helper_write_eflags(cpu_T
[0],
6409 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
| IF_MASK
) & 0xffff));
6413 gen_helper_write_eflags(cpu_T
[0],
6414 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
)));
6416 gen_helper_write_eflags(cpu_T
[0],
6417 tcg_const_i32((TF_MASK
| AC_MASK
| ID_MASK
| NT_MASK
) & 0xffff));
6422 s
->cc_op
= CC_OP_EFLAGS
;
6423 /* abort translation because TF flag may change */
6424 gen_jmp_im(s
->pc
- s
->cs_base
);
6428 case 0x9e: /* sahf */
6429 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6431 gen_op_mov_TN_reg(OT_BYTE
, 0, R_AH
);
6432 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6433 gen_op_set_cc_op(s
->cc_op
);
6434 gen_compute_eflags(cpu_cc_src
);
6435 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, CC_O
);
6436 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
6437 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, cpu_T
[0]);
6438 s
->cc_op
= CC_OP_EFLAGS
;
6440 case 0x9f: /* lahf */
6441 if (CODE64(s
) && !(s
->cpuid_ext3_features
& CPUID_EXT3_LAHF_LM
))
6443 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6444 gen_op_set_cc_op(s
->cc_op
);
6445 gen_compute_eflags(cpu_T
[0]);
6446 /* Note: gen_compute_eflags() only gives the condition codes */
6447 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], 0x02);
6448 gen_op_mov_reg_T0(OT_BYTE
, R_AH
);
6450 case 0xf5: /* cmc */
6451 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6452 gen_op_set_cc_op(s
->cc_op
);
6453 gen_compute_eflags(cpu_cc_src
);
6454 tcg_gen_xori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6455 s
->cc_op
= CC_OP_EFLAGS
;
6457 case 0xf8: /* clc */
6458 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6459 gen_op_set_cc_op(s
->cc_op
);
6460 gen_compute_eflags(cpu_cc_src
);
6461 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_C
);
6462 s
->cc_op
= CC_OP_EFLAGS
;
6464 case 0xf9: /* stc */
6465 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6466 gen_op_set_cc_op(s
->cc_op
);
6467 gen_compute_eflags(cpu_cc_src
);
6468 tcg_gen_ori_tl(cpu_cc_src
, cpu_cc_src
, CC_C
);
6469 s
->cc_op
= CC_OP_EFLAGS
;
6471 case 0xfc: /* cld */
6472 tcg_gen_movi_i32(cpu_tmp2_i32
, 1);
6473 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6475 case 0xfd: /* std */
6476 tcg_gen_movi_i32(cpu_tmp2_i32
, -1);
6477 tcg_gen_st_i32(cpu_tmp2_i32
, cpu_env
, offsetof(CPUState
, df
));
6480 /************************/
6481 /* bit operations */
6482 case 0x1ba: /* bt/bts/btr/btc Gv, im */
6483 ot
= dflag
+ OT_WORD
;
6484 modrm
= ldub_code(s
->pc
++);
6485 op
= (modrm
>> 3) & 7;
6486 mod
= (modrm
>> 6) & 3;
6487 rm
= (modrm
& 7) | REX_B(s
);
6490 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6491 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6493 gen_op_mov_TN_reg(ot
, 0, rm
);
6496 val
= ldub_code(s
->pc
++);
6497 gen_op_movl_T1_im(val
);
6502 case 0x1a3: /* bt Gv, Ev */
6505 case 0x1ab: /* bts */
6508 case 0x1b3: /* btr */
6511 case 0x1bb: /* btc */
6514 ot
= dflag
+ OT_WORD
;
6515 modrm
= ldub_code(s
->pc
++);
6516 reg
= ((modrm
>> 3) & 7) | rex_r
;
6517 mod
= (modrm
>> 6) & 3;
6518 rm
= (modrm
& 7) | REX_B(s
);
6519 gen_op_mov_TN_reg(OT_LONG
, 1, reg
);
6521 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6522 /* specific case: we need to add a displacement */
6523 gen_exts(ot
, cpu_T
[1]);
6524 tcg_gen_sari_tl(cpu_tmp0
, cpu_T
[1], 3 + ot
);
6525 tcg_gen_shli_tl(cpu_tmp0
, cpu_tmp0
, ot
);
6526 tcg_gen_add_tl(cpu_A0
, cpu_A0
, cpu_tmp0
);
6527 gen_op_ld_T0_A0(ot
+ s
->mem_index
);
6529 gen_op_mov_TN_reg(ot
, 0, rm
);
6532 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], (1 << (3 + ot
)) - 1);
6535 tcg_gen_shr_tl(cpu_cc_src
, cpu_T
[0], cpu_T
[1]);
6536 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6539 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6540 tcg_gen_movi_tl(cpu_tmp0
, 1);
6541 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6542 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6545 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6546 tcg_gen_movi_tl(cpu_tmp0
, 1);
6547 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6548 tcg_gen_not_tl(cpu_tmp0
, cpu_tmp0
);
6549 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6553 tcg_gen_shr_tl(cpu_tmp4
, cpu_T
[0], cpu_T
[1]);
6554 tcg_gen_movi_tl(cpu_tmp0
, 1);
6555 tcg_gen_shl_tl(cpu_tmp0
, cpu_tmp0
, cpu_T
[1]);
6556 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_tmp0
);
6559 s
->cc_op
= CC_OP_SARB
+ ot
;
6562 gen_op_st_T0_A0(ot
+ s
->mem_index
);
6564 gen_op_mov_reg_T0(ot
, rm
);
6565 tcg_gen_mov_tl(cpu_cc_src
, cpu_tmp4
);
6566 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6569 case 0x1bc: /* bsf */
6570 case 0x1bd: /* bsr */
6575 ot
= dflag
+ OT_WORD
;
6576 modrm
= ldub_code(s
->pc
++);
6577 reg
= ((modrm
>> 3) & 7) | rex_r
;
6578 gen_ldst_modrm(s
,modrm
, ot
, OR_TMP0
, 0);
6579 gen_extu(ot
, cpu_T
[0]);
6580 t0
= tcg_temp_local_new();
6581 tcg_gen_mov_tl(t0
, cpu_T
[0]);
6582 if ((b
& 1) && (prefixes
& PREFIX_REPZ
) &&
6583 (s
->cpuid_ext3_features
& CPUID_EXT3_ABM
)) {
6585 case OT_WORD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6586 tcg_const_i32(16)); break;
6587 case OT_LONG
: gen_helper_lzcnt(cpu_T
[0], t0
,
6588 tcg_const_i32(32)); break;
6589 case OT_QUAD
: gen_helper_lzcnt(cpu_T
[0], t0
,
6590 tcg_const_i32(64)); break;
6592 gen_op_mov_reg_T0(ot
, reg
);
6594 label1
= gen_new_label();
6595 tcg_gen_movi_tl(cpu_cc_dst
, 0);
6596 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, label1
);
6598 gen_helper_bsr(cpu_T
[0], t0
);
6600 gen_helper_bsf(cpu_T
[0], t0
);
6602 gen_op_mov_reg_T0(ot
, reg
);
6603 tcg_gen_movi_tl(cpu_cc_dst
, 1);
6604 gen_set_label(label1
);
6605 tcg_gen_discard_tl(cpu_cc_src
);
6606 s
->cc_op
= CC_OP_LOGICB
+ ot
;
6611 /************************/
6613 case 0x27: /* daa */
6616 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6617 gen_op_set_cc_op(s
->cc_op
);
6619 s
->cc_op
= CC_OP_EFLAGS
;
6621 case 0x2f: /* das */
6624 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6625 gen_op_set_cc_op(s
->cc_op
);
6627 s
->cc_op
= CC_OP_EFLAGS
;
6629 case 0x37: /* aaa */
6632 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6633 gen_op_set_cc_op(s
->cc_op
);
6635 s
->cc_op
= CC_OP_EFLAGS
;
6637 case 0x3f: /* aas */
6640 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6641 gen_op_set_cc_op(s
->cc_op
);
6643 s
->cc_op
= CC_OP_EFLAGS
;
6645 case 0xd4: /* aam */
6648 val
= ldub_code(s
->pc
++);
6650 gen_exception(s
, EXCP00_DIVZ
, pc_start
- s
->cs_base
);
6652 gen_helper_aam(tcg_const_i32(val
));
6653 s
->cc_op
= CC_OP_LOGICB
;
6656 case 0xd5: /* aad */
6659 val
= ldub_code(s
->pc
++);
6660 gen_helper_aad(tcg_const_i32(val
));
6661 s
->cc_op
= CC_OP_LOGICB
;
6663 /************************/
6665 case 0x90: /* nop */
6666 /* XXX: xchg + rex handling */
6667 /* XXX: correct lock test for all insn */
6668 if (prefixes
& PREFIX_LOCK
)
6670 if (prefixes
& PREFIX_REPZ
) {
6671 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_PAUSE
);
6674 case 0x9b: /* fwait */
6675 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
6676 (HF_MP_MASK
| HF_TS_MASK
)) {
6677 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
6679 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6680 gen_op_set_cc_op(s
->cc_op
);
6681 gen_jmp_im(pc_start
- s
->cs_base
);
6685 case 0xcc: /* int3 */
6686 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6688 case 0xcd: /* int N */
6689 val
= ldub_code(s
->pc
++);
6690 if (s
->vm86
&& s
->iopl
!= 3) {
6691 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6693 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
6696 case 0xce: /* into */
6699 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6700 gen_op_set_cc_op(s
->cc_op
);
6701 gen_jmp_im(pc_start
- s
->cs_base
);
6702 gen_helper_into(tcg_const_i32(s
->pc
- pc_start
));
6705 case 0xf1: /* icebp (undocumented, exits to external debugger) */
6706 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_ICEBP
);
6708 gen_debug(s
, pc_start
- s
->cs_base
);
6711 tb_flush(cpu_single_env
);
6712 cpu_set_log(CPU_LOG_INT
| CPU_LOG_TB_IN_ASM
);
6716 case 0xfa: /* cli */
6718 if (s
->cpl
<= s
->iopl
) {
6721 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6727 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6731 case 0xfb: /* sti */
6733 if (s
->cpl
<= s
->iopl
) {
6736 /* interruptions are enabled only the first insn after sti */
6737 /* If several instructions disable interrupts, only the
6739 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
6740 gen_helper_set_inhibit_irq();
6741 /* give a chance to handle pending irqs */
6742 gen_jmp_im(s
->pc
- s
->cs_base
);
6745 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6751 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6755 case 0x62: /* bound */
6758 ot
= dflag
? OT_LONG
: OT_WORD
;
6759 modrm
= ldub_code(s
->pc
++);
6760 reg
= (modrm
>> 3) & 7;
6761 mod
= (modrm
>> 6) & 3;
6764 gen_op_mov_TN_reg(ot
, 0, reg
);
6765 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
6766 gen_jmp_im(pc_start
- s
->cs_base
);
6767 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6769 gen_helper_boundw(cpu_A0
, cpu_tmp2_i32
);
6771 gen_helper_boundl(cpu_A0
, cpu_tmp2_i32
);
6773 case 0x1c8 ... 0x1cf: /* bswap reg */
6774 reg
= (b
& 7) | REX_B(s
);
6775 #ifdef TARGET_X86_64
6777 gen_op_mov_TN_reg(OT_QUAD
, 0, reg
);
6778 tcg_gen_bswap64_i64(cpu_T
[0], cpu_T
[0]);
6779 gen_op_mov_reg_T0(OT_QUAD
, reg
);
6783 gen_op_mov_TN_reg(OT_LONG
, 0, reg
);
6784 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
6785 tcg_gen_bswap32_tl(cpu_T
[0], cpu_T
[0]);
6786 gen_op_mov_reg_T0(OT_LONG
, reg
);
6789 case 0xd6: /* salc */
6792 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6793 gen_op_set_cc_op(s
->cc_op
);
6794 gen_compute_eflags_c(cpu_T
[0]);
6795 tcg_gen_neg_tl(cpu_T
[0], cpu_T
[0]);
6796 gen_op_mov_reg_T0(OT_BYTE
, R_EAX
);
6798 case 0xe0: /* loopnz */
6799 case 0xe1: /* loopz */
6800 case 0xe2: /* loop */
6801 case 0xe3: /* jecxz */
6805 tval
= (int8_t)insn_get(s
, OT_BYTE
);
6806 next_eip
= s
->pc
- s
->cs_base
;
6811 l1
= gen_new_label();
6812 l2
= gen_new_label();
6813 l3
= gen_new_label();
6816 case 0: /* loopnz */
6818 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6819 gen_op_set_cc_op(s
->cc_op
);
6820 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6821 gen_op_jz_ecx(s
->aflag
, l3
);
6822 gen_compute_eflags(cpu_tmp0
);
6823 tcg_gen_andi_tl(cpu_tmp0
, cpu_tmp0
, CC_Z
);
6825 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, l1
);
6827 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_tmp0
, 0, l1
);
6831 gen_op_add_reg_im(s
->aflag
, R_ECX
, -1);
6832 gen_op_jnz_ecx(s
->aflag
, l1
);
6836 gen_op_jz_ecx(s
->aflag
, l1
);
6841 gen_jmp_im(next_eip
);
6850 case 0x130: /* wrmsr */
6851 case 0x132: /* rdmsr */
6853 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6855 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6856 gen_op_set_cc_op(s
->cc_op
);
6857 gen_jmp_im(pc_start
- s
->cs_base
);
6865 case 0x131: /* rdtsc */
6866 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6867 gen_op_set_cc_op(s
->cc_op
);
6868 gen_jmp_im(pc_start
- s
->cs_base
);
6874 gen_jmp(s
, s
->pc
- s
->cs_base
);
6877 case 0x133: /* rdpmc */
6878 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6879 gen_op_set_cc_op(s
->cc_op
);
6880 gen_jmp_im(pc_start
- s
->cs_base
);
6883 case 0x134: /* sysenter */
6884 /* For Intel SYSENTER is valid on 64-bit */
6885 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6888 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6890 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6891 gen_op_set_cc_op(s
->cc_op
);
6892 s
->cc_op
= CC_OP_DYNAMIC
;
6894 gen_jmp_im(pc_start
- s
->cs_base
);
6895 gen_helper_sysenter();
6899 case 0x135: /* sysexit */
6900 /* For Intel SYSEXIT is valid on 64-bit */
6901 if (CODE64(s
) && cpu_single_env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
)
6904 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6906 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6907 gen_op_set_cc_op(s
->cc_op
);
6908 s
->cc_op
= CC_OP_DYNAMIC
;
6910 gen_jmp_im(pc_start
- s
->cs_base
);
6911 gen_helper_sysexit(tcg_const_i32(dflag
));
6915 #ifdef TARGET_X86_64
6916 case 0x105: /* syscall */
6917 /* XXX: is it usable in real mode ? */
6918 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6919 gen_op_set_cc_op(s
->cc_op
);
6920 s
->cc_op
= CC_OP_DYNAMIC
;
6922 gen_jmp_im(pc_start
- s
->cs_base
);
6923 gen_helper_syscall(tcg_const_i32(s
->pc
- pc_start
));
6926 case 0x107: /* sysret */
6928 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6930 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
6931 gen_op_set_cc_op(s
->cc_op
);
6932 s
->cc_op
= CC_OP_DYNAMIC
;
6934 gen_jmp_im(pc_start
- s
->cs_base
);
6935 gen_helper_sysret(tcg_const_i32(s
->dflag
));
6936 /* condition codes are modified only in long mode */
6938 s
->cc_op
= CC_OP_EFLAGS
;
6943 case 0x1a2: /* cpuid */
6944 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6945 gen_op_set_cc_op(s
->cc_op
);
6946 gen_jmp_im(pc_start
- s
->cs_base
);
6949 case 0xf4: /* hlt */
6951 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6953 if (s
->cc_op
!= CC_OP_DYNAMIC
)
6954 gen_op_set_cc_op(s
->cc_op
);
6955 gen_jmp_im(pc_start
- s
->cs_base
);
6956 gen_helper_hlt(tcg_const_i32(s
->pc
- pc_start
));
6961 modrm
= ldub_code(s
->pc
++);
6962 mod
= (modrm
>> 6) & 3;
6963 op
= (modrm
>> 3) & 7;
6966 if (!s
->pe
|| s
->vm86
)
6968 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_READ
);
6969 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,ldt
.selector
));
6973 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6976 if (!s
->pe
|| s
->vm86
)
6979 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
6981 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_LDTR_WRITE
);
6982 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
6983 gen_jmp_im(pc_start
- s
->cs_base
);
6984 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
6985 gen_helper_lldt(cpu_tmp2_i32
);
6989 if (!s
->pe
|| s
->vm86
)
6991 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_READ
);
6992 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,tr
.selector
));
6996 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
6999 if (!s
->pe
|| s
->vm86
)
7002 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7004 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_TR_WRITE
);
7005 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7006 gen_jmp_im(pc_start
- s
->cs_base
);
7007 tcg_gen_trunc_tl_i32(cpu_tmp2_i32
, cpu_T
[0]);
7008 gen_helper_ltr(cpu_tmp2_i32
);
7013 if (!s
->pe
|| s
->vm86
)
7015 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7016 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7017 gen_op_set_cc_op(s
->cc_op
);
7019 gen_helper_verr(cpu_T
[0]);
7021 gen_helper_verw(cpu_T
[0]);
7022 s
->cc_op
= CC_OP_EFLAGS
;
7029 modrm
= ldub_code(s
->pc
++);
7030 mod
= (modrm
>> 6) & 3;
7031 op
= (modrm
>> 3) & 7;
7037 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_GDTR_READ
);
7038 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7039 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.limit
));
7040 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7041 gen_add_A0_im(s
, 2);
7042 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, gdt
.base
));
7044 gen_op_andl_T0_im(0xffffff);
7045 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7050 case 0: /* monitor */
7051 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7054 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7055 gen_op_set_cc_op(s
->cc_op
);
7056 gen_jmp_im(pc_start
- s
->cs_base
);
7057 #ifdef TARGET_X86_64
7058 if (s
->aflag
== 2) {
7059 gen_op_movq_A0_reg(R_EAX
);
7063 gen_op_movl_A0_reg(R_EAX
);
7065 gen_op_andl_A0_ffff();
7067 gen_add_A0_ds_seg(s
);
7068 gen_helper_monitor(cpu_A0
);
7071 if (!(s
->cpuid_ext_features
& CPUID_EXT_MONITOR
) ||
7074 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7075 gen_op_set_cc_op(s
->cc_op
);
7076 s
->cc_op
= CC_OP_DYNAMIC
;
7078 gen_jmp_im(pc_start
- s
->cs_base
);
7079 gen_helper_mwait(tcg_const_i32(s
->pc
- pc_start
));
7086 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_IDTR_READ
);
7087 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7088 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.limit
));
7089 gen_op_st_T0_A0(OT_WORD
+ s
->mem_index
);
7090 gen_add_A0_im(s
, 2);
7091 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, idt
.base
));
7093 gen_op_andl_T0_im(0xffffff);
7094 gen_op_st_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7100 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7101 gen_op_set_cc_op(s
->cc_op
);
7102 gen_jmp_im(pc_start
- s
->cs_base
);
7105 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7108 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7111 gen_helper_vmrun(tcg_const_i32(s
->aflag
),
7112 tcg_const_i32(s
->pc
- pc_start
));
7117 case 1: /* VMMCALL */
7118 if (!(s
->flags
& HF_SVME_MASK
))
7120 gen_helper_vmmcall();
7122 case 2: /* VMLOAD */
7123 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7126 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7129 gen_helper_vmload(tcg_const_i32(s
->aflag
));
7132 case 3: /* VMSAVE */
7133 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7136 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7139 gen_helper_vmsave(tcg_const_i32(s
->aflag
));
7143 if ((!(s
->flags
& HF_SVME_MASK
) &&
7144 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7148 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7155 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7158 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7164 case 6: /* SKINIT */
7165 if ((!(s
->flags
& HF_SVME_MASK
) &&
7166 !(s
->cpuid_ext3_features
& CPUID_EXT3_SKINIT
)) ||
7169 gen_helper_skinit();
7171 case 7: /* INVLPGA */
7172 if (!(s
->flags
& HF_SVME_MASK
) || !s
->pe
)
7175 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7178 gen_helper_invlpga(tcg_const_i32(s
->aflag
));
7184 } else if (s
->cpl
!= 0) {
7185 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7187 gen_svm_check_intercept(s
, pc_start
,
7188 op
==2 ? SVM_EXIT_GDTR_WRITE
: SVM_EXIT_IDTR_WRITE
);
7189 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7190 gen_op_ld_T1_A0(OT_WORD
+ s
->mem_index
);
7191 gen_add_A0_im(s
, 2);
7192 gen_op_ld_T0_A0(CODE64(s
) + OT_LONG
+ s
->mem_index
);
7194 gen_op_andl_T0_im(0xffffff);
7196 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,gdt
.base
));
7197 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,gdt
.limit
));
7199 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,idt
.base
));
7200 tcg_gen_st32_tl(cpu_T
[1], cpu_env
, offsetof(CPUX86State
,idt
.limit
));
7205 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_CR0
);
7206 #if defined TARGET_X86_64 && defined HOST_WORDS_BIGENDIAN
7207 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]) + 4);
7209 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,cr
[0]));
7211 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 1);
7215 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7217 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7218 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7219 gen_helper_lmsw(cpu_T
[0]);
7220 gen_jmp_im(s
->pc
- s
->cs_base
);
7225 if (mod
!= 3) { /* invlpg */
7227 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7229 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7230 gen_op_set_cc_op(s
->cc_op
);
7231 gen_jmp_im(pc_start
- s
->cs_base
);
7232 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7233 gen_helper_invlpg(cpu_A0
);
7234 gen_jmp_im(s
->pc
- s
->cs_base
);
7239 case 0: /* swapgs */
7240 #ifdef TARGET_X86_64
7243 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7245 tcg_gen_ld_tl(cpu_T
[0], cpu_env
,
7246 offsetof(CPUX86State
,segs
[R_GS
].base
));
7247 tcg_gen_ld_tl(cpu_T
[1], cpu_env
,
7248 offsetof(CPUX86State
,kernelgsbase
));
7249 tcg_gen_st_tl(cpu_T
[1], cpu_env
,
7250 offsetof(CPUX86State
,segs
[R_GS
].base
));
7251 tcg_gen_st_tl(cpu_T
[0], cpu_env
,
7252 offsetof(CPUX86State
,kernelgsbase
));
7260 case 1: /* rdtscp */
7261 if (!(s
->cpuid_ext2_features
& CPUID_EXT2_RDTSCP
))
7263 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7264 gen_op_set_cc_op(s
->cc_op
);
7265 gen_jmp_im(pc_start
- s
->cs_base
);
7268 gen_helper_rdtscp();
7271 gen_jmp(s
, s
->pc
- s
->cs_base
);
7283 case 0x108: /* invd */
7284 case 0x109: /* wbinvd */
7286 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7288 gen_svm_check_intercept(s
, pc_start
, (b
& 2) ? SVM_EXIT_INVD
: SVM_EXIT_WBINVD
);
7292 case 0x63: /* arpl or movslS (x86_64) */
7293 #ifdef TARGET_X86_64
7296 /* d_ot is the size of destination */
7297 d_ot
= dflag
+ OT_WORD
;
7299 modrm
= ldub_code(s
->pc
++);
7300 reg
= ((modrm
>> 3) & 7) | rex_r
;
7301 mod
= (modrm
>> 6) & 3;
7302 rm
= (modrm
& 7) | REX_B(s
);
7305 gen_op_mov_TN_reg(OT_LONG
, 0, rm
);
7307 if (d_ot
== OT_QUAD
)
7308 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
7309 gen_op_mov_reg_T0(d_ot
, reg
);
7311 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7312 if (d_ot
== OT_QUAD
) {
7313 gen_op_lds_T0_A0(OT_LONG
+ s
->mem_index
);
7315 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7317 gen_op_mov_reg_T0(d_ot
, reg
);
7323 TCGv t0
, t1
, t2
, a0
;
7325 if (!s
->pe
|| s
->vm86
)
7327 t0
= tcg_temp_local_new();
7328 t1
= tcg_temp_local_new();
7329 t2
= tcg_temp_local_new();
7331 modrm
= ldub_code(s
->pc
++);
7332 reg
= (modrm
>> 3) & 7;
7333 mod
= (modrm
>> 6) & 3;
7336 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7337 gen_op_ld_v(ot
+ s
->mem_index
, t0
, cpu_A0
);
7338 a0
= tcg_temp_local_new();
7339 tcg_gen_mov_tl(a0
, cpu_A0
);
7341 gen_op_mov_v_reg(ot
, t0
, rm
);
7344 gen_op_mov_v_reg(ot
, t1
, reg
);
7345 tcg_gen_andi_tl(cpu_tmp0
, t0
, 3);
7346 tcg_gen_andi_tl(t1
, t1
, 3);
7347 tcg_gen_movi_tl(t2
, 0);
7348 label1
= gen_new_label();
7349 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_tmp0
, t1
, label1
);
7350 tcg_gen_andi_tl(t0
, t0
, ~3);
7351 tcg_gen_or_tl(t0
, t0
, t1
);
7352 tcg_gen_movi_tl(t2
, CC_Z
);
7353 gen_set_label(label1
);
7355 gen_op_st_v(ot
+ s
->mem_index
, t0
, a0
);
7358 gen_op_mov_reg_v(ot
, rm
, t0
);
7360 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7361 gen_op_set_cc_op(s
->cc_op
);
7362 gen_compute_eflags(cpu_cc_src
);
7363 tcg_gen_andi_tl(cpu_cc_src
, cpu_cc_src
, ~CC_Z
);
7364 tcg_gen_or_tl(cpu_cc_src
, cpu_cc_src
, t2
);
7365 s
->cc_op
= CC_OP_EFLAGS
;
7371 case 0x102: /* lar */
7372 case 0x103: /* lsl */
7376 if (!s
->pe
|| s
->vm86
)
7378 ot
= dflag
? OT_LONG
: OT_WORD
;
7379 modrm
= ldub_code(s
->pc
++);
7380 reg
= ((modrm
>> 3) & 7) | rex_r
;
7381 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
7382 t0
= tcg_temp_local_new();
7383 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7384 gen_op_set_cc_op(s
->cc_op
);
7386 gen_helper_lar(t0
, cpu_T
[0]);
7388 gen_helper_lsl(t0
, cpu_T
[0]);
7389 tcg_gen_andi_tl(cpu_tmp0
, cpu_cc_src
, CC_Z
);
7390 label1
= gen_new_label();
7391 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_tmp0
, 0, label1
);
7392 gen_op_mov_reg_v(ot
, reg
, t0
);
7393 gen_set_label(label1
);
7394 s
->cc_op
= CC_OP_EFLAGS
;
7399 modrm
= ldub_code(s
->pc
++);
7400 mod
= (modrm
>> 6) & 3;
7401 op
= (modrm
>> 3) & 7;
7403 case 0: /* prefetchnta */
7404 case 1: /* prefetchnt0 */
7405 case 2: /* prefetchnt0 */
7406 case 3: /* prefetchnt0 */
7409 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7410 /* nothing more to do */
7412 default: /* nop (multi byte) */
7413 gen_nop_modrm(s
, modrm
);
7417 case 0x119 ... 0x11f: /* nop (multi byte) */
7418 modrm
= ldub_code(s
->pc
++);
7419 gen_nop_modrm(s
, modrm
);
7421 case 0x120: /* mov reg, crN */
7422 case 0x122: /* mov crN, reg */
7424 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7426 modrm
= ldub_code(s
->pc
++);
7427 if ((modrm
& 0xc0) != 0xc0)
7429 rm
= (modrm
& 7) | REX_B(s
);
7430 reg
= ((modrm
>> 3) & 7) | rex_r
;
7435 if ((prefixes
& PREFIX_LOCK
) && (reg
== 0) &&
7436 (s
->cpuid_ext3_features
& CPUID_EXT3_CR8LEG
)) {
7445 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7446 gen_op_set_cc_op(s
->cc_op
);
7447 gen_jmp_im(pc_start
- s
->cs_base
);
7449 gen_op_mov_TN_reg(ot
, 0, rm
);
7450 gen_helper_write_crN(tcg_const_i32(reg
), cpu_T
[0]);
7451 gen_jmp_im(s
->pc
- s
->cs_base
);
7454 gen_helper_read_crN(cpu_T
[0], tcg_const_i32(reg
));
7455 gen_op_mov_reg_T0(ot
, rm
);
7463 case 0x121: /* mov reg, drN */
7464 case 0x123: /* mov drN, reg */
7466 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7468 modrm
= ldub_code(s
->pc
++);
7469 if ((modrm
& 0xc0) != 0xc0)
7471 rm
= (modrm
& 7) | REX_B(s
);
7472 reg
= ((modrm
>> 3) & 7) | rex_r
;
7477 /* XXX: do it dynamically with CR4.DE bit */
7478 if (reg
== 4 || reg
== 5 || reg
>= 8)
7481 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_DR0
+ reg
);
7482 gen_op_mov_TN_reg(ot
, 0, rm
);
7483 gen_helper_movl_drN_T0(tcg_const_i32(reg
), cpu_T
[0]);
7484 gen_jmp_im(s
->pc
- s
->cs_base
);
7487 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_READ_DR0
+ reg
);
7488 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
,dr
[reg
]));
7489 gen_op_mov_reg_T0(ot
, rm
);
7493 case 0x106: /* clts */
7495 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
7497 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_WRITE_CR0
);
7499 /* abort block because static cpu state changed */
7500 gen_jmp_im(s
->pc
- s
->cs_base
);
7504 /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
7505 case 0x1c3: /* MOVNTI reg, mem */
7506 if (!(s
->cpuid_features
& CPUID_SSE2
))
7508 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
7509 modrm
= ldub_code(s
->pc
++);
7510 mod
= (modrm
>> 6) & 3;
7513 reg
= ((modrm
>> 3) & 7) | rex_r
;
7514 /* generate a generic store */
7515 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
7518 modrm
= ldub_code(s
->pc
++);
7519 mod
= (modrm
>> 6) & 3;
7520 op
= (modrm
>> 3) & 7;
7522 case 0: /* fxsave */
7523 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7524 (s
->prefix
& PREFIX_LOCK
))
7526 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7527 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7530 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7531 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7532 gen_op_set_cc_op(s
->cc_op
);
7533 gen_jmp_im(pc_start
- s
->cs_base
);
7534 gen_helper_fxsave(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7536 case 1: /* fxrstor */
7537 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
) ||
7538 (s
->prefix
& PREFIX_LOCK
))
7540 if ((s
->flags
& HF_EM_MASK
) || (s
->flags
& HF_TS_MASK
)) {
7541 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7544 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7545 if (s
->cc_op
!= CC_OP_DYNAMIC
)
7546 gen_op_set_cc_op(s
->cc_op
);
7547 gen_jmp_im(pc_start
- s
->cs_base
);
7548 gen_helper_fxrstor(cpu_A0
, tcg_const_i32((s
->dflag
== 2)));
7550 case 2: /* ldmxcsr */
7551 case 3: /* stmxcsr */
7552 if (s
->flags
& HF_TS_MASK
) {
7553 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
7556 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
7559 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7561 gen_op_ld_T0_A0(OT_LONG
+ s
->mem_index
);
7562 tcg_gen_st32_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7564 tcg_gen_ld32u_tl(cpu_T
[0], cpu_env
, offsetof(CPUX86State
, mxcsr
));
7565 gen_op_st_T0_A0(OT_LONG
+ s
->mem_index
);
7568 case 5: /* lfence */
7569 case 6: /* mfence */
7570 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE
))
7573 case 7: /* sfence / clflush */
7574 if ((modrm
& 0xc7) == 0xc0) {
7576 /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
7577 if (!(s
->cpuid_features
& CPUID_SSE
))
7581 if (!(s
->cpuid_features
& CPUID_CLFLUSH
))
7583 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7590 case 0x10d: /* 3DNow! prefetch(w) */
7591 modrm
= ldub_code(s
->pc
++);
7592 mod
= (modrm
>> 6) & 3;
7595 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
7596 /* ignore for now */
7598 case 0x1aa: /* rsm */
7599 gen_svm_check_intercept(s
, pc_start
, SVM_EXIT_RSM
);
7600 if (!(s
->flags
& HF_SMM_MASK
))
7602 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
7603 gen_op_set_cc_op(s
->cc_op
);
7604 s
->cc_op
= CC_OP_DYNAMIC
;
7606 gen_jmp_im(s
->pc
- s
->cs_base
);
7610 case 0x1b8: /* SSE4.2 popcnt */
7611 if ((prefixes
& (PREFIX_REPZ
| PREFIX_LOCK
| PREFIX_REPNZ
)) !=
7614 if (!(s
->cpuid_ext_features
& CPUID_EXT_POPCNT
))
7617 modrm
= ldub_code(s
->pc
++);
7618 reg
= ((modrm
>> 3) & 7);
7620 if (s
->prefix
& PREFIX_DATA
)
7622 else if (s
->dflag
!= 2)
7627 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
7628 gen_helper_popcnt(cpu_T
[0], cpu_T
[0], tcg_const_i32(ot
));
7629 gen_op_mov_reg_T0(ot
, reg
);
7631 s
->cc_op
= CC_OP_EFLAGS
;
7633 case 0x10e ... 0x10f:
7634 /* 3DNow! instructions, ignore prefixes */
7635 s
->prefix
&= ~(PREFIX_REPZ
| PREFIX_REPNZ
| PREFIX_DATA
);
7636 case 0x110 ... 0x117:
7637 case 0x128 ... 0x12f:
7638 case 0x138 ... 0x13a:
7639 case 0x150 ... 0x179:
7640 case 0x17c ... 0x17f:
7642 case 0x1c4 ... 0x1c6:
7643 case 0x1d0 ... 0x1fe:
7644 gen_sse(s
, b
, pc_start
, rex_r
);
7649 /* lock generation */
7650 if (s
->prefix
& PREFIX_LOCK
)
7651 gen_helper_unlock();
7654 if (s
->prefix
& PREFIX_LOCK
)
7655 gen_helper_unlock();
7656 /* XXX: ensure that no lock was generated */
7657 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
7661 void optimize_flags_init(void)
7663 #if TCG_TARGET_REG_BITS == 32
7664 assert(sizeof(CCTable
) == (1 << 3));
7666 assert(sizeof(CCTable
) == (1 << 4));
7668 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
7669 cpu_cc_op
= tcg_global_mem_new_i32(TCG_AREG0
,
7670 offsetof(CPUState
, cc_op
), "cc_op");
7671 cpu_cc_src
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_src
),
7673 cpu_cc_dst
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_dst
),
7675 cpu_cc_tmp
= tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, cc_tmp
),
7678 #ifdef TARGET_X86_64
7679 cpu_regs
[R_EAX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7680 offsetof(CPUState
, regs
[R_EAX
]), "rax");
7681 cpu_regs
[R_ECX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7682 offsetof(CPUState
, regs
[R_ECX
]), "rcx");
7683 cpu_regs
[R_EDX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7684 offsetof(CPUState
, regs
[R_EDX
]), "rdx");
7685 cpu_regs
[R_EBX
] = tcg_global_mem_new_i64(TCG_AREG0
,
7686 offsetof(CPUState
, regs
[R_EBX
]), "rbx");
7687 cpu_regs
[R_ESP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7688 offsetof(CPUState
, regs
[R_ESP
]), "rsp");
7689 cpu_regs
[R_EBP
] = tcg_global_mem_new_i64(TCG_AREG0
,
7690 offsetof(CPUState
, regs
[R_EBP
]), "rbp");
7691 cpu_regs
[R_ESI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7692 offsetof(CPUState
, regs
[R_ESI
]), "rsi");
7693 cpu_regs
[R_EDI
] = tcg_global_mem_new_i64(TCG_AREG0
,
7694 offsetof(CPUState
, regs
[R_EDI
]), "rdi");
7695 cpu_regs
[8] = tcg_global_mem_new_i64(TCG_AREG0
,
7696 offsetof(CPUState
, regs
[8]), "r8");
7697 cpu_regs
[9] = tcg_global_mem_new_i64(TCG_AREG0
,
7698 offsetof(CPUState
, regs
[9]), "r9");
7699 cpu_regs
[10] = tcg_global_mem_new_i64(TCG_AREG0
,
7700 offsetof(CPUState
, regs
[10]), "r10");
7701 cpu_regs
[11] = tcg_global_mem_new_i64(TCG_AREG0
,
7702 offsetof(CPUState
, regs
[11]), "r11");
7703 cpu_regs
[12] = tcg_global_mem_new_i64(TCG_AREG0
,
7704 offsetof(CPUState
, regs
[12]), "r12");
7705 cpu_regs
[13] = tcg_global_mem_new_i64(TCG_AREG0
,
7706 offsetof(CPUState
, regs
[13]), "r13");
7707 cpu_regs
[14] = tcg_global_mem_new_i64(TCG_AREG0
,
7708 offsetof(CPUState
, regs
[14]), "r14");
7709 cpu_regs
[15] = tcg_global_mem_new_i64(TCG_AREG0
,
7710 offsetof(CPUState
, regs
[15]), "r15");
7712 cpu_regs
[R_EAX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7713 offsetof(CPUState
, regs
[R_EAX
]), "eax");
7714 cpu_regs
[R_ECX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7715 offsetof(CPUState
, regs
[R_ECX
]), "ecx");
7716 cpu_regs
[R_EDX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7717 offsetof(CPUState
, regs
[R_EDX
]), "edx");
7718 cpu_regs
[R_EBX
] = tcg_global_mem_new_i32(TCG_AREG0
,
7719 offsetof(CPUState
, regs
[R_EBX
]), "ebx");
7720 cpu_regs
[R_ESP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7721 offsetof(CPUState
, regs
[R_ESP
]), "esp");
7722 cpu_regs
[R_EBP
] = tcg_global_mem_new_i32(TCG_AREG0
,
7723 offsetof(CPUState
, regs
[R_EBP
]), "ebp");
7724 cpu_regs
[R_ESI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7725 offsetof(CPUState
, regs
[R_ESI
]), "esi");
7726 cpu_regs
[R_EDI
] = tcg_global_mem_new_i32(TCG_AREG0
,
7727 offsetof(CPUState
, regs
[R_EDI
]), "edi");
7730 /* register helpers */
7731 #define GEN_HELPER 2
7735 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
7736 basic block 'tb'. If search_pc is TRUE, also generate PC
7737 information for each intermediate instruction. */
7738 static inline void gen_intermediate_code_internal(CPUState
*env
,
7739 TranslationBlock
*tb
,
7742 DisasContext dc1
, *dc
= &dc1
;
7743 target_ulong pc_ptr
;
7744 uint16_t *gen_opc_end
;
7748 target_ulong pc_start
;
7749 target_ulong cs_base
;
7753 /* generate intermediate code */
7755 cs_base
= tb
->cs_base
;
7758 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
7759 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
7760 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
7761 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
7763 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
7764 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
7765 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
7766 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
7767 dc
->singlestep_enabled
= env
->singlestep_enabled
;
7768 dc
->cc_op
= CC_OP_DYNAMIC
;
7769 dc
->cs_base
= cs_base
;
7771 dc
->popl_esp_hack
= 0;
7772 /* select memory access functions */
7774 if (flags
& HF_SOFTMMU_MASK
) {
7776 dc
->mem_index
= 2 * 4;
7778 dc
->mem_index
= 1 * 4;
7780 dc
->cpuid_features
= env
->cpuid_features
;
7781 dc
->cpuid_ext_features
= env
->cpuid_ext_features
;
7782 dc
->cpuid_ext2_features
= env
->cpuid_ext2_features
;
7783 dc
->cpuid_ext3_features
= env
->cpuid_ext3_features
;
7784 #ifdef TARGET_X86_64
7785 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
7786 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
7789 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
7790 (flags
& HF_INHIBIT_IRQ_MASK
)
7791 #ifndef CONFIG_SOFTMMU
7792 || (flags
& HF_SOFTMMU_MASK
)
7796 /* check addseg logic */
7797 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
7798 printf("ERROR addseg\n");
7801 cpu_T
[0] = tcg_temp_new();
7802 cpu_T
[1] = tcg_temp_new();
7803 cpu_A0
= tcg_temp_new();
7804 cpu_T3
= tcg_temp_new();
7806 cpu_tmp0
= tcg_temp_new();
7807 cpu_tmp1_i64
= tcg_temp_new_i64();
7808 cpu_tmp2_i32
= tcg_temp_new_i32();
7809 cpu_tmp3_i32
= tcg_temp_new_i32();
7810 cpu_tmp4
= tcg_temp_new();
7811 cpu_tmp5
= tcg_temp_new();
7812 cpu_ptr0
= tcg_temp_new_ptr();
7813 cpu_ptr1
= tcg_temp_new_ptr();
7815 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7817 dc
->is_jmp
= DISAS_NEXT
;
7821 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7823 max_insns
= CF_COUNT_MASK
;
7827 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
7828 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7829 if (bp
->pc
== pc_ptr
&&
7830 !((bp
->flags
& BP_CPU
) && (tb
->flags
& HF_RF_MASK
))) {
7831 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
7837 j
= gen_opc_ptr
- gen_opc_buf
;
7841 gen_opc_instr_start
[lj
++] = 0;
7843 gen_opc_pc
[lj
] = pc_ptr
;
7844 gen_opc_cc_op
[lj
] = dc
->cc_op
;
7845 gen_opc_instr_start
[lj
] = 1;
7846 gen_opc_icount
[lj
] = num_insns
;
7848 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7851 pc_ptr
= disas_insn(dc
, pc_ptr
);
7853 /* stop translation if indicated */
7856 /* if single step mode, we generate only one instruction and
7857 generate an exception */
7858 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
7859 the flag and abort the translation to give the irqs a
7860 change to be happen */
7861 if (dc
->tf
|| dc
->singlestep_enabled
||
7862 (flags
& HF_INHIBIT_IRQ_MASK
)) {
7863 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7867 /* if too long translation, stop generation too */
7868 if (gen_opc_ptr
>= gen_opc_end
||
7869 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32) ||
7870 num_insns
>= max_insns
) {
7871 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7876 gen_jmp_im(pc_ptr
- dc
->cs_base
);
7881 if (tb
->cflags
& CF_LAST_IO
)
7883 gen_icount_end(tb
, num_insns
);
7884 *gen_opc_ptr
= INDEX_op_end
;
7885 /* we don't forget to fill the last values */
7887 j
= gen_opc_ptr
- gen_opc_buf
;
7890 gen_opc_instr_start
[lj
++] = 0;
7894 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, X86_DUMP_CCOP
);
7895 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
7897 qemu_log("----------------\n");
7898 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
7899 #ifdef TARGET_X86_64
7904 disas_flags
= !dc
->code32
;
7905 log_target_disas(pc_start
, pc_ptr
- pc_start
, disas_flags
);
7911 tb
->size
= pc_ptr
- pc_start
;
7912 tb
->icount
= num_insns
;
7916 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
7918 gen_intermediate_code_internal(env
, tb
, 0);
7921 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
7923 gen_intermediate_code_internal(env
, tb
, 1);
7926 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7927 unsigned long searched_pc
, int pc_pos
, void *puc
)
7931 if (qemu_loglevel_mask(CPU_LOG_TB_OP
)) {
7933 qemu_log("RESTORE:\n");
7934 for(i
= 0;i
<= pc_pos
; i
++) {
7935 if (gen_opc_instr_start
[i
]) {
7936 qemu_log("0x%04x: " TARGET_FMT_lx
"\n", i
, gen_opc_pc
[i
]);
7939 qemu_log("spc=0x%08lx pc_pos=0x%x eip=" TARGET_FMT_lx
" cs_base=%x\n",
7940 searched_pc
, pc_pos
, gen_opc_pc
[pc_pos
] - tb
->cs_base
,
7941 (uint32_t)tb
->cs_base
);
7944 env
->eip
= gen_opc_pc
[pc_pos
] - tb
->cs_base
;
7945 cc_op
= gen_opc_cc_op
[pc_pos
];
7946 if (cc_op
!= CC_OP_DYNAMIC
)