- compare disk size with the size calculated from geometry to avoid image
[bochs-mirror.git] / fpu / ferr.cc
bloba2bdfc28822f5478b1f151e0eb34b298fbae707f
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: ferr.cc,v 1.8 2007/03/23 21:27:12 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2003 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /////////////////////////////////////////////////////////////////////////
24 #define NEED_CPU_REG_SHORTCUTS 1
25 #include "bochs.h"
26 #include "cpu/cpu.h"
27 #define LOG_THIS BX_CPU_THIS_PTR
29 #if BX_SUPPORT_FPU
31 #include "softfloat-specialize.h"
33 void BX_CPU_C::FPU_stack_overflow(void)
35 /* The masked response */
36 if (BX_CPU_THIS_PTR the_i387.is_IA_masked())
38 BX_CPU_THIS_PTR the_i387.FPU_push();
39 BX_WRITE_FPU_REGISTER_AND_TAG(floatx80_default_nan, FPU_Tag_Special, 0);
41 FPU_exception(FPU_EX_Stack_Overflow);
44 void BX_CPU_C::FPU_stack_underflow(int stnr, int pop_stack)
46 /* The masked response */
47 if (BX_CPU_THIS_PTR the_i387.is_IA_masked())
49 BX_WRITE_FPU_REGISTER_AND_TAG(floatx80_default_nan, FPU_Tag_Special, stnr);
50 if (pop_stack)
51 BX_CPU_THIS_PTR the_i387.FPU_pop();
53 FPU_exception(FPU_EX_Stack_Underflow);
56 /* Returns 1 if unmasked exception occured */
57 int BX_CPU_C::FPU_exception(int exception)
59 int unmasked = 0;
61 /* Extract only the bits which we use to set the status word */
62 exception &= (FPU_SW_Exceptions_Mask);
64 /* Set the corresponding exception bits */
65 FPU_PARTIAL_STATUS |= exception;
67 /* Set summary bits iff exception isn't masked */
68 if (FPU_PARTIAL_STATUS & ~FPU_CONTROL_WORD & FPU_CW_Exceptions_Mask)
70 FPU_PARTIAL_STATUS |= (FPU_SW_Summary | FPU_SW_Backward);
71 unmasked = 1;
74 if (exception & (FPU_SW_Stack_Fault | FPU_EX_Precision))
76 if (! (exception & FPU_SW_C1))
77 /* This bit distinguishes over- from underflow for a stack fault,
78 and roundup from round-down for precision loss. */
79 FPU_PARTIAL_STATUS &= ~FPU_SW_C1;
82 return unmasked;
85 #endif