- added instructions how to update the online documentation
[bochs-mirror.git] / fpu / fpu_misc.cc
blob5383dc7c94bb11bcc0c8a2d5362ef6d4d537cca2
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: fpu_misc.cc,v 1.14 2008/05/10 13:34:01 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 "softfloatx80.h"
33 /* D9 C8 */
34 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FXCH_STi(bxInstruction_c *i)
36 #if BX_SUPPORT_FPU
37 BX_CPU_THIS_PTR prepareFPU(i);
39 int st0_tag = BX_CPU_THIS_PTR the_i387.FPU_gettagi(0);
40 int sti_tag = BX_CPU_THIS_PTR the_i387.FPU_gettagi(i->rm());
42 floatx80 st0_reg = BX_READ_FPU_REG(0);
43 floatx80 sti_reg = BX_READ_FPU_REG(i->rm());
45 clear_C1();
47 if (st0_tag == FPU_Tag_Empty || sti_tag == FPU_Tag_Empty)
49 BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
51 if(BX_CPU_THIS_PTR the_i387.is_IA_masked())
53 /* Masked response */
54 if (st0_tag == FPU_Tag_Empty)
55 st0_reg = floatx80_default_nan;
57 if (sti_tag == FPU_Tag_Empty)
58 sti_reg = floatx80_default_nan;
60 else return;
63 BX_WRITE_FPU_REG(st0_reg, i->rm());
64 BX_WRITE_FPU_REG(sti_reg, 0);
65 #else
66 BX_INFO(("FXCH_STi: required FPU, configure --enable-fpu"));
67 #endif
70 /* D9 E0 */
71 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FCHS(bxInstruction_c *i)
73 #if BX_SUPPORT_FPU
74 BX_CPU_THIS_PTR prepareFPU(i);
76 if (IS_TAG_EMPTY(0)) {
77 BX_CPU_THIS_PTR FPU_stack_underflow(0);
78 return;
81 clear_C1();
83 floatx80 st0_reg = BX_READ_FPU_REG(0);
84 BX_WRITE_FPU_REG(floatx80_chs(st0_reg), 0);
85 #else
86 BX_INFO(("FCHS: required FPU, configure --enable-fpu"));
87 #endif
90 /* D9 E1 */
91 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FABS(bxInstruction_c *i)
93 #if BX_SUPPORT_FPU
94 BX_CPU_THIS_PTR prepareFPU(i);
96 if (IS_TAG_EMPTY(0)) {
97 BX_CPU_THIS_PTR FPU_stack_underflow(0);
98 return;
101 clear_C1();
103 floatx80 st0_reg = BX_READ_FPU_REG(0);
104 BX_WRITE_FPU_REG(floatx80_abs(st0_reg), 0);
105 #else
106 BX_INFO(("FABS: required FPU, configure --enable-fpu"));
107 #endif
110 /* D9 F6 */
111 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FDECSTP(bxInstruction_c *i)
113 #if BX_SUPPORT_FPU
114 BX_CPU_THIS_PTR prepareFPU(i);
116 clear_C1();
118 BX_CPU_THIS_PTR the_i387.tos = (BX_CPU_THIS_PTR the_i387.tos-1) & 7;
119 #else
120 BX_INFO(("FDECSTP: required FPU, configure --enable-fpu"));
121 #endif
124 /* D9 F7 */
125 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FINCSTP(bxInstruction_c *i)
127 #if BX_SUPPORT_FPU
128 BX_CPU_THIS_PTR prepareFPU(i);
130 clear_C1();
132 BX_CPU_THIS_PTR the_i387.tos = (BX_CPU_THIS_PTR the_i387.tos+1) & 7;
133 #else
134 BX_INFO(("FINCSTP: required FPU, configure --enable-fpu"));
135 #endif
138 /* DD C0 */
139 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREE_STi(bxInstruction_c *i)
141 #if BX_SUPPORT_FPU
142 BX_CPU_THIS_PTR prepareFPU(i);
143 BX_CPU_THIS_PTR the_i387.FPU_settagi(FPU_Tag_Empty, i->rm());
144 #else
145 BX_INFO(("FFREE_STi: required FPU, configure --enable-fpu"));
146 #endif
150 * Free the st(0) register and pop it from the FPU stack.
151 * "Undocumented" by Intel & AMD but mentioned in AMDs Athlon Docs.
154 /* DF C0 */
155 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREEP_STi(bxInstruction_c *i)
157 #if BX_SUPPORT_FPU
158 BX_CPU_THIS_PTR prepareFPU(i);
159 BX_CPU_THIS_PTR the_i387.FPU_settagi(FPU_Tag_Empty, i->rm());
160 BX_CPU_THIS_PTR the_i387.FPU_pop();
161 #else
162 BX_INFO(("FFREEP_STi: required FPU, configure --enable-fpu"));
163 #endif
166 #endif