2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2008-05-10 22:10:53 +04:00
|
|
|
// $Id: bit.cc,v 1.56 2008-05-10 18:10:52 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2007-11-18 02:28:33 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-28 12:41:46 +04:00
|
|
|
#if BX_CPU_LEVEL >= 3
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETO_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = getB_OF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETO_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), getB_OF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNO_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !getB_OF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNO_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !getB_OF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETB_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = getB_CF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETB_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), getB_CF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNB_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !getB_CF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNB_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !getB_CF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETZ_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = getB_ZF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETZ_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), getB_ZF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNZ_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !getB_ZF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNZ_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !getB_ZF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETBE_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = (getB_CF() | getB_ZF());
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETBE_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), (getB_CF() | getB_ZF()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNBE_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !(getB_CF() | getB_ZF());
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNBE_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !(getB_CF() | getB_ZF()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETS_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = getB_SF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETS_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), getB_SF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNS_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !getB_SF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNS_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !getB_SF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETP_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = getB_PF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETP_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), getB_PF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNP_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-18 23:21:34 +03:00
|
|
|
Bit8u result_8 = !getB_PF();
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNP_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !getB_PF());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETL_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-22 01:42:40 +03:00
|
|
|
Bit8u result_8 = (getB_SF() ^ getB_OF());
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETL_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), (getB_SF() ^ getB_OF()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNL_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-11-22 01:42:40 +03:00
|
|
|
Bit8u result_8 = !(getB_SF() ^ getB_OF());
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNL_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), !(getB_SF() ^ getB_OF()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETLE_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-12-15 00:29:36 +03:00
|
|
|
Bit8u result_8 = getB_ZF() | (getB_SF() ^ getB_OF());
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETLE_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
Bit8u result_8 = getB_ZF() | (getB_SF() ^ getB_OF());
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), result_8);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNLE_EbM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-12-15 00:29:36 +03:00
|
|
|
Bit8u result_8 = !(getB_ZF() | (getB_SF() ^ getB_OF()));
|
2007-12-20 21:29:42 +03:00
|
|
|
write_virtual_byte(i->seg(), RMAddr(i), result_8);
|
2007-12-15 00:29:36 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNLE_EbR(bxInstruction_c *i)
|
2007-12-15 00:29:36 +03:00
|
|
|
{
|
|
|
|
Bit8u result_8 = !(getB_ZF() | (getB_SF() ^ getB_OF()));
|
|
|
|
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), result_8);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-09-18 00:47:19 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSWAP_ERX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-12-01 19:45:17 +03:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2006-05-07 22:58:47 +04:00
|
|
|
Bit32u val32, b0, b1, b2, b3;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-05-08 00:56:40 +04:00
|
|
|
if (i->os32L() == 0) {
|
|
|
|
BX_ERROR(("BSWAP with 16-bit opsize: undefined behavior !"));
|
|
|
|
}
|
|
|
|
|
2006-05-07 22:58:47 +04:00
|
|
|
val32 = BX_READ_32BIT_REG(i->opcodeReg());
|
|
|
|
b0 = val32 & 0xff; val32 >>= 8;
|
|
|
|
b1 = val32 & 0xff; val32 >>= 8;
|
|
|
|
b2 = val32 & 0xff; val32 >>= 8;
|
|
|
|
b3 = val32;
|
|
|
|
val32 = (b0<<24) | (b1<<16) | (b2<<8) | b3; // zero extended
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-05-07 22:58:47 +04:00
|
|
|
// in 64-bit mode, hi-order 32 bits are not modified
|
2007-01-27 01:12:05 +03:00
|
|
|
BX_WRITE_32BIT_REGZ(i->opcodeReg(), val32);
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
2006-05-07 22:58:47 +04:00
|
|
|
BX_INFO(("BSWAP_ERX: required CPU >= 4, use --enable-cpu-level=4 option"));
|
2004-01-10 22:45:53 +03:00
|
|
|
UndefinedOpcode(i);
|
2002-09-15 07:38:52 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSWAP_RRX(bxInstruction_c *i)
|
2006-05-07 22:58:47 +04:00
|
|
|
{
|
|
|
|
Bit64u val64, b0, b1, b2, b3, b4, b5, b6, b7;
|
|
|
|
|
|
|
|
val64 = BX_READ_64BIT_REG(i->opcodeReg());
|
|
|
|
b0 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b1 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b2 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b3 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b4 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b5 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b6 = val64 & 0xff; val64 >>= 8;
|
|
|
|
b7 = val64;
|
|
|
|
val64 = (b0<<56) | (b1<<48) | (b2<<40) | (b3<<32) | (b4<<24) | (b4<<16) | (b4<<8) | b7;
|
|
|
|
|
|
|
|
BX_WRITE_64BIT_REG(i->opcodeReg(), val64);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2007-11-18 23:21:34 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-10-01 23:59:37 +04:00
|
|
|
// 3-byte opcodes
|
|
|
|
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
|
|
|
|
|
|
|
|
#define CRC32_POLYNOMIAL BX_CONST64(0x11edc6f41)
|
|
|
|
|
|
|
|
#if (BX_SUPPORT_SSE >= 5) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
|
|
|
|
// primitives for CRC32 usage
|
2008-03-31 21:33:34 +04:00
|
|
|
BX_CPP_INLINE Bit8u BitReflect8(Bit8u val8)
|
2007-10-01 23:59:37 +04:00
|
|
|
{
|
2008-03-31 21:33:34 +04:00
|
|
|
return ((val8 & 0x80) >> 7) |
|
|
|
|
((val8 & 0x40) >> 5) |
|
|
|
|
((val8 & 0x20) >> 3) |
|
|
|
|
((val8 & 0x10) >> 1) |
|
|
|
|
((val8 & 0x08) << 1) |
|
|
|
|
((val8 & 0x04) << 3) |
|
|
|
|
((val8 & 0x02) << 5) |
|
|
|
|
((val8 & 0x01) << 7);
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE Bit16u BitReflect16(Bit16u val16)
|
|
|
|
{
|
2008-03-31 21:33:34 +04:00
|
|
|
return ((Bit16u)(BitReflect8(val16 & 0xff)) << 8) | BitReflect8(val16 >> 8);
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE Bit32u BitReflect32(Bit32u val32)
|
|
|
|
{
|
2008-03-31 21:33:34 +04:00
|
|
|
return ((Bit32u)(BitReflect16(val32 & 0xffff)) << 16) | BitReflect16(val32 >> 16);
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static Bit32u mod2_64bit(Bit64u divisor, Bit64u dividend)
|
|
|
|
{
|
2008-03-31 21:33:34 +04:00
|
|
|
Bit64u remainder = dividend >> 32;
|
2007-10-01 23:59:37 +04:00
|
|
|
|
2008-03-31 21:33:34 +04:00
|
|
|
for (int bitpos=31; bitpos>=0; bitpos--) {
|
|
|
|
// copy one more bit from the dividend
|
|
|
|
remainder = (remainder << 1) | ((dividend >> bitpos) & 1);
|
2007-10-01 23:59:37 +04:00
|
|
|
|
2008-03-31 21:33:34 +04:00
|
|
|
// if MSB is set, then XOR divisor and get new remainder
|
|
|
|
if (((remainder >> 32) & 1) == 1) {
|
|
|
|
remainder ^= divisor;
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
2008-03-31 21:33:34 +04:00
|
|
|
}
|
2007-10-01 23:59:37 +04:00
|
|
|
|
2008-03-31 21:33:34 +04:00
|
|
|
return remainder;
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
#endif // (BX_SUPPORT_SSE >= 5) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::CRC32_GdEb(bxInstruction_c *i)
|
2007-10-01 23:59:37 +04:00
|
|
|
{
|
|
|
|
#if (BX_SUPPORT_SSE >= 5) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit8u op1;
|
2007-10-01 23:59:37 +04:00
|
|
|
|
|
|
|
if (i->modC0()) {
|
|
|
|
op1 = BX_READ_8BIT_REGx(i->rm(),i->extend8bitL());
|
|
|
|
}
|
|
|
|
else {
|
2008-01-10 22:37:56 +03:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
|
|
|
|
2007-12-20 23:58:38 +03:00
|
|
|
op1 = read_virtual_byte(i->seg(), RMAddr(i));
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u op2 = BX_READ_32BIT_REG(i->nnn());
|
|
|
|
op2 = BitReflect32(op2);
|
|
|
|
|
|
|
|
Bit64u tmp1 = ((Bit64u) BitReflect8 (op1)) << 32;
|
|
|
|
Bit64u tmp2 = ((Bit64u) op2) << 8;
|
|
|
|
Bit64u tmp3 = tmp1 ^ tmp2;
|
|
|
|
op2 = mod2_64bit(CRC32_POLYNOMIAL, tmp3);
|
|
|
|
|
|
|
|
/* now write result back to destination */
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), BitReflect32(op2));
|
|
|
|
#else
|
2008-03-28 00:04:39 +03:00
|
|
|
BX_INFO(("CRC32_GdEb: required SSE4_2 support, use --enable-sse and --enable-sse-extension options"));
|
2007-10-01 23:59:37 +04:00
|
|
|
UndefinedOpcode(i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::CRC32_GdEv(bxInstruction_c *i)
|
2007-10-01 23:59:37 +04:00
|
|
|
{
|
|
|
|
#if (BX_SUPPORT_SSE >= 5) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
|
|
|
|
|
|
|
|
Bit32u op2 = BX_READ_32BIT_REG(i->nnn());
|
|
|
|
op2 = BitReflect32(op2);
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (i->os64L()) /* 64 bit operand size */
|
|
|
|
{
|
|
|
|
Bit64u op1;
|
|
|
|
|
|
|
|
if (i->modC0()) {
|
|
|
|
op1 = BX_READ_64BIT_REG(i->rm());
|
|
|
|
}
|
|
|
|
else {
|
2008-04-03 21:56:59 +04:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-05-10 22:10:53 +04:00
|
|
|
op1 = read_virtual_qword_64(i->seg(), RMAddr(i));
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u tmp1 = ((Bit64u) BitReflect32(op1 & 0xffffffff)) << 32;
|
|
|
|
Bit64u tmp2 = ((Bit64u) op2) << 32;
|
|
|
|
Bit64u tmp3 = tmp1 ^ tmp2;
|
|
|
|
op2 = mod2_64bit(CRC32_POLYNOMIAL, tmp3);
|
|
|
|
tmp1 = ((Bit64u) BitReflect32(op1 >> 32)) << 32;
|
|
|
|
tmp2 = ((Bit64u) op2) << 32;
|
|
|
|
tmp3 = tmp1 ^ tmp2;
|
|
|
|
op2 = mod2_64bit(CRC32_POLYNOMIAL, tmp3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (i->os32L()) /* 32 bit operand size */
|
|
|
|
{
|
|
|
|
Bit32u op1;
|
|
|
|
|
|
|
|
if (i->modC0()) {
|
|
|
|
op1 = BX_READ_32BIT_REG(i->rm());
|
|
|
|
}
|
|
|
|
else {
|
2008-04-03 21:56:59 +04:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2007-12-20 23:58:38 +03:00
|
|
|
op1 = read_virtual_dword(i->seg(), RMAddr(i));
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u tmp1 = ((Bit64u) BitReflect32(op1)) << 32;
|
|
|
|
Bit64u tmp2 = ((Bit64u) op2) << 32;
|
|
|
|
Bit64u tmp3 = tmp1 ^ tmp2;
|
|
|
|
op2 = mod2_64bit(CRC32_POLYNOMIAL, tmp3);
|
|
|
|
}
|
|
|
|
else { /* 16 bit operand size */
|
|
|
|
Bit16u op1;
|
|
|
|
|
|
|
|
if (i->modC0()) {
|
|
|
|
op1 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
}
|
|
|
|
else {
|
2008-04-03 21:56:59 +04:00
|
|
|
BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2007-12-20 23:58:38 +03:00
|
|
|
op1 = read_virtual_word(i->seg(), RMAddr(i));
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u tmp1 = ((Bit64u) BitReflect16(op1)) << 32;
|
|
|
|
Bit64u tmp2 = ((Bit64u) op2) << 16;
|
|
|
|
Bit64u tmp3 = tmp1 ^ tmp2;
|
|
|
|
op2 = mod2_64bit(CRC32_POLYNOMIAL, tmp3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now write result back to destination */
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), BitReflect32(op2));
|
2008-02-03 00:46:54 +03:00
|
|
|
|
2007-10-01 23:59:37 +04:00
|
|
|
#else
|
2008-03-28 00:04:39 +03:00
|
|
|
BX_INFO(("CRC32_GdEv: required SSE4_2 support, use --enable-sse and --enable-sse-extension options"));
|
2007-10-01 23:59:37 +04:00
|
|
|
UndefinedOpcode(i);
|
2007-09-19 23:38:10 +04:00
|
|
|
#endif
|
2007-10-01 23:59:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
|
2007-09-19 23:38:10 +04:00
|
|
|
|
2007-10-01 23:59:37 +04:00
|
|
|
#endif // (BX_CPU_LEVEL >= 3)
|