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, |
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"
29 #define _NONE_ 0 /* st0_ptr etc not needed */
30 #define _REG0_ 1 /* Will be storing st(0) */
31 #define _PUSH_ 3 /* Need to check for space to push onto stack */
32 #define _null_ 4 /* Function illegal or not implemented */
34 #define pop_0() { FPU_settag0(TAG_Empty); top++; }
36 /* index is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
37 static u_char const type_table[32] = {
38 _PUSH_, _PUSH_, _PUSH_, _PUSH_, /* /0: d9:fld f32, db:fild m32, dd:fld f64, df:fild m16 */
39 _null_, _REG0_, _REG0_, _REG0_, /* /1: d9:undef, db,dd,df:fisttp m32/64/16 */
40 _REG0_, _REG0_, _REG0_, _REG0_, /* /2: d9:fst f32, db:fist m32, dd:fst f64, df:fist m16 */
41 _REG0_, _REG0_, _REG0_, _REG0_, /* /3: d9:fstp f32, db:fistp m32, dd:fstp f64, df:fistp m16 */
42 _NONE_, _null_, _NONE_, _PUSH_,
43 _NONE_, _PUSH_, _null_, _PUSH_,
44 _NONE_, _null_, _NONE_, _REG0_,
45 _NONE_, _REG0_, _NONE_, _REG0_
48 u_char const data_sizes_16[32] = {
50 0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
53 14, 0, 94, 10, 2, 10, 0, 8,
54 14, 0, 94, 10, 2, 10, 2, 8
57 static u_char const data_sizes_32[32] = {
59 0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
62 28, 0, 108, 10, 2, 10, 0, 8,
63 28, 0, 108, 10, 2, 10, 2, 8
66 int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
67 void __user * data_address)
71 u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. */
75 st0_ptr = NULL; /* Initialized just to stop compiler warnings. */
77 if (addr_modes.default_mode & PROTECTED) {
78 if (addr_modes.default_mode == SEG32) {
79 if (access_limit < data_sizes_32[type])
80 math_abort(FPU_info, SIGSEGV);
81 } 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]) {
95 st0_ptr = &st(0); /* Some of these instructions pop after
97 st0_tag = FPU_gettag0();
101 if (FPU_gettagi(-1) != TAG_Empty) {
102 FPU_stack_overflow();
114 EXCEPTION(EX_INTERNAL | 0x141);
116 #endif /* PARANOID */
120 /* type is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
121 case 000: /* fld m32real (d9 /0) */
124 FPU_load_single((float __user *)data_address, &loaded_data);
125 if ((loaded_tag == TAG_Special)
126 && isNaN(&loaded_data)
127 && (real_1op_NaN(&loaded_data) < 0)) {
131 FPU_copy_to_reg0(&loaded_data, loaded_tag);
133 case 001: /* fild m32int (db /0) */
136 FPU_load_int32((long __user *)data_address, &loaded_data);
137 FPU_copy_to_reg0(&loaded_data, loaded_tag);
139 case 002: /* fld m64real (dd /0) */
142 FPU_load_double((double __user *)data_address,
144 if ((loaded_tag == TAG_Special)
145 && isNaN(&loaded_data)
146 && (real_1op_NaN(&loaded_data) < 0)) {
150 FPU_copy_to_reg0(&loaded_data, loaded_tag);
152 case 003: /* fild m16int (df /0) */
155 FPU_load_int16((short __user *)data_address, &loaded_data);
156 FPU_copy_to_reg0(&loaded_data, loaded_tag);
158 /* case 004: undefined (d9 /1) */
159 /* fisttp are enabled if CPUID(1).ECX(0) "sse3" is set */
160 case 005: /* fisttp m32int (db /1) */
162 sv_cw = control_word;
163 control_word |= RC_CHOP;
165 (st0_ptr, st0_tag, (long __user *)data_address))
166 pop_0(); /* pop only if the number was actually stored
167 (see the 80486 manual p16-28) */
168 control_word = sv_cw;
170 case 006: /* fisttp m64int (dd /1) */
172 sv_cw = control_word;
173 control_word |= RC_CHOP;
175 (st0_ptr, st0_tag, (long long __user *)data_address))
176 pop_0(); /* pop only if the number was actually stored
177 (see the 80486 manual p16-28) */
178 control_word = sv_cw;
180 case 007: /* fisttp m16int (df /1) */
182 sv_cw = control_word;
183 control_word |= RC_CHOP;
185 (st0_ptr, st0_tag, (short __user *)data_address))
186 pop_0(); /* pop only if the number was actually stored
187 (see the 80486 manual p16-28) */
188 control_word = sv_cw;
190 case 010: /* fst m32real */
192 FPU_store_single(st0_ptr, st0_tag,
193 (float __user *)data_address);
195 case 011: /* fist m32int */
197 FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address);
199 case 012: /* fst m64real */
201 FPU_store_double(st0_ptr, st0_tag,
202 (double __user *)data_address);
204 case 013: /* fist m16int */
206 FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address);
208 case 014: /* fstp m32real */
211 (st0_ptr, st0_tag, (float __user *)data_address))
212 pop_0(); /* pop only if the number was actually stored
213 (see the 80486 manual p16-28) */
215 case 015: /* fistp m32int */
218 (st0_ptr, st0_tag, (long __user *)data_address))
219 pop_0(); /* pop only if the number was actually stored
220 (see the 80486 manual p16-28) */
222 case 016: /* fstp m64real */
225 (st0_ptr, st0_tag, (double __user *)data_address))
226 pop_0(); /* pop only if the number was actually stored
227 (see the 80486 manual p16-28) */
229 case 017: /* fistp m16int */
232 (st0_ptr, st0_tag, (short __user *)data_address))
233 pop_0(); /* pop only if the number was actually stored
234 (see the 80486 manual p16-28) */
236 case 020: /* fldenv m14/28byte */
237 fldenv(addr_modes, (u_char __user *) data_address);
238 /* Ensure that the values just loaded are not changed by
239 fix-up operations. */
241 case 022: /* frstor m94/108byte */
242 frstor(addr_modes, (u_char __user *) data_address);
243 /* Ensure that the values just loaded are not changed by
244 fix-up operations. */
246 case 023: /* fbld m80dec */
248 loaded_tag = FPU_load_bcd((u_char __user *) data_address);
249 FPU_settag0(loaded_tag);
251 case 024: /* fldcw */
252 RE_ENTRANT_CHECK_OFF;
253 FPU_access_ok(VERIFY_READ, data_address, 2);
254 FPU_get_user(control_word,
255 (unsigned short __user *)data_address);
257 if (partial_status & ~control_word & CW_Exceptions)
258 partial_status |= (SW_Summary | SW_Backward);
260 partial_status &= ~(SW_Summary | SW_Backward);
262 control_word |= 0x40; /* An 80486 appears to always set this bit */
263 #endif /* PECULIAR_486 */
265 case 025: /* fld m80real */
268 FPU_load_extended((long double __user *)data_address, 0);
269 FPU_settag0(loaded_tag);
271 case 027: /* fild m64int */
273 loaded_tag = FPU_load_int64((long long __user *)data_address);
274 if (loaded_tag == TAG_Error)
276 FPU_settag0(loaded_tag);
278 case 030: /* fstenv m14/28byte */
279 fstenv(addr_modes, (u_char __user *) data_address);
281 case 032: /* fsave */
282 fsave(addr_modes, (u_char __user *) data_address);
284 case 033: /* fbstp m80dec */
287 (st0_ptr, st0_tag, (u_char __user *) data_address))
288 pop_0(); /* pop only if the number was actually stored
289 (see the 80486 manual p16-28) */
291 case 034: /* fstcw m16int */
292 RE_ENTRANT_CHECK_OFF;
293 FPU_access_ok(VERIFY_WRITE, data_address, 2);
294 FPU_put_user(control_word,
295 (unsigned short __user *)data_address);
298 case 035: /* fstp m80real */
300 if (FPU_store_extended
301 (st0_ptr, st0_tag, (long double __user *)data_address))
302 pop_0(); /* pop only if the number was actually stored
303 (see the 80486 manual p16-28) */
305 case 036: /* fstsw m2byte */
306 RE_ENTRANT_CHECK_OFF;
307 FPU_access_ok(VERIFY_WRITE, data_address, 2);
308 FPU_put_user(status_word(),
309 (unsigned short __user *)data_address);
312 case 037: /* fistp m64int */
315 (st0_ptr, st0_tag, (long long __user *)data_address))
316 pop_0(); /* pop only if the number was actually stored
317 (see the 80486 manual p16-28) */