* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* XXX: must use this define because the soft mmu macros have huge
- register constraints so they cannot be used in any C code. gcc 3.3
- does not seem to be able to handle some constraints in rol
- operations, so we disable it. */
-#if !(__GNUC__ == 3 && __GNUC_MINOR__ == 3)
#define ASM_SOFTMMU
-#endif
#include "exec.h"
/* n must be a constant to be efficient */
-static inline int lshift(int x, int n)
+static inline target_long lshift(target_long x, int n)
{
if (n >= 0)
return x << n;
#undef REG
#undef REGNAME
+#ifdef TARGET_X86_64
+
+#define REG (env->regs[8])
+#define REGNAME _R8
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[9])
+#define REGNAME _R9
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[10])
+#define REGNAME _R10
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[11])
+#define REGNAME _R11
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[12])
+#define REGNAME _R12
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[13])
+#define REGNAME _R13
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[14])
+#define REGNAME _R14
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#define REG (env->regs[15])
+#define REGNAME _R15
+#include "opreg_template.h"
+#undef REG
+#undef REGNAME
+
+#endif
+
/* operations with flags */
/* update flags with T0 and T1 (add/sub case) */
T0 = bswap32(T0);
}
+#ifdef TARGET_X86_64
+void OPPROTO op_bswapq_T0(void)
+{
+ helper_bswapq_T0();
+}
+#endif
+
/* multiply/divide */
/* XXX: add eflags optimizations */
{
unsigned int res;
res = (uint8_t)EAX * (uint8_t)T0;
- EAX = (EAX & 0xffff0000) | res;
+ EAX = (EAX & ~0xffff) | res;
CC_DST = res;
CC_SRC = (res & 0xff00);
}
{
int res;
res = (int8_t)EAX * (int8_t)T0;
- EAX = (EAX & 0xffff0000) | (res & 0xffff);
+ EAX = (EAX & ~0xffff) | (res & 0xffff);
CC_DST = res;
CC_SRC = (res != (int8_t)res);
}
{
unsigned int res;
res = (uint16_t)EAX * (uint16_t)T0;
- EAX = (EAX & 0xffff0000) | (res & 0xffff);
- EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff);
+ EAX = (EAX & ~0xffff) | (res & 0xffff);
+ EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
CC_DST = res;
CC_SRC = res >> 16;
}
{
int res;
res = (int16_t)EAX * (int16_t)T0;
- EAX = (EAX & 0xffff0000) | (res & 0xffff);
- EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff);
+ EAX = (EAX & ~0xffff) | (res & 0xffff);
+ EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
CC_DST = res;
CC_SRC = (res != (int16_t)res);
}
{
uint64_t res;
res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0);
- EAX = res;
- EDX = res >> 32;
- CC_DST = res;
- CC_SRC = res >> 32;
+ EAX = (uint32_t)res;
+ EDX = (uint32_t)(res >> 32);
+ CC_DST = (uint32_t)res;
+ CC_SRC = (uint32_t)(res >> 32);
}
void OPPROTO op_imull_EAX_T0(void)
{
int64_t res;
res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0);
- EAX = res;
- EDX = res >> 32;
+ EAX = (uint32_t)(res);
+ EDX = (uint32_t)(res >> 32);
CC_DST = res;
CC_SRC = (res != (int32_t)res);
}
CC_SRC = (res != (int32_t)res);
}
+#ifdef TARGET_X86_64
+void OPPROTO op_mulq_EAX_T0(void)
+{
+ helper_mulq_EAX_T0();
+}
+
+void OPPROTO op_imulq_EAX_T0(void)
+{
+ helper_imulq_EAX_T0();
+}
+
+void OPPROTO op_imulq_T0_T1(void)
+{
+ helper_imulq_T0_T1();
+}
+#endif
+
/* division, flags are undefined */
-/* XXX: add exceptions for overflow */
void OPPROTO op_divb_AL_T0(void)
{
num = (EAX & 0xffff);
den = (T0 & 0xff);
if (den == 0) {
- EIP = PARAM1;
raise_exception(EXCP00_DIVZ);
}
- q = (num / den) & 0xff;
+ q = (num / den);
+ if (q > 0xff)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xff;
r = (num % den) & 0xff;
- EAX = (EAX & 0xffff0000) | (r << 8) | q;
+ EAX = (EAX & ~0xffff) | (r << 8) | q;
}
void OPPROTO op_idivb_AL_T0(void)
num = (int16_t)EAX;
den = (int8_t)T0;
if (den == 0) {
- EIP = PARAM1;
raise_exception(EXCP00_DIVZ);
}
- q = (num / den) & 0xff;
+ q = (num / den);
+ if (q != (int8_t)q)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xff;
r = (num % den) & 0xff;
- EAX = (EAX & 0xffff0000) | (r << 8) | q;
+ EAX = (EAX & ~0xffff) | (r << 8) | q;
}
void OPPROTO op_divw_AX_T0(void)
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
den = (T0 & 0xffff);
if (den == 0) {
- EIP = PARAM1;
raise_exception(EXCP00_DIVZ);
}
- q = (num / den) & 0xffff;
+ q = (num / den);
+ if (q > 0xffff)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xffff;
r = (num % den) & 0xffff;
- EAX = (EAX & 0xffff0000) | q;
- EDX = (EDX & 0xffff0000) | r;
+ EAX = (EAX & ~0xffff) | q;
+ EDX = (EDX & ~0xffff) | r;
}
void OPPROTO op_idivw_AX_T0(void)
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
den = (int16_t)T0;
if (den == 0) {
- EIP = PARAM1;
raise_exception(EXCP00_DIVZ);
}
- q = (num / den) & 0xffff;
+ q = (num / den);
+ if (q != (int16_t)q)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xffff;
r = (num % den) & 0xffff;
- EAX = (EAX & 0xffff0000) | q;
- EDX = (EDX & 0xffff0000) | r;
+ EAX = (EAX & ~0xffff) | q;
+ EDX = (EDX & ~0xffff) | r;
}
void OPPROTO op_divl_EAX_T0(void)
{
- helper_divl_EAX_T0(PARAM1);
+ helper_divl_EAX_T0();
}
void OPPROTO op_idivl_EAX_T0(void)
{
- helper_idivl_EAX_T0(PARAM1);
+ helper_idivl_EAX_T0();
}
+#ifdef TARGET_X86_64
+void OPPROTO op_divq_EAX_T0(void)
+{
+ helper_divq_EAX_T0();
+}
+
+void OPPROTO op_idivq_EAX_T0(void)
+{
+ helper_idivq_EAX_T0();
+}
+#endif
+
/* constant load & misc op */
+/* XXX: consistent names */
+void OPPROTO op_movl_T0_imu(void)
+{
+ T0 = (uint32_t)PARAM1;
+}
+
void OPPROTO op_movl_T0_im(void)
{
- T0 = PARAM1;
+ T0 = (int32_t)PARAM1;
}
void OPPROTO op_addl_T0_im(void)
T0 = T1;
}
+void OPPROTO op_movl_T1_imu(void)
+{
+ T1 = (uint32_t)PARAM1;
+}
+
void OPPROTO op_movl_T1_im(void)
{
- T1 = PARAM1;
+ T1 = (int32_t)PARAM1;
}
void OPPROTO op_addl_T1_im(void)
void OPPROTO op_movl_A0_im(void)
{
- A0 = PARAM1;
+ A0 = (uint32_t)PARAM1;
}
void OPPROTO op_addl_A0_im(void)
{
- A0 += PARAM1;
+ A0 = (uint32_t)(A0 + PARAM1);
+}
+
+void OPPROTO op_movl_A0_seg(void)
+{
+ A0 = (uint32_t)*(target_ulong *)((char *)env + PARAM1);
+}
+
+void OPPROTO op_addl_A0_seg(void)
+{
+ A0 = (uint32_t)(A0 + *(target_ulong *)((char *)env + PARAM1));
}
void OPPROTO op_addl_A0_AL(void)
{
- A0 += (EAX & 0xff);
+ A0 = (uint32_t)(A0 + (EAX & 0xff));
+}
+
+#ifdef WORDS_BIGENDIAN
+typedef union UREG64 {
+ struct { uint16_t v3, v2, v1, v0; } w;
+ struct { uint32_t v1, v0; } l;
+ uint64_t q;
+} UREG64;
+#else
+typedef union UREG64 {
+ struct { uint16_t v0, v1, v2, v3; } w;
+ struct { uint32_t v0, v1; } l;
+ uint64_t q;
+} UREG64;
+#endif
+
+#ifdef TARGET_X86_64
+
+#define PARAMQ1 \
+({\
+ UREG64 __p;\
+ __p.l.v1 = PARAM1;\
+ __p.l.v0 = PARAM2;\
+ __p.q;\
+})
+
+void OPPROTO op_movq_T0_im64(void)
+{
+ T0 = PARAMQ1;
+}
+
+void OPPROTO op_movq_T1_im64(void)
+{
+ T1 = PARAMQ1;
+}
+
+void OPPROTO op_movq_A0_im(void)
+{
+ A0 = (int32_t)PARAM1;
+}
+
+void OPPROTO op_movq_A0_im64(void)
+{
+ A0 = PARAMQ1;
+}
+
+void OPPROTO op_addq_A0_im(void)
+{
+ A0 = (A0 + (int32_t)PARAM1);
+}
+
+void OPPROTO op_addq_A0_im64(void)
+{
+ A0 = (A0 + PARAMQ1);
+}
+
+void OPPROTO op_movq_A0_seg(void)
+{
+ A0 = *(target_ulong *)((char *)env + PARAM1);
+}
+
+void OPPROTO op_addq_A0_seg(void)
+{
+ A0 += *(target_ulong *)((char *)env + PARAM1);
}
+void OPPROTO op_addq_A0_AL(void)
+{
+ A0 = (A0 + (EAX & 0xff));
+}
+
+#endif
+
void OPPROTO op_andl_A0_ffff(void)
{
A0 = A0 & 0xffff;
#include "ops_mem.h"
#endif
-/* used for bit operations */
+/* indirect jump */
-void OPPROTO op_add_bitw_A0_T1(void)
+void OPPROTO op_jmp_T0(void)
{
- A0 += ((int16_t)T1 >> 4) << 1;
+ EIP = T0;
}
-void OPPROTO op_add_bitl_A0_T1(void)
+void OPPROTO op_movl_eip_im(void)
{
- A0 += ((int32_t)T1 >> 5) << 2;
+ EIP = (uint32_t)PARAM1;
}
-/* indirect jump */
-
-void OPPROTO op_jmp_T0(void)
+#ifdef TARGET_X86_64
+void OPPROTO op_movq_eip_im(void)
{
- EIP = T0;
+ EIP = (int32_t)PARAM1;
}
-void OPPROTO op_jmp_im(void)
+void OPPROTO op_movq_eip_im64(void)
{
- EIP = PARAM1;
+ EIP = PARAMQ1;
}
+#endif
void OPPROTO op_hlt(void)
{
+ env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
+ env->hflags |= HF_HALTED_MASK;
env->exception_index = EXCP_HLT;
cpu_loop_exit();
}
void OPPROTO op_raise_interrupt(void)
{
- int intno;
- unsigned int next_eip;
+ int intno, next_eip_addend;
intno = PARAM1;
- next_eip = PARAM2;
- raise_interrupt(intno, 1, 0, next_eip);
+ next_eip_addend = PARAM2;
+ raise_interrupt(intno, 1, 0, next_eip_addend);
}
void OPPROTO op_raise_exception(void)
void OPPROTO op_boundw(void)
{
int low, high, v;
- low = ldsw((uint8_t *)A0);
- high = ldsw((uint8_t *)A0 + 2);
+ low = ldsw(A0);
+ high = ldsw(A0 + 2);
v = (int16_t)T0;
if (v < low || v > high) {
- EIP = PARAM1;
raise_exception(EXCP05_BOUND);
}
FORCE_RET();
void OPPROTO op_boundl(void)
{
int low, high, v;
- low = ldl((uint8_t *)A0);
- high = ldl((uint8_t *)A0 + 4);
+ low = ldl(A0);
+ high = ldl(A0 + 4);
v = T0;
if (v < low || v > high) {
- EIP = PARAM1;
raise_exception(EXCP05_BOUND);
}
FORCE_RET();
helper_cmpxchg8b();
}
-void OPPROTO op_jmp(void)
-{
- JUMP_TB(op_jmp, PARAM1, 0, PARAM2);
-}
-
void OPPROTO op_movl_T0_0(void)
{
T0 = 0;
#include "ops_template.h"
#undef SHIFT
+#ifdef TARGET_X86_64
+
+#define SHIFT 3
+#include "ops_template.h"
+#undef SHIFT
+
+#endif
+
/* sign extend */
void OPPROTO op_movsbl_T0_T0(void)
EAX = (int16_t)EAX;
}
+#ifdef TARGET_X86_64
+void OPPROTO op_movslq_T0_T0(void)
+{
+ T0 = (int32_t)T0;
+}
+
+void OPPROTO op_movslq_RAX_EAX(void)
+{
+ EAX = (int32_t)EAX;
+}
+#endif
+
void OPPROTO op_movsbw_AX_AL(void)
{
- EAX = (EAX & 0xffff0000) | ((int8_t)EAX & 0xffff);
+ EAX = (EAX & ~0xffff) | ((int8_t)EAX & 0xffff);
}
void OPPROTO op_movslq_EDX_EAX(void)
void OPPROTO op_movswl_DX_AX(void)
{
- EDX = (EDX & 0xffff0000) | (((int16_t)EAX >> 15) & 0xffff);
+ EDX = (EDX & ~0xffff) | (((int16_t)EAX >> 15) & 0xffff);
+}
+
+#ifdef TARGET_X86_64
+void OPPROTO op_movsqo_RDX_RAX(void)
+{
+ EDX = (int64_t)EAX >> 63;
}
+#endif
/* string ops helpers */
void OPPROTO op_addl_ESI_T0(void)
{
- ESI += T0;
+ ESI = (uint32_t)(ESI + T0);
}
void OPPROTO op_addw_ESI_T0(void)
void OPPROTO op_addl_EDI_T0(void)
{
- EDI += T0;
+ EDI = (uint32_t)(EDI + T0);
}
void OPPROTO op_addw_EDI_T0(void)
void OPPROTO op_decl_ECX(void)
{
- ECX--;
+ ECX = (uint32_t)(ECX - 1);
}
void OPPROTO op_decw_ECX(void)
ECX = (ECX & ~0xffff) | ((ECX - 1) & 0xffff);
}
+#ifdef TARGET_X86_64
+void OPPROTO op_addq_ESI_T0(void)
+{
+ ESI = (ESI + T0);
+}
+
+void OPPROTO op_addq_EDI_T0(void)
+{
+ EDI = (EDI + T0);
+}
+
+void OPPROTO op_decq_ECX(void)
+{
+ ECX--;
+}
+#endif
+
/* push/pop utils */
void op_addl_A0_SS(void)
{
- A0 += (long)env->segs[R_SS].base;
+ A0 = (uint32_t)(A0 + env->segs[R_SS].base);
}
void op_subl_A0_2(void)
{
- A0 -= 2;
+ A0 = (uint32_t)(A0 - 2);
}
void op_subl_A0_4(void)
{
- A0 -= 4;
+ A0 = (uint32_t)(A0 - 4);
}
void op_addl_ESP_4(void)
{
- ESP += 4;
+ ESP = (uint32_t)(ESP + 4);
}
void op_addl_ESP_2(void)
{
- ESP += 2;
+ ESP = (uint32_t)(ESP + 2);
}
void op_addw_ESP_4(void)
void op_addl_ESP_im(void)
{
- ESP += PARAM1;
+ ESP = (uint32_t)(ESP + PARAM1);
}
void op_addw_ESP_im(void)
ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff);
}
+#ifdef TARGET_X86_64
+void op_subq_A0_2(void)
+{
+ A0 -= 2;
+}
+
+void op_subq_A0_8(void)
+{
+ A0 -= 8;
+}
+
+void op_addq_ESP_8(void)
+{
+ ESP += 8;
+}
+
+void op_addq_ESP_im(void)
+{
+ ESP += PARAM1;
+}
+#endif
+
void OPPROTO op_rdtsc(void)
{
helper_rdtsc();
helper_cpuid();
}
+void OPPROTO op_enter_level(void)
+{
+ helper_enter_level(PARAM1, PARAM2);
+}
+
+#ifdef TARGET_X86_64
+void OPPROTO op_enter64_level(void)
+{
+ helper_enter64_level(PARAM1, PARAM2);
+}
+#endif
+
+void OPPROTO op_sysenter(void)
+{
+ helper_sysenter();
+}
+
+void OPPROTO op_sysexit(void)
+{
+ helper_sysexit();
+}
+
+#ifdef TARGET_X86_64
+void OPPROTO op_syscall(void)
+{
+ helper_syscall(PARAM1);
+}
+
+void OPPROTO op_sysret(void)
+{
+ helper_sysret(PARAM1);
+}
+#endif
+
void OPPROTO op_rdmsr(void)
{
helper_rdmsr();
}
EAX = (EAX & ~0xffff) | al | (ah << 8);
CC_SRC = eflags;
+ FORCE_RET();
}
void OPPROTO op_aas(void)
}
EAX = (EAX & ~0xffff) | al | (ah << 8);
CC_SRC = eflags;
+ FORCE_RET();
}
void OPPROTO op_daa(void)
eflags |= parity_table[al]; /* pf */
eflags |= (al & 0x80); /* sf */
CC_SRC = eflags;
+ FORCE_RET();
}
void OPPROTO op_das(void)
eflags |= parity_table[al]; /* pf */
eflags |= (al & 0x80); /* sf */
CC_SRC = eflags;
+ FORCE_RET();
}
/* segment handling */
/* env->segs[] access */
sc = (SegmentCache *)((char *)env + PARAM1);
sc->selector = selector;
- sc->base = (void *)(selector << 4);
+ sc->base = (selector << 4);
}
void OPPROTO op_movl_T0_seg(void)
T0 = env->segs[PARAM1].selector;
}
-void OPPROTO op_movl_A0_seg(void)
-{
- A0 = *(unsigned long *)((char *)env + PARAM1);
-}
-
-void OPPROTO op_addl_A0_seg(void)
-{
- A0 += *(unsigned long *)((char *)env + PARAM1);
-}
-
void OPPROTO op_lsl(void)
{
helper_lsl();
helper_movl_crN_T0(PARAM1);
}
+#if !defined(CONFIG_USER_ONLY)
+void OPPROTO op_movtl_T0_cr8(void)
+{
+ T0 = cpu_get_apic_tpr(env);
+}
+#endif
+
/* DR registers access */
void OPPROTO op_movl_drN_T0(void)
{
void OPPROTO op_lmsw_T0(void)
{
- /* only 4 lower bits of CR0 are modified */
- T0 = (env->cr[0] & ~0xf) | (T0 & 0xf);
+ /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
+ if already set to one. */
+ T0 = (env->cr[0] & ~0xe) | (T0 & 0xf);
helper_movl_crN_T0(0);
}
*(uint32_t *)((char *)env + PARAM1) = T1;
}
+void OPPROTO op_movtl_T0_env(void)
+{
+ T0 = *(target_ulong *)((char *)env + PARAM1);
+}
+
+void OPPROTO op_movtl_env_T0(void)
+{
+ *(target_ulong *)((char *)env + PARAM1) = T0;
+}
+
+void OPPROTO op_movtl_T1_env(void)
+{
+ T1 = *(target_ulong *)((char *)env + PARAM1);
+}
+
+void OPPROTO op_movtl_env_T1(void)
+{
+ *(target_ulong *)((char *)env + PARAM1) = T1;
+}
+
void OPPROTO op_clts(void)
{
env->cr[0] &= ~CR0_TS_MASK;
/* flags handling */
-/* slow jumps cases : in order to avoid calling a function with a
- pointer (which can generate a stack frame on PowerPC), we use
- op_setcc to set T0 and then call op_jcc. */
-void OPPROTO op_jcc(void)
+void OPPROTO op_goto_tb0(void)
+{
+ GOTO_TB(op_goto_tb0, PARAM1, 0);
+}
+
+void OPPROTO op_goto_tb1(void)
+{
+ GOTO_TB(op_goto_tb1, PARAM1, 1);
+}
+
+void OPPROTO op_jmp_label(void)
+{
+ GOTO_LABEL_PARAM(1);
+}
+
+void OPPROTO op_jnz_T0_label(void)
{
if (T0)
- JUMP_TB(op_jcc, PARAM1, 0, PARAM2);
- else
- JUMP_TB(op_jcc, PARAM1, 1, PARAM3);
+ GOTO_LABEL_PARAM(1);
FORCE_RET();
}
-void OPPROTO op_jcc_im(void)
+void OPPROTO op_jz_T0_label(void)
{
- if (T0)
- EIP = PARAM1;
- else
- EIP = PARAM2;
+ if (!T0)
+ GOTO_LABEL_PARAM(1);
FORCE_RET();
}
CC_OP = PARAM1;
}
+void OPPROTO op_mov_T0_cc(void)
+{
+ T0 = cc_table[CC_OP].compute_all();
+}
+
/* XXX: clear VIF/VIP in all ops ? */
void OPPROTO op_movl_eflags_T0(void)
[CC_OP_SARB] = { compute_all_sarb, compute_c_sarl },
[CC_OP_SARW] = { compute_all_sarw, compute_c_sarl },
[CC_OP_SARL] = { compute_all_sarl, compute_c_sarl },
-};
-/* floating point support. Some of the code for complicated x87
- functions comes from the LGPL'ed x86 emulator found in the Willows
- TWIN windows emulator. */
+#ifdef TARGET_X86_64
+ [CC_OP_MULQ] = { compute_all_mulq, compute_c_mull },
-#if defined(__powerpc__)
-extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
+ [CC_OP_ADDQ] = { compute_all_addq, compute_c_addq },
-/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
-double qemu_rint(double x)
-{
- double y = 4503599627370496.0;
- if (fabs(x) >= y)
- return x;
- if (x < 0)
- y = -y;
- y = (x + y) - y;
- if (y == 0.0)
- y = copysign(y, x);
- return y;
-}
+ [CC_OP_ADCQ] = { compute_all_adcq, compute_c_adcq },
-#define rint qemu_rint
+ [CC_OP_SUBQ] = { compute_all_subq, compute_c_subq },
+
+ [CC_OP_SBBQ] = { compute_all_sbbq, compute_c_sbbq },
+
+ [CC_OP_LOGICQ] = { compute_all_logicq, compute_c_logicq },
+
+ [CC_OP_INCQ] = { compute_all_incq, compute_c_incl },
+
+ [CC_OP_DECQ] = { compute_all_decq, compute_c_incl },
+
+ [CC_OP_SHLQ] = { compute_all_shlq, compute_c_shlq },
+
+ [CC_OP_SARQ] = { compute_all_sarq, compute_c_sarl },
#endif
+};
+
+/* floating point support. Some of the code for complicated x87
+ functions comes from the LGPL'ed x86 emulator found in the Willows
+ TWIN windows emulator. */
/* fp load FT0 */
void OPPROTO op_flds_FT0_A0(void)
{
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = ldl((void *)A0);
+ FP_CONVERT.i32 = ldl(A0);
FT0 = FP_CONVERT.f;
#else
- FT0 = ldfl((void *)A0);
+ FT0 = ldfl(A0);
#endif
}
void OPPROTO op_fldl_FT0_A0(void)
{
#ifdef USE_FP_CONVERT
- FP_CONVERT.i64 = ldq((void *)A0);
+ FP_CONVERT.i64 = ldq(A0);
FT0 = FP_CONVERT.d;
#else
- FT0 = ldfq((void *)A0);
+ FT0 = ldfq(A0);
#endif
}
void helper_fild_FT0_A0(void)
{
- FT0 = (CPU86_LDouble)ldsw((void *)A0);
+ FT0 = (CPU86_LDouble)ldsw(A0);
}
void helper_fildl_FT0_A0(void)
{
- FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
+ FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
}
void helper_fildll_FT0_A0(void)
{
- FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
+ FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
}
void OPPROTO op_fild_FT0_A0(void)
void OPPROTO op_fild_FT0_A0(void)
{
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = ldsw((void *)A0);
+ FP_CONVERT.i32 = ldsw(A0);
FT0 = (CPU86_LDouble)FP_CONVERT.i32;
#else
- FT0 = (CPU86_LDouble)ldsw((void *)A0);
+ FT0 = (CPU86_LDouble)ldsw(A0);
#endif
}
void OPPROTO op_fildl_FT0_A0(void)
{
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
+ FP_CONVERT.i32 = (int32_t) ldl(A0);
FT0 = (CPU86_LDouble)FP_CONVERT.i32;
#else
- FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
+ FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
#endif
}
void OPPROTO op_fildll_FT0_A0(void)
{
#ifdef USE_FP_CONVERT
- FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
+ FP_CONVERT.i64 = (int64_t) ldq(A0);
FT0 = (CPU86_LDouble)FP_CONVERT.i64;
#else
- FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
+ FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
#endif
}
#endif
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = ldl((void *)A0);
- env->fpregs[new_fpstt] = FP_CONVERT.f;
+ FP_CONVERT.i32 = ldl(A0);
+ env->fpregs[new_fpstt].d = FP_CONVERT.f;
#else
- env->fpregs[new_fpstt] = ldfl((void *)A0);
+ env->fpregs[new_fpstt].d = ldfl(A0);
#endif
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
#ifdef USE_FP_CONVERT
- FP_CONVERT.i64 = ldq((void *)A0);
- env->fpregs[new_fpstt] = FP_CONVERT.d;
+ FP_CONVERT.i64 = ldq(A0);
+ env->fpregs[new_fpstt].d = FP_CONVERT.d;
#else
- env->fpregs[new_fpstt] = ldfq((void *)A0);
+ env->fpregs[new_fpstt].d = ldfq(A0);
#endif
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
{
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
- env->fpregs[new_fpstt] = (CPU86_LDouble)ldsw((void *)A0);
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
}
{
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
- env->fpregs[new_fpstt] = (CPU86_LDouble)((int32_t)ldl((void *)A0));
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
}
{
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
- env->fpregs[new_fpstt] = (CPU86_LDouble)((int64_t)ldq((void *)A0));
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
}
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = ldsw((void *)A0);
- env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i32;
+ FP_CONVERT.i32 = ldsw(A0);
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
#else
- env->fpregs[new_fpstt] = (CPU86_LDouble)ldsw((void *)A0);
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
#endif
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
#ifdef USE_FP_CONVERT
- FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
- env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i32;
+ FP_CONVERT.i32 = (int32_t) ldl(A0);
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
#else
- env->fpregs[new_fpstt] = (CPU86_LDouble)((int32_t)ldl((void *)A0));
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
#endif
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
int new_fpstt;
new_fpstt = (env->fpstt - 1) & 7;
#ifdef USE_FP_CONVERT
- FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
- env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i64;
+ FP_CONVERT.i64 = (int64_t) ldq(A0);
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i64;
#else
- env->fpregs[new_fpstt] = (CPU86_LDouble)((int64_t)ldq((void *)A0));
+ env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
#endif
env->fpstt = new_fpstt;
env->fptags[new_fpstt] = 0; /* validate stack entry */
{
#ifdef USE_FP_CONVERT
FP_CONVERT.f = (float)ST0;
- stfl((void *)A0, FP_CONVERT.f);
+ stfl(A0, FP_CONVERT.f);
#else
- stfl((void *)A0, (float)ST0);
+ stfl(A0, (float)ST0);
#endif
+ FORCE_RET();
}
void OPPROTO op_fstl_ST0_A0(void)
{
- stfq((void *)A0, (double)ST0);
+ stfq(A0, (double)ST0);
+ FORCE_RET();
}
void OPPROTO op_fstt_ST0_A0(void)
int val;
d = ST0;
- val = lrint(d);
+ val = floatx_to_int32(d, &env->fp_status);
if (val != (int16_t)val)
val = -32768;
- stw((void *)A0, val);
+ stw(A0, val);
+ FORCE_RET();
}
void OPPROTO op_fistl_ST0_A0(void)
int val;
d = ST0;
- val = lrint(d);
- stl((void *)A0, val);
+ val = floatx_to_int32(d, &env->fp_status);
+ stl(A0, val);
+ FORCE_RET();
}
void OPPROTO op_fistll_ST0_A0(void)
int64_t val;
d = ST0;
- val = llrint(d);
- stq((void *)A0, val);
+ val = floatx_to_int64(d, &env->fp_status);
+ stq(A0, val);
+ FORCE_RET();
+}
+
+void OPPROTO op_fistt_ST0_A0(void)
+{
+#if defined(__sparc__) && !defined(__sparc_v9__)
+ register CPU86_LDouble d asm("o0");
+#else
+ CPU86_LDouble d;
+#endif
+ int val;
+
+ d = ST0;
+ val = floatx_to_int32_round_to_zero(d, &env->fp_status);
+ if (val != (int16_t)val)
+ val = -32768;
+ stw(A0, val);
+ FORCE_RET();
+}
+
+void OPPROTO op_fisttl_ST0_A0(void)
+{
+#if defined(__sparc__) && !defined(__sparc_v9__)
+ register CPU86_LDouble d asm("o0");
+#else
+ CPU86_LDouble d;
+#endif
+ int val;
+
+ d = ST0;
+ val = floatx_to_int32_round_to_zero(d, &env->fp_status);
+ stl(A0, val);
+ FORCE_RET();
+}
+
+void OPPROTO op_fisttll_ST0_A0(void)
+{
+#if defined(__sparc__) && !defined(__sparc_v9__)
+ register CPU86_LDouble d asm("o0");
+#else
+ CPU86_LDouble d;
+#endif
+ int64_t val;
+
+ d = ST0;
+ val = floatx_to_int64_round_to_zero(d, &env->fp_status);
+ stq(A0, val);
+ FORCE_RET();
}
void OPPROTO op_fbld_ST0_A0(void)
env->fpus &= (~0x4700);
}
+void OPPROTO op_ffree_STN(void)
+{
+ env->fptags[(env->fpstt + PARAM1) & 7] = 1;
+}
+
void OPPROTO op_fmov_ST0_FT0(void)
{
ST0 = FT0;
/* FPU operations */
-/* XXX: handle nans */
+const int fcom_ccval[4] = {0x0100, 0x4000, 0x0000, 0x4500};
+
void OPPROTO op_fcom_ST0_FT0(void)
{
- env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */
- if (ST0 < FT0)
- env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */
- else if (ST0 == FT0)
- env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */
+ int ret;
+
+ ret = floatx_compare(ST0, FT0, &env->fp_status);
+ env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret + 1];
FORCE_RET();
}
-/* XXX: handle nans */
void OPPROTO op_fucom_ST0_FT0(void)
{
- env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */
- if (ST0 < FT0)
- env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */
- else if (ST0 == FT0)
- env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */
+ int ret;
+
+ ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
+ env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret+ 1];
FORCE_RET();
}
-/* XXX: handle nans */
+const int fcomi_ccval[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
+
void OPPROTO op_fcomi_ST0_FT0(void)
{
int eflags;
+ int ret;
+
+ ret = floatx_compare(ST0, FT0, &env->fp_status);
eflags = cc_table[CC_OP].compute_all();
- eflags &= ~(CC_Z | CC_P | CC_C);
- if (ST0 < FT0)
- eflags |= CC_C;
- else if (ST0 == FT0)
- eflags |= CC_Z;
+ eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
CC_SRC = eflags;
FORCE_RET();
}
-/* XXX: handle nans */
void OPPROTO op_fucomi_ST0_FT0(void)
{
int eflags;
+ int ret;
+
+ ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
eflags = cc_table[CC_OP].compute_all();
- eflags &= ~(CC_Z | CC_P | CC_C);
- if (ST0 < FT0)
- eflags |= CC_C;
- else if (ST0 == FT0)
- eflags |= CC_Z;
+ eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
CC_SRC = eflags;
FORCE_RET();
}
void OPPROTO op_fdiv_ST0_FT0(void)
{
- ST0 /= FT0;
+ ST0 = helper_fdiv(ST0, FT0);
}
void OPPROTO op_fdivr_ST0_FT0(void)
{
- ST0 = FT0 / ST0;
+ ST0 = helper_fdiv(FT0, ST0);
}
/* fp operations between STN and ST0 */
void OPPROTO op_fdiv_STN_ST0(void)
{
- ST(PARAM1) /= ST0;
+ CPU86_LDouble *p;
+ p = &ST(PARAM1);
+ *p = helper_fdiv(*p, ST0);
}
void OPPROTO op_fdivr_STN_ST0(void)
{
CPU86_LDouble *p;
p = &ST(PARAM1);
- *p = ST0 / *p;
+ *p = helper_fdiv(ST0, *p);
}
/* misc FPU operations */
void OPPROTO op_fchs_ST0(void)
{
- ST0 = -ST0;
+ ST0 = floatx_chs(ST0);
}
void OPPROTO op_fabs_ST0(void)
{
- ST0 = fabs(ST0);
+ ST0 = floatx_abs(ST0);
}
void OPPROTO op_fxam_ST0(void)
{
int fpus;
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
- stw((void *)A0, fpus);
+ stw(A0, fpus);
+ FORCE_RET();
}
void OPPROTO op_fnstsw_EAX(void)
{
int fpus;
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
- EAX = (EAX & 0xffff0000) | fpus;
+ EAX = (EAX & ~0xffff) | fpus;
}
void OPPROTO op_fnstcw_A0(void)
{
- stw((void *)A0, env->fpuc);
+ stw(A0, env->fpuc);
+ FORCE_RET();
}
void OPPROTO op_fldcw_A0(void)
{
- int rnd_type;
- env->fpuc = lduw((void *)A0);
- /* set rounding mode */
- switch(env->fpuc & RC_MASK) {
- default:
- case RC_NEAR:
- rnd_type = FE_TONEAREST;
- break;
- case RC_DOWN:
- rnd_type = FE_DOWNWARD;
- break;
- case RC_UP:
- rnd_type = FE_UPWARD;
- break;
- case RC_CHOP:
- rnd_type = FE_TOWARDZERO;
- break;
- }
- fesetround(rnd_type);
+ env->fpuc = lduw(A0);
+ update_fp_status();
}
void OPPROTO op_fclex(void)
env->fpus &= 0x7f00;
}
+void OPPROTO op_fwait(void)
+{
+ if (env->fpus & FPUS_SE)
+ fpu_raise_exception();
+ FORCE_RET();
+}
+
void OPPROTO op_fninit(void)
{
env->fpus = 0;
void OPPROTO op_fnstenv_A0(void)
{
- helper_fstenv((uint8_t *)A0, PARAM1);
+ helper_fstenv(A0, PARAM1);
}
void OPPROTO op_fldenv_A0(void)
{
- helper_fldenv((uint8_t *)A0, PARAM1);
+ helper_fldenv(A0, PARAM1);
}
void OPPROTO op_fnsave_A0(void)
{
- helper_fsave((uint8_t *)A0, PARAM1);
+ helper_fsave(A0, PARAM1);
}
void OPPROTO op_frstor_A0(void)
{
- helper_frstor((uint8_t *)A0, PARAM1);
+ helper_frstor(A0, PARAM1);
}
/* threading support */
cpu_unlock();
}
+/* SSE support */
+static inline void memcpy16(void *d, void *s)
+{
+ ((uint32_t *)d)[0] = ((uint32_t *)s)[0];
+ ((uint32_t *)d)[1] = ((uint32_t *)s)[1];
+ ((uint32_t *)d)[2] = ((uint32_t *)s)[2];
+ ((uint32_t *)d)[3] = ((uint32_t *)s)[3];
+}
+
+void OPPROTO op_movo(void)
+{
+ /* XXX: badly generated code */
+ XMMReg *d, *s;
+ d = (XMMReg *)((char *)env + PARAM1);
+ s = (XMMReg *)((char *)env + PARAM2);
+ memcpy16(d, s);
+}
+
+void OPPROTO op_movq(void)
+{
+ uint64_t *d, *s;
+ d = (uint64_t *)((char *)env + PARAM1);
+ s = (uint64_t *)((char *)env + PARAM2);
+ *d = *s;
+}
+
+void OPPROTO op_movl(void)
+{
+ uint32_t *d, *s;
+ d = (uint32_t *)((char *)env + PARAM1);
+ s = (uint32_t *)((char *)env + PARAM2);
+ *d = *s;
+}
+
+void OPPROTO op_movq_env_0(void)
+{
+ uint64_t *d;
+ d = (uint64_t *)((char *)env + PARAM1);
+ *d = 0;
+}
+
+void OPPROTO op_fxsave_A0(void)
+{
+ helper_fxsave(A0, PARAM1);
+}
+
+void OPPROTO op_fxrstor_A0(void)
+{
+ helper_fxrstor(A0, PARAM1);
+}
+
+/* XXX: optimize by storing fptt and fptags in the static cpu state */
+void OPPROTO op_enter_mmx(void)
+{
+ env->fpstt = 0;
+ *(uint32_t *)(env->fptags) = 0;
+ *(uint32_t *)(env->fptags + 4) = 0;
+}
+
+void OPPROTO op_emms(void)
+{
+ /* set to empty state */
+ *(uint32_t *)(env->fptags) = 0x01010101;
+ *(uint32_t *)(env->fptags + 4) = 0x01010101;
+}
+
+#define SHIFT 0
+#include "ops_sse.h"
+
+#define SHIFT 1
+#include "ops_sse.h"