From: <ssh...@us...> - 2011-11-27 13:23:32
|
Revision: 10798 http://bochs.svn.sourceforge.net/bochs/?rev=10798&view=rev Author: sshwarts Date: 2011-11-27 13:23:26 +0000 (Sun, 27 Nov 2011) Log Message: ----------- fixed flags handling for BMI instructions Modified Paths: -------------- trunk/bochs/cpu/bit16.cc trunk/bochs/cpu/bit32.cc trunk/bochs/cpu/bit64.cc trunk/bochs/cpu/bmi32.cc trunk/bochs/cpu/bmi64.cc trunk/bochs/cpu/cpu.h trunk/bochs/cpu/lazy_flags.h Modified: trunk/bochs/cpu/bit16.cc =================================================================== --- trunk/bochs/cpu/bit16.cc 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/bit16.cc 2011-11-27 13:23:26 UTC (rev 10798) @@ -372,15 +372,8 @@ result_16++; } - if (op1_16 == 0) - assert_CF(); - else - clear_CF(); - - if (result_16 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_16); + set_ZF(! result_16); BX_WRITE_16BIT_REG(i->nnn(), result_16); @@ -398,15 +391,8 @@ result_16++; } - if (op1_16 == 0) - assert_CF(); - else - clear_CF(); - - if (result_16 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_16); + set_ZF(! result_16); BX_WRITE_16BIT_REG(i->nnn(), result_16); Modified: trunk/bochs/cpu/bit32.cc =================================================================== --- trunk/bochs/cpu/bit32.cc 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/bit32.cc 2011-11-27 13:23:26 UTC (rev 10798) @@ -377,15 +377,8 @@ result_32++; } - if (op1_32 == 0) - assert_CF(); - else - clear_CF(); - - if (result_32 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_32); + set_ZF(! result_32); BX_WRITE_32BIT_REGZ(i->nnn(), result_32); @@ -403,15 +396,8 @@ result_32++; } - if (op1_32 == 0) - assert_CF(); - else - clear_CF(); - - if (result_32 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_32); + set_ZF(! result_32); BX_WRITE_32BIT_REGZ(i->nnn(), result_32); Modified: trunk/bochs/cpu/bit64.cc =================================================================== --- trunk/bochs/cpu/bit64.cc 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/bit64.cc 2011-11-27 13:23:26 UTC (rev 10798) @@ -381,15 +381,8 @@ result_64++; } - if (op1_64 == 0) - assert_CF(); - else - clear_CF(); - - if (result_64 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_64); + set_ZF(! result_64); BX_WRITE_64BIT_REG(i->nnn(), result_64); @@ -407,15 +400,8 @@ result_64++; } - if (op1_64 == 0) - assert_CF(); - else - clear_CF(); - - if (result_64 == 0) - assert_ZF(); - else - clear_ZF(); + set_CF(! op1_64); + set_ZF(! result_64); BX_WRITE_64BIT_REG(i->nnn(), result_64); Modified: trunk/bochs/cpu/bmi32.cc =================================================================== --- trunk/bochs/cpu/bmi32.cc 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/bmi32.cc 2011-11-27 13:23:26 UTC (rev 10798) @@ -34,7 +34,7 @@ op1_32 = op1_32 & ~op2_32; - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged BX_WRITE_32BIT_REGZ(i->nnn(), op1_32); @@ -56,11 +56,11 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BLSI_BdEdR(bxInstruction_c *i) { Bit32u op1_32 = BX_READ_32BIT_REG(i->rm()); - bx_bool tmpCF = (op1_32 == 0); + bx_bool tmpCF = (op1_32 != 0); op1_32 = (-op1_32) & op1_32; - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged set_CF(tmpCF); BX_WRITE_32BIT_REGZ(i->vvv(), op1_32); @@ -75,7 +75,7 @@ op1_32 = (op1_32-1) ^ op1_32; - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged set_CF(tmpCF); BX_WRITE_32BIT_REGZ(i->vvv(), op1_32); @@ -90,7 +90,7 @@ op1_32 = (op1_32-1) & op1_32; - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged set_CF(tmpCF); BX_WRITE_32BIT_REGZ(i->vvv(), op1_32); @@ -170,7 +170,7 @@ } } - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged BX_WRITE_32BIT_REGZ(i->nnn(), op1_32); @@ -191,7 +191,7 @@ tmpCF = 1; } - SET_FLAGS_OSZAPC_LOGIC_32(op1_32); + SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged set_CF(tmpCF); BX_WRITE_32BIT_REGZ(i->nnn(), op1_32); Modified: trunk/bochs/cpu/bmi64.cc =================================================================== --- trunk/bochs/cpu/bmi64.cc 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/bmi64.cc 2011-11-27 13:23:26 UTC (rev 10798) @@ -34,7 +34,7 @@ op1_64 = op1_64 & ~op2_64; - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged BX_WRITE_64BIT_REG(i->nnn(), op1_64); @@ -65,11 +65,11 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BLSI_BqEqR(bxInstruction_c *i) { Bit64u op1_64 = BX_READ_64BIT_REG(i->rm()); - bx_bool tmpCF = (op1_64 == 0); + bx_bool tmpCF = (op1_64 != 0); op1_64 = (-op1_64) & op1_64; - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged set_CF(tmpCF); BX_WRITE_64BIT_REG(i->vvv(), op1_64); @@ -84,7 +84,7 @@ op1_64 = (op1_64-1) ^ op1_64; - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged set_CF(tmpCF); BX_WRITE_64BIT_REG(i->vvv(), op1_64); @@ -99,7 +99,7 @@ op1_64 = (op1_64-1) & op1_64; - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged set_CF(tmpCF); BX_WRITE_64BIT_REG(i->vvv(), op1_64); @@ -179,7 +179,7 @@ } } - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged BX_WRITE_64BIT_REG(i->nnn(), op1_64); @@ -200,7 +200,7 @@ tmpCF = 1; } - SET_FLAGS_OSZAPC_LOGIC_64(op1_64); + SET_FLAGS_OSZAxC_LOGIC_64(op1_64); // keep PF unchanged set_CF(tmpCF); BX_WRITE_64BIT_REG(i->nnn(), op1_64); Modified: trunk/bochs/cpu/cpu.h =================================================================== --- trunk/bochs/cpu/cpu.h 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/cpu.h 2011-11-27 13:23:26 UTC (rev 10798) @@ -1117,25 +1117,25 @@ BX_SMF void setEFlags(Bit32u val) BX_CPP_AttrRegparmN(1); - BX_SMF void setEFlagsOSZAPC(Bit32u flags32) { + BX_SMF BX_CPP_INLINE void setEFlagsOSZAPC(Bit32u flags32) { set_OF(1 & ((flags32) >> 11)); set_SF(1 & ((flags32) >> 7)); set_ZF(1 & ((flags32) >> 6)); set_AF(1 & ((flags32) >> 4)); set_PF(1 & ((flags32) >> 2)); set_CF(1 & ((flags32) >> 0)); - } + } - BX_SMF void SET_FLAGS_OxxxxC(Bit32u new_of, Bit32u new_cf) { + BX_SMF BX_CPP_INLINE void SET_FLAGS_OxxxxC(Bit32u new_of, Bit32u new_cf) { Bit32u temp_po = new_of ^ new_cf; BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_PO | LF_MASK_CF); BX_CPU_THIS_PTR oszapc.auxbits |= (temp_po << LF_BIT_PO) | (new_cf << LF_BIT_CF); - } + } - BX_SMF void ASSERT_FLAGS_OxxxxC() { + BX_SMF BX_CPP_INLINE void ASSERT_FLAGS_OxxxxC() { SET_FLAGS_OxxxxC(1, 1); - } + } // ZF BX_SMF BX_CPP_INLINE bx_bool getB_ZF(void) { @@ -1145,19 +1145,19 @@ BX_SMF BX_CPP_INLINE bx_bool get_ZF(void) { return getB_ZF(); } - BX_SMF void set_ZF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_ZF(bx_bool val) { BX_CPU_THIS_PTR oszapc.result |= (1 << 8); BX_CPU_THIS_PTR oszapc.result ^= (val) << 8; BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_ZF); BX_CPU_THIS_PTR oszapc.auxbits |= (val) << LF_BIT_ZF; } - BX_SMF void clear_ZF(void) { + BX_SMF BX_CPP_INLINE void clear_ZF(void) { BX_CPU_THIS_PTR oszapc.result |= (1 << 8); BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_ZF); } - BX_SMF void assert_ZF(void) { + BX_SMF BX_CPP_INLINE void assert_ZF(void) { BX_CPU_THIS_PTR oszapc.result &= ~(1 << 8); BX_CPU_THIS_PTR oszapc.auxbits |= (LF_MASK_ZF); } @@ -1169,65 +1169,65 @@ BX_SMF BX_CPP_INLINE bx_bool get_SF(void) { return getB_SF(); } - BX_SMF void set_SF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_SF(bx_bool val) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result &= ~(BX_CONST64(1) << BX_LF_SIGN_BIT); BX_CPU_THIS_PTR oszapc.result |= ((bx_address)(val)) << BX_LF_SIGN_BIT; } - BX_SMF void clear_SF(void) { + BX_SMF BX_CPP_INLINE void clear_SF(void) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result &= ~(BX_CONST64(1) << BX_LF_SIGN_BIT); } - BX_SMF void assert_SF(void) { + BX_SMF BX_CPP_INLINE void assert_SF(void) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result |= (BX_CONST64(1) << BX_LF_SIGN_BIT); } // PF - bit 2 in EFLAGS, represented by lower 8 bits of oszapc.result - BX_SMF bx_bool getB_PF(void) { + BX_SMF BX_CPP_INLINE bx_bool getB_PF(void) { Bit8u temp = (Bit8u)(255 & BX_CPU_THIS_PTR oszapc.result); temp = (temp ^ (temp >> 4)) & 0x0F; return (0x9669U >> temp) & 1; } - BX_SMF bx_bool get_PF(void) { return getB_PF(); } + BX_SMF BX_CPP_INLINE bx_bool get_PF(void) { return getB_PF(); } - BX_SMF void set_PF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_PF(bx_bool val) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result &= ~(0xFF); BX_CPU_THIS_PTR oszapc.result |= 1 - (val); } - BX_SMF void clear_PF(void) { + BX_SMF BX_CPP_INLINE void clear_PF(void) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result &= ~(0xFF); BX_CPU_THIS_PTR oszapc.result |= 0x01; } - BX_SMF void assert_PF(void) { + BX_SMF BX_CPP_INLINE void assert_PF(void) { set_ZF(getB_ZF()); BX_CPU_THIS_PTR oszapc.result &= ~(0xFF); } // AF - bit 4 in EFLAGS, represented by bit LF_BIT_AF of oszapc.auxbits - BX_SMF bx_bool getB_AF(void) { + BX_SMF BX_CPP_INLINE bx_bool getB_AF(void) { return ((BX_CPU_THIS_PTR oszapc.auxbits >> LF_BIT_AF) & 1); } - BX_SMF bx_bool get_AF(void) { return getB_AF(); } + BX_SMF BX_CPP_INLINE bx_bool get_AF(void) { return getB_AF(); } - BX_SMF void set_AF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_AF(bx_bool val) { BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_AF); BX_CPU_THIS_PTR oszapc.auxbits |= (val) << LF_BIT_AF; } - BX_SMF void clear_AF(void) { + BX_SMF BX_CPP_INLINE void clear_AF(void) { BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_AF); } - BX_SMF void assert_AF(void) { + BX_SMF BX_CPP_INLINE void assert_AF(void) { BX_CPU_THIS_PTR oszapc.auxbits |= (LF_MASK_AF); } @@ -1240,17 +1240,17 @@ return BX_CPU_THIS_PTR oszapc.auxbits & (1U << LF_BIT_CF); } - BX_SMF void set_CF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_CF(bx_bool val) { Bit8u temp_of = getB_OF(); SET_FLAGS_OxxxxC(temp_of, (val)); } - BX_SMF void clear_CF(void) { + BX_SMF BX_CPP_INLINE void clear_CF(void) { Bit8u temp_of = getB_OF(); SET_FLAGS_OxxxxC(temp_of, (0)); } - BX_SMF void assert_CF(void) { + BX_SMF BX_CPP_INLINE void assert_CF(void) { Bit8u temp_of = getB_OF(); SET_FLAGS_OxxxxC(temp_of, (1)); } @@ -1264,17 +1264,17 @@ return (BX_CPU_THIS_PTR oszapc.auxbits + (1U << LF_BIT_PO)) & (1U << LF_BIT_CF); } - BX_SMF void set_OF(bx_bool val) { + BX_SMF BX_CPP_INLINE void set_OF(bx_bool val) { Bit8u temp_cf = getB_CF(); SET_FLAGS_OxxxxC((val), temp_cf); } - BX_SMF void clear_OF(void) { + BX_SMF BX_CPP_INLINE void clear_OF(void) { Bit8u temp_cf = getB_CF(); SET_FLAGS_OxxxxC((0), temp_cf); } - BX_SMF void assert_OF(void) { + BX_SMF BX_CPP_INLINE void assert_OF(void) { Bit8u temp_cf = getB_CF(); SET_FLAGS_OxxxxC((1), temp_cf); } Modified: trunk/bochs/cpu/lazy_flags.h =================================================================== --- trunk/bochs/cpu/lazy_flags.h 2011-11-27 12:13:22 UTC (rev 10797) +++ trunk/bochs/cpu/lazy_flags.h 2011-11-27 13:23:26 UTC (rev 10798) @@ -170,4 +170,23 @@ SET_FLAGS_OSZAP_64(SUB_COUT_VEC((op1_64), (op2_64), (diff_64)), (diff_64)) #endif +// ******************* +// OSZAxC +// ******************* + +/* size, carries, result */ +#define SET_FLAGS_OSZAxC_LOGIC_SIZE(size, lf_result) { \ + set_ZF(!lf_result); \ + BX_CPU_THIS_PTR oszapc.result = ((bx_address)(Bit##size##s)(lf_result) & ~((bx_address)(0xff))) \ + | (BX_CPU_THIS_PTR oszapc.result & 0xff); \ +} + +/* result */ +#define SET_FLAGS_OSZAxC_LOGIC_32(result_32) \ + SET_FLAGS_OSZAxC_LOGIC_SIZE(32, (result_32)) +#if BX_SUPPORT_X86_64 +#define SET_FLAGS_OSZAxC_LOGIC_64(result_64) \ + SET_FLAGS_OSZAxC_LOGIC_SIZE(64, (result_64)) +#endif + #endif // BX_LAZY_FLAGS_DEF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |