2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 00:54:04 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-09-12 23:36:53 +04:00
|
|
|
// Copyright (C) 2001-2011 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2011-09-12 23:36:53 +04:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-01-29 20:13:10 +03:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 01:26:03 +03:00
|
|
|
#ifndef BX_LAZY_FLAGS_DEF
|
|
|
|
#define BX_LAZY_FLAGS_DEF
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-12-04 22:27:23 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
#define BX_LF_SIGN_BIT 63
|
|
|
|
#else
|
|
|
|
#define BX_LF_SIGN_BIT 31
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
typedef struct {
|
2007-12-05 09:17:09 +03:00
|
|
|
bx_address result;
|
2011-09-12 23:36:53 +04:00
|
|
|
bx_address auxbits;
|
2004-08-10 01:28:47 +04:00
|
|
|
} bx_lf_flags_entry;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
// These are the lazy flags bits in oszapc.auxbits which hold lazy state
|
|
|
|
// of zero flag, adjust flag, carry flag, and overflow flag.
|
2010-04-15 09:51:00 +04:00
|
|
|
|
2012-03-17 12:51:52 +04:00
|
|
|
#define LF_BIT_SD (0) /* lazy Sign Flag Delta */
|
2011-09-12 23:36:53 +04:00
|
|
|
#define LF_BIT_AF (3) /* lazy Adjust flag */
|
2012-03-17 12:51:52 +04:00
|
|
|
#define LF_BIT_PDB (8) /* lazy Parity Delta Byte (8 bits) */
|
2011-09-12 23:36:53 +04:00
|
|
|
#define LF_BIT_CF (31) /* lazy Carry Flag */
|
|
|
|
#define LF_BIT_PO (30) /* lazy Partial Overflow = CF ^ OF */
|
2010-04-15 09:51:00 +04:00
|
|
|
|
2012-03-17 12:51:52 +04:00
|
|
|
#define LF_MASK_SD (0x01 << LF_BIT_SD)
|
|
|
|
#define LF_MASK_AF (0x01 << LF_BIT_AF)
|
|
|
|
#define LF_MASK_PDB (0xFF << LF_BIT_PDB)
|
|
|
|
#define LF_MASK_CF (0x01 << LF_BIT_CF)
|
|
|
|
#define LF_MASK_PO (0x01 << LF_BIT_PO)
|
2010-04-15 09:51:00 +04:00
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
#define ADD_COUT_VEC(op1, op2, result) \
|
|
|
|
(((op1) & (op2)) | (((op1) | (op2)) & (~(result))))
|
2010-04-15 09:51:00 +04:00
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
#define SUB_COUT_VEC(op1, op2, result) \
|
|
|
|
(((~(op1)) & (op2)) | ((~((op1) ^ (op2))) & (result)))
|
2010-04-15 09:51:00 +04:00
|
|
|
|
2012-07-12 18:51:54 +04:00
|
|
|
#define GET_ADD_OVERFLOW(op1, op2, result, mask) \
|
|
|
|
((((op1) ^ (result)) & ((op2) ^ (result))) & (mask))
|
2010-04-15 09:51:00 +04:00
|
|
|
|
|
|
|
// *******************
|
2011-09-12 23:36:53 +04:00
|
|
|
// OSZAPC
|
2010-04-15 09:51:00 +04:00
|
|
|
// *******************
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* size, carries, result */
|
|
|
|
#define SET_FLAGS_OSZAPC_SIZE(size, lf_carries, lf_result) { \
|
|
|
|
bx_address temp = ((lf_carries) & (LF_MASK_AF)) | \
|
|
|
|
(((lf_carries) >> (size - 2)) << LF_BIT_PO); \
|
|
|
|
BX_CPU_THIS_PTR oszapc.result = (bx_address)(Bit##size##s)(lf_result); \
|
2012-03-17 12:51:52 +04:00
|
|
|
if ((size) == 32) temp = ((lf_carries) & ~(LF_MASK_PDB | LF_MASK_SD)); \
|
2011-09-12 23:36:53 +04:00
|
|
|
if ((size) == 16) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 16); \
|
|
|
|
if ((size) == 8) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 24); \
|
|
|
|
BX_CPU_THIS_PTR oszapc.auxbits = (bx_address)(Bit32u)temp; \
|
2010-04-15 09:51:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* carries, result */
|
|
|
|
#define SET_FLAGS_OSZAPC_8(carries, result) \
|
|
|
|
SET_FLAGS_OSZAPC_SIZE(8, carries, result)
|
|
|
|
#define SET_FLAGS_OSZAPC_16(carries, result) \
|
|
|
|
SET_FLAGS_OSZAPC_SIZE(16, carries, result)
|
|
|
|
#define SET_FLAGS_OSZAPC_32(carries, result) \
|
|
|
|
SET_FLAGS_OSZAPC_SIZE(32, carries, result)
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2011-09-12 23:36:53 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_64(carries, result) \
|
|
|
|
SET_FLAGS_OSZAPC_SIZE(64, carries, result)
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* result */
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_LOGIC_8(result_8) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_8(0, (result_8))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_LOGIC_16(result_16) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_16(0, (result_16))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_LOGIC_32(result_32) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_32(0, (result_32))
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
#define SET_FLAGS_OSZAPC_LOGIC_64(result_64) \
|
2011-11-26 23:01:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_64(BX_CONST64(0), (result_64))
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* op1, op2, result */
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_ADD_8(op1_8, op2_8, sum_8) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_8(ADD_COUT_VEC((op1_8), (op2_8), (sum_8)), (sum_8))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_ADD_16(op1_16, op2_16, sum_16) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_16(ADD_COUT_VEC((op1_16), (op2_16), (sum_16)), (sum_16))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_ADD_32(op1_32, op2_32, sum_32) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_32(ADD_COUT_VEC((op1_32), (op2_32), (sum_32)), (sum_32))
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
#define SET_FLAGS_OSZAPC_ADD_64(op1_64, op2_64, sum_64) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_64(ADD_COUT_VEC((op1_64), (op2_64), (sum_64)), (sum_64))
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* op1, op2, result */
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_SUB_8(op1_8, op2_8, diff_8) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_8(SUB_COUT_VEC((op1_8), (op2_8), (diff_8)), (diff_8))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_SUB_16(op1_16, op2_16, diff_16) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_16(SUB_COUT_VEC((op1_16), (op2_16), (diff_16)), (diff_16))
|
2010-04-15 09:51:00 +04:00
|
|
|
#define SET_FLAGS_OSZAPC_SUB_32(op1_32, op2_32, diff_32) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_32(SUB_COUT_VEC((op1_32), (op2_32), (diff_32)), (diff_32))
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
#define SET_FLAGS_OSZAPC_SUB_64(op1_64, op2_64, diff_64) \
|
2011-09-12 23:36:53 +04:00
|
|
|
SET_FLAGS_OSZAPC_64(SUB_COUT_VEC((op1_64), (op2_64), (diff_64)), (diff_64))
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
// *******************
|
|
|
|
// OSZAP
|
|
|
|
// *******************
|
|
|
|
|
|
|
|
/* size, carries, result */
|
|
|
|
#define SET_FLAGS_OSZAP_SIZE(size, lf_carries, lf_result) { \
|
|
|
|
bx_address temp = ((lf_carries) & (LF_MASK_AF)) | \
|
|
|
|
(((lf_carries) >> (size - 2)) << LF_BIT_PO); \
|
2012-03-17 12:51:52 +04:00
|
|
|
if ((size) == 32) temp = ((lf_carries) & ~(LF_MASK_PDB | LF_MASK_SD)); \
|
2011-09-12 23:36:53 +04:00
|
|
|
if ((size) == 16) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 16); \
|
|
|
|
if ((size) == 8) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 24); \
|
|
|
|
BX_CPU_THIS_PTR oszapc.result = (bx_address)(Bit##size##s)(lf_result); \
|
|
|
|
bx_address delta_c = (BX_CPU_THIS_PTR oszapc.auxbits ^ temp) & LF_MASK_CF; \
|
|
|
|
delta_c ^= (delta_c >> 1); \
|
|
|
|
BX_CPU_THIS_PTR oszapc.auxbits = (bx_address)(Bit32u)(temp ^ delta_c); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* carries, result */
|
|
|
|
#define SET_FLAGS_OSZAP_8(carries, result) \
|
|
|
|
SET_FLAGS_OSZAP_SIZE(8, carries, result)
|
|
|
|
#define SET_FLAGS_OSZAP_16(carries, result) \
|
|
|
|
SET_FLAGS_OSZAP_SIZE(16, carries, result)
|
|
|
|
#define SET_FLAGS_OSZAP_32(carries, result) \
|
|
|
|
SET_FLAGS_OSZAP_SIZE(32, carries, result)
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
#define SET_FLAGS_OSZAP_64(carries, result) \
|
|
|
|
SET_FLAGS_OSZAP_SIZE(64, carries, result)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* op1, op2, result */
|
|
|
|
#define SET_FLAGS_OSZAP_ADD_8(op1_8, op2_8, sum_8) \
|
|
|
|
SET_FLAGS_OSZAP_8(ADD_COUT_VEC((op1_8), (op2_8), (sum_8)), (sum_8))
|
|
|
|
#define SET_FLAGS_OSZAP_ADD_16(op1_16, op2_16, sum_16) \
|
|
|
|
SET_FLAGS_OSZAP_16(ADD_COUT_VEC((op1_16), (op2_16), (sum_16)), (sum_16))
|
|
|
|
#define SET_FLAGS_OSZAP_ADD_32(op1_32, op2_32, sum_32) \
|
|
|
|
SET_FLAGS_OSZAP_32(ADD_COUT_VEC((op1_32), (op2_32), (sum_32)), (sum_32))
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2011-09-12 23:36:53 +04:00
|
|
|
#define SET_FLAGS_OSZAP_ADD_64(op1_64, op2_64, sum_64) \
|
|
|
|
SET_FLAGS_OSZAP_64(ADD_COUT_VEC((op1_64), (op2_64), (sum_64)), (sum_64))
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-09-12 23:36:53 +04:00
|
|
|
/* op1, op2, result */
|
|
|
|
#define SET_FLAGS_OSZAP_SUB_8(op1_8, op2_8, diff_8) \
|
|
|
|
SET_FLAGS_OSZAP_8(SUB_COUT_VEC((op1_8), (op2_8), (diff_8)), (diff_8))
|
|
|
|
#define SET_FLAGS_OSZAP_SUB_16(op1_16, op2_16, diff_16) \
|
|
|
|
SET_FLAGS_OSZAP_16(SUB_COUT_VEC((op1_16), (op2_16), (diff_16)), (diff_16))
|
|
|
|
#define SET_FLAGS_OSZAP_SUB_32(op1_32, op2_32, diff_32) \
|
|
|
|
SET_FLAGS_OSZAP_32(SUB_COUT_VEC((op1_32), (op2_32), (diff_32)), (diff_32))
|
2010-04-15 09:51:00 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2011-09-12 23:36:53 +04:00
|
|
|
#define SET_FLAGS_OSZAP_SUB_64(op1_64, op2_64, diff_64) \
|
|
|
|
SET_FLAGS_OSZAP_64(SUB_COUT_VEC((op1_64), (op2_64), (diff_64)), (diff_64))
|
2010-04-15 09:51:00 +04:00
|
|
|
#endif
|
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
// *******************
|
|
|
|
// OSZAxC
|
|
|
|
// *******************
|
|
|
|
|
|
|
|
/* size, carries, result */
|
|
|
|
#define SET_FLAGS_OSZAxC_LOGIC_SIZE(size, lf_result) { \
|
2011-11-29 23:50:26 +04:00
|
|
|
bx_bool saved_PF = getB_PF(); \
|
2011-12-02 23:40:31 +04:00
|
|
|
SET_FLAGS_OSZAPC_SIZE(size, (Bit##size##u)(0), lf_result); \
|
2011-11-29 23:50:26 +04:00
|
|
|
set_PF(saved_PF); \
|
2011-11-27 17:23:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2008-03-23 01:26:03 +03:00
|
|
|
#endif // BX_LAZY_FLAGS_DEF
|