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
|
|
|
//
|
2017-05-06 00:09:27 +03:00
|
|
|
// Copyright (c) 2003-2017 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
|
|
|
|
|
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
|
|
|
|
#include "softfloat-specialize.h"
|
|
|
|
|
2017-05-05 23:56:13 +03:00
|
|
|
void BX_CPU_C::FPU_stack_overflow(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
}
|
2017-05-05 23:56:13 +03:00
|
|
|
FPU_exception(i, FPU_EX_Stack_Overflow);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
2017-05-05 23:56:13 +03:00
|
|
|
void BX_CPU_C::FPU_stack_underflow(bxInstruction_c *i, int stnr, int pop_stack)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
}
|
2017-05-05 23:56:13 +03:00
|
|
|
FPU_exception(i, FPU_EX_Stack_Underflow);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
|
2019-12-09 19:29:23 +03:00
|
|
|
/* Returns unmasked exceptions if occurred */
|
2017-05-05 23:56:13 +03:00
|
|
|
unsigned BX_CPU_C::FPU_exception(bxInstruction_c *i, unsigned exception, bx_bool is_store)
|
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);
|
|
|
|
|
2009-04-27 21:58:17 +04:00
|
|
|
Bit32u status = FPU_PARTIAL_STATUS;
|
|
|
|
|
2009-05-24 19:29:43 +04:00
|
|
|
unsigned unmasked = exception & ~FPU_CONTROL_WORD & FPU_CW_Exceptions_Mask;
|
2009-06-01 14:39:34 +04:00
|
|
|
// if IE or DZ exception happen nothing else will be reported
|
|
|
|
if (exception & (FPU_EX_Invalid | FPU_EX_Zero_Div))
|
|
|
|
unmasked &= (FPU_EX_Invalid | FPU_EX_Zero_Div);
|
2008-09-02 09:36:15 +04:00
|
|
|
|
2004-06-18 18:11:11 +04:00
|
|
|
/* Set summary bits iff exception isn't masked */
|
2017-05-05 23:56:13 +03: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
|
|
|
|
2017-05-05 23:56:13 +03:00
|
|
|
// when FOPCODE deprecation is set, FOPCODE is updated only when unmasked x87 exception occurs
|
|
|
|
if (is_cpu_extension_supported(BX_ISA_FOPCODE_DEPRECATION))
|
|
|
|
BX_CPU_THIS_PTR the_i387.foo = i->foo();
|
|
|
|
|
|
|
|
// when FOPCODE deprecation is set, FCS/FDP are updated only when unmasked x87 exception occurs
|
|
|
|
if (is_cpu_extension_supported(BX_ISA_FDP_DEPRECATION)) {
|
|
|
|
if (! i->modC0()) {
|
|
|
|
BX_CPU_THIS_PTR the_i387.fds = BX_CPU_THIS_PTR sregs[i->seg()].selector.value;
|
|
|
|
BX_CPU_THIS_PTR the_i387.fdp = RMAddr(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 19:29:43 +04:00
|
|
|
if (exception & FPU_EX_Invalid) {
|
|
|
|
// FPU_EX_Invalid cannot come with any other exception but x87 stack fault
|
|
|
|
FPU_PARTIAL_STATUS |= exception;
|
|
|
|
if (exception & FPU_SW_Stack_Fault) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unmasked;
|
|
|
|
}
|
|
|
|
|
2009-06-01 14:39:34 +04:00
|
|
|
if (exception & FPU_EX_Zero_Div) {
|
|
|
|
FPU_PARTIAL_STATUS |= FPU_EX_Zero_Div;
|
|
|
|
return unmasked;
|
|
|
|
}
|
|
|
|
|
2009-05-24 19:29:43 +04:00
|
|
|
if (exception & FPU_EX_Denormal) {
|
|
|
|
FPU_PARTIAL_STATUS |= FPU_EX_Denormal;
|
|
|
|
if (unmasked & FPU_EX_Denormal)
|
2009-06-01 14:39:34 +04:00
|
|
|
return unmasked & FPU_EX_Denormal;
|
2009-05-24 19:29:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the corresponding exception bits */
|
|
|
|
FPU_PARTIAL_STATUS |= exception;
|
|
|
|
|
|
|
|
if (exception & FPU_EX_Precision)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-12-09 19:29:23 +03:00
|
|
|
// If #P unmasked exception occurred the result still has to be
|
2008-09-02 09:36:15 +04:00
|
|
|
// written to the destination.
|
2009-05-24 19:29:43 +04:00
|
|
|
unmasked &= ~FPU_EX_Precision;
|
2008-09-02 09:36:15 +04:00
|
|
|
|
2009-05-24 19:29:43 +04:00
|
|
|
if (unmasked & (FPU_EX_Underflow | FPU_EX_Overflow)) {
|
2009-04-27 21:58:17 +04:00
|
|
|
// If unmasked over- or underflow occurs and dest is a memory location:
|
|
|
|
// - the TOS and destination operands remain unchanged
|
|
|
|
// - the inexact-result condition is not reported and C1 flag is cleared
|
|
|
|
// - no result is stored in the memory
|
|
|
|
// If the destination is in the register stack, adjusted resulting value
|
|
|
|
// is stored in the destination operand.
|
|
|
|
if (! is_store) {
|
2009-05-24 19:29:43 +04:00
|
|
|
unmasked &= ~(FPU_EX_Underflow | FPU_EX_Overflow);
|
2009-04-27 21:58:17 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
FPU_PARTIAL_STATUS &= ~FPU_SW_C1; // clear C1 flag
|
2009-05-24 19:29:43 +04:00
|
|
|
if (! (status & FPU_EX_Precision))
|
|
|
|
FPU_PARTIAL_STATUS &= ~FPU_EX_Precision;
|
2009-04-27 21:58:17 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-02 23:46:30 +04:00
|
|
|
|
2004-06-18 18:11:11 +04:00
|
|
|
return unmasked;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|