4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 /* XXX: move that elsewhere */
33 static uint16_t *gen_opc_ptr
;
34 static uint32_t *gen_opparam_ptr
;
36 #define PREFIX_REPZ 0x01
37 #define PREFIX_REPNZ 0x02
38 #define PREFIX_LOCK 0x04
39 #define PREFIX_DATA 0x08
40 #define PREFIX_ADR 0x10
43 #define X86_64_ONLY(x) x
44 #define X86_64_DEF(x...) x
45 #define CODE64(s) ((s)->code64)
46 #define REX_X(s) ((s)->rex_x)
47 #define REX_B(s) ((s)->rex_b)
48 /* XXX: gcc generates push/pop in some opcodes, so we cannot use them */
50 #define BUGGY_64(x) NULL
53 #define X86_64_ONLY(x) NULL
54 #define X86_64_DEF(x...)
61 static int x86_64_hregs
;
64 #ifdef USE_DIRECT_JUMP
67 #define TBPARAM(x) (long)(x)
70 typedef struct DisasContext
{
71 /* current insn context */
72 int override
; /* -1 if no override */
75 target_ulong pc
; /* pc = eip + cs_base */
76 int is_jmp
; /* 1 = means jump (stop translation), 2 means CPU
77 static state change (stop translation) */
78 /* current block context */
79 target_ulong cs_base
; /* base of CS segment */
80 int pe
; /* protected mode */
81 int code32
; /* 32 bit code segment */
83 int lma
; /* long mode active */
84 int code64
; /* 64 bit code segment */
87 int ss32
; /* 32 bit stack segment */
88 int cc_op
; /* current CC operation */
89 int addseg
; /* non zero if either DS/ES/SS have a non zero base */
90 int f_st
; /* currently unused */
91 int vm86
; /* vm86 mode */
94 int tf
; /* TF cpu flag */
95 int singlestep_enabled
; /* "hardware" single step enabled */
96 int jmp_opt
; /* use direct block chaining for direct jumps */
97 int mem_index
; /* select memory access functions */
98 int flags
; /* all execution flags */
99 struct TranslationBlock
*tb
;
100 int popl_esp_hack
; /* for correct popl with esp base handling */
101 int rip_offset
; /* only used in x86_64, but left for simplicity */
105 static void gen_eob(DisasContext
*s
);
106 static void gen_jmp(DisasContext
*s
, target_ulong eip
);
107 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
);
109 /* i386 arith/logic operations */
129 OP_SHL1
, /* undocumented */
134 #define DEF(s, n, copy_size) INDEX_op_ ## s,
151 /* I386 int registers */
152 OR_EAX
, /* MUST be even numbered */
161 OR_TMP0
= 16, /* temporary operand register */
163 OR_A0
, /* temporary register used when doing address evaluation */
168 #define NB_OP_SIZES 4
170 #define DEF_REGS(prefix, suffix) \
171 prefix ## EAX ## suffix,\
172 prefix ## ECX ## suffix,\
173 prefix ## EDX ## suffix,\
174 prefix ## EBX ## suffix,\
175 prefix ## ESP ## suffix,\
176 prefix ## EBP ## suffix,\
177 prefix ## ESI ## suffix,\
178 prefix ## EDI ## suffix,\
179 prefix ## R8 ## suffix,\
180 prefix ## R9 ## suffix,\
181 prefix ## R10 ## suffix,\
182 prefix ## R11 ## suffix,\
183 prefix ## R12 ## suffix,\
184 prefix ## R13 ## suffix,\
185 prefix ## R14 ## suffix,\
186 prefix ## R15 ## suffix,
188 #define DEF_BREGS(prefixb, prefixh, suffix) \
190 static void prefixb ## ESP ## suffix ## _wrapper(void) \
193 prefixb ## ESP ## suffix (); \
195 prefixh ## EAX ## suffix (); \
198 static void prefixb ## EBP ## suffix ## _wrapper(void) \
201 prefixb ## EBP ## suffix (); \
203 prefixh ## ECX ## suffix (); \
206 static void prefixb ## ESI ## suffix ## _wrapper(void) \
209 prefixb ## ESI ## suffix (); \
211 prefixh ## EDX ## suffix (); \
214 static void prefixb ## EDI ## suffix ## _wrapper(void) \
217 prefixb ## EDI ## suffix (); \
219 prefixh ## EBX ## suffix (); \
222 DEF_BREGS(gen_op_movb_
, gen_op_movh_
, _T0
)
223 DEF_BREGS(gen_op_movb_
, gen_op_movh_
, _T1
)
224 DEF_BREGS(gen_op_movl_T0_
, gen_op_movh_T0_
, )
225 DEF_BREGS(gen_op_movl_T1_
, gen_op_movh_T1_
, )
227 #else /* !TARGET_X86_64 */
229 #define NB_OP_SIZES 3
231 #define DEF_REGS(prefix, suffix) \
232 prefix ## EAX ## suffix,\
233 prefix ## ECX ## suffix,\
234 prefix ## EDX ## suffix,\
235 prefix ## EBX ## suffix,\
236 prefix ## ESP ## suffix,\
237 prefix ## EBP ## suffix,\
238 prefix ## ESI ## suffix,\
239 prefix ## EDI ## suffix,
241 #endif /* !TARGET_X86_64 */
243 static GenOpFunc
*gen_op_mov_reg_T0
[NB_OP_SIZES
][CPU_NB_REGS
] = {
250 gen_op_movb_ESP_T0_wrapper
,
251 gen_op_movb_EBP_T0_wrapper
,
252 gen_op_movb_ESI_T0_wrapper
,
253 gen_op_movb_EDI_T0_wrapper
,
270 DEF_REGS(gen_op_movw_
, _T0
)
273 DEF_REGS(gen_op_movl_
, _T0
)
277 DEF_REGS(gen_op_movq_
, _T0
)
282 static GenOpFunc
*gen_op_mov_reg_T1
[NB_OP_SIZES
][CPU_NB_REGS
] = {
289 gen_op_movb_ESP_T1_wrapper
,
290 gen_op_movb_EBP_T1_wrapper
,
291 gen_op_movb_ESI_T1_wrapper
,
292 gen_op_movb_EDI_T1_wrapper
,
309 DEF_REGS(gen_op_movw_
, _T1
)
312 DEF_REGS(gen_op_movl_
, _T1
)
316 DEF_REGS(gen_op_movq_
, _T1
)
321 static GenOpFunc
*gen_op_mov_reg_A0
[NB_OP_SIZES
- 1][CPU_NB_REGS
] = {
323 DEF_REGS(gen_op_movw_
, _A0
)
326 DEF_REGS(gen_op_movl_
, _A0
)
330 DEF_REGS(gen_op_movq_
, _A0
)
335 static GenOpFunc
*gen_op_mov_TN_reg
[NB_OP_SIZES
][2][CPU_NB_REGS
] =
344 gen_op_movl_T0_ESP_wrapper
,
345 gen_op_movl_T0_EBP_wrapper
,
346 gen_op_movl_T0_ESI_wrapper
,
347 gen_op_movl_T0_EDI_wrapper
,
369 gen_op_movl_T1_ESP_wrapper
,
370 gen_op_movl_T1_EBP_wrapper
,
371 gen_op_movl_T1_ESI_wrapper
,
372 gen_op_movl_T1_EDI_wrapper
,
391 DEF_REGS(gen_op_movl_T0_
, )
394 DEF_REGS(gen_op_movl_T1_
, )
399 DEF_REGS(gen_op_movl_T0_
, )
402 DEF_REGS(gen_op_movl_T1_
, )
408 DEF_REGS(gen_op_movl_T0_
, )
411 DEF_REGS(gen_op_movl_T1_
, )
417 static GenOpFunc
*gen_op_movl_A0_reg
[CPU_NB_REGS
] = {
418 DEF_REGS(gen_op_movl_A0_
, )
421 static GenOpFunc
*gen_op_addl_A0_reg_sN
[4][CPU_NB_REGS
] = {
423 DEF_REGS(gen_op_addl_A0_
, )
426 DEF_REGS(gen_op_addl_A0_
, _s1
)
429 DEF_REGS(gen_op_addl_A0_
, _s2
)
432 DEF_REGS(gen_op_addl_A0_
, _s3
)
437 static GenOpFunc
*gen_op_movq_A0_reg
[CPU_NB_REGS
] = {
438 DEF_REGS(gen_op_movq_A0_
, )
441 static GenOpFunc
*gen_op_addq_A0_reg_sN
[4][CPU_NB_REGS
] = {
443 DEF_REGS(gen_op_addq_A0_
, )
446 DEF_REGS(gen_op_addq_A0_
, _s1
)
449 DEF_REGS(gen_op_addq_A0_
, _s2
)
452 DEF_REGS(gen_op_addq_A0_
, _s3
)
457 static GenOpFunc
*gen_op_cmov_reg_T1_T0
[NB_OP_SIZES
- 1][CPU_NB_REGS
] = {
459 DEF_REGS(gen_op_cmovw_
, _T1_T0
)
462 DEF_REGS(gen_op_cmovl_
, _T1_T0
)
466 DEF_REGS(gen_op_cmovq_
, _T1_T0
)
471 static GenOpFunc
*gen_op_arith_T0_T1_cc
[8] = {
482 #define DEF_ARITHC(SUFFIX)\
484 gen_op_adcb ## SUFFIX ## _T0_T1_cc,\
485 gen_op_sbbb ## SUFFIX ## _T0_T1_cc,\
488 gen_op_adcw ## SUFFIX ## _T0_T1_cc,\
489 gen_op_sbbw ## SUFFIX ## _T0_T1_cc,\
492 gen_op_adcl ## SUFFIX ## _T0_T1_cc,\
493 gen_op_sbbl ## SUFFIX ## _T0_T1_cc,\
496 X86_64_ONLY(gen_op_adcq ## SUFFIX ## _T0_T1_cc),\
497 X86_64_ONLY(gen_op_sbbq ## SUFFIX ## _T0_T1_cc),\
500 static GenOpFunc
*gen_op_arithc_T0_T1_cc
[4][2] = {
504 static GenOpFunc
*gen_op_arithc_mem_T0_T1_cc
[3 * 4][2] = {
506 #ifndef CONFIG_USER_ONLY
512 static const int cc_op_arithb
[8] = {
523 #define DEF_CMPXCHG(SUFFIX)\
524 gen_op_cmpxchgb ## SUFFIX ## _T0_T1_EAX_cc,\
525 gen_op_cmpxchgw ## SUFFIX ## _T0_T1_EAX_cc,\
526 gen_op_cmpxchgl ## SUFFIX ## _T0_T1_EAX_cc,\
527 X86_64_ONLY(gen_op_cmpxchgq ## SUFFIX ## _T0_T1_EAX_cc),
529 static GenOpFunc
*gen_op_cmpxchg_T0_T1_EAX_cc
[4] = {
533 static GenOpFunc
*gen_op_cmpxchg_mem_T0_T1_EAX_cc
[3 * 4] = {
535 #ifndef CONFIG_USER_ONLY
541 #define DEF_SHIFT(SUFFIX)\
543 gen_op_rolb ## SUFFIX ## _T0_T1_cc,\
544 gen_op_rorb ## SUFFIX ## _T0_T1_cc,\
545 gen_op_rclb ## SUFFIX ## _T0_T1_cc,\
546 gen_op_rcrb ## SUFFIX ## _T0_T1_cc,\
547 gen_op_shlb ## SUFFIX ## _T0_T1_cc,\
548 gen_op_shrb ## SUFFIX ## _T0_T1_cc,\
549 gen_op_shlb ## SUFFIX ## _T0_T1_cc,\
550 gen_op_sarb ## SUFFIX ## _T0_T1_cc,\
553 gen_op_rolw ## SUFFIX ## _T0_T1_cc,\
554 gen_op_rorw ## SUFFIX ## _T0_T1_cc,\
555 gen_op_rclw ## SUFFIX ## _T0_T1_cc,\
556 gen_op_rcrw ## SUFFIX ## _T0_T1_cc,\
557 gen_op_shlw ## SUFFIX ## _T0_T1_cc,\
558 gen_op_shrw ## SUFFIX ## _T0_T1_cc,\
559 gen_op_shlw ## SUFFIX ## _T0_T1_cc,\
560 gen_op_sarw ## SUFFIX ## _T0_T1_cc,\
563 gen_op_roll ## SUFFIX ## _T0_T1_cc,\
564 gen_op_rorl ## SUFFIX ## _T0_T1_cc,\
565 gen_op_rcll ## SUFFIX ## _T0_T1_cc,\
566 gen_op_rcrl ## SUFFIX ## _T0_T1_cc,\
567 gen_op_shll ## SUFFIX ## _T0_T1_cc,\
568 gen_op_shrl ## SUFFIX ## _T0_T1_cc,\
569 gen_op_shll ## SUFFIX ## _T0_T1_cc,\
570 gen_op_sarl ## SUFFIX ## _T0_T1_cc,\
573 X86_64_ONLY(gen_op_rolq ## SUFFIX ## _T0_T1_cc),\
574 X86_64_ONLY(gen_op_rorq ## SUFFIX ## _T0_T1_cc),\
575 X86_64_ONLY(gen_op_rclq ## SUFFIX ## _T0_T1_cc),\
576 X86_64_ONLY(gen_op_rcrq ## SUFFIX ## _T0_T1_cc),\
577 X86_64_ONLY(gen_op_shlq ## SUFFIX ## _T0_T1_cc),\
578 X86_64_ONLY(gen_op_shrq ## SUFFIX ## _T0_T1_cc),\
579 X86_64_ONLY(gen_op_shlq ## SUFFIX ## _T0_T1_cc),\
580 X86_64_ONLY(gen_op_sarq ## SUFFIX ## _T0_T1_cc),\
583 static GenOpFunc
*gen_op_shift_T0_T1_cc
[4][8] = {
587 static GenOpFunc
*gen_op_shift_mem_T0_T1_cc
[3 * 4][8] = {
589 #ifndef CONFIG_USER_ONLY
595 #define DEF_SHIFTD(SUFFIX, op)\
601 gen_op_shldw ## SUFFIX ## _T0_T1_ ## op ## _cc,\
602 gen_op_shrdw ## SUFFIX ## _T0_T1_ ## op ## _cc,\
605 gen_op_shldl ## SUFFIX ## _T0_T1_ ## op ## _cc,\
606 gen_op_shrdl ## SUFFIX ## _T0_T1_ ## op ## _cc,\
609 X86_64_DEF(gen_op_shldq ## SUFFIX ## _T0_T1_ ## op ## _cc,\
610 gen_op_shrdq ## SUFFIX ## _T0_T1_ ## op ## _cc,)\
613 static GenOpFunc1
*gen_op_shiftd_T0_T1_im_cc
[4][2] = {
617 static GenOpFunc
*gen_op_shiftd_T0_T1_ECX_cc
[4][2] = {
621 static GenOpFunc1
*gen_op_shiftd_mem_T0_T1_im_cc
[3 * 4][2] = {
623 #ifndef CONFIG_USER_ONLY
624 DEF_SHIFTD(_kernel
, im
)
625 DEF_SHIFTD(_user
, im
)
629 static GenOpFunc
*gen_op_shiftd_mem_T0_T1_ECX_cc
[3 * 4][2] = {
630 DEF_SHIFTD(_raw
, ECX
)
631 #ifndef CONFIG_USER_ONLY
632 DEF_SHIFTD(_kernel
, ECX
)
633 DEF_SHIFTD(_user
, ECX
)
637 static GenOpFunc
*gen_op_btx_T0_T1_cc
[3][4] = {
640 gen_op_btsw_T0_T1_cc
,
641 gen_op_btrw_T0_T1_cc
,
642 gen_op_btcw_T0_T1_cc
,
646 gen_op_btsl_T0_T1_cc
,
647 gen_op_btrl_T0_T1_cc
,
648 gen_op_btcl_T0_T1_cc
,
653 gen_op_btsq_T0_T1_cc
,
654 gen_op_btrq_T0_T1_cc
,
655 gen_op_btcq_T0_T1_cc
,
660 static GenOpFunc
*gen_op_add_bit_A0_T1
[3] = {
661 gen_op_add_bitw_A0_T1
,
662 gen_op_add_bitl_A0_T1
,
663 X86_64_ONLY(gen_op_add_bitq_A0_T1
),
666 static GenOpFunc
*gen_op_bsx_T0_cc
[3][2] = {
683 static GenOpFunc
*gen_op_lds_T0_A0
[3 * 4] = {
684 gen_op_ldsb_raw_T0_A0
,
685 gen_op_ldsw_raw_T0_A0
,
686 X86_64_ONLY(gen_op_ldsl_raw_T0_A0
),
688 #ifndef CONFIG_USER_ONLY
689 gen_op_ldsb_kernel_T0_A0
,
690 gen_op_ldsw_kernel_T0_A0
,
691 X86_64_ONLY(gen_op_ldsl_kernel_T0_A0
),
694 gen_op_ldsb_user_T0_A0
,
695 gen_op_ldsw_user_T0_A0
,
696 X86_64_ONLY(gen_op_ldsl_user_T0_A0
),
701 static GenOpFunc
*gen_op_ldu_T0_A0
[3 * 4] = {
702 gen_op_ldub_raw_T0_A0
,
703 gen_op_lduw_raw_T0_A0
,
707 #ifndef CONFIG_USER_ONLY
708 gen_op_ldub_kernel_T0_A0
,
709 gen_op_lduw_kernel_T0_A0
,
713 gen_op_ldub_user_T0_A0
,
714 gen_op_lduw_user_T0_A0
,
720 /* sign does not matter, except for lidt/lgdt call (TODO: fix it) */
721 static GenOpFunc
*gen_op_ld_T0_A0
[3 * 4] = {
722 gen_op_ldub_raw_T0_A0
,
723 gen_op_lduw_raw_T0_A0
,
724 gen_op_ldl_raw_T0_A0
,
725 X86_64_ONLY(gen_op_ldq_raw_T0_A0
),
727 #ifndef CONFIG_USER_ONLY
728 gen_op_ldub_kernel_T0_A0
,
729 gen_op_lduw_kernel_T0_A0
,
730 gen_op_ldl_kernel_T0_A0
,
731 X86_64_ONLY(gen_op_ldq_kernel_T0_A0
),
733 gen_op_ldub_user_T0_A0
,
734 gen_op_lduw_user_T0_A0
,
735 gen_op_ldl_user_T0_A0
,
736 X86_64_ONLY(gen_op_ldq_user_T0_A0
),
740 static GenOpFunc
*gen_op_ld_T1_A0
[3 * 4] = {
741 gen_op_ldub_raw_T1_A0
,
742 gen_op_lduw_raw_T1_A0
,
743 gen_op_ldl_raw_T1_A0
,
744 X86_64_ONLY(gen_op_ldq_raw_T1_A0
),
746 #ifndef CONFIG_USER_ONLY
747 gen_op_ldub_kernel_T1_A0
,
748 gen_op_lduw_kernel_T1_A0
,
749 gen_op_ldl_kernel_T1_A0
,
750 X86_64_ONLY(gen_op_ldq_kernel_T1_A0
),
752 gen_op_ldub_user_T1_A0
,
753 gen_op_lduw_user_T1_A0
,
754 gen_op_ldl_user_T1_A0
,
755 X86_64_ONLY(gen_op_ldq_user_T1_A0
),
759 static GenOpFunc
*gen_op_st_T0_A0
[3 * 4] = {
760 gen_op_stb_raw_T0_A0
,
761 gen_op_stw_raw_T0_A0
,
762 gen_op_stl_raw_T0_A0
,
763 X86_64_ONLY(gen_op_stq_raw_T0_A0
),
765 #ifndef CONFIG_USER_ONLY
766 gen_op_stb_kernel_T0_A0
,
767 gen_op_stw_kernel_T0_A0
,
768 gen_op_stl_kernel_T0_A0
,
769 X86_64_ONLY(gen_op_stq_kernel_T0_A0
),
771 gen_op_stb_user_T0_A0
,
772 gen_op_stw_user_T0_A0
,
773 gen_op_stl_user_T0_A0
,
774 X86_64_ONLY(gen_op_stq_user_T0_A0
),
778 static GenOpFunc
*gen_op_st_T1_A0
[3 * 4] = {
780 gen_op_stw_raw_T1_A0
,
781 gen_op_stl_raw_T1_A0
,
782 X86_64_ONLY(gen_op_stq_raw_T1_A0
),
784 #ifndef CONFIG_USER_ONLY
786 gen_op_stw_kernel_T1_A0
,
787 gen_op_stl_kernel_T1_A0
,
788 X86_64_ONLY(gen_op_stq_kernel_T1_A0
),
791 gen_op_stw_user_T1_A0
,
792 gen_op_stl_user_T1_A0
,
793 X86_64_ONLY(gen_op_stq_user_T1_A0
),
797 static inline void gen_jmp_im(target_ulong pc
)
800 if (pc
== (uint32_t)pc
) {
801 gen_op_movl_eip_im(pc
);
802 } else if (pc
== (int32_t)pc
) {
803 gen_op_movq_eip_im(pc
);
805 gen_op_movq_eip_im64(pc
>> 32, pc
);
808 gen_op_movl_eip_im(pc
);
812 static inline void gen_string_movl_A0_ESI(DisasContext
*s
)
816 override
= s
->override
;
820 gen_op_movq_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
821 gen_op_addq_A0_reg_sN
[0][R_ESI
]();
823 gen_op_movq_A0_reg
[R_ESI
]();
829 if (s
->addseg
&& override
< 0)
832 gen_op_movl_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
833 gen_op_addl_A0_reg_sN
[0][R_ESI
]();
835 gen_op_movl_A0_reg
[R_ESI
]();
838 /* 16 address, always override */
841 gen_op_movl_A0_reg
[R_ESI
]();
842 gen_op_andl_A0_ffff();
843 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
847 static inline void gen_string_movl_A0_EDI(DisasContext
*s
)
851 gen_op_movq_A0_reg
[R_EDI
]();
856 gen_op_movl_A0_seg(offsetof(CPUX86State
,segs
[R_ES
].base
));
857 gen_op_addl_A0_reg_sN
[0][R_EDI
]();
859 gen_op_movl_A0_reg
[R_EDI
]();
862 gen_op_movl_A0_reg
[R_EDI
]();
863 gen_op_andl_A0_ffff();
864 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[R_ES
].base
));
868 static GenOpFunc
*gen_op_movl_T0_Dshift
[4] = {
869 gen_op_movl_T0_Dshiftb
,
870 gen_op_movl_T0_Dshiftw
,
871 gen_op_movl_T0_Dshiftl
,
872 X86_64_ONLY(gen_op_movl_T0_Dshiftq
),
875 static GenOpFunc1
*gen_op_jnz_ecx
[3] = {
878 X86_64_ONLY(gen_op_jnz_ecxq
),
881 static GenOpFunc1
*gen_op_jz_ecx
[3] = {
884 X86_64_ONLY(gen_op_jz_ecxq
),
887 static GenOpFunc
*gen_op_dec_ECX
[3] = {
890 X86_64_ONLY(gen_op_decq_ECX
),
893 static GenOpFunc1
*gen_op_string_jnz_sub
[2][4] = {
898 X86_64_ONLY(gen_op_jnz_subq
),
904 X86_64_ONLY(gen_op_jz_subq
),
908 static GenOpFunc
*gen_op_in_DX_T0
[3] = {
914 static GenOpFunc
*gen_op_out_DX_T0
[3] = {
920 static GenOpFunc
*gen_op_in
[3] = {
926 static GenOpFunc
*gen_op_out
[3] = {
932 static GenOpFunc
*gen_check_io_T0
[3] = {
938 static GenOpFunc
*gen_check_io_DX
[3] = {
944 static void gen_check_io(DisasContext
*s
, int ot
, int use_dx
, target_ulong cur_eip
)
946 if (s
->pe
&& (s
->cpl
> s
->iopl
|| s
->vm86
)) {
947 if (s
->cc_op
!= CC_OP_DYNAMIC
)
948 gen_op_set_cc_op(s
->cc_op
);
951 gen_check_io_DX
[ot
]();
953 gen_check_io_T0
[ot
]();
957 static inline void gen_movs(DisasContext
*s
, int ot
)
959 gen_string_movl_A0_ESI(s
);
960 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
961 gen_string_movl_A0_EDI(s
);
962 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
963 gen_op_movl_T0_Dshift
[ot
]();
966 gen_op_addq_ESI_T0();
967 gen_op_addq_EDI_T0();
971 gen_op_addl_ESI_T0();
972 gen_op_addl_EDI_T0();
974 gen_op_addw_ESI_T0();
975 gen_op_addw_EDI_T0();
979 static inline void gen_update_cc_op(DisasContext
*s
)
981 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
982 gen_op_set_cc_op(s
->cc_op
);
983 s
->cc_op
= CC_OP_DYNAMIC
;
987 /* XXX: does not work with gdbstub "ice" single step - not a
989 static int gen_jz_ecx_string(DisasContext
*s
, target_ulong next_eip
)
993 l1
= gen_new_label();
994 l2
= gen_new_label();
995 gen_op_jnz_ecx
[s
->aflag
](l1
);
997 gen_jmp_tb(s
, next_eip
, 1);
1002 static inline void gen_stos(DisasContext
*s
, int ot
)
1004 gen_op_mov_TN_reg
[OT_LONG
][0][R_EAX
]();
1005 gen_string_movl_A0_EDI(s
);
1006 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
1007 gen_op_movl_T0_Dshift
[ot
]();
1008 #ifdef TARGET_X86_64
1009 if (s
->aflag
== 2) {
1010 gen_op_addq_EDI_T0();
1014 gen_op_addl_EDI_T0();
1016 gen_op_addw_EDI_T0();
1020 static inline void gen_lods(DisasContext
*s
, int ot
)
1022 gen_string_movl_A0_ESI(s
);
1023 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
1024 gen_op_mov_reg_T0
[ot
][R_EAX
]();
1025 gen_op_movl_T0_Dshift
[ot
]();
1026 #ifdef TARGET_X86_64
1027 if (s
->aflag
== 2) {
1028 gen_op_addq_ESI_T0();
1032 gen_op_addl_ESI_T0();
1034 gen_op_addw_ESI_T0();
1038 static inline void gen_scas(DisasContext
*s
, int ot
)
1040 gen_op_mov_TN_reg
[OT_LONG
][0][R_EAX
]();
1041 gen_string_movl_A0_EDI(s
);
1042 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
1043 gen_op_cmpl_T0_T1_cc();
1044 gen_op_movl_T0_Dshift
[ot
]();
1045 #ifdef TARGET_X86_64
1046 if (s
->aflag
== 2) {
1047 gen_op_addq_EDI_T0();
1051 gen_op_addl_EDI_T0();
1053 gen_op_addw_EDI_T0();
1057 static inline void gen_cmps(DisasContext
*s
, int ot
)
1059 gen_string_movl_A0_ESI(s
);
1060 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
1061 gen_string_movl_A0_EDI(s
);
1062 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
1063 gen_op_cmpl_T0_T1_cc();
1064 gen_op_movl_T0_Dshift
[ot
]();
1065 #ifdef TARGET_X86_64
1066 if (s
->aflag
== 2) {
1067 gen_op_addq_ESI_T0();
1068 gen_op_addq_EDI_T0();
1072 gen_op_addl_ESI_T0();
1073 gen_op_addl_EDI_T0();
1075 gen_op_addw_ESI_T0();
1076 gen_op_addw_EDI_T0();
1080 static inline void gen_ins(DisasContext
*s
, int ot
)
1082 gen_string_movl_A0_EDI(s
);
1084 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
1085 gen_op_in_DX_T0
[ot
]();
1086 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
1087 gen_op_movl_T0_Dshift
[ot
]();
1088 #ifdef TARGET_X86_64
1089 if (s
->aflag
== 2) {
1090 gen_op_addq_EDI_T0();
1094 gen_op_addl_EDI_T0();
1096 gen_op_addw_EDI_T0();
1100 static inline void gen_outs(DisasContext
*s
, int ot
)
1102 gen_string_movl_A0_ESI(s
);
1103 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
1104 gen_op_out_DX_T0
[ot
]();
1105 gen_op_movl_T0_Dshift
[ot
]();
1106 #ifdef TARGET_X86_64
1107 if (s
->aflag
== 2) {
1108 gen_op_addq_ESI_T0();
1112 gen_op_addl_ESI_T0();
1114 gen_op_addw_ESI_T0();
1118 /* same method as Valgrind : we generate jumps to current or next
1120 #define GEN_REPZ(op) \
1121 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1122 target_ulong cur_eip, target_ulong next_eip) \
1125 gen_update_cc_op(s); \
1126 l2 = gen_jz_ecx_string(s, next_eip); \
1127 gen_ ## op(s, ot); \
1128 gen_op_dec_ECX[s->aflag](); \
1129 /* a loop would cause two single step exceptions if ECX = 1 \
1130 before rep string_insn */ \
1132 gen_op_jz_ecx[s->aflag](l2); \
1133 gen_jmp(s, cur_eip); \
1136 #define GEN_REPZ2(op) \
1137 static inline void gen_repz_ ## op(DisasContext *s, int ot, \
1138 target_ulong cur_eip, \
1139 target_ulong next_eip, \
1143 gen_update_cc_op(s); \
1144 l2 = gen_jz_ecx_string(s, next_eip); \
1145 gen_ ## op(s, ot); \
1146 gen_op_dec_ECX[s->aflag](); \
1147 gen_op_set_cc_op(CC_OP_SUBB + ot); \
1148 gen_op_string_jnz_sub[nz][ot](l2);\
1150 gen_op_jz_ecx[s->aflag](l2); \
1151 gen_jmp(s, cur_eip); \
1173 static GenOpFunc1
*gen_jcc_sub
[4][8] = {
1204 #ifdef TARGET_X86_64
1207 BUGGY_64(gen_op_jb_subq
),
1209 BUGGY_64(gen_op_jbe_subq
),
1212 BUGGY_64(gen_op_jl_subq
),
1213 BUGGY_64(gen_op_jle_subq
),
1217 static GenOpFunc1
*gen_op_loop
[3][4] = {
1228 #ifdef TARGET_X86_64
1237 static GenOpFunc
*gen_setcc_slow
[8] = {
1248 static GenOpFunc
*gen_setcc_sub
[4][8] = {
1251 gen_op_setb_T0_subb
,
1252 gen_op_setz_T0_subb
,
1253 gen_op_setbe_T0_subb
,
1254 gen_op_sets_T0_subb
,
1256 gen_op_setl_T0_subb
,
1257 gen_op_setle_T0_subb
,
1261 gen_op_setb_T0_subw
,
1262 gen_op_setz_T0_subw
,
1263 gen_op_setbe_T0_subw
,
1264 gen_op_sets_T0_subw
,
1266 gen_op_setl_T0_subw
,
1267 gen_op_setle_T0_subw
,
1271 gen_op_setb_T0_subl
,
1272 gen_op_setz_T0_subl
,
1273 gen_op_setbe_T0_subl
,
1274 gen_op_sets_T0_subl
,
1276 gen_op_setl_T0_subl
,
1277 gen_op_setle_T0_subl
,
1279 #ifdef TARGET_X86_64
1282 gen_op_setb_T0_subq
,
1283 gen_op_setz_T0_subq
,
1284 gen_op_setbe_T0_subq
,
1285 gen_op_sets_T0_subq
,
1287 gen_op_setl_T0_subq
,
1288 gen_op_setle_T0_subq
,
1293 static GenOpFunc
*gen_op_fp_arith_ST0_FT0
[8] = {
1294 gen_op_fadd_ST0_FT0
,
1295 gen_op_fmul_ST0_FT0
,
1296 gen_op_fcom_ST0_FT0
,
1297 gen_op_fcom_ST0_FT0
,
1298 gen_op_fsub_ST0_FT0
,
1299 gen_op_fsubr_ST0_FT0
,
1300 gen_op_fdiv_ST0_FT0
,
1301 gen_op_fdivr_ST0_FT0
,
1304 /* NOTE the exception in "r" op ordering */
1305 static GenOpFunc1
*gen_op_fp_arith_STN_ST0
[8] = {
1306 gen_op_fadd_STN_ST0
,
1307 gen_op_fmul_STN_ST0
,
1310 gen_op_fsubr_STN_ST0
,
1311 gen_op_fsub_STN_ST0
,
1312 gen_op_fdivr_STN_ST0
,
1313 gen_op_fdiv_STN_ST0
,
1316 /* if d == OR_TMP0, it means memory operand (address in A0) */
1317 static void gen_op(DisasContext
*s1
, int op
, int ot
, int d
)
1319 GenOpFunc
*gen_update_cc
;
1322 gen_op_mov_TN_reg
[ot
][0][d
]();
1324 gen_op_ld_T0_A0
[ot
+ s1
->mem_index
]();
1329 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1330 gen_op_set_cc_op(s1
->cc_op
);
1332 gen_op_arithc_T0_T1_cc
[ot
][op
- OP_ADCL
]();
1333 gen_op_mov_reg_T0
[ot
][d
]();
1335 gen_op_arithc_mem_T0_T1_cc
[ot
+ s1
->mem_index
][op
- OP_ADCL
]();
1337 s1
->cc_op
= CC_OP_DYNAMIC
;
1340 gen_op_addl_T0_T1();
1341 s1
->cc_op
= CC_OP_ADDB
+ ot
;
1342 gen_update_cc
= gen_op_update2_cc
;
1345 gen_op_subl_T0_T1();
1346 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1347 gen_update_cc
= gen_op_update2_cc
;
1353 gen_op_arith_T0_T1_cc
[op
]();
1354 s1
->cc_op
= CC_OP_LOGICB
+ ot
;
1355 gen_update_cc
= gen_op_update1_cc
;
1358 gen_op_cmpl_T0_T1_cc();
1359 s1
->cc_op
= CC_OP_SUBB
+ ot
;
1360 gen_update_cc
= NULL
;
1363 if (op
!= OP_CMPL
) {
1365 gen_op_mov_reg_T0
[ot
][d
]();
1367 gen_op_st_T0_A0
[ot
+ s1
->mem_index
]();
1369 /* the flags update must happen after the memory write (precise
1370 exception support) */
1376 /* if d == OR_TMP0, it means memory operand (address in A0) */
1377 static void gen_inc(DisasContext
*s1
, int ot
, int d
, int c
)
1380 gen_op_mov_TN_reg
[ot
][0][d
]();
1382 gen_op_ld_T0_A0
[ot
+ s1
->mem_index
]();
1383 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1384 gen_op_set_cc_op(s1
->cc_op
);
1387 s1
->cc_op
= CC_OP_INCB
+ ot
;
1390 s1
->cc_op
= CC_OP_DECB
+ ot
;
1393 gen_op_mov_reg_T0
[ot
][d
]();
1395 gen_op_st_T0_A0
[ot
+ s1
->mem_index
]();
1396 gen_op_update_inc_cc();
1399 static void gen_shift(DisasContext
*s1
, int op
, int ot
, int d
, int s
)
1402 gen_op_mov_TN_reg
[ot
][0][d
]();
1404 gen_op_ld_T0_A0
[ot
+ s1
->mem_index
]();
1406 gen_op_mov_TN_reg
[ot
][1][s
]();
1407 /* for zero counts, flags are not updated, so must do it dynamically */
1408 if (s1
->cc_op
!= CC_OP_DYNAMIC
)
1409 gen_op_set_cc_op(s1
->cc_op
);
1412 gen_op_shift_T0_T1_cc
[ot
][op
]();
1414 gen_op_shift_mem_T0_T1_cc
[ot
+ s1
->mem_index
][op
]();
1416 gen_op_mov_reg_T0
[ot
][d
]();
1417 s1
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
1420 static void gen_shifti(DisasContext
*s1
, int op
, int ot
, int d
, int c
)
1422 /* currently not optimized */
1423 gen_op_movl_T1_im(c
);
1424 gen_shift(s1
, op
, ot
, d
, OR_TMP1
);
1427 static void gen_lea_modrm(DisasContext
*s
, int modrm
, int *reg_ptr
, int *offset_ptr
)
1435 int mod
, rm
, code
, override
, must_add_seg
;
1437 override
= s
->override
;
1438 must_add_seg
= s
->addseg
;
1441 mod
= (modrm
>> 6) & 3;
1453 code
= ldub_code(s
->pc
++);
1454 scale
= (code
>> 6) & 3;
1455 index
= ((code
>> 3) & 7) | REX_X(s
);
1462 if ((base
& 7) == 5) {
1464 disp
= (int32_t)ldl_code(s
->pc
);
1466 if (CODE64(s
) && !havesib
) {
1467 disp
+= s
->pc
+ s
->rip_offset
;
1474 disp
= (int8_t)ldub_code(s
->pc
++);
1478 disp
= ldl_code(s
->pc
);
1484 /* for correct popl handling with esp */
1485 if (base
== 4 && s
->popl_esp_hack
)
1486 disp
+= s
->popl_esp_hack
;
1487 #ifdef TARGET_X86_64
1488 if (s
->aflag
== 2) {
1489 gen_op_movq_A0_reg
[base
]();
1491 if ((int32_t)disp
== disp
)
1492 gen_op_addq_A0_im(disp
);
1494 gen_op_addq_A0_im64(disp
>> 32, disp
);
1499 gen_op_movl_A0_reg
[base
]();
1501 gen_op_addl_A0_im(disp
);
1504 #ifdef TARGET_X86_64
1505 if (s
->aflag
== 2) {
1506 if ((int32_t)disp
== disp
)
1507 gen_op_movq_A0_im(disp
);
1509 gen_op_movq_A0_im64(disp
>> 32, disp
);
1513 gen_op_movl_A0_im(disp
);
1516 /* XXX: index == 4 is always invalid */
1517 if (havesib
&& (index
!= 4 || scale
!= 0)) {
1518 #ifdef TARGET_X86_64
1519 if (s
->aflag
== 2) {
1520 gen_op_addq_A0_reg_sN
[scale
][index
]();
1524 gen_op_addl_A0_reg_sN
[scale
][index
]();
1529 if (base
== R_EBP
|| base
== R_ESP
)
1534 #ifdef TARGET_X86_64
1535 if (s
->aflag
== 2) {
1536 gen_op_addq_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
1540 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
1547 disp
= lduw_code(s
->pc
);
1549 gen_op_movl_A0_im(disp
);
1550 rm
= 0; /* avoid SS override */
1557 disp
= (int8_t)ldub_code(s
->pc
++);
1561 disp
= lduw_code(s
->pc
);
1567 gen_op_movl_A0_reg
[R_EBX
]();
1568 gen_op_addl_A0_reg_sN
[0][R_ESI
]();
1571 gen_op_movl_A0_reg
[R_EBX
]();
1572 gen_op_addl_A0_reg_sN
[0][R_EDI
]();
1575 gen_op_movl_A0_reg
[R_EBP
]();
1576 gen_op_addl_A0_reg_sN
[0][R_ESI
]();
1579 gen_op_movl_A0_reg
[R_EBP
]();
1580 gen_op_addl_A0_reg_sN
[0][R_EDI
]();
1583 gen_op_movl_A0_reg
[R_ESI
]();
1586 gen_op_movl_A0_reg
[R_EDI
]();
1589 gen_op_movl_A0_reg
[R_EBP
]();
1593 gen_op_movl_A0_reg
[R_EBX
]();
1597 gen_op_addl_A0_im(disp
);
1598 gen_op_andl_A0_ffff();
1602 if (rm
== 2 || rm
== 3 || rm
== 6)
1607 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
1617 /* used for LEA and MOV AX, mem */
1618 static void gen_add_A0_ds_seg(DisasContext
*s
)
1620 int override
, must_add_seg
;
1621 must_add_seg
= s
->addseg
;
1623 if (s
->override
>= 0) {
1624 override
= s
->override
;
1630 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[override
].base
));
1634 /* generate modrm memory load or store of 'reg'. TMP0 is used if reg !=
1636 static void gen_ldst_modrm(DisasContext
*s
, int modrm
, int ot
, int reg
, int is_store
)
1638 int mod
, rm
, opreg
, disp
;
1640 mod
= (modrm
>> 6) & 3;
1641 rm
= (modrm
& 7) | REX_B(s
);
1645 gen_op_mov_TN_reg
[ot
][0][reg
]();
1646 gen_op_mov_reg_T0
[ot
][rm
]();
1648 gen_op_mov_TN_reg
[ot
][0][rm
]();
1650 gen_op_mov_reg_T0
[ot
][reg
]();
1653 gen_lea_modrm(s
, modrm
, &opreg
, &disp
);
1656 gen_op_mov_TN_reg
[ot
][0][reg
]();
1657 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
1659 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
1661 gen_op_mov_reg_T0
[ot
][reg
]();
1666 static inline uint32_t insn_get(DisasContext
*s
, int ot
)
1672 ret
= ldub_code(s
->pc
);
1676 ret
= lduw_code(s
->pc
);
1681 ret
= ldl_code(s
->pc
);
1688 static inline int insn_const_size(unsigned int ot
)
1696 static inline void gen_jcc(DisasContext
*s
, int b
,
1697 target_ulong val
, target_ulong next_eip
)
1699 TranslationBlock
*tb
;
1706 jcc_op
= (b
>> 1) & 7;
1710 /* we optimize the cmp/jcc case */
1715 func
= gen_jcc_sub
[s
->cc_op
- CC_OP_SUBB
][jcc_op
];
1718 /* some jumps are easy to compute */
1760 func
= gen_jcc_sub
[(s
->cc_op
- CC_OP_ADDB
) % 4][jcc_op
];
1763 func
= gen_jcc_sub
[(s
->cc_op
- CC_OP_ADDB
) % 4][jcc_op
];
1775 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1776 gen_op_set_cc_op(s
->cc_op
);
1779 gen_setcc_slow
[jcc_op
]();
1780 func
= gen_op_jnz_T0_label
;
1790 l1
= gen_new_label();
1793 gen_op_goto_tb0(TBPARAM(tb
));
1794 gen_jmp_im(next_eip
);
1795 gen_op_movl_T0_im((long)tb
+ 0);
1799 gen_op_goto_tb1(TBPARAM(tb
));
1801 gen_op_movl_T0_im((long)tb
+ 1);
1807 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
1808 gen_op_set_cc_op(s
->cc_op
);
1809 s
->cc_op
= CC_OP_DYNAMIC
;
1811 gen_setcc_slow
[jcc_op
]();
1817 l1
= gen_new_label();
1818 l2
= gen_new_label();
1819 gen_op_jnz_T0_label(l1
);
1820 gen_jmp_im(next_eip
);
1821 gen_op_jmp_label(l2
);
1829 static void gen_setcc(DisasContext
*s
, int b
)
1835 jcc_op
= (b
>> 1) & 7;
1837 /* we optimize the cmp/jcc case */
1842 func
= gen_setcc_sub
[s
->cc_op
- CC_OP_SUBB
][jcc_op
];
1847 /* some jumps are easy to compute */
1874 func
= gen_setcc_sub
[(s
->cc_op
- CC_OP_ADDB
) % 4][jcc_op
];
1877 func
= gen_setcc_sub
[(s
->cc_op
- CC_OP_ADDB
) % 4][jcc_op
];
1885 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1886 gen_op_set_cc_op(s
->cc_op
);
1887 func
= gen_setcc_slow
[jcc_op
];
1896 /* move T0 to seg_reg and compute if the CPU state may change. Never
1897 call this function with seg_reg == R_CS */
1898 static void gen_movl_seg_T0(DisasContext
*s
, int seg_reg
, target_ulong cur_eip
)
1900 if (s
->pe
&& !s
->vm86
) {
1901 /* XXX: optimize by finding processor state dynamically */
1902 if (s
->cc_op
!= CC_OP_DYNAMIC
)
1903 gen_op_set_cc_op(s
->cc_op
);
1904 gen_jmp_im(cur_eip
);
1905 gen_op_movl_seg_T0(seg_reg
);
1906 /* abort translation because the addseg value may change or
1907 because ss32 may change. For R_SS, translation must always
1908 stop as a special handling must be done to disable hardware
1909 interrupts for the next instruction */
1910 if (seg_reg
== R_SS
|| (s
->code32
&& seg_reg
< R_FS
))
1913 gen_op_movl_seg_T0_vm(offsetof(CPUX86State
,segs
[seg_reg
]));
1914 if (seg_reg
== R_SS
)
1919 static inline void gen_stack_update(DisasContext
*s
, int addend
)
1921 #ifdef TARGET_X86_64
1924 gen_op_addq_ESP_8();
1926 gen_op_addq_ESP_im(addend
);
1931 gen_op_addl_ESP_2();
1932 else if (addend
== 4)
1933 gen_op_addl_ESP_4();
1935 gen_op_addl_ESP_im(addend
);
1938 gen_op_addw_ESP_2();
1939 else if (addend
== 4)
1940 gen_op_addw_ESP_4();
1942 gen_op_addw_ESP_im(addend
);
1946 /* generate a push. It depends on ss32, addseg and dflag */
1947 static void gen_push_T0(DisasContext
*s
)
1949 #ifdef TARGET_X86_64
1951 /* XXX: check 16 bit behaviour */
1952 gen_op_movq_A0_reg
[R_ESP
]();
1954 gen_op_st_T0_A0
[OT_QUAD
+ s
->mem_index
]();
1955 gen_op_movq_ESP_A0();
1959 gen_op_movl_A0_reg
[R_ESP
]();
1966 gen_op_movl_T1_A0();
1967 gen_op_addl_A0_SS();
1970 gen_op_andl_A0_ffff();
1971 gen_op_movl_T1_A0();
1972 gen_op_addl_A0_SS();
1974 gen_op_st_T0_A0
[s
->dflag
+ 1 + s
->mem_index
]();
1975 if (s
->ss32
&& !s
->addseg
)
1976 gen_op_movl_ESP_A0();
1978 gen_op_mov_reg_T1
[s
->ss32
+ 1][R_ESP
]();
1982 /* generate a push. It depends on ss32, addseg and dflag */
1983 /* slower version for T1, only used for call Ev */
1984 static void gen_push_T1(DisasContext
*s
)
1986 #ifdef TARGET_X86_64
1988 /* XXX: check 16 bit behaviour */
1989 gen_op_movq_A0_reg
[R_ESP
]();
1991 gen_op_st_T1_A0
[OT_QUAD
+ s
->mem_index
]();
1992 gen_op_movq_ESP_A0();
1996 gen_op_movl_A0_reg
[R_ESP
]();
2003 gen_op_addl_A0_SS();
2006 gen_op_andl_A0_ffff();
2007 gen_op_addl_A0_SS();
2009 gen_op_st_T1_A0
[s
->dflag
+ 1 + s
->mem_index
]();
2011 if (s
->ss32
&& !s
->addseg
)
2012 gen_op_movl_ESP_A0();
2014 gen_stack_update(s
, (-2) << s
->dflag
);
2018 /* two step pop is necessary for precise exceptions */
2019 static void gen_pop_T0(DisasContext
*s
)
2021 #ifdef TARGET_X86_64
2023 /* XXX: check 16 bit behaviour */
2024 gen_op_movq_A0_reg
[R_ESP
]();
2025 gen_op_ld_T0_A0
[OT_QUAD
+ s
->mem_index
]();
2029 gen_op_movl_A0_reg
[R_ESP
]();
2032 gen_op_addl_A0_SS();
2034 gen_op_andl_A0_ffff();
2035 gen_op_addl_A0_SS();
2037 gen_op_ld_T0_A0
[s
->dflag
+ 1 + s
->mem_index
]();
2041 static void gen_pop_update(DisasContext
*s
)
2043 #ifdef TARGET_X86_64
2045 gen_stack_update(s
, 8);
2049 gen_stack_update(s
, 2 << s
->dflag
);
2053 static void gen_stack_A0(DisasContext
*s
)
2055 gen_op_movl_A0_ESP();
2057 gen_op_andl_A0_ffff();
2058 gen_op_movl_T1_A0();
2060 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[R_SS
].base
));
2063 /* NOTE: wrap around in 16 bit not fully handled */
2064 static void gen_pusha(DisasContext
*s
)
2067 gen_op_movl_A0_ESP();
2068 gen_op_addl_A0_im(-16 << s
->dflag
);
2070 gen_op_andl_A0_ffff();
2071 gen_op_movl_T1_A0();
2073 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[R_SS
].base
));
2074 for(i
= 0;i
< 8; i
++) {
2075 gen_op_mov_TN_reg
[OT_LONG
][0][7 - i
]();
2076 gen_op_st_T0_A0
[OT_WORD
+ s
->dflag
+ s
->mem_index
]();
2077 gen_op_addl_A0_im(2 << s
->dflag
);
2079 gen_op_mov_reg_T1
[OT_WORD
+ s
->ss32
][R_ESP
]();
2082 /* NOTE: wrap around in 16 bit not fully handled */
2083 static void gen_popa(DisasContext
*s
)
2086 gen_op_movl_A0_ESP();
2088 gen_op_andl_A0_ffff();
2089 gen_op_movl_T1_A0();
2090 gen_op_addl_T1_im(16 << s
->dflag
);
2092 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[R_SS
].base
));
2093 for(i
= 0;i
< 8; i
++) {
2094 /* ESP is not reloaded */
2096 gen_op_ld_T0_A0
[OT_WORD
+ s
->dflag
+ s
->mem_index
]();
2097 gen_op_mov_reg_T0
[OT_WORD
+ s
->dflag
][7 - i
]();
2099 gen_op_addl_A0_im(2 << s
->dflag
);
2101 gen_op_mov_reg_T1
[OT_WORD
+ s
->ss32
][R_ESP
]();
2104 static void gen_enter(DisasContext
*s
, int esp_addend
, int level
)
2108 ot
= s
->dflag
+ OT_WORD
;
2110 opsize
= 2 << s
->dflag
;
2112 gen_op_movl_A0_ESP();
2113 gen_op_addl_A0_im(-opsize
);
2115 gen_op_andl_A0_ffff();
2116 gen_op_movl_T1_A0();
2118 gen_op_addl_A0_seg(offsetof(CPUX86State
,segs
[R_SS
].base
));
2120 gen_op_mov_TN_reg
[OT_LONG
][0][R_EBP
]();
2121 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
2123 gen_op_enter_level(level
, s
->dflag
);
2125 gen_op_mov_reg_T1
[ot
][R_EBP
]();
2126 gen_op_addl_T1_im( -esp_addend
+ (-opsize
* level
) );
2127 gen_op_mov_reg_T1
[OT_WORD
+ s
->ss32
][R_ESP
]();
2130 static void gen_exception(DisasContext
*s
, int trapno
, target_ulong cur_eip
)
2132 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2133 gen_op_set_cc_op(s
->cc_op
);
2134 gen_jmp_im(cur_eip
);
2135 gen_op_raise_exception(trapno
);
2139 /* an interrupt is different from an exception because of the
2140 priviledge checks */
2141 static void gen_interrupt(DisasContext
*s
, int intno
,
2142 target_ulong cur_eip
, target_ulong next_eip
)
2144 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2145 gen_op_set_cc_op(s
->cc_op
);
2146 gen_jmp_im(cur_eip
);
2147 gen_op_raise_interrupt(intno
, (int)(next_eip
- cur_eip
));
2151 static void gen_debug(DisasContext
*s
, target_ulong cur_eip
)
2153 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2154 gen_op_set_cc_op(s
->cc_op
);
2155 gen_jmp_im(cur_eip
);
2160 /* generate a generic end of block. Trace exception is also generated
2162 static void gen_eob(DisasContext
*s
)
2164 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2165 gen_op_set_cc_op(s
->cc_op
);
2166 if (s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
) {
2167 gen_op_reset_inhibit_irq();
2169 if (s
->singlestep_enabled
) {
2172 gen_op_raise_exception(EXCP01_SSTP
);
2180 /* generate a jump to eip. No segment change must happen before as a
2181 direct call to the next block may occur */
2182 static void gen_jmp_tb(DisasContext
*s
, target_ulong eip
, int tb_num
)
2184 TranslationBlock
*tb
= s
->tb
;
2187 if (s
->cc_op
!= CC_OP_DYNAMIC
)
2188 gen_op_set_cc_op(s
->cc_op
);
2190 gen_op_goto_tb1(TBPARAM(tb
));
2192 gen_op_goto_tb0(TBPARAM(tb
));
2194 gen_op_movl_T0_im((long)tb
+ tb_num
);
2203 static void gen_jmp(DisasContext
*s
, target_ulong eip
)
2205 gen_jmp_tb(s
, eip
, 0);
2208 static void gen_movtl_T0_im(target_ulong val
)
2210 #ifdef TARGET_X86_64
2211 if ((int32_t)val
== val
) {
2212 gen_op_movl_T0_im(val
);
2214 gen_op_movq_T0_im64(val
>> 32, val
);
2217 gen_op_movl_T0_im(val
);
2221 static void gen_movtl_T1_im(target_ulong val
)
2223 #ifdef TARGET_X86_64
2224 if ((int32_t)val
== val
) {
2225 gen_op_movl_T1_im(val
);
2227 gen_op_movq_T1_im64(val
>> 32, val
);
2230 gen_op_movl_T1_im(val
);
2234 static GenOpFunc1
*gen_ldq_env_A0
[3] = {
2235 gen_op_ldq_raw_env_A0
,
2236 #ifndef CONFIG_USER_ONLY
2237 gen_op_ldq_kernel_env_A0
,
2238 gen_op_ldq_user_env_A0
,
2242 static GenOpFunc1
*gen_stq_env_A0
[3] = {
2243 gen_op_stq_raw_env_A0
,
2244 #ifndef CONFIG_USER_ONLY
2245 gen_op_stq_kernel_env_A0
,
2246 gen_op_stq_user_env_A0
,
2250 static GenOpFunc1
*gen_ldo_env_A0
[3] = {
2251 gen_op_ldo_raw_env_A0
,
2252 #ifndef CONFIG_USER_ONLY
2253 gen_op_ldo_kernel_env_A0
,
2254 gen_op_ldo_user_env_A0
,
2258 static GenOpFunc1
*gen_sto_env_A0
[3] = {
2259 gen_op_sto_raw_env_A0
,
2260 #ifndef CONFIG_USER_ONLY
2261 gen_op_sto_kernel_env_A0
,
2262 gen_op_sto_user_env_A0
,
2266 #define SSE_SPECIAL ((GenOpFunc2 *)1)
2268 #define MMX_OP2(x) { gen_op_ ## x ## _mmx, gen_op_ ## x ## _xmm }
2269 #define SSE_FOP(x) { gen_op_ ## x ## ps, gen_op_ ## x ## pd, \
2270 gen_op_ ## x ## ss, gen_op_ ## x ## sd, }
2272 static GenOpFunc2
*sse_op_table1
[256][4] = {
2273 /* pure SSE operations */
2274 [0x10] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2275 [0x11] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movups, movupd, movss, movsd */
2276 [0x12] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2277 [0x13] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movlps, movlpd */
2278 [0x14] = { gen_op_punpckldq_xmm
, gen_op_punpcklqdq_xmm
},
2279 [0x15] = { gen_op_punpckhdq_xmm
, gen_op_punpckhqdq_xmm
},
2280 [0x16] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd, movshdup */
2281 [0x17] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movhps, movhpd */
2283 [0x28] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2284 [0x29] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movaps, movapd */
2285 [0x2a] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
2286 [0x2b] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntps, movntpd */
2287 [0x2c] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
2288 [0x2d] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
2289 [0x2e] = { gen_op_ucomiss
, gen_op_ucomisd
},
2290 [0x2f] = { gen_op_comiss
, gen_op_comisd
},
2291 [0x50] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movmskps, movmskpd */
2292 [0x51] = SSE_FOP(sqrt
),
2293 [0x52] = { gen_op_rsqrtps
, NULL
, gen_op_rsqrtss
, NULL
},
2294 [0x53] = { gen_op_rcpps
, NULL
, gen_op_rcpss
, NULL
},
2295 [0x54] = { gen_op_pand_xmm
, gen_op_pand_xmm
}, /* andps, andpd */
2296 [0x55] = { gen_op_pandn_xmm
, gen_op_pandn_xmm
}, /* andnps, andnpd */
2297 [0x56] = { gen_op_por_xmm
, gen_op_por_xmm
}, /* orps, orpd */
2298 [0x57] = { gen_op_pxor_xmm
, gen_op_pxor_xmm
}, /* xorps, xorpd */
2299 [0x58] = SSE_FOP(add
),
2300 [0x59] = SSE_FOP(mul
),
2301 [0x5a] = { gen_op_cvtps2pd
, gen_op_cvtpd2ps
,
2302 gen_op_cvtss2sd
, gen_op_cvtsd2ss
},
2303 [0x5b] = { gen_op_cvtdq2ps
, gen_op_cvtps2dq
, gen_op_cvttps2dq
},
2304 [0x5c] = SSE_FOP(sub
),
2305 [0x5d] = SSE_FOP(min
),
2306 [0x5e] = SSE_FOP(div
),
2307 [0x5f] = SSE_FOP(max
),
2309 [0xc2] = SSE_FOP(cmpeq
),
2310 [0xc6] = { (GenOpFunc2
*)gen_op_shufps
, (GenOpFunc2
*)gen_op_shufpd
},
2312 /* MMX ops and their SSE extensions */
2313 [0x60] = MMX_OP2(punpcklbw
),
2314 [0x61] = MMX_OP2(punpcklwd
),
2315 [0x62] = MMX_OP2(punpckldq
),
2316 [0x63] = MMX_OP2(packsswb
),
2317 [0x64] = MMX_OP2(pcmpgtb
),
2318 [0x65] = MMX_OP2(pcmpgtw
),
2319 [0x66] = MMX_OP2(pcmpgtl
),
2320 [0x67] = MMX_OP2(packuswb
),
2321 [0x68] = MMX_OP2(punpckhbw
),
2322 [0x69] = MMX_OP2(punpckhwd
),
2323 [0x6a] = MMX_OP2(punpckhdq
),
2324 [0x6b] = MMX_OP2(packssdw
),
2325 [0x6c] = { NULL
, gen_op_punpcklqdq_xmm
},
2326 [0x6d] = { NULL
, gen_op_punpckhqdq_xmm
},
2327 [0x6e] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movd mm, ea */
2328 [0x6f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, , movqdu */
2329 [0x70] = { (GenOpFunc2
*)gen_op_pshufw_mmx
,
2330 (GenOpFunc2
*)gen_op_pshufd_xmm
,
2331 (GenOpFunc2
*)gen_op_pshufhw_xmm
,
2332 (GenOpFunc2
*)gen_op_pshuflw_xmm
},
2333 [0x71] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftw */
2334 [0x72] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftd */
2335 [0x73] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* shiftq */
2336 [0x74] = MMX_OP2(pcmpeqb
),
2337 [0x75] = MMX_OP2(pcmpeqw
),
2338 [0x76] = MMX_OP2(pcmpeql
),
2339 [0x77] = { SSE_SPECIAL
}, /* emms */
2340 [0x7c] = { NULL
, gen_op_haddpd
, NULL
, gen_op_haddps
},
2341 [0x7d] = { NULL
, gen_op_hsubpd
, NULL
, gen_op_hsubps
},
2342 [0x7e] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movd, movd, , movq */
2343 [0x7f] = { SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
}, /* movq, movdqa, movdqu */
2344 [0xc4] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pinsrw */
2345 [0xc5] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pextrw */
2346 [0xd0] = { NULL
, gen_op_addsubpd
, NULL
, gen_op_addsubps
},
2347 [0xd1] = MMX_OP2(psrlw
),
2348 [0xd2] = MMX_OP2(psrld
),
2349 [0xd3] = MMX_OP2(psrlq
),
2350 [0xd4] = MMX_OP2(paddq
),
2351 [0xd5] = MMX_OP2(pmullw
),
2352 [0xd6] = { NULL
, SSE_SPECIAL
, SSE_SPECIAL
, SSE_SPECIAL
},
2353 [0xd7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* pmovmskb */
2354 [0xd8] = MMX_OP2(psubusb
),
2355 [0xd9] = MMX_OP2(psubusw
),
2356 [0xda] = MMX_OP2(pminub
),
2357 [0xdb] = MMX_OP2(pand
),
2358 [0xdc] = MMX_OP2(paddusb
),
2359 [0xdd] = MMX_OP2(paddusw
),
2360 [0xde] = MMX_OP2(pmaxub
),
2361 [0xdf] = MMX_OP2(pandn
),
2362 [0xe0] = MMX_OP2(pavgb
),
2363 [0xe1] = MMX_OP2(psraw
),
2364 [0xe2] = MMX_OP2(psrad
),
2365 [0xe3] = MMX_OP2(pavgw
),
2366 [0xe4] = MMX_OP2(pmulhuw
),
2367 [0xe5] = MMX_OP2(pmulhw
),
2368 [0xe6] = { NULL
, gen_op_cvttpd2dq
, gen_op_cvtdq2pd
, gen_op_cvtpd2dq
},
2369 [0xe7] = { SSE_SPECIAL
, SSE_SPECIAL
}, /* movntq, movntq */
2370 [0xe8] = MMX_OP2(psubsb
),
2371 [0xe9] = MMX_OP2(psubsw
),
2372 [0xea] = MMX_OP2(pminsw
),
2373 [0xeb] = MMX_OP2(por
),
2374 [0xec] = MMX_OP2(paddsb
),
2375 [0xed] = MMX_OP2(paddsw
),
2376 [0xee] = MMX_OP2(pmaxsw
),
2377 [0xef] = MMX_OP2(pxor
),
2378 [0xf0] = { NULL
, NULL
, NULL
, SSE_SPECIAL
}, /* lddqu (PNI) */
2379 [0xf1] = MMX_OP2(psllw
),
2380 [0xf2] = MMX_OP2(pslld
),
2381 [0xf3] = MMX_OP2(psllq
),
2382 [0xf4] = MMX_OP2(pmuludq
),
2383 [0xf5] = MMX_OP2(pmaddwd
),
2384 [0xf6] = MMX_OP2(psadbw
),
2385 [0xf7] = MMX_OP2(maskmov
),
2386 [0xf8] = MMX_OP2(psubb
),
2387 [0xf9] = MMX_OP2(psubw
),
2388 [0xfa] = MMX_OP2(psubl
),
2389 [0xfb] = MMX_OP2(psubq
),
2390 [0xfc] = MMX_OP2(paddb
),
2391 [0xfd] = MMX_OP2(paddw
),
2392 [0xfe] = MMX_OP2(paddl
),
2395 static GenOpFunc2
*sse_op_table2
[3 * 8][2] = {
2396 [0 + 2] = MMX_OP2(psrlw
),
2397 [0 + 4] = MMX_OP2(psraw
),
2398 [0 + 6] = MMX_OP2(psllw
),
2399 [8 + 2] = MMX_OP2(psrld
),
2400 [8 + 4] = MMX_OP2(psrad
),
2401 [8 + 6] = MMX_OP2(pslld
),
2402 [16 + 2] = MMX_OP2(psrlq
),
2403 [16 + 3] = { NULL
, gen_op_psrldq_xmm
},
2404 [16 + 6] = MMX_OP2(psllq
),
2405 [16 + 7] = { NULL
, gen_op_pslldq_xmm
},
2408 static GenOpFunc1
*sse_op_table3
[4 * 3] = {
2411 X86_64_ONLY(gen_op_cvtsq2ss
),
2412 X86_64_ONLY(gen_op_cvtsq2sd
),
2416 X86_64_ONLY(gen_op_cvttss2sq
),
2417 X86_64_ONLY(gen_op_cvttsd2sq
),
2421 X86_64_ONLY(gen_op_cvtss2sq
),
2422 X86_64_ONLY(gen_op_cvtsd2sq
),
2425 static GenOpFunc2
*sse_op_table4
[8][4] = {
2436 static void gen_sse(DisasContext
*s
, int b
, target_ulong pc_start
, int rex_r
)
2438 int b1
, op1_offset
, op2_offset
, is_xmm
, val
, ot
;
2439 int modrm
, mod
, rm
, reg
, reg_addr
, offset_addr
;
2440 GenOpFunc2
*sse_op2
;
2441 GenOpFunc3
*sse_op3
;
2444 if (s
->prefix
& PREFIX_DATA
)
2446 else if (s
->prefix
& PREFIX_REPZ
)
2448 else if (s
->prefix
& PREFIX_REPNZ
)
2452 sse_op2
= sse_op_table1
[b
][b1
];
2455 if (b
<= 0x5f || b
== 0xc6 || b
== 0xc2) {
2465 /* simple MMX/SSE operation */
2466 if (s
->flags
& HF_TS_MASK
) {
2467 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
2470 if (s
->flags
& HF_EM_MASK
) {
2472 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
2475 if (is_xmm
&& !(s
->flags
& HF_OSFXSR_MASK
))
2482 /* prepare MMX state (XXX: optimize by storing fptt and fptags in
2483 the static cpu state) */
2488 modrm
= ldub_code(s
->pc
++);
2489 reg
= ((modrm
>> 3) & 7);
2492 mod
= (modrm
>> 6) & 3;
2493 if (sse_op2
== SSE_SPECIAL
) {
2496 case 0x0e7: /* movntq */
2499 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2500 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2502 case 0x1e7: /* movntdq */
2503 case 0x02b: /* movntps */
2504 case 0x12b: /* movntps */
2505 case 0x2f0: /* lddqu */
2508 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2509 gen_sto_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
]));
2511 case 0x6e: /* movd mm, ea */
2512 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
2513 gen_op_movl_mm_T0_mmx(offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2515 case 0x16e: /* movd xmm, ea */
2516 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 0);
2517 gen_op_movl_mm_T0_xmm(offsetof(CPUX86State
,xmm_regs
[reg
]));
2519 case 0x6f: /* movq mm, ea */
2521 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2522 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2525 gen_op_movq(offsetof(CPUX86State
,fpregs
[reg
].mmx
),
2526 offsetof(CPUX86State
,fpregs
[rm
].mmx
));
2529 case 0x010: /* movups */
2530 case 0x110: /* movupd */
2531 case 0x028: /* movaps */
2532 case 0x128: /* movapd */
2533 case 0x16f: /* movdqa xmm, ea */
2534 case 0x26f: /* movdqu xmm, ea */
2536 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2537 gen_ldo_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
]));
2539 rm
= (modrm
& 7) | REX_B(s
);
2540 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[reg
]),
2541 offsetof(CPUX86State
,xmm_regs
[rm
]));
2544 case 0x210: /* movss xmm, ea */
2546 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2547 gen_op_ld_T0_A0
[OT_LONG
+ s
->mem_index
]();
2548 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
2550 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
2551 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
2552 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
2554 rm
= (modrm
& 7) | REX_B(s
);
2555 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
2556 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)));
2559 case 0x310: /* movsd xmm, ea */
2561 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2562 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2564 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)));
2565 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
2567 rm
= (modrm
& 7) | REX_B(s
);
2568 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
2569 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
2572 case 0x012: /* movlps */
2573 case 0x112: /* movlpd */
2575 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2576 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2579 rm
= (modrm
& 7) | REX_B(s
);
2580 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
2581 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
2584 case 0x016: /* movhps */
2585 case 0x116: /* movhpd */
2587 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2588 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
2591 rm
= (modrm
& 7) | REX_B(s
);
2592 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)),
2593 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
2596 case 0x216: /* movshdup */
2598 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2599 gen_ldo_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
]));
2601 rm
= (modrm
& 7) | REX_B(s
);
2602 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)),
2603 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(1)));
2604 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)),
2605 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(3)));
2607 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)),
2608 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(1)));
2609 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(2)),
2610 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(3)));
2612 case 0x7e: /* movd ea, mm */
2613 gen_op_movl_T0_mm_mmx(offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2614 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
2616 case 0x17e: /* movd ea, xmm */
2617 gen_op_movl_T0_mm_xmm(offsetof(CPUX86State
,xmm_regs
[reg
]));
2618 gen_ldst_modrm(s
, modrm
, OT_LONG
, OR_TMP0
, 1);
2620 case 0x27e: /* movq xmm, ea */
2622 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2623 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2625 rm
= (modrm
& 7) | REX_B(s
);
2626 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)),
2627 offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)));
2629 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
2631 case 0x7f: /* movq ea, mm */
2633 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2634 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2637 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
2638 offsetof(CPUX86State
,fpregs
[reg
].mmx
));
2641 case 0x011: /* movups */
2642 case 0x111: /* movupd */
2643 case 0x029: /* movaps */
2644 case 0x129: /* movapd */
2645 case 0x17f: /* movdqa ea, xmm */
2646 case 0x27f: /* movdqu ea, xmm */
2648 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2649 gen_sto_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
]));
2651 rm
= (modrm
& 7) | REX_B(s
);
2652 gen_op_movo(offsetof(CPUX86State
,xmm_regs
[rm
]),
2653 offsetof(CPUX86State
,xmm_regs
[reg
]));
2656 case 0x211: /* movss ea, xmm */
2658 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2659 gen_op_movl_T0_env(offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
2660 gen_op_st_T0_A0
[OT_LONG
+ s
->mem_index
]();
2662 rm
= (modrm
& 7) | REX_B(s
);
2663 gen_op_movl(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_L(0)),
2664 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_L(0)));
2667 case 0x311: /* movsd ea, xmm */
2669 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2670 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2672 rm
= (modrm
& 7) | REX_B(s
);
2673 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
2674 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2677 case 0x013: /* movlps */
2678 case 0x113: /* movlpd */
2680 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2681 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2686 case 0x017: /* movhps */
2687 case 0x117: /* movhpd */
2689 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2690 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(1)));
2695 case 0x71: /* shift mm, im */
2698 case 0x171: /* shift xmm, im */
2701 val
= ldub_code(s
->pc
++);
2703 gen_op_movl_T0_im(val
);
2704 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
2706 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_t0
.XMM_L(1)));
2707 op1_offset
= offsetof(CPUX86State
,xmm_t0
);
2709 gen_op_movl_T0_im(val
);
2710 gen_op_movl_env_T0(offsetof(CPUX86State
,mmx_t0
.MMX_L(0)));
2712 gen_op_movl_env_T0(offsetof(CPUX86State
,mmx_t0
.MMX_L(1)));
2713 op1_offset
= offsetof(CPUX86State
,mmx_t0
);
2715 sse_op2
= sse_op_table2
[((b
- 1) & 3) * 8 + (((modrm
>> 3)) & 7)][b1
];
2719 rm
= (modrm
& 7) | REX_B(s
);
2720 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
2723 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
2725 sse_op2(op2_offset
, op1_offset
);
2727 case 0x050: /* movmskps */
2728 rm
= (modrm
& 7) | REX_B(s
);
2729 gen_op_movmskps(offsetof(CPUX86State
,xmm_regs
[rm
]));
2730 gen_op_mov_reg_T0
[OT_LONG
][reg
]();
2732 case 0x150: /* movmskpd */
2733 rm
= (modrm
& 7) | REX_B(s
);
2734 gen_op_movmskpd(offsetof(CPUX86State
,xmm_regs
[rm
]));
2735 gen_op_mov_reg_T0
[OT_LONG
][reg
]();
2737 case 0x02a: /* cvtpi2ps */
2738 case 0x12a: /* cvtpi2pd */
2741 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2742 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
2743 gen_ldq_env_A0
[s
->mem_index
>> 2](op2_offset
);
2746 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
2748 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
2751 gen_op_cvtpi2ps(op1_offset
, op2_offset
);
2755 gen_op_cvtpi2pd(op1_offset
, op2_offset
);
2759 case 0x22a: /* cvtsi2ss */
2760 case 0x32a: /* cvtsi2sd */
2761 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
2762 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
2763 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
2764 sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2)](op1_offset
);
2766 case 0x02c: /* cvttps2pi */
2767 case 0x12c: /* cvttpd2pi */
2768 case 0x02d: /* cvtps2pi */
2769 case 0x12d: /* cvtpd2pi */
2772 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2773 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
2774 gen_ldo_env_A0
[s
->mem_index
>> 2](op2_offset
);
2776 rm
= (modrm
& 7) | REX_B(s
);
2777 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
2779 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
);
2782 gen_op_cvttps2pi(op1_offset
, op2_offset
);
2785 gen_op_cvttpd2pi(op1_offset
, op2_offset
);
2788 gen_op_cvtps2pi(op1_offset
, op2_offset
);
2791 gen_op_cvtpd2pi(op1_offset
, op2_offset
);
2795 case 0x22c: /* cvttss2si */
2796 case 0x32c: /* cvttsd2si */
2797 case 0x22d: /* cvtss2si */
2798 case 0x32d: /* cvtsd2si */
2799 ot
= (s
->dflag
== 2) ? OT_QUAD
: OT_LONG
;
2801 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2803 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_t0
.XMM_Q(0)));
2805 gen_op_ld_T0_A0
[OT_LONG
+ s
->mem_index
]();
2806 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
2808 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
2810 rm
= (modrm
& 7) | REX_B(s
);
2811 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
2813 sse_op_table3
[(s
->dflag
== 2) * 2 + ((b
>> 8) - 2) + 4 +
2814 (b
& 1) * 4](op2_offset
);
2815 gen_op_mov_reg_T0
[ot
][reg
]();
2817 case 0xc4: /* pinsrw */
2819 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
2820 val
= ldub_code(s
->pc
++);
2823 gen_op_pinsrw_xmm(offsetof(CPUX86State
,xmm_regs
[reg
]), val
);
2826 gen_op_pinsrw_mmx(offsetof(CPUX86State
,fpregs
[reg
].mmx
), val
);
2829 case 0xc5: /* pextrw */
2833 val
= ldub_code(s
->pc
++);
2836 rm
= (modrm
& 7) | REX_B(s
);
2837 gen_op_pextrw_xmm(offsetof(CPUX86State
,xmm_regs
[rm
]), val
);
2841 gen_op_pextrw_mmx(offsetof(CPUX86State
,fpregs
[rm
].mmx
), val
);
2843 reg
= ((modrm
>> 3) & 7) | rex_r
;
2844 gen_op_mov_reg_T0
[OT_LONG
][reg
]();
2846 case 0x1d6: /* movq ea, xmm */
2848 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2849 gen_stq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2851 rm
= (modrm
& 7) | REX_B(s
);
2852 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
2853 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2854 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
2857 case 0x2d6: /* movq2dq */
2859 rm
= (modrm
& 7) | REX_B(s
);
2860 gen_op_movq(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(0)),
2861 offsetof(CPUX86State
,fpregs
[reg
& 7].mmx
));
2862 gen_op_movq_env_0(offsetof(CPUX86State
,xmm_regs
[rm
].XMM_Q(1)));
2864 case 0x3d6: /* movdq2q */
2867 gen_op_movq(offsetof(CPUX86State
,fpregs
[rm
].mmx
),
2868 offsetof(CPUX86State
,xmm_regs
[reg
].XMM_Q(0)));
2870 case 0xd7: /* pmovmskb */
2875 rm
= (modrm
& 7) | REX_B(s
);
2876 gen_op_pmovmskb_xmm(offsetof(CPUX86State
,xmm_regs
[rm
]));
2879 gen_op_pmovmskb_mmx(offsetof(CPUX86State
,fpregs
[rm
].mmx
));
2881 reg
= ((modrm
>> 3) & 7) | rex_r
;
2882 gen_op_mov_reg_T0
[OT_LONG
][reg
]();
2888 /* generic MMX or SSE operation */
2890 /* maskmov : we must prepare A0 */
2893 #ifdef TARGET_X86_64
2895 gen_op_movq_A0_reg
[R_EDI
]();
2899 gen_op_movl_A0_reg
[R_EDI
]();
2901 gen_op_andl_A0_ffff();
2903 gen_add_A0_ds_seg(s
);
2906 op1_offset
= offsetof(CPUX86State
,xmm_regs
[reg
]);
2908 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2909 op2_offset
= offsetof(CPUX86State
,xmm_t0
);
2910 if (b1
>= 2 && ((b
>= 0x50 && b
<= 0x5f) ||
2912 /* specific case for SSE single instructions */
2915 gen_op_ld_T0_A0
[OT_LONG
+ s
->mem_index
]();
2916 gen_op_movl_env_T0(offsetof(CPUX86State
,xmm_t0
.XMM_L(0)));
2919 gen_ldq_env_A0
[s
->mem_index
>> 2](offsetof(CPUX86State
,xmm_t0
.XMM_D(0)));
2922 gen_ldo_env_A0
[s
->mem_index
>> 2](op2_offset
);
2925 rm
= (modrm
& 7) | REX_B(s
);
2926 op2_offset
= offsetof(CPUX86State
,xmm_regs
[rm
]);
2929 op1_offset
= offsetof(CPUX86State
,fpregs
[reg
].mmx
);
2931 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
2932 op2_offset
= offsetof(CPUX86State
,mmx_t0
);
2933 gen_ldq_env_A0
[s
->mem_index
>> 2](op2_offset
);
2936 op2_offset
= offsetof(CPUX86State
,fpregs
[rm
].mmx
);
2940 case 0x70: /* pshufx insn */
2941 case 0xc6: /* pshufx insn */
2942 val
= ldub_code(s
->pc
++);
2943 sse_op3
= (GenOpFunc3
*)sse_op2
;
2944 sse_op3(op1_offset
, op2_offset
, val
);
2948 val
= ldub_code(s
->pc
++);
2951 sse_op2
= sse_op_table4
[val
][b1
];
2952 sse_op2(op1_offset
, op2_offset
);
2955 sse_op2(op1_offset
, op2_offset
);
2958 if (b
== 0x2e || b
== 0x2f) {
2959 s
->cc_op
= CC_OP_EFLAGS
;
2965 /* convert one instruction. s->is_jmp is set if the translation must
2966 be stopped. Return the next pc value */
2967 static target_ulong
disas_insn(DisasContext
*s
, target_ulong pc_start
)
2969 int b
, prefixes
, aflag
, dflag
;
2971 int modrm
, reg
, rm
, mod
, reg_addr
, op
, opreg
, offset_addr
, val
;
2972 target_ulong next_eip
, tval
;
2982 #ifdef TARGET_X86_64
2987 s
->rip_offset
= 0; /* for relative ip address */
2989 b
= ldub_code(s
->pc
);
2991 /* check prefixes */
2992 #ifdef TARGET_X86_64
2996 prefixes
|= PREFIX_REPZ
;
2999 prefixes
|= PREFIX_REPNZ
;
3002 prefixes
|= PREFIX_LOCK
;
3023 prefixes
|= PREFIX_DATA
;
3026 prefixes
|= PREFIX_ADR
;
3030 rex_w
= (b
>> 3) & 1;
3031 rex_r
= (b
& 0x4) << 1;
3032 s
->rex_x
= (b
& 0x2) << 2;
3033 REX_B(s
) = (b
& 0x1) << 3;
3034 x86_64_hregs
= 1; /* select uniform byte register addressing */
3038 /* 0x66 is ignored if rex.w is set */
3041 if (prefixes
& PREFIX_DATA
)
3044 if (!(prefixes
& PREFIX_ADR
))
3051 prefixes
|= PREFIX_REPZ
;
3054 prefixes
|= PREFIX_REPNZ
;
3057 prefixes
|= PREFIX_LOCK
;
3078 prefixes
|= PREFIX_DATA
;
3081 prefixes
|= PREFIX_ADR
;
3084 if (prefixes
& PREFIX_DATA
)
3086 if (prefixes
& PREFIX_ADR
)
3090 s
->prefix
= prefixes
;
3094 /* lock generation */
3095 if (prefixes
& PREFIX_LOCK
)
3098 /* now check op code */
3102 /**************************/
3103 /* extended op code */
3104 b
= ldub_code(s
->pc
++) | 0x100;
3107 /**************************/
3125 ot
= dflag
+ OT_WORD
;
3128 case 0: /* OP Ev, Gv */
3129 modrm
= ldub_code(s
->pc
++);
3130 reg
= ((modrm
>> 3) & 7) | rex_r
;
3131 mod
= (modrm
>> 6) & 3;
3132 rm
= (modrm
& 7) | REX_B(s
);
3134 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3136 } else if (op
== OP_XORL
&& rm
== reg
) {
3138 /* xor reg, reg optimisation */
3140 s
->cc_op
= CC_OP_LOGICB
+ ot
;
3141 gen_op_mov_reg_T0
[ot
][reg
]();
3142 gen_op_update1_cc();
3147 gen_op_mov_TN_reg
[ot
][1][reg
]();
3148 gen_op(s
, op
, ot
, opreg
);
3150 case 1: /* OP Gv, Ev */
3151 modrm
= ldub_code(s
->pc
++);
3152 mod
= (modrm
>> 6) & 3;
3153 reg
= ((modrm
>> 3) & 7) | rex_r
;
3154 rm
= (modrm
& 7) | REX_B(s
);
3156 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3157 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
3158 } else if (op
== OP_XORL
&& rm
== reg
) {
3161 gen_op_mov_TN_reg
[ot
][1][rm
]();
3163 gen_op(s
, op
, ot
, reg
);
3165 case 2: /* OP A, Iv */
3166 val
= insn_get(s
, ot
);
3167 gen_op_movl_T1_im(val
);
3168 gen_op(s
, op
, ot
, OR_EAX
);
3174 case 0x80: /* GRP1 */
3184 ot
= dflag
+ OT_WORD
;
3186 modrm
= ldub_code(s
->pc
++);
3187 mod
= (modrm
>> 6) & 3;
3188 rm
= (modrm
& 7) | REX_B(s
);
3189 op
= (modrm
>> 3) & 7;
3195 s
->rip_offset
= insn_const_size(ot
);
3196 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3207 val
= insn_get(s
, ot
);
3210 val
= (int8_t)insn_get(s
, OT_BYTE
);
3213 gen_op_movl_T1_im(val
);
3214 gen_op(s
, op
, ot
, opreg
);
3218 /**************************/
3219 /* inc, dec, and other misc arith */
3220 case 0x40 ... 0x47: /* inc Gv */
3221 ot
= dflag
? OT_LONG
: OT_WORD
;
3222 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), 1);
3224 case 0x48 ... 0x4f: /* dec Gv */
3225 ot
= dflag
? OT_LONG
: OT_WORD
;
3226 gen_inc(s
, ot
, OR_EAX
+ (b
& 7), -1);
3228 case 0xf6: /* GRP3 */
3233 ot
= dflag
+ OT_WORD
;
3235 modrm
= ldub_code(s
->pc
++);
3236 mod
= (modrm
>> 6) & 3;
3237 rm
= (modrm
& 7) | REX_B(s
);
3238 op
= (modrm
>> 3) & 7;
3241 s
->rip_offset
= insn_const_size(ot
);
3242 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3243 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
3245 gen_op_mov_TN_reg
[ot
][0][rm
]();
3250 val
= insn_get(s
, ot
);
3251 gen_op_movl_T1_im(val
);
3252 gen_op_testl_T0_T1_cc();
3253 s
->cc_op
= CC_OP_LOGICB
+ ot
;
3258 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
3260 gen_op_mov_reg_T0
[ot
][rm
]();
3266 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
3268 gen_op_mov_reg_T0
[ot
][rm
]();
3270 gen_op_update_neg_cc();
3271 s
->cc_op
= CC_OP_SUBB
+ ot
;
3276 gen_op_mulb_AL_T0();
3277 s
->cc_op
= CC_OP_MULB
;
3280 gen_op_mulw_AX_T0();
3281 s
->cc_op
= CC_OP_MULW
;
3285 gen_op_mull_EAX_T0();
3286 s
->cc_op
= CC_OP_MULL
;
3288 #ifdef TARGET_X86_64
3290 gen_op_mulq_EAX_T0();
3291 s
->cc_op
= CC_OP_MULQ
;
3299 gen_op_imulb_AL_T0();
3300 s
->cc_op
= CC_OP_MULB
;
3303 gen_op_imulw_AX_T0();
3304 s
->cc_op
= CC_OP_MULW
;
3308 gen_op_imull_EAX_T0();
3309 s
->cc_op
= CC_OP_MULL
;
3311 #ifdef TARGET_X86_64
3313 gen_op_imulq_EAX_T0();
3314 s
->cc_op
= CC_OP_MULQ
;
3322 gen_jmp_im(pc_start
- s
->cs_base
);
3323 gen_op_divb_AL_T0();
3326 gen_jmp_im(pc_start
- s
->cs_base
);
3327 gen_op_divw_AX_T0();
3331 gen_jmp_im(pc_start
- s
->cs_base
);
3332 gen_op_divl_EAX_T0();
3334 #ifdef TARGET_X86_64
3336 gen_jmp_im(pc_start
- s
->cs_base
);
3337 gen_op_divq_EAX_T0();
3345 gen_jmp_im(pc_start
- s
->cs_base
);
3346 gen_op_idivb_AL_T0();
3349 gen_jmp_im(pc_start
- s
->cs_base
);
3350 gen_op_idivw_AX_T0();
3354 gen_jmp_im(pc_start
- s
->cs_base
);
3355 gen_op_idivl_EAX_T0();
3357 #ifdef TARGET_X86_64
3359 gen_jmp_im(pc_start
- s
->cs_base
);
3360 gen_op_idivq_EAX_T0();
3370 case 0xfe: /* GRP4 */
3371 case 0xff: /* GRP5 */
3375 ot
= dflag
+ OT_WORD
;
3377 modrm
= ldub_code(s
->pc
++);
3378 mod
= (modrm
>> 6) & 3;
3379 rm
= (modrm
& 7) | REX_B(s
);
3380 op
= (modrm
>> 3) & 7;
3381 if (op
>= 2 && b
== 0xfe) {
3385 if (op
>= 2 && op
<= 5) {
3386 /* operand size for jumps is 64 bit */
3388 } else if (op
== 6) {
3389 /* default push size is 64 bit */
3390 ot
= dflag
? OT_QUAD
: OT_WORD
;
3394 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3395 if (op
>= 2 && op
!= 3 && op
!= 5)
3396 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
3398 gen_op_mov_TN_reg
[ot
][0][rm
]();
3402 case 0: /* inc Ev */
3407 gen_inc(s
, ot
, opreg
, 1);
3409 case 1: /* dec Ev */
3414 gen_inc(s
, ot
, opreg
, -1);
3416 case 2: /* call Ev */
3417 /* XXX: optimize if memory (no 'and' is necessary) */
3419 gen_op_andl_T0_ffff();
3420 next_eip
= s
->pc
- s
->cs_base
;
3421 gen_movtl_T1_im(next_eip
);
3426 case 3: /* lcall Ev */
3427 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
3428 gen_op_addl_A0_im(1 << (ot
- OT_WORD
+ 1));
3429 gen_op_ldu_T0_A0
[OT_WORD
+ s
->mem_index
]();
3431 if (s
->pe
&& !s
->vm86
) {
3432 if (s
->cc_op
!= CC_OP_DYNAMIC
)
3433 gen_op_set_cc_op(s
->cc_op
);
3434 gen_jmp_im(pc_start
- s
->cs_base
);
3435 gen_op_lcall_protected_T0_T1(dflag
, s
->pc
- s
->cs_base
);
3437 gen_op_lcall_real_T0_T1(dflag
, s
->pc
- s
->cs_base
);
3441 case 4: /* jmp Ev */
3443 gen_op_andl_T0_ffff();
3447 case 5: /* ljmp Ev */
3448 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
3449 gen_op_addl_A0_im(1 << (ot
- OT_WORD
+ 1));
3450 gen_op_ldu_T0_A0
[OT_WORD
+ s
->mem_index
]();
3452 if (s
->pe
&& !s
->vm86
) {
3453 if (s
->cc_op
!= CC_OP_DYNAMIC
)
3454 gen_op_set_cc_op(s
->cc_op
);
3455 gen_jmp_im(pc_start
- s
->cs_base
);
3456 gen_op_ljmp_protected_T0_T1(s
->pc
- s
->cs_base
);
3458 gen_op_movl_seg_T0_vm(offsetof(CPUX86State
,segs
[R_CS
]));
3459 gen_op_movl_T0_T1();
3464 case 6: /* push Ev */
3472 case 0x84: /* test Ev, Gv */
3477 ot
= dflag
+ OT_WORD
;
3479 modrm
= ldub_code(s
->pc
++);
3480 mod
= (modrm
>> 6) & 3;
3481 rm
= (modrm
& 7) | REX_B(s
);
3482 reg
= ((modrm
>> 3) & 7) | rex_r
;
3484 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3485 gen_op_mov_TN_reg
[ot
][1][reg
]();
3486 gen_op_testl_T0_T1_cc();
3487 s
->cc_op
= CC_OP_LOGICB
+ ot
;
3490 case 0xa8: /* test eAX, Iv */
3495 ot
= dflag
+ OT_WORD
;
3496 val
= insn_get(s
, ot
);
3498 gen_op_mov_TN_reg
[ot
][0][OR_EAX
]();
3499 gen_op_movl_T1_im(val
);
3500 gen_op_testl_T0_T1_cc();
3501 s
->cc_op
= CC_OP_LOGICB
+ ot
;
3504 case 0x98: /* CWDE/CBW */
3505 #ifdef TARGET_X86_64
3507 gen_op_movslq_RAX_EAX();
3511 gen_op_movswl_EAX_AX();
3513 gen_op_movsbw_AX_AL();
3515 case 0x99: /* CDQ/CWD */
3516 #ifdef TARGET_X86_64
3518 gen_op_movsqo_RDX_RAX();
3522 gen_op_movslq_EDX_EAX();
3524 gen_op_movswl_DX_AX();
3526 case 0x1af: /* imul Gv, Ev */
3527 case 0x69: /* imul Gv, Ev, I */
3529 ot
= dflag
+ OT_WORD
;
3530 modrm
= ldub_code(s
->pc
++);
3531 reg
= ((modrm
>> 3) & 7) | rex_r
;
3533 s
->rip_offset
= insn_const_size(ot
);
3536 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3538 val
= insn_get(s
, ot
);
3539 gen_op_movl_T1_im(val
);
3540 } else if (b
== 0x6b) {
3541 val
= (int8_t)insn_get(s
, OT_BYTE
);
3542 gen_op_movl_T1_im(val
);
3544 gen_op_mov_TN_reg
[ot
][1][reg
]();
3547 #ifdef TARGET_X86_64
3548 if (ot
== OT_QUAD
) {
3549 gen_op_imulq_T0_T1();
3552 if (ot
== OT_LONG
) {
3553 gen_op_imull_T0_T1();
3555 gen_op_imulw_T0_T1();
3557 gen_op_mov_reg_T0
[ot
][reg
]();
3558 s
->cc_op
= CC_OP_MULB
+ ot
;
3561 case 0x1c1: /* xadd Ev, Gv */
3565 ot
= dflag
+ OT_WORD
;
3566 modrm
= ldub_code(s
->pc
++);
3567 reg
= ((modrm
>> 3) & 7) | rex_r
;
3568 mod
= (modrm
>> 6) & 3;
3570 rm
= (modrm
& 7) | REX_B(s
);
3571 gen_op_mov_TN_reg
[ot
][0][reg
]();
3572 gen_op_mov_TN_reg
[ot
][1][rm
]();
3573 gen_op_addl_T0_T1();
3574 gen_op_mov_reg_T1
[ot
][reg
]();
3575 gen_op_mov_reg_T0
[ot
][rm
]();
3577 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3578 gen_op_mov_TN_reg
[ot
][0][reg
]();
3579 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
3580 gen_op_addl_T0_T1();
3581 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
3582 gen_op_mov_reg_T1
[ot
][reg
]();
3584 gen_op_update2_cc();
3585 s
->cc_op
= CC_OP_ADDB
+ ot
;
3588 case 0x1b1: /* cmpxchg Ev, Gv */
3592 ot
= dflag
+ OT_WORD
;
3593 modrm
= ldub_code(s
->pc
++);
3594 reg
= ((modrm
>> 3) & 7) | rex_r
;
3595 mod
= (modrm
>> 6) & 3;
3596 gen_op_mov_TN_reg
[ot
][1][reg
]();
3598 rm
= (modrm
& 7) | REX_B(s
);
3599 gen_op_mov_TN_reg
[ot
][0][rm
]();
3600 gen_op_cmpxchg_T0_T1_EAX_cc
[ot
]();
3601 gen_op_mov_reg_T0
[ot
][rm
]();
3603 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3604 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
3605 gen_op_cmpxchg_mem_T0_T1_EAX_cc
[ot
+ s
->mem_index
]();
3607 s
->cc_op
= CC_OP_SUBB
+ ot
;
3609 case 0x1c7: /* cmpxchg8b */
3610 modrm
= ldub_code(s
->pc
++);
3611 mod
= (modrm
>> 6) & 3;
3614 if (s
->cc_op
!= CC_OP_DYNAMIC
)
3615 gen_op_set_cc_op(s
->cc_op
);
3616 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3618 s
->cc_op
= CC_OP_EFLAGS
;
3621 /**************************/
3623 case 0x50 ... 0x57: /* push */
3624 gen_op_mov_TN_reg
[OT_LONG
][0][(b
& 7) | REX_B(s
)]();
3627 case 0x58 ... 0x5f: /* pop */
3629 ot
= dflag
? OT_QUAD
: OT_WORD
;
3631 ot
= dflag
+ OT_WORD
;
3634 /* NOTE: order is important for pop %sp */
3636 gen_op_mov_reg_T0
[ot
][(b
& 7) | REX_B(s
)]();
3638 case 0x60: /* pusha */
3643 case 0x61: /* popa */
3648 case 0x68: /* push Iv */
3651 ot
= dflag
? OT_QUAD
: OT_WORD
;
3653 ot
= dflag
+ OT_WORD
;
3656 val
= insn_get(s
, ot
);
3658 val
= (int8_t)insn_get(s
, OT_BYTE
);
3659 gen_op_movl_T0_im(val
);
3662 case 0x8f: /* pop Ev */
3664 ot
= dflag
? OT_QUAD
: OT_WORD
;
3666 ot
= dflag
+ OT_WORD
;
3668 modrm
= ldub_code(s
->pc
++);
3669 mod
= (modrm
>> 6) & 3;
3672 /* NOTE: order is important for pop %sp */
3674 rm
= (modrm
& 7) | REX_B(s
);
3675 gen_op_mov_reg_T0
[ot
][rm
]();
3677 /* NOTE: order is important too for MMU exceptions */
3678 s
->popl_esp_hack
= 1 << ot
;
3679 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
3680 s
->popl_esp_hack
= 0;
3684 case 0xc8: /* enter */
3686 /* XXX: long mode support */
3688 val
= lduw_code(s
->pc
);
3690 level
= ldub_code(s
->pc
++);
3691 gen_enter(s
, val
, level
);
3694 case 0xc9: /* leave */
3695 /* XXX: exception not precise (ESP is updated before potential exception) */
3696 /* XXX: may be invalid for 16 bit in long mode */
3698 gen_op_mov_TN_reg
[OT_QUAD
][0][R_EBP
]();
3699 gen_op_mov_reg_T0
[OT_QUAD
][R_ESP
]();
3700 } else if (s
->ss32
) {
3701 gen_op_mov_TN_reg
[OT_LONG
][0][R_EBP
]();
3702 gen_op_mov_reg_T0
[OT_LONG
][R_ESP
]();
3704 gen_op_mov_TN_reg
[OT_WORD
][0][R_EBP
]();
3705 gen_op_mov_reg_T0
[OT_WORD
][R_ESP
]();
3709 ot
= dflag
? OT_QUAD
: OT_WORD
;
3711 ot
= dflag
+ OT_WORD
;
3713 gen_op_mov_reg_T0
[ot
][R_EBP
]();
3716 case 0x06: /* push es */
3717 case 0x0e: /* push cs */
3718 case 0x16: /* push ss */
3719 case 0x1e: /* push ds */
3722 gen_op_movl_T0_seg(b
>> 3);
3725 case 0x1a0: /* push fs */
3726 case 0x1a8: /* push gs */
3727 gen_op_movl_T0_seg((b
>> 3) & 7);
3730 case 0x07: /* pop es */
3731 case 0x17: /* pop ss */
3732 case 0x1f: /* pop ds */
3737 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
3740 /* if reg == SS, inhibit interrupts/trace. */
3741 /* If several instructions disable interrupts, only the
3743 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
3744 gen_op_set_inhibit_irq();
3748 gen_jmp_im(s
->pc
- s
->cs_base
);
3752 case 0x1a1: /* pop fs */
3753 case 0x1a9: /* pop gs */
3755 gen_movl_seg_T0(s
, (b
>> 3) & 7, pc_start
- s
->cs_base
);
3758 gen_jmp_im(s
->pc
- s
->cs_base
);
3763 /**************************/
3766 case 0x89: /* mov Gv, Ev */
3770 ot
= dflag
+ OT_WORD
;
3771 modrm
= ldub_code(s
->pc
++);
3772 reg
= ((modrm
>> 3) & 7) | rex_r
;
3774 /* generate a generic store */
3775 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
3778 case 0xc7: /* mov Ev, Iv */
3782 ot
= dflag
+ OT_WORD
;
3783 modrm
= ldub_code(s
->pc
++);
3784 mod
= (modrm
>> 6) & 3;
3786 s
->rip_offset
= insn_const_size(ot
);
3787 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3789 val
= insn_get(s
, ot
);
3790 gen_op_movl_T0_im(val
);
3792 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
3794 gen_op_mov_reg_T0
[ot
][(modrm
& 7) | REX_B(s
)]();
3797 case 0x8b: /* mov Ev, Gv */
3801 ot
= OT_WORD
+ dflag
;
3802 modrm
= ldub_code(s
->pc
++);
3803 reg
= ((modrm
>> 3) & 7) | rex_r
;
3805 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
3806 gen_op_mov_reg_T0
[ot
][reg
]();
3808 case 0x8e: /* mov seg, Gv */
3809 modrm
= ldub_code(s
->pc
++);
3810 reg
= (modrm
>> 3) & 7;
3811 if (reg
>= 6 || reg
== R_CS
)
3813 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
3814 gen_movl_seg_T0(s
, reg
, pc_start
- s
->cs_base
);
3816 /* if reg == SS, inhibit interrupts/trace */
3817 /* If several instructions disable interrupts, only the
3819 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
3820 gen_op_set_inhibit_irq();
3824 gen_jmp_im(s
->pc
- s
->cs_base
);
3828 case 0x8c: /* mov Gv, seg */
3829 modrm
= ldub_code(s
->pc
++);
3830 reg
= (modrm
>> 3) & 7;
3831 mod
= (modrm
>> 6) & 3;
3834 gen_op_movl_T0_seg(reg
);
3836 ot
= OT_WORD
+ dflag
;
3839 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
3842 case 0x1b6: /* movzbS Gv, Eb */
3843 case 0x1b7: /* movzwS Gv, Eb */
3844 case 0x1be: /* movsbS Gv, Eb */
3845 case 0x1bf: /* movswS Gv, Eb */
3848 /* d_ot is the size of destination */
3849 d_ot
= dflag
+ OT_WORD
;
3850 /* ot is the size of source */
3851 ot
= (b
& 1) + OT_BYTE
;
3852 modrm
= ldub_code(s
->pc
++);
3853 reg
= ((modrm
>> 3) & 7) | rex_r
;
3854 mod
= (modrm
>> 6) & 3;
3855 rm
= (modrm
& 7) | REX_B(s
);
3858 gen_op_mov_TN_reg
[ot
][0][rm
]();
3859 switch(ot
| (b
& 8)) {
3861 gen_op_movzbl_T0_T0();
3864 gen_op_movsbl_T0_T0();
3867 gen_op_movzwl_T0_T0();
3871 gen_op_movswl_T0_T0();
3874 gen_op_mov_reg_T0
[d_ot
][reg
]();
3876 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3878 gen_op_lds_T0_A0
[ot
+ s
->mem_index
]();
3880 gen_op_ldu_T0_A0
[ot
+ s
->mem_index
]();
3882 gen_op_mov_reg_T0
[d_ot
][reg
]();
3887 case 0x8d: /* lea */
3888 ot
= dflag
+ OT_WORD
;
3889 modrm
= ldub_code(s
->pc
++);
3890 mod
= (modrm
>> 6) & 3;
3893 reg
= ((modrm
>> 3) & 7) | rex_r
;
3894 /* we must ensure that no segment is added */
3898 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
3900 gen_op_mov_reg_A0
[ot
- OT_WORD
][reg
]();
3903 case 0xa0: /* mov EAX, Ov */
3905 case 0xa2: /* mov Ov, EAX */
3908 target_ulong offset_addr
;
3913 ot
= dflag
+ OT_WORD
;
3914 #ifdef TARGET_X86_64
3916 offset_addr
= ldq_code(s
->pc
);
3918 if (offset_addr
== (int32_t)offset_addr
)
3919 gen_op_movq_A0_im(offset_addr
);
3921 gen_op_movq_A0_im64(offset_addr
>> 32, offset_addr
);
3926 offset_addr
= insn_get(s
, OT_LONG
);
3928 offset_addr
= insn_get(s
, OT_WORD
);
3930 gen_op_movl_A0_im(offset_addr
);
3932 gen_add_A0_ds_seg(s
);
3934 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
3935 gen_op_mov_reg_T0
[ot
][R_EAX
]();
3937 gen_op_mov_TN_reg
[ot
][0][R_EAX
]();
3938 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
3942 case 0xd7: /* xlat */
3943 #ifdef TARGET_X86_64
3945 gen_op_movq_A0_reg
[R_EBX
]();
3946 gen_op_addq_A0_AL();
3950 gen_op_movl_A0_reg
[R_EBX
]();
3951 gen_op_addl_A0_AL();
3953 gen_op_andl_A0_ffff();
3955 gen_add_A0_ds_seg(s
);
3956 gen_op_ldu_T0_A0
[OT_BYTE
+ s
->mem_index
]();
3957 gen_op_mov_reg_T0
[OT_BYTE
][R_EAX
]();
3959 case 0xb0 ... 0xb7: /* mov R, Ib */
3960 val
= insn_get(s
, OT_BYTE
);
3961 gen_op_movl_T0_im(val
);
3962 gen_op_mov_reg_T0
[OT_BYTE
][(b
& 7) | REX_B(s
)]();
3964 case 0xb8 ... 0xbf: /* mov R, Iv */
3965 #ifdef TARGET_X86_64
3969 tmp
= ldq_code(s
->pc
);
3971 reg
= (b
& 7) | REX_B(s
);
3972 gen_movtl_T0_im(tmp
);
3973 gen_op_mov_reg_T0
[OT_QUAD
][reg
]();
3977 ot
= dflag
? OT_LONG
: OT_WORD
;
3978 val
= insn_get(s
, ot
);
3979 reg
= (b
& 7) | REX_B(s
);
3980 gen_op_movl_T0_im(val
);
3981 gen_op_mov_reg_T0
[ot
][reg
]();
3985 case 0x91 ... 0x97: /* xchg R, EAX */
3986 ot
= dflag
+ OT_WORD
;
3987 reg
= (b
& 7) | REX_B(s
);
3991 case 0x87: /* xchg Ev, Gv */
3995 ot
= dflag
+ OT_WORD
;
3996 modrm
= ldub_code(s
->pc
++);
3997 reg
= ((modrm
>> 3) & 7) | rex_r
;
3998 mod
= (modrm
>> 6) & 3;
4000 rm
= (modrm
& 7) | REX_B(s
);
4002 gen_op_mov_TN_reg
[ot
][0][reg
]();
4003 gen_op_mov_TN_reg
[ot
][1][rm
]();
4004 gen_op_mov_reg_T0
[ot
][rm
]();
4005 gen_op_mov_reg_T1
[ot
][reg
]();
4007 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4008 gen_op_mov_TN_reg
[ot
][0][reg
]();
4009 /* for xchg, lock is implicit */
4010 if (!(prefixes
& PREFIX_LOCK
))
4012 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
4013 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
4014 if (!(prefixes
& PREFIX_LOCK
))
4016 gen_op_mov_reg_T1
[ot
][reg
]();
4019 case 0xc4: /* les Gv */
4024 case 0xc5: /* lds Gv */
4029 case 0x1b2: /* lss Gv */
4032 case 0x1b4: /* lfs Gv */
4035 case 0x1b5: /* lgs Gv */
4038 ot
= dflag
? OT_LONG
: OT_WORD
;
4039 modrm
= ldub_code(s
->pc
++);
4040 reg
= ((modrm
>> 3) & 7) | rex_r
;
4041 mod
= (modrm
>> 6) & 3;
4044 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4045 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
4046 gen_op_addl_A0_im(1 << (ot
- OT_WORD
+ 1));
4047 /* load the segment first to handle exceptions properly */
4048 gen_op_ldu_T0_A0
[OT_WORD
+ s
->mem_index
]();
4049 gen_movl_seg_T0(s
, op
, pc_start
- s
->cs_base
);
4050 /* then put the data */
4051 gen_op_mov_reg_T1
[ot
][reg
]();
4053 gen_jmp_im(s
->pc
- s
->cs_base
);
4058 /************************/
4069 ot
= dflag
+ OT_WORD
;
4071 modrm
= ldub_code(s
->pc
++);
4072 mod
= (modrm
>> 6) & 3;
4073 op
= (modrm
>> 3) & 7;
4079 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4082 opreg
= (modrm
& 7) | REX_B(s
);
4087 gen_shift(s
, op
, ot
, opreg
, OR_ECX
);
4090 shift
= ldub_code(s
->pc
++);
4092 gen_shifti(s
, op
, ot
, opreg
, shift
);
4107 case 0x1a4: /* shld imm */
4111 case 0x1a5: /* shld cl */
4115 case 0x1ac: /* shrd imm */
4119 case 0x1ad: /* shrd cl */
4123 ot
= dflag
+ OT_WORD
;
4124 modrm
= ldub_code(s
->pc
++);
4125 mod
= (modrm
>> 6) & 3;
4126 rm
= (modrm
& 7) | REX_B(s
);
4127 reg
= ((modrm
>> 3) & 7) | rex_r
;
4130 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4131 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
4133 gen_op_mov_TN_reg
[ot
][0][rm
]();
4135 gen_op_mov_TN_reg
[ot
][1][reg
]();
4138 val
= ldub_code(s
->pc
++);
4145 gen_op_shiftd_T0_T1_im_cc
[ot
][op
](val
);
4147 gen_op_shiftd_mem_T0_T1_im_cc
[ot
+ s
->mem_index
][op
](val
);
4148 if (op
== 0 && ot
!= OT_WORD
)
4149 s
->cc_op
= CC_OP_SHLB
+ ot
;
4151 s
->cc_op
= CC_OP_SARB
+ ot
;
4154 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4155 gen_op_set_cc_op(s
->cc_op
);
4157 gen_op_shiftd_T0_T1_ECX_cc
[ot
][op
]();
4159 gen_op_shiftd_mem_T0_T1_ECX_cc
[ot
+ s
->mem_index
][op
]();
4160 s
->cc_op
= CC_OP_DYNAMIC
; /* cannot predict flags after */
4163 gen_op_mov_reg_T0
[ot
][rm
]();
4167 /************************/
4170 if (s
->flags
& (HF_EM_MASK
| HF_TS_MASK
)) {
4171 /* if CR0.EM or CR0.TS are set, generate an FPU exception */
4172 /* XXX: what to do if illegal op ? */
4173 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
4176 modrm
= ldub_code(s
->pc
++);
4177 mod
= (modrm
>> 6) & 3;
4179 op
= ((b
& 7) << 3) | ((modrm
>> 3) & 7);
4182 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4184 case 0x00 ... 0x07: /* fxxxs */
4185 case 0x10 ... 0x17: /* fixxxl */
4186 case 0x20 ... 0x27: /* fxxxl */
4187 case 0x30 ... 0x37: /* fixxx */
4194 gen_op_flds_FT0_A0();
4197 gen_op_fildl_FT0_A0();
4200 gen_op_fldl_FT0_A0();
4204 gen_op_fild_FT0_A0();
4208 gen_op_fp_arith_ST0_FT0
[op1
]();
4210 /* fcomp needs pop */
4215 case 0x08: /* flds */
4216 case 0x0a: /* fsts */
4217 case 0x0b: /* fstps */
4218 case 0x18: /* fildl */
4219 case 0x1a: /* fistl */
4220 case 0x1b: /* fistpl */
4221 case 0x28: /* fldl */
4222 case 0x2a: /* fstl */
4223 case 0x2b: /* fstpl */
4224 case 0x38: /* filds */
4225 case 0x3a: /* fists */
4226 case 0x3b: /* fistps */
4232 gen_op_flds_ST0_A0();
4235 gen_op_fildl_ST0_A0();
4238 gen_op_fldl_ST0_A0();
4242 gen_op_fild_ST0_A0();
4249 gen_op_fsts_ST0_A0();
4252 gen_op_fistl_ST0_A0();
4255 gen_op_fstl_ST0_A0();
4259 gen_op_fist_ST0_A0();
4267 case 0x0c: /* fldenv mem */
4268 gen_op_fldenv_A0(s
->dflag
);
4270 case 0x0d: /* fldcw mem */
4273 case 0x0e: /* fnstenv mem */
4274 gen_op_fnstenv_A0(s
->dflag
);
4276 case 0x0f: /* fnstcw mem */
4279 case 0x1d: /* fldt mem */
4280 gen_op_fldt_ST0_A0();
4282 case 0x1f: /* fstpt mem */
4283 gen_op_fstt_ST0_A0();
4286 case 0x2c: /* frstor mem */
4287 gen_op_frstor_A0(s
->dflag
);
4289 case 0x2e: /* fnsave mem */
4290 gen_op_fnsave_A0(s
->dflag
);
4292 case 0x2f: /* fnstsw mem */
4295 case 0x3c: /* fbld */
4296 gen_op_fbld_ST0_A0();
4298 case 0x3e: /* fbstp */
4299 gen_op_fbst_ST0_A0();
4302 case 0x3d: /* fildll */
4303 gen_op_fildll_ST0_A0();
4305 case 0x3f: /* fistpll */
4306 gen_op_fistll_ST0_A0();
4313 /* register float ops */
4317 case 0x08: /* fld sti */
4319 gen_op_fmov_ST0_STN((opreg
+ 1) & 7);
4321 case 0x09: /* fxchg sti */
4322 case 0x29: /* fxchg4 sti, undocumented op */
4323 case 0x39: /* fxchg7 sti, undocumented op */
4324 gen_op_fxchg_ST0_STN(opreg
);
4326 case 0x0a: /* grp d9/2 */
4329 /* check exceptions (FreeBSD FPU probe) */
4330 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4331 gen_op_set_cc_op(s
->cc_op
);
4332 gen_jmp_im(pc_start
- s
->cs_base
);
4339 case 0x0c: /* grp d9/4 */
4349 gen_op_fcom_ST0_FT0();
4358 case 0x0d: /* grp d9/5 */
4367 gen_op_fldl2t_ST0();
4371 gen_op_fldl2e_ST0();
4379 gen_op_fldlg2_ST0();
4383 gen_op_fldln2_ST0();
4394 case 0x0e: /* grp d9/6 */
4405 case 3: /* fpatan */
4408 case 4: /* fxtract */
4411 case 5: /* fprem1 */
4414 case 6: /* fdecstp */
4418 case 7: /* fincstp */
4423 case 0x0f: /* grp d9/7 */
4428 case 1: /* fyl2xp1 */
4434 case 3: /* fsincos */
4437 case 5: /* fscale */
4440 case 4: /* frndint */
4452 case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
4453 case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
4454 case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
4460 gen_op_fp_arith_STN_ST0
[op1
](opreg
);
4464 gen_op_fmov_FT0_STN(opreg
);
4465 gen_op_fp_arith_ST0_FT0
[op1
]();
4469 case 0x02: /* fcom */
4470 case 0x22: /* fcom2, undocumented op */
4471 gen_op_fmov_FT0_STN(opreg
);
4472 gen_op_fcom_ST0_FT0();
4474 case 0x03: /* fcomp */
4475 case 0x23: /* fcomp3, undocumented op */
4476 case 0x32: /* fcomp5, undocumented op */
4477 gen_op_fmov_FT0_STN(opreg
);
4478 gen_op_fcom_ST0_FT0();
4481 case 0x15: /* da/5 */
4483 case 1: /* fucompp */
4484 gen_op_fmov_FT0_STN(1);
4485 gen_op_fucom_ST0_FT0();
4495 case 0: /* feni (287 only, just do nop here) */
4497 case 1: /* fdisi (287 only, just do nop here) */
4502 case 3: /* fninit */
4505 case 4: /* fsetpm (287 only, just do nop here) */
4511 case 0x1d: /* fucomi */
4512 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4513 gen_op_set_cc_op(s
->cc_op
);
4514 gen_op_fmov_FT0_STN(opreg
);
4515 gen_op_fucomi_ST0_FT0();
4516 s
->cc_op
= CC_OP_EFLAGS
;
4518 case 0x1e: /* fcomi */
4519 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4520 gen_op_set_cc_op(s
->cc_op
);
4521 gen_op_fmov_FT0_STN(opreg
);
4522 gen_op_fcomi_ST0_FT0();
4523 s
->cc_op
= CC_OP_EFLAGS
;
4525 case 0x28: /* ffree sti */
4526 gen_op_ffree_STN(opreg
);
4528 case 0x2a: /* fst sti */
4529 gen_op_fmov_STN_ST0(opreg
);
4531 case 0x2b: /* fstp sti */
4532 case 0x0b: /* fstp1 sti, undocumented op */
4533 case 0x3a: /* fstp8 sti, undocumented op */
4534 case 0x3b: /* fstp9 sti, undocumented op */
4535 gen_op_fmov_STN_ST0(opreg
);
4538 case 0x2c: /* fucom st(i) */
4539 gen_op_fmov_FT0_STN(opreg
);
4540 gen_op_fucom_ST0_FT0();
4542 case 0x2d: /* fucomp st(i) */
4543 gen_op_fmov_FT0_STN(opreg
);
4544 gen_op_fucom_ST0_FT0();
4547 case 0x33: /* de/3 */
4549 case 1: /* fcompp */
4550 gen_op_fmov_FT0_STN(1);
4551 gen_op_fcom_ST0_FT0();
4559 case 0x38: /* ffreep sti, undocumented op */
4560 gen_op_ffree_STN(opreg
);
4563 case 0x3c: /* df/4 */
4566 gen_op_fnstsw_EAX();
4572 case 0x3d: /* fucomip */
4573 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4574 gen_op_set_cc_op(s
->cc_op
);
4575 gen_op_fmov_FT0_STN(opreg
);
4576 gen_op_fucomi_ST0_FT0();
4578 s
->cc_op
= CC_OP_EFLAGS
;
4580 case 0x3e: /* fcomip */
4581 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4582 gen_op_set_cc_op(s
->cc_op
);
4583 gen_op_fmov_FT0_STN(opreg
);
4584 gen_op_fcomi_ST0_FT0();
4586 s
->cc_op
= CC_OP_EFLAGS
;
4588 case 0x10 ... 0x13: /* fcmovxx */
4592 const static uint8_t fcmov_cc
[8] = {
4598 op1
= fcmov_cc
[op
& 3] | ((op
>> 3) & 1);
4600 gen_op_fcmov_ST0_STN_T0(opreg
);
4607 #ifdef USE_CODE_COPY
4608 s
->tb
->cflags
|= CF_TB_FP_USED
;
4611 /************************/
4614 case 0xa4: /* movsS */
4619 ot
= dflag
+ OT_WORD
;
4621 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
4622 gen_repz_movs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
4628 case 0xaa: /* stosS */
4633 ot
= dflag
+ OT_WORD
;
4635 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
4636 gen_repz_stos(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
4641 case 0xac: /* lodsS */
4646 ot
= dflag
+ OT_WORD
;
4647 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
4648 gen_repz_lods(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
4653 case 0xae: /* scasS */
4658 ot
= dflag
+ OT_WORD
;
4659 if (prefixes
& PREFIX_REPNZ
) {
4660 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
4661 } else if (prefixes
& PREFIX_REPZ
) {
4662 gen_repz_scas(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
4665 s
->cc_op
= CC_OP_SUBB
+ ot
;
4669 case 0xa6: /* cmpsS */
4674 ot
= dflag
+ OT_WORD
;
4675 if (prefixes
& PREFIX_REPNZ
) {
4676 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 1);
4677 } else if (prefixes
& PREFIX_REPZ
) {
4678 gen_repz_cmps(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
, 0);
4681 s
->cc_op
= CC_OP_SUBB
+ ot
;
4684 case 0x6c: /* insS */
4689 ot
= dflag
? OT_LONG
: OT_WORD
;
4690 gen_check_io(s
, ot
, 1, pc_start
- s
->cs_base
);
4691 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
4692 gen_repz_ins(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
4697 case 0x6e: /* outsS */
4702 ot
= dflag
? OT_LONG
: OT_WORD
;
4703 gen_check_io(s
, ot
, 1, pc_start
- s
->cs_base
);
4704 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
)) {
4705 gen_repz_outs(s
, ot
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
4711 /************************/
4718 ot
= dflag
? OT_LONG
: OT_WORD
;
4719 val
= ldub_code(s
->pc
++);
4720 gen_op_movl_T0_im(val
);
4721 gen_check_io(s
, ot
, 0, pc_start
- s
->cs_base
);
4723 gen_op_mov_reg_T1
[ot
][R_EAX
]();
4730 ot
= dflag
? OT_LONG
: OT_WORD
;
4731 val
= ldub_code(s
->pc
++);
4732 gen_op_movl_T0_im(val
);
4733 gen_check_io(s
, ot
, 0, pc_start
- s
->cs_base
);
4734 gen_op_mov_TN_reg
[ot
][1][R_EAX
]();
4742 ot
= dflag
? OT_LONG
: OT_WORD
;
4743 gen_op_mov_TN_reg
[OT_WORD
][0][R_EDX
]();
4744 gen_op_andl_T0_ffff();
4745 gen_check_io(s
, ot
, 0, pc_start
- s
->cs_base
);
4747 gen_op_mov_reg_T1
[ot
][R_EAX
]();
4754 ot
= dflag
? OT_LONG
: OT_WORD
;
4755 gen_op_mov_TN_reg
[OT_WORD
][0][R_EDX
]();
4756 gen_op_andl_T0_ffff();
4757 gen_check_io(s
, ot
, 0, pc_start
- s
->cs_base
);
4758 gen_op_mov_TN_reg
[ot
][1][R_EAX
]();
4762 /************************/
4764 case 0xc2: /* ret im */
4765 val
= ldsw_code(s
->pc
);
4768 gen_stack_update(s
, val
+ (2 << s
->dflag
));
4770 gen_op_andl_T0_ffff();
4774 case 0xc3: /* ret */
4778 gen_op_andl_T0_ffff();
4782 case 0xca: /* lret im */
4783 val
= ldsw_code(s
->pc
);
4786 if (s
->pe
&& !s
->vm86
) {
4787 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4788 gen_op_set_cc_op(s
->cc_op
);
4789 gen_jmp_im(pc_start
- s
->cs_base
);
4790 gen_op_lret_protected(s
->dflag
, val
);
4794 gen_op_ld_T0_A0
[1 + s
->dflag
+ s
->mem_index
]();
4796 gen_op_andl_T0_ffff();
4797 /* NOTE: keeping EIP updated is not a problem in case of
4801 gen_op_addl_A0_im(2 << s
->dflag
);
4802 gen_op_ld_T0_A0
[1 + s
->dflag
+ s
->mem_index
]();
4803 gen_op_movl_seg_T0_vm(offsetof(CPUX86State
,segs
[R_CS
]));
4804 /* add stack offset */
4805 gen_stack_update(s
, val
+ (4 << s
->dflag
));
4809 case 0xcb: /* lret */
4812 case 0xcf: /* iret */
4815 gen_op_iret_real(s
->dflag
);
4816 s
->cc_op
= CC_OP_EFLAGS
;
4817 } else if (s
->vm86
) {
4819 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
4821 gen_op_iret_real(s
->dflag
);
4822 s
->cc_op
= CC_OP_EFLAGS
;
4825 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4826 gen_op_set_cc_op(s
->cc_op
);
4827 gen_jmp_im(pc_start
- s
->cs_base
);
4828 gen_op_iret_protected(s
->dflag
, s
->pc
- s
->cs_base
);
4829 s
->cc_op
= CC_OP_EFLAGS
;
4833 case 0xe8: /* call im */
4836 tval
= (int32_t)insn_get(s
, OT_LONG
);
4838 tval
= (int16_t)insn_get(s
, OT_WORD
);
4839 next_eip
= s
->pc
- s
->cs_base
;
4843 gen_movtl_T0_im(next_eip
);
4848 case 0x9a: /* lcall im */
4850 unsigned int selector
, offset
;
4854 ot
= dflag
? OT_LONG
: OT_WORD
;
4855 offset
= insn_get(s
, ot
);
4856 selector
= insn_get(s
, OT_WORD
);
4858 gen_op_movl_T0_im(selector
);
4859 gen_op_movl_T1_imu(offset
);
4862 case 0xe9: /* jmp */
4864 tval
= (int32_t)insn_get(s
, OT_LONG
);
4866 tval
= (int16_t)insn_get(s
, OT_WORD
);
4867 tval
+= s
->pc
- s
->cs_base
;
4872 case 0xea: /* ljmp im */
4874 unsigned int selector
, offset
;
4878 ot
= dflag
? OT_LONG
: OT_WORD
;
4879 offset
= insn_get(s
, ot
);
4880 selector
= insn_get(s
, OT_WORD
);
4882 gen_op_movl_T0_im(selector
);
4883 gen_op_movl_T1_imu(offset
);
4886 case 0xeb: /* jmp Jb */
4887 tval
= (int8_t)insn_get(s
, OT_BYTE
);
4888 tval
+= s
->pc
- s
->cs_base
;
4893 case 0x70 ... 0x7f: /* jcc Jb */
4894 tval
= (int8_t)insn_get(s
, OT_BYTE
);
4896 case 0x180 ... 0x18f: /* jcc Jv */
4898 tval
= (int32_t)insn_get(s
, OT_LONG
);
4900 tval
= (int16_t)insn_get(s
, OT_WORD
);
4903 next_eip
= s
->pc
- s
->cs_base
;
4907 gen_jcc(s
, b
, tval
, next_eip
);
4910 case 0x190 ... 0x19f: /* setcc Gv */
4911 modrm
= ldub_code(s
->pc
++);
4913 gen_ldst_modrm(s
, modrm
, OT_BYTE
, OR_TMP0
, 1);
4915 case 0x140 ... 0x14f: /* cmov Gv, Ev */
4916 ot
= dflag
+ OT_WORD
;
4917 modrm
= ldub_code(s
->pc
++);
4918 reg
= ((modrm
>> 3) & 7) | rex_r
;
4919 mod
= (modrm
>> 6) & 3;
4922 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
4923 gen_op_ld_T1_A0
[ot
+ s
->mem_index
]();
4925 rm
= (modrm
& 7) | REX_B(s
);
4926 gen_op_mov_TN_reg
[ot
][1][rm
]();
4928 gen_op_cmov_reg_T1_T0
[ot
- OT_WORD
][reg
]();
4931 /************************/
4933 case 0x9c: /* pushf */
4934 if (s
->vm86
&& s
->iopl
!= 3) {
4935 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
4937 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4938 gen_op_set_cc_op(s
->cc_op
);
4939 gen_op_movl_T0_eflags();
4943 case 0x9d: /* popf */
4944 if (s
->vm86
&& s
->iopl
!= 3) {
4945 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
4950 gen_op_movl_eflags_T0_cpl0();
4952 gen_op_movw_eflags_T0_cpl0();
4955 if (s
->cpl
<= s
->iopl
) {
4957 gen_op_movl_eflags_T0_io();
4959 gen_op_movw_eflags_T0_io();
4963 gen_op_movl_eflags_T0();
4965 gen_op_movw_eflags_T0();
4970 s
->cc_op
= CC_OP_EFLAGS
;
4971 /* abort translation because TF flag may change */
4972 gen_jmp_im(s
->pc
- s
->cs_base
);
4976 case 0x9e: /* sahf */
4979 gen_op_mov_TN_reg
[OT_BYTE
][0][R_AH
]();
4980 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4981 gen_op_set_cc_op(s
->cc_op
);
4982 gen_op_movb_eflags_T0();
4983 s
->cc_op
= CC_OP_EFLAGS
;
4985 case 0x9f: /* lahf */
4988 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4989 gen_op_set_cc_op(s
->cc_op
);
4990 gen_op_movl_T0_eflags();
4991 gen_op_mov_reg_T0
[OT_BYTE
][R_AH
]();
4993 case 0xf5: /* cmc */
4994 if (s
->cc_op
!= CC_OP_DYNAMIC
)
4995 gen_op_set_cc_op(s
->cc_op
);
4997 s
->cc_op
= CC_OP_EFLAGS
;
4999 case 0xf8: /* clc */
5000 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5001 gen_op_set_cc_op(s
->cc_op
);
5003 s
->cc_op
= CC_OP_EFLAGS
;
5005 case 0xf9: /* stc */
5006 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5007 gen_op_set_cc_op(s
->cc_op
);
5009 s
->cc_op
= CC_OP_EFLAGS
;
5011 case 0xfc: /* cld */
5014 case 0xfd: /* std */
5018 /************************/
5019 /* bit operations */
5020 case 0x1ba: /* bt/bts/btr/btc Gv, im */
5021 ot
= dflag
+ OT_WORD
;
5022 modrm
= ldub_code(s
->pc
++);
5023 op
= ((modrm
>> 3) & 7) | rex_r
;
5024 mod
= (modrm
>> 6) & 3;
5025 rm
= (modrm
& 7) | REX_B(s
);
5028 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5029 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
5031 gen_op_mov_TN_reg
[ot
][0][rm
]();
5034 val
= ldub_code(s
->pc
++);
5035 gen_op_movl_T1_im(val
);
5039 gen_op_btx_T0_T1_cc
[ot
- OT_WORD
][op
]();
5040 s
->cc_op
= CC_OP_SARB
+ ot
;
5043 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
5045 gen_op_mov_reg_T0
[ot
][rm
]();
5046 gen_op_update_bt_cc();
5049 case 0x1a3: /* bt Gv, Ev */
5052 case 0x1ab: /* bts */
5055 case 0x1b3: /* btr */
5058 case 0x1bb: /* btc */
5061 ot
= dflag
+ OT_WORD
;
5062 modrm
= ldub_code(s
->pc
++);
5063 reg
= ((modrm
>> 3) & 7) | rex_r
;
5064 mod
= (modrm
>> 6) & 3;
5065 rm
= (modrm
& 7) | REX_B(s
);
5066 gen_op_mov_TN_reg
[OT_LONG
][1][reg
]();
5068 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5069 /* specific case: we need to add a displacement */
5070 gen_op_add_bit_A0_T1
[ot
- OT_WORD
]();
5071 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
5073 gen_op_mov_TN_reg
[ot
][0][rm
]();
5075 gen_op_btx_T0_T1_cc
[ot
- OT_WORD
][op
]();
5076 s
->cc_op
= CC_OP_SARB
+ ot
;
5079 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
5081 gen_op_mov_reg_T0
[ot
][rm
]();
5082 gen_op_update_bt_cc();
5085 case 0x1bc: /* bsf */
5086 case 0x1bd: /* bsr */
5087 ot
= dflag
+ OT_WORD
;
5088 modrm
= ldub_code(s
->pc
++);
5089 reg
= ((modrm
>> 3) & 7) | rex_r
;
5090 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5091 /* NOTE: in order to handle the 0 case, we must load the
5092 result. It could be optimized with a generated jump */
5093 gen_op_mov_TN_reg
[ot
][1][reg
]();
5094 gen_op_bsx_T0_cc
[ot
- OT_WORD
][b
& 1]();
5095 gen_op_mov_reg_T1
[ot
][reg
]();
5096 s
->cc_op
= CC_OP_LOGICB
+ ot
;
5098 /************************/
5100 case 0x27: /* daa */
5103 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5104 gen_op_set_cc_op(s
->cc_op
);
5106 s
->cc_op
= CC_OP_EFLAGS
;
5108 case 0x2f: /* das */
5111 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5112 gen_op_set_cc_op(s
->cc_op
);
5114 s
->cc_op
= CC_OP_EFLAGS
;
5116 case 0x37: /* aaa */
5119 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5120 gen_op_set_cc_op(s
->cc_op
);
5122 s
->cc_op
= CC_OP_EFLAGS
;
5124 case 0x3f: /* aas */
5127 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5128 gen_op_set_cc_op(s
->cc_op
);
5130 s
->cc_op
= CC_OP_EFLAGS
;
5132 case 0xd4: /* aam */
5135 val
= ldub_code(s
->pc
++);
5137 s
->cc_op
= CC_OP_LOGICB
;
5139 case 0xd5: /* aad */
5142 val
= ldub_code(s
->pc
++);
5144 s
->cc_op
= CC_OP_LOGICB
;
5146 /************************/
5148 case 0x90: /* nop */
5149 /* XXX: xchg + rex handling */
5150 /* XXX: correct lock test for all insn */
5151 if (prefixes
& PREFIX_LOCK
)
5154 case 0x9b: /* fwait */
5155 if ((s
->flags
& (HF_MP_MASK
| HF_TS_MASK
)) ==
5156 (HF_MP_MASK
| HF_TS_MASK
)) {
5157 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5159 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5160 gen_op_set_cc_op(s
->cc_op
);
5161 gen_jmp_im(pc_start
- s
->cs_base
);
5165 case 0xcc: /* int3 */
5166 gen_interrupt(s
, EXCP03_INT3
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5168 case 0xcd: /* int N */
5169 val
= ldub_code(s
->pc
++);
5170 if (s
->vm86
&& s
->iopl
!= 3) {
5171 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5173 gen_interrupt(s
, val
, pc_start
- s
->cs_base
, s
->pc
- s
->cs_base
);
5176 case 0xce: /* into */
5179 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5180 gen_op_set_cc_op(s
->cc_op
);
5181 gen_jmp_im(pc_start
- s
->cs_base
);
5182 gen_op_into(s
->pc
- pc_start
);
5184 case 0xf1: /* icebp (undocumented, exits to external debugger) */
5185 gen_debug(s
, pc_start
- s
->cs_base
);
5187 case 0xfa: /* cli */
5189 if (s
->cpl
<= s
->iopl
) {
5192 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5198 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5202 case 0xfb: /* sti */
5204 if (s
->cpl
<= s
->iopl
) {
5207 /* interruptions are enabled only the first insn after sti */
5208 /* If several instructions disable interrupts, only the
5210 if (!(s
->tb
->flags
& HF_INHIBIT_IRQ_MASK
))
5211 gen_op_set_inhibit_irq();
5212 /* give a chance to handle pending irqs */
5213 gen_jmp_im(s
->pc
- s
->cs_base
);
5216 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5222 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5226 case 0x62: /* bound */
5229 ot
= dflag
? OT_LONG
: OT_WORD
;
5230 modrm
= ldub_code(s
->pc
++);
5231 reg
= (modrm
>> 3) & 7;
5232 mod
= (modrm
>> 6) & 3;
5235 gen_op_mov_TN_reg
[ot
][0][reg
]();
5236 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5237 gen_jmp_im(pc_start
- s
->cs_base
);
5243 case 0x1c8 ... 0x1cf: /* bswap reg */
5244 reg
= (b
& 7) | REX_B(s
);
5245 #ifdef TARGET_X86_64
5247 gen_op_mov_TN_reg
[OT_QUAD
][0][reg
]();
5249 gen_op_mov_reg_T0
[OT_QUAD
][reg
]();
5253 gen_op_mov_TN_reg
[OT_LONG
][0][reg
]();
5255 gen_op_mov_reg_T0
[OT_LONG
][reg
]();
5258 case 0xd6: /* salc */
5261 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5262 gen_op_set_cc_op(s
->cc_op
);
5265 case 0xe0: /* loopnz */
5266 case 0xe1: /* loopz */
5267 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5268 gen_op_set_cc_op(s
->cc_op
);
5270 case 0xe2: /* loop */
5271 case 0xe3: /* jecxz */
5275 tval
= (int8_t)insn_get(s
, OT_BYTE
);
5276 next_eip
= s
->pc
- s
->cs_base
;
5281 l1
= gen_new_label();
5282 l2
= gen_new_label();
5285 gen_op_jz_ecx
[s
->aflag
](l1
);
5287 gen_op_dec_ECX
[s
->aflag
]();
5290 gen_op_loop
[s
->aflag
][b
](l1
);
5293 gen_jmp_im(next_eip
);
5294 gen_op_jmp_label(l2
);
5301 case 0x130: /* wrmsr */
5302 case 0x132: /* rdmsr */
5304 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5312 case 0x131: /* rdtsc */
5315 case 0x134: /* sysenter */
5319 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5321 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
5322 gen_op_set_cc_op(s
->cc_op
);
5323 s
->cc_op
= CC_OP_DYNAMIC
;
5325 gen_jmp_im(pc_start
- s
->cs_base
);
5330 case 0x135: /* sysexit */
5334 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5336 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
5337 gen_op_set_cc_op(s
->cc_op
);
5338 s
->cc_op
= CC_OP_DYNAMIC
;
5340 gen_jmp_im(pc_start
- s
->cs_base
);
5345 #ifdef TARGET_X86_64
5346 case 0x105: /* syscall */
5347 /* XXX: is it usable in real mode ? */
5348 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
5349 gen_op_set_cc_op(s
->cc_op
);
5350 s
->cc_op
= CC_OP_DYNAMIC
;
5352 gen_jmp_im(pc_start
- s
->cs_base
);
5353 gen_op_syscall(s
->pc
- pc_start
);
5356 case 0x107: /* sysret */
5358 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5360 if (s
->cc_op
!= CC_OP_DYNAMIC
) {
5361 gen_op_set_cc_op(s
->cc_op
);
5362 s
->cc_op
= CC_OP_DYNAMIC
;
5364 gen_jmp_im(pc_start
- s
->cs_base
);
5365 gen_op_sysret(s
->dflag
);
5370 case 0x1a2: /* cpuid */
5373 case 0xf4: /* hlt */
5375 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5377 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5378 gen_op_set_cc_op(s
->cc_op
);
5379 gen_jmp_im(s
->pc
- s
->cs_base
);
5385 modrm
= ldub_code(s
->pc
++);
5386 mod
= (modrm
>> 6) & 3;
5387 op
= (modrm
>> 3) & 7;
5390 if (!s
->pe
|| s
->vm86
)
5392 gen_op_movl_T0_env(offsetof(CPUX86State
,ldt
.selector
));
5396 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5399 if (!s
->pe
|| s
->vm86
)
5402 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5404 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5405 gen_jmp_im(pc_start
- s
->cs_base
);
5410 if (!s
->pe
|| s
->vm86
)
5412 gen_op_movl_T0_env(offsetof(CPUX86State
,tr
.selector
));
5416 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 1);
5419 if (!s
->pe
|| s
->vm86
)
5422 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5424 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5425 gen_jmp_im(pc_start
- s
->cs_base
);
5431 if (!s
->pe
|| s
->vm86
)
5433 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5434 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5435 gen_op_set_cc_op(s
->cc_op
);
5440 s
->cc_op
= CC_OP_EFLAGS
;
5447 modrm
= ldub_code(s
->pc
++);
5448 mod
= (modrm
>> 6) & 3;
5449 op
= (modrm
>> 3) & 7;
5455 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5457 gen_op_movl_T0_env(offsetof(CPUX86State
,gdt
.limit
));
5459 gen_op_movl_T0_env(offsetof(CPUX86State
,idt
.limit
));
5460 gen_op_st_T0_A0
[OT_WORD
+ s
->mem_index
]();
5461 #ifdef TARGET_X86_64
5463 gen_op_addq_A0_im(2);
5466 gen_op_addl_A0_im(2);
5468 gen_op_movtl_T0_env(offsetof(CPUX86State
,gdt
.base
));
5470 gen_op_movtl_T0_env(offsetof(CPUX86State
,idt
.base
));
5472 gen_op_andl_T0_im(0xffffff);
5473 gen_op_st_T0_A0
[CODE64(s
) + OT_LONG
+ s
->mem_index
]();
5480 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5482 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5483 gen_op_ld_T1_A0
[OT_WORD
+ s
->mem_index
]();
5484 #ifdef TARGET_X86_64
5486 gen_op_addq_A0_im(2);
5489 gen_op_addl_A0_im(2);
5490 gen_op_ld_T0_A0
[CODE64(s
) + OT_LONG
+ s
->mem_index
]();
5492 gen_op_andl_T0_im(0xffffff);
5494 gen_op_movtl_env_T0(offsetof(CPUX86State
,gdt
.base
));
5495 gen_op_movl_env_T1(offsetof(CPUX86State
,gdt
.limit
));
5497 gen_op_movtl_env_T0(offsetof(CPUX86State
,idt
.base
));
5498 gen_op_movl_env_T1(offsetof(CPUX86State
,idt
.limit
));
5503 gen_op_movl_T0_env(offsetof(CPUX86State
,cr
[0]));
5504 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 1);
5508 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5510 gen_ldst_modrm(s
, modrm
, OT_WORD
, OR_TMP0
, 0);
5512 gen_jmp_im(s
->pc
- s
->cs_base
);
5516 case 7: /* invlpg */
5518 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5521 #ifdef TARGET_X86_64
5522 if (CODE64(s
) && (modrm
& 7) == 0) {
5524 gen_op_movtl_T0_env(offsetof(CPUX86State
,segs
[R_GS
].base
));
5525 gen_op_movtl_T1_env(offsetof(CPUX86State
,kernelgsbase
));
5526 gen_op_movtl_env_T1(offsetof(CPUX86State
,segs
[R_GS
].base
));
5527 gen_op_movtl_env_T0(offsetof(CPUX86State
,kernelgsbase
));
5534 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5536 gen_jmp_im(s
->pc
- s
->cs_base
);
5545 case 0x108: /* invd */
5546 case 0x109: /* wbinvd */
5548 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5553 case 0x63: /* arpl or movslS (x86_64) */
5554 #ifdef TARGET_X86_64
5557 /* d_ot is the size of destination */
5558 d_ot
= dflag
+ OT_WORD
;
5560 modrm
= ldub_code(s
->pc
++);
5561 reg
= ((modrm
>> 3) & 7) | rex_r
;
5562 mod
= (modrm
>> 6) & 3;
5563 rm
= (modrm
& 7) | REX_B(s
);
5566 gen_op_mov_TN_reg
[OT_LONG
][0][rm
]();
5568 if (d_ot
== OT_QUAD
)
5569 gen_op_movslq_T0_T0();
5570 gen_op_mov_reg_T0
[d_ot
][reg
]();
5572 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5573 if (d_ot
== OT_QUAD
) {
5574 gen_op_lds_T0_A0
[OT_LONG
+ s
->mem_index
]();
5576 gen_op_ld_T0_A0
[OT_LONG
+ s
->mem_index
]();
5578 gen_op_mov_reg_T0
[d_ot
][reg
]();
5583 if (!s
->pe
|| s
->vm86
)
5585 ot
= dflag
? OT_LONG
: OT_WORD
;
5586 modrm
= ldub_code(s
->pc
++);
5587 reg
= (modrm
>> 3) & 7;
5588 mod
= (modrm
>> 6) & 3;
5591 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5592 gen_op_ld_T0_A0
[ot
+ s
->mem_index
]();
5594 gen_op_mov_TN_reg
[ot
][0][rm
]();
5596 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5597 gen_op_set_cc_op(s
->cc_op
);
5599 s
->cc_op
= CC_OP_EFLAGS
;
5601 gen_op_st_T0_A0
[ot
+ s
->mem_index
]();
5603 gen_op_mov_reg_T0
[ot
][rm
]();
5605 gen_op_arpl_update();
5608 case 0x102: /* lar */
5609 case 0x103: /* lsl */
5610 if (!s
->pe
|| s
->vm86
)
5612 ot
= dflag
? OT_LONG
: OT_WORD
;
5613 modrm
= ldub_code(s
->pc
++);
5614 reg
= ((modrm
>> 3) & 7) | rex_r
;
5615 gen_ldst_modrm(s
, modrm
, ot
, OR_TMP0
, 0);
5616 gen_op_mov_TN_reg
[ot
][1][reg
]();
5617 if (s
->cc_op
!= CC_OP_DYNAMIC
)
5618 gen_op_set_cc_op(s
->cc_op
);
5623 s
->cc_op
= CC_OP_EFLAGS
;
5624 gen_op_mov_reg_T1
[ot
][reg
]();
5627 modrm
= ldub_code(s
->pc
++);
5628 mod
= (modrm
>> 6) & 3;
5629 op
= (modrm
>> 3) & 7;
5631 case 0: /* prefetchnta */
5632 case 1: /* prefetchnt0 */
5633 case 2: /* prefetchnt0 */
5634 case 3: /* prefetchnt0 */
5637 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5638 /* nothing more to do */
5644 case 0x120: /* mov reg, crN */
5645 case 0x122: /* mov crN, reg */
5647 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5649 modrm
= ldub_code(s
->pc
++);
5650 if ((modrm
& 0xc0) != 0xc0)
5652 rm
= (modrm
& 7) | REX_B(s
);
5653 reg
= ((modrm
>> 3) & 7) | rex_r
;
5665 gen_op_mov_TN_reg
[ot
][0][rm
]();
5666 gen_op_movl_crN_T0(reg
);
5667 gen_jmp_im(s
->pc
- s
->cs_base
);
5670 #if !defined(CONFIG_USER_ONLY)
5672 gen_op_movtl_T0_cr8();
5675 gen_op_movtl_T0_env(offsetof(CPUX86State
,cr
[reg
]));
5676 gen_op_mov_reg_T0
[ot
][rm
]();
5684 case 0x121: /* mov reg, drN */
5685 case 0x123: /* mov drN, reg */
5687 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5689 modrm
= ldub_code(s
->pc
++);
5690 if ((modrm
& 0xc0) != 0xc0)
5692 rm
= (modrm
& 7) | REX_B(s
);
5693 reg
= ((modrm
>> 3) & 7) | rex_r
;
5698 /* XXX: do it dynamically with CR4.DE bit */
5699 if (reg
== 4 || reg
== 5 || reg
>= 8)
5702 gen_op_mov_TN_reg
[ot
][0][rm
]();
5703 gen_op_movl_drN_T0(reg
);
5704 gen_jmp_im(s
->pc
- s
->cs_base
);
5707 gen_op_movtl_T0_env(offsetof(CPUX86State
,dr
[reg
]));
5708 gen_op_mov_reg_T0
[ot
][rm
]();
5712 case 0x106: /* clts */
5714 gen_exception(s
, EXCP0D_GPF
, pc_start
- s
->cs_base
);
5717 /* abort block because static cpu state changed */
5718 gen_jmp_im(s
->pc
- s
->cs_base
);
5722 /* MMX/SSE/SSE2/PNI support */
5723 case 0x1c3: /* MOVNTI reg, mem */
5724 if (!(s
->cpuid_features
& CPUID_SSE2
))
5726 ot
= s
->dflag
== 2 ? OT_QUAD
: OT_LONG
;
5727 modrm
= ldub_code(s
->pc
++);
5728 mod
= (modrm
>> 6) & 3;
5731 reg
= ((modrm
>> 3) & 7) | rex_r
;
5732 /* generate a generic store */
5733 gen_ldst_modrm(s
, modrm
, ot
, reg
, 1);
5736 modrm
= ldub_code(s
->pc
++);
5737 mod
= (modrm
>> 6) & 3;
5738 op
= (modrm
>> 3) & 7;
5740 case 0: /* fxsave */
5741 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
))
5743 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5744 gen_op_fxsave_A0((s
->dflag
== 2));
5746 case 1: /* fxrstor */
5747 if (mod
== 3 || !(s
->cpuid_features
& CPUID_FXSR
))
5749 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5750 gen_op_fxrstor_A0((s
->dflag
== 2));
5752 case 2: /* ldmxcsr */
5753 case 3: /* stmxcsr */
5754 if (s
->flags
& HF_TS_MASK
) {
5755 gen_exception(s
, EXCP07_PREX
, pc_start
- s
->cs_base
);
5758 if ((s
->flags
& HF_EM_MASK
) || !(s
->flags
& HF_OSFXSR_MASK
) ||
5761 gen_lea_modrm(s
, modrm
, ®_addr
, &offset_addr
);
5763 gen_op_ld_T0_A0
[OT_LONG
+ s
->mem_index
]();
5764 gen_op_movl_env_T0(offsetof(CPUX86State
, mxcsr
));
5766 gen_op_movl_T0_env(offsetof(CPUX86State
, mxcsr
));
5767 gen_op_st_T0_A0
[OT_LONG
+ s
->mem_index
]();
5770 case 5: /* lfence */
5771 case 6: /* mfence */
5772 case 7: /* sfence */
5773 if ((modrm
& 0xc7) != 0xc0 || !(s
->cpuid_features
& CPUID_SSE
))
5780 case 0x110 ... 0x117:
5781 case 0x128 ... 0x12f:
5782 case 0x150 ... 0x177:
5783 case 0x17c ... 0x17f:
5785 case 0x1c4 ... 0x1c6:
5786 case 0x1d0 ... 0x1fe:
5787 gen_sse(s
, b
, pc_start
, rex_r
);
5792 /* lock generation */
5793 if (s
->prefix
& PREFIX_LOCK
)
5797 if (s
->prefix
& PREFIX_LOCK
)
5799 /* XXX: ensure that no lock was generated */
5800 gen_exception(s
, EXCP06_ILLOP
, pc_start
- s
->cs_base
);
5804 #define CC_OSZAPC (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C)
5805 #define CC_OSZAP (CC_O | CC_S | CC_Z | CC_A | CC_P)
5807 /* flags read by an operation */
5808 static uint16_t opc_read_flags
[NB_OPS
] = {
5809 [INDEX_op_aas
] = CC_A
,
5810 [INDEX_op_aaa
] = CC_A
,
5811 [INDEX_op_das
] = CC_A
| CC_C
,
5812 [INDEX_op_daa
] = CC_A
| CC_C
,
5814 /* subtle: due to the incl/decl implementation, C is used */
5815 [INDEX_op_update_inc_cc
] = CC_C
,
5817 [INDEX_op_into
] = CC_O
,
5819 [INDEX_op_jb_subb
] = CC_C
,
5820 [INDEX_op_jb_subw
] = CC_C
,
5821 [INDEX_op_jb_subl
] = CC_C
,
5823 [INDEX_op_jz_subb
] = CC_Z
,
5824 [INDEX_op_jz_subw
] = CC_Z
,
5825 [INDEX_op_jz_subl
] = CC_Z
,
5827 [INDEX_op_jbe_subb
] = CC_Z
| CC_C
,
5828 [INDEX_op_jbe_subw
] = CC_Z
| CC_C
,
5829 [INDEX_op_jbe_subl
] = CC_Z
| CC_C
,
5831 [INDEX_op_js_subb
] = CC_S
,
5832 [INDEX_op_js_subw
] = CC_S
,
5833 [INDEX_op_js_subl
] = CC_S
,
5835 [INDEX_op_jl_subb
] = CC_O
| CC_S
,
5836 [INDEX_op_jl_subw
] = CC_O
| CC_S
,
5837 [INDEX_op_jl_subl
] = CC_O
| CC_S
,
5839 [INDEX_op_jle_subb
] = CC_O
| CC_S
| CC_Z
,
5840 [INDEX_op_jle_subw
] = CC_O
| CC_S
| CC_Z
,
5841 [INDEX_op_jle_subl
] = CC_O
| CC_S
| CC_Z
,
5843 [INDEX_op_loopnzw
] = CC_Z
,
5844 [INDEX_op_loopnzl
] = CC_Z
,
5845 [INDEX_op_loopzw
] = CC_Z
,
5846 [INDEX_op_loopzl
] = CC_Z
,
5848 [INDEX_op_seto_T0_cc
] = CC_O
,
5849 [INDEX_op_setb_T0_cc
] = CC_C
,
5850 [INDEX_op_setz_T0_cc
] = CC_Z
,
5851 [INDEX_op_setbe_T0_cc
] = CC_Z
| CC_C
,
5852 [INDEX_op_sets_T0_cc
] = CC_S
,
5853 [INDEX_op_setp_T0_cc
] = CC_P
,
5854 [INDEX_op_setl_T0_cc
] = CC_O
| CC_S
,
5855 [INDEX_op_setle_T0_cc
] = CC_O
| CC_S
| CC_Z
,
5857 [INDEX_op_setb_T0_subb
] = CC_C
,
5858 [INDEX_op_setb_T0_subw
] = CC_C
,
5859 [INDEX_op_setb_T0_subl
] = CC_C
,
5861 [INDEX_op_setz_T0_subb
] = CC_Z
,
5862 [INDEX_op_setz_T0_subw
] = CC_Z
,
5863 [INDEX_op_setz_T0_subl
] = CC_Z
,
5865 [INDEX_op_setbe_T0_subb
] = CC_Z
| CC_C
,
5866 [INDEX_op_setbe_T0_subw
] = CC_Z
| CC_C
,
5867 [INDEX_op_setbe_T0_subl
] = CC_Z
| CC_C
,
5869 [INDEX_op_sets_T0_subb
] = CC_S
,
5870 [INDEX_op_sets_T0_subw
] = CC_S
,
5871 [INDEX_op_sets_T0_subl
] = CC_S
,
5873 [INDEX_op_setl_T0_subb
] = CC_O
| CC_S
,
5874 [INDEX_op_setl_T0_subw
] = CC_O
| CC_S
,
5875 [INDEX_op_setl_T0_subl
] = CC_O
| CC_S
,
5877 [INDEX_op_setle_T0_subb
] = CC_O
| CC_S
| CC_Z
,
5878 [INDEX_op_setle_T0_subw
] = CC_O
| CC_S
| CC_Z
,
5879 [INDEX_op_setle_T0_subl
] = CC_O
| CC_S
| CC_Z
,
5881 [INDEX_op_movl_T0_eflags
] = CC_OSZAPC
,
5882 [INDEX_op_cmc
] = CC_C
,
5883 [INDEX_op_salc
] = CC_C
,
5885 /* needed for correct flag optimisation before string ops */
5886 [INDEX_op_jnz_ecxw
] = CC_OSZAPC
,
5887 [INDEX_op_jnz_ecxl
] = CC_OSZAPC
,
5888 [INDEX_op_jz_ecxw
] = CC_OSZAPC
,
5889 [INDEX_op_jz_ecxl
] = CC_OSZAPC
,
5891 #ifdef TARGET_X86_64
5892 [INDEX_op_jb_subq
] = CC_C
,
5893 [INDEX_op_jz_subq
] = CC_Z
,
5894 [INDEX_op_jbe_subq
] = CC_Z
| CC_C
,
5895 [INDEX_op_js_subq
] = CC_S
,
5896 [INDEX_op_jl_subq
] = CC_O
| CC_S
,
5897 [INDEX_op_jle_subq
] = CC_O
| CC_S
| CC_Z
,
5899 [INDEX_op_loopnzq
] = CC_Z
,
5900 [INDEX_op_loopzq
] = CC_Z
,
5902 [INDEX_op_setb_T0_subq
] = CC_C
,
5903 [INDEX_op_setz_T0_subq
] = CC_Z
,
5904 [INDEX_op_setbe_T0_subq
] = CC_Z
| CC_C
,
5905 [INDEX_op_sets_T0_subq
] = CC_S
,
5906 [INDEX_op_setl_T0_subq
] = CC_O
| CC_S
,
5907 [INDEX_op_setle_T0_subq
] = CC_O
| CC_S
| CC_Z
,
5909 [INDEX_op_jnz_ecxq
] = CC_OSZAPC
,
5910 [INDEX_op_jz_ecxq
] = CC_OSZAPC
,
5913 #define DEF_READF(SUFFIX)\
5914 [INDEX_op_adcb ## SUFFIX ## _T0_T1_cc] = CC_C,\
5915 [INDEX_op_adcw ## SUFFIX ## _T0_T1_cc] = CC_C,\
5916 [INDEX_op_adcl ## SUFFIX ## _T0_T1_cc] = CC_C,\
5917 X86_64_DEF([INDEX_op_adcq ## SUFFIX ## _T0_T1_cc] = CC_C,)\
5918 [INDEX_op_sbbb ## SUFFIX ## _T0_T1_cc] = CC_C,\
5919 [INDEX_op_sbbw ## SUFFIX ## _T0_T1_cc] = CC_C,\
5920 [INDEX_op_sbbl ## SUFFIX ## _T0_T1_cc] = CC_C,\
5921 X86_64_DEF([INDEX_op_sbbq ## SUFFIX ## _T0_T1_cc] = CC_C,)\
5923 [INDEX_op_rclb ## SUFFIX ## _T0_T1_cc] = CC_C,\
5924 [INDEX_op_rclw ## SUFFIX ## _T0_T1_cc] = CC_C,\
5925 [INDEX_op_rcll ## SUFFIX ## _T0_T1_cc] = CC_C,\
5926 X86_64_DEF([INDEX_op_rclq ## SUFFIX ## _T0_T1_cc] = CC_C,)\
5927 [INDEX_op_rcrb ## SUFFIX ## _T0_T1_cc] = CC_C,\
5928 [INDEX_op_rcrw ## SUFFIX ## _T0_T1_cc] = CC_C,\
5929 [INDEX_op_rcrl ## SUFFIX ## _T0_T1_cc] = CC_C,\
5930 X86_64_DEF([INDEX_op_rcrq ## SUFFIX ## _T0_T1_cc] = CC_C,)
5934 #ifndef CONFIG_USER_ONLY
5940 /* flags written by an operation */
5941 static uint16_t opc_write_flags
[NB_OPS
] = {
5942 [INDEX_op_update2_cc
] = CC_OSZAPC
,
5943 [INDEX_op_update1_cc
] = CC_OSZAPC
,
5944 [INDEX_op_cmpl_T0_T1_cc
] = CC_OSZAPC
,
5945 [INDEX_op_update_neg_cc
] = CC_OSZAPC
,
5946 /* subtle: due to the incl/decl implementation, C is used */
5947 [INDEX_op_update_inc_cc
] = CC_OSZAPC
,
5948 [INDEX_op_testl_T0_T1_cc
] = CC_OSZAPC
,
5950 [INDEX_op_mulb_AL_T0
] = CC_OSZAPC
,
5951 [INDEX_op_mulw_AX_T0
] = CC_OSZAPC
,
5952 [INDEX_op_mull_EAX_T0
] = CC_OSZAPC
,
5953 X86_64_DEF([INDEX_op_mulq_EAX_T0
] = CC_OSZAPC
,)
5954 [INDEX_op_imulb_AL_T0
] = CC_OSZAPC
,
5955 [INDEX_op_imulw_AX_T0
] = CC_OSZAPC
,
5956 [INDEX_op_imull_EAX_T0
] = CC_OSZAPC
,
5957 X86_64_DEF([INDEX_op_imulq_EAX_T0
] = CC_OSZAPC
,)
5958 [INDEX_op_imulw_T0_T1
] = CC_OSZAPC
,
5959 [INDEX_op_imull_T0_T1
] = CC_OSZAPC
,
5960 X86_64_DEF([INDEX_op_imulq_T0_T1
] = CC_OSZAPC
,)
5963 [INDEX_op_ucomiss
] = CC_OSZAPC
,
5964 [INDEX_op_ucomisd
] = CC_OSZAPC
,
5965 [INDEX_op_comiss
] = CC_OSZAPC
,
5966 [INDEX_op_comisd
] = CC_OSZAPC
,
5969 [INDEX_op_aam
] = CC_OSZAPC
,
5970 [INDEX_op_aad
] = CC_OSZAPC
,
5971 [INDEX_op_aas
] = CC_OSZAPC
,
5972 [INDEX_op_aaa
] = CC_OSZAPC
,
5973 [INDEX_op_das
] = CC_OSZAPC
,
5974 [INDEX_op_daa
] = CC_OSZAPC
,
5976 [INDEX_op_movb_eflags_T0
] = CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
,
5977 [INDEX_op_movw_eflags_T0
] = CC_OSZAPC
,
5978 [INDEX_op_movl_eflags_T0
] = CC_OSZAPC
,
5979 [INDEX_op_movw_eflags_T0_io
] = CC_OSZAPC
,
5980 [INDEX_op_movl_eflags_T0_io
] = CC_OSZAPC
,
5981 [INDEX_op_movw_eflags_T0_cpl0
] = CC_OSZAPC
,
5982 [INDEX_op_movl_eflags_T0_cpl0
] = CC_OSZAPC
,
5983 [INDEX_op_clc
] = CC_C
,
5984 [INDEX_op_stc
] = CC_C
,
5985 [INDEX_op_cmc
] = CC_C
,
5987 [INDEX_op_btw_T0_T1_cc
] = CC_OSZAPC
,
5988 [INDEX_op_btl_T0_T1_cc
] = CC_OSZAPC
,
5989 X86_64_DEF([INDEX_op_btq_T0_T1_cc
] = CC_OSZAPC
,)
5990 [INDEX_op_btsw_T0_T1_cc
] = CC_OSZAPC
,
5991 [INDEX_op_btsl_T0_T1_cc
] = CC_OSZAPC
,
5992 X86_64_DEF([INDEX_op_btsq_T0_T1_cc
] = CC_OSZAPC
,)
5993 [INDEX_op_btrw_T0_T1_cc
] = CC_OSZAPC
,
5994 [INDEX_op_btrl_T0_T1_cc
] = CC_OSZAPC
,
5995 X86_64_DEF([INDEX_op_btrq_T0_T1_cc
] = CC_OSZAPC
,)
5996 [INDEX_op_btcw_T0_T1_cc
] = CC_OSZAPC
,
5997 [INDEX_op_btcl_T0_T1_cc
] = CC_OSZAPC
,
5998 X86_64_DEF([INDEX_op_btcq_T0_T1_cc
] = CC_OSZAPC
,)
6000 [INDEX_op_bsfw_T0_cc
] = CC_OSZAPC
,
6001 [INDEX_op_bsfl_T0_cc
] = CC_OSZAPC
,
6002 X86_64_DEF([INDEX_op_bsfq_T0_cc
] = CC_OSZAPC
,)
6003 [INDEX_op_bsrw_T0_cc
] = CC_OSZAPC
,
6004 [INDEX_op_bsrl_T0_cc
] = CC_OSZAPC
,
6005 X86_64_DEF([INDEX_op_bsrq_T0_cc
] = CC_OSZAPC
,)
6007 [INDEX_op_cmpxchgb_T0_T1_EAX_cc
] = CC_OSZAPC
,
6008 [INDEX_op_cmpxchgw_T0_T1_EAX_cc
] = CC_OSZAPC
,
6009 [INDEX_op_cmpxchgl_T0_T1_EAX_cc
] = CC_OSZAPC
,
6010 X86_64_DEF([INDEX_op_cmpxchgq_T0_T1_EAX_cc
] = CC_OSZAPC
,)
6012 [INDEX_op_cmpxchg8b
] = CC_Z
,
6013 [INDEX_op_lar
] = CC_Z
,
6014 [INDEX_op_lsl
] = CC_Z
,
6015 [INDEX_op_fcomi_ST0_FT0
] = CC_Z
| CC_P
| CC_C
,
6016 [INDEX_op_fucomi_ST0_FT0
] = CC_Z
| CC_P
| CC_C
,
6018 #define DEF_WRITEF(SUFFIX)\
6019 [INDEX_op_adcb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6020 [INDEX_op_adcw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6021 [INDEX_op_adcl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6022 X86_64_DEF([INDEX_op_adcq ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,)\
6023 [INDEX_op_sbbb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6024 [INDEX_op_sbbw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6025 [INDEX_op_sbbl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6026 X86_64_DEF([INDEX_op_sbbq ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,)\
6028 [INDEX_op_rolb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6029 [INDEX_op_rolw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6030 [INDEX_op_roll ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6031 X86_64_DEF([INDEX_op_rolq ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,)\
6032 [INDEX_op_rorb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6033 [INDEX_op_rorw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6034 [INDEX_op_rorl ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6035 X86_64_DEF([INDEX_op_rorq ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,)\
6037 [INDEX_op_rclb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6038 [INDEX_op_rclw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6039 [INDEX_op_rcll ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6040 X86_64_DEF([INDEX_op_rclq ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,)\
6041 [INDEX_op_rcrb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6042 [INDEX_op_rcrw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6043 [INDEX_op_rcrl ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\
6044 X86_64_DEF([INDEX_op_rcrq ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,)\
6046 [INDEX_op_shlb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6047 [INDEX_op_shlw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6048 [INDEX_op_shll ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6049 X86_64_DEF([INDEX_op_shlq ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,)\
6051 [INDEX_op_shrb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6052 [INDEX_op_shrw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6053 [INDEX_op_shrl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6054 X86_64_DEF([INDEX_op_shrq ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,)\
6056 [INDEX_op_sarb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6057 [INDEX_op_sarw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6058 [INDEX_op_sarl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\
6059 X86_64_DEF([INDEX_op_sarq ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,)\
6061 [INDEX_op_shldw ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\
6062 [INDEX_op_shldl ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\
6063 X86_64_DEF([INDEX_op_shldq ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,)\
6064 [INDEX_op_shldw ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\
6065 [INDEX_op_shldl ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\
6066 X86_64_DEF([INDEX_op_shldq ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,)\
6068 [INDEX_op_shrdw ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\
6069 [INDEX_op_shrdl ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\
6070 X86_64_DEF([INDEX_op_shrdq ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,)\
6071 [INDEX_op_shrdw ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\
6072 [INDEX_op_shrdl ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\
6073 X86_64_DEF([INDEX_op_shrdq ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,)\
6075 [INDEX_op_cmpxchgb ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,\
6076 [INDEX_op_cmpxchgw ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,\
6077 [INDEX_op_cmpxchgl ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,\
6078 X86_64_DEF([INDEX_op_cmpxchgq ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,)
6083 #ifndef CONFIG_USER_ONLY
6089 /* simpler form of an operation if no flags need to be generated */
6090 static uint16_t opc_simpler
[NB_OPS
] = {
6091 [INDEX_op_update2_cc
] = INDEX_op_nop
,
6092 [INDEX_op_update1_cc
] = INDEX_op_nop
,
6093 [INDEX_op_update_neg_cc
] = INDEX_op_nop
,
6095 /* broken: CC_OP logic must be rewritten */
6096 [INDEX_op_update_inc_cc
] = INDEX_op_nop
,
6099 [INDEX_op_shlb_T0_T1_cc
] = INDEX_op_shlb_T0_T1
,
6100 [INDEX_op_shlw_T0_T1_cc
] = INDEX_op_shlw_T0_T1
,
6101 [INDEX_op_shll_T0_T1_cc
] = INDEX_op_shll_T0_T1
,
6102 X86_64_DEF([INDEX_op_shlq_T0_T1_cc
] = INDEX_op_shlq_T0_T1
,)
6104 [INDEX_op_shrb_T0_T1_cc
] = INDEX_op_shrb_T0_T1
,
6105 [INDEX_op_shrw_T0_T1_cc
] = INDEX_op_shrw_T0_T1
,
6106 [INDEX_op_shrl_T0_T1_cc
] = INDEX_op_shrl_T0_T1
,
6107 X86_64_DEF([INDEX_op_shrq_T0_T1_cc
] = INDEX_op_shrq_T0_T1
,)
6109 [INDEX_op_sarb_T0_T1_cc
] = INDEX_op_sarb_T0_T1
,
6110 [INDEX_op_sarw_T0_T1_cc
] = INDEX_op_sarw_T0_T1
,
6111 [INDEX_op_sarl_T0_T1_cc
] = INDEX_op_sarl_T0_T1
,
6112 X86_64_DEF([INDEX_op_sarq_T0_T1_cc
] = INDEX_op_sarq_T0_T1
,)
6114 #define DEF_SIMPLER(SUFFIX)\
6115 [INDEX_op_rolb ## SUFFIX ## _T0_T1_cc] = INDEX_op_rolb ## SUFFIX ## _T0_T1,\
6116 [INDEX_op_rolw ## SUFFIX ## _T0_T1_cc] = INDEX_op_rolw ## SUFFIX ## _T0_T1,\
6117 [INDEX_op_roll ## SUFFIX ## _T0_T1_cc] = INDEX_op_roll ## SUFFIX ## _T0_T1,\
6118 X86_64_DEF([INDEX_op_rolq ## SUFFIX ## _T0_T1_cc] = INDEX_op_rolq ## SUFFIX ## _T0_T1,)\
6120 [INDEX_op_rorb ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorb ## SUFFIX ## _T0_T1,\
6121 [INDEX_op_rorw ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorw ## SUFFIX ## _T0_T1,\
6122 [INDEX_op_rorl ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorl ## SUFFIX ## _T0_T1,\
6123 X86_64_DEF([INDEX_op_rorq ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorq ## SUFFIX ## _T0_T1,)
6127 #ifndef CONFIG_USER_ONLY
6128 DEF_SIMPLER(_kernel
)
6133 void optimize_flags_init(void)
6136 /* put default values in arrays */
6137 for(i
= 0; i
< NB_OPS
; i
++) {
6138 if (opc_simpler
[i
] == 0)
6143 /* CPU flags computation optimization: we move backward thru the
6144 generated code to see which flags are needed. The operation is
6145 modified if suitable */
6146 static void optimize_flags(uint16_t *opc_buf
, int opc_buf_len
)
6149 int live_flags
, write_flags
, op
;
6151 opc_ptr
= opc_buf
+ opc_buf_len
;
6152 /* live_flags contains the flags needed by the next instructions
6153 in the code. At the end of the bloc, we consider that all the
6155 live_flags
= CC_OSZAPC
;
6156 while (opc_ptr
> opc_buf
) {
6158 /* if none of the flags written by the instruction is used,
6159 then we can try to find a simpler instruction */
6160 write_flags
= opc_write_flags
[op
];
6161 if ((live_flags
& write_flags
) == 0) {
6162 *opc_ptr
= opc_simpler
[op
];
6164 /* compute the live flags before the instruction */
6165 live_flags
&= ~write_flags
;
6166 live_flags
|= opc_read_flags
[op
];
6170 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
6171 basic block 'tb'. If search_pc is TRUE, also generate PC
6172 information for each intermediate instruction. */
6173 static inline int gen_intermediate_code_internal(CPUState
*env
,
6174 TranslationBlock
*tb
,
6177 DisasContext dc1
, *dc
= &dc1
;
6178 target_ulong pc_ptr
;
6179 uint16_t *gen_opc_end
;
6180 int flags
, j
, lj
, cflags
;
6181 target_ulong pc_start
;
6182 target_ulong cs_base
;
6184 /* generate intermediate code */
6186 cs_base
= tb
->cs_base
;
6188 cflags
= tb
->cflags
;
6190 dc
->pe
= (flags
>> HF_PE_SHIFT
) & 1;
6191 dc
->code32
= (flags
>> HF_CS32_SHIFT
) & 1;
6192 dc
->ss32
= (flags
>> HF_SS32_SHIFT
) & 1;
6193 dc
->addseg
= (flags
>> HF_ADDSEG_SHIFT
) & 1;
6195 dc
->vm86
= (flags
>> VM_SHIFT
) & 1;
6196 dc
->cpl
= (flags
>> HF_CPL_SHIFT
) & 3;
6197 dc
->iopl
= (flags
>> IOPL_SHIFT
) & 3;
6198 dc
->tf
= (flags
>> TF_SHIFT
) & 1;
6199 dc
->singlestep_enabled
= env
->singlestep_enabled
;
6200 dc
->cc_op
= CC_OP_DYNAMIC
;
6201 dc
->cs_base
= cs_base
;
6203 dc
->popl_esp_hack
= 0;
6204 /* select memory access functions */
6206 if (flags
& HF_SOFTMMU_MASK
) {
6208 dc
->mem_index
= 2 * 4;
6210 dc
->mem_index
= 1 * 4;
6212 dc
->cpuid_features
= env
->cpuid_features
;
6213 #ifdef TARGET_X86_64
6214 dc
->lma
= (flags
>> HF_LMA_SHIFT
) & 1;
6215 dc
->code64
= (flags
>> HF_CS64_SHIFT
) & 1;
6218 dc
->jmp_opt
= !(dc
->tf
|| env
->singlestep_enabled
||
6219 (flags
& HF_INHIBIT_IRQ_MASK
)
6220 #ifndef CONFIG_SOFTMMU
6221 || (flags
& HF_SOFTMMU_MASK
)
6225 /* check addseg logic */
6226 if (!dc
->addseg
&& (dc
->vm86
|| !dc
->pe
|| !dc
->code32
))
6227 printf("ERROR addseg\n");
6230 gen_opc_ptr
= gen_opc_buf
;
6231 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6232 gen_opparam_ptr
= gen_opparam_buf
;
6235 dc
->is_jmp
= DISAS_NEXT
;
6240 if (env
->nb_breakpoints
> 0) {
6241 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6242 if (env
->breakpoints
[j
] == pc_ptr
) {
6243 gen_debug(dc
, pc_ptr
- dc
->cs_base
);
6249 j
= gen_opc_ptr
- gen_opc_buf
;
6253 gen_opc_instr_start
[lj
++] = 0;
6255 gen_opc_pc
[lj
] = pc_ptr
;
6256 gen_opc_cc_op
[lj
] = dc
->cc_op
;
6257 gen_opc_instr_start
[lj
] = 1;
6259 pc_ptr
= disas_insn(dc
, pc_ptr
);
6260 /* stop translation if indicated */
6263 /* if single step mode, we generate only one instruction and
6264 generate an exception */
6265 /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
6266 the flag and abort the translation to give the irqs a
6267 change to be happen */
6268 if (dc
->tf
|| dc
->singlestep_enabled
||
6269 (flags
& HF_INHIBIT_IRQ_MASK
) ||
6270 (cflags
& CF_SINGLE_INSN
)) {
6271 gen_jmp_im(pc_ptr
- dc
->cs_base
);
6275 /* if too long translation, stop generation too */
6276 if (gen_opc_ptr
>= gen_opc_end
||
6277 (pc_ptr
- pc_start
) >= (TARGET_PAGE_SIZE
- 32)) {
6278 gen_jmp_im(pc_ptr
- dc
->cs_base
);
6283 *gen_opc_ptr
= INDEX_op_end
;
6284 /* we don't forget to fill the last values */
6286 j
= gen_opc_ptr
- gen_opc_buf
;
6289 gen_opc_instr_start
[lj
++] = 0;
6293 if (loglevel
& CPU_LOG_TB_CPU
) {
6294 cpu_dump_state(env
, logfile
, fprintf
, X86_DUMP_CCOP
);
6296 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6298 fprintf(logfile
, "----------------\n");
6299 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6300 #ifdef TARGET_X86_64
6305 disas_flags
= !dc
->code32
;
6306 target_disas(logfile
, pc_start
, pc_ptr
- pc_start
, disas_flags
);
6307 fprintf(logfile
, "\n");
6308 if (loglevel
& CPU_LOG_TB_OP
) {
6309 fprintf(logfile
, "OP:\n");
6310 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6311 fprintf(logfile
, "\n");
6316 /* optimize flag computations */
6317 optimize_flags(gen_opc_buf
, gen_opc_ptr
- gen_opc_buf
);
6320 if (loglevel
& CPU_LOG_TB_OP_OPT
) {
6321 fprintf(logfile
, "AFTER FLAGS OPT:\n");
6322 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6323 fprintf(logfile
, "\n");
6327 tb
->size
= pc_ptr
- pc_start
;
6331 int gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
6333 return gen_intermediate_code_internal(env
, tb
, 0);
6336 int gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
6338 return gen_intermediate_code_internal(env
, tb
, 1);