2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 00:54:04 +03:00
|
|
|
// $Id$
|
2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-02-28 01:12:02 +04:00
|
|
|
// Copyright (C) 2001-2014 The Bochs Project
|
2007-12-07 13:59:18 +03: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
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BSF_GqEqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
if (op2_64 == 0) {
|
2011-06-28 20:04:40 +04:00
|
|
|
assert_ZF(); /* op1_64 undefined */
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
2008-07-13 19:52:55 +04:00
|
|
|
else {
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit64u op1_64 = 0;
|
2008-07-13 19:52:55 +04:00
|
|
|
while ((op2_64 & 0x01) == 0) {
|
|
|
|
op1_64++;
|
|
|
|
op2_64 >>= 1;
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 19:52:55 +04:00
|
|
|
SET_FLAGS_OSZAPC_LOGIC_64(op1_64);
|
2011-06-28 20:04:40 +04:00
|
|
|
clear_ZF();
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2008-07-13 19:52:55 +04:00
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BSR_GqEqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
if (op2_64 == 0) {
|
2011-06-28 20:04:40 +04:00
|
|
|
assert_ZF(); /* op1_64 undefined */
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
2008-07-13 19:52:55 +04:00
|
|
|
else {
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit64u op1_64 = 63;
|
2008-07-13 19:52:55 +04:00
|
|
|
while ((op2_64 & BX_CONST64(0x8000000000000000)) == 0) {
|
|
|
|
op1_64--;
|
|
|
|
op2_64 <<= 1;
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 19:52:55 +04:00
|
|
|
SET_FLAGS_OSZAPC_LOGIC_64(op1_64);
|
2011-06-28 22:53:20 +04:00
|
|
|
clear_ZF();
|
2008-02-03 00:46:54 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2008-07-13 19:52:55 +04:00
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EqGqM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
Bit64s displacement64;
|
|
|
|
Bit64u index;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
index = op2_64 & 0x3f;
|
|
|
|
displacement64 = ((Bit64s) (op2_64 & BX_CONST64(0xffffffffffffffc0))) / 64;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 8 * displacement64;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2008-05-10 22:10:53 +04:00
|
|
|
op1_64 = read_virtual_qword_64(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF((op1_64 >> index) & 0x01);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EqGqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_64 = BX_READ_64BIT_REG(i->dst());
|
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_64 &= 0x3f;
|
|
|
|
set_CF((op1_64 >> op2_64) & 0x01);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EqGqM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit64u op1_64, op2_64, index;
|
|
|
|
Bit64s displacement64;
|
2007-12-23 20:21:28 +03:00
|
|
|
bx_bool bit_i;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
index = op2_64 & 0x3f;
|
|
|
|
displacement64 = ((Bit64s) (op2_64 & BX_CONST64(0xffffffffffffffc0))) / 64;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 8 * displacement64;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2008-05-10 22:10:53 +04:00
|
|
|
op1_64 = read_RMW_virtual_qword_64(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bit_i = (op1_64 >> index) & 0x01;
|
|
|
|
op1_64 |= (((Bit64u) 1) << index);
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
|
|
|
|
|
|
|
set_CF(bit_i);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EqGqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_64 = BX_READ_64BIT_REG(i->dst());
|
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_64 &= 0x3f;
|
|
|
|
set_CF((op1_64 >> op2_64) & 0x01);
|
|
|
|
op1_64 |= (((Bit64u) 1) << op2_64);
|
|
|
|
|
|
|
|
/* now write result back to the destination */
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EqGqM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit64u op1_64, op2_64, index;
|
|
|
|
Bit64s displacement64;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
index = op2_64 & 0x3f;
|
|
|
|
displacement64 = ((Bit64s) (op2_64 & BX_CONST64(0xffffffffffffffc0))) / 64;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 8 * displacement64;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2008-05-10 22:10:53 +04:00
|
|
|
op1_64 = read_RMW_virtual_qword_64(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_cf = (op1_64 >> index) & 0x01;
|
|
|
|
op1_64 &= ~(((Bit64u) 1) << index);
|
|
|
|
/* now write back to destination */
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
|
|
|
|
|
|
|
set_CF(temp_cf);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EqGqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_64 = BX_READ_64BIT_REG(i->dst());
|
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_64 &= 0x3f;
|
|
|
|
set_CF((op1_64 >> op2_64) & 0x01);
|
|
|
|
op1_64 &= ~(((Bit64u) 1) << op2_64);
|
|
|
|
|
|
|
|
/* now write result back to the destination */
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EqGqM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
Bit64s displacement64;
|
|
|
|
Bit64u index;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
index = op2_64 & 0x3f;
|
|
|
|
displacement64 = ((Bit64s) (op2_64 & BX_CONST64(0xffffffffffffffc0))) / 64;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 8 * displacement64;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-05-10 22:10:53 +04:00
|
|
|
op1_64 = read_RMW_virtual_qword_64(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> index) & 0x01;
|
|
|
|
op1_64 ^= (((Bit64u) 1) << index); /* toggle bit */
|
|
|
|
set_CF(temp_CF);
|
|
|
|
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EqGqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit64u op1_64, op2_64;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_64 = BX_READ_64BIT_REG(i->dst());
|
|
|
|
op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_64 &= 0x3f;
|
|
|
|
|
|
|
|
bx_bool temp_CF = (op1_64 >> op2_64) & 0x01;
|
|
|
|
op1_64 ^= (((Bit64u) 1) << op2_64); /* toggle bit */
|
|
|
|
set_CF(temp_CF);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EqIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit64u op1_64 = read_virtual_qword_64(i->seg(), eaddr);
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF((op1_64 >> op2_8) & 0x01);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EqIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->dst());
|
2007-12-07 13:59:18 +03:00
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
|
|
|
set_CF((op1_64 >> op2_8) & 0x01);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EqIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit64u op1_64 = read_RMW_virtual_qword_64(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 |= (((Bit64u) 1) << op2_8);
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EqIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->dst());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 |= (((Bit64u) 1) << op2_8);
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EqIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit64u op1_64 = read_RMW_virtual_qword_64(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 ^= (((Bit64u) 1) << op2_8); /* toggle bit */
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EqIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->dst());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 ^= (((Bit64u) 1) << op2_8); /* toggle bit */
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EqIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit64u op1_64 = read_RMW_virtual_qword_64(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 &= ~(((Bit64u) 1) << op2_8);
|
|
|
|
write_RMW_virtual_qword(op1_64);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EqIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0x3f;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->dst());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_64 >> op2_8) & 0x01;
|
|
|
|
op1_64 &= ~(((Bit64u) 1) << op2_8);
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF(temp_CF);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2014-02-28 01:12:02 +04:00
|
|
|
#include "scalar_arith.h"
|
|
|
|
|
2010-02-09 22:44:25 +03:00
|
|
|
/* F3 0F B8 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPCNT_GqEqR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op2_64 = BX_READ_64BIT_REG(i->src());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-08-11 01:16:12 +04:00
|
|
|
Bit64u op1_64 = 0;
|
2007-12-07 13:59:18 +03:00
|
|
|
while (op2_64 != 0) {
|
2012-09-21 18:56:56 +04:00
|
|
|
op2_64 &= (op2_64-1);
|
|
|
|
op1_64++;
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u flags = op1_64 ? 0 : EFlagsZFMask;
|
|
|
|
setEFlagsOSZAPC(flags);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), op1_64);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2011-09-01 00:43:47 +04:00
|
|
|
/* F3 0F BC */
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::TZCNT_GqEqR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->src());
|
2014-02-28 01:12:02 +04:00
|
|
|
Bit64u result_64 = tzcntq(op1_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
set_CF(! op1_64);
|
|
|
|
set_ZF(! result_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), result_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* F3 0F BD */
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LZCNT_GqEqR(bxInstruction_c *i)
|
|
|
|
{
|
2014-02-28 01:12:02 +04:00
|
|
|
Bit64u op1_64 = BX_READ_64BIT_REG(i->src());
|
|
|
|
Bit64u result_64 = lzcntq(op1_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
set_CF(! op1_64);
|
|
|
|
set_ZF(! result_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_64BIT_REG(i->dst(), result_64);
|
2011-09-01 00:43:47 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
2007-12-07 13:59:18 +03:00
|
|
|
#endif // BX_SUPPORT_X86_64
|