(cpu64) Merged lazy_flags.cc.

This commit is contained in:
Kevin Lawton 2002-09-15 00:18:41 +00:00
parent 278e27d5fe
commit 425a8cda81
2 changed files with 270 additions and 56 deletions

View File

@ -54,7 +54,6 @@ OBJS32 = \
flag_ctrl_pro.o \
segment_ctrl_pro.o \
stack_pro.o \
lazy_flags.o \
paging.o \
debugstuff.o \
arith32.o \
@ -104,6 +103,7 @@ OBJSXX = \
data_xfer32.o \
exception.o \
proc_ctrl.o \
lazy_flags.o \
# Objects which are only used for x86-64 code, but which have been

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: lazy_flags.cc,v 1.7 2002-09-08 04:08:14 kevinlawton Exp $
// $Id: lazy_flags.cc,v 1.8 2002-09-15 00:18:41 kevinlawton Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -63,6 +63,13 @@ BX_CPU_C::get_CF(void)
cf = (BX_CPU_THIS_PTR oszapc.result_32 <
BX_CPU_THIS_PTR oszapc.op1_32);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_XADD64:
cf = (BX_CPU_THIS_PTR oszapc.result_64 <
BX_CPU_THIS_PTR oszapc.op1_64);
break;
#endif
case BX_INSTR_ADC8:
cf =
(BX_CPU_THIS_PTR oszapc.result_8 <
@ -87,6 +94,16 @@ BX_CPU_C::get_CF(void)
BX_CPU_THIS_PTR oszapc.result_32 ==
BX_CPU_THIS_PTR oszapc.op1_32);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADC64:
cf =
(BX_CPU_THIS_PTR oszapc.result_64 <
BX_CPU_THIS_PTR oszapc.op1_64) ||
(BX_CPU_THIS_PTR oszapc.prev_CF &&
BX_CPU_THIS_PTR oszapc.result_64 ==
BX_CPU_THIS_PTR oszapc.op1_64);
break;
#endif
case BX_INSTR_SUB8:
case BX_INSTR_CMP8:
case BX_INSTR_CMPS8:
@ -108,6 +125,15 @@ BX_CPU_C::get_CF(void)
cf = (BX_CPU_THIS_PTR oszapc.op1_32 <
BX_CPU_THIS_PTR oszapc.op2_32);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SUB64:
case BX_INSTR_CMP64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
cf = (BX_CPU_THIS_PTR oszapc.op1_64 <
BX_CPU_THIS_PTR oszapc.op2_64);
break;
#endif
case BX_INSTR_SBB8:
cf =
(BX_CPU_THIS_PTR oszapc.op1_8 <
@ -116,34 +142,51 @@ BX_CPU_C::get_CF(void)
BX_CPU_THIS_PTR oszapc.prev_CF);
break;
case BX_INSTR_SBB16:
cf =
cf =
(BX_CPU_THIS_PTR oszapc.op1_16 <
BX_CPU_THIS_PTR oszapc.result_16) ||
((BX_CPU_THIS_PTR oszapc.op2_16==0xffff) &&
BX_CPU_THIS_PTR oszapc.prev_CF);
break;
case BX_INSTR_SBB32:
cf =
cf =
(BX_CPU_THIS_PTR oszapc.op1_32 <
BX_CPU_THIS_PTR oszapc.result_32) ||
((BX_CPU_THIS_PTR oszapc.op2_32==0xffffffff) &&
BX_CPU_THIS_PTR oszapc.prev_CF);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SBB64:
cf =
(BX_CPU_THIS_PTR oszapc.op1_64 <
BX_CPU_THIS_PTR oszapc.result_64) ||
((BX_CPU_THIS_PTR oszapc.op2_64==BX_CONST64(0xffffffffffffffff)) &&
BX_CPU_THIS_PTR oszapc.prev_CF);
break;
#endif
case BX_INSTR_NEG8:
cf =
BX_CPU_THIS_PTR oszapc.op1_8 != 0;
cf = BX_CPU_THIS_PTR oszapc.op1_8 != 0;
break;
case BX_INSTR_NEG16:
cf =
BX_CPU_THIS_PTR oszapc.op1_16 != 0;
cf = BX_CPU_THIS_PTR oszapc.op1_16 != 0;
break;
case BX_INSTR_NEG32:
cf =
BX_CPU_THIS_PTR oszapc.op1_32 != 0;
cf = BX_CPU_THIS_PTR oszapc.op1_32 != 0;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_NEG64:
cf = BX_CPU_THIS_PTR oszapc.op1_64 != 0;
break;
#endif
case BX_INSTR_OR8:
case BX_INSTR_OR16:
case BX_INSTR_OR32:
#if BX_SUPPORT_X86_64
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
#endif
case BX_INSTR_AND8:
case BX_INSTR_AND16:
case BX_INSTR_AND32:
@ -170,6 +213,13 @@ BX_CPU_C::get_CF(void)
(BX_CPU_THIS_PTR oszapc.op1_32 >>
(BX_CPU_THIS_PTR oszapc.op2_32 - 1)) & 0x01;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SHR64:
cf =
(BX_CPU_THIS_PTR oszapc.op1_64 >>
(BX_CPU_THIS_PTR oszapc.op2_64 - 1)) & 0x01;
break;
#endif
case BX_INSTR_SHL8:
if (BX_CPU_THIS_PTR oszapc.op2_8 <= 8) {
cf =
@ -195,6 +245,13 @@ BX_CPU_C::get_CF(void)
(BX_CPU_THIS_PTR oszapc.op1_32 >>
(32 - BX_CPU_THIS_PTR oszapc.op2_32)) & 0x01;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SHL64:
cf =
(BX_CPU_THIS_PTR oszapc.op1_64 >>
(32 - BX_CPU_THIS_PTR oszapc.op2_64)) & 0x01;
break;
#endif
default:
cf = 0; // Keep compiler quiet.
BX_PANIC(("get_CF: OSZAPC: unknown instr %u",
@ -262,21 +319,46 @@ BX_CPU_C::get_AF(void)
BX_CPU_THIS_PTR oszapc.op2_32) ^
BX_CPU_THIS_PTR oszapc.result_32) & 0x10;
break;
case BX_INSTR_NEG8:
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_ADC64:
case BX_INSTR_SUB64:
case BX_INSTR_SBB64:
case BX_INSTR_CMP64:
case BX_INSTR_XADD64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
af =
(BX_CPU_THIS_PTR oszapc.op1_8 & 0x0f) > 0;
((BX_CPU_THIS_PTR oszapc.op1_64 ^
BX_CPU_THIS_PTR oszapc.op2_64) ^
BX_CPU_THIS_PTR oszapc.result_64) & 0x10;
break;
#endif
case BX_INSTR_NEG8:
af = (BX_CPU_THIS_PTR oszapc.op1_8 & 0x0f) > 0;
break;
case BX_INSTR_NEG16:
af =
(BX_CPU_THIS_PTR oszapc.op1_16 & 0x0f) > 0;
af = (BX_CPU_THIS_PTR oszapc.op1_16 & 0x0f) > 0;
break;
case BX_INSTR_NEG32:
af =
(BX_CPU_THIS_PTR oszapc.op1_32 & 0x0f) > 0;
af = (BX_CPU_THIS_PTR oszapc.op1_32 & 0x0f) > 0;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_NEG64:
af = (BX_CPU_THIS_PTR oszapc.op1_64 & 0x0f) > 0;
break;
#endif
case BX_INSTR_OR8:
case BX_INSTR_OR16:
case BX_INSTR_OR32:
#if BX_SUPPORT_X86_64
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
case BX_INSTR_SHR64:
case BX_INSTR_SHL64:
#endif
case BX_INSTR_AND8:
case BX_INSTR_AND16:
case BX_INSTR_AND32:
@ -296,7 +378,7 @@ BX_CPU_C::get_AF(void)
/* undefined */
break;
default:
af = 0; // Keep compiler quiet.
af = 0; // Keep compiler quiet.
BX_PANIC(("get_AF: OSZAPC: unknown instr %u",
(unsigned) BX_CPU_THIS_PTR oszapc.instr));
}
@ -308,29 +390,33 @@ BX_CPU_C::get_AF(void)
case BX_LF_INDEX_OSZAP:
switch (BX_CPU_THIS_PTR oszap.instr) {
case BX_INSTR_INC8:
af =
(BX_CPU_THIS_PTR oszap.result_8 & 0x0f) == 0;
af = (BX_CPU_THIS_PTR oszap.result_8 & 0x0f) == 0;
break;
case BX_INSTR_INC16:
af =
(BX_CPU_THIS_PTR oszap.result_16 & 0x0f) == 0;
af = (BX_CPU_THIS_PTR oszap.result_16 & 0x0f) == 0;
break;
case BX_INSTR_INC32:
af =
(BX_CPU_THIS_PTR oszap.result_32 & 0x0f) == 0;
af = (BX_CPU_THIS_PTR oszap.result_32 & 0x0f) == 0;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_INC64:
af = (BX_CPU_THIS_PTR oszap.result_64 & 0x0f) == 0;
break;
#endif
case BX_INSTR_DEC8:
af =
(BX_CPU_THIS_PTR oszap.result_8 & 0x0f) == 0x0f;
af = (BX_CPU_THIS_PTR oszap.result_8 & 0x0f) == 0x0f;
break;
case BX_INSTR_DEC16:
af =
(BX_CPU_THIS_PTR oszap.result_16 & 0x0f) == 0x0f;
af = (BX_CPU_THIS_PTR oszap.result_16 & 0x0f) == 0x0f;
break;
case BX_INSTR_DEC32:
af =
(BX_CPU_THIS_PTR oszap.result_32 & 0x0f) == 0x0f;
af = (BX_CPU_THIS_PTR oszap.result_32 & 0x0f) == 0x0f;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_DEC64:
af = (BX_CPU_THIS_PTR oszap.result_64 & 0x0f) == 0x0f;
break;
#endif
default:
af = 0; // Keep compiler quiet.
BX_PANIC(("get_AF: OSZAP: unknown instr %u",
@ -410,6 +496,25 @@ BX_CPU_C::get_ZF(void)
case BX_INSTR_SHL32:
zf = (BX_CPU_THIS_PTR oszapc.result_32 == 0);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_ADC64:
case BX_INSTR_SUB64:
case BX_INSTR_SBB64:
case BX_INSTR_CMP64:
case BX_INSTR_NEG64:
case BX_INSTR_XADD64:
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
case BX_INSTR_SHR64:
case BX_INSTR_SHL64:
zf = (BX_CPU_THIS_PTR oszapc.result_64 == 0);
break;
#endif
default:
zf = 0;
BX_PANIC(("get_ZF: OSZAPC: unknown instr"));
@ -433,8 +538,14 @@ BX_CPU_C::get_ZF(void)
case BX_INSTR_DEC32:
zf = (BX_CPU_THIS_PTR oszap.result_32 == 0);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_INC64:
case BX_INSTR_DEC64:
zf = (BX_CPU_THIS_PTR oszap.result_64 == 0);
break;
#endif
default:
zf = 0;
zf = 0;
BX_PANIC(("get_ZF: OSZAP: unknown instr"));
}
BX_CPU_THIS_PTR lf_flags_status &= 0xff0fff;
@ -475,8 +586,7 @@ BX_CPU_C::get_SF(void)
case BX_INSTR_SCAS8:
case BX_INSTR_SHR8:
case BX_INSTR_SHL8:
sf =
(BX_CPU_THIS_PTR oszapc.result_8 >= 0x80);
sf = (BX_CPU_THIS_PTR oszapc.result_8 >= 0x80);
break;
case BX_INSTR_ADD16:
case BX_INSTR_ADC16:
@ -493,8 +603,7 @@ BX_CPU_C::get_SF(void)
case BX_INSTR_SCAS16:
case BX_INSTR_SHR16:
case BX_INSTR_SHL16:
sf =
(BX_CPU_THIS_PTR oszapc.result_16 >= 0x8000);
sf = (BX_CPU_THIS_PTR oszapc.result_16 >= 0x8000);
break;
case BX_INSTR_ADD32:
case BX_INSTR_ADC32:
@ -511,9 +620,27 @@ BX_CPU_C::get_SF(void)
case BX_INSTR_SCAS32:
case BX_INSTR_SHR32:
case BX_INSTR_SHL32:
sf =
(BX_CPU_THIS_PTR oszapc.result_32 >= 0x80000000);
sf = (BX_CPU_THIS_PTR oszapc.result_32 >= 0x80000000);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_ADC64:
case BX_INSTR_SUB64:
case BX_INSTR_SBB64:
case BX_INSTR_CMP64:
case BX_INSTR_NEG64:
case BX_INSTR_XADD64:
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
case BX_INSTR_SHR64:
case BX_INSTR_SHL64:
sf = (BX_CPU_THIS_PTR oszapc.result_64 >= BX_CONST64(0x8000000000000000));
break;
#endif
default:
sf = 0; // Keep compiler quiet.
BX_PANIC(("get_SF: OSZAPC: unknown instr"));
@ -527,19 +654,22 @@ BX_CPU_C::get_SF(void)
switch (BX_CPU_THIS_PTR oszap.instr) {
case BX_INSTR_INC8:
case BX_INSTR_DEC8:
sf =
(BX_CPU_THIS_PTR oszap.result_8 >= 0x80);
sf = (BX_CPU_THIS_PTR oszap.result_8 >= 0x80);
break;
case BX_INSTR_INC16:
case BX_INSTR_DEC16:
sf =
(BX_CPU_THIS_PTR oszap.result_16 >= 0x8000);
sf = (BX_CPU_THIS_PTR oszap.result_16 >= 0x8000);
break;
case BX_INSTR_INC32:
case BX_INSTR_DEC32:
sf =
(BX_CPU_THIS_PTR oszap.result_32 >= 0x80000000);
sf = (BX_CPU_THIS_PTR oszap.result_32 >= 0x80000000);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_INC64:
case BX_INSTR_DEC64:
sf = (BX_CPU_THIS_PTR oszap.result_64 >= BX_CONST64(0x8000000000000000));
break;
#endif
default:
sf = 0; // Keep compiler quiet.
BX_PANIC(("get_SF: OSZAP: unknown instr"));
@ -561,6 +691,9 @@ BX_CPU_C::get_OF(void)
Bit8u op1_b7, op2_b7, result_b7;
Bit16u op1_b15, op2_b15, result_b15;
Bit32u op1_b31, op2_b31, result_b31;
#if BX_SUPPORT_X86_64
Bit64u op1_b63, op2_b63, result_b63;
#endif
unsigned of;
switch ( (BX_CPU_THIS_PTR lf_flags_status>>20) & 0x00000f ) {
@ -596,6 +729,17 @@ BX_CPU_C::get_OF(void)
of = (op1_b31 == op2_b31) && (result_b31 ^ op2_b31);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_ADC64:
case BX_INSTR_XADD64:
op1_b63 = BX_CPU_THIS_PTR oszapc.op1_64 & BX_CONST64(0x8000000000000000);
op2_b63 = BX_CPU_THIS_PTR oszapc.op2_64 & BX_CONST64(0x8000000000000000);
result_b63 = BX_CPU_THIS_PTR oszapc.result_64 & BX_CONST64(0x8000000000000000);
of = (op1_b63 == op2_b63) && (result_b63 ^ op2_b63);
break;
#endif
case BX_INSTR_SUB8:
case BX_INSTR_SBB8:
case BX_INSTR_CMP8:
@ -629,6 +773,19 @@ BX_CPU_C::get_OF(void)
of = (op1_b31 ^ op2_b31) && (op1_b31 ^ result_b31);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SUB64:
case BX_INSTR_SBB64:
case BX_INSTR_CMP64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
op1_b63 = BX_CPU_THIS_PTR oszapc.op1_64 & BX_CONST64(0x8000000000000000);
op2_b63 = BX_CPU_THIS_PTR oszapc.op2_64 & BX_CONST64(0x8000000000000000);
result_b63 = BX_CPU_THIS_PTR oszapc.result_64 & BX_CONST64(0x8000000000000000);
of = (op1_b63 ^ op2_b63) && (op1_b63 ^ result_b63);
break;
#endif
case BX_INSTR_NEG8:
of = (BX_CPU_THIS_PTR oszapc.op1_8 == 0x80);
break;
@ -638,9 +795,20 @@ BX_CPU_C::get_OF(void)
case BX_INSTR_NEG32:
of = (BX_CPU_THIS_PTR oszapc.op1_32 == 0x80000000);
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_NEG64:
of = (BX_CPU_THIS_PTR oszapc.op1_64 == BX_CONST64(0x8000000000000000));
break;
#endif
case BX_INSTR_OR8:
case BX_INSTR_OR16:
case BX_INSTR_OR32:
#if BX_SUPPORT_X86_64
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
#endif
case BX_INSTR_AND8:
case BX_INSTR_AND16:
case BX_INSTR_AND32:
@ -670,6 +838,14 @@ BX_CPU_C::get_OF(void)
else
of = (BX_CPU_THIS_PTR eflags.val32 >> 11) & 1; // Old val
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SHR64:
if (BX_CPU_THIS_PTR oszapc.op2_64 == 1)
of = (BX_CPU_THIS_PTR oszapc.op1_64 >= BX_CONST64(0x8000000000000000));
else
of = (BX_CPU_THIS_PTR eflags.val32 >> 11) & 1; // Old val
break;
#endif
case BX_INSTR_SHL8:
if (BX_CPU_THIS_PTR oszapc.op2_8 == 1)
of = ((BX_CPU_THIS_PTR oszapc.op1_8 ^
@ -691,6 +867,15 @@ BX_CPU_C::get_OF(void)
else
of = (BX_CPU_THIS_PTR eflags.val32 >> 11) & 1; // Old val
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_SHL64:
if (BX_CPU_THIS_PTR oszapc.op2_64 == 1)
of = ((BX_CPU_THIS_PTR oszapc.op1_64 ^
BX_CPU_THIS_PTR oszapc.result_64) & BX_CONST64(0x8000000000000000)) > 0;
else
of = (BX_CPU_THIS_PTR eflags.val32 >> 11) & 1; // Old val
break;
#endif
default:
of = 0; // Keep compiler happy.
BX_PANIC(("get_OF: OSZAPC: unknown instr"));
@ -703,31 +888,35 @@ BX_CPU_C::get_OF(void)
case BX_LF_INDEX_OSZAP:
switch (BX_CPU_THIS_PTR oszap.instr) {
case BX_INSTR_INC8:
of =
BX_CPU_THIS_PTR oszap.result_8 == 0x80;
of = BX_CPU_THIS_PTR oszap.result_8 == 0x80;
break;
case BX_INSTR_INC16:
of =
BX_CPU_THIS_PTR oszap.result_16 == 0x8000;
of = BX_CPU_THIS_PTR oszap.result_16 == 0x8000;
break;
case BX_INSTR_INC32:
of =
BX_CPU_THIS_PTR oszap.result_32 == 0x80000000;
of = BX_CPU_THIS_PTR oszap.result_32 == 0x80000000;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_INC64:
of = BX_CPU_THIS_PTR oszap.result_64 == BX_CONST64(0x8000000000000000);
break;
#endif
case BX_INSTR_DEC8:
of =
BX_CPU_THIS_PTR oszap.result_8 == 0x7F;
of = BX_CPU_THIS_PTR oszap.result_8 == 0x7F;
break;
case BX_INSTR_DEC16:
of =
BX_CPU_THIS_PTR oszap.result_16 == 0x7FFF;
of = BX_CPU_THIS_PTR oszap.result_16 == 0x7FFF;
break;
case BX_INSTR_DEC32:
of =
BX_CPU_THIS_PTR oszap.result_32 == 0x7FFFFFFF;
of = BX_CPU_THIS_PTR oszap.result_32 == 0x7FFFFFFF;
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_DEC64:
of = BX_CPU_THIS_PTR oszap.result_64 == BX_CONST64(0x7FFFFFFFFFFFFFFF);
break;
#endif
default:
of = 0; // Keep compiler happy.
of = 0; // Keep compiler happy.
BX_PANIC(("get_OF: OSZAP: unknown instr"));
}
BX_CPU_THIS_PTR lf_flags_status &= 0x0fffff;
@ -802,8 +991,27 @@ BX_CPU_C::get_PF(void)
case BX_INSTR_SHL32:
pf = bx_parity_lookup[(Bit8u) BX_CPU_THIS_PTR oszapc.result_32];
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_ADD64:
case BX_INSTR_ADC64:
case BX_INSTR_SUB64:
case BX_INSTR_SBB64:
case BX_INSTR_CMP64:
case BX_INSTR_NEG64:
case BX_INSTR_XADD64:
case BX_INSTR_OR64:
case BX_INSTR_AND64:
case BX_INSTR_TEST64:
case BX_INSTR_XOR64:
case BX_INSTR_CMPS64:
case BX_INSTR_SCAS64:
case BX_INSTR_SHR64:
case BX_INSTR_SHL64:
pf = bx_parity_lookup[(Bit8u) BX_CPU_THIS_PTR oszapc.result_64];
break;
#endif
default:
pf = 0; // Keep compiler quiet.
pf = 0; // Keep compiler quiet.
BX_PANIC(("get_PF: OSZAPC: unknown instr"));
}
BX_CPU_THIS_PTR lf_flags_status &= 0xffff0f;
@ -825,6 +1033,12 @@ BX_CPU_C::get_PF(void)
case BX_INSTR_DEC32:
pf = bx_parity_lookup[(Bit8u) BX_CPU_THIS_PTR oszap.result_32];
break;
#if BX_SUPPORT_X86_64
case BX_INSTR_INC64:
case BX_INSTR_DEC64:
pf = bx_parity_lookup[(Bit8u) BX_CPU_THIS_PTR oszap.result_64];
break;
#endif
default:
pf = 0; // Keep compiler quiet.
BX_PANIC(("get_PF: OSZAP: unknown instr"));