root / op-i386.c @ 564c8f99
History | View | Annotate | Download (50.1 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 |
int intno;
|
620 |
intno = PARAM1; |
621 |
EIP = PARAM2; |
622 |
raise_exception_err(EXCP0D_GPF, intno * 8 + 2); |
623 |
} |
624 |
|
625 |
void OPPROTO op_raise_exception(void) |
626 |
{ |
627 |
int exception_index;
|
628 |
exception_index = PARAM1; |
629 |
raise_exception(exception_index); |
630 |
} |
631 |
|
632 |
void OPPROTO op_into(void) |
633 |
{ |
634 |
int eflags;
|
635 |
eflags = cc_table[CC_OP].compute_all(); |
636 |
if (eflags & CC_O) {
|
637 |
raise_exception(EXCP04_INTO); |
638 |
} |
639 |
FORCE_RET(); |
640 |
} |
641 |
|
642 |
void OPPROTO op_cli(void) |
643 |
{ |
644 |
env->eflags &= ~IF_MASK; |
645 |
} |
646 |
|
647 |
void OPPROTO op_sti(void) |
648 |
{ |
649 |
env->eflags |= IF_MASK; |
650 |
} |
651 |
|
652 |
#if 0
|
653 |
/* vm86plus instructions */
|
654 |
void OPPROTO op_cli_vm(void)
|
655 |
{
|
656 |
env->eflags &= ~VIF_MASK;
|
657 |
}
|
658 |
|
659 |
void OPPROTO op_sti_vm(void)
|
660 |
{
|
661 |
env->eflags |= VIF_MASK;
|
662 |
if (env->eflags & VIP_MASK) {
|
663 |
EIP = PARAM1;
|
664 |
raise_exception(EXCP0D_GPF);
|
665 |
}
|
666 |
FORCE_RET();
|
667 |
}
|
668 |
#endif
|
669 |
|
670 |
void OPPROTO op_boundw(void) |
671 |
{ |
672 |
int low, high, v;
|
673 |
low = ldsw((uint8_t *)A0); |
674 |
high = ldsw((uint8_t *)A0 + 2);
|
675 |
v = (int16_t)T0; |
676 |
if (v < low || v > high)
|
677 |
raise_exception(EXCP05_BOUND); |
678 |
FORCE_RET(); |
679 |
} |
680 |
|
681 |
void OPPROTO op_boundl(void) |
682 |
{ |
683 |
int low, high, v;
|
684 |
low = ldl((uint8_t *)A0); |
685 |
high = ldl((uint8_t *)A0 + 4);
|
686 |
v = T0; |
687 |
if (v < low || v > high)
|
688 |
raise_exception(EXCP05_BOUND); |
689 |
FORCE_RET(); |
690 |
} |
691 |
|
692 |
void OPPROTO op_cmpxchg8b(void) |
693 |
{ |
694 |
uint64_t d; |
695 |
int eflags;
|
696 |
|
697 |
eflags = cc_table[CC_OP].compute_all(); |
698 |
d = ldq((uint8_t *)A0); |
699 |
if (d == (((uint64_t)EDX << 32) | EAX)) { |
700 |
stq((uint8_t *)A0, ((uint64_t)ECX << 32) | EBX);
|
701 |
eflags |= CC_Z; |
702 |
} else {
|
703 |
EDX = d >> 32;
|
704 |
EAX = d; |
705 |
eflags &= ~CC_Z; |
706 |
} |
707 |
CC_SRC = eflags; |
708 |
FORCE_RET(); |
709 |
} |
710 |
|
711 |
/* string ops */
|
712 |
|
713 |
#define ldul ldl
|
714 |
|
715 |
#define SHIFT 0 |
716 |
#include "ops_template.h" |
717 |
#undef SHIFT
|
718 |
|
719 |
#define SHIFT 1 |
720 |
#include "ops_template.h" |
721 |
#undef SHIFT
|
722 |
|
723 |
#define SHIFT 2 |
724 |
#include "ops_template.h" |
725 |
#undef SHIFT
|
726 |
|
727 |
/* sign extend */
|
728 |
|
729 |
void OPPROTO op_movsbl_T0_T0(void) |
730 |
{ |
731 |
T0 = (int8_t)T0; |
732 |
} |
733 |
|
734 |
void OPPROTO op_movzbl_T0_T0(void) |
735 |
{ |
736 |
T0 = (uint8_t)T0; |
737 |
} |
738 |
|
739 |
void OPPROTO op_movswl_T0_T0(void) |
740 |
{ |
741 |
T0 = (int16_t)T0; |
742 |
} |
743 |
|
744 |
void OPPROTO op_movzwl_T0_T0(void) |
745 |
{ |
746 |
T0 = (uint16_t)T0; |
747 |
} |
748 |
|
749 |
void OPPROTO op_movswl_EAX_AX(void) |
750 |
{ |
751 |
EAX = (int16_t)EAX; |
752 |
} |
753 |
|
754 |
void OPPROTO op_movsbw_AX_AL(void) |
755 |
{ |
756 |
EAX = (EAX & 0xffff0000) | ((int8_t)EAX & 0xffff); |
757 |
} |
758 |
|
759 |
void OPPROTO op_movslq_EDX_EAX(void) |
760 |
{ |
761 |
EDX = (int32_t)EAX >> 31;
|
762 |
} |
763 |
|
764 |
void OPPROTO op_movswl_DX_AX(void) |
765 |
{ |
766 |
EDX = (EDX & 0xffff0000) | (((int16_t)EAX >> 15) & 0xffff); |
767 |
} |
768 |
|
769 |
/* push/pop */
|
770 |
|
771 |
void op_pushl_T0(void) |
772 |
{ |
773 |
uint32_t offset; |
774 |
offset = ESP - 4;
|
775 |
stl((void *)offset, T0);
|
776 |
/* modify ESP after to handle exceptions correctly */
|
777 |
ESP = offset; |
778 |
} |
779 |
|
780 |
void op_pushw_T0(void) |
781 |
{ |
782 |
uint32_t offset; |
783 |
offset = ESP - 2;
|
784 |
stw((void *)offset, T0);
|
785 |
/* modify ESP after to handle exceptions correctly */
|
786 |
ESP = offset; |
787 |
} |
788 |
|
789 |
void op_pushl_ss32_T0(void) |
790 |
{ |
791 |
uint32_t offset; |
792 |
offset = ESP - 4;
|
793 |
stl(env->seg_cache[R_SS].base + offset, T0); |
794 |
/* modify ESP after to handle exceptions correctly */
|
795 |
ESP = offset; |
796 |
} |
797 |
|
798 |
void op_pushw_ss32_T0(void) |
799 |
{ |
800 |
uint32_t offset; |
801 |
offset = ESP - 2;
|
802 |
stw(env->seg_cache[R_SS].base + offset, T0); |
803 |
/* modify ESP after to handle exceptions correctly */
|
804 |
ESP = offset; |
805 |
} |
806 |
|
807 |
void op_pushl_ss16_T0(void) |
808 |
{ |
809 |
uint32_t offset; |
810 |
offset = (ESP - 4) & 0xffff; |
811 |
stl(env->seg_cache[R_SS].base + offset, T0); |
812 |
/* modify ESP after to handle exceptions correctly */
|
813 |
ESP = (ESP & ~0xffff) | offset;
|
814 |
} |
815 |
|
816 |
void op_pushw_ss16_T0(void) |
817 |
{ |
818 |
uint32_t offset; |
819 |
offset = (ESP - 2) & 0xffff; |
820 |
stw(env->seg_cache[R_SS].base + offset, T0); |
821 |
/* modify ESP after to handle exceptions correctly */
|
822 |
ESP = (ESP & ~0xffff) | offset;
|
823 |
} |
824 |
|
825 |
/* NOTE: ESP update is done after */
|
826 |
void op_popl_T0(void) |
827 |
{ |
828 |
T0 = ldl((void *)ESP);
|
829 |
} |
830 |
|
831 |
void op_popw_T0(void) |
832 |
{ |
833 |
T0 = lduw((void *)ESP);
|
834 |
} |
835 |
|
836 |
void op_popl_ss32_T0(void) |
837 |
{ |
838 |
T0 = ldl(env->seg_cache[R_SS].base + ESP); |
839 |
} |
840 |
|
841 |
void op_popw_ss32_T0(void) |
842 |
{ |
843 |
T0 = lduw(env->seg_cache[R_SS].base + ESP); |
844 |
} |
845 |
|
846 |
void op_popl_ss16_T0(void) |
847 |
{ |
848 |
T0 = ldl(env->seg_cache[R_SS].base + (ESP & 0xffff));
|
849 |
} |
850 |
|
851 |
void op_popw_ss16_T0(void) |
852 |
{ |
853 |
T0 = lduw(env->seg_cache[R_SS].base + (ESP & 0xffff));
|
854 |
} |
855 |
|
856 |
void op_addl_ESP_4(void) |
857 |
{ |
858 |
ESP += 4;
|
859 |
} |
860 |
|
861 |
void op_addl_ESP_2(void) |
862 |
{ |
863 |
ESP += 2;
|
864 |
} |
865 |
|
866 |
void op_addw_ESP_4(void) |
867 |
{ |
868 |
ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff); |
869 |
} |
870 |
|
871 |
void op_addw_ESP_2(void) |
872 |
{ |
873 |
ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff); |
874 |
} |
875 |
|
876 |
void op_addl_ESP_im(void) |
877 |
{ |
878 |
ESP += PARAM1; |
879 |
} |
880 |
|
881 |
void op_addw_ESP_im(void) |
882 |
{ |
883 |
ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff); |
884 |
} |
885 |
|
886 |
/* rdtsc */
|
887 |
#ifndef __i386__
|
888 |
uint64_t emu_time; |
889 |
#endif
|
890 |
|
891 |
void OPPROTO op_rdtsc(void) |
892 |
{ |
893 |
uint64_t val; |
894 |
#ifdef __i386__
|
895 |
asm("rdtsc" : "=A" (val)); |
896 |
#else
|
897 |
/* better than nothing: the time increases */
|
898 |
val = emu_time++; |
899 |
#endif
|
900 |
EAX = val; |
901 |
EDX = val >> 32;
|
902 |
} |
903 |
|
904 |
/* We simulate a pre-MMX pentium as in valgrind */
|
905 |
#define CPUID_FP87 (1 << 0) |
906 |
#define CPUID_VME (1 << 1) |
907 |
#define CPUID_DE (1 << 2) |
908 |
#define CPUID_PSE (1 << 3) |
909 |
#define CPUID_TSC (1 << 4) |
910 |
#define CPUID_MSR (1 << 5) |
911 |
#define CPUID_PAE (1 << 6) |
912 |
#define CPUID_MCE (1 << 7) |
913 |
#define CPUID_CX8 (1 << 8) |
914 |
#define CPUID_APIC (1 << 9) |
915 |
#define CPUID_SEP (1 << 11) /* sysenter/sysexit */ |
916 |
#define CPUID_MTRR (1 << 12) |
917 |
#define CPUID_PGE (1 << 13) |
918 |
#define CPUID_MCA (1 << 14) |
919 |
#define CPUID_CMOV (1 << 15) |
920 |
/* ... */
|
921 |
#define CPUID_MMX (1 << 23) |
922 |
#define CPUID_FXSR (1 << 24) |
923 |
#define CPUID_SSE (1 << 25) |
924 |
#define CPUID_SSE2 (1 << 26) |
925 |
|
926 |
void helper_cpuid(void) |
927 |
{ |
928 |
if (EAX == 0) { |
929 |
EAX = 1; /* max EAX index supported */ |
930 |
EBX = 0x756e6547;
|
931 |
ECX = 0x6c65746e;
|
932 |
EDX = 0x49656e69;
|
933 |
} else {
|
934 |
/* EAX = 1 info */
|
935 |
EAX = 0x52b;
|
936 |
EBX = 0;
|
937 |
ECX = 0;
|
938 |
EDX = CPUID_FP87 | CPUID_DE | CPUID_PSE | |
939 |
CPUID_TSC | CPUID_MSR | CPUID_MCE | |
940 |
CPUID_CX8; |
941 |
} |
942 |
} |
943 |
|
944 |
void OPPROTO op_cpuid(void) |
945 |
{ |
946 |
helper_cpuid(); |
947 |
} |
948 |
|
949 |
/* bcd */
|
950 |
|
951 |
/* XXX: exception */
|
952 |
void OPPROTO op_aam(void) |
953 |
{ |
954 |
int base = PARAM1;
|
955 |
int al, ah;
|
956 |
al = EAX & 0xff;
|
957 |
ah = al / base; |
958 |
al = al % base; |
959 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
960 |
CC_DST = al; |
961 |
} |
962 |
|
963 |
void OPPROTO op_aad(void) |
964 |
{ |
965 |
int base = PARAM1;
|
966 |
int al, ah;
|
967 |
al = EAX & 0xff;
|
968 |
ah = (EAX >> 8) & 0xff; |
969 |
al = ((ah * base) + al) & 0xff;
|
970 |
EAX = (EAX & ~0xffff) | al;
|
971 |
CC_DST = al; |
972 |
} |
973 |
|
974 |
void OPPROTO op_aaa(void) |
975 |
{ |
976 |
int icarry;
|
977 |
int al, ah, af;
|
978 |
int eflags;
|
979 |
|
980 |
eflags = cc_table[CC_OP].compute_all(); |
981 |
af = eflags & CC_A; |
982 |
al = EAX & 0xff;
|
983 |
ah = (EAX >> 8) & 0xff; |
984 |
|
985 |
icarry = (al > 0xf9);
|
986 |
if (((al & 0x0f) > 9 ) || af) { |
987 |
al = (al + 6) & 0x0f; |
988 |
ah = (ah + 1 + icarry) & 0xff; |
989 |
eflags |= CC_C | CC_A; |
990 |
} else {
|
991 |
eflags &= ~(CC_C | CC_A); |
992 |
al &= 0x0f;
|
993 |
} |
994 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
995 |
CC_SRC = eflags; |
996 |
} |
997 |
|
998 |
void OPPROTO op_aas(void) |
999 |
{ |
1000 |
int icarry;
|
1001 |
int al, ah, af;
|
1002 |
int eflags;
|
1003 |
|
1004 |
eflags = cc_table[CC_OP].compute_all(); |
1005 |
af = eflags & CC_A; |
1006 |
al = EAX & 0xff;
|
1007 |
ah = (EAX >> 8) & 0xff; |
1008 |
|
1009 |
icarry = (al < 6);
|
1010 |
if (((al & 0x0f) > 9 ) || af) { |
1011 |
al = (al - 6) & 0x0f; |
1012 |
ah = (ah - 1 - icarry) & 0xff; |
1013 |
eflags |= CC_C | CC_A; |
1014 |
} else {
|
1015 |
eflags &= ~(CC_C | CC_A); |
1016 |
al &= 0x0f;
|
1017 |
} |
1018 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
1019 |
CC_SRC = eflags; |
1020 |
} |
1021 |
|
1022 |
void OPPROTO op_daa(void) |
1023 |
{ |
1024 |
int al, af, cf;
|
1025 |
int eflags;
|
1026 |
|
1027 |
eflags = cc_table[CC_OP].compute_all(); |
1028 |
cf = eflags & CC_C; |
1029 |
af = eflags & CC_A; |
1030 |
al = EAX & 0xff;
|
1031 |
|
1032 |
eflags = 0;
|
1033 |
if (((al & 0x0f) > 9 ) || af) { |
1034 |
al = (al + 6) & 0xff; |
1035 |
eflags |= CC_A; |
1036 |
} |
1037 |
if ((al > 0x9f) || cf) { |
1038 |
al = (al + 0x60) & 0xff; |
1039 |
eflags |= CC_C; |
1040 |
} |
1041 |
EAX = (EAX & ~0xff) | al;
|
1042 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1043 |
eflags |= (al == 0) << 6; /* zf */ |
1044 |
eflags |= parity_table[al]; /* pf */
|
1045 |
eflags |= (al & 0x80); /* sf */ |
1046 |
CC_SRC = eflags; |
1047 |
} |
1048 |
|
1049 |
void OPPROTO op_das(void) |
1050 |
{ |
1051 |
int al, al1, af, cf;
|
1052 |
int eflags;
|
1053 |
|
1054 |
eflags = cc_table[CC_OP].compute_all(); |
1055 |
cf = eflags & CC_C; |
1056 |
af = eflags & CC_A; |
1057 |
al = EAX & 0xff;
|
1058 |
|
1059 |
eflags = 0;
|
1060 |
al1 = al; |
1061 |
if (((al & 0x0f) > 9 ) || af) { |
1062 |
eflags |= CC_A; |
1063 |
if (al < 6 || cf) |
1064 |
eflags |= CC_C; |
1065 |
al = (al - 6) & 0xff; |
1066 |
} |
1067 |
if ((al1 > 0x99) || cf) { |
1068 |
al = (al - 0x60) & 0xff; |
1069 |
eflags |= CC_C; |
1070 |
} |
1071 |
EAX = (EAX & ~0xff) | al;
|
1072 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1073 |
eflags |= (al == 0) << 6; /* zf */ |
1074 |
eflags |= parity_table[al]; /* pf */
|
1075 |
eflags |= (al & 0x80); /* sf */ |
1076 |
CC_SRC = eflags; |
1077 |
} |
1078 |
|
1079 |
/* segment handling */
|
1080 |
|
1081 |
/* XXX: use static VM86 information */
|
1082 |
void load_seg(int seg_reg, int selector) |
1083 |
{ |
1084 |
SegmentCache *sc; |
1085 |
SegmentDescriptorTable *dt; |
1086 |
int index;
|
1087 |
uint32_t e1, e2; |
1088 |
uint8_t *ptr; |
1089 |
|
1090 |
sc = &env->seg_cache[seg_reg]; |
1091 |
if (env->eflags & VM_MASK) {
|
1092 |
sc->base = (void *)(selector << 4); |
1093 |
sc->limit = 0xffff;
|
1094 |
sc->seg_32bit = 0;
|
1095 |
} else {
|
1096 |
if (selector & 0x4) |
1097 |
dt = &env->ldt; |
1098 |
else
|
1099 |
dt = &env->gdt; |
1100 |
index = selector & ~7;
|
1101 |
if ((index + 7) > dt->limit) |
1102 |
raise_exception_err(EXCP0D_GPF, selector); |
1103 |
ptr = dt->base + index; |
1104 |
e1 = ldl(ptr); |
1105 |
e2 = ldl(ptr + 4);
|
1106 |
sc->base = (void *)((e1 >> 16) | ((e2 & 0xff) << 16) | (e2 & 0xff000000)); |
1107 |
sc->limit = (e1 & 0xffff) | (e2 & 0x000f0000); |
1108 |
if (e2 & (1 << 23)) |
1109 |
sc->limit = (sc->limit << 12) | 0xfff; |
1110 |
sc->seg_32bit = (e2 >> 22) & 1; |
1111 |
#if 0
|
1112 |
fprintf(logfile, "load_seg: sel=0x%04x base=0x%08lx limit=0x%08lx seg_32bit=%d\n",
|
1113 |
selector, (unsigned long)sc->base, sc->limit, sc->seg_32bit);
|
1114 |
#endif
|
1115 |
} |
1116 |
env->segs[seg_reg] = selector; |
1117 |
} |
1118 |
|
1119 |
void OPPROTO op_movl_seg_T0(void) |
1120 |
{ |
1121 |
load_seg(PARAM1, T0 & 0xffff);
|
1122 |
} |
1123 |
|
1124 |
void OPPROTO op_movl_T0_seg(void) |
1125 |
{ |
1126 |
T0 = env->segs[PARAM1]; |
1127 |
} |
1128 |
|
1129 |
void OPPROTO op_movl_A0_seg(void) |
1130 |
{ |
1131 |
A0 = *(unsigned long *)((char *)env + PARAM1); |
1132 |
} |
1133 |
|
1134 |
void OPPROTO op_addl_A0_seg(void) |
1135 |
{ |
1136 |
A0 += *(unsigned long *)((char *)env + PARAM1); |
1137 |
} |
1138 |
|
1139 |
/* flags handling */
|
1140 |
|
1141 |
/* slow jumps cases (compute x86 flags) */
|
1142 |
void OPPROTO op_jo_cc(void) |
1143 |
{ |
1144 |
int eflags;
|
1145 |
eflags = cc_table[CC_OP].compute_all(); |
1146 |
if (eflags & CC_O)
|
1147 |
EIP = PARAM1; |
1148 |
else
|
1149 |
EIP = PARAM2; |
1150 |
FORCE_RET(); |
1151 |
} |
1152 |
|
1153 |
void OPPROTO op_jb_cc(void) |
1154 |
{ |
1155 |
if (cc_table[CC_OP].compute_c())
|
1156 |
EIP = PARAM1; |
1157 |
else
|
1158 |
EIP = PARAM2; |
1159 |
FORCE_RET(); |
1160 |
} |
1161 |
|
1162 |
void OPPROTO op_jz_cc(void) |
1163 |
{ |
1164 |
int eflags;
|
1165 |
eflags = cc_table[CC_OP].compute_all(); |
1166 |
if (eflags & CC_Z)
|
1167 |
EIP = PARAM1; |
1168 |
else
|
1169 |
EIP = PARAM2; |
1170 |
FORCE_RET(); |
1171 |
} |
1172 |
|
1173 |
void OPPROTO op_jbe_cc(void) |
1174 |
{ |
1175 |
int eflags;
|
1176 |
eflags = cc_table[CC_OP].compute_all(); |
1177 |
if (eflags & (CC_Z | CC_C))
|
1178 |
EIP = PARAM1; |
1179 |
else
|
1180 |
EIP = PARAM2; |
1181 |
FORCE_RET(); |
1182 |
} |
1183 |
|
1184 |
void OPPROTO op_js_cc(void) |
1185 |
{ |
1186 |
int eflags;
|
1187 |
eflags = cc_table[CC_OP].compute_all(); |
1188 |
if (eflags & CC_S)
|
1189 |
EIP = PARAM1; |
1190 |
else
|
1191 |
EIP = PARAM2; |
1192 |
FORCE_RET(); |
1193 |
} |
1194 |
|
1195 |
void OPPROTO op_jp_cc(void) |
1196 |
{ |
1197 |
int eflags;
|
1198 |
eflags = cc_table[CC_OP].compute_all(); |
1199 |
if (eflags & CC_P)
|
1200 |
EIP = PARAM1; |
1201 |
else
|
1202 |
EIP = PARAM2; |
1203 |
FORCE_RET(); |
1204 |
} |
1205 |
|
1206 |
void OPPROTO op_jl_cc(void) |
1207 |
{ |
1208 |
int eflags;
|
1209 |
eflags = cc_table[CC_OP].compute_all(); |
1210 |
if ((eflags ^ (eflags >> 4)) & 0x80) |
1211 |
EIP = PARAM1; |
1212 |
else
|
1213 |
EIP = PARAM2; |
1214 |
FORCE_RET(); |
1215 |
} |
1216 |
|
1217 |
void OPPROTO op_jle_cc(void) |
1218 |
{ |
1219 |
int eflags;
|
1220 |
eflags = cc_table[CC_OP].compute_all(); |
1221 |
if (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) |
1222 |
EIP = PARAM1; |
1223 |
else
|
1224 |
EIP = PARAM2; |
1225 |
FORCE_RET(); |
1226 |
} |
1227 |
|
1228 |
/* slow set cases (compute x86 flags) */
|
1229 |
void OPPROTO op_seto_T0_cc(void) |
1230 |
{ |
1231 |
int eflags;
|
1232 |
eflags = cc_table[CC_OP].compute_all(); |
1233 |
T0 = (eflags >> 11) & 1; |
1234 |
} |
1235 |
|
1236 |
void OPPROTO op_setb_T0_cc(void) |
1237 |
{ |
1238 |
T0 = cc_table[CC_OP].compute_c(); |
1239 |
} |
1240 |
|
1241 |
void OPPROTO op_setz_T0_cc(void) |
1242 |
{ |
1243 |
int eflags;
|
1244 |
eflags = cc_table[CC_OP].compute_all(); |
1245 |
T0 = (eflags >> 6) & 1; |
1246 |
} |
1247 |
|
1248 |
void OPPROTO op_setbe_T0_cc(void) |
1249 |
{ |
1250 |
int eflags;
|
1251 |
eflags = cc_table[CC_OP].compute_all(); |
1252 |
T0 = (eflags & (CC_Z | CC_C)) != 0;
|
1253 |
} |
1254 |
|
1255 |
void OPPROTO op_sets_T0_cc(void) |
1256 |
{ |
1257 |
int eflags;
|
1258 |
eflags = cc_table[CC_OP].compute_all(); |
1259 |
T0 = (eflags >> 7) & 1; |
1260 |
} |
1261 |
|
1262 |
void OPPROTO op_setp_T0_cc(void) |
1263 |
{ |
1264 |
int eflags;
|
1265 |
eflags = cc_table[CC_OP].compute_all(); |
1266 |
T0 = (eflags >> 2) & 1; |
1267 |
} |
1268 |
|
1269 |
void OPPROTO op_setl_T0_cc(void) |
1270 |
{ |
1271 |
int eflags;
|
1272 |
eflags = cc_table[CC_OP].compute_all(); |
1273 |
T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1; |
1274 |
} |
1275 |
|
1276 |
void OPPROTO op_setle_T0_cc(void) |
1277 |
{ |
1278 |
int eflags;
|
1279 |
eflags = cc_table[CC_OP].compute_all(); |
1280 |
T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0; |
1281 |
} |
1282 |
|
1283 |
void OPPROTO op_xor_T0_1(void) |
1284 |
{ |
1285 |
T0 ^= 1;
|
1286 |
} |
1287 |
|
1288 |
void OPPROTO op_set_cc_op(void) |
1289 |
{ |
1290 |
CC_OP = PARAM1; |
1291 |
} |
1292 |
|
1293 |
#define FL_UPDATE_MASK32 (TF_MASK | AC_MASK | ID_MASK)
|
1294 |
#define FL_UPDATE_MASK16 (TF_MASK)
|
1295 |
|
1296 |
void OPPROTO op_movl_eflags_T0(void) |
1297 |
{ |
1298 |
int eflags;
|
1299 |
eflags = T0; |
1300 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1301 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1302 |
/* we also update some system flags as in user mode */
|
1303 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK32) | (eflags & FL_UPDATE_MASK32); |
1304 |
} |
1305 |
|
1306 |
void OPPROTO op_movw_eflags_T0(void) |
1307 |
{ |
1308 |
int eflags;
|
1309 |
eflags = T0; |
1310 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1311 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1312 |
/* we also update some system flags as in user mode */
|
1313 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK16) | (eflags & FL_UPDATE_MASK16); |
1314 |
} |
1315 |
|
1316 |
#if 0
|
1317 |
/* vm86plus version */
|
1318 |
void OPPROTO op_movw_eflags_T0_vm(void)
|
1319 |
{
|
1320 |
int eflags;
|
1321 |
eflags = T0;
|
1322 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1323 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1324 |
/* we also update some system flags as in user mode */
|
1325 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
|
1326 |
(eflags & FL_UPDATE_MASK16);
|
1327 |
if (eflags & IF_MASK) {
|
1328 |
env->eflags |= VIF_MASK;
|
1329 |
if (env->eflags & VIP_MASK) {
|
1330 |
EIP = PARAM1;
|
1331 |
raise_exception(EXCP0D_GPF);
|
1332 |
}
|
1333 |
}
|
1334 |
FORCE_RET();
|
1335 |
}
|
1336 |
|
1337 |
void OPPROTO op_movl_eflags_T0_vm(void)
|
1338 |
{
|
1339 |
int eflags;
|
1340 |
eflags = T0;
|
1341 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1342 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1343 |
/* we also update some system flags as in user mode */
|
1344 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
|
1345 |
(eflags & FL_UPDATE_MASK32);
|
1346 |
if (eflags & IF_MASK) {
|
1347 |
env->eflags |= VIF_MASK;
|
1348 |
if (env->eflags & VIP_MASK) {
|
1349 |
EIP = PARAM1;
|
1350 |
raise_exception(EXCP0D_GPF);
|
1351 |
}
|
1352 |
}
|
1353 |
FORCE_RET();
|
1354 |
}
|
1355 |
#endif
|
1356 |
|
1357 |
/* XXX: compute only O flag */
|
1358 |
void OPPROTO op_movb_eflags_T0(void) |
1359 |
{ |
1360 |
int of;
|
1361 |
of = cc_table[CC_OP].compute_all() & CC_O; |
1362 |
CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of; |
1363 |
} |
1364 |
|
1365 |
void OPPROTO op_movl_T0_eflags(void) |
1366 |
{ |
1367 |
int eflags;
|
1368 |
eflags = cc_table[CC_OP].compute_all(); |
1369 |
eflags |= (DF & DF_MASK); |
1370 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK); |
1371 |
T0 = eflags; |
1372 |
} |
1373 |
|
1374 |
/* vm86plus version */
|
1375 |
#if 0
|
1376 |
void OPPROTO op_movl_T0_eflags_vm(void)
|
1377 |
{
|
1378 |
int eflags;
|
1379 |
eflags = cc_table[CC_OP].compute_all();
|
1380 |
eflags |= (DF & DF_MASK);
|
1381 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
|
1382 |
if (env->eflags & VIF_MASK)
|
1383 |
eflags |= IF_MASK;
|
1384 |
T0 = eflags;
|
1385 |
}
|
1386 |
#endif
|
1387 |
|
1388 |
void OPPROTO op_cld(void) |
1389 |
{ |
1390 |
DF = 1;
|
1391 |
} |
1392 |
|
1393 |
void OPPROTO op_std(void) |
1394 |
{ |
1395 |
DF = -1;
|
1396 |
} |
1397 |
|
1398 |
void OPPROTO op_clc(void) |
1399 |
{ |
1400 |
int eflags;
|
1401 |
eflags = cc_table[CC_OP].compute_all(); |
1402 |
eflags &= ~CC_C; |
1403 |
CC_SRC = eflags; |
1404 |
} |
1405 |
|
1406 |
void OPPROTO op_stc(void) |
1407 |
{ |
1408 |
int eflags;
|
1409 |
eflags = cc_table[CC_OP].compute_all(); |
1410 |
eflags |= CC_C; |
1411 |
CC_SRC = eflags; |
1412 |
} |
1413 |
|
1414 |
void OPPROTO op_cmc(void) |
1415 |
{ |
1416 |
int eflags;
|
1417 |
eflags = cc_table[CC_OP].compute_all(); |
1418 |
eflags ^= CC_C; |
1419 |
CC_SRC = eflags; |
1420 |
} |
1421 |
|
1422 |
void OPPROTO op_salc(void) |
1423 |
{ |
1424 |
int cf;
|
1425 |
cf = cc_table[CC_OP].compute_c(); |
1426 |
EAX = (EAX & ~0xff) | ((-cf) & 0xff); |
1427 |
} |
1428 |
|
1429 |
static int compute_all_eflags(void) |
1430 |
{ |
1431 |
return CC_SRC;
|
1432 |
} |
1433 |
|
1434 |
static int compute_c_eflags(void) |
1435 |
{ |
1436 |
return CC_SRC & CC_C;
|
1437 |
} |
1438 |
|
1439 |
static int compute_c_mul(void) |
1440 |
{ |
1441 |
int cf;
|
1442 |
cf = (CC_SRC != 0);
|
1443 |
return cf;
|
1444 |
} |
1445 |
|
1446 |
static int compute_all_mul(void) |
1447 |
{ |
1448 |
int cf, pf, af, zf, sf, of;
|
1449 |
cf = (CC_SRC != 0);
|
1450 |
pf = 0; /* undefined */ |
1451 |
af = 0; /* undefined */ |
1452 |
zf = 0; /* undefined */ |
1453 |
sf = 0; /* undefined */ |
1454 |
of = cf << 11;
|
1455 |
return cf | pf | af | zf | sf | of;
|
1456 |
} |
1457 |
|
1458 |
CCTable cc_table[CC_OP_NB] = { |
1459 |
[CC_OP_DYNAMIC] = { /* should never happen */ },
|
1460 |
|
1461 |
[CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags }, |
1462 |
|
1463 |
[CC_OP_MUL] = { compute_all_mul, compute_c_mul }, |
1464 |
|
1465 |
[CC_OP_ADDB] = { compute_all_addb, compute_c_addb }, |
1466 |
[CC_OP_ADDW] = { compute_all_addw, compute_c_addw }, |
1467 |
[CC_OP_ADDL] = { compute_all_addl, compute_c_addl }, |
1468 |
|
1469 |
[CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb }, |
1470 |
[CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw }, |
1471 |
[CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl }, |
1472 |
|
1473 |
[CC_OP_SUBB] = { compute_all_subb, compute_c_subb }, |
1474 |
[CC_OP_SUBW] = { compute_all_subw, compute_c_subw }, |
1475 |
[CC_OP_SUBL] = { compute_all_subl, compute_c_subl }, |
1476 |
|
1477 |
[CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb }, |
1478 |
[CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw }, |
1479 |
[CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl }, |
1480 |
|
1481 |
[CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb }, |
1482 |
[CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw }, |
1483 |
[CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl }, |
1484 |
|
1485 |
[CC_OP_INCB] = { compute_all_incb, compute_c_incl }, |
1486 |
[CC_OP_INCW] = { compute_all_incw, compute_c_incl }, |
1487 |
[CC_OP_INCL] = { compute_all_incl, compute_c_incl }, |
1488 |
|
1489 |
[CC_OP_DECB] = { compute_all_decb, compute_c_incl }, |
1490 |
[CC_OP_DECW] = { compute_all_decw, compute_c_incl }, |
1491 |
[CC_OP_DECL] = { compute_all_decl, compute_c_incl }, |
1492 |
|
1493 |
[CC_OP_SHLB] = { compute_all_shlb, compute_c_shll }, |
1494 |
[CC_OP_SHLW] = { compute_all_shlw, compute_c_shll }, |
1495 |
[CC_OP_SHLL] = { compute_all_shll, compute_c_shll }, |
1496 |
|
1497 |
[CC_OP_SARB] = { compute_all_sarb, compute_c_shll }, |
1498 |
[CC_OP_SARW] = { compute_all_sarw, compute_c_shll }, |
1499 |
[CC_OP_SARL] = { compute_all_sarl, compute_c_shll }, |
1500 |
}; |
1501 |
|
1502 |
/* floating point support. Some of the code for complicated x87
|
1503 |
functions comes from the LGPL'ed x86 emulator found in the Willows
|
1504 |
TWIN windows emulator. */
|
1505 |
|
1506 |
#ifdef USE_X86LDOUBLE
|
1507 |
/* use long double functions */
|
1508 |
#define lrint lrintl
|
1509 |
#define llrint llrintl
|
1510 |
#define fabs fabsl
|
1511 |
#define sin sinl
|
1512 |
#define cos cosl
|
1513 |
#define sqrt sqrtl
|
1514 |
#define pow powl
|
1515 |
#define log logl
|
1516 |
#define tan tanl
|
1517 |
#define atan2 atan2l
|
1518 |
#define floor floorl
|
1519 |
#define ceil ceill
|
1520 |
#define rint rintl
|
1521 |
#endif
|
1522 |
|
1523 |
extern int lrint(CPU86_LDouble x); |
1524 |
extern int64_t llrint(CPU86_LDouble x);
|
1525 |
extern CPU86_LDouble fabs(CPU86_LDouble x);
|
1526 |
extern CPU86_LDouble sin(CPU86_LDouble x);
|
1527 |
extern CPU86_LDouble cos(CPU86_LDouble x);
|
1528 |
extern CPU86_LDouble sqrt(CPU86_LDouble x);
|
1529 |
extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
|
1530 |
extern CPU86_LDouble log(CPU86_LDouble x);
|
1531 |
extern CPU86_LDouble tan(CPU86_LDouble x);
|
1532 |
extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
|
1533 |
extern CPU86_LDouble floor(CPU86_LDouble x);
|
1534 |
extern CPU86_LDouble ceil(CPU86_LDouble x);
|
1535 |
extern CPU86_LDouble rint(CPU86_LDouble x);
|
1536 |
|
1537 |
#if defined(__powerpc__)
|
1538 |
extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
|
1539 |
|
1540 |
/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
1541 |
double qemu_rint(double x) |
1542 |
{ |
1543 |
double y = 4503599627370496.0; |
1544 |
if (fabs(x) >= y)
|
1545 |
return x;
|
1546 |
if (x < 0) |
1547 |
y = -y; |
1548 |
y = (x + y) - y; |
1549 |
if (y == 0.0) |
1550 |
y = copysign(y, x); |
1551 |
return y;
|
1552 |
} |
1553 |
|
1554 |
#define rint qemu_rint
|
1555 |
#endif
|
1556 |
|
1557 |
#define RC_MASK 0xc00 |
1558 |
#define RC_NEAR 0x000 |
1559 |
#define RC_DOWN 0x400 |
1560 |
#define RC_UP 0x800 |
1561 |
#define RC_CHOP 0xc00 |
1562 |
|
1563 |
#define MAXTAN 9223372036854775808.0 |
1564 |
|
1565 |
#ifdef USE_X86LDOUBLE
|
1566 |
|
1567 |
/* only for x86 */
|
1568 |
typedef union { |
1569 |
long double d; |
1570 |
struct {
|
1571 |
unsigned long long lower; |
1572 |
unsigned short upper; |
1573 |
} l; |
1574 |
} CPU86_LDoubleU; |
1575 |
|
1576 |
/* the following deal with x86 long double-precision numbers */
|
1577 |
#define MAXEXPD 0x7fff |
1578 |
#define EXPBIAS 16383 |
1579 |
#define EXPD(fp) (fp.l.upper & 0x7fff) |
1580 |
#define SIGND(fp) ((fp.l.upper) & 0x8000) |
1581 |
#define MANTD(fp) (fp.l.lower)
|
1582 |
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS |
1583 |
|
1584 |
#else
|
1585 |
|
1586 |
typedef union { |
1587 |
double d;
|
1588 |
#ifndef WORDS_BIGENDIAN
|
1589 |
struct {
|
1590 |
unsigned long lower; |
1591 |
long upper;
|
1592 |
} l; |
1593 |
#else
|
1594 |
struct {
|
1595 |
long upper;
|
1596 |
unsigned long lower; |
1597 |
} l; |
1598 |
#endif
|
1599 |
long long ll; |
1600 |
} CPU86_LDoubleU; |
1601 |
|
1602 |
/* the following deal with IEEE double-precision numbers */
|
1603 |
#define MAXEXPD 0x7ff |
1604 |
#define EXPBIAS 1023 |
1605 |
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) |
1606 |
#define SIGND(fp) ((fp.l.upper) & 0x80000000) |
1607 |
#define MANTD(fp) (fp.ll & ((1LL << 52) - 1)) |
1608 |
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20) |
1609 |
#endif
|
1610 |
|
1611 |
/* fp load FT0 */
|
1612 |
|
1613 |
void OPPROTO op_flds_FT0_A0(void) |
1614 |
{ |
1615 |
#ifdef USE_FP_CONVERT
|
1616 |
FP_CONVERT.i32 = ldl((void *)A0);
|
1617 |
FT0 = FP_CONVERT.f; |
1618 |
#else
|
1619 |
FT0 = ldfl((void *)A0);
|
1620 |
#endif
|
1621 |
} |
1622 |
|
1623 |
void OPPROTO op_fldl_FT0_A0(void) |
1624 |
{ |
1625 |
#ifdef USE_FP_CONVERT
|
1626 |
FP_CONVERT.i64 = ldq((void *)A0);
|
1627 |
FT0 = FP_CONVERT.d; |
1628 |
#else
|
1629 |
FT0 = ldfq((void *)A0);
|
1630 |
#endif
|
1631 |
} |
1632 |
|
1633 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1634 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1635 |
|
1636 |
void helper_fild_FT0_A0(void) |
1637 |
{ |
1638 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1639 |
} |
1640 |
|
1641 |
void helper_fildl_FT0_A0(void) |
1642 |
{ |
1643 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1644 |
} |
1645 |
|
1646 |
void helper_fildll_FT0_A0(void) |
1647 |
{ |
1648 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1649 |
} |
1650 |
|
1651 |
void OPPROTO op_fild_FT0_A0(void) |
1652 |
{ |
1653 |
helper_fild_FT0_A0(); |
1654 |
} |
1655 |
|
1656 |
void OPPROTO op_fildl_FT0_A0(void) |
1657 |
{ |
1658 |
helper_fildl_FT0_A0(); |
1659 |
} |
1660 |
|
1661 |
void OPPROTO op_fildll_FT0_A0(void) |
1662 |
{ |
1663 |
helper_fildll_FT0_A0(); |
1664 |
} |
1665 |
|
1666 |
#else
|
1667 |
|
1668 |
void OPPROTO op_fild_FT0_A0(void) |
1669 |
{ |
1670 |
#ifdef USE_FP_CONVERT
|
1671 |
FP_CONVERT.i32 = ldsw((void *)A0);
|
1672 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1673 |
#else
|
1674 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1675 |
#endif
|
1676 |
} |
1677 |
|
1678 |
void OPPROTO op_fildl_FT0_A0(void) |
1679 |
{ |
1680 |
#ifdef USE_FP_CONVERT
|
1681 |
FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
|
1682 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1683 |
#else
|
1684 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1685 |
#endif
|
1686 |
} |
1687 |
|
1688 |
void OPPROTO op_fildll_FT0_A0(void) |
1689 |
{ |
1690 |
#ifdef USE_FP_CONVERT
|
1691 |
FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
|
1692 |
FT0 = (CPU86_LDouble)FP_CONVERT.i64; |
1693 |
#else
|
1694 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1695 |
#endif
|
1696 |
} |
1697 |
#endif
|
1698 |
|
1699 |
/* fp load ST0 */
|
1700 |
|
1701 |
void OPPROTO op_flds_ST0_A0(void) |
1702 |
{ |
1703 |
#ifdef USE_FP_CONVERT
|
1704 |
FP_CONVERT.i32 = ldl((void *)A0);
|
1705 |
ST0 = FP_CONVERT.f; |
1706 |
#else
|
1707 |
ST0 = ldfl((void *)A0);
|
1708 |
#endif
|
1709 |
} |
1710 |
|
1711 |
void OPPROTO op_fldl_ST0_A0(void) |
1712 |
{ |
1713 |
#ifdef USE_FP_CONVERT
|
1714 |
FP_CONVERT.i64 = ldq((void *)A0);
|
1715 |
ST0 = FP_CONVERT.d; |
1716 |
#else
|
1717 |
ST0 = ldfq((void *)A0);
|
1718 |
#endif
|
1719 |
} |
1720 |
|
1721 |
#ifdef USE_X86LDOUBLE
|
1722 |
void OPPROTO op_fldt_ST0_A0(void) |
1723 |
{ |
1724 |
ST0 = *(long double *)A0; |
1725 |
} |
1726 |
#else
|
1727 |
void helper_fldt_ST0_A0(void) |
1728 |
{ |
1729 |
CPU86_LDoubleU temp; |
1730 |
int upper, e;
|
1731 |
/* mantissa */
|
1732 |
upper = lduw((uint8_t *)A0 + 8);
|
1733 |
/* XXX: handle overflow ? */
|
1734 |
e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */ |
1735 |
e |= (upper >> 4) & 0x800; /* sign */ |
1736 |
temp.ll = ((ldq((void *)A0) >> 11) & ((1LL << 52) - 1)) | ((uint64_t)e << 52); |
1737 |
ST0 = temp.d; |
1738 |
} |
1739 |
|
1740 |
void OPPROTO op_fldt_ST0_A0(void) |
1741 |
{ |
1742 |
helper_fldt_ST0_A0(); |
1743 |
} |
1744 |
#endif
|
1745 |
|
1746 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1747 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1748 |
|
1749 |
void helper_fild_ST0_A0(void) |
1750 |
{ |
1751 |
ST0 = (CPU86_LDouble)ldsw((void *)A0);
|
1752 |
} |
1753 |
|
1754 |
void helper_fildl_ST0_A0(void) |
1755 |
{ |
1756 |
ST0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1757 |
} |
1758 |
|
1759 |
void helper_fildll_ST0_A0(void) |
1760 |
{ |
1761 |
ST0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1762 |
} |
1763 |
|
1764 |
void OPPROTO op_fild_ST0_A0(void) |
1765 |
{ |
1766 |
helper_fild_ST0_A0(); |
1767 |
} |
1768 |
|
1769 |
void OPPROTO op_fildl_ST0_A0(void) |
1770 |
{ |
1771 |
helper_fildl_ST0_A0(); |
1772 |
} |
1773 |
|
1774 |
void OPPROTO op_fildll_ST0_A0(void) |
1775 |
{ |
1776 |
helper_fildll_ST0_A0(); |
1777 |
} |
1778 |
|
1779 |
#else
|
1780 |
|
1781 |
void OPPROTO op_fild_ST0_A0(void) |
1782 |
{ |
1783 |
#ifdef USE_FP_CONVERT
|
1784 |
FP_CONVERT.i32 = ldsw((void *)A0);
|
1785 |
ST0 = (CPU86_LDouble)FP_CONVERT.i32; |
1786 |
#else
|
1787 |
ST0 = (CPU86_LDouble)ldsw((void *)A0);
|
1788 |
#endif
|
1789 |
} |
1790 |
|
1791 |
void OPPROTO op_fildl_ST0_A0(void) |
1792 |
{ |
1793 |
#ifdef USE_FP_CONVERT
|
1794 |
FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
|
1795 |
ST0 = (CPU86_LDouble)FP_CONVERT.i32; |
1796 |
#else
|
1797 |
ST0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1798 |
#endif
|
1799 |
} |
1800 |
|
1801 |
void OPPROTO op_fildll_ST0_A0(void) |
1802 |
{ |
1803 |
#ifdef USE_FP_CONVERT
|
1804 |
FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
|
1805 |
ST0 = (CPU86_LDouble)FP_CONVERT.i64; |
1806 |
#else
|
1807 |
ST0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1808 |
#endif
|
1809 |
} |
1810 |
|
1811 |
#endif
|
1812 |
|
1813 |
/* fp store */
|
1814 |
|
1815 |
void OPPROTO op_fsts_ST0_A0(void) |
1816 |
{ |
1817 |
#ifdef USE_FP_CONVERT
|
1818 |
FP_CONVERT.d = ST0; |
1819 |
stfl((void *)A0, FP_CONVERT.f);
|
1820 |
#else
|
1821 |
stfl((void *)A0, (float)ST0); |
1822 |
#endif
|
1823 |
} |
1824 |
|
1825 |
void OPPROTO op_fstl_ST0_A0(void) |
1826 |
{ |
1827 |
stfq((void *)A0, (double)ST0); |
1828 |
} |
1829 |
|
1830 |
#ifdef USE_X86LDOUBLE
|
1831 |
void OPPROTO op_fstt_ST0_A0(void) |
1832 |
{ |
1833 |
*(long double *)A0 = ST0; |
1834 |
} |
1835 |
#else
|
1836 |
void helper_fstt_ST0_A0(void) |
1837 |
{ |
1838 |
CPU86_LDoubleU temp; |
1839 |
int e;
|
1840 |
temp.d = ST0; |
1841 |
/* mantissa */
|
1842 |
stq((void *)A0, (MANTD(temp) << 11) | (1LL << 63)); |
1843 |
/* exponent + sign */
|
1844 |
e = EXPD(temp) - EXPBIAS + 16383;
|
1845 |
e |= SIGND(temp) >> 16;
|
1846 |
stw((uint8_t *)A0 + 8, e);
|
1847 |
} |
1848 |
|
1849 |
void OPPROTO op_fstt_ST0_A0(void) |
1850 |
{ |
1851 |
helper_fstt_ST0_A0(); |
1852 |
} |
1853 |
#endif
|
1854 |
|
1855 |
void OPPROTO op_fist_ST0_A0(void) |
1856 |
{ |
1857 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1858 |
register CPU86_LDouble d asm("o0"); |
1859 |
#else
|
1860 |
CPU86_LDouble d; |
1861 |
#endif
|
1862 |
int val;
|
1863 |
|
1864 |
d = ST0; |
1865 |
val = lrint(d); |
1866 |
stw((void *)A0, val);
|
1867 |
} |
1868 |
|
1869 |
void OPPROTO op_fistl_ST0_A0(void) |
1870 |
{ |
1871 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1872 |
register CPU86_LDouble d asm("o0"); |
1873 |
#else
|
1874 |
CPU86_LDouble d; |
1875 |
#endif
|
1876 |
int val;
|
1877 |
|
1878 |
d = ST0; |
1879 |
val = lrint(d); |
1880 |
stl((void *)A0, val);
|
1881 |
} |
1882 |
|
1883 |
void OPPROTO op_fistll_ST0_A0(void) |
1884 |
{ |
1885 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1886 |
register CPU86_LDouble d asm("o0"); |
1887 |
#else
|
1888 |
CPU86_LDouble d; |
1889 |
#endif
|
1890 |
int64_t val; |
1891 |
|
1892 |
d = ST0; |
1893 |
val = llrint(d); |
1894 |
stq((void *)A0, val);
|
1895 |
} |
1896 |
|
1897 |
/* BCD ops */
|
1898 |
|
1899 |
#define MUL10(iv) ( iv + iv + (iv << 3) ) |
1900 |
|
1901 |
void helper_fbld_ST0_A0(void) |
1902 |
{ |
1903 |
uint8_t *seg; |
1904 |
CPU86_LDouble fpsrcop; |
1905 |
int m32i;
|
1906 |
unsigned int v; |
1907 |
|
1908 |
/* in this code, seg/m32i will be used as temporary ptr/int */
|
1909 |
seg = (uint8_t *)A0 + 8;
|
1910 |
v = ldub(seg--); |
1911 |
/* XXX: raise exception */
|
1912 |
if (v != 0) |
1913 |
return;
|
1914 |
v = ldub(seg--); |
1915 |
/* XXX: raise exception */
|
1916 |
if ((v & 0xf0) != 0) |
1917 |
return;
|
1918 |
m32i = v; /* <-- d14 */
|
1919 |
v = ldub(seg--); |
1920 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d13 */ |
1921 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d12 */ |
1922 |
v = ldub(seg--); |
1923 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d11 */ |
1924 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d10 */ |
1925 |
v = ldub(seg--); |
1926 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d9 */ |
1927 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d8 */ |
1928 |
fpsrcop = ((CPU86_LDouble)m32i) * 100000000.0; |
1929 |
|
1930 |
v = ldub(seg--); |
1931 |
m32i = (v >> 4); /* <-- d7 */ |
1932 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d6 */ |
1933 |
v = ldub(seg--); |
1934 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d5 */ |
1935 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d4 */ |
1936 |
v = ldub(seg--); |
1937 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d3 */ |
1938 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d2 */ |
1939 |
v = ldub(seg); |
1940 |
m32i = MUL10(m32i) + (v >> 4); /* <-- val * 10 + d1 */ |
1941 |
m32i = MUL10(m32i) + (v & 0xf); /* <-- val * 10 + d0 */ |
1942 |
fpsrcop += ((CPU86_LDouble)m32i); |
1943 |
if ( ldub(seg+9) & 0x80 ) |
1944 |
fpsrcop = -fpsrcop; |
1945 |
ST0 = fpsrcop; |
1946 |
} |
1947 |
|
1948 |
void OPPROTO op_fbld_ST0_A0(void) |
1949 |
{ |
1950 |
helper_fbld_ST0_A0(); |
1951 |
} |
1952 |
|
1953 |
void helper_fbst_ST0_A0(void) |
1954 |
{ |
1955 |
CPU86_LDouble fptemp; |
1956 |
CPU86_LDouble fpsrcop; |
1957 |
int v;
|
1958 |
uint8_t *mem_ref, *mem_end; |
1959 |
|
1960 |
fpsrcop = rint(ST0); |
1961 |
mem_ref = (uint8_t *)A0; |
1962 |
mem_end = mem_ref + 8;
|
1963 |
if ( fpsrcop < 0.0 ) { |
1964 |
stw(mem_end, 0x8000);
|
1965 |
fpsrcop = -fpsrcop; |
1966 |
} else {
|
1967 |
stw(mem_end, 0x0000);
|
1968 |
} |
1969 |
while (mem_ref < mem_end) {
|
1970 |
if (fpsrcop == 0.0) |
1971 |
break;
|
1972 |
fptemp = floor(fpsrcop/10.0); |
1973 |
v = ((int)(fpsrcop - fptemp*10.0)); |
1974 |
if (fptemp == 0.0) { |
1975 |
stb(mem_ref++, v); |
1976 |
break;
|
1977 |
} |
1978 |
fpsrcop = fptemp; |
1979 |
fptemp = floor(fpsrcop/10.0); |
1980 |
v |= (((int)(fpsrcop - fptemp*10.0)) << 4); |
1981 |
stb(mem_ref++, v); |
1982 |
fpsrcop = fptemp; |
1983 |
} |
1984 |
while (mem_ref < mem_end) {
|
1985 |
stb(mem_ref++, 0);
|
1986 |
} |
1987 |
} |
1988 |
|
1989 |
void OPPROTO op_fbst_ST0_A0(void) |
1990 |
{ |
1991 |
helper_fbst_ST0_A0(); |
1992 |
} |
1993 |
|
1994 |
/* FPU move */
|
1995 |
|
1996 |
static inline void fpush(void) |
1997 |
{ |
1998 |
env->fpstt = (env->fpstt - 1) & 7; |
1999 |
env->fptags[env->fpstt] = 0; /* validate stack entry */ |
2000 |
} |
2001 |
|
2002 |
static inline void fpop(void) |
2003 |
{ |
2004 |
env->fptags[env->fpstt] = 1; /* invvalidate stack entry */ |
2005 |
env->fpstt = (env->fpstt + 1) & 7; |
2006 |
} |
2007 |
|
2008 |
void OPPROTO op_fpush(void) |
2009 |
{ |
2010 |
fpush(); |
2011 |
} |
2012 |
|
2013 |
void OPPROTO op_fpop(void) |
2014 |
{ |
2015 |
fpop(); |
2016 |
} |
2017 |
|
2018 |
void OPPROTO op_fdecstp(void) |
2019 |
{ |
2020 |
env->fpstt = (env->fpstt - 1) & 7; |
2021 |
env->fpus &= (~0x4700);
|
2022 |
} |
2023 |
|
2024 |
void OPPROTO op_fincstp(void) |
2025 |
{ |
2026 |
env->fpstt = (env->fpstt + 1) & 7; |
2027 |
env->fpus &= (~0x4700);
|
2028 |
} |
2029 |
|
2030 |
void OPPROTO op_fmov_ST0_FT0(void) |
2031 |
{ |
2032 |
ST0 = FT0; |
2033 |
} |
2034 |
|
2035 |
void OPPROTO op_fmov_FT0_STN(void) |
2036 |
{ |
2037 |
FT0 = ST(PARAM1); |
2038 |
} |
2039 |
|
2040 |
void OPPROTO op_fmov_ST0_STN(void) |
2041 |
{ |
2042 |
ST0 = ST(PARAM1); |
2043 |
} |
2044 |
|
2045 |
void OPPROTO op_fmov_STN_ST0(void) |
2046 |
{ |
2047 |
ST(PARAM1) = ST0; |
2048 |
} |
2049 |
|
2050 |
void OPPROTO op_fxchg_ST0_STN(void) |
2051 |
{ |
2052 |
CPU86_LDouble tmp; |
2053 |
tmp = ST(PARAM1); |
2054 |
ST(PARAM1) = ST0; |
2055 |
ST0 = tmp; |
2056 |
} |
2057 |
|
2058 |
/* FPU operations */
|
2059 |
|
2060 |
/* XXX: handle nans */
|
2061 |
void OPPROTO op_fcom_ST0_FT0(void) |
2062 |
{ |
2063 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
2064 |
if (ST0 < FT0)
|
2065 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
2066 |
else if (ST0 == FT0) |
2067 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
2068 |
FORCE_RET(); |
2069 |
} |
2070 |
|
2071 |
/* XXX: handle nans */
|
2072 |
void OPPROTO op_fucom_ST0_FT0(void) |
2073 |
{ |
2074 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
2075 |
if (ST0 < FT0)
|
2076 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
2077 |
else if (ST0 == FT0) |
2078 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
2079 |
FORCE_RET(); |
2080 |
} |
2081 |
|
2082 |
void OPPROTO op_fadd_ST0_FT0(void) |
2083 |
{ |
2084 |
ST0 += FT0; |
2085 |
} |
2086 |
|
2087 |
void OPPROTO op_fmul_ST0_FT0(void) |
2088 |
{ |
2089 |
ST0 *= FT0; |
2090 |
} |
2091 |
|
2092 |
void OPPROTO op_fsub_ST0_FT0(void) |
2093 |
{ |
2094 |
ST0 -= FT0; |
2095 |
} |
2096 |
|
2097 |
void OPPROTO op_fsubr_ST0_FT0(void) |
2098 |
{ |
2099 |
ST0 = FT0 - ST0; |
2100 |
} |
2101 |
|
2102 |
void OPPROTO op_fdiv_ST0_FT0(void) |
2103 |
{ |
2104 |
ST0 /= FT0; |
2105 |
} |
2106 |
|
2107 |
void OPPROTO op_fdivr_ST0_FT0(void) |
2108 |
{ |
2109 |
ST0 = FT0 / ST0; |
2110 |
} |
2111 |
|
2112 |
/* fp operations between STN and ST0 */
|
2113 |
|
2114 |
void OPPROTO op_fadd_STN_ST0(void) |
2115 |
{ |
2116 |
ST(PARAM1) += ST0; |
2117 |
} |
2118 |
|
2119 |
void OPPROTO op_fmul_STN_ST0(void) |
2120 |
{ |
2121 |
ST(PARAM1) *= ST0; |
2122 |
} |
2123 |
|
2124 |
void OPPROTO op_fsub_STN_ST0(void) |
2125 |
{ |
2126 |
ST(PARAM1) -= ST0; |
2127 |
} |
2128 |
|
2129 |
void OPPROTO op_fsubr_STN_ST0(void) |
2130 |
{ |
2131 |
CPU86_LDouble *p; |
2132 |
p = &ST(PARAM1); |
2133 |
*p = ST0 - *p; |
2134 |
} |
2135 |
|
2136 |
void OPPROTO op_fdiv_STN_ST0(void) |
2137 |
{ |
2138 |
ST(PARAM1) /= ST0; |
2139 |
} |
2140 |
|
2141 |
void OPPROTO op_fdivr_STN_ST0(void) |
2142 |
{ |
2143 |
CPU86_LDouble *p; |
2144 |
p = &ST(PARAM1); |
2145 |
*p = ST0 / *p; |
2146 |
} |
2147 |
|
2148 |
/* misc FPU operations */
|
2149 |
void OPPROTO op_fchs_ST0(void) |
2150 |
{ |
2151 |
ST0 = -ST0; |
2152 |
} |
2153 |
|
2154 |
void OPPROTO op_fabs_ST0(void) |
2155 |
{ |
2156 |
ST0 = fabs(ST0); |
2157 |
} |
2158 |
|
2159 |
void helper_fxam_ST0(void) |
2160 |
{ |
2161 |
CPU86_LDoubleU temp; |
2162 |
int expdif;
|
2163 |
|
2164 |
temp.d = ST0; |
2165 |
|
2166 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2167 |
if (SIGND(temp))
|
2168 |
env->fpus |= 0x200; /* C1 <-- 1 */ |
2169 |
|
2170 |
expdif = EXPD(temp); |
2171 |
if (expdif == MAXEXPD) {
|
2172 |
if (MANTD(temp) == 0) |
2173 |
env->fpus |= 0x500 /*Infinity*/; |
2174 |
else
|
2175 |
env->fpus |= 0x100 /*NaN*/; |
2176 |
} else if (expdif == 0) { |
2177 |
if (MANTD(temp) == 0) |
2178 |
env->fpus |= 0x4000 /*Zero*/; |
2179 |
else
|
2180 |
env->fpus |= 0x4400 /*Denormal*/; |
2181 |
} else {
|
2182 |
env->fpus |= 0x400;
|
2183 |
} |
2184 |
} |
2185 |
|
2186 |
void OPPROTO op_fxam_ST0(void) |
2187 |
{ |
2188 |
helper_fxam_ST0(); |
2189 |
} |
2190 |
|
2191 |
void OPPROTO op_fld1_ST0(void) |
2192 |
{ |
2193 |
ST0 = *(CPU86_LDouble *)&f15rk[1];
|
2194 |
} |
2195 |
|
2196 |
void OPPROTO op_fldl2t_ST0(void) |
2197 |
{ |
2198 |
ST0 = *(CPU86_LDouble *)&f15rk[6];
|
2199 |
} |
2200 |
|
2201 |
void OPPROTO op_fldl2e_ST0(void) |
2202 |
{ |
2203 |
ST0 = *(CPU86_LDouble *)&f15rk[5];
|
2204 |
} |
2205 |
|
2206 |
void OPPROTO op_fldpi_ST0(void) |
2207 |
{ |
2208 |
ST0 = *(CPU86_LDouble *)&f15rk[2];
|
2209 |
} |
2210 |
|
2211 |
void OPPROTO op_fldlg2_ST0(void) |
2212 |
{ |
2213 |
ST0 = *(CPU86_LDouble *)&f15rk[3];
|
2214 |
} |
2215 |
|
2216 |
void OPPROTO op_fldln2_ST0(void) |
2217 |
{ |
2218 |
ST0 = *(CPU86_LDouble *)&f15rk[4];
|
2219 |
} |
2220 |
|
2221 |
void OPPROTO op_fldz_ST0(void) |
2222 |
{ |
2223 |
ST0 = *(CPU86_LDouble *)&f15rk[0];
|
2224 |
} |
2225 |
|
2226 |
void OPPROTO op_fldz_FT0(void) |
2227 |
{ |
2228 |
ST0 = *(CPU86_LDouble *)&f15rk[0];
|
2229 |
} |
2230 |
|
2231 |
void helper_f2xm1(void) |
2232 |
{ |
2233 |
ST0 = pow(2.0,ST0) - 1.0; |
2234 |
} |
2235 |
|
2236 |
void helper_fyl2x(void) |
2237 |
{ |
2238 |
CPU86_LDouble fptemp; |
2239 |
|
2240 |
fptemp = ST0; |
2241 |
if (fptemp>0.0){ |
2242 |
fptemp = log(fptemp)/log(2.0); /* log2(ST) */ |
2243 |
ST1 *= fptemp; |
2244 |
fpop(); |
2245 |
} else {
|
2246 |
env->fpus &= (~0x4700);
|
2247 |
env->fpus |= 0x400;
|
2248 |
} |
2249 |
} |
2250 |
|
2251 |
void helper_fptan(void) |
2252 |
{ |
2253 |
CPU86_LDouble fptemp; |
2254 |
|
2255 |
fptemp = ST0; |
2256 |
if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2257 |
env->fpus |= 0x400;
|
2258 |
} else {
|
2259 |
ST0 = tan(fptemp); |
2260 |
fpush(); |
2261 |
ST0 = 1.0; |
2262 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2263 |
/* the above code is for |arg| < 2**52 only */
|
2264 |
} |
2265 |
} |
2266 |
|
2267 |
void helper_fpatan(void) |
2268 |
{ |
2269 |
CPU86_LDouble fptemp, fpsrcop; |
2270 |
|
2271 |
fpsrcop = ST1; |
2272 |
fptemp = ST0; |
2273 |
ST1 = atan2(fpsrcop,fptemp); |
2274 |
fpop(); |
2275 |
} |
2276 |
|
2277 |
void helper_fxtract(void) |
2278 |
{ |
2279 |
CPU86_LDoubleU temp; |
2280 |
unsigned int expdif; |
2281 |
|
2282 |
temp.d = ST0; |
2283 |
expdif = EXPD(temp) - EXPBIAS; |
2284 |
/*DP exponent bias*/
|
2285 |
ST0 = expdif; |
2286 |
fpush(); |
2287 |
BIASEXPONENT(temp); |
2288 |
ST0 = temp.d; |
2289 |
} |
2290 |
|
2291 |
void helper_fprem1(void) |
2292 |
{ |
2293 |
CPU86_LDouble dblq, fpsrcop, fptemp; |
2294 |
CPU86_LDoubleU fpsrcop1, fptemp1; |
2295 |
int expdif;
|
2296 |
int q;
|
2297 |
|
2298 |
fpsrcop = ST0; |
2299 |
fptemp = ST1; |
2300 |
fpsrcop1.d = fpsrcop; |
2301 |
fptemp1.d = fptemp; |
2302 |
expdif = EXPD(fpsrcop1) - EXPD(fptemp1); |
2303 |
if (expdif < 53) { |
2304 |
dblq = fpsrcop / fptemp; |
2305 |
dblq = (dblq < 0.0)? ceil(dblq): floor(dblq); |
2306 |
ST0 = fpsrcop - fptemp*dblq; |
2307 |
q = (int)dblq; /* cutting off top bits is assumed here */ |
2308 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2309 |
/* (C0,C1,C3) <-- (q2,q1,q0) */
|
2310 |
env->fpus |= (q&0x4) << 6; /* (C0) <-- q2 */ |
2311 |
env->fpus |= (q&0x2) << 8; /* (C1) <-- q1 */ |
2312 |
env->fpus |= (q&0x1) << 14; /* (C3) <-- q0 */ |
2313 |
} else {
|
2314 |
env->fpus |= 0x400; /* C2 <-- 1 */ |
2315 |
fptemp = pow(2.0, expdif-50); |
2316 |
fpsrcop = (ST0 / ST1) / fptemp; |
2317 |
/* fpsrcop = integer obtained by rounding to the nearest */
|
2318 |
fpsrcop = (fpsrcop-floor(fpsrcop) < ceil(fpsrcop)-fpsrcop)? |
2319 |
floor(fpsrcop): ceil(fpsrcop); |
2320 |
ST0 -= (ST1 * fpsrcop * fptemp); |
2321 |
} |
2322 |
} |
2323 |
|
2324 |
void helper_fprem(void) |
2325 |
{ |
2326 |
CPU86_LDouble dblq, fpsrcop, fptemp; |
2327 |
CPU86_LDoubleU fpsrcop1, fptemp1; |
2328 |
int expdif;
|
2329 |
int q;
|
2330 |
|
2331 |
fpsrcop = ST0; |
2332 |
fptemp = ST1; |
2333 |
fpsrcop1.d = fpsrcop; |
2334 |
fptemp1.d = fptemp; |
2335 |
expdif = EXPD(fpsrcop1) - EXPD(fptemp1); |
2336 |
if ( expdif < 53 ) { |
2337 |
dblq = fpsrcop / fptemp; |
2338 |
dblq = (dblq < 0.0)? ceil(dblq): floor(dblq); |
2339 |
ST0 = fpsrcop - fptemp*dblq; |
2340 |
q = (int)dblq; /* cutting off top bits is assumed here */ |
2341 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2342 |
/* (C0,C1,C3) <-- (q2,q1,q0) */
|
2343 |
env->fpus |= (q&0x4) << 6; /* (C0) <-- q2 */ |
2344 |
env->fpus |= (q&0x2) << 8; /* (C1) <-- q1 */ |
2345 |
env->fpus |= (q&0x1) << 14; /* (C3) <-- q0 */ |
2346 |
} else {
|
2347 |
env->fpus |= 0x400; /* C2 <-- 1 */ |
2348 |
fptemp = pow(2.0, expdif-50); |
2349 |
fpsrcop = (ST0 / ST1) / fptemp; |
2350 |
/* fpsrcop = integer obtained by chopping */
|
2351 |
fpsrcop = (fpsrcop < 0.0)? |
2352 |
-(floor(fabs(fpsrcop))): floor(fpsrcop); |
2353 |
ST0 -= (ST1 * fpsrcop * fptemp); |
2354 |
} |
2355 |
} |
2356 |
|
2357 |
void helper_fyl2xp1(void) |
2358 |
{ |
2359 |
CPU86_LDouble fptemp; |
2360 |
|
2361 |
fptemp = ST0; |
2362 |
if ((fptemp+1.0)>0.0) { |
2363 |
fptemp = log(fptemp+1.0) / log(2.0); /* log2(ST+1.0) */ |
2364 |
ST1 *= fptemp; |
2365 |
fpop(); |
2366 |
} else {
|
2367 |
env->fpus &= (~0x4700);
|
2368 |
env->fpus |= 0x400;
|
2369 |
} |
2370 |
} |
2371 |
|
2372 |
void helper_fsqrt(void) |
2373 |
{ |
2374 |
CPU86_LDouble fptemp; |
2375 |
|
2376 |
fptemp = ST0; |
2377 |
if (fptemp<0.0) { |
2378 |
env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */ |
2379 |
env->fpus |= 0x400;
|
2380 |
} |
2381 |
ST0 = sqrt(fptemp); |
2382 |
} |
2383 |
|
2384 |
void helper_fsincos(void) |
2385 |
{ |
2386 |
CPU86_LDouble fptemp; |
2387 |
|
2388 |
fptemp = ST0; |
2389 |
if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2390 |
env->fpus |= 0x400;
|
2391 |
} else {
|
2392 |
ST0 = sin(fptemp); |
2393 |
fpush(); |
2394 |
ST0 = cos(fptemp); |
2395 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2396 |
/* the above code is for |arg| < 2**63 only */
|
2397 |
} |
2398 |
} |
2399 |
|
2400 |
void helper_frndint(void) |
2401 |
{ |
2402 |
ST0 = rint(ST0); |
2403 |
} |
2404 |
|
2405 |
void helper_fscale(void) |
2406 |
{ |
2407 |
CPU86_LDouble fpsrcop, fptemp; |
2408 |
|
2409 |
fpsrcop = 2.0; |
2410 |
fptemp = pow(fpsrcop,ST1); |
2411 |
ST0 *= fptemp; |
2412 |
} |
2413 |
|
2414 |
void helper_fsin(void) |
2415 |
{ |
2416 |
CPU86_LDouble fptemp; |
2417 |
|
2418 |
fptemp = ST0; |
2419 |
if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2420 |
env->fpus |= 0x400;
|
2421 |
} else {
|
2422 |
ST0 = sin(fptemp); |
2423 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2424 |
/* the above code is for |arg| < 2**53 only */
|
2425 |
} |
2426 |
} |
2427 |
|
2428 |
void helper_fcos(void) |
2429 |
{ |
2430 |
CPU86_LDouble fptemp; |
2431 |
|
2432 |
fptemp = ST0; |
2433 |
if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
|
2434 |
env->fpus |= 0x400;
|
2435 |
} else {
|
2436 |
ST0 = cos(fptemp); |
2437 |
env->fpus &= (~0x400); /* C2 <-- 0 */ |
2438 |
/* the above code is for |arg5 < 2**63 only */
|
2439 |
} |
2440 |
} |
2441 |
|
2442 |
/* associated heplers to reduce generated code length and to simplify
|
2443 |
relocation (FP constants are usually stored in .rodata section) */
|
2444 |
|
2445 |
void OPPROTO op_f2xm1(void) |
2446 |
{ |
2447 |
helper_f2xm1(); |
2448 |
} |
2449 |
|
2450 |
void OPPROTO op_fyl2x(void) |
2451 |
{ |
2452 |
helper_fyl2x(); |
2453 |
} |
2454 |
|
2455 |
void OPPROTO op_fptan(void) |
2456 |
{ |
2457 |
helper_fptan(); |
2458 |
} |
2459 |
|
2460 |
void OPPROTO op_fpatan(void) |
2461 |
{ |
2462 |
helper_fpatan(); |
2463 |
} |
2464 |
|
2465 |
void OPPROTO op_fxtract(void) |
2466 |
{ |
2467 |
helper_fxtract(); |
2468 |
} |
2469 |
|
2470 |
void OPPROTO op_fprem1(void) |
2471 |
{ |
2472 |
helper_fprem1(); |
2473 |
} |
2474 |
|
2475 |
|
2476 |
void OPPROTO op_fprem(void) |
2477 |
{ |
2478 |
helper_fprem(); |
2479 |
} |
2480 |
|
2481 |
void OPPROTO op_fyl2xp1(void) |
2482 |
{ |
2483 |
helper_fyl2xp1(); |
2484 |
} |
2485 |
|
2486 |
void OPPROTO op_fsqrt(void) |
2487 |
{ |
2488 |
helper_fsqrt(); |
2489 |
} |
2490 |
|
2491 |
void OPPROTO op_fsincos(void) |
2492 |
{ |
2493 |
helper_fsincos(); |
2494 |
} |
2495 |
|
2496 |
void OPPROTO op_frndint(void) |
2497 |
{ |
2498 |
helper_frndint(); |
2499 |
} |
2500 |
|
2501 |
void OPPROTO op_fscale(void) |
2502 |
{ |
2503 |
helper_fscale(); |
2504 |
} |
2505 |
|
2506 |
void OPPROTO op_fsin(void) |
2507 |
{ |
2508 |
helper_fsin(); |
2509 |
} |
2510 |
|
2511 |
void OPPROTO op_fcos(void) |
2512 |
{ |
2513 |
helper_fcos(); |
2514 |
} |
2515 |
|
2516 |
void OPPROTO op_fnstsw_A0(void) |
2517 |
{ |
2518 |
int fpus;
|
2519 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2520 |
stw((void *)A0, fpus);
|
2521 |
} |
2522 |
|
2523 |
void OPPROTO op_fnstsw_EAX(void) |
2524 |
{ |
2525 |
int fpus;
|
2526 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2527 |
EAX = (EAX & 0xffff0000) | fpus;
|
2528 |
} |
2529 |
|
2530 |
void OPPROTO op_fnstcw_A0(void) |
2531 |
{ |
2532 |
stw((void *)A0, env->fpuc);
|
2533 |
} |
2534 |
|
2535 |
void OPPROTO op_fldcw_A0(void) |
2536 |
{ |
2537 |
int rnd_type;
|
2538 |
env->fpuc = lduw((void *)A0);
|
2539 |
/* set rounding mode */
|
2540 |
switch(env->fpuc & RC_MASK) {
|
2541 |
default:
|
2542 |
case RC_NEAR:
|
2543 |
rnd_type = FE_TONEAREST; |
2544 |
break;
|
2545 |
case RC_DOWN:
|
2546 |
rnd_type = FE_DOWNWARD; |
2547 |
break;
|
2548 |
case RC_UP:
|
2549 |
rnd_type = FE_UPWARD; |
2550 |
break;
|
2551 |
case RC_CHOP:
|
2552 |
rnd_type = FE_TOWARDZERO; |
2553 |
break;
|
2554 |
} |
2555 |
fesetround(rnd_type); |
2556 |
} |
2557 |
|
2558 |
void OPPROTO op_fclex(void) |
2559 |
{ |
2560 |
env->fpus &= 0x7f00;
|
2561 |
} |
2562 |
|
2563 |
void OPPROTO op_fninit(void) |
2564 |
{ |
2565 |
env->fpus = 0;
|
2566 |
env->fpstt = 0;
|
2567 |
env->fpuc = 0x37f;
|
2568 |
env->fptags[0] = 1; |
2569 |
env->fptags[1] = 1; |
2570 |
env->fptags[2] = 1; |
2571 |
env->fptags[3] = 1; |
2572 |
env->fptags[4] = 1; |
2573 |
env->fptags[5] = 1; |
2574 |
env->fptags[6] = 1; |
2575 |
env->fptags[7] = 1; |
2576 |
} |
2577 |
|
2578 |
/* threading support */
|
2579 |
void OPPROTO op_lock(void) |
2580 |
{ |
2581 |
cpu_lock(); |
2582 |
} |
2583 |
|
2584 |
void OPPROTO op_unlock(void) |
2585 |
{ |
2586 |
cpu_unlock(); |
2587 |
} |