Initial import from FreeBSD RELENG_4:
[games.git] / sys / i386 / gnu / fpemul / fpu_arith.c
1 /*
2  *  fpu_arith.c
3  *
4  * Code to implement the FPU register/register arithmetic instructions
5  *
6  *
7  * Copyright (C) 1992,1993,1994
8  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
9  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
10  * All rights reserved.
11  *
12  * This copyright notice covers the redistribution and use of the
13  * FPU emulator developed by W. Metzenthen. It covers only its use
14  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
15  * use is not permitted under this copyright.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must include information specifying
23  *    that source code for the emulator is freely available and include
24  *    either:
25  *      a) an offer to provide the source code for a nominal distribution
26  *         fee, or
27  *      b) list at least two alternative methods whereby the source
28  *         can be obtained, e.g. a publically accessible bulletin board
29  *         and an anonymous ftp site from which the software can be
30  *         downloaded.
31  * 3. All advertising materials specifically mentioning features or use of
32  *    this emulator must acknowledge that it was developed by W. Metzenthen.
33  * 4. The name of W. Metzenthen may not be used to endorse or promote
34  *    products derived from this software without specific prior written
35  *    permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
38  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
39  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
40  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  *
48  *
49  * The purpose of this copyright, based upon the Berkeley copyright, is to
50  * ensure that the covered software remains freely available to everyone.
51  *
52  * The software (with necessary differences) is also available, but under
53  * the terms of the GNU copyleft, for the Linux operating system and for
54  * the djgpp ms-dos extender.
55  *
56  * W. Metzenthen   June 1994.
57  *
58  *
59  * $FreeBSD: src/sys/gnu/i386/fpemul/fpu_arith.c,v 1.9 1999/08/28 00:42:49 peter Exp $
60  *
61  */
62
63
64
65
66 #include <sys/param.h>
67 #include <sys/proc.h>
68 #include <machine/pcb.h>
69
70 #include <gnu/i386/fpemul/fpu_emu.h>
71 #include <gnu/i386/fpemul/fpu_system.h>
72
73
74 void
75 fadd__()
76 {
77         /* fadd st,st(i) */
78         reg_add(FPU_st0_ptr, &st(FPU_rm), FPU_st0_ptr, control_word);
79 }
80
81
82 void
83 fmul__()
84 {
85         /* fmul st,st(i) */
86         reg_mul(FPU_st0_ptr, &st(FPU_rm), FPU_st0_ptr, control_word);
87 }
88
89
90
91 void
92 fsub__()
93 {
94         /* fsub st,st(i) */
95         reg_sub(FPU_st0_ptr, &st(FPU_rm), FPU_st0_ptr, control_word);
96 }
97
98
99 void
100 fsubr_()
101 {
102         /* fsubr st,st(i) */
103         reg_sub(&st(FPU_rm), FPU_st0_ptr, FPU_st0_ptr, control_word);
104 }
105
106
107 void
108 fdiv__()
109 {
110         /* fdiv st,st(i) */
111         reg_div(FPU_st0_ptr, &st(FPU_rm), FPU_st0_ptr, control_word);
112 }
113
114
115 void
116 fdivr_()
117 {
118         /* fdivr st,st(i) */
119         reg_div(&st(FPU_rm), FPU_st0_ptr, FPU_st0_ptr, control_word);
120 }
121
122
123
124 void
125 fadd_i()
126 {
127         /* fadd st(i),st */
128         reg_add(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
129 }
130
131
132 void
133 fmul_i()
134 {
135         /* fmul st(i),st */
136         reg_mul(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
137 }
138
139
140 void
141 fsubri()
142 {
143         /* fsubr st(i),st */
144         /* This is the sense of the 80486 manual reg_sub(&st(FPU_rm),
145          * FPU_st0_ptr, &st(FPU_rm), control_word); */
146         reg_sub(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
147 }
148
149
150 void
151 fsub_i()
152 {
153         /* fsub st(i),st */
154         /* This is the sense of the 80486 manual reg_sub(FPU_st0_ptr,
155          * &st(FPU_rm), &st(FPU_rm), control_word); */
156         reg_sub(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
157 }
158
159
160 void
161 fdivri()
162 {
163         /* fdivr st(i),st */
164         reg_div(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
165 }
166
167
168 void
169 fdiv_i()
170 {
171         /* fdiv st(i),st */
172         reg_div(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
173 }
174
175
176
177 void
178 faddp_()
179 {
180         /* faddp st(i),st */
181         reg_add(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
182         pop();
183 }
184
185
186 void
187 fmulp_()
188 {
189         /* fmulp st(i),st */
190         reg_mul(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
191         pop();
192 }
193
194
195
196 void
197 fsubrp()
198 {
199         /* fsubrp st(i),st */
200         /* This is the sense of the 80486 manual reg_sub(&st(FPU_rm),
201          * FPU_st0_ptr, &st(FPU_rm), control_word); */
202         reg_sub(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
203         pop();
204 }
205
206
207 void
208 fsubp_()
209 {
210         /* fsubp st(i),st */
211         /* This is the sense of the 80486 manual reg_sub(FPU_st0_ptr,
212          * &st(FPU_rm), &st(FPU_rm), control_word); */
213         reg_sub(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
214         pop();
215 }
216
217
218 void
219 fdivrp()
220 {
221         /* fdivrp st(i),st */
222         reg_div(FPU_st0_ptr, &st(FPU_rm), &st(FPU_rm), control_word);
223         pop();
224 }
225
226
227 void
228 fdivp_()
229 {
230         /* fdivp st(i),st */
231         reg_div(&st(FPU_rm), FPU_st0_ptr, &st(FPU_rm), control_word);
232         pop();
233 }