root / op-i386.c @ d34720fd
History | View | Annotate | Download (48.4 kB)
1 |
/*
|
---|---|
2 |
* i386 micro operations
|
3 |
*
|
4 |
* Copyright (c) 2003 Fabrice Bellard
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation; either
|
9 |
* version 2 of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with this library; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
#include "exec-i386.h" |
21 |
|
22 |
/* NOTE: data are not static to force relocation generation by GCC */
|
23 |
|
24 |
uint8_t parity_table[256] = {
|
25 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
26 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
27 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
28 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
29 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
30 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
31 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
32 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
33 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
34 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
35 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
36 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
37 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
38 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
39 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
40 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
41 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
42 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
43 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
44 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
45 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
46 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
47 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
48 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
49 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
50 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
51 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
52 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
53 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
54 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
55 |
CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0, |
56 |
0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, |
57 |
}; |
58 |
|
59 |
/* modulo 17 table */
|
60 |
const uint8_t rclw_table[32] = { |
61 |
0, 1, 2, 3, 4, 5, 6, 7, |
62 |
8, 9,10,11,12,13,14,15, |
63 |
16, 0, 1, 2, 3, 4, 5, 6, |
64 |
7, 8, 9,10,11,12,13,14, |
65 |
}; |
66 |
|
67 |
/* modulo 9 table */
|
68 |
const uint8_t rclb_table[32] = { |
69 |
0, 1, 2, 3, 4, 5, 6, 7, |
70 |
8, 0, 1, 2, 3, 4, 5, 6, |
71 |
7, 8, 0, 1, 2, 3, 4, 5, |
72 |
6, 7, 8, 0, 1, 2, 3, 4, |
73 |
}; |
74 |
|
75 |
#ifdef USE_X86LDOUBLE
|
76 |
/* an array of Intel 80-bit FP constants, to be loaded via integer ops */
|
77 |
typedef unsigned short f15ld[5]; |
78 |
const f15ld f15rk[] =
|
79 |
{ |
80 |
/*0*/ {0x0000,0x0000,0x0000,0x0000,0x0000}, |
81 |
/*1*/ {0x0000,0x0000,0x0000,0x8000,0x3fff}, |
82 |
/*pi*/ {0xc235,0x2168,0xdaa2,0xc90f,0x4000}, |
83 |
/*lg2*/ {0xf799,0xfbcf,0x9a84,0x9a20,0x3ffd}, |
84 |
/*ln2*/ {0x79ac,0xd1cf,0x17f7,0xb172,0x3ffe}, |
85 |
/*l2e*/ {0xf0bc,0x5c17,0x3b29,0xb8aa,0x3fff}, |
86 |
/*l2t*/ {0x8afe,0xcd1b,0x784b,0xd49a,0x4000} |
87 |
}; |
88 |
#else
|
89 |
/* the same, 64-bit version */
|
90 |
typedef unsigned short f15ld[4]; |
91 |
const f15ld f15rk[] =
|
92 |
{ |
93 |
#ifndef WORDS_BIGENDIAN
|
94 |
/*0*/ {0x0000,0x0000,0x0000,0x0000}, |
95 |
/*1*/ {0x0000,0x0000,0x0000,0x3ff0}, |
96 |
/*pi*/ {0x2d18,0x5444,0x21fb,0x4009}, |
97 |
/*lg2*/ {0x79ff,0x509f,0x4413,0x3fd3}, |
98 |
/*ln2*/ {0x39ef,0xfefa,0x2e42,0x3fe6}, |
99 |
/*l2e*/ {0x82fe,0x652b,0x1547,0x3ff7}, |
100 |
/*l2t*/ {0xa371,0x0979,0x934f,0x400a} |
101 |
#else
|
102 |
/*0*/ {0x0000,0x0000,0x0000,0x0000}, |
103 |
/*1*/ {0x3ff0,0x0000,0x0000,0x0000}, |
104 |
/*pi*/ {0x4009,0x21fb,0x5444,0x2d18}, |
105 |
/*lg2*/ {0x3fd3,0x4413,0x509f,0x79ff}, |
106 |
/*ln2*/ {0x3fe6,0x2e42,0xfefa,0x39ef}, |
107 |
/*l2e*/ {0x3ff7,0x1547,0x652b,0x82fe}, |
108 |
/*l2t*/ {0x400a,0x934f,0x0979,0xa371} |
109 |
#endif
|
110 |
}; |
111 |
#endif
|
112 |
|
113 |
/* n must be a constant to be efficient */
|
114 |
static inline int lshift(int x, int n) |
115 |
{ |
116 |
if (n >= 0) |
117 |
return x << n;
|
118 |
else
|
119 |
return x >> (-n);
|
120 |
} |
121 |
|
122 |
/* we define the various pieces of code used by the JIT */
|
123 |
|
124 |
#define REG EAX
|
125 |
#define REGNAME _EAX
|
126 |
#include "opreg_template.h" |
127 |
#undef REG
|
128 |
#undef REGNAME
|
129 |
|
130 |
#define REG ECX
|
131 |
#define REGNAME _ECX
|
132 |
#include "opreg_template.h" |
133 |
#undef REG
|
134 |
#undef REGNAME
|
135 |
|
136 |
#define REG EDX
|
137 |
#define REGNAME _EDX
|
138 |
#include "opreg_template.h" |
139 |
#undef REG
|
140 |
#undef REGNAME
|
141 |
|
142 |
#define REG EBX
|
143 |
#define REGNAME _EBX
|
144 |
#include "opreg_template.h" |
145 |
#undef REG
|
146 |
#undef REGNAME
|
147 |
|
148 |
#define REG ESP
|
149 |
#define REGNAME _ESP
|
150 |
#include "opreg_template.h" |
151 |
#undef REG
|
152 |
#undef REGNAME
|
153 |
|
154 |
#define REG EBP
|
155 |
#define REGNAME _EBP
|
156 |
#include "opreg_template.h" |
157 |
#undef REG
|
158 |
#undef REGNAME
|
159 |
|
160 |
#define REG ESI
|
161 |
#define REGNAME _ESI
|
162 |
#include "opreg_template.h" |
163 |
#undef REG
|
164 |
#undef REGNAME
|
165 |
|
166 |
#define REG EDI
|
167 |
#define REGNAME _EDI
|
168 |
#include "opreg_template.h" |
169 |
#undef REG
|
170 |
#undef REGNAME
|
171 |
|
172 |
/* operations with flags */
|
173 |
|
174 |
void OPPROTO op_addl_T0_T1_cc(void) |
175 |
{ |
176 |
CC_SRC = T0; |
177 |
T0 += T1; |
178 |
CC_DST = T0; |
179 |
} |
180 |
|
181 |
void OPPROTO op_orl_T0_T1_cc(void) |
182 |
{ |
183 |
T0 |= T1; |
184 |
CC_DST = T0; |
185 |
} |
186 |
|
187 |
void OPPROTO op_andl_T0_T1_cc(void) |
188 |
{ |
189 |
T0 &= T1; |
190 |
CC_DST = T0; |
191 |
} |
192 |
|
193 |
void OPPROTO op_subl_T0_T1_cc(void) |
194 |
{ |
195 |
CC_SRC = T0; |
196 |
T0 -= T1; |
197 |
CC_DST = T0; |
198 |
} |
199 |
|
200 |
void OPPROTO op_xorl_T0_T1_cc(void) |
201 |
{ |
202 |
T0 ^= T1; |
203 |
CC_DST = T0; |
204 |
} |
205 |
|
206 |
void OPPROTO op_cmpl_T0_T1_cc(void) |
207 |
{ |
208 |
CC_SRC = T0; |
209 |
CC_DST = T0 - T1; |
210 |
} |
211 |
|
212 |
void OPPROTO op_negl_T0_cc(void) |
213 |
{ |
214 |
CC_SRC = 0;
|
215 |
T0 = -T0; |
216 |
CC_DST = T0; |
217 |
} |
218 |
|
219 |
void OPPROTO op_incl_T0_cc(void) |
220 |
{ |
221 |
CC_SRC = cc_table[CC_OP].compute_c(); |
222 |
T0++; |
223 |
CC_DST = T0; |
224 |
} |
225 |
|
226 |
void OPPROTO op_decl_T0_cc(void) |
227 |
{ |
228 |
CC_SRC = cc_table[CC_OP].compute_c(); |
229 |
T0--; |
230 |
CC_DST = T0; |
231 |
} |
232 |
|
233 |
void OPPROTO op_testl_T0_T1_cc(void) |
234 |
{ |
235 |
CC_DST = T0 & T1; |
236 |
} |
237 |
|
238 |
/* operations without flags */
|
239 |
|
240 |
void OPPROTO op_addl_T0_T1(void) |
241 |
{ |
242 |
T0 += T1; |
243 |
} |
244 |
|
245 |
void OPPROTO op_orl_T0_T1(void) |
246 |
{ |
247 |
T0 |= T1; |
248 |
} |
249 |
|
250 |
void OPPROTO op_andl_T0_T1(void) |
251 |
{ |
252 |
T0 &= T1; |
253 |
} |
254 |
|
255 |
void OPPROTO op_subl_T0_T1(void) |
256 |
{ |
257 |
T0 -= T1; |
258 |
} |
259 |
|
260 |
void OPPROTO op_xorl_T0_T1(void) |
261 |
{ |
262 |
T0 ^= T1; |
263 |
} |
264 |
|
265 |
void OPPROTO op_negl_T0(void) |
266 |
{ |
267 |
T0 = -T0; |
268 |
} |
269 |
|
270 |
void OPPROTO op_incl_T0(void) |
271 |
{ |
272 |
T0++; |
273 |
} |
274 |
|
275 |
void OPPROTO op_decl_T0(void) |
276 |
{ |
277 |
T0--; |
278 |
} |
279 |
|
280 |
void OPPROTO op_notl_T0(void) |
281 |
{ |
282 |
T0 = ~T0; |
283 |
} |
284 |
|
285 |
void OPPROTO op_bswapl_T0(void) |
286 |
{ |
287 |
T0 = bswap32(T0); |
288 |
} |
289 |
|
290 |
/* multiply/divide */
|
291 |
void OPPROTO op_mulb_AL_T0(void) |
292 |
{ |
293 |
unsigned int res; |
294 |
res = (uint8_t)EAX * (uint8_t)T0; |
295 |
EAX = (EAX & 0xffff0000) | res;
|
296 |
CC_SRC = (res & 0xff00);
|
297 |
} |
298 |
|
299 |
void OPPROTO op_imulb_AL_T0(void) |
300 |
{ |
301 |
int res;
|
302 |
res = (int8_t)EAX * (int8_t)T0; |
303 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
304 |
CC_SRC = (res != (int8_t)res); |
305 |
} |
306 |
|
307 |
void OPPROTO op_mulw_AX_T0(void) |
308 |
{ |
309 |
unsigned int res; |
310 |
res = (uint16_t)EAX * (uint16_t)T0; |
311 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
312 |
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff); |
313 |
CC_SRC = res >> 16;
|
314 |
} |
315 |
|
316 |
void OPPROTO op_imulw_AX_T0(void) |
317 |
{ |
318 |
int res;
|
319 |
res = (int16_t)EAX * (int16_t)T0; |
320 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
321 |
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff); |
322 |
CC_SRC = (res != (int16_t)res); |
323 |
} |
324 |
|
325 |
void OPPROTO op_mull_EAX_T0(void) |
326 |
{ |
327 |
uint64_t res; |
328 |
res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0); |
329 |
EAX = res; |
330 |
EDX = res >> 32;
|
331 |
CC_SRC = res >> 32;
|
332 |
} |
333 |
|
334 |
void OPPROTO op_imull_EAX_T0(void) |
335 |
{ |
336 |
int64_t res; |
337 |
res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0); |
338 |
EAX = res; |
339 |
EDX = res >> 32;
|
340 |
CC_SRC = (res != (int32_t)res); |
341 |
} |
342 |
|
343 |
void OPPROTO op_imulw_T0_T1(void) |
344 |
{ |
345 |
int res;
|
346 |
res = (int16_t)T0 * (int16_t)T1; |
347 |
T0 = res; |
348 |
CC_SRC = (res != (int16_t)res); |
349 |
} |
350 |
|
351 |
void OPPROTO op_imull_T0_T1(void) |
352 |
{ |
353 |
int64_t res; |
354 |
res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1); |
355 |
T0 = res; |
356 |
CC_SRC = (res != (int32_t)res); |
357 |
} |
358 |
|
359 |
/* division, flags are undefined */
|
360 |
/* XXX: add exceptions for overflow */
|
361 |
void OPPROTO op_divb_AL_T0(void) |
362 |
{ |
363 |
unsigned int num, den, q, r; |
364 |
|
365 |
num = (EAX & 0xffff);
|
366 |
den = (T0 & 0xff);
|
367 |
if (den == 0) |
368 |
raise_exception(EXCP00_DIVZ); |
369 |
q = (num / den) & 0xff;
|
370 |
r = (num % den) & 0xff;
|
371 |
EAX = (EAX & 0xffff0000) | (r << 8) | q; |
372 |
} |
373 |
|
374 |
void OPPROTO op_idivb_AL_T0(void) |
375 |
{ |
376 |
int num, den, q, r;
|
377 |
|
378 |
num = (int16_t)EAX; |
379 |
den = (int8_t)T0; |
380 |
if (den == 0) |
381 |
raise_exception(EXCP00_DIVZ); |
382 |
q = (num / den) & 0xff;
|
383 |
r = (num % den) & 0xff;
|
384 |
EAX = (EAX & 0xffff0000) | (r << 8) | q; |
385 |
} |
386 |
|
387 |
void OPPROTO op_divw_AX_T0(void) |
388 |
{ |
389 |
unsigned int num, den, q, r; |
390 |
|
391 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
392 |
den = (T0 & 0xffff);
|
393 |
if (den == 0) |
394 |
raise_exception(EXCP00_DIVZ); |
395 |
q = (num / den) & 0xffff;
|
396 |
r = (num % den) & 0xffff;
|
397 |
EAX = (EAX & 0xffff0000) | q;
|
398 |
EDX = (EDX & 0xffff0000) | r;
|
399 |
} |
400 |
|
401 |
void OPPROTO op_idivw_AX_T0(void) |
402 |
{ |
403 |
int num, den, q, r;
|
404 |
|
405 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
406 |
den = (int16_t)T0; |
407 |
if (den == 0) |
408 |
raise_exception(EXCP00_DIVZ); |
409 |
q = (num / den) & 0xffff;
|
410 |
r = (num % den) & 0xffff;
|
411 |
EAX = (EAX & 0xffff0000) | q;
|
412 |
EDX = (EDX & 0xffff0000) | r;
|
413 |
} |
414 |
|
415 |
#ifdef BUGGY_GCC_DIV64
|
416 |
/* gcc 2.95.4 on PowerPC does not seem to like using __udivdi3, so we
|
417 |
call it from another function */
|
418 |
uint32_t div64(uint32_t *q_ptr, uint64_t num, uint32_t den) |
419 |
{ |
420 |
*q_ptr = num / den; |
421 |
return num % den;
|
422 |
} |
423 |
|
424 |
int32_t idiv64(int32_t *q_ptr, int64_t num, int32_t den) |
425 |
{ |
426 |
*q_ptr = num / den; |
427 |
return num % den;
|
428 |
} |
429 |
#endif
|
430 |
|
431 |
void OPPROTO op_divl_EAX_T0(void) |
432 |
{ |
433 |
unsigned int den, q, r; |
434 |
uint64_t num; |
435 |
|
436 |
num = EAX | ((uint64_t)EDX << 32);
|
437 |
den = T0; |
438 |
if (den == 0) |
439 |
raise_exception(EXCP00_DIVZ); |
440 |
#ifdef BUGGY_GCC_DIV64
|
441 |
r = div64(&q, num, den); |
442 |
#else
|
443 |
q = (num / den); |
444 |
r = (num % den); |
445 |
#endif
|
446 |
EAX = q; |
447 |
EDX = r; |
448 |
} |
449 |
|
450 |
void OPPROTO op_idivl_EAX_T0(void) |
451 |
{ |
452 |
int den, q, r;
|
453 |
int64_t num; |
454 |
|
455 |
num = EAX | ((uint64_t)EDX << 32);
|
456 |
den = T0; |
457 |
if (den == 0) |
458 |
raise_exception(EXCP00_DIVZ); |
459 |
#ifdef BUGGY_GCC_DIV64
|
460 |
r = idiv64(&q, num, den); |
461 |
#else
|
462 |
q = (num / den); |
463 |
r = (num % den); |
464 |
#endif
|
465 |
EAX = q; |
466 |
EDX = r; |
467 |
} |
468 |
|
469 |
/* constant load & misc op */
|
470 |
|
471 |
void OPPROTO op_movl_T0_im(void) |
472 |
{ |
473 |
T0 = PARAM1; |
474 |
} |
475 |
|
476 |
void OPPROTO op_addl_T0_im(void) |
477 |
{ |
478 |
T0 += PARAM1; |
479 |
} |
480 |
|
481 |
void OPPROTO op_andl_T0_ffff(void) |
482 |
{ |
483 |
T0 = T0 & 0xffff;
|
484 |
} |
485 |
|
486 |
void OPPROTO op_movl_T0_T1(void) |
487 |
{ |
488 |
T0 = T1; |
489 |
} |
490 |
|
491 |
void OPPROTO op_movl_T1_im(void) |
492 |
{ |
493 |
T1 = PARAM1; |
494 |
} |
495 |
|
496 |
void OPPROTO op_addl_T1_im(void) |
497 |
{ |
498 |
T1 += PARAM1; |
499 |
} |
500 |
|
501 |
void OPPROTO op_movl_T1_A0(void) |
502 |
{ |
503 |
T1 = A0; |
504 |
} |
505 |
|
506 |
void OPPROTO op_movl_A0_im(void) |
507 |
{ |
508 |
A0 = PARAM1; |
509 |
} |
510 |
|
511 |
void OPPROTO op_addl_A0_im(void) |
512 |
{ |
513 |
A0 += PARAM1; |
514 |
} |
515 |
|
516 |
void OPPROTO op_addl_A0_AL(void) |
517 |
{ |
518 |
A0 += (EAX & 0xff);
|
519 |
} |
520 |
|
521 |
void OPPROTO op_andl_A0_ffff(void) |
522 |
{ |
523 |
A0 = A0 & 0xffff;
|
524 |
} |
525 |
|
526 |
/* memory access */
|
527 |
|
528 |
void OPPROTO op_ldub_T0_A0(void) |
529 |
{ |
530 |
T0 = ldub((uint8_t *)A0); |
531 |
} |
532 |
|
533 |
void OPPROTO op_ldsb_T0_A0(void) |
534 |
{ |
535 |
T0 = ldsb((int8_t *)A0); |
536 |
} |
537 |
|
538 |
void OPPROTO op_lduw_T0_A0(void) |
539 |
{ |
540 |
T0 = lduw((uint8_t *)A0); |
541 |
} |
542 |
|
543 |
void OPPROTO op_ldsw_T0_A0(void) |
544 |
{ |
545 |
T0 = ldsw((int8_t *)A0); |
546 |
} |
547 |
|
548 |
void OPPROTO op_ldl_T0_A0(void) |
549 |
{ |
550 |
T0 = ldl((uint8_t *)A0); |
551 |
} |
552 |
|
553 |
void OPPROTO op_ldub_T1_A0(void) |
554 |
{ |
555 |
T1 = ldub((uint8_t *)A0); |
556 |
} |
557 |
|
558 |
void OPPROTO op_ldsb_T1_A0(void) |
559 |
{ |
560 |
T1 = ldsb((int8_t *)A0); |
561 |
} |
562 |
|
563 |
void OPPROTO op_lduw_T1_A0(void) |
564 |
{ |
565 |
T1 = lduw((uint8_t *)A0); |
566 |
} |
567 |
|
568 |
void OPPROTO op_ldsw_T1_A0(void) |
569 |
{ |
570 |
T1 = ldsw((int8_t *)A0); |
571 |
} |
572 |
|
573 |
void OPPROTO op_ldl_T1_A0(void) |
574 |
{ |
575 |
T1 = ldl((uint8_t *)A0); |
576 |
} |
577 |
|
578 |
void OPPROTO op_stb_T0_A0(void) |
579 |
{ |
580 |
stb((uint8_t *)A0, T0); |
581 |
} |
582 |
|
583 |
void OPPROTO op_stw_T0_A0(void) |
584 |
{ |
585 |
stw((uint8_t *)A0, T0); |
586 |
} |
587 |
|
588 |
void OPPROTO op_stl_T0_A0(void) |
589 |
{ |
590 |
stl((uint8_t *)A0, T0); |
591 |
} |
592 |
|
593 |
/* used for bit operations */
|
594 |
|
595 |
void OPPROTO op_add_bitw_A0_T1(void) |
596 |
{ |
597 |
A0 += ((int32_t)T1 >> 4) << 1; |
598 |
} |
599 |
|
600 |
void OPPROTO op_add_bitl_A0_T1(void) |
601 |
{ |
602 |
A0 += ((int32_t)T1 >> 5) << 2; |
603 |
} |
604 |
|
605 |
/* indirect jump */
|
606 |
|
607 |
void OPPROTO op_jmp_T0(void) |
608 |
{ |
609 |
EIP = T0; |
610 |
} |
611 |
|
612 |
void OPPROTO op_jmp_im(void) |
613 |
{ |
614 |
EIP = PARAM1; |
615 |
} |
616 |
|
617 |
void OPPROTO op_int_im(void) |
618 |
{ |
619 |
EIP = PARAM1; |
620 |
raise_exception(EXCP0D_GPF); |
621 |
} |
622 |
|
623 |
void OPPROTO op_int3(void) |
624 |
{ |
625 |
EIP = PARAM1; |
626 |
raise_exception(EXCP03_INT3); |
627 |
} |
628 |
|
629 |
void OPPROTO op_into(void) |
630 |
{ |
631 |
int eflags;
|
632 |
eflags = cc_table[CC_OP].compute_all(); |
633 |
if (eflags & CC_O) {
|
634 |
raise_exception(EXCP04_INTO); |
635 |
} |
636 |
} |
637 |
|
638 |
/* XXX: add IOPL/CPL tests */
|
639 |
void OPPROTO op_cli(void) |
640 |
{ |
641 |
raise_exception(EXCP0D_GPF); |
642 |
} |
643 |
|
644 |
/* XXX: add IOPL/CPL tests */
|
645 |
void OPPROTO op_sti(void) |
646 |
{ |
647 |
raise_exception(EXCP0D_GPF); |
648 |
} |
649 |
|
650 |
/* vm86plus instructions */
|
651 |
|
652 |
void OPPROTO op_cli_vm(void) |
653 |
{ |
654 |
env->eflags &= ~VIF_MASK; |
655 |
} |
656 |
|
657 |
void OPPROTO op_sti_vm(void) |
658 |
{ |
659 |
env->eflags |= VIF_MASK; |
660 |
if (env->eflags & VIP_MASK) {
|
661 |
EIP = PARAM1; |
662 |
raise_exception(EXCP0D_GPF); |
663 |
} |
664 |
FORCE_RET(); |
665 |
} |
666 |
|
667 |
void OPPROTO op_boundw(void) |
668 |
{ |
669 |
int low, high, v;
|
670 |
low = ldsw((uint8_t *)A0); |
671 |
high = ldsw((uint8_t *)A0 + 2);
|
672 |
v = (int16_t)T0; |
673 |
if (v < low || v > high)
|
674 |
raise_exception(EXCP05_BOUND); |
675 |
FORCE_RET(); |
676 |
} |
677 |
|
678 |
void OPPROTO op_boundl(void) |
679 |
{ |
680 |
int low, high, v;
|
681 |
low = ldl((uint8_t *)A0); |
682 |
high = ldl((uint8_t *)A0 + 4);
|
683 |
v = T0; |
684 |
if (v < low || v > high)
|
685 |
raise_exception(EXCP05_BOUND); |
686 |
FORCE_RET(); |
687 |
} |
688 |
|
689 |
void OPPROTO op_cmpxchg8b(void) |
690 |
{ |
691 |
uint64_t d; |
692 |
int eflags;
|
693 |
|
694 |
eflags = cc_table[CC_OP].compute_all(); |
695 |
d = ldq((uint8_t *)A0); |
696 |
if (d == (((uint64_t)EDX << 32) | EAX)) { |
697 |
stq((uint8_t *)A0, ((uint64_t)ECX << 32) | EBX);
|
698 |
eflags |= CC_Z; |
699 |
} else {
|
700 |
EDX = d >> 32;
|
701 |
EAX = d; |
702 |
eflags &= ~CC_Z; |
703 |
} |
704 |
CC_SRC = eflags; |
705 |
FORCE_RET(); |
706 |
} |
707 |
|
708 |
/* string ops */
|
709 |
|
710 |
#define ldul ldl
|
711 |
|
712 |
#define SHIFT 0 |
713 |
#include "ops_template.h" |
714 |
#undef SHIFT
|
715 |
|
716 |
#define SHIFT 1 |
717 |
#include "ops_template.h" |
718 |
#undef SHIFT
|
719 |
|
720 |
#define SHIFT 2 |
721 |
#include "ops_template.h" |
722 |
#undef SHIFT
|
723 |
|
724 |
/* sign extend */
|
725 |
|
726 |
void OPPROTO op_movsbl_T0_T0(void) |
727 |
{ |
728 |
T0 = (int8_t)T0; |
729 |
} |
730 |
|
731 |
void OPPROTO op_movzbl_T0_T0(void) |
732 |
{ |
733 |
T0 = (uint8_t)T0; |
734 |
} |
735 |
|
736 |
void OPPROTO op_movswl_T0_T0(void) |
737 |
{ |
738 |
T0 = (int16_t)T0; |
739 |
} |
740 |
|
741 |
void OPPROTO op_movzwl_T0_T0(void) |
742 |
{ |
743 |
T0 = (uint16_t)T0; |
744 |
} |
745 |
|
746 |
void OPPROTO op_movswl_EAX_AX(void) |
747 |
{ |
748 |
EAX = (int16_t)EAX; |
749 |
} |
750 |
|
751 |
void OPPROTO op_movsbw_AX_AL(void) |
752 |
{ |
753 |
EAX = (EAX & 0xffff0000) | ((int8_t)EAX & 0xffff); |
754 |
} |
755 |
|
756 |
void OPPROTO op_movslq_EDX_EAX(void) |
757 |
{ |
758 |
EDX = (int32_t)EAX >> 31;
|
759 |
} |
760 |
|
761 |
void OPPROTO op_movswl_DX_AX(void) |
762 |
{ |
763 |
EDX = (EDX & 0xffff0000) | (((int16_t)EAX >> 15) & 0xffff); |
764 |
} |
765 |
|
766 |
/* push/pop */
|
767 |
|
768 |
void op_pushl_T0(void) |
769 |
{ |
770 |
uint32_t offset; |
771 |
offset = ESP - 4;
|
772 |
stl((void *)offset, T0);
|
773 |
/* modify ESP after to handle exceptions correctly */
|
774 |
ESP = offset; |
775 |
} |
776 |
|
777 |
void op_pushw_T0(void) |
778 |
{ |
779 |
uint32_t offset; |
780 |
offset = ESP - 2;
|
781 |
stw((void *)offset, T0);
|
782 |
/* modify ESP after to handle exceptions correctly */
|
783 |
ESP = offset; |
784 |
} |
785 |
|
786 |
void op_pushl_ss32_T0(void) |
787 |
{ |
788 |
uint32_t offset; |
789 |
offset = ESP - 4;
|
790 |
stl(env->seg_cache[R_SS].base + offset, T0); |
791 |
/* modify ESP after to handle exceptions correctly */
|
792 |
ESP = offset; |
793 |
} |
794 |
|
795 |
void op_pushw_ss32_T0(void) |
796 |
{ |
797 |
uint32_t offset; |
798 |
offset = ESP - 2;
|
799 |
stw(env->seg_cache[R_SS].base + offset, T0); |
800 |
/* modify ESP after to handle exceptions correctly */
|
801 |
ESP = offset; |
802 |
} |
803 |
|
804 |
void op_pushl_ss16_T0(void) |
805 |
{ |
806 |
uint32_t offset; |
807 |
offset = (ESP - 4) & 0xffff; |
808 |
stl(env->seg_cache[R_SS].base + offset, T0); |
809 |
/* modify ESP after to handle exceptions correctly */
|
810 |
ESP = (ESP & ~0xffff) | offset;
|
811 |
} |
812 |
|
813 |
void op_pushw_ss16_T0(void) |
814 |
{ |
815 |
uint32_t offset; |
816 |
offset = (ESP - 2) & 0xffff; |
817 |
stw(env->seg_cache[R_SS].base + offset, T0); |
818 |
/* modify ESP after to handle exceptions correctly */
|
819 |
ESP = (ESP & ~0xffff) | offset;
|
820 |
} |
821 |
|
822 |
/* NOTE: ESP update is done after */
|
823 |
void op_popl_T0(void) |
824 |
{ |
825 |
T0 = ldl((void *)ESP);
|
826 |
} |
827 |
|
828 |
void op_popw_T0(void) |
829 |
{ |
830 |
T0 = lduw((void *)ESP);
|
831 |
} |
832 |
|
833 |
void op_popl_ss32_T0(void) |
834 |
{ |
835 |
T0 = ldl(env->seg_cache[R_SS].base + ESP); |
836 |
} |
837 |
|
838 |
void op_popw_ss32_T0(void) |
839 |
{ |
840 |
T0 = lduw(env->seg_cache[R_SS].base + ESP); |
841 |
} |
842 |
|
843 |
void op_popl_ss16_T0(void) |
844 |
{ |
845 |
T0 = ldl(env->seg_cache[R_SS].base + (ESP & 0xffff));
|
846 |
} |
847 |
|
848 |
void op_popw_ss16_T0(void) |
849 |
{ |
850 |
T0 = lduw(env->seg_cache[R_SS].base + (ESP & 0xffff));
|
851 |
} |
852 |
|
853 |
void op_addl_ESP_4(void) |
854 |
{ |
855 |
ESP += 4;
|
856 |
} |
857 |
|
858 |
void op_addl_ESP_2(void) |
859 |
{ |
860 |
ESP += 2;
|
861 |
} |
862 |
|
863 |
void op_addw_ESP_4(void) |
864 |
{ |
865 |
ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff); |
866 |
} |
867 |
|
868 |
void op_addw_ESP_2(void) |
869 |
{ |
870 |
ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff); |
871 |
} |
872 |
|
873 |
void op_addl_ESP_im(void) |
874 |
{ |
875 |
ESP += PARAM1; |
876 |
} |
877 |
|
878 |
void op_addw_ESP_im(void) |
879 |
{ |
880 |
ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff); |
881 |
} |
882 |
|
883 |
/* rdtsc */
|
884 |
#ifndef __i386__
|
885 |
uint64_t emu_time; |
886 |
#endif
|
887 |
|
888 |
void OPPROTO op_rdtsc(void) |
889 |
{ |
890 |
uint64_t val; |
891 |
#ifdef __i386__
|
892 |
asm("rdtsc" : "=A" (val)); |
893 |
#else
|
894 |
/* better than nothing: the time increases */
|
895 |
val = emu_time++; |
896 |
#endif
|
897 |
EAX = val; |
898 |
EDX = val >> 32;
|
899 |
} |
900 |
|
901 |
/* We simulate a pre-MMX pentium as in valgrind */
|
902 |
#define CPUID_FP87 (1 << 0) |
903 |
#define CPUID_VME (1 << 1) |
904 |
#define CPUID_DE (1 << 2) |
905 |
#define CPUID_PSE (1 << 3) |
906 |
#define CPUID_TSC (1 << 4) |
907 |
#define CPUID_MSR (1 << 5) |
908 |
#define CPUID_PAE (1 << 6) |
909 |
#define CPUID_MCE (1 << 7) |
910 |
#define CPUID_CX8 (1 << 8) |
911 |
#define CPUID_APIC (1 << 9) |
912 |
#define CPUID_SEP (1 << 11) /* sysenter/sysexit */ |
913 |
#define CPUID_MTRR (1 << 12) |
914 |
#define CPUID_PGE (1 << 13) |
915 |
#define CPUID_MCA (1 << 14) |
916 |
#define CPUID_CMOV (1 << 15) |
917 |
/* ... */
|
918 |
#define CPUID_MMX (1 << 23) |
919 |
#define CPUID_FXSR (1 << 24) |
920 |
#define CPUID_SSE (1 << 25) |
921 |
#define CPUID_SSE2 (1 << 26) |
922 |
|
923 |
void helper_cpuid(void) |
924 |
{ |
925 |
if (EAX == 0) { |
926 |
EAX = 1; /* max EAX index supported */ |
927 |
EBX = 0x756e6547;
|
928 |
ECX = 0x6c65746e;
|
929 |
EDX = 0x49656e69;
|
930 |
} else {
|
931 |
/* EAX = 1 info */
|
932 |
EAX = 0x52b;
|
933 |
EBX = 0;
|
934 |
ECX = 0;
|
935 |
EDX = CPUID_FP87 | CPUID_VME | CPUID_DE | CPUID_PSE | |
936 |
CPUID_TSC | CPUID_MSR | CPUID_MCE | |
937 |
CPUID_CX8; |
938 |
} |
939 |
} |
940 |
|
941 |
void OPPROTO op_cpuid(void) |
942 |
{ |
943 |
helper_cpuid(); |
944 |
} |
945 |
|
946 |
/* bcd */
|
947 |
|
948 |
/* XXX: exception */
|
949 |
void OPPROTO op_aam(void) |
950 |
{ |
951 |
int base = PARAM1;
|
952 |
int al, ah;
|
953 |
al = EAX & 0xff;
|
954 |
ah = al / base; |
955 |
al = al % base; |
956 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
957 |
CC_DST = al; |
958 |
} |
959 |
|
960 |
void OPPROTO op_aad(void) |
961 |
{ |
962 |
int base = PARAM1;
|
963 |
int al, ah;
|
964 |
al = EAX & 0xff;
|
965 |
ah = (EAX >> 8) & 0xff; |
966 |
al = ((ah * base) + al) & 0xff;
|
967 |
EAX = (EAX & ~0xffff) | al;
|
968 |
CC_DST = al; |
969 |
} |
970 |
|
971 |
void OPPROTO op_aaa(void) |
972 |
{ |
973 |
int icarry;
|
974 |
int al, ah, af;
|
975 |
int eflags;
|
976 |
|
977 |
eflags = cc_table[CC_OP].compute_all(); |
978 |
af = eflags & CC_A; |
979 |
al = EAX & 0xff;
|
980 |
ah = (EAX >> 8) & 0xff; |
981 |
|
982 |
icarry = (al > 0xf9);
|
983 |
if (((al & 0x0f) > 9 ) || af) { |
984 |
al = (al + 6) & 0x0f; |
985 |
ah = (ah + 1 + icarry) & 0xff; |
986 |
eflags |= CC_C | CC_A; |
987 |
} else {
|
988 |
eflags &= ~(CC_C | CC_A); |
989 |
al &= 0x0f;
|
990 |
} |
991 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
992 |
CC_SRC = eflags; |
993 |
} |
994 |
|
995 |
void OPPROTO op_aas(void) |
996 |
{ |
997 |
int icarry;
|
998 |
int al, ah, af;
|
999 |
int eflags;
|
1000 |
|
1001 |
eflags = cc_table[CC_OP].compute_all(); |
1002 |
af = eflags & CC_A; |
1003 |
al = EAX & 0xff;
|
1004 |
ah = (EAX >> 8) & 0xff; |
1005 |
|
1006 |
icarry = (al < 6);
|
1007 |
if (((al & 0x0f) > 9 ) || af) { |
1008 |
al = (al - 6) & 0x0f; |
1009 |
ah = (ah - 1 - icarry) & 0xff; |
1010 |
eflags |= CC_C | CC_A; |
1011 |
} else {
|
1012 |
eflags &= ~(CC_C | CC_A); |
1013 |
al &= 0x0f;
|
1014 |
} |
1015 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
1016 |
CC_SRC = eflags; |
1017 |
} |
1018 |
|
1019 |
void OPPROTO op_daa(void) |
1020 |
{ |
1021 |
int al, af, cf;
|
1022 |
int eflags;
|
1023 |
|
1024 |
eflags = cc_table[CC_OP].compute_all(); |
1025 |
cf = eflags & CC_C; |
1026 |
af = eflags & CC_A; |
1027 |
al = EAX & 0xff;
|
1028 |
|
1029 |
eflags = 0;
|
1030 |
if (((al & 0x0f) > 9 ) || af) { |
1031 |
al = (al + 6) & 0xff; |
1032 |
eflags |= CC_A; |
1033 |
} |
1034 |
if ((al > 0x9f) || cf) { |
1035 |
al = (al + 0x60) & 0xff; |
1036 |
eflags |= CC_C; |
1037 |
} |
1038 |
EAX = (EAX & ~0xff) | al;
|
1039 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1040 |
eflags |= (al == 0) << 6; /* zf */ |
1041 |
eflags |= parity_table[al]; /* pf */
|
1042 |
eflags |= (al & 0x80); /* sf */ |
1043 |
CC_SRC = eflags; |
1044 |
} |
1045 |
|
1046 |
void OPPROTO op_das(void) |
1047 |
{ |
1048 |
int al, al1, af, cf;
|
1049 |
int eflags;
|
1050 |
|
1051 |
eflags = cc_table[CC_OP].compute_all(); |
1052 |
cf = eflags & CC_C; |
1053 |
af = eflags & CC_A; |
1054 |
al = EAX & 0xff;
|
1055 |
|
1056 |
eflags = 0;
|
1057 |
al1 = al; |
1058 |
if (((al & 0x0f) > 9 ) || af) { |
1059 |
eflags |= CC_A; |
1060 |
if (al < 6 || cf) |
1061 |
eflags |= CC_C; |
1062 |
al = (al - 6) & 0xff; |
1063 |
} |
1064 |
if ((al1 > 0x99) || cf) { |
1065 |
al = (al - 0x60) & 0xff; |
1066 |
eflags |= CC_C; |
1067 |
} |
1068 |
EAX = (EAX & ~0xff) | al;
|
1069 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1070 |
eflags |= (al == 0) << 6; /* zf */ |
1071 |
eflags |= parity_table[al]; /* pf */
|
1072 |
eflags |= (al & 0x80); /* sf */ |
1073 |
CC_SRC = eflags; |
1074 |
} |
1075 |
|
1076 |
/* segment handling */
|
1077 |
|
1078 |
/* XXX: use static VM86 information */
|
1079 |
void load_seg(int seg_reg, int selector) |
1080 |
{ |
1081 |
SegmentCache *sc; |
1082 |
SegmentDescriptorTable *dt; |
1083 |
int index;
|
1084 |
uint32_t e1, e2; |
1085 |
uint8_t *ptr; |
1086 |
|
1087 |
env->segs[seg_reg] = selector; |
1088 |
sc = &env->seg_cache[seg_reg]; |
1089 |
if (env->eflags & VM_MASK) {
|
1090 |
sc->base = (void *)(selector << 4); |
1091 |
sc->limit = 0xffff;
|
1092 |
sc->seg_32bit = 0;
|
1093 |
} else {
|
1094 |
if (selector & 0x4) |
1095 |
dt = &env->ldt; |
1096 |
else
|
1097 |
dt = &env->gdt; |
1098 |
index = selector & ~7;
|
1099 |
if ((index + 7) > dt->limit) |
1100 |
raise_exception(EXCP0D_GPF); |
1101 |
ptr = dt->base + index; |
1102 |
e1 = ldl(ptr); |
1103 |
e2 = ldl(ptr + 4);
|
1104 |
sc->base = (void *)((e1 >> 16) | ((e2 & 0xff) << 16) | (e2 & 0xff000000)); |
1105 |
sc->limit = (e1 & 0xffff) | (e2 & 0x000f0000); |
1106 |
if (e2 & (1 << 23)) |
1107 |
sc->limit = (sc->limit << 12) | 0xfff; |
1108 |
sc->seg_32bit = (e2 >> 22) & 1; |
1109 |
#if 0
|
1110 |
fprintf(logfile, "load_seg: sel=0x%04x base=0x%08lx limit=0x%08lx seg_32bit=%d\n",
|
1111 |
selector, (unsigned long)sc->base, sc->limit, sc->seg_32bit);
|
1112 |
#endif
|
1113 |
} |
1114 |
} |
1115 |
|
1116 |
void OPPROTO op_movl_seg_T0(void) |
1117 |
{ |
1118 |
load_seg(PARAM1, T0 & 0xffff);
|
1119 |
} |
1120 |
|
1121 |
void OPPROTO op_movl_T0_seg(void) |
1122 |
{ |
1123 |
T0 = env->segs[PARAM1]; |
1124 |
} |
1125 |
|
1126 |
void OPPROTO op_movl_A0_seg(void) |
1127 |
{ |
1128 |
A0 = *(unsigned long *)((char *)env + PARAM1); |
1129 |
} |
1130 |
|
1131 |
void OPPROTO op_addl_A0_seg(void) |
1132 |
{ |
1133 |
A0 += *(unsigned long *)((char *)env + PARAM1); |
1134 |
} |
1135 |
|
1136 |
/* flags handling */
|
1137 |
|
1138 |
/* slow jumps cases (compute x86 flags) */
|
1139 |
void OPPROTO op_jo_cc(void) |
1140 |
{ |
1141 |
int eflags;
|
1142 |
eflags = cc_table[CC_OP].compute_all(); |
1143 |
if (eflags & CC_O)
|
1144 |
EIP = PARAM1; |
1145 |
else
|
1146 |
EIP = PARAM2; |
1147 |
FORCE_RET(); |
1148 |
} |
1149 |
|
1150 |
void OPPROTO op_jb_cc(void) |
1151 |
{ |
1152 |
if (cc_table[CC_OP].compute_c())
|
1153 |
EIP = PARAM1; |
1154 |
else
|
1155 |
EIP = PARAM2; |
1156 |
FORCE_RET(); |
1157 |
} |
1158 |
|
1159 |
void OPPROTO op_jz_cc(void) |
1160 |
{ |
1161 |
int eflags;
|
1162 |
eflags = cc_table[CC_OP].compute_all(); |
1163 |
if (eflags & CC_Z)
|
1164 |
EIP = PARAM1; |
1165 |
else
|
1166 |
EIP = PARAM2; |
1167 |
FORCE_RET(); |
1168 |
} |
1169 |
|
1170 |
void OPPROTO op_jbe_cc(void) |
1171 |
{ |
1172 |
int eflags;
|
1173 |
eflags = cc_table[CC_OP].compute_all(); |
1174 |
if (eflags & (CC_Z | CC_C))
|
1175 |
EIP = PARAM1; |
1176 |
else
|
1177 |
EIP = PARAM2; |
1178 |
FORCE_RET(); |
1179 |
} |
1180 |
|
1181 |
void OPPROTO op_js_cc(void) |
1182 |
{ |
1183 |
int eflags;
|
1184 |
eflags = cc_table[CC_OP].compute_all(); |
1185 |
if (eflags & CC_S)
|
1186 |
EIP = PARAM1; |
1187 |
else
|
1188 |
EIP = PARAM2; |
1189 |
FORCE_RET(); |
1190 |
} |
1191 |
|
1192 |
void OPPROTO op_jp_cc(void) |
1193 |
{ |
1194 |
int eflags;
|
1195 |
eflags = cc_table[CC_OP].compute_all(); |
1196 |
if (eflags & CC_P)
|
1197 |
EIP = PARAM1; |
1198 |
else
|
1199 |
EIP = PARAM2; |
1200 |
FORCE_RET(); |
1201 |
} |
1202 |
|
1203 |
void OPPROTO op_jl_cc(void) |
1204 |
{ |
1205 |
int eflags;
|
1206 |
eflags = cc_table[CC_OP].compute_all(); |
1207 |
if ((eflags ^ (eflags >> 4)) & 0x80) |
1208 |
EIP = PARAM1; |
1209 |
else
|
1210 |
EIP = PARAM2; |
1211 |
FORCE_RET(); |
1212 |
} |
1213 |
|
1214 |
void OPPROTO op_jle_cc(void) |
1215 |
{ |
1216 |
int eflags;
|
1217 |
eflags = cc_table[CC_OP].compute_all(); |
1218 |
if (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) |
1219 |
EIP = PARAM1; |
1220 |
else
|
1221 |
EIP = PARAM2; |
1222 |
FORCE_RET(); |
1223 |
} |
1224 |
|
1225 |
/* slow set cases (compute x86 flags) */
|
1226 |
void OPPROTO op_seto_T0_cc(void) |
1227 |
{ |
1228 |
int eflags;
|
1229 |
eflags = cc_table[CC_OP].compute_all(); |
1230 |
T0 = (eflags >> 11) & 1; |
1231 |
} |
1232 |
|
1233 |
void OPPROTO op_setb_T0_cc(void) |
1234 |
{ |
1235 |
T0 = cc_table[CC_OP].compute_c(); |
1236 |
} |
1237 |
|
1238 |
void OPPROTO op_setz_T0_cc(void) |
1239 |
{ |
1240 |
int eflags;
|
1241 |
eflags = cc_table[CC_OP].compute_all(); |
1242 |
T0 = (eflags >> 6) & 1; |
1243 |
} |
1244 |
|
1245 |
void OPPROTO op_setbe_T0_cc(void) |
1246 |
{ |
1247 |
int eflags;
|
1248 |
eflags = cc_table[CC_OP].compute_all(); |
1249 |
T0 = (eflags & (CC_Z | CC_C)) != 0;
|
1250 |
} |
1251 |
|
1252 |
void OPPROTO op_sets_T0_cc(void) |
1253 |
{ |
1254 |
int eflags;
|
1255 |
eflags = cc_table[CC_OP].compute_all(); |
1256 |
T0 = (eflags >> 7) & 1; |
1257 |
} |
1258 |
|
1259 |
void OPPROTO op_setp_T0_cc(void) |
1260 |
{ |
1261 |
int eflags;
|
1262 |
eflags = cc_table[CC_OP].compute_all(); |
1263 |
T0 = (eflags >> 2) & 1; |
1264 |
} |
1265 |
|
1266 |
void OPPROTO op_setl_T0_cc(void) |
1267 |
{ |
1268 |
int eflags;
|
1269 |
eflags = cc_table[CC_OP].compute_all(); |
1270 |
T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1; |
1271 |
} |
1272 |
|
1273 |
void OPPROTO op_setle_T0_cc(void) |
1274 |
{ |
1275 |
int eflags;
|
1276 |
eflags = cc_table[CC_OP].compute_all(); |
1277 |
T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0; |
1278 |
} |
1279 |
|
1280 |
void OPPROTO op_xor_T0_1(void) |
1281 |
{ |
1282 |
T0 ^= 1;
|
1283 |
} |
1284 |
|
1285 |
void OPPROTO op_set_cc_op(void) |
1286 |
{ |
1287 |
CC_OP = PARAM1; |
1288 |
} |
1289 |
|
1290 |
#define FL_UPDATE_MASK32 (TF_MASK | AC_MASK | ID_MASK)
|
1291 |
#define FL_UPDATE_MASK16 (TF_MASK)
|
1292 |
|
1293 |
void OPPROTO op_movl_eflags_T0(void) |
1294 |
{ |
1295 |
int eflags;
|
1296 |
eflags = T0; |
1297 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1298 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1299 |
/* we also update some system flags as in user mode */
|
1300 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK32) | (eflags & FL_UPDATE_MASK32); |
1301 |
} |
1302 |
|
1303 |
void OPPROTO op_movw_eflags_T0(void) |
1304 |
{ |
1305 |
int eflags;
|
1306 |
eflags = T0; |
1307 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1308 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1309 |
/* we also update some system flags as in user mode */
|
1310 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK16) | (eflags & FL_UPDATE_MASK16); |
1311 |
} |
1312 |
|
1313 |
/* vm86 version */
|
1314 |
void OPPROTO op_movw_eflags_T0_vm(void) |
1315 |
{ |
1316 |
int eflags;
|
1317 |
eflags = T0; |
1318 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1319 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1320 |
/* we also update some system flags as in user mode */
|
1321 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) | |
1322 |
(eflags & FL_UPDATE_MASK16); |
1323 |
if (eflags & IF_MASK) {
|
1324 |
env->eflags |= VIF_MASK; |
1325 |
if (env->eflags & VIP_MASK) {
|
1326 |
EIP = PARAM1; |
1327 |
raise_exception(EXCP0D_GPF); |
1328 |
} |
1329 |
} |
1330 |
FORCE_RET(); |
1331 |
} |
1332 |
|
1333 |
void OPPROTO op_movl_eflags_T0_vm(void) |
1334 |
{ |
1335 |
int eflags;
|
1336 |
eflags = T0; |
1337 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1338 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1339 |
/* we also update some system flags as in user mode */
|
1340 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) | |
1341 |
(eflags & FL_UPDATE_MASK32); |
1342 |
if (eflags & IF_MASK) {
|
1343 |
env->eflags |= VIF_MASK; |
1344 |
if (env->eflags & VIP_MASK) {
|
1345 |
EIP = PARAM1; |
1346 |
raise_exception(EXCP0D_GPF); |
1347 |
} |
1348 |
} |
1349 |
FORCE_RET(); |
1350 |
} |
1351 |
|
1352 |
/* XXX: compute only O flag */
|
1353 |
void OPPROTO op_movb_eflags_T0(void) |
1354 |
{ |
1355 |
int of;
|
1356 |
of = cc_table[CC_OP].compute_all() & CC_O; |
1357 |
CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of; |
1358 |
} |
1359 |
|
1360 |
void OPPROTO op_movl_T0_eflags(void) |
1361 |
{ |
1362 |
int eflags;
|
1363 |
eflags = cc_table[CC_OP].compute_all(); |
1364 |
eflags |= (DF & DF_MASK); |
1365 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK); |
1366 |
T0 = eflags; |
1367 |
} |
1368 |
|
1369 |
/* vm86 version */
|
1370 |
void OPPROTO op_movl_T0_eflags_vm(void) |
1371 |
{ |
1372 |
int eflags;
|
1373 |
eflags = cc_table[CC_OP].compute_all(); |
1374 |
eflags |= (DF & DF_MASK); |
1375 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK); |
1376 |
if (env->eflags & VIF_MASK)
|
1377 |
eflags |= IF_MASK; |
1378 |
T0 = eflags; |
1379 |
} |
1380 |
|
1381 |
void OPPROTO op_cld(void) |
1382 |
{ |
1383 |
DF = 1;
|
1384 |
} |
1385 |
|
1386 |
void OPPROTO op_std(void) |
1387 |
{ |
1388 |
DF = -1;
|
1389 |
} |
1390 |
|
1391 |
void OPPROTO op_clc(void) |
1392 |
{ |
1393 |
int eflags;
|
1394 |
eflags = cc_table[CC_OP].compute_all(); |
1395 |
eflags &= ~CC_C; |
1396 |
CC_SRC = eflags; |
1397 |
} |
1398 |
|
1399 |
void OPPROTO op_stc(void) |
1400 |
{ |
1401 |
int eflags;
|
1402 |
eflags = cc_table[CC_OP].compute_all(); |
1403 |
eflags |= CC_C; |
1404 |
CC_SRC = eflags; |
1405 |
} |
1406 |
|
1407 |
void OPPROTO op_cmc(void) |
1408 |
{ |
1409 |
int eflags;
|
1410 |
eflags = cc_table[CC_OP].compute_all(); |
1411 |
eflags ^= CC_C; |
1412 |
CC_SRC = eflags; |
1413 |
} |
1414 |
|
1415 |
void OPPROTO op_salc(void) |
1416 |
{ |
1417 |
int cf;
|
1418 |
cf = cc_table[CC_OP].compute_c(); |
1419 |
EAX = (EAX & ~0xff) | ((-cf) & 0xff); |
1420 |
} |
1421 |
|
1422 |
static int compute_all_eflags(void) |
1423 |
{ |
1424 |
return CC_SRC;
|
1425 |
} |
1426 |
|
1427 |
static int compute_c_eflags(void) |
1428 |
{ |
1429 |
return CC_SRC & CC_C;
|
1430 |
} |
1431 |
|
1432 |
static int compute_c_mul(void) |
1433 |
{ |
1434 |
int cf;
|
1435 |
cf = (CC_SRC != 0);
|
1436 |
return cf;
|
1437 |
} |
1438 |
|
1439 |
static int compute_all_mul(void) |
1440 |
{ |
1441 |
int cf, pf, af, zf, sf, of;
|
1442 |
cf = (CC_SRC != 0);
|
1443 |
pf = 0; /* undefined */ |
1444 |
af = 0; /* undefined */ |
1445 |
zf = 0; /* undefined */ |
1446 |
sf = 0; /* undefined */ |
1447 |
of = cf << 11;
|
1448 |
return cf | pf | af | zf | sf | of;
|
1449 |
} |
1450 |
|
1451 |
CCTable cc_table[CC_OP_NB] = { |
1452 |
[CC_OP_DYNAMIC] = { /* should never happen */ },
|
1453 |
|
1454 |
[CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags }, |
1455 |
|
1456 |
[CC_OP_MUL] = { compute_all_mul, compute_c_mul }, |
1457 |
|
1458 |
[CC_OP_ADDB] = { compute_all_addb, compute_c_addb }, |
1459 |
[CC_OP_ADDW] = { compute_all_addw, compute_c_addw }, |
1460 |
[CC_OP_ADDL] = { compute_all_addl, compute_c_addl }, |
1461 |
|
1462 |
[CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb }, |
1463 |
[CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw }, |
1464 |
[CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl }, |
1465 |
|
1466 |
[CC_OP_SUBB] = { compute_all_subb, compute_c_subb }, |
1467 |
[CC_OP_SUBW] = { compute_all_subw, compute_c_subw }, |
1468 |
[CC_OP_SUBL] = { compute_all_subl, compute_c_subl }, |
1469 |
|
1470 |
[CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb }, |
1471 |
[CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw }, |
1472 |
[CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl }, |
1473 |
|
1474 |
[CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb }, |
1475 |
[CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw }, |
1476 |
[CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl }, |
1477 |
|
1478 |
[CC_OP_INCB] = { compute_all_incb, compute_c_incl }, |
1479 |
[CC_OP_INCW] = { compute_all_incw, compute_c_incl }, |
1480 |
[CC_OP_INCL] = { compute_all_incl, compute_c_incl }, |
1481 |
|
1482 |
[CC_OP_DECB] = { compute_all_decb, compute_c_incl }, |
1483 |
[CC_OP_DECW] = { compute_all_decw, compute_c_incl }, |
1484 |
[CC_OP_DECL] = { compute_all_decl, compute_c_incl }, |
1485 |
|
1486 |
[CC_OP_SHLB] = { compute_all_shlb, compute_c_shll }, |
1487 |
[CC_OP_SHLW] = { compute_all_shlw, compute_c_shll }, |
1488 |
[CC_OP_SHLL] = { compute_all_shll, compute_c_shll }, |
1489 |
|
1490 |
[CC_OP_SARB] = { compute_all_sarb, compute_c_shll }, |
1491 |
[CC_OP_SARW] = { compute_all_sarw, compute_c_shll }, |
1492 |
[CC_OP_SARL] = { compute_all_sarl, compute_c_shll }, |
1493 |
}; |
1494 |
|
1495 |
/* floating point support. Some of the code for complicated x87
|
1496 |
functions comes from the LGPL'ed x86 emulator found in the Willows
|
1497 |
TWIN windows emulator. */
|
1498 |
|
1499 |
#ifdef USE_X86LDOUBLE
|
1500 |
/* use long double functions */
|
1501 |
#define lrint lrintl
|
1502 |
#define llrint llrintl
|
1503 |
#define fabs fabsl
|
1504 |
#define sin sinl
|
1505 |
#define cos cosl
|
1506 |
#define sqrt sqrtl
|
1507 |
#define pow powl
|
1508 |
#define log logl
|
1509 |
#define tan tanl
|
1510 |
#define atan2 atan2l
|
1511 |
#define floor floorl
|
1512 |
#define ceil ceill
|
1513 |
#define rint rintl
|
1514 |
#endif
|
1515 |
|
1516 |
extern int lrint(CPU86_LDouble x); |
1517 |
extern int64_t llrint(CPU86_LDouble x);
|
1518 |
extern CPU86_LDouble fabs(CPU86_LDouble x);
|
1519 |
extern CPU86_LDouble sin(CPU86_LDouble x);
|
1520 |
extern CPU86_LDouble cos(CPU86_LDouble x);
|
1521 |
extern CPU86_LDouble sqrt(CPU86_LDouble x);
|
1522 |
extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
|
1523 |
extern CPU86_LDouble log(CPU86_LDouble x);
|
1524 |
extern CPU86_LDouble tan(CPU86_LDouble x);
|
1525 |
extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
|
1526 |
extern CPU86_LDouble floor(CPU86_LDouble x);
|
1527 |
extern CPU86_LDouble ceil(CPU86_LDouble x);
|
1528 |
extern CPU86_LDouble rint(CPU86_LDouble x);
|
1529 |
|
1530 |
#if defined(__powerpc__)
|
1531 |
extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
|
1532 |
|
1533 |
/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
1534 |
double qemu_rint(double x) |
1535 |
{ |
1536 |
double y = 4503599627370496.0; |
1537 |
if (fabs(x) >= y)
|
1538 |
return x;
|
1539 |
if (x < 0) |
1540 |
y = -y; |
1541 |
y = (x + y) - y; |
1542 |
if (y == 0.0) |
1543 |
y = copysign(y, x); |
1544 |
return y;
|
1545 |
} |
1546 |
|
1547 |
#define rint qemu_rint
|
1548 |
#endif
|
1549 |
|
1550 |
#define RC_MASK 0xc00 |
1551 |
#define RC_NEAR 0x000 |
1552 |
#define RC_DOWN 0x400 |
1553 |
#define RC_UP 0x800 |
1554 |
#define RC_CHOP 0xc00 |
1555 |
|
1556 |
#define MAXTAN 9223372036854775808.0 |
1557 |
|
1558 |
#ifdef USE_X86LDOUBLE
|
1559 |
|
1560 |
/* only for x86 */
|
1561 |
typedef union { |
1562 |
long double d; |
1563 |
struct {
|
1564 |
unsigned long long lower; |
1565 |
unsigned short upper; |
1566 |
} l; |
1567 |
} CPU86_LDoubleU; |
1568 |
|
1569 |
/* the following deal with x86 long double-precision numbers */
|
1570 |
#define MAXEXPD 0x7fff |
1571 |
#define EXPBIAS 16383 |
1572 |
#define EXPD(fp) (fp.l.upper & 0x7fff) |
1573 |
#define SIGND(fp) ((fp.l.upper) & 0x8000) |
1574 |
#define MANTD(fp) (fp.l.lower)
|
1575 |
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS |
1576 |
|
1577 |
#else
|
1578 |
|
1579 |
typedef union { |
1580 |
double d;
|
1581 |
#ifndef WORDS_BIGENDIAN
|
1582 |
struct {
|
1583 |
unsigned long lower; |
1584 |
long upper;
|
1585 |
} l; |
1586 |
#else
|
1587 |
struct {
|
1588 |
long upper;
|
1589 |
unsigned long lower; |
1590 |
} l; |
1591 |
#endif
|
1592 |
long long ll; |
1593 |
} CPU86_LDoubleU; |
1594 |
|
1595 |
/* the following deal with IEEE double-precision numbers */
|
1596 |
#define MAXEXPD 0x7ff |
1597 |
#define EXPBIAS 1023 |
1598 |
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) |
1599 |
#define SIGND(fp) ((fp.l.upper) & 0x80000000) |
1600 |
#define MANTD(fp) (fp.ll & ((1LL << 52) - 1)) |
1601 |
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20) |
1602 |
#endif
|
1603 |
|
1604 |
/* fp load FT0 */
|
1605 |
|
1606 |
void OPPROTO op_flds_FT0_A0(void) |
1607 |
{ |
1608 |
FT0 = ldfl((void *)A0);
|
1609 |
} |
1610 |
|
1611 |
void OPPROTO op_fldl_FT0_A0(void) |
1612 |
{ |
1613 |
FT0 = ldfq((void *)A0);
|
1614 |
} |
1615 |
|
1616 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1617 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1618 |
|
1619 |
void helper_fild_FT0_A0(void) |
1620 |
{ |
1621 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1622 |
} |
1623 |
|
1624 |
void helper_fildl_FT0_A0(void) |
1625 |
{ |
1626 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1627 |
} |
1628 |
|
1629 |
void helper_fildll_FT0_A0(void) |
1630 |
{ |
1631 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1632 |
} |
1633 |
|
1634 |
void OPPROTO op_fild_FT0_A0(void) |
1635 |
{ |
1636 |
helper_fild_FT0_A0(); |
1637 |
} |
1638 |
|
1639 |
void OPPROTO op_fildl_FT0_A0(void) |
1640 |
{ |
1641 |
helper_fildl_FT0_A0(); |
1642 |
} |
1643 |
|
1644 |
void OPPROTO op_fildll_FT0_A0(void) |
1645 |
{ |
1646 |
helper_fildll_FT0_A0(); |
1647 |
} |
1648 |
|
1649 |
#else
|
1650 |
|
1651 |
void OPPROTO op_fild_FT0_A0(void) |
1652 |
{ |
1653 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1654 |
} |
1655 |
|
1656 |
void OPPROTO op_fildl_FT0_A0(void) |
1657 |
{ |
1658 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1659 |
} |
1660 |
|
1661 |
void OPPROTO op_fildll_FT0_A0(void) |
1662 |
{ |
1663 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1664 |
} |
1665 |
#endif
|
1666 |
|
1667 |
/* fp load ST0 */
|
1668 |
|
1669 |
void OPPROTO op_flds_ST0_A0(void) |
1670 |
{ |
1671 |
ST0 = ldfl((void *)A0);
|
1672 |
} |
1673 |
|
1674 |
void OPPROTO op_fldl_ST0_A0(void) |
1675 |
{ |
1676 |
ST0 = ldfq((void *)A0);
|
1677 |
} |
1678 |
|
1679 |
#ifdef USE_X86LDOUBLE
|
1680 |
void OPPROTO op_fldt_ST0_A0(void) |
1681 |
{ |
1682 |
ST0 = *(long double *)A0; |
1683 |
} |
1684 |
#else
|
1685 |
void helper_fldt_ST0_A0(void) |
1686 |
{ |
1687 |
CPU86_LDoubleU temp; |
1688 |
int upper, e;
|
1689 |
/* mantissa */
|
1690 |
upper = lduw((uint8_t *)A0 + 8);
|
1691 |
/* XXX: handle overflow ? */
|
1692 |
e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */ |
1693 |
e |= (upper >> 4) & 0x800; /* sign */ |
1694 |
temp.ll = ((ldq((void *)A0) >> 11) & ((1LL << 52) - 1)) | ((uint64_t)e << 52); |
1695 |
ST0 = temp.d; |
1696 |
} |
1697 |
|
1698 |
void OPPROTO op_fldt_ST0_A0(void) |
1699 |
{ |
1700 |
helper_fldt_ST0_A0(); |
1701 |
} |
1702 |
#endif
|
1703 |
|
1704 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1705 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1706 |
|
1707 |
void helper_fild_ST0_A0(void) |
1708 |
{ |
1709 |
ST0 = (CPU86_LDouble)ldsw((void *)A0);
|
1710 |
} |
1711 |
|
1712 |
void helper_fildl_ST0_A0(void) |
1713 |
{ |
1714 |
ST0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1715 |
} |
1716 |
|
1717 |
void helper_fildll_ST0_A0(void) |
1718 |
{ |
1719 |
ST0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1720 |
} |
1721 |
|
1722 |
void OPPROTO op_fild_ST0_A0(void) |
1723 |
{ |
1724 |
helper_fild_ST0_A0(); |
1725 |
} |
1726 |
|
1727 |
void OPPROTO op_fildl_ST0_A0(void) |
1728 |
{ |
1729 |
helper_fildl_ST0_A0(); |
1730 |
} |
1731 |
|
1732 |
void OPPROTO op_fildll_ST0_A0(void) |
1733 |
{ |
1734 |
helper_fildll_ST0_A0(); |
1735 |
} |
1736 |
|
1737 |
#else
|
1738 |
|
1739 |
void OPPROTO op_fild_ST0_A0(void) |
1740 |
{ |
1741 |
ST0 = (CPU86_LDouble)ldsw((void *)A0);
|
1742 |
} |
1743 |
|
1744 |
void OPPROTO op_fildl_ST0_A0(void) |
1745 |
{ |
1746 |
ST0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1747 |
} |
1748 |
|
1749 |
void OPPROTO op_fildll_ST0_A0(void) |
1750 |
{ |
1751 |
ST0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1752 |
} |
1753 |
|
1754 |
#endif
|
1755 |
|
1756 |
/* fp store */
|
1757 |
|
1758 |
void OPPROTO op_fsts_ST0_A0(void) |
1759 |
{ |
1760 |
stfl((void *)A0, (float)ST0); |
1761 |
} |
1762 |
|
1763 |
void OPPROTO op_fstl_ST0_A0(void) |
1764 |
{ |
1765 |
stfq((void *)A0, (double)ST0); |
1766 |
} |
1767 |
|
1768 |
#ifdef USE_X86LDOUBLE
|
1769 |
void OPPROTO op_fstt_ST0_A0(void) |
1770 |
{ |
1771 |
*(long double *)A0 = ST0; |
1772 |
} |
1773 |
#else
|
1774 |
void helper_fstt_ST0_A0(void) |
1775 |
{ |
1776 |
CPU86_LDoubleU temp; |
1777 |
int e;
|
1778 |
temp.d = ST0; |
1779 |
/* mantissa */
|
1780 |
stq((void *)A0, (MANTD(temp) << 11) | (1LL << 63)); |
1781 |
/* exponent + sign */
|
1782 |
e = EXPD(temp) - EXPBIAS + 16383;
|
1783 |
e |= SIGND(temp) >> 16;
|
1784 |
stw((uint8_t *)A0 + 8, e);
|
1785 |
} |
1786 |
|
1787 |
void OPPROTO op_fstt_ST0_A0(void) |
1788 |
{ |
1789 |
helper_fstt_ST0_A0(); |
1790 |
} |
1791 |
#endif
|
1792 |
|
1793 |
void OPPROTO op_fist_ST0_A0(void) |
1794 |
{ |
1795 |
int val;
|
1796 |
val = lrint(ST0); |
1797 |
stw((void *)A0, val);
|
1798 |
} |
1799 |
|
1800 |
void OPPROTO op_fistl_ST0_A0(void) |
1801 |
{ |
1802 |
int val;
|
1803 |
val = lrint(ST0); |
1804 |
stl((void *)A0, val);
|
1805 |
} |
1806 |
|
1807 |
void OPPROTO op_fistll_ST0_A0(void) |
1808 |
{ |
1809 |
int64_t val; |
1810 |
val = llrint(ST0); |
1811 |
stq((void *)A0, val);
|
1812 |
} |
1813 |
|
1814 |
/* BCD ops */
|
1815 |
|
1816 |
#define MUL10(iv) ( iv + iv + (iv << 3) ) |
1817 |
|
1818 |
void helper_fbld_ST0_A0(void) |
1819 |
{ |
1820 |
uint8_t *seg; |
1821 |
CPU86_LDouble fpsrcop; |
1822 |
int m32i;
|
1823 |
unsigned int v; |
1824 |
|
1825 |
/* in this code, seg/m32i will be used as temporary ptr/int */
|
1826 |
seg = (uint8_t *)A0 + 8;
|
1827 |
v = ldub(seg--); |
1828 |
/* XXX: raise exception */
|
1829 |
if (v != 0) |
1830 |
return;
|
1831 |
v = ldub(seg--); |
1832 |
/* XXX: raise exception */
|
1833 |
if ((v & 0xf0) != 0) |
1834 |
return;
|
1835 |
m32i = v; /* <-- d14 */
|
1836 |
v = ldub(seg--); |
1837 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d13 */ |
1838 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d12 */ |
1839 |
v = ldub(seg--); |
1840 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d11 */ |
1841 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d10 */ |
1842 |
v = ldub(seg--); |
1843 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d9 */ |
1844 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d8 */ |
1845 |
fpsrcop = ((CPU86_LDouble)m32i) * 100000000.0; |
1846 |
|
1847 |
v = ldub(seg--); |
1848 |
m32i = (v >> 4); /* <-- d7 */ |
1849 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d6 */ |
1850 |
v = ldub(seg--); |
1851 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d5 */ |
1852 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d4 */ |
1853 |
v = ldub(seg--); |
1854 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d3 */ |
1855 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d2 */ |
1856 |
v = ldub(seg); |
1857 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d1 */ |
1858 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d0 */ |
1859 |
fpsrcop += ((CPU86_LDouble)m32i); |
1860 |
if ( ldub(seg+9) & 0x80 ) |
1861 |
fpsrcop = -fpsrcop; |
1862 |
ST0 = fpsrcop; |
1863 |
} |
1864 |
|
1865 |
void OPPROTO op_fbld_ST0_A0(void) |
1866 |
{ |
1867 |
helper_fbld_ST0_A0(); |
1868 |
} |
1869 |
|
1870 |
void helper_fbst_ST0_A0(void) |
1871 |
{ |
1872 |
CPU86_LDouble fptemp; |
1873 |
CPU86_LDouble fpsrcop; |
1874 |
int v;
|
1875 |
uint8_t *mem_ref, *mem_end; |
1876 |
|
1877 |
fpsrcop = rint(ST0); |
1878 |
mem_ref = (uint8_t *)A0; |
1879 |
mem_end = mem_ref + 8;
|
1880 |
if ( fpsrcop < 0.0 ) { |
1881 |
stw(mem_end, 0x8000);
|
1882 |
fpsrcop = -fpsrcop; |
1883 |
} else {
|
1884 |
stw(mem_end, 0x0000);
|
1885 |
} |
1886 |
while (mem_ref < mem_end) {
|
1887 |
if (fpsrcop == 0.0) |
1888 |
break;
|
1889 |
fptemp = floor(fpsrcop/10.0); |
1890 |
v = ((int)(fpsrcop - fptemp*10.0)); |
1891 |
if (fptemp == 0.0) { |
1892 |
stb(mem_ref++, v); |
1893 |
break;
|
1894 |
} |
1895 |
fpsrcop = fptemp; |
1896 |
fptemp = floor(fpsrcop/10.0); |
1897 |
v |= (((int)(fpsrcop - fptemp*10.0)) << 4); |
1898 |
stb(mem_ref++, v); |
1899 |
fpsrcop = fptemp; |
1900 |
} |
1901 |
while (mem_ref < mem_end) {
|
1902 |
stb(mem_ref++, 0);
|
1903 |
} |
1904 |
} |
1905 |
|
1906 |
void OPPROTO op_fbst_ST0_A0(void) |
1907 |
{ |
1908 |
helper_fbst_ST0_A0(); |
1909 |
} |
1910 |
|
1911 |
/* FPU move */
|
1912 |
|
1913 |
static inline void fpush(void) |
1914 |
{ |
1915 |
env->fpstt = (env->fpstt - 1) & 7; |
1916 |
env->fptags[env->fpstt] = 0; /* validate stack entry */ |
1917 |
} |
1918 |
|
1919 |
static inline void fpop(void) |
1920 |
{ |
1921 |
env->fptags[env->fpstt] = 1; /* invvalidate stack entry */ |
1922 |
env->fpstt = (env->fpstt + 1) & 7; |
1923 |
} |
1924 |
|
1925 |
void OPPROTO op_fpush(void) |
1926 |
{ |
1927 |
fpush(); |
1928 |
} |
1929 |
|
1930 |
void OPPROTO op_fpop(void) |
1931 |
{ |
1932 |
fpop(); |
1933 |
} |
1934 |
|
1935 |
void OPPROTO op_fdecstp(void) |
1936 |
{ |
1937 |
env->fpstt = (env->fpstt - 1) & 7; |
1938 |
env->fpus &= (~0x4700);
|
1939 |
} |
1940 |
|
1941 |
void OPPROTO op_fincstp(void) |
1942 |
{ |
1943 |
env->fpstt = (env->fpstt + 1) & 7; |
1944 |
env->fpus &= (~0x4700);
|
1945 |
} |
1946 |
|
1947 |
void OPPROTO op_fmov_ST0_FT0(void) |
1948 |
{ |
1949 |
ST0 = FT0; |
1950 |
} |
1951 |
|
1952 |
void OPPROTO op_fmov_FT0_STN(void) |
1953 |
{ |
1954 |
FT0 = ST(PARAM1); |
1955 |
} |
1956 |
|
1957 |
void OPPROTO op_fmov_ST0_STN(void) |
1958 |
{ |
1959 |
ST0 = ST(PARAM1); |
1960 |
} |
1961 |
|
1962 |
void OPPROTO op_fmov_STN_ST0(void) |
1963 |
{ |
1964 |
ST(PARAM1) = ST0; |
1965 |
} |
1966 |
|
1967 |
void OPPROTO op_fxchg_ST0_STN(void) |
1968 |
{ |
1969 |
CPU86_LDouble tmp; |
1970 |
tmp = ST(PARAM1); |
1971 |
ST(PARAM1) = ST0; |
1972 |
ST0 = tmp; |
1973 |
} |
1974 |
|
1975 |
/* FPU operations */
|
1976 |
|
1977 |
/* XXX: handle nans */
|
1978 |
void OPPROTO op_fcom_ST0_FT0(void) |
1979 |
{ |
1980 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1981 |
if (ST0 < FT0)
|
1982 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1983 |
else if (ST0 == FT0) |
1984 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1985 |
FORCE_RET(); |
1986 |
} |
1987 |
|
1988 |
/* XXX: handle nans */
|
1989 |
void OPPROTO op_fucom_ST0_FT0(void) |
1990 |
{ |
1991 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1992 |
if (ST0 < FT0)
|
1993 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1994 |
else if (ST0 == FT0) |
1995 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1996 |
FORCE_RET(); |
1997 |
} |
1998 |
|
1999 |
void OPPROTO op_fadd_ST0_FT0(void) |
2000 |
{ |
2001 |
ST0 += FT0; |
2002 |
} |
2003 |
|
2004 |
void OPPROTO op_fmul_ST0_FT0(void) |
2005 |
{ |
2006 |
ST0 *= FT0; |
2007 |
} |
2008 |
|
2009 |
void OPPROTO op_fsub_ST0_FT0(void) |
2010 |
{ |
2011 |
ST0 -= FT0; |
2012 |
} |
2013 |
|
2014 |
void OPPROTO op_fsubr_ST0_FT0(void) |
2015 |
{ |
2016 |
ST0 = FT0 - ST0; |
2017 |
} |
2018 |
|
2019 |
void OPPROTO op_fdiv_ST0_FT0(void) |
2020 |
{ |
2021 |
ST0 /= FT0; |
2022 |
} |
2023 |
|
2024 |
void OPPROTO op_fdivr_ST0_FT0(void) |
2025 |
{ |
2026 |
ST0 = FT0 / ST0; |
2027 |
} |
2028 |
|
2029 |
/* fp operations between STN and ST0 */
|
2030 |
|
2031 |
void OPPROTO op_fadd_STN_ST0(void) |
2032 |
{ |
2033 |
ST(PARAM1) += ST0; |
2034 |
} |
2035 |
|
2036 |
void OPPROTO op_fmul_STN_ST0(void) |
2037 |
{ |
2038 |
ST(PARAM1) *= ST0; |
2039 |
} |
2040 |
|
2041 |
void OPPROTO op_fsub_STN_ST0(void) |
2042 |
{ |
2043 |
ST(PARAM1) -= ST0; |
2044 |
} |
2045 |
|
2046 |
void OPPROTO op_fsubr_STN_ST0(void) |
2047 |
{ |
2048 |
CPU86_LDouble *p; |
2049 |
p = &ST(PARAM1); |
2050 |
*p = ST0 - *p; |
2051 |
} |
2052 |
|
2053 |
void OPPROTO op_fdiv_STN_ST0(void) |
2054 |
{ |
2055 |
ST(PARAM1) /= ST0; |
2056 |
} |
2057 |
|
2058 |
void OPPROTO op_fdivr_STN_ST0(void) |
2059 |
{ |
2060 |
CPU86_LDouble *p; |
2061 |
p = &ST(PARAM1); |
2062 |
*p = ST0 / *p; |
2063 |
} |
2064 |
|
2065 |
/* misc FPU operations */
|
2066 |
void OPPROTO op_fchs_ST0(void) |
2067 |
{ |
2068 |
ST0 = -ST0; |
2069 |
} |
2070 |
|
2071 |
void OPPROTO op_fabs_ST0(void) |
2072 |
{ |
2073 |
ST0 = fabs(ST0); |
2074 |
} |
2075 |
|
2076 |
void helper_fxam_ST0(void) |
2077 |
{ |
2078 |
CPU86_LDoubleU temp; |
2079 |
int expdif;
|
2080 |
|
2081 |
temp.d = ST0; |
2082 |
|
2083 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2084 |
if (SIGND(temp))
|
2085 |
env->fpus |= 0x200; /* C1 <-- 1 */ |
2086 |
|
2087 |
expdif = EXPD(temp); |
2088 |
if (expdif == MAXEXPD) {
|
2089 |
if (MANTD(temp) == 0) |
2090 |
env->fpus |= 0x500 /*Infinity*/; |
2091 |
else
|
2092 |
env->fpus |= 0x100 /*NaN*/; |
2093 |
} else if (expdif == 0) { |
2094 |
if (MANTD(temp) == 0) |
2095 |
env->fpus |= 0x4000 /*Zero*/; |
2096 |
else
|
2097 |
env->fpus |= 0x4400 /*Denormal*/; |
2098 |
} else {
|
2099 |
env->fpus |= 0x400;
|
2100 |
} |
2101 |
} |
2102 |
|
2103 |
void OPPROTO op_fxam_ST0(void) |
2104 |
{ |
2105 |
helper_fxam_ST0(); |
2106 |
} |
2107 |
|
2108 |
void OPPROTO op_fld1_ST0(void) |
2109 |
{ |
2110 |
ST0 = *(CPU86_LDouble *)&f15rk[1];
|
2111 |
} |
2112 |
|
2113 |
void OPPROTO op_fldl2t_ST0(void) |
2114 |
{ |
2115 |
ST0 = *(CPU86_LDouble *)&f15rk[6];
|
2116 |
} |
2117 |
|
2118 |
void OPPROTO op_fldl2e_ST0(void) |
2119 |
{ |
2120 |
ST0 = *(CPU86_LDouble *)&f15rk[5];
|
2121 |
} |
2122 |
|
2123 |
void OPPROTO op_fldpi_ST0(void) |
2124 |
{ |
2125 |
ST0 = *(CPU86_LDouble *)&f15rk[2];
|
2126 |
} |
2127 |
|
2128 |
void OPPROTO op_fldlg2_ST0(void) |
2129 |
{ |
2130 |
ST0 = *(CPU86_LDouble *)&f15rk[3];
|
2131 |
} |
2132 |
|
2133 |
void OPPROTO op_fldln2_ST0(void) |
2134 |
{ |
2135 |
ST0 = *(CPU86_LDouble *)&f15rk[4];
|
2136 |
} |
2137 |
|
2138 |
void OPPROTO op_fldz_ST0(void) |
2139 |
{ |
2140 |
ST0 = *(CPU86_LDouble *)&f15rk[0];
|
2141 |
} |
2142 |
|
2143 |
void OPPROTO op_fldz_FT0(void) |
2144 |
{ |
2145 |
ST0 = *(CPU86_LDouble *)&f15rk[0];
|
2146 |
} |
2147 |
|
2148 |
void helper_f2xm1(void) |
2149 |
{ |
2150 |
ST0 = pow(2.0,ST0) - 1.0; |
2151 |
} |
2152 |
|
2153 |
void helper_fyl2x(void) |
2154 |
{ |
2155 |
CPU86_LDouble fptemp; |
2156 |
|
2157 |
fptemp = ST0; |
2158 |
if (fptemp>0.0){ |
2159 |
fptemp = log(fptemp)/log(2.0); /* log2(ST) */ |
2160 |
ST1 *= fptemp; |
2161 |
fpop(); |
2162 |
} else {
|
2163 |
env->fpus &= (~0x4700);
|
2164 |
env->fpus |= 0x400;
|
2165 |
} |
2166 |
} |
2167 |
|
2168 |
void helper_fptan(void) |
2169 |
{ |
2170 |
CPU86_LDouble fptemp; |
2171 |
|
2172 |
fptemp = ST0; |
2173 |
if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2174 |
env->fpus |= 0x400;
|
2175 |
} else {
|
2176 |
ST0 = tan(fptemp); |
2177 |
fpush(); |
2178 |
ST0 = 1.0; |
2179 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2180 |
/* the above code is for |arg| < 2**52 only */
|
2181 |
} |
2182 |
} |
2183 |
|
2184 |
void helper_fpatan(void) |
2185 |
{ |
2186 |
CPU86_LDouble fptemp, fpsrcop; |
2187 |
|
2188 |
fpsrcop = ST1; |
2189 |
fptemp = ST0; |
2190 |
ST1 = atan2(fpsrcop,fptemp); |
2191 |
fpop(); |
2192 |
} |
2193 |
|
2194 |
void helper_fxtract(void) |
2195 |
{ |
2196 |
CPU86_LDoubleU temp; |
2197 |
unsigned int expdif; |
2198 |
|
2199 |
temp.d = ST0; |
2200 |
expdif = EXPD(temp) - EXPBIAS; |
2201 |
/*DP exponent bias*/
|
2202 |
ST0 = expdif; |
2203 |
fpush(); |
2204 |
BIASEXPONENT(temp); |
2205 |
ST0 = temp.d; |
2206 |
} |
2207 |
|
2208 |
void helper_fprem1(void) |
2209 |
{ |
2210 |
CPU86_LDouble dblq, fpsrcop, fptemp; |
2211 |
CPU86_LDoubleU fpsrcop1, fptemp1; |
2212 |
int expdif;
|
2213 |
int q;
|
2214 |
|
2215 |
fpsrcop = ST0; |
2216 |
fptemp = ST1; |
2217 |
fpsrcop1.d = fpsrcop; |
2218 |
fptemp1.d = fptemp; |
2219 |
expdif = EXPD(fpsrcop1) - EXPD(fptemp1); |
2220 |
if (expdif < 53) { |
2221 |
dblq = fpsrcop / fptemp; |
2222 |
dblq = (dblq < 0.0)? ceil(dblq): floor(dblq); |
2223 |
ST0 = fpsrcop - fptemp*dblq; |
2224 |
q = (int)dblq; /* cutting off top bits is assumed here */ |
2225 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2226 |
/* (C0,C1,C3) <-- (q2,q1,q0) */
|
2227 |
env->fpus |= (q&0x4) << 6; /* (C0) <-- q2 */ |
2228 |
env->fpus |= (q&0x2) << 8; /* (C1) <-- q1 */ |
2229 |
env->fpus |= (q&0x1) << 14; /* (C3) <-- q0 */ |
2230 |
} else {
|
2231 |
env->fpus |= 0x400; /* C2 <-- 1 */ |
2232 |
fptemp = pow(2.0, expdif-50); |
2233 |
fpsrcop = (ST0 / ST1) / fptemp; |
2234 |
/* fpsrcop = integer obtained by rounding to the nearest */
|
2235 |
fpsrcop = (fpsrcop-floor(fpsrcop) < ceil(fpsrcop)-fpsrcop)? |
2236 |
floor(fpsrcop): ceil(fpsrcop); |
2237 |
ST0 -= (ST1 * fpsrcop * fptemp); |
2238 |
} |
2239 |
} |
2240 |
|
2241 |
void helper_fprem(void) |
2242 |
{ |
2243 |
CPU86_LDouble dblq, fpsrcop, fptemp; |
2244 |
CPU86_LDoubleU fpsrcop1, fptemp1; |
2245 |
int expdif;
|
2246 |
int q;
|
2247 |
|
2248 |
fpsrcop = ST0; |
2249 |
fptemp = ST1; |
2250 |
fpsrcop1.d = fpsrcop; |
2251 |
fptemp1.d = fptemp; |
2252 |
expdif = EXPD(fpsrcop1) - EXPD(fptemp1); |
2253 |
if ( expdif < 53 ) { |
2254 |
dblq = fpsrcop / fptemp; |
2255 |
dblq = (dblq < 0.0)? ceil(dblq): floor(dblq); |
2256 |
ST0 = fpsrcop - fptemp*dblq; |
2257 |
q = (int)dblq; /* cutting off top bits is assumed here */ |
2258 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2259 |
/* (C0,C1,C3) <-- (q2,q1,q0) */
|
2260 |
env->fpus |= (q&0x4) << 6; /* (C0) <-- q2 */ |
2261 |
env->fpus |= (q&0x2) << 8; /* (C1) <-- q1 */ |
2262 |
env->fpus |= (q&0x1) << 14; /* (C3) <-- q0 */ |
2263 |
} else {
|
2264 |
env->fpus |= 0x400; /* C2 <-- 1 */ |
2265 |
fptemp = pow(2.0, expdif-50); |
2266 |
fpsrcop = (ST0 / ST1) / fptemp; |
2267 |
/* fpsrcop = integer obtained by chopping */
|
2268 |
fpsrcop = (fpsrcop < 0.0)? |
2269 |
-(floor(fabs(fpsrcop))): floor(fpsrcop); |
2270 |
ST0 -= (ST1 * fpsrcop * fptemp); |
2271 |
} |
2272 |
} |
2273 |
|
2274 |
void helper_fyl2xp1(void) |
2275 |
{ |
2276 |
CPU86_LDouble fptemp; |
2277 |
|
2278 |
fptemp = ST0; |
2279 |
if ((fptemp+1.0)>0.0) { |
2280 |
fptemp = log(fptemp+1.0) / log(2.0); /* log2(ST+1.0) */ |
2281 |
ST1 *= fptemp; |
2282 |
fpop(); |
2283 |
} else {
|
2284 |
env->fpus &= (~0x4700);
|
2285 |
env->fpus |= 0x400;
|
2286 |
} |
2287 |
} |
2288 |
|
2289 |
void helper_fsqrt(void) |
2290 |
{ |
2291 |
CPU86_LDouble fptemp; |
2292 |
|
2293 |
fptemp = ST0; |
2294 |
if (fptemp<0.0) { |
2295 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2296 |
env->fpus |= 0x400;
|
2297 |
} |
2298 |
ST0 = sqrt(fptemp); |
2299 |
} |
2300 |
|
2301 |
void helper_fsincos(void) |
2302 |
{ |
2303 |
CPU86_LDouble fptemp; |
2304 |
|
2305 |
fptemp = ST0; |
2306 |
if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2307 |
env->fpus |= 0x400;
|
2308 |
} else {
|
2309 |
ST0 = sin(fptemp); |
2310 |
fpush(); |
2311 |
ST0 = cos(fptemp); |
2312 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2313 |
/* the above code is for |arg| < 2**63 only */
|
2314 |
} |
2315 |
} |
2316 |
|
2317 |
void helper_frndint(void) |
2318 |
{ |
2319 |
ST0 = rint(ST0); |
2320 |
} |
2321 |
|
2322 |
void helper_fscale(void) |
2323 |
{ |
2324 |
CPU86_LDouble fpsrcop, fptemp; |
2325 |
|
2326 |
fpsrcop = 2.0; |
2327 |
fptemp = pow(fpsrcop,ST1); |
2328 |
ST0 *= fptemp; |
2329 |
} |
2330 |
|
2331 |
void helper_fsin(void) |
2332 |
{ |
2333 |
CPU86_LDouble fptemp; |
2334 |
|
2335 |
fptemp = ST0; |
2336 |
if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2337 |
env->fpus |= 0x400;
|
2338 |
} else {
|
2339 |
ST0 = sin(fptemp); |
2340 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2341 |
/* the above code is for |arg| < 2**53 only */
|
2342 |
} |
2343 |
} |
2344 |
|
2345 |
void helper_fcos(void) |
2346 |
{ |
2347 |
CPU86_LDouble fptemp; |
2348 |
|
2349 |
fptemp = ST0; |
2350 |
if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2351 |
env->fpus |= 0x400;
|
2352 |
} else {
|
2353 |
ST0 = cos(fptemp); |
2354 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2355 |
/* the above code is for |arg5 < 2**63 only */
|
2356 |
} |
2357 |
} |
2358 |
|
2359 |
/* associated heplers to reduce generated code length and to simplify
|
2360 |
relocation (FP constants are usually stored in .rodata section) */
|
2361 |
|
2362 |
void OPPROTO op_f2xm1(void) |
2363 |
{ |
2364 |
helper_f2xm1(); |
2365 |
} |
2366 |
|
2367 |
void OPPROTO op_fyl2x(void) |
2368 |
{ |
2369 |
helper_fyl2x(); |
2370 |
} |
2371 |
|
2372 |
void OPPROTO op_fptan(void) |
2373 |
{ |
2374 |
helper_fptan(); |
2375 |
} |
2376 |
|
2377 |
void OPPROTO op_fpatan(void) |
2378 |
{ |
2379 |
helper_fpatan(); |
2380 |
} |
2381 |
|
2382 |
void OPPROTO op_fxtract(void) |
2383 |
{ |
2384 |
helper_fxtract(); |
2385 |
} |
2386 |
|
2387 |
void OPPROTO op_fprem1(void) |
2388 |
{ |
2389 |
helper_fprem1(); |
2390 |
} |
2391 |
|
2392 |
|
2393 |
void OPPROTO op_fprem(void) |
2394 |
{ |
2395 |
helper_fprem(); |
2396 |
} |
2397 |
|
2398 |
void OPPROTO op_fyl2xp1(void) |
2399 |
{ |
2400 |
helper_fyl2xp1(); |
2401 |
} |
2402 |
|
2403 |
void OPPROTO op_fsqrt(void) |
2404 |
{ |
2405 |
helper_fsqrt(); |
2406 |
} |
2407 |
|
2408 |
void OPPROTO op_fsincos(void) |
2409 |
{ |
2410 |
helper_fsincos(); |
2411 |
} |
2412 |
|
2413 |
void OPPROTO op_frndint(void) |
2414 |
{ |
2415 |
helper_frndint(); |
2416 |
} |
2417 |
|
2418 |
void OPPROTO op_fscale(void) |
2419 |
{ |
2420 |
helper_fscale(); |
2421 |
} |
2422 |
|
2423 |
void OPPROTO op_fsin(void) |
2424 |
{ |
2425 |
helper_fsin(); |
2426 |
} |
2427 |
|
2428 |
void OPPROTO op_fcos(void) |
2429 |
{ |
2430 |
helper_fcos(); |
2431 |
} |
2432 |
|
2433 |
void OPPROTO op_fnstsw_A0(void) |
2434 |
{ |
2435 |
int fpus;
|
2436 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2437 |
stw((void *)A0, fpus);
|
2438 |
} |
2439 |
|
2440 |
void OPPROTO op_fnstsw_EAX(void) |
2441 |
{ |
2442 |
int fpus;
|
2443 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2444 |
EAX = (EAX & 0xffff0000) | fpus;
|
2445 |
} |
2446 |
|
2447 |
void OPPROTO op_fnstcw_A0(void) |
2448 |
{ |
2449 |
stw((void *)A0, env->fpuc);
|
2450 |
} |
2451 |
|
2452 |
void OPPROTO op_fldcw_A0(void) |
2453 |
{ |
2454 |
int rnd_type;
|
2455 |
env->fpuc = lduw((void *)A0);
|
2456 |
/* set rounding mode */
|
2457 |
switch(env->fpuc & RC_MASK) {
|
2458 |
default:
|
2459 |
case RC_NEAR:
|
2460 |
rnd_type = FE_TONEAREST; |
2461 |
break;
|
2462 |
case RC_DOWN:
|
2463 |
rnd_type = FE_DOWNWARD; |
2464 |
break;
|
2465 |
case RC_UP:
|
2466 |
rnd_type = FE_UPWARD; |
2467 |
break;
|
2468 |
case RC_CHOP:
|
2469 |
rnd_type = FE_TOWARDZERO; |
2470 |
break;
|
2471 |
} |
2472 |
fesetround(rnd_type); |
2473 |
} |
2474 |
|
2475 |
void OPPROTO op_fclex(void) |
2476 |
{ |
2477 |
env->fpus &= 0x7f00;
|
2478 |
} |
2479 |
|
2480 |
void OPPROTO op_fninit(void) |
2481 |
{ |
2482 |
env->fpus = 0;
|
2483 |
env->fpstt = 0;
|
2484 |
env->fpuc = 0x37f;
|
2485 |
env->fptags[0] = 1; |
2486 |
env->fptags[1] = 1; |
2487 |
env->fptags[2] = 1; |
2488 |
env->fptags[3] = 1; |
2489 |
env->fptags[4] = 1; |
2490 |
env->fptags[5] = 1; |
2491 |
env->fptags[6] = 1; |
2492 |
env->fptags[7] = 1; |
2493 |
} |
2494 |
|
2495 |
/* threading support */
|
2496 |
void OPPROTO op_lock(void) |
2497 |
{ |
2498 |
cpu_lock(); |
2499 |
} |
2500 |
|
2501 |
void OPPROTO op_unlock(void) |
2502 |
{ |
2503 |
cpu_unlock(); |
2504 |
} |