translate.c revision 1b64dfcf7b569db9d6b8b2ba464061534abbcd90
/*
* i386 translation
*
* Copyright (c) 2003 Fabrice Bellard
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#ifndef VBOX
#include <signal.h>
#include <assert.h>
#endif /* !VBOX */
#include "cpu.h"
#include "exec-all.h"
#include "disas.h"
/* XXX: move that elsewhere */
static uint16_t *gen_opc_ptr;
static uint32_t *gen_opparam_ptr;
#define PREFIX_REPZ 0x01
#define PREFIX_REPNZ 0x02
#define PREFIX_LOCK 0x04
#define PREFIX_DATA 0x08
#define PREFIX_ADR 0x10
#ifdef TARGET_X86_64
#define X86_64_ONLY(x) x
#define X86_64_DEF(x...) x
#if 1
#endif
#else
#define X86_64_ONLY(x) NULL
#define X86_64_DEF(x...)
#define CODE64(s) 0
#define REX_X(s) 0
#define REX_B(s) 0
#endif
#ifdef TARGET_X86_64
static int x86_64_hregs;
#endif
#ifdef USE_DIRECT_JUMP
#define TBPARAM(x)
#else
#define TBPARAM(x) (long)(x)
#endif
#ifdef VBOX
{
uint8_t b;
return b;
}
#define ldub_code(a) ldub_code_raw(a)
{
}
#define lduw_code(a) lduw_code_raw(a)
{
}
#define ldl_code(a) ldl_code_raw(a)
#endif /* VBOX */
typedef struct DisasContext {
/* current insn context */
int override; /* -1 if no override */
int prefix;
int is_jmp; /* 1 = means jump (stop translation), 2 means CPU
static state change (stop translation) */
/* current block context */
int pe; /* protected mode */
int code32; /* 32 bit code segment */
#ifdef TARGET_X86_64
int lma; /* long mode active */
int code64; /* 64 bit code segment */
#endif
int ss32; /* 32 bit stack segment */
int cc_op; /* current CC operation */
int f_st; /* currently unused */
int vm86; /* vm86 mode */
#ifdef VBOX
int vme; /* CR4.VME */
int record_call; /* record calls for CSAM or not? */
#endif
int cpl;
int iopl;
int tf; /* TF cpu flag */
int singlestep_enabled; /* "hardware" single step enabled */
int jmp_opt; /* use direct block chaining for direct jumps */
int mem_index; /* select memory access functions */
int flags; /* all execution flags */
struct TranslationBlock *tb;
int popl_esp_hack; /* for correct popl with esp base handling */
int rip_offset; /* only used in x86_64, but left for simplicity */
int cpuid_features;
int cpuid_ext_features;
} DisasContext;
static void gen_eob(DisasContext *s);
enum {
};
/* i386 shift ops */
enum {
OP_SHL1, /* undocumented */
OP_SAR = 7,
};
enum {
#include "opc.h"
};
#include "gen-op.h"
/* operand size */
enum {
OT_BYTE = 0,
};
enum {
/* I386 int registers */
OR_EAX, /* MUST be even numbered */
OR_A0, /* temporary register used when doing address evaluation */
};
#ifdef TARGET_X86_64
#define NB_OP_SIZES 4
\
{ \
if (x86_64_hregs) \
else \
} \
\
{ \
if (x86_64_hregs) \
else \
} \
\
{ \
if (x86_64_hregs) \
else \
} \
\
{ \
if (x86_64_hregs) \
else \
}
#else /* !TARGET_X86_64 */
#define NB_OP_SIZES 3
#endif /* !TARGET_X86_64 */
[OT_BYTE] = {
#ifdef TARGET_X86_64
#else
#endif
},
[OT_WORD] = {
},
[OT_LONG] = {
},
#ifdef TARGET_X86_64
[OT_QUAD] = {
},
#endif
};
[OT_BYTE] = {
#ifdef TARGET_X86_64
#else
#endif
},
[OT_WORD] = {
},
[OT_LONG] = {
},
#ifdef TARGET_X86_64
[OT_QUAD] = {
},
#endif
};
[0] = {
},
[1] = {
},
#ifdef TARGET_X86_64
[2] = {
},
#endif
};
{
[OT_BYTE] = {
{
#ifdef TARGET_X86_64
#else
#endif
},
{
#ifdef TARGET_X86_64
#else
#endif
},
},
[OT_WORD] = {
{
},
{
},
},
[OT_LONG] = {
{
},
{
},
},
#ifdef TARGET_X86_64
[OT_QUAD] = {
{
},
{
},
},
#endif
};
};
[0] = {
},
[1] = {
},
[2] = {
},
[3] = {
},
};
#ifdef TARGET_X86_64
};
[0] = {
},
[1] = {
},
[2] = {
},
[3] = {
},
};
#endif
[0] = {
},
[1] = {
},
#ifdef TARGET_X86_64
[2] = {
},
#endif
};
NULL,
NULL,
NULL,
NULL,
NULL,
};
#define DEF_ARITHC(SUFFIX)\
{\
},\
{\
},\
{\
},\
{\
},
DEF_ARITHC( )
};
#ifndef CONFIG_USER_ONLY
#endif
};
static const int cc_op_arithb[8] = {
};
#define DEF_CMPXCHG(SUFFIX)\
DEF_CMPXCHG( )
};
#ifndef CONFIG_USER_ONLY
#endif
};
{\
},\
{\
},\
{\
},\
{\
},
DEF_SHIFT( )
};
#ifndef CONFIG_USER_ONLY
#endif
};
{\
NULL,\
NULL,\
},\
{\
},\
{\
},\
{\
},
DEF_SHIFTD(, im)
};
DEF_SHIFTD(, ECX)
};
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
[0] = {
},
[1] = {
},
#ifdef TARGET_X86_64
[2] = {
},
#endif
};
};
[0] = {
},
[1] = {
},
#ifdef TARGET_X86_64
[2] = {
},
#endif
};
NULL,
#ifndef CONFIG_USER_ONLY
NULL,
NULL,
#endif
};
NULL,
NULL,
#ifndef CONFIG_USER_ONLY
NULL,
NULL,
NULL,
NULL,
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
NULL,
#ifndef CONFIG_USER_ONLY
NULL,
NULL,
#endif
};
#ifdef VBOX
static void gen_check_external_event()
{
}
{
#ifdef TARGET_X86_64
} else {
}
#else
#endif
}
#endif /* VBOX */
{
#ifdef VBOX
#endif /* VBOX */
#ifdef TARGET_X86_64
} else {
}
#else
#endif
}
static inline void gen_string_movl_A0_ESI(DisasContext *s)
{
int override;
#ifdef TARGET_X86_64
if (s->aflag == 2) {
if (override >= 0) {
gen_op_addq_A0_reg_sN[0][R_ESI]();
} else {
}
} else
#endif
if (s->aflag) {
/* 32 bit address */
if (override >= 0) {
gen_op_addl_A0_reg_sN[0][R_ESI]();
} else {
}
} else {
/* 16 address, always override */
if (override < 0)
}
}
static inline void gen_string_movl_A0_EDI(DisasContext *s)
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
if (s->addseg) {
gen_op_addl_A0_reg_sN[0][R_EDI]();
} else {
}
} else {
}
}
};
};
};
};
{
},
{
},
};
};
};
};
};
};
};
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
if (use_dx)
gen_check_io_DX[ot]();
else
gen_check_io_T0[ot]();
}
}
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
static inline void gen_update_cc_op(DisasContext *s)
{
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
}
/* XXX: does not work with gdbstub "ice" single step - not a
serious problem */
{
l1 = gen_new_label();
l2 = gen_new_label();
return l2;
}
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
{
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
{
gen_op_in_DX_T0[ot]();
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
{
gen_op_out_DX_T0[ot]();
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
if (s->aflag) {
} else {
}
}
/* same method as Valgrind : we generate jumps to current or next
instruction */
{ \
int l2;\
gen_update_cc_op(s); \
gen_op_dec_ECX[s->aflag](); \
/* a loop would cause two single step exceptions if ECX = 1 \
before rep string_insn */ \
if (!s->jmp_opt) \
}
int nz) \
{ \
int l2;\
gen_update_cc_op(s); \
gen_op_dec_ECX[s->aflag](); \
if (!s->jmp_opt) \
}
enum {
};
[OT_BYTE] = {
NULL,
NULL,
},
[OT_WORD] = {
NULL,
NULL,
},
[OT_LONG] = {
NULL,
NULL,
},
#ifdef TARGET_X86_64
[OT_QUAD] = {
NULL,
NULL,
},
#endif
};
[0] = {
},
[1] = {
},
#ifdef TARGET_X86_64
[2] = {
},
#endif
};
};
[OT_BYTE] = {
NULL,
NULL,
},
[OT_WORD] = {
NULL,
NULL,
},
[OT_LONG] = {
NULL,
NULL,
},
#ifdef TARGET_X86_64
[OT_QUAD] = {
NULL,
NULL,
},
#endif
};
};
/* NOTE the exception in "r" op ordering */
NULL,
NULL,
};
/* if d == OR_TMP0, it means memory operand (address in A0) */
{
if (d != OR_TMP0) {
gen_op_mov_TN_reg[ot][0][d]();
} else {
}
switch(op) {
case OP_ADCL:
case OP_SBBL:
if (d != OR_TMP0) {
gen_op_mov_reg_T0[ot][d]();
} else {
}
goto the_end;
case OP_ADDL:
break;
case OP_SUBL:
break;
default:
case OP_ANDL:
case OP_ORL:
case OP_XORL:
break;
case OP_CMPL:
break;
}
if (d != OR_TMP0)
gen_op_mov_reg_T0[ot][d]();
else
}
/* the flags update must happen after the memory write (precise
exception support) */
if (gen_update_cc)
the_end: ;
}
/* if d == OR_TMP0, it means memory operand (address in A0) */
{
if (d != OR_TMP0)
gen_op_mov_TN_reg[ot][0][d]();
else
if (c > 0) {
} else {
}
if (d != OR_TMP0)
gen_op_mov_reg_T0[ot][d]();
else
}
{
if (d != OR_TMP0)
gen_op_mov_TN_reg[ot][0][d]();
else
if (s != OR_TMP1)
/* for zero counts, flags are not updated, so must do it dynamically */
if (d != OR_TMP0)
else
if (d != OR_TMP0)
gen_op_mov_reg_T0[ot][d]();
}
{
/* currently not optimized */
}
{
int havesib;
int base;
int index;
int scale;
int opreg;
must_add_seg = s->addseg;
if (override >= 0)
must_add_seg = 1;
if (s->aflag) {
havesib = 0;
index = 0;
scale = 0;
if (base == 4) {
havesib = 1;
}
switch (mod) {
case 0:
base = -1;
s->pc += 4;
}
} else {
disp = 0;
}
break;
case 1:
break;
default:
case 2:
s->pc += 4;
break;
}
if (base >= 0) {
/* for correct popl handling with esp */
disp += s->popl_esp_hack;
#ifdef TARGET_X86_64
if (s->aflag == 2) {
if (disp != 0) {
else
}
} else
#endif
{
if (disp != 0)
}
} else {
#ifdef TARGET_X86_64
if (s->aflag == 2) {
else
} else
#endif
{
}
}
/* XXX: index == 4 is always invalid */
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
{
}
}
if (must_add_seg) {
if (override < 0) {
else
}
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
{
}
}
} else {
switch (mod) {
case 0:
if (rm == 6) {
s->pc += 2;
rm = 0; /* avoid SS override */
goto no_rm;
} else {
disp = 0;
}
break;
case 1:
break;
default:
case 2:
s->pc += 2;
break;
}
switch(rm) {
case 0:
gen_op_addl_A0_reg_sN[0][R_ESI]();
break;
case 1:
gen_op_addl_A0_reg_sN[0][R_EDI]();
break;
case 2:
gen_op_addl_A0_reg_sN[0][R_ESI]();
break;
case 3:
gen_op_addl_A0_reg_sN[0][R_EDI]();
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
case 7:
break;
}
if (disp != 0)
if (must_add_seg) {
if (override < 0) {
else
}
}
}
disp = 0;
*offset_ptr = disp;
}
{
if (mod == 3)
return;
if (s->aflag) {
if (base == 4) {
}
switch (mod) {
case 0:
if (base == 5) {
s->pc += 4;
}
break;
case 1:
s->pc++;
break;
default:
case 2:
s->pc += 4;
break;
}
} else {
switch (mod) {
case 0:
if (rm == 6) {
s->pc += 2;
}
break;
case 1:
s->pc++;
break;
default:
case 2:
s->pc += 2;
break;
}
}
}
/* used for LEA and MOV AX, mem */
static void gen_add_A0_ds_seg(DisasContext *s)
{
int override, must_add_seg;
must_add_seg = s->addseg;
if (s->override >= 0) {
must_add_seg = 1;
} else {
}
if (must_add_seg) {
#ifdef TARGET_X86_64
if (CODE64(s)) {
} else
#endif
{
}
}
}
/* generate modrm memory load or store of 'reg'. TMP0 is used if reg !=
OR_TMP0 */
{
if (mod == 3) {
if (is_store) {
} else {
}
} else {
if (is_store) {
} else {
}
}
}
{
switch(ot) {
case OT_BYTE:
s->pc++;
break;
case OT_WORD:
s->pc += 2;
break;
default:
case OT_LONG:
s->pc += 4;
break;
}
return ret;
}
static inline int insn_const_size(unsigned int ot)
{
return 1 << ot;
else
return 4;
}
{
/* NOTE: we handle the case where the TB spans two pages here */
/* jump to same page: we can use a direct jump */
if (tb_num == 0)
else
} else {
/* jump to another page: currently not optimized */
gen_eob(s);
}
}
static inline void gen_jcc(DisasContext *s, int b,
{
inv = b & 1;
if (s->jmp_opt) {
#ifdef VBOX
#endif /* VBOX */
switch(s->cc_op) {
case CC_OP_SUBB:
case CC_OP_SUBW:
case CC_OP_SUBL:
case CC_OP_SUBQ:
break;
/* some jumps are easy to compute */
case CC_OP_ADDB:
case CC_OP_ADDW:
case CC_OP_ADDL:
case CC_OP_ADDQ:
case CC_OP_ADCB:
case CC_OP_ADCW:
case CC_OP_ADCL:
case CC_OP_ADCQ:
case CC_OP_SBBB:
case CC_OP_SBBW:
case CC_OP_SBBL:
case CC_OP_SBBQ:
case CC_OP_LOGICB:
case CC_OP_LOGICW:
case CC_OP_LOGICL:
case CC_OP_LOGICQ:
case CC_OP_INCB:
case CC_OP_INCW:
case CC_OP_INCL:
case CC_OP_INCQ:
case CC_OP_DECB:
case CC_OP_DECW:
case CC_OP_DECL:
case CC_OP_DECQ:
case CC_OP_SHLB:
case CC_OP_SHLW:
case CC_OP_SHLL:
case CC_OP_SHLQ:
case CC_OP_SARB:
case CC_OP_SARW:
case CC_OP_SARL:
case CC_OP_SARQ:
switch(jcc_op) {
case JCC_Z:
break;
case JCC_S:
break;
default:
break;
}
break;
default:
break;
}
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
if (!func) {
gen_setcc_slow[jcc_op]();
}
if (inv) {
}
l1 = gen_new_label();
gen_goto_tb(s, 0, next_eip);
s->is_jmp = 3;
} else {
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_setcc_slow[jcc_op]();
if (inv) {
}
l1 = gen_new_label();
l2 = gen_new_label();
gen_eob(s);
}
}
static void gen_setcc(DisasContext *s, int b)
{
inv = b & 1;
switch(s->cc_op) {
case CC_OP_SUBB:
case CC_OP_SUBW:
case CC_OP_SUBL:
case CC_OP_SUBQ:
if (!func)
goto slow_jcc;
break;
/* some jumps are easy to compute */
case CC_OP_ADDB:
case CC_OP_ADDW:
case CC_OP_ADDL:
case CC_OP_ADDQ:
case CC_OP_LOGICB:
case CC_OP_LOGICW:
case CC_OP_LOGICL:
case CC_OP_LOGICQ:
case CC_OP_INCB:
case CC_OP_INCW:
case CC_OP_INCL:
case CC_OP_INCQ:
case CC_OP_DECB:
case CC_OP_DECW:
case CC_OP_DECL:
case CC_OP_DECQ:
case CC_OP_SHLB:
case CC_OP_SHLW:
case CC_OP_SHLL:
case CC_OP_SHLQ:
switch(jcc_op) {
case JCC_Z:
break;
case JCC_S:
break;
default:
goto slow_jcc;
}
break;
default:
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
break;
}
func();
if (inv) {
}
}
/* move T0 to seg_reg and compute if the CPU state may change. Never
call this function with seg_reg == R_CS */
{
/* XXX: optimize by finding processor state dynamically */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
/* abort translation because the addseg value may change or
because ss32 may change. For R_SS, translation must always
stop as a special handling must be done to disable hardware
interrupts for the next instruction */
s->is_jmp = 3;
} else {
s->is_jmp = 3;
}
}
{
#ifdef TARGET_X86_64
if (CODE64(s)) {
if (addend == 8)
else
} else
#endif
if (s->ss32) {
if (addend == 2)
else if (addend == 4)
else
} else {
if (addend == 2)
else if (addend == 4)
else
}
}
/* generate a push. It depends on ss32, addseg and dflag */
static void gen_push_T0(DisasContext *s)
{
#ifdef TARGET_X86_64
if (CODE64(s)) {
if (s->dflag) {
} else {
}
} else
#endif
{
if (!s->dflag)
else
if (s->ss32) {
if (s->addseg) {
}
} else {
}
else
}
}
/* generate a push. It depends on ss32, addseg and dflag */
/* slower version for T1, only used for call Ev */
static void gen_push_T1(DisasContext *s)
{
#ifdef TARGET_X86_64
if (CODE64(s)) {
if (s->dflag) {
} else {
}
} else
#endif
{
if (!s->dflag)
else
if (s->ss32) {
if (s->addseg) {
}
} else {
}
else
}
}
/* two step pop is necessary for precise exceptions */
static void gen_pop_T0(DisasContext *s)
{
#ifdef TARGET_X86_64
if (CODE64(s)) {
} else
#endif
{
if (s->ss32) {
if (s->addseg)
} else {
}
}
}
static void gen_pop_update(DisasContext *s)
{
#ifdef TARGET_X86_64
gen_stack_update(s, 8);
} else
#endif
{
}
}
static void gen_stack_A0(DisasContext *s)
{
if (!s->ss32)
if (s->addseg)
}
/* NOTE: wrap around in 16 bit not fully handled */
static void gen_pusha(DisasContext *s)
{
int i;
if (!s->ss32)
if (s->addseg)
for(i = 0;i < 8; i++) {
}
}
/* NOTE: wrap around in 16 bit not fully handled */
static void gen_popa(DisasContext *s)
{
int i;
if (!s->ss32)
if (s->addseg)
for(i = 0;i < 8; i++) {
/* ESP is not reloaded */
if (i != 3) {
}
}
}
{
level &= 0x1f;
#ifdef TARGET_X86_64
if (CODE64(s)) {
/* push bp */
if (level) {
}
} else
#endif
{
if (!s->ss32)
if (s->addseg)
/* push bp */
if (level) {
}
}
}
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->is_jmp = 3;
}
/* an interrupt is different from an exception because of the
priviledge checks */
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->is_jmp = 3;
}
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_debug();
s->is_jmp = 3;
}
/* generate a generic end of block. Trace exception is also generated
if needed */
static void gen_eob(DisasContext *s)
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
}
if (s->singlestep_enabled) {
gen_op_debug();
} else if (s->tf) {
} else {
}
s->is_jmp = 3;
}
/* generate a jump to eip. No segment change must happen before as a
direct call to the next block may occur */
{
if (s->jmp_opt) {
#ifdef VBOX
#endif /* VBOX */
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
s->is_jmp = 3;
} else {
gen_eob(s);
}
}
{
gen_jmp_tb(s, eip, 0);
}
{
#ifdef TARGET_X86_64
} else {
}
#else
#endif
}
{
#ifdef TARGET_X86_64
} else {
}
#else
#endif
}
{
#ifdef TARGET_X86_64
if (CODE64(s))
else
#endif
}
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
#ifndef CONFIG_USER_ONLY
#endif
};
/* pure SSE operations */
[0x12] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movlps, movlpd, movsldup, movddup */
[0x2a] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */
[0x2c] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */
[0x2d] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */
/* MMX ops and their SSE extensions */
(GenOpFunc2 *)gen_op_pshuflw_xmm },
};
};
};
};
{
b &= 0xff;
if (s->prefix & PREFIX_DATA)
b1 = 1;
else if (s->prefix & PREFIX_REPZ)
b1 = 2;
else if (s->prefix & PREFIX_REPNZ)
b1 = 3;
else
b1 = 0;
if (!sse_op2)
goto illegal_op;
if (b <= 0x5f || b == 0xc6 || b == 0xc2) {
is_xmm = 1;
} else {
if (b1 == 0) {
/* MMX case */
is_xmm = 0;
} else {
is_xmm = 1;
}
}
if (s->flags & HF_TS_MASK) {
return;
}
if (s->flags & HF_EM_MASK) {
return;
}
goto illegal_op;
if (b == 0x77) {
/* emms */
gen_op_emms();
return;
}
/* prepare MMX state (XXX: optimize by storing fptt and fptags in
the static cpu state) */
if (!is_xmm) {
}
if (is_xmm)
if (sse_op2 == SSE_SPECIAL) {
b |= (b1 << 8);
switch(b) {
case 0x0e7: /* movntq */
if (mod == 3)
goto illegal_op;
break;
case 0x1e7: /* movntdq */
case 0x02b: /* movntps */
case 0x12b: /* movntps */
case 0x3f0: /* lddqu */
if (mod == 3)
goto illegal_op;
break;
case 0x6e: /* movd mm, ea */
#ifdef TARGET_X86_64
if (s->dflag == 2) {
} else
#endif
{
}
break;
case 0x16e: /* movd xmm, ea */
#ifdef TARGET_X86_64
if (s->dflag == 2) {
} else
#endif
{
}
break;
case 0x6f: /* movq mm, ea */
if (mod != 3) {
} else {
}
break;
case 0x010: /* movups */
case 0x110: /* movupd */
case 0x028: /* movaps */
case 0x128: /* movapd */
case 0x16f: /* movdqa xmm, ea */
case 0x26f: /* movdqu xmm, ea */
if (mod != 3) {
} else {
}
break;
case 0x210: /* movss xmm, ea */
if (mod != 3) {
} else {
}
break;
case 0x310: /* movsd xmm, ea */
if (mod != 3) {
} else {
}
break;
case 0x012: /* movlps */
case 0x112: /* movlpd */
if (mod != 3) {
} else {
/* movhlps */
}
break;
case 0x212: /* movsldup */
if (mod != 3) {
} else {
}
break;
case 0x312: /* movddup */
if (mod != 3) {
} else {
}
break;
case 0x016: /* movhps */
case 0x116: /* movhpd */
if (mod != 3) {
} else {
/* movlhps */
}
break;
case 0x216: /* movshdup */
if (mod != 3) {
} else {
}
break;
case 0x7e: /* movd ea, mm */
#ifdef TARGET_X86_64
if (s->dflag == 2) {
} else
#endif
{
}
break;
case 0x17e: /* movd ea, xmm */
#ifdef TARGET_X86_64
if (s->dflag == 2) {
} else
#endif
{
}
break;
case 0x27e: /* movq xmm, ea */
if (mod != 3) {
} else {
}
break;
case 0x7f: /* movq ea, mm */
if (mod != 3) {
} else {
}
break;
case 0x011: /* movups */
case 0x111: /* movupd */
case 0x029: /* movaps */
case 0x129: /* movapd */
case 0x17f: /* movdqa ea, xmm */
case 0x27f: /* movdqu ea, xmm */
if (mod != 3) {
} else {
}
break;
case 0x211: /* movss ea, xmm */
if (mod != 3) {
} else {
}
break;
case 0x311: /* movsd ea, xmm */
if (mod != 3) {
} else {
}
break;
case 0x013: /* movlps */
case 0x113: /* movlpd */
if (mod != 3) {
} else {
goto illegal_op;
}
break;
case 0x017: /* movhps */
case 0x117: /* movhpd */
if (mod != 3) {
} else {
goto illegal_op;
}
break;
case 0x71: /* shift mm, im */
case 0x72:
case 0x73:
case 0x171: /* shift xmm, im */
case 0x172:
case 0x173:
if (is_xmm) {
} else {
}
if (!sse_op2)
goto illegal_op;
if (is_xmm) {
} else {
}
break;
case 0x050: /* movmskps */
break;
case 0x150: /* movmskpd */
break;
case 0x02a: /* cvtpi2ps */
case 0x12a: /* cvtpi2pd */
if (mod != 3) {
} else {
}
switch(b >> 8) {
case 0x0:
break;
default:
case 0x1:
break;
}
break;
case 0x22a: /* cvtsi2ss */
case 0x32a: /* cvtsi2sd */
break;
case 0x02c: /* cvttps2pi */
case 0x12c: /* cvttpd2pi */
case 0x02d: /* cvtps2pi */
case 0x12d: /* cvtpd2pi */
if (mod != 3) {
} else {
}
switch(b) {
case 0x02c:
break;
case 0x12c:
break;
case 0x02d:
break;
case 0x12d:
break;
}
break;
case 0x22c: /* cvttss2si */
case 0x32c: /* cvttsd2si */
case 0x22d: /* cvtss2si */
case 0x32d: /* cvtsd2si */
if (mod != 3) {
if ((b >> 8) & 1) {
} else {
}
} else {
}
break;
case 0xc4: /* pinsrw */
case 0x1c4:
s->rip_offset = 1;
if (b1) {
val &= 7;
} else {
val &= 3;
}
break;
case 0xc5: /* pextrw */
case 0x1c5:
if (mod != 3)
goto illegal_op;
if (b1) {
val &= 7;
} else {
val &= 3;
}
break;
case 0x1d6: /* movq ea, xmm */
if (mod != 3) {
} else {
}
break;
case 0x2d6: /* movq2dq */
break;
case 0x3d6: /* movdq2q */
break;
case 0xd7: /* pmovmskb */
case 0x1d7:
if (mod != 3)
goto illegal_op;
if (b1) {
} else {
}
break;
default:
goto illegal_op;
}
} else {
/* generic MMX or SSE operation */
switch(b) {
case 0xf7:
/* maskmov : we must prepare A0 */
if (mod != 3)
goto illegal_op;
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
{
if (s->aflag == 0)
}
break;
case 0x70: /* pshufx insn */
case 0xc6: /* pshufx insn */
case 0xc2: /* compare insns */
s->rip_offset = 1;
break;
default:
break;
}
if (is_xmm) {
if (mod != 3) {
b == 0xc2)) {
/* specific case for SSE single instructions */
if (b1 == 2) {
/* 32 bit access */
} else {
/* 64 bit access */
}
} else {
}
} else {
}
} else {
if (mod != 3) {
} else {
}
}
switch(b) {
case 0x70: /* pshufx insn */
case 0xc6: /* pshufx insn */
break;
case 0xc2:
/* compare insns */
if (val >= 8)
goto illegal_op;
break;
default:
break;
}
if (b == 0x2e || b == 0x2f) {
s->cc_op = CC_OP_EFLAGS;
}
}
}
/* convert one instruction. s->is_jmp is set if the translation must
be stopped. Return the next pc value */
{
prefixes = 0;
s->override = -1;
rex_w = -1;
rex_r = 0;
#ifdef TARGET_X86_64
s->rex_x = 0;
s->rex_b = 0;
x86_64_hregs = 0;
#endif
s->rip_offset = 0; /* for relative ip address */
#ifdef VBOX
/* Always update EIP. Otherwise one must be very careful with generated code that can raise exceptions. */
#endif
s->pc++;
/* check prefixes */
#ifdef TARGET_X86_64
if (CODE64(s)) {
switch (b) {
case 0xf3:
prefixes |= PREFIX_REPZ;
goto next_byte;
case 0xf2:
prefixes |= PREFIX_REPNZ;
goto next_byte;
case 0xf0:
prefixes |= PREFIX_LOCK;
goto next_byte;
case 0x2e:
goto next_byte;
case 0x36:
goto next_byte;
case 0x3e:
goto next_byte;
case 0x26:
goto next_byte;
case 0x64:
goto next_byte;
case 0x65:
goto next_byte;
case 0x66:
prefixes |= PREFIX_DATA;
goto next_byte;
case 0x67:
prefixes |= PREFIX_ADR;
goto next_byte;
case 0x40 ... 0x4f:
/* REX prefix */
goto next_byte;
}
if (rex_w == 1) {
/* 0x66 is ignored if rex.w is set */
dflag = 2;
} else {
if (prefixes & PREFIX_DATA)
dflag ^= 1;
}
if (!(prefixes & PREFIX_ADR))
aflag = 2;
} else
#endif
{
switch (b) {
case 0xf3:
prefixes |= PREFIX_REPZ;
goto next_byte;
case 0xf2:
prefixes |= PREFIX_REPNZ;
goto next_byte;
case 0xf0:
prefixes |= PREFIX_LOCK;
goto next_byte;
case 0x2e:
goto next_byte;
case 0x36:
goto next_byte;
case 0x3e:
goto next_byte;
case 0x26:
goto next_byte;
case 0x64:
goto next_byte;
case 0x65:
goto next_byte;
case 0x66:
prefixes |= PREFIX_DATA;
goto next_byte;
case 0x67:
prefixes |= PREFIX_ADR;
goto next_byte;
}
if (prefixes & PREFIX_DATA)
dflag ^= 1;
if (prefixes & PREFIX_ADR)
aflag ^= 1;
}
/* lock generation */
if (prefixes & PREFIX_LOCK)
gen_op_lock();
/* now check op code */
switch(b) {
case 0x0f:
/**************************/
/* extended op code */
goto reswitch;
/**************************/
/* arith & logic */
case 0x00 ... 0x05:
case 0x08 ... 0x0d:
case 0x10 ... 0x15:
case 0x18 ... 0x1d:
case 0x20 ... 0x25:
case 0x28 ... 0x2d:
case 0x30 ... 0x35:
case 0x38 ... 0x3d:
{
f = (b >> 1) & 3;
if ((b & 1) == 0)
else
switch(f) {
case 0: /* OP Ev, Gv */
if (mod != 3) {
/* xor reg, reg optimisation */
break;
} else {
}
break;
case 1: /* OP Gv, Ev */
if (mod != 3) {
goto xor_zero;
} else {
}
break;
case 2: /* OP A, Iv */
break;
}
}
break;
case 0x80: /* GRP1 */
case 0x81:
case 0x82:
case 0x83:
{
int val;
if ((b & 1) == 0)
else
if (mod != 3) {
if (b == 0x83)
s->rip_offset = 1;
else
} else {
}
switch(b) {
default:
case 0x80:
case 0x81:
case 0x82:
break;
case 0x83:
break;
}
}
break;
/**************************/
/* inc, dec, and other misc arith */
case 0x40 ... 0x47: /* inc Gv */
break;
case 0x48 ... 0x4f: /* dec Gv */
break;
case 0xf6: /* GRP3 */
case 0xf7:
if ((b & 1) == 0)
else
if (mod != 3) {
if (op == 0)
} else {
}
switch(op) {
case 0: /* test */
break;
case 2: /* not */
if (mod != 3) {
} else {
}
break;
case 3: /* neg */
if (mod != 3) {
} else {
}
break;
case 4: /* mul */
switch(ot) {
case OT_BYTE:
s->cc_op = CC_OP_MULB;
break;
case OT_WORD:
s->cc_op = CC_OP_MULW;
break;
default:
case OT_LONG:
s->cc_op = CC_OP_MULL;
break;
#ifdef TARGET_X86_64
case OT_QUAD:
s->cc_op = CC_OP_MULQ;
break;
#endif
}
break;
case 5: /* imul */
switch(ot) {
case OT_BYTE:
s->cc_op = CC_OP_MULB;
break;
case OT_WORD:
s->cc_op = CC_OP_MULW;
break;
default:
case OT_LONG:
s->cc_op = CC_OP_MULL;
break;
#ifdef TARGET_X86_64
case OT_QUAD:
s->cc_op = CC_OP_MULQ;
break;
#endif
}
break;
case 6: /* div */
switch(ot) {
case OT_BYTE:
break;
case OT_WORD:
break;
default:
case OT_LONG:
break;
#ifdef TARGET_X86_64
case OT_QUAD:
break;
#endif
}
break;
case 7: /* idiv */
switch(ot) {
case OT_BYTE:
break;
case OT_WORD:
break;
default:
case OT_LONG:
break;
#ifdef TARGET_X86_64
case OT_QUAD:
break;
#endif
}
break;
default:
goto illegal_op;
}
break;
case 0xfe: /* GRP4 */
case 0xff: /* GRP5 */
if ((b & 1) == 0)
else
goto illegal_op;
}
if (CODE64(s)) {
/* operand size for jumps is 64 bit */
/* for call calls, the operand is 16 or 32 bit, even
in long mode */
} else if (op == 6) {
/* default push size is 64 bit */
}
}
if (mod != 3) {
} else {
}
switch(op) {
case 0: /* inc Ev */
if (mod != 3)
else
break;
case 1: /* dec Ev */
if (mod != 3)
else
break;
case 2: /* call Ev */
/* XXX: optimize if memory (no 'and' is necessary) */
#ifdef VBOX_WITH_CALL_RECORD
if (s->record_call)
#endif
if (s->dflag == 0)
gen_push_T1(s);
gen_eob(s);
break;
case 3: /* lcall Ev */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
} else {
}
gen_eob(s);
break;
case 4: /* jmp Ev */
if (s->dflag == 0)
gen_eob(s);
break;
case 5: /* ljmp Ev */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
} else {
}
gen_eob(s);
break;
case 6: /* push Ev */
gen_push_T0(s);
break;
default:
goto illegal_op;
}
break;
case 0x84: /* test Ev, Gv */
case 0x85:
if ((b & 1) == 0)
else
break;
case 0xa8: /* test eAX, Iv */
case 0xa9:
if ((b & 1) == 0)
else
break;
#ifdef TARGET_X86_64
if (dflag == 2) {
} else
#endif
if (dflag == 1)
else
break;
#ifdef TARGET_X86_64
if (dflag == 2) {
} else
#endif
if (dflag == 1)
else
break;
case 0x1af: /* imul Gv, Ev */
case 0x69: /* imul Gv, Ev, I */
case 0x6b:
if (b == 0x69)
else if (b == 0x6b)
s->rip_offset = 1;
if (b == 0x69) {
} else if (b == 0x6b) {
} else {
}
#ifdef TARGET_X86_64
} else
#endif
} else {
}
break;
case 0x1c0:
case 0x1c1: /* xadd Ev, Gv */
if ((b & 1) == 0)
else
if (mod == 3) {
} else {
}
break;
case 0x1b0:
case 0x1b1: /* cmpxchg Ev, Gv */
if ((b & 1) == 0)
else
if (mod == 3) {
} else {
}
break;
case 0x1c7: /* cmpxchg8b */
if (mod == 3)
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_EFLAGS;
break;
/**************************/
case 0x50 ... 0x57: /* push */
gen_push_T0(s);
break;
case 0x58 ... 0x5f: /* pop */
if (CODE64(s)) {
} else {
}
gen_pop_T0(s);
/* NOTE: order is important for pop %sp */
gen_pop_update(s);
break;
case 0x60: /* pusha */
if (CODE64(s))
goto illegal_op;
gen_pusha(s);
break;
case 0x61: /* popa */
if (CODE64(s))
goto illegal_op;
gen_popa(s);
break;
case 0x68: /* push Iv */
case 0x6a:
if (CODE64(s)) {
} else {
}
if (b == 0x68)
else
gen_push_T0(s);
break;
case 0x8f: /* pop Ev */
if (CODE64(s)) {
} else {
}
gen_pop_T0(s);
if (mod == 3) {
/* NOTE: order is important for pop %sp */
gen_pop_update(s);
} else {
/* NOTE: order is important too for MMU exceptions */
s->popl_esp_hack = 0;
gen_pop_update(s);
}
break;
case 0xc8: /* enter */
{
int level;
s->pc += 2;
}
break;
case 0xc9: /* leave */
/* XXX: exception not precise (ESP is updated before potential exception) */
if (CODE64(s)) {
} else if (s->ss32) {
} else {
}
gen_pop_T0(s);
if (CODE64(s)) {
} else {
}
gen_pop_update(s);
break;
case 0x06: /* push es */
case 0x0e: /* push cs */
case 0x16: /* push ss */
case 0x1e: /* push ds */
if (CODE64(s))
goto illegal_op;
gen_op_movl_T0_seg(b >> 3);
gen_push_T0(s);
break;
case 0x1a0: /* push fs */
case 0x1a8: /* push gs */
gen_push_T0(s);
break;
case 0x07: /* pop es */
case 0x17: /* pop ss */
case 0x1f: /* pop ds */
if (CODE64(s))
goto illegal_op;
reg = b >> 3;
gen_pop_T0(s);
gen_pop_update(s);
/* if reg == SS, inhibit interrupts/trace. */
/* If several instructions disable interrupts, only the
_first_ does it */
s->tf = 0;
}
if (s->is_jmp) {
gen_eob(s);
}
break;
case 0x1a1: /* pop fs */
case 0x1a9: /* pop gs */
gen_pop_T0(s);
gen_pop_update(s);
if (s->is_jmp) {
gen_eob(s);
}
break;
/**************************/
/* mov */
case 0x88:
case 0x89: /* mov Gv, Ev */
if ((b & 1) == 0)
else
/* generate a generic store */
break;
case 0xc6:
case 0xc7: /* mov Ev, Iv */
if ((b & 1) == 0)
else
if (mod != 3) {
}
if (mod != 3)
else
break;
case 0x8a:
case 0x8b: /* mov Ev, Gv */
if ((b & 1) == 0)
else
break;
case 0x8e: /* mov seg, Gv */
goto illegal_op;
/* if reg == SS, inhibit interrupts/trace */
/* If several instructions disable interrupts, only the
_first_ does it */
s->tf = 0;
}
if (s->is_jmp) {
gen_eob(s);
}
break;
case 0x8c: /* mov Gv, seg */
if (reg >= 6)
goto illegal_op;
if (mod == 3)
else
break;
case 0x1b6: /* movzbS Gv, Eb */
case 0x1b7: /* movzwS Gv, Eb */
case 0x1be: /* movsbS Gv, Eb */
case 0x1bf: /* movswS Gv, Eb */
{
int d_ot;
/* d_ot is the size of destination */
/* ot is the size of source */
if (mod == 3) {
switch(ot | (b & 8)) {
case OT_BYTE:
break;
case OT_BYTE | 8:
break;
case OT_WORD:
break;
default:
case OT_WORD | 8:
break;
}
} else {
if (b & 8) {
} else {
}
}
}
break;
case 0x8d: /* lea */
if (mod == 3)
goto illegal_op;
/* we must ensure that no segment is added */
s->override = -1;
s->addseg = 0;
break;
case 0xa0: /* mov EAX, Ov */
case 0xa1:
case 0xa2: /* mov Ov, EAX */
case 0xa3:
{
if ((b & 1) == 0)
else
#ifdef TARGET_X86_64
if (s->aflag == 2) {
s->pc += 8;
else
} else
#endif
{
if (s->aflag) {
} else {
}
}
if ((b & 2) == 0) {
} else {
}
}
break;
case 0xd7: /* xlat */
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
{
if (s->aflag == 0)
}
break;
case 0xb0 ... 0xb7: /* mov R, Ib */
break;
case 0xb8 ... 0xbf: /* mov R, Iv */
#ifdef TARGET_X86_64
if (dflag == 2) {
/* 64 bit case */
s->pc += 8;
} else
#endif
{
}
break;
case 0x91 ... 0x97: /* xchg R, EAX */
goto do_xchg_reg;
case 0x86:
case 0x87: /* xchg Ev, Gv */
if ((b & 1) == 0)
else
if (mod == 3) {
} else {
/* for xchg, lock is implicit */
if (!(prefixes & PREFIX_LOCK))
gen_op_lock();
if (!(prefixes & PREFIX_LOCK))
}
break;
case 0xc4: /* les Gv */
if (CODE64(s))
goto illegal_op;
goto do_lxx;
case 0xc5: /* lds Gv */
if (CODE64(s))
goto illegal_op;
goto do_lxx;
case 0x1b2: /* lss Gv */
goto do_lxx;
case 0x1b4: /* lfs Gv */
goto do_lxx;
case 0x1b5: /* lgs Gv */
if (mod == 3)
goto illegal_op;
/* load the segment first to handle exceptions properly */
/* then put the data */
if (s->is_jmp) {
gen_eob(s);
}
break;
/************************/
/* shifts */
case 0xc0:
case 0xc1:
/* shift Ev,Ib */
shift = 2;
grp2:
{
if ((b & 1) == 0)
else
if (mod != 3) {
if (shift == 2) {
s->rip_offset = 1;
}
} else {
}
/* simpler op */
if (shift == 0) {
} else {
if (shift == 2) {
}
}
}
break;
case 0xd0:
case 0xd1:
/* shift Ev,1 */
shift = 1;
goto grp2;
case 0xd2:
case 0xd3:
/* shift Ev,cl */
shift = 0;
goto grp2;
case 0x1a4: /* shld imm */
op = 0;
shift = 1;
goto do_shiftd;
case 0x1a5: /* shld cl */
op = 0;
shift = 0;
goto do_shiftd;
case 0x1ac: /* shrd imm */
op = 1;
shift = 1;
goto do_shiftd;
case 0x1ad: /* shrd cl */
op = 1;
shift = 0;
if (mod != 3) {
} else {
}
if (shift) {
val &= 0x3f;
else
val &= 0x1f;
if (val) {
if (mod == 3)
else
else
}
} else {
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
if (mod == 3)
else
}
if (mod == 3) {
}
break;
/************************/
/* floats */
case 0xd8 ... 0xdf:
/* if CR0.EM or CR0.TS are set, generate an FPU exception */
/* XXX: what to do if illegal op ? */
break;
}
if (mod != 3) {
/* memory op */
switch(op) {
case 0x00 ... 0x07: /* fxxxs */
case 0x10 ... 0x17: /* fixxxl */
case 0x20 ... 0x27: /* fxxxl */
case 0x30 ... 0x37: /* fixxx */
{
int op1;
switch(op >> 4) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
default:
break;
}
if (op1 == 3) {
/* fcomp needs pop */
gen_op_fpop();
}
}
break;
case 0x08: /* flds */
case 0x0a: /* fsts */
case 0x0b: /* fstps */
case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */
case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */
case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */
switch(op & 7) {
case 0:
switch(op >> 4) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
default:
break;
}
break;
case 1:
switch(op >> 4) {
case 1:
break;
case 2:
break;
case 3:
default:
}
gen_op_fpop();
break;
default:
switch(op >> 4) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
default:
break;
}
gen_op_fpop();
break;
}
break;
case 0x0c: /* fldenv mem */
gen_op_fldenv_A0(s->dflag);
break;
case 0x0d: /* fldcw mem */
break;
case 0x0e: /* fnstenv mem */
gen_op_fnstenv_A0(s->dflag);
break;
case 0x0f: /* fnstcw mem */
break;
case 0x1d: /* fldt mem */
break;
case 0x1f: /* fstpt mem */
gen_op_fpop();
break;
case 0x2c: /* frstor mem */
gen_op_frstor_A0(s->dflag);
break;
case 0x2e: /* fnsave mem */
gen_op_fnsave_A0(s->dflag);
break;
case 0x2f: /* fnstsw mem */
break;
case 0x3c: /* fbld */
break;
case 0x3e: /* fbstp */
gen_op_fpop();
break;
case 0x3d: /* fildll */
break;
case 0x3f: /* fistpll */
gen_op_fpop();
break;
default:
goto illegal_op;
}
} else {
/* register float ops */
switch(op) {
case 0x08: /* fld sti */
gen_op_fpush();
break;
case 0x09: /* fxchg sti */
case 0x29: /* fxchg4 sti, undocumented op */
case 0x39: /* fxchg7 sti, undocumented op */
break;
case 0x0a: /* grp d9/2 */
switch(rm) {
case 0: /* fnop */
/* check exceptions (FreeBSD FPU probe) */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_fwait();
break;
default:
goto illegal_op;
}
break;
case 0x0c: /* grp d9/4 */
switch(rm) {
case 0: /* fchs */
break;
case 1: /* fabs */
break;
case 4: /* ftst */
break;
case 5: /* fxam */
break;
default:
goto illegal_op;
}
break;
case 0x0d: /* grp d9/5 */
{
switch(rm) {
case 0:
gen_op_fpush();
break;
case 1:
gen_op_fpush();
break;
case 2:
gen_op_fpush();
break;
case 3:
gen_op_fpush();
break;
case 4:
gen_op_fpush();
break;
case 5:
gen_op_fpush();
break;
case 6:
gen_op_fpush();
break;
default:
goto illegal_op;
}
}
break;
case 0x0e: /* grp d9/6 */
switch(rm) {
case 0: /* f2xm1 */
gen_op_f2xm1();
break;
case 1: /* fyl2x */
gen_op_fyl2x();
break;
case 2: /* fptan */
gen_op_fptan();
break;
case 3: /* fpatan */
break;
case 4: /* fxtract */
break;
case 5: /* fprem1 */
break;
case 6: /* fdecstp */
break;
default:
case 7: /* fincstp */
break;
}
break;
case 0x0f: /* grp d9/7 */
switch(rm) {
case 0: /* fprem */
gen_op_fprem();
break;
case 1: /* fyl2xp1 */
break;
case 2: /* fsqrt */
gen_op_fsqrt();
break;
case 3: /* fsincos */
break;
case 5: /* fscale */
break;
case 4: /* frndint */
break;
case 6: /* fsin */
gen_op_fsin();
break;
default:
case 7: /* fcos */
gen_op_fcos();
break;
}
break;
case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */
case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */
case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */
{
int op1;
if (op >= 0x20) {
if (op >= 0x30)
gen_op_fpop();
} else {
}
}
break;
case 0x02: /* fcom */
case 0x22: /* fcom2, undocumented op */
break;
case 0x03: /* fcomp */
case 0x23: /* fcomp3, undocumented op */
case 0x32: /* fcomp5, undocumented op */
gen_op_fpop();
break;
case 0x15: /* da/5 */
switch(rm) {
case 1: /* fucompp */
gen_op_fpop();
gen_op_fpop();
break;
default:
goto illegal_op;
}
break;
case 0x1c:
switch(rm) {
case 0: /* feni (287 only, just do nop here) */
break;
case 1: /* fdisi (287 only, just do nop here) */
break;
case 2: /* fclex */
gen_op_fclex();
break;
case 3: /* fninit */
break;
case 4: /* fsetpm (287 only, just do nop here) */
break;
default:
goto illegal_op;
}
break;
case 0x1d: /* fucomi */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_EFLAGS;
break;
case 0x1e: /* fcomi */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_EFLAGS;
break;
case 0x28: /* ffree sti */
break;
case 0x2a: /* fst sti */
break;
case 0x2b: /* fstp sti */
case 0x0b: /* fstp1 sti, undocumented op */
case 0x3a: /* fstp8 sti, undocumented op */
case 0x3b: /* fstp9 sti, undocumented op */
gen_op_fpop();
break;
case 0x2c: /* fucom st(i) */
break;
case 0x2d: /* fucomp st(i) */
gen_op_fpop();
break;
case 0x33: /* de/3 */
switch(rm) {
case 1: /* fcompp */
gen_op_fpop();
gen_op_fpop();
break;
default:
goto illegal_op;
}
break;
case 0x38: /* ffreep sti, undocumented op */
gen_op_fpop();
break;
case 0x3c: /* df/4 */
switch(rm) {
case 0:
break;
default:
goto illegal_op;
}
break;
case 0x3d: /* fucomip */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_fpop();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x3e: /* fcomip */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_fpop();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x10 ... 0x13: /* fcmovxx */
case 0x18 ... 0x1b:
{
int op1;
(JCC_B << 1),
(JCC_Z << 1),
(JCC_BE << 1),
(JCC_P << 1),
};
}
break;
default:
goto illegal_op;
}
}
#ifdef USE_CODE_COPY
#endif
break;
/************************/
/* string ops */
case 0xa4: /* movsS */
case 0xa5:
if ((b & 1) == 0)
else
} else {
}
break;
case 0xaa: /* stosS */
case 0xab:
if ((b & 1) == 0)
else
} else {
}
break;
case 0xac: /* lodsS */
case 0xad:
if ((b & 1) == 0)
else
} else {
}
break;
case 0xae: /* scasS */
case 0xaf:
if ((b & 1) == 0)
else
if (prefixes & PREFIX_REPNZ) {
} else if (prefixes & PREFIX_REPZ) {
} else {
}
break;
case 0xa6: /* cmpsS */
case 0xa7:
if ((b & 1) == 0)
else
if (prefixes & PREFIX_REPNZ) {
} else if (prefixes & PREFIX_REPZ) {
} else {
}
break;
case 0x6c: /* insS */
case 0x6d:
if ((b & 1) == 0)
else
} else {
}
break;
case 0x6e: /* outsS */
case 0x6f:
if ((b & 1) == 0)
else
} else {
}
break;
/************************/
/* port I/O */
case 0xe4:
case 0xe5:
if ((b & 1) == 0)
else
break;
case 0xe6:
case 0xe7:
if ((b & 1) == 0)
else
#ifdef VBOX /* bird: linux is writing to this port for delaying I/O. */
if (val == 0x80)
break;
#endif /* VBOX */
gen_op_out[ot]();
break;
case 0xec:
case 0xed:
if ((b & 1) == 0)
else
break;
case 0xee:
case 0xef:
if ((b & 1) == 0)
else
gen_op_out[ot]();
break;
/************************/
/* control */
case 0xc2: /* ret im */
s->pc += 2;
gen_pop_T0(s);
s->dflag = 2;
if (s->dflag == 0)
gen_eob(s);
break;
case 0xc3: /* ret */
gen_pop_T0(s);
gen_pop_update(s);
if (s->dflag == 0)
gen_eob(s);
break;
case 0xca: /* lret im */
s->pc += 2;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
} else {
gen_stack_A0(s);
/* pop offset */
if (s->dflag == 0)
/* NOTE: keeping EIP updated is not a problem in case of
exception */
/* pop selector */
/* add stack offset */
}
gen_eob(s);
break;
case 0xcb: /* lret */
val = 0;
goto do_lret;
case 0xcf: /* iret */
if (!s->pe) {
/* real mode */
gen_op_iret_real(s->dflag);
s->cc_op = CC_OP_EFLAGS;
} else if (s->vm86) {
#ifdef VBOX
#else
if (s->iopl != 3) {
#endif
} else {
gen_op_iret_real(s->dflag);
s->cc_op = CC_OP_EFLAGS;
}
} else {
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_EFLAGS;
}
gen_eob(s);
break;
case 0xe8: /* call im */
{
if (dflag)
else
if (s->dflag == 0)
tval &= 0xffff;
gen_push_T0(s);
}
break;
case 0x9a: /* lcall im */
{
if (CODE64(s))
goto illegal_op;
}
goto do_lcall;
case 0xe9: /* jmp im */
if (dflag)
else
if (s->dflag == 0)
tval &= 0xffff;
break;
case 0xea: /* ljmp im */
{
if (CODE64(s))
goto illegal_op;
}
goto do_ljmp;
case 0xeb: /* jmp Jb */
if (s->dflag == 0)
tval &= 0xffff;
break;
case 0x70 ... 0x7f: /* jcc Jb */
goto do_jcc;
case 0x180 ... 0x18f: /* jcc Jv */
if (dflag) {
} else {
}
if (s->dflag == 0)
tval &= 0xffff;
break;
case 0x190 ... 0x19f: /* setcc Gv */
gen_setcc(s, b);
break;
case 0x140 ... 0x14f: /* cmov Gv, Ev */
gen_setcc(s, b);
if (mod != 3) {
} else {
}
break;
/************************/
/* flags */
case 0x9c: /* pushf */
#ifdef VBOX
#else
#endif
} else {
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
#ifdef VBOX
else
#endif
gen_push_T0(s);
}
break;
case 0x9d: /* popf */
#ifdef VBOX
#else
#endif
} else {
gen_pop_T0(s);
if (s->cpl == 0) {
if (s->dflag) {
} else {
}
} else {
if (s->dflag) {
} else {
}
} else {
if (s->dflag) {
} else {
#ifdef VBOX
else
#endif
}
}
}
gen_pop_update(s);
s->cc_op = CC_OP_EFLAGS;
/* abort translation because TF flag may change */
gen_eob(s);
}
break;
case 0x9e: /* sahf */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_EFLAGS;
break;
case 0x9f: /* lahf */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
break;
case 0xf5: /* cmc */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_cmc();
s->cc_op = CC_OP_EFLAGS;
break;
case 0xf8: /* clc */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_clc();
s->cc_op = CC_OP_EFLAGS;
break;
case 0xf9: /* stc */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_stc();
s->cc_op = CC_OP_EFLAGS;
break;
case 0xfc: /* cld */
gen_op_cld();
break;
case 0xfd: /* std */
gen_op_std();
break;
/************************/
/* bit operations */
if (mod != 3) {
s->rip_offset = 1;
} else {
}
/* load shift */
if (op < 4)
goto illegal_op;
op -= 4;
if (op != 0) {
if (mod != 3)
else
}
break;
case 0x1a3: /* bt Gv, Ev */
op = 0;
goto do_btx;
case 0x1ab: /* bts */
op = 1;
goto do_btx;
case 0x1b3: /* btr */
op = 2;
goto do_btx;
case 0x1bb: /* btc */
op = 3;
if (mod != 3) {
/* specific case: we need to add a displacement */
} else {
}
if (op != 0) {
if (mod != 3)
else
}
break;
case 0x1bc: /* bsf */
case 0x1bd: /* bsr */
/* NOTE: in order to handle the 0 case, we must load the
result. It could be optimized with a generated jump */
break;
/************************/
/* bcd */
case 0x27: /* daa */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_daa();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x2f: /* das */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_das();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x37: /* aaa */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_aaa();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x3f: /* aas */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_aas();
s->cc_op = CC_OP_EFLAGS;
break;
case 0xd4: /* aam */
if (CODE64(s))
goto illegal_op;
if (val == 0) {
} else {
s->cc_op = CC_OP_LOGICB;
}
break;
case 0xd5: /* aad */
if (CODE64(s))
goto illegal_op;
s->cc_op = CC_OP_LOGICB;
break;
/************************/
/* misc */
case 0x90: /* nop */
/* XXX: xchg + rex handling */
/* XXX: correct lock test for all insn */
if (prefixes & PREFIX_LOCK)
goto illegal_op;
break;
case 0x9b: /* fwait */
(HF_MP_MASK | HF_TS_MASK)) {
} else {
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_fwait();
}
break;
case 0xcc: /* int3 */
#ifdef VBOX
} else
#endif
break;
case 0xcd: /* int N */
#ifdef VBOX
#else
#endif
} else {
}
break;
case 0xce: /* into */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
break;
case 0xf1: /* icebp (undocumented, exits to external debugger) */
#if 1
#else
/* start debug */
#endif
break;
case 0xfa: /* cli */
if (!s->vm86) {
gen_op_cli();
} else {
}
} else {
if (s->iopl == 3) {
gen_op_cli();
#ifdef VBOX
#endif
} else {
}
}
break;
case 0xfb: /* sti */
if (!s->vm86) {
gen_op_sti();
/* interruptions are enabled only the first insn after sti */
/* If several instructions disable interrupts, only the
_first_ does it */
/* give a chance to handle pending irqs */
gen_eob(s);
} else {
}
} else {
if (s->iopl == 3) {
goto gen_sti;
#ifdef VBOX
/* give a chance to handle pending irqs */
gen_eob(s);
#endif
} else {
}
}
break;
case 0x62: /* bound */
if (CODE64(s))
goto illegal_op;
if (mod == 3)
goto illegal_op;
else
break;
case 0x1c8 ... 0x1cf: /* bswap reg */
#ifdef TARGET_X86_64
if (dflag == 2) {
} else
#endif
{
}
break;
case 0xd6: /* salc */
if (CODE64(s))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_salc();
break;
case 0xe0: /* loopnz */
case 0xe1: /* loopz */
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
/* FALL THRU */
case 0xe2: /* loop */
case 0xe3: /* jecxz */
{
if (s->dflag == 0)
tval &= 0xffff;
l1 = gen_new_label();
l2 = gen_new_label();
b &= 3;
if (b == 3) {
} else {
gen_op_dec_ECX[s->aflag]();
if (b <= 1)
}
gen_eob(s);
}
break;
case 0x130: /* wrmsr */
case 0x132: /* rdmsr */
if (s->cpl != 0) {
} else {
if (b & 2)
gen_op_rdmsr();
else
gen_op_wrmsr();
}
break;
case 0x131: /* rdtsc */
gen_op_rdtsc();
break;
case 0x134: /* sysenter */
if (CODE64(s))
goto illegal_op;
if (!s->pe) {
} else {
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_eob(s);
}
break;
case 0x135: /* sysexit */
if (CODE64(s))
goto illegal_op;
if (!s->pe) {
} else {
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_eob(s);
}
break;
#ifdef TARGET_X86_64
case 0x105: /* syscall */
/* XXX: is it usable in real mode ? */
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_eob(s);
break;
case 0x107: /* sysret */
if (!s->pe) {
} else {
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_op_sysret(s->dflag);
/* condition codes are modified only in long mode */
if (s->lma)
s->cc_op = CC_OP_EFLAGS;
gen_eob(s);
}
break;
#endif
case 0x1a2: /* cpuid */
gen_op_cpuid();
break;
case 0xf4: /* hlt */
if (s->cpl != 0) {
} else {
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_hlt();
s->is_jmp = 3;
}
break;
case 0x100:
switch(op) {
case 0: /* sldt */
goto illegal_op;
if (mod == 3)
break;
case 2: /* lldt */
goto illegal_op;
if (s->cpl != 0) {
} else {
}
break;
case 1: /* str */
goto illegal_op;
if (mod == 3)
break;
case 3: /* ltr */
goto illegal_op;
if (s->cpl != 0) {
} else {
}
break;
case 4: /* verr */
case 5: /* verw */
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
if (op == 4)
gen_op_verr();
else
gen_op_verw();
s->cc_op = CC_OP_EFLAGS;
break;
default:
goto illegal_op;
}
break;
case 0x101:
switch(op) {
case 0: /* sgdt */
if (mod == 3)
goto illegal_op;
gen_add_A0_im(s, 2);
if (!s->dflag)
gen_op_andl_T0_im(0xffffff);
break;
case 1:
if (mod == 3) {
switch (rm) {
case 0: /* monitor */
if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
s->cpl != 0)
goto illegal_op;
#ifdef TARGET_X86_64
if (s->aflag == 2) {
} else
#endif
{
if (s->aflag == 0)
}
break;
case 1: /* mwait */
if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
s->cpl != 0)
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_op_mwait();
gen_eob(s);
break;
default:
goto illegal_op;
}
} else { /* sidt */
gen_add_A0_im(s, 2);
if (!s->dflag)
gen_op_andl_T0_im(0xffffff);
}
break;
case 2: /* lgdt */
case 3: /* lidt */
if (mod == 3)
goto illegal_op;
if (s->cpl != 0) {
} else {
gen_add_A0_im(s, 2);
if (!s->dflag)
gen_op_andl_T0_im(0xffffff);
if (op == 2) {
} else {
}
}
break;
case 4: /* smsw */
break;
case 6: /* lmsw */
if (s->cpl != 0) {
} else {
gen_eob(s);
}
break;
case 7: /* invlpg */
if (s->cpl != 0) {
} else {
if (mod == 3) {
#ifdef TARGET_X86_64
/* swapgs */
} else
#endif
{
goto illegal_op;
}
} else {
gen_eob(s);
}
}
break;
default:
goto illegal_op;
}
break;
case 0x108: /* invd */
case 0x109: /* wbinvd */
if (s->cpl != 0) {
} else {
/* nothing to do */
}
break;
case 0x63: /* arpl or movslS (x86_64) */
#ifdef TARGET_X86_64
if (CODE64(s)) {
int d_ot;
/* d_ot is the size of destination */
if (mod == 3) {
/* sign extend */
} else {
} else {
}
}
} else
#endif
{
goto illegal_op;
#ifdef VBOX /* Fix for obvious bug - T1 needs to be loaded */
#endif
if (mod != 3) {
} else {
}
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
gen_op_arpl();
s->cc_op = CC_OP_EFLAGS;
if (mod != 3) {
} else {
}
}
break;
case 0x102: /* lar */
case 0x103: /* lsl */
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
if (b == 0x102)
gen_op_lar();
else
gen_op_lsl();
s->cc_op = CC_OP_EFLAGS;
break;
case 0x118:
switch(op) {
case 0: /* prefetchnta */
case 1: /* prefetchnt0 */
case 2: /* prefetchnt0 */
case 3: /* prefetchnt0 */
if (mod == 3)
goto illegal_op;
/* nothing more to do */
break;
default: /* nop (multi byte) */
gen_nop_modrm(s, modrm);
break;
}
break;
case 0x119 ... 0x11f: /* nop (multi byte) */
gen_nop_modrm(s, modrm);
break;
case 0x120: /* mov reg, crN */
case 0x122: /* mov crN, reg */
if (s->cpl != 0) {
} else {
goto illegal_op;
if (CODE64(s))
else
switch(reg) {
case 0:
case 2:
case 3:
case 4:
case 8:
if (b & 2) {
gen_eob(s);
} else {
#if !defined(CONFIG_USER_ONLY)
if (reg == 8)
else
#endif
}
break;
default:
goto illegal_op;
}
}
break;
case 0x121: /* mov reg, drN */
case 0x123: /* mov drN, reg */
if (s->cpl != 0) {
} else {
goto illegal_op;
if (CODE64(s))
else
/* XXX: do it dynamically with CR4.DE bit */
goto illegal_op;
if (b & 2) {
gen_eob(s);
} else {
}
}
break;
case 0x106: /* clts */
if (s->cpl != 0) {
} else {
gen_op_clts();
/* abort block because static cpu state changed */
gen_eob(s);
}
break;
case 0x1c3: /* MOVNTI reg, mem */
if (!(s->cpuid_features & CPUID_SSE2))
goto illegal_op;
if (mod == 3)
goto illegal_op;
/* generate a generic store */
break;
case 0x1ae:
switch(op) {
case 0: /* fxsave */
(s->flags & HF_EM_MASK))
goto illegal_op;
if (s->flags & HF_TS_MASK) {
break;
}
break;
case 1: /* fxrstor */
(s->flags & HF_EM_MASK))
goto illegal_op;
if (s->flags & HF_TS_MASK) {
break;
}
break;
case 2: /* ldmxcsr */
case 3: /* stmxcsr */
if (s->flags & HF_TS_MASK) {
break;
}
mod == 3)
goto illegal_op;
if (op == 2) {
} else {
}
break;
case 5: /* lfence */
case 6: /* mfence */
goto illegal_op;
break;
case 7: /* sfence / clflush */
/* sfence */
if (!(s->cpuid_features & CPUID_SSE))
goto illegal_op;
} else {
/* clflush */
if (!(s->cpuid_features & CPUID_CLFLUSH))
goto illegal_op;
}
break;
default:
goto illegal_op;
}
break;
case 0x10d: /* prefetch */
/* ignore for now */
break;
case 0x1aa: /* rsm */
if (!(s->flags & HF_SMM_MASK))
goto illegal_op;
if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
s->cc_op = CC_OP_DYNAMIC;
}
gen_op_rsm();
gen_eob(s);
break;
case 0x110 ... 0x117:
case 0x128 ... 0x12f:
case 0x150 ... 0x177:
case 0x17c ... 0x17f:
case 0x1c2:
case 0x1c4 ... 0x1c6:
case 0x1d0 ... 0x1fe:
break;
default:
goto illegal_op;
}
/* lock generation */
if (s->prefix & PREFIX_LOCK)
return s->pc;
if (s->prefix & PREFIX_LOCK)
/* XXX: ensure that no lock was generated */
return s->pc;
}
/* flags read by an operation */
[INDEX_op_aas] = CC_A,
[INDEX_op_aaa] = CC_A,
[INDEX_op_into] = CC_O,
[INDEX_op_jb_subb] = CC_C,
[INDEX_op_jb_subw] = CC_C,
[INDEX_op_jb_subl] = CC_C,
[INDEX_op_jz_subb] = CC_Z,
[INDEX_op_jz_subw] = CC_Z,
[INDEX_op_jz_subl] = CC_Z,
[INDEX_op_js_subb] = CC_S,
[INDEX_op_js_subw] = CC_S,
[INDEX_op_js_subl] = CC_S,
[INDEX_op_loopnzw] = CC_Z,
[INDEX_op_loopnzl] = CC_Z,
[INDEX_op_loopzw] = CC_Z,
[INDEX_op_loopzl] = CC_Z,
[INDEX_op_seto_T0_cc] = CC_O,
[INDEX_op_setb_T0_cc] = CC_C,
[INDEX_op_setz_T0_cc] = CC_Z,
[INDEX_op_sets_T0_cc] = CC_S,
[INDEX_op_setp_T0_cc] = CC_P,
[INDEX_op_cmc] = CC_C,
[INDEX_op_salc] = CC_C,
/* needed for correct flag optimisation before string ops */
#ifdef TARGET_X86_64
[INDEX_op_jb_subq] = CC_C,
[INDEX_op_jz_subq] = CC_Z,
[INDEX_op_js_subq] = CC_S,
[INDEX_op_loopnzq] = CC_Z,
[INDEX_op_loopzq] = CC_Z,
#endif
\
DEF_READF( )
#ifndef CONFIG_USER_ONLY
#endif
};
/* flags written by an operation */
/* sse */
[INDEX_op_comiss] = CC_OSZAPC,
[INDEX_op_comisd] = CC_OSZAPC,
/* bcd */
[INDEX_op_aam] = CC_OSZAPC,
[INDEX_op_aad] = CC_OSZAPC,
[INDEX_op_aas] = CC_OSZAPC,
[INDEX_op_aaa] = CC_OSZAPC,
[INDEX_op_das] = CC_OSZAPC,
[INDEX_op_daa] = CC_OSZAPC,
[INDEX_op_clc] = CC_C,
[INDEX_op_stc] = CC_C,
[INDEX_op_cmc] = CC_C,
[INDEX_op_cmpxchg8b] = CC_Z,
[INDEX_op_lar] = CC_Z,
[INDEX_op_lsl] = CC_Z,
[INDEX_op_verr] = CC_Z,
[INDEX_op_verw] = CC_Z,
#define DEF_WRITEF(SUFFIX)\
\
\
\
\
\
\
\
\
DEF_WRITEF( )
#ifndef CONFIG_USER_ONLY
#endif
};
/* simpler form of an operation if no flags need to be generated */
#if 0
/* broken: CC_OP logic must be rewritten */
#endif
#define DEF_SIMPLER(SUFFIX)\
\
DEF_SIMPLER( )
#ifndef CONFIG_USER_ONLY
#endif
};
void optimize_flags_init(void)
{
int i;
/* put default values in arrays */
for(i = 0; i < NB_OPS; i++) {
if (opc_simpler[i] == 0)
opc_simpler[i] = i;
}
}
/* CPU flags computation optimization: we move backward thru the
generated code to see which flags are needed. The operation is
modified if suitable */
{
/* live_flags contains the flags needed by the next instructions
in the code. At the end of the bloc, we consider that all the
flags are live. */
/* if none of the flags written by the instruction is used,
then we can try to find a simpler instruction */
if ((live_flags & write_flags) == 0) {
}
/* compute the live flags before the instruction */
live_flags &= ~write_flags;
}
}
/* generate intermediate code in gen_opc_buf and gen_opparam_buf for
basic block 'tb'. If search_pc is TRUE, also generate PC
information for each intermediate instruction. */
int search_pc)
{
/* generate intermediate code */
#ifdef VBOX_WITH_CALL_RECORD
else
dc->record_call = 0;
#endif
dc->popl_esp_hack = 0;
/* select memory access functions */
if (flags & HF_SOFTMMU_MASK) {
else
}
#ifdef TARGET_X86_64
#endif
#ifndef CONFIG_SOFTMMU
|| (flags & HF_SOFTMMU_MASK)
#endif
);
#if 0
/* check addseg logic */
printf("ERROR addseg\n");
#endif
nb_gen_labels = 0;
lj = -1;
for(;;) {
if (env->nb_breakpoints > 0) {
for(j = 0; j < env->nb_breakpoints; j++) {
break;
}
}
}
if (search_pc) {
j = gen_opc_ptr - gen_opc_buf;
if (lj < j) {
lj++;
while (lj < j)
gen_opc_instr_start[lj++] = 0;
}
}
/* stop translation if indicated */
break;
#ifdef VBOX
#ifdef DEBUG
/*
if(cpu_check_code_raw(env, pc_ptr, env->hflags | (env->eflags & (IOPL_MASK | TF_MASK | VM_MASK))) == ERROR_SUCCESS)
{
//should never happen as the jump to the patch code terminates the translation block
dprintf(("QEmu is about to execute instructions in our patch block at %08X!!\n", pc_ptr));
}
*/
#endif
{
break;
}
#endif /* VBOX */
/* if single step mode, we generate only one instruction and
generate an exception */
/* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
the flag and abort the translation to give the irqs a
change to be happen */
(flags & HF_INHIBIT_IRQ_MASK) ||
(cflags & CF_SINGLE_INSN)) {
break;
}
/* if too long translation, stop generation too */
if (gen_opc_ptr >= gen_opc_end ||
break;
}
}
/* we don't forget to fill the last values */
if (search_pc) {
j = gen_opc_ptr - gen_opc_buf;
lj++;
while (lj <= j)
gen_opc_instr_start[lj++] = 0;
}
#ifdef DEBUG_DISAS
if (loglevel & CPU_LOG_TB_CPU) {
}
if (loglevel & CPU_LOG_TB_IN_ASM) {
int disas_flags;
#ifdef TARGET_X86_64
disas_flags = 2;
else
#endif
if (loglevel & CPU_LOG_TB_OP) {
}
}
#endif
/* optimize flag computations */
#ifdef DEBUG_DISAS
if (loglevel & CPU_LOG_TB_OP_OPT) {
}
#endif
if (!search_pc)
return 0;
}
{
}
{
}