diff --git a/src/dynarec/dynarec.c b/src/dynarec/dynarec.c index 5dddc23bf..858709e3e 100644 --- a/src/dynarec/dynarec.c +++ b/src/dynarec/dynarec.c @@ -106,9 +106,6 @@ void DynaCall(x64emu_t* emu, uintptr_t addr) multiuint_t old_op1 = emu->op1; multiuint_t old_op2 = emu->op2; multiuint_t old_res = emu->res; - multiuint_t old_op1_sav= emu->op1_sav; - multiuint_t old_res_sav= emu->res_sav; - deferred_flags_t old_df_sav= emu->df_sav; // uc_link void* old_uc_link = emu->uc_link; emu->uc_link = NULL; @@ -134,9 +131,6 @@ void DynaCall(x64emu_t* emu, uintptr_t addr) emu->op1 = old_op1; emu->op2 = old_op2; emu->res = old_res; - emu->op1_sav = old_op1_sav; - emu->res_sav = old_res_sav; - emu->df_sav = old_df_sav; // and the old registers emu->eflags = old_eflags; R_RBX = old_rbx; diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c index 760ba1704..8eec238b2 100644 --- a/src/emu/x64emu.c +++ b/src/emu/x64emu.c @@ -253,12 +253,9 @@ void CloneEmu(x64emu_t *newemu, const x64emu_t* emu) memcpy(newemu->xmm, emu->xmm, sizeof(emu->xmm)); memcpy(newemu->ymm, emu->ymm, sizeof(emu->ymm)); newemu->df = emu->df; - newemu->df_sav = emu->df_sav; newemu->op1 = emu->op1; newemu->op2 = emu->op2; newemu->res = emu->res; - newemu->op1_sav = emu->op1_sav; - newemu->res_sav = emu->res_sav; newemu->mxcsr = emu->mxcsr; newemu->quit = emu->quit; newemu->error = emu->error; @@ -286,12 +283,9 @@ void CopyEmu(x64emu_t *newemu, const x64emu_t* emu) newemu->top = emu->top; newemu->fpu_stack = emu->fpu_stack; newemu->df = emu->df; - newemu->df_sav = emu->df_sav; newemu->op1 = emu->op1; newemu->op2 = emu->op2; newemu->res = emu->res; - newemu->op1_sav = emu->op1_sav; - newemu->res_sav = emu->res_sav; newemu->mxcsr = emu->mxcsr; newemu->quit = emu->quit; newemu->error = emu->error; @@ -609,9 +603,6 @@ void EmuCall(x64emu_t* emu, uintptr_t addr) multiuint_t old_op1 = emu->op1; multiuint_t old_op2 = emu->op2; multiuint_t old_res = emu->res; - multiuint_t old_op1_sav= emu->op1_sav; - multiuint_t old_res_sav= emu->res_sav; - deferred_flags_t old_df_sav= emu->df_sav; // uc_link void* old_uc_link = emu->uc_link; emu->uc_link = NULL; @@ -640,9 +631,6 @@ void EmuCall(x64emu_t* emu, uintptr_t addr) emu->op1 = old_op1; emu->op2 = old_op2; emu->res = old_res; - emu->op1_sav = old_op1_sav; - emu->res_sav = old_res_sav; - emu->df_sav = old_df_sav; // and the old registers emu->eflags = old_eflags; R_RBX = old_rbx; diff --git a/src/emu/x64emu_private.h b/src/emu/x64emu_private.h index 0c02f5edf..1976012a5 100644 --- a/src/emu/x64emu_private.h +++ b/src/emu/x64emu_private.h @@ -91,9 +91,6 @@ typedef struct x64emu_s { multiuint_t op1; multiuint_t op2; multiuint_t res; - multiuint_t op1_sav; // for dec/inc deferred flags, to be able to compute CF - multiuint_t res_sav; - deferred_flags_t df_sav; uint32_t *x64emu_parity_tab; // helper // segments uint16_t segs[6]; // only 32bits value? diff --git a/src/emu/x64primop.c b/src/emu/x64primop.c index 72485ca07..9f5092e47 100644 --- a/src/emu/x64primop.c +++ b/src/emu/x64primop.c @@ -1189,9 +1189,8 @@ uint16_t sbb16(x64emu_t *emu, uint16_t d, uint16_t s) if (ACCESS_FLAG(F_CF)) res = d - s - 1; - else { + else res = d - s; - } CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); @@ -1212,9 +1211,8 @@ uint32_t sbb32(x64emu_t *emu, uint32_t d, uint32_t s) if (ACCESS_FLAG(F_CF)) res = d - s - 1; - else { + else res = d - s; - } CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); CONDITIONAL_SET_FLAG(!res, F_ZF); CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); @@ -1235,9 +1233,8 @@ uint64_t sbb64(x64emu_t *emu, uint64_t d, uint64_t s) if (ACCESS_FLAG(F_CF)) res = d - s - 1; - else { + else res = d - s; - } CONDITIONAL_SET_FLAG(res & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(!res, F_ZF); CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); @@ -1256,32 +1253,32 @@ Implements the TEST instruction and side effects. ****************************************************************************/ void test8(x64emu_t *emu, uint8_t d, uint8_t s) { - uint32_t res; /* all operands in native machine order */ + uint8_t res; /* all operands in native machine order */ RESET_FLAGS(emu); res = d & s; CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); CLEAR_FLAG(F_AF); /* AF == dont care */ CLEAR_FLAG(F_CF); + CONDITIONAL_SET_FLAG(res & 0x80, F_SF); + CONDITIONAL_SET_FLAG(!res, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); } void test16(x64emu_t *emu, uint16_t d, uint16_t s) { - uint32_t res; /* all operands in native machine order */ + uint16_t res; /* all operands in native machine order */ RESET_FLAGS(emu); res = d & s; CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); CLEAR_FLAG(F_AF); /* AF == dont care */ CLEAR_FLAG(F_CF); + CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); + CONDITIONAL_SET_FLAG(!res, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); } void test32(x64emu_t *emu, uint32_t d, uint32_t s) @@ -1292,11 +1289,11 @@ void test32(x64emu_t *emu, uint32_t d, uint32_t s) res = d & s; CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); CLEAR_FLAG(F_AF); /* AF == dont care */ CLEAR_FLAG(F_CF); + CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); + CONDITIONAL_SET_FLAG(!res, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); } void test64(x64emu_t *emu, uint64_t d, uint64_t s) @@ -1307,21 +1304,30 @@ void test64(x64emu_t *emu, uint64_t d, uint64_t s) res = d & s; CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); CLEAR_FLAG(F_AF); /* AF == dont care */ CLEAR_FLAG(F_CF); + CONDITIONAL_SET_FLAG(res & 0x8000000000000000LL, F_SF); + CONDITIONAL_SET_FLAG(!res, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); } /**************************************************************************** REMARKS: Implements the IDIV instruction and side effects. ****************************************************************************/ +extern int box64_dynarec_test; void idiv8(x64emu_t *emu, uint8_t s) { int32_t dvd, quot, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (int16_t)R_AX; if (s == 0) { @@ -1342,6 +1348,15 @@ void idiv8(x64emu_t *emu, uint8_t s) void idiv16(x64emu_t *emu, uint16_t s) { int32_t dvd, quot, mod; + RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((int32_t)R_DX) << 16) | R_AX; if (s == 0) { @@ -1355,10 +1370,6 @@ void idiv16(x64emu_t *emu, uint16_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(quot == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_AX = (uint16_t)quot; R_DX = (uint16_t)mod; @@ -1368,6 +1379,14 @@ void idiv32(x64emu_t *emu, uint32_t s) { int64_t dvd, quot, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((int64_t)R_EDX) << 32) | R_EAX; if (s == 0) { @@ -1381,11 +1400,6 @@ void idiv32(x64emu_t *emu, uint32_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_RAX = (uint32_t)quot; R_RDX = (uint32_t)mod; @@ -1395,6 +1409,14 @@ void idiv64(x64emu_t *emu, uint64_t s) { __int128 dvd, quot, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((__int128)R_RDX) << 64) | R_RAX; if (s == 0) { @@ -1407,11 +1429,6 @@ void idiv64(x64emu_t *emu, uint64_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_RAX = (uint64_t)quot; R_RDX = (uint64_t)mod; @@ -1425,6 +1442,14 @@ void div8(x64emu_t *emu, uint8_t s) { uint32_t dvd, div, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = R_AX; if (s == 0) { @@ -1445,6 +1470,14 @@ void div16(x64emu_t *emu, uint16_t s) { uint32_t dvd, div, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((uint32_t)R_DX) << 16) | R_AX; if (s == 0) { @@ -1457,10 +1490,6 @@ void div16(x64emu_t *emu, uint16_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(div == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_AX = (uint16_t)div; R_DX = (uint16_t)mod; @@ -1470,6 +1499,14 @@ void div32(x64emu_t *emu, uint32_t s) { uint64_t dvd, div, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((uint64_t)R_EDX) << 32) | R_EAX; if (s == 0) { @@ -1482,11 +1519,6 @@ void div32(x64emu_t *emu, uint32_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_RAX = (uint32_t)div; R_RDX = (uint32_t)mod; @@ -1496,6 +1528,14 @@ void div64(x64emu_t *emu, uint64_t s) { __int128 dvd, div, mod; RESET_FLAGS(emu); + if(box64_dynarec_test) { + CLEAR_FLAG(F_CF); + CLEAR_FLAG(F_AF); + CLEAR_FLAG(F_PF); + CLEAR_FLAG(F_ZF); + CLEAR_FLAG(F_SF); + CLEAR_FLAG(F_OF); + } dvd = (((__int128)R_RDX) << 64) | R_RAX; if (s == 0) { @@ -1508,11 +1548,6 @@ void div64(x64emu_t *emu, uint64_t s) INTR_RAISE_DIV0(emu); return; } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); R_RAX = (uint64_t)div; R_RDX = (uint64_t)mod; diff --git a/src/emu/x64primop.h b/src/emu/x64primop.h index db1e3dd67..e02fd9e75 100644 --- a/src/emu/x64primop.h +++ b/src/emu/x64primop.h @@ -16,7 +16,7 @@ uint64_t adc64 (x64emu_t *emu, uint64_t d, uint64_t s); static inline uint8_t add8(x64emu_t *emu, uint8_t d, uint8_t s) { - emu->res.u16 = d + s; + emu->res.u16 = (uint16_t)d + s; emu->op1.u8 = d; emu->op2.u8 = s; emu->df = d_add8; @@ -25,7 +25,7 @@ static inline uint8_t add8(x64emu_t *emu, uint8_t d, uint8_t s) static inline uint16_t add16(x64emu_t *emu, uint16_t d, uint16_t s) { - emu->res.u32 = d + s; + emu->res.u32 = (uint32_t)d + s; emu->op1.u16 = d; emu->op2.u16 = s; emu->df = d_add16; @@ -89,103 +89,78 @@ uint64_t cmp64 (x64emu_t *emu, uint64_t d, uint64_t s); uint8_t daa8 (x64emu_t *emu, uint8_t d); uint8_t das8 (x64emu_t *emu, uint8_t d); -#define CF_SAV() \ - if(emu->df>=d_dec8 && emu->df<=d_inc64) { \ - emu->df_sav = d_none; \ - } else if(emu->dfdf>d_inc64i) {\ - emu->df_sav = emu->df; \ - emu->op1_sav = emu->op1; \ - emu->res_sav = emu->res; \ - } - static inline uint8_t dec8(x64emu_t *emu, uint8_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u8 = d - 1; emu->op1.u8 = d; - emu->df = d_dec8i; + emu->df = d_dec8; return emu->res.u8; } static inline uint16_t dec16(x64emu_t *emu, uint16_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u16 = d - 1; emu->op1.u16 = d; - emu->df = d_dec16i; + emu->df = d_dec16; return emu->res.u16; } static inline uint32_t dec32(x64emu_t *emu, uint32_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u32 = d - 1; emu->op1.u32 = d; - emu->df = d_dec32i; + emu->df = d_dec32; return emu->res.u32; } static inline uint64_t dec64(x64emu_t *emu, uint64_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u64 = d - 1; emu->op1.u64 = d; - emu->df = d_dec64i; + emu->df = d_dec64; return emu->res.u64; } static inline uint8_t inc8(x64emu_t *emu, uint8_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u8 = d + 1; emu->op1.u8 = d; - emu->df = d_inc8i; + emu->df = d_inc8; return emu->res.u8; } static inline uint16_t inc16(x64emu_t *emu, uint16_t d) { - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u16 = d + 1; emu->op1.u16 = d; - emu->df = d_inc16i; + emu->df = d_inc16; return emu->res.u16; } static inline uint32_t inc32(x64emu_t *emu, uint32_t d) { - /*if(emu->df == d_shr32) { - // workaround for some wine trickery - uint32_t cnt = emu->op2.u32; - if (cnt > 0) { - uint32_t cc = emu->op1.u32 & (1 << (cnt - 1)); - CONDITIONAL_SET_FLAG(cc, F_CF); - } - }*/ - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u32 = d + 1; emu->op1.u32 = d; - emu->df = d_inc32i; + emu->df = d_inc32; return emu->res.u32; } static inline uint64_t inc64(x64emu_t *emu, uint64_t d) { - /*if(emu->df == d_shr64) { - // workaround for some wine trickery - uint64_t cnt = emu->op2.u64; - if (cnt > 0) { - uint64_t cc = emu->op1.u64 & (1LL << (cnt - 1)); - CONDITIONAL_SET_FLAG(cc, F_CF); - } - }*/ - CF_SAV(); + CHECK_FLAGS(emu); //need to grab CF in case it's needed emu->res.u64 = d + 1; emu->op1.u64 = d; - emu->df = d_inc64i; + emu->df = d_inc64; return emu->res.u64; } #undef CF_SAV @@ -201,7 +176,6 @@ static inline uint16_t or16(x64emu_t *emu, uint16_t d, uint16_t s) { emu->res.u16 = d | s; emu->df = d_or16; - /* set the carry flag to be bit 8 */ return emu->res.u16; } @@ -221,7 +195,7 @@ static inline uint64_t or64(x64emu_t *emu, uint64_t d, uint64_t s) static inline uint8_t neg8(x64emu_t *emu, uint8_t s) { - emu->res.u8 = (uint8_t)-s; + emu->res.i8 = -(int8_t)s; emu->op1.u8 = s; emu->df = d_neg8; return emu->res.u8; @@ -229,7 +203,7 @@ static inline uint8_t neg8(x64emu_t *emu, uint8_t s) static inline uint16_t neg16(x64emu_t *emu, uint16_t s) { - emu->res.u16 = (uint16_t)-s; + emu->res.i16 = -(int16_t)s; emu->op1.u16 = s; emu->df = d_neg16; return emu->res.u16; @@ -237,7 +211,7 @@ static inline uint16_t neg16(x64emu_t *emu, uint16_t s) static inline uint32_t neg32(x64emu_t *emu, uint32_t s) { - emu->res.u32 = (uint32_t)-s; + emu->res.i32 = -(int32_t)s; emu->op1.u32 = s; emu->df = d_neg32; return emu->res.u32; @@ -245,7 +219,7 @@ static inline uint32_t neg32(x64emu_t *emu, uint32_t s) static inline uint64_t neg64(x64emu_t *emu, uint64_t s) { - emu->res.u64 = (uint64_t)-s; + emu->res.i64 = -(int64_t)s; emu->op1.u64 = s; emu->df = d_neg64; return emu->res.u64; @@ -306,7 +280,6 @@ static inline uint8_t shl8(x64emu_t *emu, uint8_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shl8; emu->op1.u8 = d; @@ -322,7 +295,6 @@ static inline uint16_t shl16(x64emu_t *emu, uint16_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shl16; emu->op1.u16 = d; @@ -337,7 +309,6 @@ static inline uint32_t shl32(x64emu_t *emu, uint32_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shl32; emu->op1.u32 = d; @@ -353,7 +324,6 @@ static inline uint64_t shl64(x64emu_t *emu, uint64_t d, uint8_t s) { if(s&0x3f) { s &= 0x3f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shl64; emu->op1.u64 = d; @@ -369,7 +339,6 @@ static inline uint8_t shr8(x64emu_t *emu, uint8_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shr8; emu->op1.u8 = d; @@ -385,7 +354,6 @@ static inline uint16_t shr16(x64emu_t *emu, uint16_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shr16; emu->op1.u16 = d; @@ -401,7 +369,6 @@ static inline uint32_t shr32(x64emu_t *emu, uint32_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shr32; emu->op1.u32 = d; @@ -417,7 +384,6 @@ static inline uint64_t shr64(x64emu_t *emu, uint64_t d, uint8_t s) { if(s&0x3f) { s &= 0x3f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_shr64; emu->op1.u64 = d; @@ -433,7 +399,6 @@ static inline uint8_t sar8(x64emu_t *emu, uint8_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_sar8; emu->op1.u8 = d; @@ -452,7 +417,6 @@ static inline uint16_t sar16(x64emu_t *emu, uint16_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_sar16; emu->op1.u16 = d; @@ -471,7 +435,6 @@ static inline uint32_t sar32(x64emu_t *emu, uint32_t d, uint8_t s) { if(s&0x1f) { s &= 0x1f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_sar32; emu->op1.u32 = d; @@ -487,7 +450,6 @@ static inline uint64_t sar64(x64emu_t *emu, uint64_t d, uint8_t s) { if(s&0x3f) { s &= 0x3f; - if(s!=1) CHECK_FLAGS(emu); // for OF, need to find something more elegant here, using sav stuffs emu->df = d_sar64; emu->op1.u64 = d; @@ -572,13 +534,13 @@ static inline uint64_t xor64(x64emu_t *emu, uint64_t d, uint64_t s) static inline void imul8(x64emu_t *emu, uint8_t s) { emu->df = d_imul8; - R_AX = emu->res.u16 = (int16_t)(int8_t)R_AL * (int8_t)s; + R_AX = emu->res.u16 = ((int16_t)(int8_t)R_AL) * (int8_t)s; } static inline void imul16_eax(x64emu_t *emu, uint16_t s) { emu->df = d_imul16; - emu->res.u32 = (int32_t)(int16_t)R_AX * (int16_t)s; + emu->res.u32 = ((int32_t)(int16_t)R_AX) * (int16_t)s; R_AX = (uint16_t)emu->res.u32; R_DX = (uint16_t)(emu->res.u32 >> 16); } @@ -586,13 +548,13 @@ static inline void imul16_eax(x64emu_t *emu, uint16_t s) static inline uint16_t imul16(x64emu_t *emu, uint16_t op1, uint16_t op2) { emu->df = d_imul16; - emu->res.u32 = (int32_t)(int16_t)op1 * (int16_t)op2; + emu->res.u32 = ((int32_t)(int16_t)op1) * (int16_t)op2; return emu->res.u16; } static inline void imul32_direct(uint32_t *res_lo, uint32_t* res_hi,uint32_t d, uint32_t s) { - int64_t res = (int64_t)(int32_t)d * (int32_t)s; + uint64_t res = ((int64_t)(int32_t)d) * (int32_t)s; *res_lo = (uint32_t)res; *res_hi = (uint32_t)(res >> 32); @@ -611,14 +573,14 @@ static inline uint32_t imul32(x64emu_t *emu, uint32_t op1, uint32_t op2) static inline void imul32_eax(x64emu_t *emu, uint32_t s) { emu->df = d_imul32; - imul32_direct(&R_EAX,&R_EDX,R_EAX,s); - emu->res.u32 = R_EAX; - emu->op1.u32 = R_EDX; + imul32_direct(&emu->res.u32,&emu->op1.u32,R_EAX,s); + R_EAX = emu->res.u32; + R_EDX = emu->op1.u32; } static inline void imul64_direct(uint64_t *res_lo, uint64_t* res_hi,uint64_t d, uint64_t s) { - __int128 res = (__int128)(int64_t)d * (int64_t)s; + unsigned __int128 res = ((__int128)(int64_t)d) * (int64_t)s; *res_lo = (uint64_t)res; *res_hi = (uint64_t)(res >> 64); @@ -634,9 +596,9 @@ static inline uint64_t imul64(x64emu_t *emu, uint64_t op1, uint64_t op2) static inline void imul64_rax(x64emu_t *emu, uint64_t s) { emu->df = d_imul64; - imul64_direct(&R_RAX,&R_RDX,R_RAX,s); - emu->res.u64 = R_RAX; - emu->op1.u64 = R_RDX; + imul64_direct(&emu->res.u64,&emu->op1.u64,R_RAX,s); + R_RAX = emu->res.u64; + R_RDX = emu->op1.u64; } static inline void mul8(x64emu_t *emu, uint8_t s) diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c index 58331a1d2..6027a7444 100644 --- a/src/emu/x64run_private.c +++ b/src/emu/x64run_private.c @@ -209,28 +209,27 @@ void UpdateFlags(x64emu_t *emu) return; case d_add8: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x100, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(emu->res.u16 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); - + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u8 & emu->op2.u8) | ((~emu->res.u8) & (emu->op1.u8 | emu->op2.u8)); CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); break; case d_add16: CONDITIONAL_SET_FLAG(emu->res.u32 & 0x10000, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u32 & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(emu->res.u32 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u16 & emu->op2.u16) | ((~emu->res.u16) & (emu->op1.u16 | emu->op2.u16)); CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); break; case d_add32: CONDITIONAL_SET_FLAG(emu->res.u64 & 0x100000000LL, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u64 & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(emu->res.u64 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); + CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u32 & emu->op2.u32) | ((~emu->res.u32) & (emu->op1.u32 | emu->op2.u32)); CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -241,7 +240,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(hi & 0x10000, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u32 & emu->op2.u32) | ((~emu->res.u32) & (emu->op1.u32 | emu->op2.u32)); CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -252,7 +251,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(hi & 0x100000000L, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u64 & emu->op2.u64) | ((~emu->res.u64) & (emu->op1.u64 | emu->op2.u64)); CONDITIONAL_SET_FLAG(XOR2(cc >> 62), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -262,24 +261,24 @@ void UpdateFlags(x64emu_t *emu) CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u8 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_and16: CLEAR_FLAG(F_OF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u16 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_and32: CLEAR_FLAG(F_OF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u32 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_and64: CLEAR_FLAG(F_OF); @@ -287,20 +286,20 @@ void UpdateFlags(x64emu_t *emu) CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(emu->res.u64 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_dec8: CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG((emu->res.u8) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u8 & (~emu->op1.u8 | 1)) | (~emu->op1.u8 & 1); CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); break; case d_dec16: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((emu->res.u16) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u16 & (~emu->op1.u16 | 1)) | (~emu->op1.u16 & 1); CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); @@ -308,7 +307,7 @@ void UpdateFlags(x64emu_t *emu) case d_dec32: CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u32 & (~emu->op1.u32 | 1)) | (~emu->op1.u32 & 1); CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); @@ -316,23 +315,23 @@ void UpdateFlags(x64emu_t *emu) case d_dec64: CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); - bc = (emu->res.u64 & (~emu->op1.u64 | 1)) | (~emu->op1.u64 & 1); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); + bc = (emu->res.u64 & (~emu->op1.u64 | 1LL)) | (~emu->op1.u64 & 1LL); CONDITIONAL_SET_FLAG(XOR2(bc >> 62), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); break; case d_inc8: - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = ((1 & emu->op1.u8) | (~emu->res.u8)) & (1 | emu->op1.u8); CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); break; case d_inc16: - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (1 & emu->op1.u16) | ((~emu->res.u16) & (1 | emu->op1.u16)); CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -340,7 +339,7 @@ void UpdateFlags(x64emu_t *emu) case d_inc32: CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (1 & emu->op1.u32) | ((~emu->res.u32) & (1 | emu->op1.u32)); CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -348,8 +347,8 @@ void UpdateFlags(x64emu_t *emu) case d_inc64: CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); - cc = (1 & emu->op1.u64) | ((~emu->res.u64) & (1 | emu->op1.u64)); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); + cc = (1LL & emu->op1.u64) | ((~emu->res.u64) & (1LL | emu->op1.u64)); CONDITIONAL_SET_FLAG(XOR2(cc >> 62), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); break; @@ -426,7 +425,6 @@ void UpdateFlags(x64emu_t *emu) } break; case d_mul8: - lo = emu->res.u16 & 0xff; hi = (emu->res.u16>>8)&0xff; if (hi == 0) { CLEAR_FLAG(F_CF); @@ -444,7 +442,6 @@ void UpdateFlags(x64emu_t *emu) } break; case d_mul16: - lo = (uint16_t)emu->res.u32; hi = (uint16_t)(emu->res.u32 >> 16); if (hi == 0) { CLEAR_FLAG(F_CF); @@ -498,65 +495,65 @@ void UpdateFlags(x64emu_t *emu) CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u8 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_or16: CLEAR_FLAG(F_OF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u16 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_or32: CLEAR_FLAG(F_OF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u32 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_or64: CLEAR_FLAG(F_OF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u64 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_neg8: - CONDITIONAL_SET_FLAG(emu->op1.u8 != 0, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(emu->op1.u8, F_CF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = emu->res.u8 | emu->op1.u8; CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); break; case d_neg16: - CONDITIONAL_SET_FLAG(emu->op1.u16 != 0, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(emu->op1.u16, F_CF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = emu->res.u16 | emu->op1.u16; CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); break; case d_neg32: - CONDITIONAL_SET_FLAG(emu->op1.u32 != 0, F_CF); + CONDITIONAL_SET_FLAG(emu->op1.u32, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = emu->res.u32 | emu->op1.u32; CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); break; case d_neg64: - CONDITIONAL_SET_FLAG(emu->op1.u64 != 0, F_CF); + CONDITIONAL_SET_FLAG(emu->op1.u64, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = emu->res.u64 | emu->op1.u64; CONDITIONAL_SET_FLAG(XOR2(bc >> 62), F_OF); CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); @@ -566,9 +563,9 @@ void UpdateFlags(x64emu_t *emu) if (cnt > 0) { cc = emu->op1.u8 & (1 << (8 - cnt)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((((emu->res.u8 & 0x80) == 0x80) ^(ACCESS_FLAG(F_CF) != 0)), F_OF); } else { @@ -584,9 +581,9 @@ void UpdateFlags(x64emu_t *emu) if (cnt > 0) { cc = emu->op1.u16 & (1 << (16 - cnt)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG(((!!(emu->res.u16 & 0x8000)) ^(ACCESS_FLAG(F_CF) != 0)), F_OF); } else { @@ -604,7 +601,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG(((!!(emu->res.u32 & 0x80000000)) ^ (ACCESS_FLAG(F_CF) != 0)), F_OF); @@ -622,7 +619,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (emu->op2.u64 == 1) { CONDITIONAL_SET_FLAG(((!!(emu->res.u64 & 0x8000000000000000LL)) ^ (ACCESS_FLAG(F_CF) != 0)), F_OF); @@ -638,8 +635,8 @@ void UpdateFlags(x64emu_t *emu) if(emu->op2.u8) { cc = (emu->op1.i8 >> (emu->op2.u8 - 1)) & 1; CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); if(emu->op2.u8==1) CLEAR_FLAG(F_OF); @@ -652,9 +649,9 @@ void UpdateFlags(x64emu_t *emu) if(emu->op2.u16) { cc = (emu->op1.i16 >> (emu->op2.u16 - 1)) & 1; CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(emu->op2.u16==1) CLEAR_FLAG(F_OF); if(box64_dynarec_test) { @@ -666,9 +663,9 @@ void UpdateFlags(x64emu_t *emu) if(emu->op2.u32) { cc = emu->op1.u32 & (1 << (emu->op2.u32 - 1)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u32 & 0xffffffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(emu->op2.u32==1) CLEAR_FLAG(F_OF); if(box64_dynarec_test) { @@ -680,9 +677,9 @@ void UpdateFlags(x64emu_t *emu) if(emu->op2.u64) { cc = emu->op1.u64 & (1LL << (emu->op2.u64 - 1)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG(emu->res.u64 == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(emu->op2.u64==1) CLEAR_FLAG(F_OF); if(box64_dynarec_test) { @@ -695,9 +692,9 @@ void UpdateFlags(x64emu_t *emu) if (cnt > 0) { cc = emu->op1.u8 & (1 << (cnt - 1)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(box64_dynarec_test) { CLEAR_FLAG(F_AF); } @@ -711,9 +708,9 @@ void UpdateFlags(x64emu_t *emu) if (cnt > 0) { cc = emu->op1.u16 & (1 << (cnt - 1)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(box64_dynarec_test) { CLEAR_FLAG(F_AF); } @@ -727,9 +724,9 @@ void UpdateFlags(x64emu_t *emu) if (cnt > 0) { cc = emu->op1.u32 & (1 << (cnt - 1)); CONDITIONAL_SET_FLAG(cc, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u32 & 0xffffffff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if(box64_dynarec_test) { CLEAR_FLAG(F_AF); } @@ -745,7 +742,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG(emu->op1.u64 & 0x8000000000000000LL, F_OF); } @@ -761,7 +758,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u16 ^ emu->res.u16) & 0x8000, F_OF); } @@ -774,7 +771,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u32 ^ emu->res.u32) & 0x80000000, F_OF); } @@ -787,7 +784,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u64 ^ emu->res.u64) & 0x8000000000000000LL, F_OF); } @@ -800,7 +797,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u16 ^ emu->res.u16) & 0x8000, F_OF); } else { @@ -815,7 +812,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u32 ^ emu->res.u32) & 0x80000000, F_OF); } else { @@ -830,7 +827,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(cc, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); if (cnt == 1) { CONDITIONAL_SET_FLAG((emu->op1.u64 ^ emu->res.u64) & 0x8000000000000000LL, F_OF); } else { @@ -840,8 +837,8 @@ void UpdateFlags(x64emu_t *emu) break; case d_sub8: CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u8 & (~emu->op1.u8 | emu->op2.u8)) | (~emu->op1.u8 & emu->op2.u8); CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); @@ -849,8 +846,8 @@ void UpdateFlags(x64emu_t *emu) break; case d_sub16: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u16 & (~emu->op1.u16 | emu->op2.u16)) | (~emu->op1.u16 & emu->op2.u16); CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); @@ -859,7 +856,7 @@ void UpdateFlags(x64emu_t *emu) case d_sub32: CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u32 & (~emu->op1.u32 | emu->op2.u32)) | (~emu->op1.u32 & emu->op2.u32); CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); @@ -868,7 +865,7 @@ void UpdateFlags(x64emu_t *emu) case d_sub64: CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u64 & (~emu->op1.u64 | emu->op2.u64)) | (~emu->op1.u64 & emu->op2.u64); CONDITIONAL_SET_FLAG(bc & 0x8000000000000000LL, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 62), F_OF); @@ -876,41 +873,40 @@ void UpdateFlags(x64emu_t *emu) break; case d_xor8: CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u8 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); + CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_xor16: CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u16 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); + CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_xor32: CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u32 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); + CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_xor64: CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u64 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); CLEAR_FLAG(F_CF); CLEAR_FLAG(F_AF); + CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); + CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); break; case d_cmp8: - CLEAR_FLAG(F_CF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u8 & (~emu->op1.u8 | emu->op2.u8)) | (~emu->op1.u8 & emu->op2.u8); CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); @@ -919,7 +915,7 @@ void UpdateFlags(x64emu_t *emu) case d_cmp16: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u16 & (~emu->op1.u16 | emu->op2.u16)) | (~emu->op1.u16 & emu->op2.u16); CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); @@ -928,7 +924,7 @@ void UpdateFlags(x64emu_t *emu) case d_cmp32: CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u32 & (~emu->op1.u32 | emu->op2.u32)) | (~emu->op1.u32 & emu->op2.u32); CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); @@ -937,7 +933,7 @@ void UpdateFlags(x64emu_t *emu) case d_cmp64: CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u64 & (~emu->op1.u64 | emu->op2.u64)) | (~emu->op1.u64 & emu->op2.u64); CONDITIONAL_SET_FLAG(bc & 0x8000000000000000LL, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 62), F_OF); @@ -946,36 +942,36 @@ void UpdateFlags(x64emu_t *emu) case d_tst8: CLEAR_FLAG(F_OF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u8 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); CLEAR_FLAG(F_CF); break; case d_tst16: CLEAR_FLAG(F_OF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u16 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); CLEAR_FLAG(F_CF); break; case d_tst32: CLEAR_FLAG(F_OF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u32 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); CLEAR_FLAG(F_CF); break; case d_tst64: CLEAR_FLAG(F_OF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(emu->res.u64 == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); CLEAR_FLAG(F_CF); break; case d_adc8: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x100, F_CF); - CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); + CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u8 & emu->op2.u8) | ((~emu->res.u8) & (emu->op1.u8 | emu->op2.u8)); CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -984,7 +980,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(emu->res.u32 & 0x10000, F_CF); CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u16 & emu->op2.u16) | ((~emu->res.u16) & (emu->op1.u16 | emu->op2.u16)); CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -993,7 +989,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(emu->res.u64 & 0x100000000L, F_CF); CONDITIONAL_SET_FLAG((emu->res.u32 & 0xffffffff) == 0, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op1.u32 & emu->op2.u32) | ((~emu->res.u32) & (emu->op1.u32 | emu->op2.u32)); CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -1008,7 +1004,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(hi & 0x10000, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op2.u32 & emu->op1.u32) | ((~emu->res.u32) & (emu->op2.u32 | emu->op1.u32)); CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -1023,7 +1019,7 @@ void UpdateFlags(x64emu_t *emu) CONDITIONAL_SET_FLAG(hi & 0x100000000L, F_CF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); cc = (emu->op2.u64 & emu->op1.u64) | ((~emu->res.u64) & (emu->op2.u64 | emu->op1.u64)); CONDITIONAL_SET_FLAG(XOR2(cc >> 62), F_OF); CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); @@ -1031,7 +1027,7 @@ void UpdateFlags(x64emu_t *emu) case d_sbb8: CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF); CONDITIONAL_SET_FLAG((emu->res.u8 & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u8 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u8 & (~emu->op1.u8 | emu->op2.u8)) | (~emu->op1.u8 & emu->op2.u8); CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); @@ -1040,7 +1036,7 @@ void UpdateFlags(x64emu_t *emu) case d_sbb16: CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF); CONDITIONAL_SET_FLAG((emu->res.u16 & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u16 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u16 & (~emu->op1.u16 | emu->op2.u16)) | (~emu->op1.u16 & emu->op2.u16); CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); @@ -1049,7 +1045,7 @@ void UpdateFlags(x64emu_t *emu) case d_sbb32: CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u32 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u32 & (~emu->op1.u32 | emu->op2.u32)) | (~emu->op1.u32 & emu->op2.u32); CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); @@ -1058,7 +1054,7 @@ void UpdateFlags(x64emu_t *emu) case d_sbb64: CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF); CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(emu->res.u64 & 0xff), F_PF); + CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF); bc = (emu->res.u64 & (~emu->op1.u64 | emu->op2.u64)) | (~emu->op1.u64 & emu->op2.u64); CONDITIONAL_SET_FLAG(bc & 0x8000000000000000LL, F_CF); CONDITIONAL_SET_FLAG(XOR2(bc >> 62), F_OF); @@ -1116,33 +1112,6 @@ void UpdateFlags(x64emu_t *emu) case d_unknown: printf_log(LOG_NONE, "Box64: %p trying to evaluate Unknown deferred Flags\n", (void*)R_RIP); break; - - case d_dec8i: - case d_dec16i: - case d_dec32i: - case d_dec64i: - case d_inc8i: - case d_inc16i: - case d_inc32i: - case d_inc64i: - { - deferred_flags_t df = emu->df - (d_dec8i - d_dec8); - if(emu->df_sav!=d_none) { - // compute CF - multiuint_t op1 = emu->op1; - multiuint_t res = emu->res; - emu->df = emu->df_sav; - emu->op1 = emu->op1_sav; - emu->res = emu->res_sav; - emu->df_sav = d_none; - UpdateFlags(emu); - emu->op1 = op1; - emu->res = res; - } - emu->df = df; - } - UpdateFlags(emu); - break; } RESET_FLAGS(emu); } diff --git a/src/include/regs.h b/src/include/regs.h index 5b2a9c410..6589ac2e2 100644 --- a/src/include/regs.h +++ b/src/include/regs.h @@ -119,14 +119,6 @@ typedef enum { d_ror16, d_ror32, d_ror64, - d_dec8i, // interpreter version, to handle the CF flags that is untouched - d_dec16i, - d_dec32i, - d_dec64i, - d_inc8i, - d_inc16i, - d_inc32i, - d_inc64i, d_shrd16, d_shrd32, d_shrd64, diff --git a/src/tools/callback.c b/src/tools/callback.c index 3c58bc6ed..4cdcc754e 100644 --- a/src/tools/callback.c +++ b/src/tools/callback.c @@ -278,9 +278,6 @@ uint64_t RunSafeFunction(uintptr_t fnc, int nargs, ...) multiuint_t old_op1 = emu->op1; multiuint_t old_op2 = emu->op2; multiuint_t old_res = emu->res; - multiuint_t old_op1_sav= emu->op1_sav; - multiuint_t old_res_sav= emu->res_sav; - deferred_flags_t old_df_sav= emu->df_sav; R_RSP -= stackn*sizeof(void*); // need to push in reverse order @@ -322,9 +319,6 @@ uint64_t RunSafeFunction(uintptr_t fnc, int nargs, ...) emu->op1 = old_op1; emu->op2 = old_op2; emu->res = old_res; - emu->op1_sav = old_op1_sav; - emu->res_sav = old_res_sav; - emu->df_sav = old_df_sav; return ret; }