2004-06-18 18:11:11 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2008-09-02 09:36:15 +04:00
|
|
|
// $Id: ferr.cc,v 1.12 2008-09-02 05:36:15 sshwarts Exp $
|
2005-03-21 00:19:38 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-06-18 18:11:11 +04:00
|
|
|
//
|
2005-05-12 22:07:48 +04:00
|
|
|
// Copyright (c) 2003 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
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
|
|
|
|
|
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
|
|
|
|
#include "softfloat-specialize.h"
|
|
|
|
|
|
|
|
void BX_CPU_C::FPU_stack_overflow(void)
|
|
|
|
{
|
|
|
|
/* The masked response */
|
|
|
|
if (BX_CPU_THIS_PTR the_i387.is_IA_masked())
|
|
|
|
{
|
2008-04-26 23:38:53 +04:00
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
2008-05-10 17:34:01 +04:00
|
|
|
BX_WRITE_FPU_REG(floatx80_default_nan, 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
FPU_exception(FPU_EX_Stack_Overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPU_C::FPU_stack_underflow(int stnr, int pop_stack)
|
|
|
|
{
|
|
|
|
/* The masked response */
|
|
|
|
if (BX_CPU_THIS_PTR the_i387.is_IA_masked())
|
|
|
|
{
|
2008-05-10 17:34:01 +04:00
|
|
|
BX_WRITE_FPU_REG(floatx80_default_nan, stnr);
|
2008-04-26 23:38:53 +04:00
|
|
|
if (pop_stack)
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_pop();
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
FPU_exception(FPU_EX_Stack_Underflow);
|
|
|
|
}
|
|
|
|
|
2008-09-02 09:36:15 +04:00
|
|
|
/* Returns unmasked exceptions if occured */
|
|
|
|
unsigned BX_CPU_C::FPU_exception(int exception)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
/* Extract only the bits which we use to set the status word */
|
|
|
|
exception &= (FPU_SW_Exceptions_Mask);
|
|
|
|
|
|
|
|
/* Set the corresponding exception bits */
|
|
|
|
FPU_PARTIAL_STATUS |= exception;
|
|
|
|
|
2008-09-02 09:36:15 +04:00
|
|
|
unsigned unmasked = FPU_PARTIAL_STATUS & ~FPU_CONTROL_WORD & FPU_CW_Exceptions_Mask;
|
|
|
|
|
2004-06-18 18:11:11 +04:00
|
|
|
/* Set summary bits iff exception isn't masked */
|
2008-09-02 09:36:15 +04:00
|
|
|
if (unmasked)
|
2008-04-26 23:38:53 +04:00
|
|
|
FPU_PARTIAL_STATUS |= (FPU_SW_Summary | FPU_SW_Backward);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
if (exception & (FPU_SW_Stack_Fault | FPU_EX_Precision))
|
|
|
|
{
|
2008-04-26 23:38:53 +04:00
|
|
|
if (! (exception & FPU_SW_C1)) {
|
|
|
|
/* This bit distinguishes over- from underflow for a stack fault,
|
|
|
|
and roundup from round-down for precision loss. */
|
|
|
|
FPU_PARTIAL_STATUS &= ~FPU_SW_C1;
|
|
|
|
}
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
2008-09-02 09:36:15 +04:00
|
|
|
// if #P unmasked exception occured the result still has to be
|
|
|
|
// written to the destination.
|
|
|
|
unmasked &= ~FPU_CW_Precision;
|
|
|
|
|
2004-06-18 18:11:11 +04:00
|
|
|
return unmasked;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|