Blame view

arch/x86/math-emu/load_store.c 8.51 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  /*---------------------------------------------------------------------------+
   |  load_store.c                                                             |
   |                                                                           |
   | This file contains most of the code to interpret the FPU instructions     |
   | which load and store from user memory.                                    |
   |                                                                           |
   | Copyright (C) 1992,1993,1994,1997                                         |
   |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
   |                       Australia.  E-mail   billm@suburbia.net             |
   |                                                                           |
   |                                                                           |
   +---------------------------------------------------------------------------*/
  
  /*---------------------------------------------------------------------------+
   | Note:                                                                     |
   |    The file contains code which accesses user memory.                     |
   |    Emulator static data may change when user memory is accessed, due to   |
   |    other processes using the emulator while swapping is in progress.      |
   +---------------------------------------------------------------------------*/
  
  #include <asm/uaccess.h>
  
  #include "fpu_system.h"
  #include "exception.h"
  #include "fpu_emu.h"
  #include "status_w.h"
  #include "control_w.h"
3d0d14f98   Ingo Molnar   x86: lindent arch...
28
29
30
31
  #define _NONE_ 0		/* st0_ptr etc not needed */
  #define _REG0_ 1		/* Will be storing st(0) */
  #define _PUSH_ 3		/* Need to check for space to push onto stack */
  #define _null_ 4		/* Function illegal or not implemented */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
  
  #define pop_0()	{ FPU_settag0(TAG_Empty); top++; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
  static u_char const type_table[32] = {
3d0d14f98   Ingo Molnar   x86: lindent arch...
35
36
37
38
39
40
41
42
43
  	_PUSH_, _PUSH_, _PUSH_, _PUSH_,
  	_null_, _null_, _null_, _null_,
  	_REG0_, _REG0_, _REG0_, _REG0_,
  	_REG0_, _REG0_, _REG0_, _REG0_,
  	_NONE_, _null_, _NONE_, _PUSH_,
  	_NONE_, _PUSH_, _null_, _PUSH_,
  	_NONE_, _null_, _NONE_, _REG0_,
  	_NONE_, _REG0_, _NONE_, _REG0_
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  
  u_char const data_sizes_16[32] = {
3d0d14f98   Ingo Molnar   x86: lindent arch...
46
47
48
49
  	4, 4, 8, 2, 0, 0, 0, 0,
  	4, 4, 8, 2, 4, 4, 8, 2,
  	14, 0, 94, 10, 2, 10, 0, 8,
  	14, 0, 94, 10, 2, 10, 2, 8
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
  };
  
  static u_char const data_sizes_32[32] = {
3d0d14f98   Ingo Molnar   x86: lindent arch...
53
54
55
56
  	4, 4, 8, 2, 0, 0, 0, 0,
  	4, 4, 8, 2, 4, 4, 8, 2,
  	28, 0, 108, 10, 2, 10, 0, 8,
  	28, 0, 108, 10, 2, 10, 2, 8
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
  };
  
  int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
3d0d14f98   Ingo Molnar   x86: lindent arch...
60
  		   void __user * data_address)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  {
3d0d14f98   Ingo Molnar   x86: lindent arch...
62
63
64
65
  	FPU_REG loaded_data;
  	FPU_REG *st0_ptr;
  	u_char st0_tag = TAG_Empty;	/* This is just to stop a gcc warning. */
  	u_char loaded_tag;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66

3d0d14f98   Ingo Molnar   x86: lindent arch...
67
  	st0_ptr = NULL;		/* Initialized just to stop compiler warnings. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68

3d0d14f98   Ingo Molnar   x86: lindent arch...
69
70
71
72
73
74
75
76
  	if (addr_modes.default_mode & PROTECTED) {
  		if (addr_modes.default_mode == SEG32) {
  			if (access_limit < data_sizes_32[type])
  				math_abort(FPU_info, SIGSEGV);
  		} else if (addr_modes.default_mode == PM16) {
  			if (access_limit < data_sizes_16[type])
  				math_abort(FPU_info, SIGSEGV);
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  #ifdef PARANOID
3d0d14f98   Ingo Molnar   x86: lindent arch...
78
79
  		else
  			EXCEPTION(EX_INTERNAL | 0x140);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  #endif /* PARANOID */
3d0d14f98   Ingo Molnar   x86: lindent arch...
81
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82

3d0d14f98   Ingo Molnar   x86: lindent arch...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  	switch (type_table[type]) {
  	case _NONE_:
  		break;
  	case _REG0_:
  		st0_ptr = &st(0);	/* Some of these instructions pop after
  					   storing */
  		st0_tag = FPU_gettag0();
  		break;
  	case _PUSH_:
  		{
  			if (FPU_gettagi(-1) != TAG_Empty) {
  				FPU_stack_overflow();
  				return 0;
  			}
  			top--;
  			st0_ptr = &st(0);
  		}
  		break;
  	case _null_:
  		FPU_illegal();
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
  #ifdef PARANOID
3d0d14f98   Ingo Molnar   x86: lindent arch...
105
106
107
  	default:
  		EXCEPTION(EX_INTERNAL | 0x141);
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
  #endif /* PARANOID */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  	}
3d0d14f98   Ingo Molnar   x86: lindent arch...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  
  	switch (type) {
  	case 000:		/* fld m32real */
  		clear_C1();
  		loaded_tag =
  		    FPU_load_single((float __user *)data_address, &loaded_data);
  		if ((loaded_tag == TAG_Special)
  		    && isNaN(&loaded_data)
  		    && (real_1op_NaN(&loaded_data) < 0)) {
  			top++;
  			break;
  		}
  		FPU_copy_to_reg0(&loaded_data, loaded_tag);
  		break;
  	case 001:		/* fild m32int */
  		clear_C1();
  		loaded_tag =
  		    FPU_load_int32((long __user *)data_address, &loaded_data);
  		FPU_copy_to_reg0(&loaded_data, loaded_tag);
  		break;
  	case 002:		/* fld m64real */
  		clear_C1();
  		loaded_tag =
  		    FPU_load_double((double __user *)data_address,
  				    &loaded_data);
  		if ((loaded_tag == TAG_Special)
  		    && isNaN(&loaded_data)
  		    && (real_1op_NaN(&loaded_data) < 0)) {
  			top++;
  			break;
  		}
  		FPU_copy_to_reg0(&loaded_data, loaded_tag);
  		break;
  	case 003:		/* fild m16int */
  		clear_C1();
  		loaded_tag =
  		    FPU_load_int16((short __user *)data_address, &loaded_data);
  		FPU_copy_to_reg0(&loaded_data, loaded_tag);
  		break;
  	case 010:		/* fst m32real */
  		clear_C1();
  		FPU_store_single(st0_ptr, st0_tag,
  				 (float __user *)data_address);
  		break;
  	case 011:		/* fist m32int */
  		clear_C1();
  		FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address);
  		break;
  	case 012:		/* fst m64real */
  		clear_C1();
  		FPU_store_double(st0_ptr, st0_tag,
  				 (double __user *)data_address);
  		break;
  	case 013:		/* fist m16int */
  		clear_C1();
  		FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address);
  		break;
  	case 014:		/* fstp m32real */
  		clear_C1();
  		if (FPU_store_single
  		    (st0_ptr, st0_tag, (float __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 015:		/* fistp m32int */
  		clear_C1();
  		if (FPU_store_int32
  		    (st0_ptr, st0_tag, (long __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 016:		/* fstp m64real */
  		clear_C1();
  		if (FPU_store_double
  		    (st0_ptr, st0_tag, (double __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 017:		/* fistp m16int */
  		clear_C1();
  		if (FPU_store_int16
  		    (st0_ptr, st0_tag, (short __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 020:		/* fldenv  m14/28byte */
  		fldenv(addr_modes, (u_char __user *) data_address);
  		/* Ensure that the values just loaded are not changed by
  		   fix-up operations. */
  		return 1;
  	case 022:		/* frstor m94/108byte */
  		frstor(addr_modes, (u_char __user *) data_address);
  		/* Ensure that the values just loaded are not changed by
  		   fix-up operations. */
  		return 1;
  	case 023:		/* fbld m80dec */
  		clear_C1();
  		loaded_tag = FPU_load_bcd((u_char __user *) data_address);
  		FPU_settag0(loaded_tag);
  		break;
  	case 024:		/* fldcw */
  		RE_ENTRANT_CHECK_OFF;
  		FPU_access_ok(VERIFY_READ, data_address, 2);
  		FPU_get_user(control_word,
  			     (unsigned short __user *)data_address);
  		RE_ENTRANT_CHECK_ON;
  		if (partial_status & ~control_word & CW_Exceptions)
  			partial_status |= (SW_Summary | SW_Backward);
  		else
  			partial_status &= ~(SW_Summary | SW_Backward);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220
  #ifdef PECULIAR_486
3d0d14f98   Ingo Molnar   x86: lindent arch...
221
  		control_word |= 0x40;	/* An 80486 appears to always set this bit */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
  #endif /* PECULIAR_486 */
3d0d14f98   Ingo Molnar   x86: lindent arch...
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
  		return 1;
  	case 025:		/* fld m80real */
  		clear_C1();
  		loaded_tag =
  		    FPU_load_extended((long double __user *)data_address, 0);
  		FPU_settag0(loaded_tag);
  		break;
  	case 027:		/* fild m64int */
  		clear_C1();
  		loaded_tag = FPU_load_int64((long long __user *)data_address);
  		if (loaded_tag == TAG_Error)
  			return 0;
  		FPU_settag0(loaded_tag);
  		break;
  	case 030:		/* fstenv  m14/28byte */
  		fstenv(addr_modes, (u_char __user *) data_address);
  		return 1;
  	case 032:		/* fsave */
  		fsave(addr_modes, (u_char __user *) data_address);
  		return 1;
  	case 033:		/* fbstp m80dec */
  		clear_C1();
  		if (FPU_store_bcd
  		    (st0_ptr, st0_tag, (u_char __user *) data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 034:		/* fstcw m16int */
  		RE_ENTRANT_CHECK_OFF;
  		FPU_access_ok(VERIFY_WRITE, data_address, 2);
  		FPU_put_user(control_word,
  			     (unsigned short __user *)data_address);
  		RE_ENTRANT_CHECK_ON;
  		return 1;
  	case 035:		/* fstp m80real */
  		clear_C1();
  		if (FPU_store_extended
  		    (st0_ptr, st0_tag, (long double __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	case 036:		/* fstsw m2byte */
  		RE_ENTRANT_CHECK_OFF;
  		FPU_access_ok(VERIFY_WRITE, data_address, 2);
  		FPU_put_user(status_word(),
  			     (unsigned short __user *)data_address);
  		RE_ENTRANT_CHECK_ON;
  		return 1;
  	case 037:		/* fistp m64int */
  		clear_C1();
  		if (FPU_store_int64
  		    (st0_ptr, st0_tag, (long long __user *)data_address))
  			pop_0();	/* pop only if the number was actually stored
  					   (see the 80486 manual p16-28) */
  		break;
  	}
d606f88fa   Randy Dunlap   [PATCH] i386: fix...
279
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
  }