2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-12-04 19:53:12 +03:00
|
|
|
// $Id: mult8.cc,v 1.33 2009-12-04 16:53:12 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 19:53:12 +03:00
|
|
|
// Copyright (C) 2001-2009 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
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 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
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::MUL_ALEbR(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit8u op1 = AL;
|
|
|
|
Bit8u op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit32u product_16 = ((Bit16u) op1) * ((Bit16u) op2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-27 00:37:50 +04:00
|
|
|
Bit8u product_8l = (product_16 & 0xFF);
|
|
|
|
Bit8u product_8h = product_16 >> 8;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* now write product back to destination */
|
|
|
|
AX = product_16;
|
2007-12-06 19:57:59 +03:00
|
|
|
|
|
|
|
/* set EFLAGS */
|
|
|
|
SET_FLAGS_OSZAPC_LOGIC_8(product_8l);
|
|
|
|
if(product_8h != 0)
|
|
|
|
{
|
|
|
|
ASSERT_FLAGS_OxxxxC();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_ALEbR(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit8s op1 = AL;
|
|
|
|
Bit8s op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-18 23:27:52 +04:00
|
|
|
Bit16s product_16 = op1 * op2;
|
2007-12-06 19:57:59 +03:00
|
|
|
Bit8u product_8 = (product_16 & 0xFF);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-11-30 00:45:10 +03:00
|
|
|
/* now write product back to destination */
|
|
|
|
AX = product_16;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
/* set EFLAGS:
|
|
|
|
* IMUL r/m8: condition for clearing CF & OF:
|
2004-08-31 23:43:58 +04:00
|
|
|
* AX = sign-extend of AL to 16 bits
|
2001-04-10 05:04:59 +04:00
|
|
|
*/
|
2007-12-06 19:57:59 +03:00
|
|
|
|
|
|
|
SET_FLAGS_OSZAPC_LOGIC_8(product_8);
|
|
|
|
if(product_16 != (Bit8s) product_16)
|
|
|
|
{
|
|
|
|
ASSERT_FLAGS_OxxxxC();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::DIV_ALEbR(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit8u op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
|
2001-04-10 05:04:59 +04:00
|
|
|
if (op2 == 0) {
|
|
|
|
exception(BX_DE_EXCEPTION, 0, 0);
|
2004-08-10 01:28:47 +04:00
|
|
|
}
|
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit16u op1 = AX;
|
|
|
|
|
|
|
|
Bit16u quotient_16 = op1 / op2;
|
|
|
|
Bit8u remainder_8 = op1 % op2;
|
|
|
|
Bit8u quotient_8l = quotient_16 & 0xFF;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-10 01:28:47 +04:00
|
|
|
if (quotient_16 != quotient_8l)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_DE_EXCEPTION, 0, 0);
|
2004-08-10 01:28:47 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* now write quotient back to destination */
|
|
|
|
AL = quotient_8l;
|
|
|
|
AH = remainder_8;
|
|
|
|
}
|
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_ALEbR(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit16s op1 = AX;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
/* check MIN_INT case */
|
|
|
|
if (op1 == ((Bit16s)0x8000))
|
|
|
|
exception(BX_DE_EXCEPTION, 0, 0);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit8s op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-18 23:27:52 +04:00
|
|
|
if (op2 == 0)
|
|
|
|
exception(BX_DE_EXCEPTION, 0, 0);
|
|
|
|
|
2008-08-12 00:34:05 +04:00
|
|
|
Bit16s quotient_16 = op1 / op2;
|
|
|
|
Bit8s remainder_8 = op1 % op2;
|
|
|
|
Bit8s quotient_8l = quotient_16 & 0xFF;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-18 23:27:52 +04:00
|
|
|
if (quotient_16 != quotient_8l)
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_DE_EXCEPTION, 0, 0);
|
|
|
|
|
|
|
|
/* now write quotient back to destination */
|
|
|
|
AL = quotient_8l;
|
|
|
|
AH = remainder_8;
|
|
|
|
}
|