4 * This file contains most of the code to interpret the FPU instructions
5 * which load and store from user memory.
8 * Copyright (C) 1992,1993,1994
9 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
10 * Australia. E-mail billm@vaxc.cc.monash.edu.au
11 * All rights reserved.
13 * This copyright notice covers the redistribution and use of the
14 * FPU emulator developed by W. Metzenthen. It covers only its use
15 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
16 * use is not permitted under this copyright.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must include information specifying
24 * that source code for the emulator is freely available and include
26 * a) an offer to provide the source code for a nominal distribution
28 * b) list at least two alternative methods whereby the source
29 * can be obtained, e.g. a publically accessible bulletin board
30 * and an anonymous ftp site from which the software can be
32 * 3. All advertising materials specifically mentioning features or use of
33 * this emulator must acknowledge that it was developed by W. Metzenthen.
34 * 4. The name of W. Metzenthen may not be used to endorse or promote
35 * products derived from this software without specific prior written
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
39 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
40 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
41 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 * The purpose of this copyright, based upon the Berkeley copyright, is to
51 * ensure that the covered software remains freely available to everyone.
53 * The software (with necessary differences) is also available, but under
54 * the terms of the GNU copyleft, for the Linux operating system and for
55 * the djgpp ms-dos extender.
57 * W. Metzenthen June 1994.
60 * $FreeBSD: src/sys/gnu/i386/fpemul/load_store.c,v 1.13 1999/08/28 00:42:52 peter Exp $
64 /*---------------------------------------------------------------------------+
66 | The file contains code which accesses user memory. |
67 | Emulator static data may change when user memory is accessed, due to |
68 | other processes using the emulator while swapping is in progress. |
69 +---------------------------------------------------------------------------*/
71 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <machine/pcb.h>
76 #include <gnu/i386/fpemul/fpu_emu.h>
77 #include <gnu/i386/fpemul/fpu_system.h>
78 #include <gnu/i386/fpemul/status_w.h>
81 #define _NONE_ 0 /* FPU_st0_ptr etc not needed */
82 #define _REG0_ 1 /* Will be storing st(0) */
83 #define _PUSH_ 3 /* Need to check for space to push onto stack */
84 #define _null_ 4 /* Function illegal or not implemented */
86 #define pop_0() { pop_ptr->tag = TW_Empty; top++; }
89 static unsigned char type_table[32] = {
90 _PUSH_, _PUSH_, _PUSH_, _PUSH_,
91 _null_, _null_, _null_, _null_,
92 _REG0_, _REG0_, _REG0_, _REG0_,
93 _REG0_, _REG0_, _REG0_, _REG0_,
94 _NONE_, _null_, _NONE_, _PUSH_,
95 _NONE_, _PUSH_, _null_, _PUSH_,
96 _NONE_, _null_, _NONE_, _REG0_,
97 _NONE_, _REG0_, _NONE_, _REG0_
101 load_store_instr(char type)
103 FPU_REG *pop_ptr; /* We need a version of FPU_st0_ptr which
106 pop_ptr = NULL; /* Initialized just to stop compiler warnings. */
109 switch (type_table[(int) (unsigned) type]) {
113 pop_ptr = &st(0); /* Some of these instructions pop
116 FPU_st0_ptr = pop_ptr; /* Set the global variables. */
117 FPU_st0_tag = FPU_st0_ptr->tag;
122 if (pop_ptr->tag != TW_Empty) {
134 return EXCEPTION(EX_INTERNAL);
135 #endif /* PARANOID */
139 case 000: /* fld m32real */
141 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
142 reg_move(&FPU_loaded_data, pop_ptr);
144 case 001: /* fild m32int */
146 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
147 reg_move(&FPU_loaded_data, pop_ptr);
149 case 002: /* fld m64real */
151 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
152 reg_move(&FPU_loaded_data, pop_ptr);
154 case 003: /* fild m16int */
156 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
157 reg_move(&FPU_loaded_data, pop_ptr);
159 case 010: /* fst m32real */
162 case 011: /* fist m32int */
165 case 012: /* fst m64real */
168 case 013: /* fist m16int */
171 case 014: /* fstp m32real */
172 if (reg_store_single())
173 pop_0();/* pop only if the number was actually stored
174 * (see the 80486 manual p16-28) */
176 case 015: /* fistp m32int */
177 if (reg_store_int32())
178 pop_0();/* pop only if the number was actually stored
179 * (see the 80486 manual p16-28) */
181 case 016: /* fstp m64real */
182 if (reg_store_double())
183 pop_0();/* pop only if the number was actually stored
184 * (see the 80486 manual p16-28) */
186 case 017: /* fistp m16int */
187 if (reg_store_int16())
188 pop_0();/* pop only if the number was actually stored
189 * (see the 80486 manual p16-28) */
191 case 020: /* fldenv m14/28byte */
194 case 022: /* frstor m94/108byte */
197 case 023: /* fbld m80dec */
199 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
200 reg_move(&FPU_loaded_data, pop_ptr);
202 case 024: /* fldcw */
203 REENTRANT_CHECK(OFF);
204 control_word = fusword((unsigned short *) FPU_data_address);
206 #ifdef NO_UNDERFLOW_TRAP
207 if (!(control_word & EX_Underflow)) {
208 control_word |= EX_Underflow;
211 /* We want no net effect: */
212 FPU_data_address = (void *) (intptr_t) data_operand_offset;
213 FPU_entry_eip = ip_offset; /* We want no net effect */
215 case 025: /* fld m80real */
217 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
218 reg_move(&FPU_loaded_data, pop_ptr);
220 case 027: /* fild m64int */
222 setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
223 reg_move(&FPU_loaded_data, pop_ptr);
225 case 030: /* fstenv m14/28byte */
227 /* We want no net effect: */
228 FPU_data_address = (void *) (intptr_t) data_operand_offset;
229 FPU_entry_eip = ip_offset; /* We want no net effect */
231 case 032: /* fsave */
233 /* We want no net effect: */
234 FPU_data_address = (void *) (intptr_t) data_operand_offset;
235 FPU_entry_eip = ip_offset; /* We want no net effect */
237 case 033: /* fbstp m80dec */
239 pop_0();/* pop only if the number was actually stored
240 * (see the 80486 manual p16-28) */
242 case 034: /* fstcw m16int */
243 REENTRANT_CHECK(OFF);
244 /* verify_area(VERIFY_WRITE, FPU_data_address, 2);*/
245 susword( (short *) FPU_data_address,control_word);
247 /* We want no net effect: */
248 FPU_data_address = (void *) (intptr_t ) data_operand_offset;
249 FPU_entry_eip = ip_offset; /* We want no net effect */
251 case 035: /* fstp m80real */
252 if (reg_store_extended())
253 pop_0();/* pop only if the number was actually stored
254 * (see the 80486 manual p16-28) */
256 case 036: /* fstsw m2byte */
257 status_word &= ~SW_Top;
258 status_word |= (top & 7) << SW_Top_Shift;
259 REENTRANT_CHECK(OFF);
260 /* verify_area(VERIFY_WRITE, FPU_data_address, 2);*/
261 susword( (short *) FPU_data_address,status_word);
263 /* We want no net effect: */
264 FPU_data_address = (void *) (intptr_t) data_operand_offset;
265 FPU_entry_eip = ip_offset; /* We want no net effect */
267 case 037: /* fistp m64int */
268 if (reg_store_int64())
269 pop_0();/* pop only if the number was actually stored
270 * (see the 80486 manual p16-28) */