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"
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
static u_char const type_table[32] = {
37
_PUSH_, _PUSH_, _PUSH_, _PUSH_,
38
_null_, _null_, _null_, _null_,
39
_REG0_, _REG0_, _REG0_, _REG0_,
40
_REG0_, _REG0_, _REG0_, _REG0_,
41
_NONE_, _null_, _NONE_, _PUSH_,
42
_NONE_, _PUSH_, _null_, _PUSH_,
43
_NONE_, _null_, _NONE_, _REG0_,
44
_NONE_, _REG0_, _NONE_, _REG0_
47
u_char const data_sizes_16[32] = {
48
4, 4, 8, 2, 0, 0, 0, 0,
49
4, 4, 8, 2, 4, 4, 8, 2,
50
14, 0, 94, 10, 2, 10, 0, 8,
51
14, 0, 94, 10, 2, 10, 2, 8
54
static u_char const data_sizes_32[32] = {
55
4, 4, 8, 2, 0, 0, 0, 0,
56
4, 4, 8, 2, 4, 4, 8, 2,
57
28, 0, 108, 10, 2, 10, 0, 8,
58
28, 0, 108, 10, 2, 10, 2, 8
61
int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
62
void __user * data_address)
66
u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. */
69
st0_ptr = NULL; /* Initialized just to stop compiler warnings. */
71
if (addr_modes.default_mode & PROTECTED) {
72
if (addr_modes.default_mode == SEG32) {
73
if (access_limit < data_sizes_32[type])
74
math_abort(FPU_info, SIGSEGV);
75
} else if (addr_modes.default_mode == PM16) {
76
if (access_limit < data_sizes_16[type])
77
math_abort(FPU_info, SIGSEGV);
81
EXCEPTION(EX_INTERNAL | 0x140);
85
switch (type_table[type]) {
89
st0_ptr = &st(0); /* Some of these instructions pop after
91
st0_tag = FPU_gettag0();
95
if (FPU_gettagi(-1) != TAG_Empty) {
108
EXCEPTION(EX_INTERNAL | 0x141);
110
#endif /* PARANOID */
114
case 000: /* fld m32real */
117
FPU_load_single((float __user *)data_address, &loaded_data);
118
if ((loaded_tag == TAG_Special)
119
&& isNaN(&loaded_data)
120
&& (real_1op_NaN(&loaded_data) < 0)) {
124
FPU_copy_to_reg0(&loaded_data, loaded_tag);
126
case 001: /* fild m32int */
129
FPU_load_int32((long __user *)data_address, &loaded_data);
130
FPU_copy_to_reg0(&loaded_data, loaded_tag);
132
case 002: /* fld m64real */
135
FPU_load_double((double __user *)data_address,
137
if ((loaded_tag == TAG_Special)
138
&& isNaN(&loaded_data)
139
&& (real_1op_NaN(&loaded_data) < 0)) {
143
FPU_copy_to_reg0(&loaded_data, loaded_tag);
145
case 003: /* fild m16int */
148
FPU_load_int16((short __user *)data_address, &loaded_data);
149
FPU_copy_to_reg0(&loaded_data, loaded_tag);
151
case 010: /* fst m32real */
153
FPU_store_single(st0_ptr, st0_tag,
154
(float __user *)data_address);
156
case 011: /* fist m32int */
158
FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address);
160
case 012: /* fst m64real */
162
FPU_store_double(st0_ptr, st0_tag,
163
(double __user *)data_address);
165
case 013: /* fist m16int */
167
FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address);
169
case 014: /* fstp m32real */
172
(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 */
179
(st0_ptr, st0_tag, (long __user *)data_address))
180
pop_0(); /* pop only if the number was actually stored
181
(see the 80486 manual p16-28) */
183
case 016: /* fstp m64real */
186
(st0_ptr, st0_tag, (double __user *)data_address))
187
pop_0(); /* pop only if the number was actually stored
188
(see the 80486 manual p16-28) */
190
case 017: /* fistp m16int */
193
(st0_ptr, st0_tag, (short __user *)data_address))
194
pop_0(); /* pop only if the number was actually stored
195
(see the 80486 manual p16-28) */
197
case 020: /* fldenv m14/28byte */
198
fldenv(addr_modes, (u_char __user *) data_address);
199
/* Ensure that the values just loaded are not changed by
200
fix-up operations. */
202
case 022: /* frstor m94/108byte */
203
frstor(addr_modes, (u_char __user *) data_address);
204
/* Ensure that the values just loaded are not changed by
205
fix-up operations. */
207
case 023: /* fbld m80dec */
209
loaded_tag = FPU_load_bcd((u_char __user *) data_address);
210
FPU_settag0(loaded_tag);
212
case 024: /* fldcw */
213
RE_ENTRANT_CHECK_OFF;
214
FPU_access_ok(VERIFY_READ, data_address, 2);
215
FPU_get_user(control_word,
216
(unsigned short __user *)data_address);
218
if (partial_status & ~control_word & CW_Exceptions)
219
partial_status |= (SW_Summary | SW_Backward);
221
partial_status &= ~(SW_Summary | SW_Backward);
223
control_word |= 0x40; /* An 80486 appears to always set this bit */
224
#endif /* PECULIAR_486 */
226
case 025: /* fld m80real */
229
FPU_load_extended((long double __user *)data_address, 0);
230
FPU_settag0(loaded_tag);
232
case 027: /* fild m64int */
234
loaded_tag = FPU_load_int64((long long __user *)data_address);
235
if (loaded_tag == TAG_Error)
237
FPU_settag0(loaded_tag);
239
case 030: /* fstenv m14/28byte */
240
fstenv(addr_modes, (u_char __user *) data_address);
242
case 032: /* fsave */
243
fsave(addr_modes, (u_char __user *) data_address);
245
case 033: /* fbstp m80dec */
248
(st0_ptr, st0_tag, (u_char __user *) data_address))
249
pop_0(); /* pop only if the number was actually stored
250
(see the 80486 manual p16-28) */
252
case 034: /* fstcw m16int */
253
RE_ENTRANT_CHECK_OFF;
254
FPU_access_ok(VERIFY_WRITE, data_address, 2);
255
FPU_put_user(control_word,
256
(unsigned short __user *)data_address);
259
case 035: /* fstp m80real */
261
if (FPU_store_extended
262
(st0_ptr, st0_tag, (long double __user *)data_address))
263
pop_0(); /* pop only if the number was actually stored
264
(see the 80486 manual p16-28) */
266
case 036: /* fstsw m2byte */
267
RE_ENTRANT_CHECK_OFF;
268
FPU_access_ok(VERIFY_WRITE, data_address, 2);
269
FPU_put_user(status_word(),
270
(unsigned short __user *)data_address);
273
case 037: /* fistp m64int */
276
(st0_ptr, st0_tag, (long long __user *)data_address))
277
pop_0(); /* pop only if the number was actually stored
278
(see the 80486 manual p16-28) */