2004-06-18 18:11:11 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2005-03-21 00:19:38 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-06-18 18:11:11 +04:00
|
|
|
//
|
2012-08-05 17:52:40 +04:00
|
|
|
// Copyright (c) 2003-2012 Stanislav Shwartsman
|
2007-03-24 00:27:13 +03:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
2004-06-18 18:11:11 +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-02-08 20:29:34 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-05-12 22:07:48 +04:00
|
|
|
//
|
2004-06-18 18:11:11 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu/cpu.h"
|
2004-06-18 18:11:11 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
2008-04-05 01:05:37 +04:00
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
|
2004-06-18 18:11:11 +04:00
|
|
|
#include "softfloatx80.h"
|
|
|
|
|
|
|
|
/* D9 C8 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FXCH_STi(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
int st0_tag = BX_CPU_THIS_PTR the_i387.FPU_gettagi(0);
|
2012-08-05 17:52:40 +04:00
|
|
|
int sti_tag = BX_CPU_THIS_PTR the_i387.FPU_gettagi(i->src());
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
floatx80 st0_reg = BX_READ_FPU_REG(0);
|
2012-08-05 17:52:40 +04:00
|
|
|
floatx80 sti_reg = BX_READ_FPU_REG(i->src());
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (st0_tag == FPU_Tag_Empty || sti_tag == FPU_Tag_Empty)
|
|
|
|
{
|
2017-05-05 23:56:13 +03:00
|
|
|
FPU_exception(i, FPU_EX_Stack_Underflow);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
2010-02-06 23:52:27 +03:00
|
|
|
if(BX_CPU_THIS_PTR the_i387.is_IA_masked())
|
|
|
|
{
|
|
|
|
/* Masked response */
|
|
|
|
if (st0_tag == FPU_Tag_Empty)
|
|
|
|
st0_reg = floatx80_default_nan;
|
2008-05-10 17:34:01 +04:00
|
|
|
|
2010-02-06 23:52:27 +03:00
|
|
|
if (sti_tag == FPU_Tag_Empty)
|
|
|
|
sti_reg = floatx80_default_nan;
|
|
|
|
}
|
2010-02-08 17:28:20 +03:00
|
|
|
else {
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_NEXT_INSTR(i);
|
2010-02-08 17:28:20 +03:00
|
|
|
}
|
2010-02-06 23:52:27 +03:00
|
|
|
}
|
2010-02-08 17:28:20 +03:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_FPU_REG(st0_reg, i->src());
|
2010-02-08 17:28:20 +03:00
|
|
|
BX_WRITE_FPU_REG(sti_reg, 0);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* D9 E0 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FCHS(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
2008-05-10 17:34:01 +04:00
|
|
|
if (IS_TAG_EMPTY(0)) {
|
2017-05-05 23:56:13 +03:00
|
|
|
FPU_stack_underflow(i, 0);
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
clear_C1();
|
|
|
|
floatx80 st0_reg = BX_READ_FPU_REG(0);
|
|
|
|
BX_WRITE_FPU_REG(floatx80_chs(st0_reg), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* D9 E1 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FABS(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
2008-05-10 17:34:01 +04:00
|
|
|
if (IS_TAG_EMPTY(0)) {
|
2017-05-05 23:56:13 +03:00
|
|
|
FPU_stack_underflow(i, 0);
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
clear_C1();
|
|
|
|
floatx80 st0_reg = BX_READ_FPU_REG(0);
|
|
|
|
BX_WRITE_FPU_REG(floatx80_abs(st0_reg), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* D9 F6 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FDECSTP(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
BX_CPU_THIS_PTR the_i387.tos = (BX_CPU_THIS_PTR the_i387.tos-1) & 7;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* D9 F7 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FINCSTP(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
BX_CPU_THIS_PTR the_i387.tos = (BX_CPU_THIS_PTR the_i387.tos+1) & 7;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DD C0 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREE_STi(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2009-10-18 23:24:56 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_settagi(FPU_Tag_Empty, i->dst());
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
2004-07-15 23:45:33 +04:00
|
|
|
|
2008-02-06 01:33:35 +03:00
|
|
|
/*
|
2004-07-15 23:45:33 +04:00
|
|
|
* Free the st(0) register and pop it from the FPU stack.
|
|
|
|
* "Undocumented" by Intel & AMD but mentioned in AMDs Athlon Docs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* DF C0 */
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREEP_STi(bxInstruction_c *i)
|
2004-07-15 23:45:33 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2009-10-18 23:24:56 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_settagi(FPU_Tag_Empty, i->dst());
|
2004-07-15 23:45:33 +04:00
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_pop();
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2004-07-15 23:45:33 +04:00
|
|
|
}
|
2008-04-05 01:05:37 +04:00
|
|
|
|
|
|
|
#endif
|