1 /*---------------------------------------------------------------------------+
4 | This file contains most of the code to interpret the FPU instructions |
5 | which load and store from user memory. |
7 | Copyright (C) 1992,1993,1994,1997 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
9 | Australia. E-mail billm@suburbia.net |
12 +---------------------------------------------------------------------------*/
14 /*---------------------------------------------------------------------------+
16 | The file contains code which accesses user memory. |
17 | Emulator static data may change when user memory is accessed, due to |
18 | other processes using the emulator while swapping is in progress. |
19 +---------------------------------------------------------------------------*/
21 #include <asm/uaccess.h>
23 #include "fpu_system.h"
24 #include "exception.h"
27 #include "control_w.h"
30 #define _NONE_ 0 /* st0_ptr etc not needed */
31 #define _REG0_ 1 /* Will be storing st(0) */
32 #define _PUSH_ 3 /* Need to check for space to push onto stack */
33 #define _null_ 4 /* Function illegal or not implemented */
35 #define pop_0() { FPU_settag0(TAG_Empty); top++; }
38 static u_char
const type_table
[32] = {
39 _PUSH_
, _PUSH_
, _PUSH_
, _PUSH_
,
40 _null_
, _null_
, _null_
, _null_
,
41 _REG0_
, _REG0_
, _REG0_
, _REG0_
,
42 _REG0_
, _REG0_
, _REG0_
, _REG0_
,
43 _NONE_
, _null_
, _NONE_
, _PUSH_
,
44 _NONE_
, _PUSH_
, _null_
, _PUSH_
,
45 _NONE_
, _null_
, _NONE_
, _REG0_
,
46 _NONE_
, _REG0_
, _NONE_
, _REG0_
49 u_char
const data_sizes_16
[32] = {
50 4, 4, 8, 2, 0, 0, 0, 0,
51 4, 4, 8, 2, 4, 4, 8, 2,
52 14, 0, 94, 10, 2, 10, 0, 8,
53 14, 0, 94, 10, 2, 10, 2, 8
56 static u_char
const data_sizes_32
[32] = {
57 4, 4, 8, 2, 0, 0, 0, 0,
58 4, 4, 8, 2, 4, 4, 8, 2,
59 28, 0,108, 10, 2, 10, 0, 8,
60 28, 0,108, 10, 2, 10, 2, 8
63 int FPU_load_store(u_char type
, fpu_addr_modes addr_modes
,
64 void __user
*data_address
)
68 u_char st0_tag
= TAG_Empty
; /* This is just to stop a gcc warning. */
71 st0_ptr
= NULL
; /* Initialized just to stop compiler warnings. */
73 if ( addr_modes
.default_mode
& PROTECTED
)
75 if ( addr_modes
.default_mode
== SEG32
)
77 if ( access_limit
< data_sizes_32
[type
] )
78 math_abort(FPU_info
,SIGSEGV
);
80 else if ( addr_modes
.default_mode
== PM16
)
82 if ( access_limit
< data_sizes_16
[type
] )
83 math_abort(FPU_info
,SIGSEGV
);
87 EXCEPTION(EX_INTERNAL
|0x140);
91 switch ( type_table
[type
] )
96 st0_ptr
= &st(0); /* Some of these instructions pop after
98 st0_tag
= FPU_gettag0();
102 if ( FPU_gettagi(-1) != TAG_Empty
)
103 { FPU_stack_overflow(); return 0; }
113 EXCEPTION(EX_INTERNAL
|0x141);
115 #endif /* PARANOID */
120 case 000: /* fld m32real */
122 loaded_tag
= FPU_load_single((float __user
*)data_address
, &loaded_data
);
123 if ( (loaded_tag
== TAG_Special
)
124 && isNaN(&loaded_data
)
125 && (real_1op_NaN(&loaded_data
) < 0) )
130 FPU_copy_to_reg0(&loaded_data
, loaded_tag
);
132 case 001: /* fild m32int */
134 loaded_tag
= FPU_load_int32((long __user
*)data_address
, &loaded_data
);
135 FPU_copy_to_reg0(&loaded_data
, loaded_tag
);
137 case 002: /* fld m64real */
139 loaded_tag
= FPU_load_double((double __user
*)data_address
, &loaded_data
);
140 if ( (loaded_tag
== TAG_Special
)
141 && isNaN(&loaded_data
)
142 && (real_1op_NaN(&loaded_data
) < 0) )
147 FPU_copy_to_reg0(&loaded_data
, loaded_tag
);
149 case 003: /* fild m16int */
151 loaded_tag
= FPU_load_int16((short __user
*)data_address
, &loaded_data
);
152 FPU_copy_to_reg0(&loaded_data
, loaded_tag
);
154 case 010: /* fst m32real */
156 FPU_store_single(st0_ptr
, st0_tag
, (float __user
*)data_address
);
158 case 011: /* fist m32int */
160 FPU_store_int32(st0_ptr
, st0_tag
, (long __user
*)data_address
);
162 case 012: /* fst m64real */
164 FPU_store_double(st0_ptr
, st0_tag
, (double __user
*)data_address
);
166 case 013: /* fist m16int */
168 FPU_store_int16(st0_ptr
, st0_tag
, (short __user
*)data_address
);
170 case 014: /* fstp m32real */
172 if ( FPU_store_single(st0_ptr
, st0_tag
, (float __user
*)data_address
) )
173 pop_0(); /* pop only if the number was actually stored
174 (see the 80486 manual p16-28) */
176 case 015: /* fistp m32int */
178 if ( FPU_store_int32(st0_ptr
, st0_tag
, (long __user
*)data_address
) )
179 pop_0(); /* pop only if the number was actually stored
180 (see the 80486 manual p16-28) */
182 case 016: /* fstp m64real */
184 if ( FPU_store_double(st0_ptr
, st0_tag
, (double __user
*)data_address
) )
185 pop_0(); /* pop only if the number was actually stored
186 (see the 80486 manual p16-28) */
188 case 017: /* fistp m16int */
190 if ( FPU_store_int16(st0_ptr
, st0_tag
, (short __user
*)data_address
) )
191 pop_0(); /* pop only if the number was actually stored
192 (see the 80486 manual p16-28) */
194 case 020: /* fldenv m14/28byte */
195 fldenv(addr_modes
, (u_char __user
*)data_address
);
196 /* Ensure that the values just loaded are not changed by
197 fix-up operations. */
199 case 022: /* frstor m94/108byte */
200 frstor(addr_modes
, (u_char __user
*)data_address
);
201 /* Ensure that the values just loaded are not changed by
202 fix-up operations. */
204 case 023: /* fbld m80dec */
206 loaded_tag
= FPU_load_bcd((u_char __user
*)data_address
);
207 FPU_settag0(loaded_tag
);
209 case 024: /* fldcw */
210 RE_ENTRANT_CHECK_OFF
;
211 FPU_access_ok(VERIFY_READ
, data_address
, 2);
212 FPU_get_user(control_word
, (unsigned short __user
*) data_address
);
214 if ( partial_status
& ~control_word
& CW_Exceptions
)
215 partial_status
|= (SW_Summary
| SW_Backward
);
217 partial_status
&= ~(SW_Summary
| SW_Backward
);
219 control_word
|= 0x40; /* An 80486 appears to always set this bit */
220 #endif /* PECULIAR_486 */
222 case 025: /* fld m80real */
224 loaded_tag
= FPU_load_extended((long double __user
*)data_address
, 0);
225 FPU_settag0(loaded_tag
);
227 case 027: /* fild m64int */
229 loaded_tag
= FPU_load_int64((long long __user
*)data_address
);
230 FPU_settag0(loaded_tag
);
232 case 030: /* fstenv m14/28byte */
233 fstenv(addr_modes
, (u_char __user
*)data_address
);
235 case 032: /* fsave */
236 fsave(addr_modes
, (u_char __user
*)data_address
);
238 case 033: /* fbstp m80dec */
240 if ( FPU_store_bcd(st0_ptr
, st0_tag
, (u_char __user
*)data_address
) )
241 pop_0(); /* pop only if the number was actually stored
242 (see the 80486 manual p16-28) */
244 case 034: /* fstcw m16int */
245 RE_ENTRANT_CHECK_OFF
;
246 FPU_access_ok(VERIFY_WRITE
,data_address
,2);
247 FPU_put_user(control_word
, (unsigned short __user
*) data_address
);
250 case 035: /* fstp m80real */
252 if ( FPU_store_extended(st0_ptr
, st0_tag
, (long double __user
*)data_address
) )
253 pop_0(); /* pop only if the number was actually stored
254 (see the 80486 manual p16-28) */
256 case 036: /* fstsw m2byte */
257 RE_ENTRANT_CHECK_OFF
;
258 FPU_access_ok(VERIFY_WRITE
,data_address
,2);
259 FPU_put_user(status_word(),(unsigned short __user
*) data_address
);
262 case 037: /* fistp m64int */
264 if ( FPU_store_int64(st0_ptr
, st0_tag
, (long long __user
*)data_address
) )
265 pop_0(); /* pop only if the number was actually stored
266 (see the 80486 manual p16-28) */