root / op-i386.c @ 2c1794c4
History | View | Annotate | Download (36.5 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 |
/* n must be a constant to be efficient */
|
23 |
static inline int lshift(int x, int n) |
24 |
{ |
25 |
if (n >= 0) |
26 |
return x << n;
|
27 |
else
|
28 |
return x >> (-n);
|
29 |
} |
30 |
|
31 |
/* we define the various pieces of code used by the JIT */
|
32 |
|
33 |
#define REG EAX
|
34 |
#define REGNAME _EAX
|
35 |
#include "opreg_template.h" |
36 |
#undef REG
|
37 |
#undef REGNAME
|
38 |
|
39 |
#define REG ECX
|
40 |
#define REGNAME _ECX
|
41 |
#include "opreg_template.h" |
42 |
#undef REG
|
43 |
#undef REGNAME
|
44 |
|
45 |
#define REG EDX
|
46 |
#define REGNAME _EDX
|
47 |
#include "opreg_template.h" |
48 |
#undef REG
|
49 |
#undef REGNAME
|
50 |
|
51 |
#define REG EBX
|
52 |
#define REGNAME _EBX
|
53 |
#include "opreg_template.h" |
54 |
#undef REG
|
55 |
#undef REGNAME
|
56 |
|
57 |
#define REG ESP
|
58 |
#define REGNAME _ESP
|
59 |
#include "opreg_template.h" |
60 |
#undef REG
|
61 |
#undef REGNAME
|
62 |
|
63 |
#define REG EBP
|
64 |
#define REGNAME _EBP
|
65 |
#include "opreg_template.h" |
66 |
#undef REG
|
67 |
#undef REGNAME
|
68 |
|
69 |
#define REG ESI
|
70 |
#define REGNAME _ESI
|
71 |
#include "opreg_template.h" |
72 |
#undef REG
|
73 |
#undef REGNAME
|
74 |
|
75 |
#define REG EDI
|
76 |
#define REGNAME _EDI
|
77 |
#include "opreg_template.h" |
78 |
#undef REG
|
79 |
#undef REGNAME
|
80 |
|
81 |
/* operations with flags */
|
82 |
|
83 |
/* update flags with T0 and T1 (add/sub case) */
|
84 |
void OPPROTO op_update2_cc(void) |
85 |
{ |
86 |
CC_SRC = T1; |
87 |
CC_DST = T0; |
88 |
} |
89 |
|
90 |
/* update flags with T0 (logic operation case) */
|
91 |
void OPPROTO op_update1_cc(void) |
92 |
{ |
93 |
CC_DST = T0; |
94 |
} |
95 |
|
96 |
void OPPROTO op_update_neg_cc(void) |
97 |
{ |
98 |
CC_SRC = -T0; |
99 |
CC_DST = T0; |
100 |
} |
101 |
|
102 |
void OPPROTO op_cmpl_T0_T1_cc(void) |
103 |
{ |
104 |
CC_SRC = T1; |
105 |
CC_DST = T0 - T1; |
106 |
} |
107 |
|
108 |
void OPPROTO op_update_inc_cc(void) |
109 |
{ |
110 |
CC_SRC = cc_table[CC_OP].compute_c(); |
111 |
CC_DST = T0; |
112 |
} |
113 |
|
114 |
void OPPROTO op_testl_T0_T1_cc(void) |
115 |
{ |
116 |
CC_DST = T0 & T1; |
117 |
} |
118 |
|
119 |
/* operations without flags */
|
120 |
|
121 |
void OPPROTO op_addl_T0_T1(void) |
122 |
{ |
123 |
T0 += T1; |
124 |
} |
125 |
|
126 |
void OPPROTO op_orl_T0_T1(void) |
127 |
{ |
128 |
T0 |= T1; |
129 |
} |
130 |
|
131 |
void OPPROTO op_andl_T0_T1(void) |
132 |
{ |
133 |
T0 &= T1; |
134 |
} |
135 |
|
136 |
void OPPROTO op_subl_T0_T1(void) |
137 |
{ |
138 |
T0 -= T1; |
139 |
} |
140 |
|
141 |
void OPPROTO op_xorl_T0_T1(void) |
142 |
{ |
143 |
T0 ^= T1; |
144 |
} |
145 |
|
146 |
void OPPROTO op_negl_T0(void) |
147 |
{ |
148 |
T0 = -T0; |
149 |
} |
150 |
|
151 |
void OPPROTO op_incl_T0(void) |
152 |
{ |
153 |
T0++; |
154 |
} |
155 |
|
156 |
void OPPROTO op_decl_T0(void) |
157 |
{ |
158 |
T0--; |
159 |
} |
160 |
|
161 |
void OPPROTO op_notl_T0(void) |
162 |
{ |
163 |
T0 = ~T0; |
164 |
} |
165 |
|
166 |
void OPPROTO op_bswapl_T0(void) |
167 |
{ |
168 |
T0 = bswap32(T0); |
169 |
} |
170 |
|
171 |
/* multiply/divide */
|
172 |
void OPPROTO op_mulb_AL_T0(void) |
173 |
{ |
174 |
unsigned int res; |
175 |
res = (uint8_t)EAX * (uint8_t)T0; |
176 |
EAX = (EAX & 0xffff0000) | res;
|
177 |
CC_SRC = (res & 0xff00);
|
178 |
} |
179 |
|
180 |
void OPPROTO op_imulb_AL_T0(void) |
181 |
{ |
182 |
int res;
|
183 |
res = (int8_t)EAX * (int8_t)T0; |
184 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
185 |
CC_SRC = (res != (int8_t)res); |
186 |
} |
187 |
|
188 |
void OPPROTO op_mulw_AX_T0(void) |
189 |
{ |
190 |
unsigned int res; |
191 |
res = (uint16_t)EAX * (uint16_t)T0; |
192 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
193 |
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff); |
194 |
CC_SRC = res >> 16;
|
195 |
} |
196 |
|
197 |
void OPPROTO op_imulw_AX_T0(void) |
198 |
{ |
199 |
int res;
|
200 |
res = (int16_t)EAX * (int16_t)T0; |
201 |
EAX = (EAX & 0xffff0000) | (res & 0xffff); |
202 |
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff); |
203 |
CC_SRC = (res != (int16_t)res); |
204 |
} |
205 |
|
206 |
void OPPROTO op_mull_EAX_T0(void) |
207 |
{ |
208 |
uint64_t res; |
209 |
res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0); |
210 |
EAX = res; |
211 |
EDX = res >> 32;
|
212 |
CC_SRC = res >> 32;
|
213 |
} |
214 |
|
215 |
void OPPROTO op_imull_EAX_T0(void) |
216 |
{ |
217 |
int64_t res; |
218 |
res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0); |
219 |
EAX = res; |
220 |
EDX = res >> 32;
|
221 |
CC_SRC = (res != (int32_t)res); |
222 |
} |
223 |
|
224 |
void OPPROTO op_imulw_T0_T1(void) |
225 |
{ |
226 |
int res;
|
227 |
res = (int16_t)T0 * (int16_t)T1; |
228 |
T0 = res; |
229 |
CC_SRC = (res != (int16_t)res); |
230 |
} |
231 |
|
232 |
void OPPROTO op_imull_T0_T1(void) |
233 |
{ |
234 |
int64_t res; |
235 |
res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1); |
236 |
T0 = res; |
237 |
CC_SRC = (res != (int32_t)res); |
238 |
} |
239 |
|
240 |
/* division, flags are undefined */
|
241 |
/* XXX: add exceptions for overflow */
|
242 |
|
243 |
void OPPROTO op_divb_AL_T0(void) |
244 |
{ |
245 |
unsigned int num, den, q, r; |
246 |
|
247 |
num = (EAX & 0xffff);
|
248 |
den = (T0 & 0xff);
|
249 |
if (den == 0) { |
250 |
EIP = PARAM1; |
251 |
raise_exception(EXCP00_DIVZ); |
252 |
} |
253 |
q = (num / den) & 0xff;
|
254 |
r = (num % den) & 0xff;
|
255 |
EAX = (EAX & 0xffff0000) | (r << 8) | q; |
256 |
} |
257 |
|
258 |
void OPPROTO op_idivb_AL_T0(void) |
259 |
{ |
260 |
int num, den, q, r;
|
261 |
|
262 |
num = (int16_t)EAX; |
263 |
den = (int8_t)T0; |
264 |
if (den == 0) { |
265 |
EIP = PARAM1; |
266 |
raise_exception(EXCP00_DIVZ); |
267 |
} |
268 |
q = (num / den) & 0xff;
|
269 |
r = (num % den) & 0xff;
|
270 |
EAX = (EAX & 0xffff0000) | (r << 8) | q; |
271 |
} |
272 |
|
273 |
void OPPROTO op_divw_AX_T0(void) |
274 |
{ |
275 |
unsigned int num, den, q, r; |
276 |
|
277 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
278 |
den = (T0 & 0xffff);
|
279 |
if (den == 0) { |
280 |
EIP = PARAM1; |
281 |
raise_exception(EXCP00_DIVZ); |
282 |
} |
283 |
q = (num / den) & 0xffff;
|
284 |
r = (num % den) & 0xffff;
|
285 |
EAX = (EAX & 0xffff0000) | q;
|
286 |
EDX = (EDX & 0xffff0000) | r;
|
287 |
} |
288 |
|
289 |
void OPPROTO op_idivw_AX_T0(void) |
290 |
{ |
291 |
int num, den, q, r;
|
292 |
|
293 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
294 |
den = (int16_t)T0; |
295 |
if (den == 0) { |
296 |
EIP = PARAM1; |
297 |
raise_exception(EXCP00_DIVZ); |
298 |
} |
299 |
q = (num / den) & 0xffff;
|
300 |
r = (num % den) & 0xffff;
|
301 |
EAX = (EAX & 0xffff0000) | q;
|
302 |
EDX = (EDX & 0xffff0000) | r;
|
303 |
} |
304 |
|
305 |
void OPPROTO op_divl_EAX_T0(void) |
306 |
{ |
307 |
helper_divl_EAX_T0(PARAM1); |
308 |
} |
309 |
|
310 |
void OPPROTO op_idivl_EAX_T0(void) |
311 |
{ |
312 |
helper_idivl_EAX_T0(PARAM1); |
313 |
} |
314 |
|
315 |
/* constant load & misc op */
|
316 |
|
317 |
void OPPROTO op_movl_T0_im(void) |
318 |
{ |
319 |
T0 = PARAM1; |
320 |
} |
321 |
|
322 |
void OPPROTO op_addl_T0_im(void) |
323 |
{ |
324 |
T0 += PARAM1; |
325 |
} |
326 |
|
327 |
void OPPROTO op_andl_T0_ffff(void) |
328 |
{ |
329 |
T0 = T0 & 0xffff;
|
330 |
} |
331 |
|
332 |
void OPPROTO op_andl_T0_im(void) |
333 |
{ |
334 |
T0 = T0 & PARAM1; |
335 |
} |
336 |
|
337 |
void OPPROTO op_movl_T0_T1(void) |
338 |
{ |
339 |
T0 = T1; |
340 |
} |
341 |
|
342 |
void OPPROTO op_movl_T1_im(void) |
343 |
{ |
344 |
T1 = PARAM1; |
345 |
} |
346 |
|
347 |
void OPPROTO op_addl_T1_im(void) |
348 |
{ |
349 |
T1 += PARAM1; |
350 |
} |
351 |
|
352 |
void OPPROTO op_movl_T1_A0(void) |
353 |
{ |
354 |
T1 = A0; |
355 |
} |
356 |
|
357 |
void OPPROTO op_movl_A0_im(void) |
358 |
{ |
359 |
A0 = PARAM1; |
360 |
} |
361 |
|
362 |
void OPPROTO op_addl_A0_im(void) |
363 |
{ |
364 |
A0 += PARAM1; |
365 |
} |
366 |
|
367 |
void OPPROTO op_addl_A0_AL(void) |
368 |
{ |
369 |
A0 += (EAX & 0xff);
|
370 |
} |
371 |
|
372 |
void OPPROTO op_andl_A0_ffff(void) |
373 |
{ |
374 |
A0 = A0 & 0xffff;
|
375 |
} |
376 |
|
377 |
/* memory access */
|
378 |
|
379 |
void OPPROTO op_ldub_T0_A0(void) |
380 |
{ |
381 |
T0 = ldub((uint8_t *)A0); |
382 |
} |
383 |
|
384 |
void OPPROTO op_ldsb_T0_A0(void) |
385 |
{ |
386 |
T0 = ldsb((int8_t *)A0); |
387 |
} |
388 |
|
389 |
void OPPROTO op_lduw_T0_A0(void) |
390 |
{ |
391 |
T0 = lduw((uint8_t *)A0); |
392 |
} |
393 |
|
394 |
void OPPROTO op_ldsw_T0_A0(void) |
395 |
{ |
396 |
T0 = ldsw((int8_t *)A0); |
397 |
} |
398 |
|
399 |
void OPPROTO op_ldl_T0_A0(void) |
400 |
{ |
401 |
T0 = ldl((uint8_t *)A0); |
402 |
} |
403 |
|
404 |
void OPPROTO op_ldub_T1_A0(void) |
405 |
{ |
406 |
T1 = ldub((uint8_t *)A0); |
407 |
} |
408 |
|
409 |
void OPPROTO op_ldsb_T1_A0(void) |
410 |
{ |
411 |
T1 = ldsb((int8_t *)A0); |
412 |
} |
413 |
|
414 |
void OPPROTO op_lduw_T1_A0(void) |
415 |
{ |
416 |
T1 = lduw((uint8_t *)A0); |
417 |
} |
418 |
|
419 |
void OPPROTO op_ldsw_T1_A0(void) |
420 |
{ |
421 |
T1 = ldsw((int8_t *)A0); |
422 |
} |
423 |
|
424 |
void OPPROTO op_ldl_T1_A0(void) |
425 |
{ |
426 |
T1 = ldl((uint8_t *)A0); |
427 |
} |
428 |
|
429 |
void OPPROTO op_stb_T0_A0(void) |
430 |
{ |
431 |
stb((uint8_t *)A0, T0); |
432 |
} |
433 |
|
434 |
void OPPROTO op_stw_T0_A0(void) |
435 |
{ |
436 |
stw((uint8_t *)A0, T0); |
437 |
} |
438 |
|
439 |
void OPPROTO op_stl_T0_A0(void) |
440 |
{ |
441 |
stl((uint8_t *)A0, T0); |
442 |
} |
443 |
|
444 |
/* used for bit operations */
|
445 |
|
446 |
void OPPROTO op_add_bitw_A0_T1(void) |
447 |
{ |
448 |
A0 += ((int32_t)T1 >> 4) << 1; |
449 |
} |
450 |
|
451 |
void OPPROTO op_add_bitl_A0_T1(void) |
452 |
{ |
453 |
A0 += ((int32_t)T1 >> 5) << 2; |
454 |
} |
455 |
|
456 |
/* indirect jump */
|
457 |
|
458 |
void OPPROTO op_jmp_T0(void) |
459 |
{ |
460 |
EIP = T0; |
461 |
} |
462 |
|
463 |
void OPPROTO op_jmp_im(void) |
464 |
{ |
465 |
EIP = PARAM1; |
466 |
} |
467 |
|
468 |
void OPPROTO op_hlt(void) |
469 |
{ |
470 |
env->exception_index = EXCP_HLT; |
471 |
cpu_loop_exit(); |
472 |
} |
473 |
|
474 |
void OPPROTO op_debug(void) |
475 |
{ |
476 |
env->exception_index = EXCP_DEBUG; |
477 |
cpu_loop_exit(); |
478 |
} |
479 |
|
480 |
void OPPROTO op_raise_interrupt(void) |
481 |
{ |
482 |
int intno;
|
483 |
unsigned int next_eip; |
484 |
intno = PARAM1; |
485 |
next_eip = PARAM2; |
486 |
raise_interrupt(intno, 1, 0, next_eip); |
487 |
} |
488 |
|
489 |
void OPPROTO op_raise_exception(void) |
490 |
{ |
491 |
int exception_index;
|
492 |
exception_index = PARAM1; |
493 |
raise_exception(exception_index); |
494 |
} |
495 |
|
496 |
void OPPROTO op_into(void) |
497 |
{ |
498 |
int eflags;
|
499 |
eflags = cc_table[CC_OP].compute_all(); |
500 |
if (eflags & CC_O) {
|
501 |
raise_interrupt(EXCP04_INTO, 1, 0, PARAM1); |
502 |
} |
503 |
FORCE_RET(); |
504 |
} |
505 |
|
506 |
void OPPROTO op_cli(void) |
507 |
{ |
508 |
env->eflags &= ~IF_MASK; |
509 |
} |
510 |
|
511 |
void OPPROTO op_sti(void) |
512 |
{ |
513 |
env->eflags |= IF_MASK; |
514 |
} |
515 |
|
516 |
#if 0
|
517 |
/* vm86plus instructions */
|
518 |
void OPPROTO op_cli_vm(void)
|
519 |
{
|
520 |
env->eflags &= ~VIF_MASK;
|
521 |
}
|
522 |
|
523 |
void OPPROTO op_sti_vm(void)
|
524 |
{
|
525 |
env->eflags |= VIF_MASK;
|
526 |
if (env->eflags & VIP_MASK) {
|
527 |
EIP = PARAM1;
|
528 |
raise_exception(EXCP0D_GPF);
|
529 |
}
|
530 |
FORCE_RET();
|
531 |
}
|
532 |
#endif
|
533 |
|
534 |
void OPPROTO op_boundw(void) |
535 |
{ |
536 |
int low, high, v;
|
537 |
low = ldsw((uint8_t *)A0); |
538 |
high = ldsw((uint8_t *)A0 + 2);
|
539 |
v = (int16_t)T0; |
540 |
if (v < low || v > high) {
|
541 |
EIP = PARAM1; |
542 |
raise_exception(EXCP05_BOUND); |
543 |
} |
544 |
FORCE_RET(); |
545 |
} |
546 |
|
547 |
void OPPROTO op_boundl(void) |
548 |
{ |
549 |
int low, high, v;
|
550 |
low = ldl((uint8_t *)A0); |
551 |
high = ldl((uint8_t *)A0 + 4);
|
552 |
v = T0; |
553 |
if (v < low || v > high) {
|
554 |
EIP = PARAM1; |
555 |
raise_exception(EXCP05_BOUND); |
556 |
} |
557 |
FORCE_RET(); |
558 |
} |
559 |
|
560 |
void OPPROTO op_cmpxchg8b(void) |
561 |
{ |
562 |
helper_cmpxchg8b(); |
563 |
} |
564 |
|
565 |
void OPPROTO op_jmp_tb_next(void) |
566 |
{ |
567 |
JUMP_TB(PARAM1, 0, PARAM2);
|
568 |
} |
569 |
|
570 |
void OPPROTO op_movl_T0_0(void) |
571 |
{ |
572 |
T0 = 0;
|
573 |
} |
574 |
|
575 |
void OPPROTO op_exit_tb(void) |
576 |
{ |
577 |
EXIT_TB(); |
578 |
} |
579 |
|
580 |
/* multiple size ops */
|
581 |
|
582 |
#define ldul ldl
|
583 |
|
584 |
#define SHIFT 0 |
585 |
#include "ops_template.h" |
586 |
#undef SHIFT
|
587 |
|
588 |
#define SHIFT 1 |
589 |
#include "ops_template.h" |
590 |
#undef SHIFT
|
591 |
|
592 |
#define SHIFT 2 |
593 |
#include "ops_template.h" |
594 |
#undef SHIFT
|
595 |
|
596 |
/* sign extend */
|
597 |
|
598 |
void OPPROTO op_movsbl_T0_T0(void) |
599 |
{ |
600 |
T0 = (int8_t)T0; |
601 |
} |
602 |
|
603 |
void OPPROTO op_movzbl_T0_T0(void) |
604 |
{ |
605 |
T0 = (uint8_t)T0; |
606 |
} |
607 |
|
608 |
void OPPROTO op_movswl_T0_T0(void) |
609 |
{ |
610 |
T0 = (int16_t)T0; |
611 |
} |
612 |
|
613 |
void OPPROTO op_movzwl_T0_T0(void) |
614 |
{ |
615 |
T0 = (uint16_t)T0; |
616 |
} |
617 |
|
618 |
void OPPROTO op_movswl_EAX_AX(void) |
619 |
{ |
620 |
EAX = (int16_t)EAX; |
621 |
} |
622 |
|
623 |
void OPPROTO op_movsbw_AX_AL(void) |
624 |
{ |
625 |
EAX = (EAX & 0xffff0000) | ((int8_t)EAX & 0xffff); |
626 |
} |
627 |
|
628 |
void OPPROTO op_movslq_EDX_EAX(void) |
629 |
{ |
630 |
EDX = (int32_t)EAX >> 31;
|
631 |
} |
632 |
|
633 |
void OPPROTO op_movswl_DX_AX(void) |
634 |
{ |
635 |
EDX = (EDX & 0xffff0000) | (((int16_t)EAX >> 15) & 0xffff); |
636 |
} |
637 |
|
638 |
/* push/pop */
|
639 |
|
640 |
void op_pushl_T0(void) |
641 |
{ |
642 |
uint32_t offset; |
643 |
offset = ESP - 4;
|
644 |
stl((void *)offset, T0);
|
645 |
/* modify ESP after to handle exceptions correctly */
|
646 |
ESP = offset; |
647 |
} |
648 |
|
649 |
void op_pushw_T0(void) |
650 |
{ |
651 |
uint32_t offset; |
652 |
offset = ESP - 2;
|
653 |
stw((void *)offset, T0);
|
654 |
/* modify ESP after to handle exceptions correctly */
|
655 |
ESP = offset; |
656 |
} |
657 |
|
658 |
void op_pushl_ss32_T0(void) |
659 |
{ |
660 |
uint32_t offset; |
661 |
offset = ESP - 4;
|
662 |
stl(env->segs[R_SS].base + offset, T0); |
663 |
/* modify ESP after to handle exceptions correctly */
|
664 |
ESP = offset; |
665 |
} |
666 |
|
667 |
void op_pushw_ss32_T0(void) |
668 |
{ |
669 |
uint32_t offset; |
670 |
offset = ESP - 2;
|
671 |
stw(env->segs[R_SS].base + offset, T0); |
672 |
/* modify ESP after to handle exceptions correctly */
|
673 |
ESP = offset; |
674 |
} |
675 |
|
676 |
void op_pushl_ss16_T0(void) |
677 |
{ |
678 |
uint32_t offset; |
679 |
offset = (ESP - 4) & 0xffff; |
680 |
stl(env->segs[R_SS].base + offset, T0); |
681 |
/* modify ESP after to handle exceptions correctly */
|
682 |
ESP = (ESP & ~0xffff) | offset;
|
683 |
} |
684 |
|
685 |
void op_pushw_ss16_T0(void) |
686 |
{ |
687 |
uint32_t offset; |
688 |
offset = (ESP - 2) & 0xffff; |
689 |
stw(env->segs[R_SS].base + offset, T0); |
690 |
/* modify ESP after to handle exceptions correctly */
|
691 |
ESP = (ESP & ~0xffff) | offset;
|
692 |
} |
693 |
|
694 |
/* NOTE: ESP update is done after */
|
695 |
void op_popl_T0(void) |
696 |
{ |
697 |
T0 = ldl((void *)ESP);
|
698 |
} |
699 |
|
700 |
void op_popw_T0(void) |
701 |
{ |
702 |
T0 = lduw((void *)ESP);
|
703 |
} |
704 |
|
705 |
void op_popl_ss32_T0(void) |
706 |
{ |
707 |
T0 = ldl(env->segs[R_SS].base + ESP); |
708 |
} |
709 |
|
710 |
void op_popw_ss32_T0(void) |
711 |
{ |
712 |
T0 = lduw(env->segs[R_SS].base + ESP); |
713 |
} |
714 |
|
715 |
void op_popl_ss16_T0(void) |
716 |
{ |
717 |
T0 = ldl(env->segs[R_SS].base + (ESP & 0xffff));
|
718 |
} |
719 |
|
720 |
void op_popw_ss16_T0(void) |
721 |
{ |
722 |
T0 = lduw(env->segs[R_SS].base + (ESP & 0xffff));
|
723 |
} |
724 |
|
725 |
void op_addl_ESP_4(void) |
726 |
{ |
727 |
ESP += 4;
|
728 |
} |
729 |
|
730 |
void op_addl_ESP_2(void) |
731 |
{ |
732 |
ESP += 2;
|
733 |
} |
734 |
|
735 |
void op_addw_ESP_4(void) |
736 |
{ |
737 |
ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff); |
738 |
} |
739 |
|
740 |
void op_addw_ESP_2(void) |
741 |
{ |
742 |
ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff); |
743 |
} |
744 |
|
745 |
void op_addl_ESP_im(void) |
746 |
{ |
747 |
ESP += PARAM1; |
748 |
} |
749 |
|
750 |
void op_addw_ESP_im(void) |
751 |
{ |
752 |
ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff); |
753 |
} |
754 |
|
755 |
void OPPROTO op_rdtsc(void) |
756 |
{ |
757 |
helper_rdtsc(); |
758 |
} |
759 |
|
760 |
void OPPROTO op_cpuid(void) |
761 |
{ |
762 |
helper_cpuid(); |
763 |
} |
764 |
|
765 |
void OPPROTO op_rdmsr(void) |
766 |
{ |
767 |
helper_rdmsr(); |
768 |
} |
769 |
|
770 |
void OPPROTO op_wrmsr(void) |
771 |
{ |
772 |
helper_wrmsr(); |
773 |
} |
774 |
|
775 |
/* bcd */
|
776 |
|
777 |
/* XXX: exception */
|
778 |
void OPPROTO op_aam(void) |
779 |
{ |
780 |
int base = PARAM1;
|
781 |
int al, ah;
|
782 |
al = EAX & 0xff;
|
783 |
ah = al / base; |
784 |
al = al % base; |
785 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
786 |
CC_DST = al; |
787 |
} |
788 |
|
789 |
void OPPROTO op_aad(void) |
790 |
{ |
791 |
int base = PARAM1;
|
792 |
int al, ah;
|
793 |
al = EAX & 0xff;
|
794 |
ah = (EAX >> 8) & 0xff; |
795 |
al = ((ah * base) + al) & 0xff;
|
796 |
EAX = (EAX & ~0xffff) | al;
|
797 |
CC_DST = al; |
798 |
} |
799 |
|
800 |
void OPPROTO op_aaa(void) |
801 |
{ |
802 |
int icarry;
|
803 |
int al, ah, af;
|
804 |
int eflags;
|
805 |
|
806 |
eflags = cc_table[CC_OP].compute_all(); |
807 |
af = eflags & CC_A; |
808 |
al = EAX & 0xff;
|
809 |
ah = (EAX >> 8) & 0xff; |
810 |
|
811 |
icarry = (al > 0xf9);
|
812 |
if (((al & 0x0f) > 9 ) || af) { |
813 |
al = (al + 6) & 0x0f; |
814 |
ah = (ah + 1 + icarry) & 0xff; |
815 |
eflags |= CC_C | CC_A; |
816 |
} else {
|
817 |
eflags &= ~(CC_C | CC_A); |
818 |
al &= 0x0f;
|
819 |
} |
820 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
821 |
CC_SRC = eflags; |
822 |
} |
823 |
|
824 |
void OPPROTO op_aas(void) |
825 |
{ |
826 |
int icarry;
|
827 |
int al, ah, af;
|
828 |
int eflags;
|
829 |
|
830 |
eflags = cc_table[CC_OP].compute_all(); |
831 |
af = eflags & CC_A; |
832 |
al = EAX & 0xff;
|
833 |
ah = (EAX >> 8) & 0xff; |
834 |
|
835 |
icarry = (al < 6);
|
836 |
if (((al & 0x0f) > 9 ) || af) { |
837 |
al = (al - 6) & 0x0f; |
838 |
ah = (ah - 1 - icarry) & 0xff; |
839 |
eflags |= CC_C | CC_A; |
840 |
} else {
|
841 |
eflags &= ~(CC_C | CC_A); |
842 |
al &= 0x0f;
|
843 |
} |
844 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
845 |
CC_SRC = eflags; |
846 |
} |
847 |
|
848 |
void OPPROTO op_daa(void) |
849 |
{ |
850 |
int al, af, cf;
|
851 |
int eflags;
|
852 |
|
853 |
eflags = cc_table[CC_OP].compute_all(); |
854 |
cf = eflags & CC_C; |
855 |
af = eflags & CC_A; |
856 |
al = EAX & 0xff;
|
857 |
|
858 |
eflags = 0;
|
859 |
if (((al & 0x0f) > 9 ) || af) { |
860 |
al = (al + 6) & 0xff; |
861 |
eflags |= CC_A; |
862 |
} |
863 |
if ((al > 0x9f) || cf) { |
864 |
al = (al + 0x60) & 0xff; |
865 |
eflags |= CC_C; |
866 |
} |
867 |
EAX = (EAX & ~0xff) | al;
|
868 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
869 |
eflags |= (al == 0) << 6; /* zf */ |
870 |
eflags |= parity_table[al]; /* pf */
|
871 |
eflags |= (al & 0x80); /* sf */ |
872 |
CC_SRC = eflags; |
873 |
} |
874 |
|
875 |
void OPPROTO op_das(void) |
876 |
{ |
877 |
int al, al1, af, cf;
|
878 |
int eflags;
|
879 |
|
880 |
eflags = cc_table[CC_OP].compute_all(); |
881 |
cf = eflags & CC_C; |
882 |
af = eflags & CC_A; |
883 |
al = EAX & 0xff;
|
884 |
|
885 |
eflags = 0;
|
886 |
al1 = al; |
887 |
if (((al & 0x0f) > 9 ) || af) { |
888 |
eflags |= CC_A; |
889 |
if (al < 6 || cf) |
890 |
eflags |= CC_C; |
891 |
al = (al - 6) & 0xff; |
892 |
} |
893 |
if ((al1 > 0x99) || cf) { |
894 |
al = (al - 0x60) & 0xff; |
895 |
eflags |= CC_C; |
896 |
} |
897 |
EAX = (EAX & ~0xff) | al;
|
898 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
899 |
eflags |= (al == 0) << 6; /* zf */ |
900 |
eflags |= parity_table[al]; /* pf */
|
901 |
eflags |= (al & 0x80); /* sf */ |
902 |
CC_SRC = eflags; |
903 |
} |
904 |
|
905 |
/* segment handling */
|
906 |
|
907 |
void OPPROTO op_movl_seg_T0(void) |
908 |
{ |
909 |
load_seg(PARAM1, T0 & 0xffff, PARAM2);
|
910 |
} |
911 |
|
912 |
/* faster VM86 version */
|
913 |
void OPPROTO op_movl_seg_T0_vm(void) |
914 |
{ |
915 |
int selector;
|
916 |
SegmentCache *sc; |
917 |
|
918 |
selector = T0 & 0xffff;
|
919 |
/* env->segs[] access */
|
920 |
sc = (SegmentCache *)((char *)env + PARAM1);
|
921 |
sc->selector = selector; |
922 |
sc->base = (void *)(selector << 4); |
923 |
} |
924 |
|
925 |
void OPPROTO op_movl_T0_seg(void) |
926 |
{ |
927 |
T0 = env->segs[PARAM1].selector; |
928 |
} |
929 |
|
930 |
void OPPROTO op_movl_A0_seg(void) |
931 |
{ |
932 |
A0 = *(unsigned long *)((char *)env + PARAM1); |
933 |
} |
934 |
|
935 |
void OPPROTO op_addl_A0_seg(void) |
936 |
{ |
937 |
A0 += *(unsigned long *)((char *)env + PARAM1); |
938 |
} |
939 |
|
940 |
void OPPROTO op_lsl(void) |
941 |
{ |
942 |
helper_lsl(); |
943 |
} |
944 |
|
945 |
void OPPROTO op_lar(void) |
946 |
{ |
947 |
helper_lar(); |
948 |
} |
949 |
|
950 |
/* T0: segment, T1:eip */
|
951 |
void OPPROTO op_ljmp_protected_T0_T1(void) |
952 |
{ |
953 |
helper_ljmp_protected_T0_T1(); |
954 |
} |
955 |
|
956 |
void OPPROTO op_lcall_real_T0_T1(void) |
957 |
{ |
958 |
helper_lcall_real_T0_T1(PARAM1, PARAM2); |
959 |
} |
960 |
|
961 |
void OPPROTO op_lcall_protected_T0_T1(void) |
962 |
{ |
963 |
helper_lcall_protected_T0_T1(PARAM1, PARAM2); |
964 |
} |
965 |
|
966 |
void OPPROTO op_iret_real(void) |
967 |
{ |
968 |
helper_iret_real(PARAM1); |
969 |
} |
970 |
|
971 |
void OPPROTO op_iret_protected(void) |
972 |
{ |
973 |
helper_iret_protected(PARAM1); |
974 |
} |
975 |
|
976 |
void OPPROTO op_lret_protected(void) |
977 |
{ |
978 |
helper_lret_protected(PARAM1, PARAM2); |
979 |
} |
980 |
|
981 |
void OPPROTO op_lldt_T0(void) |
982 |
{ |
983 |
helper_lldt_T0(); |
984 |
} |
985 |
|
986 |
void OPPROTO op_ltr_T0(void) |
987 |
{ |
988 |
helper_ltr_T0(); |
989 |
} |
990 |
|
991 |
/* CR registers access */
|
992 |
void OPPROTO op_movl_crN_T0(void) |
993 |
{ |
994 |
helper_movl_crN_T0(PARAM1); |
995 |
} |
996 |
|
997 |
/* DR registers access */
|
998 |
void OPPROTO op_movl_drN_T0(void) |
999 |
{ |
1000 |
helper_movl_drN_T0(PARAM1); |
1001 |
} |
1002 |
|
1003 |
void OPPROTO op_lmsw_T0(void) |
1004 |
{ |
1005 |
/* only 4 lower bits of CR0 are modified */
|
1006 |
T0 = (env->cr[0] & ~0xf) | (T0 & 0xf); |
1007 |
helper_movl_crN_T0(0);
|
1008 |
} |
1009 |
|
1010 |
void OPPROTO op_invlpg_A0(void) |
1011 |
{ |
1012 |
helper_invlpg(A0); |
1013 |
} |
1014 |
|
1015 |
void OPPROTO op_movl_T0_env(void) |
1016 |
{ |
1017 |
T0 = *(uint32_t *)((char *)env + PARAM1);
|
1018 |
} |
1019 |
|
1020 |
void OPPROTO op_movl_env_T0(void) |
1021 |
{ |
1022 |
*(uint32_t *)((char *)env + PARAM1) = T0;
|
1023 |
} |
1024 |
|
1025 |
void OPPROTO op_movl_env_T1(void) |
1026 |
{ |
1027 |
*(uint32_t *)((char *)env + PARAM1) = T1;
|
1028 |
} |
1029 |
|
1030 |
void OPPROTO op_clts(void) |
1031 |
{ |
1032 |
env->cr[0] &= ~CR0_TS_MASK;
|
1033 |
} |
1034 |
|
1035 |
/* flags handling */
|
1036 |
|
1037 |
/* slow jumps cases : in order to avoid calling a function with a
|
1038 |
pointer (which can generate a stack frame on PowerPC), we use
|
1039 |
op_setcc to set T0 and then call op_jcc. */
|
1040 |
void OPPROTO op_jcc(void) |
1041 |
{ |
1042 |
if (T0)
|
1043 |
JUMP_TB(PARAM1, 0, PARAM2);
|
1044 |
else
|
1045 |
JUMP_TB(PARAM1, 1, PARAM3);
|
1046 |
FORCE_RET(); |
1047 |
} |
1048 |
|
1049 |
/* slow set cases (compute x86 flags) */
|
1050 |
void OPPROTO op_seto_T0_cc(void) |
1051 |
{ |
1052 |
int eflags;
|
1053 |
eflags = cc_table[CC_OP].compute_all(); |
1054 |
T0 = (eflags >> 11) & 1; |
1055 |
} |
1056 |
|
1057 |
void OPPROTO op_setb_T0_cc(void) |
1058 |
{ |
1059 |
T0 = cc_table[CC_OP].compute_c(); |
1060 |
} |
1061 |
|
1062 |
void OPPROTO op_setz_T0_cc(void) |
1063 |
{ |
1064 |
int eflags;
|
1065 |
eflags = cc_table[CC_OP].compute_all(); |
1066 |
T0 = (eflags >> 6) & 1; |
1067 |
} |
1068 |
|
1069 |
void OPPROTO op_setbe_T0_cc(void) |
1070 |
{ |
1071 |
int eflags;
|
1072 |
eflags = cc_table[CC_OP].compute_all(); |
1073 |
T0 = (eflags & (CC_Z | CC_C)) != 0;
|
1074 |
} |
1075 |
|
1076 |
void OPPROTO op_sets_T0_cc(void) |
1077 |
{ |
1078 |
int eflags;
|
1079 |
eflags = cc_table[CC_OP].compute_all(); |
1080 |
T0 = (eflags >> 7) & 1; |
1081 |
} |
1082 |
|
1083 |
void OPPROTO op_setp_T0_cc(void) |
1084 |
{ |
1085 |
int eflags;
|
1086 |
eflags = cc_table[CC_OP].compute_all(); |
1087 |
T0 = (eflags >> 2) & 1; |
1088 |
} |
1089 |
|
1090 |
void OPPROTO op_setl_T0_cc(void) |
1091 |
{ |
1092 |
int eflags;
|
1093 |
eflags = cc_table[CC_OP].compute_all(); |
1094 |
T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1; |
1095 |
} |
1096 |
|
1097 |
void OPPROTO op_setle_T0_cc(void) |
1098 |
{ |
1099 |
int eflags;
|
1100 |
eflags = cc_table[CC_OP].compute_all(); |
1101 |
T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0; |
1102 |
} |
1103 |
|
1104 |
void OPPROTO op_xor_T0_1(void) |
1105 |
{ |
1106 |
T0 ^= 1;
|
1107 |
} |
1108 |
|
1109 |
void OPPROTO op_set_cc_op(void) |
1110 |
{ |
1111 |
CC_OP = PARAM1; |
1112 |
} |
1113 |
|
1114 |
#define FL_UPDATE_MASK16 (FL_UPDATE_MASK32 & 0xffff) |
1115 |
|
1116 |
void OPPROTO op_movl_eflags_T0(void) |
1117 |
{ |
1118 |
int eflags;
|
1119 |
eflags = T0; |
1120 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1121 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1122 |
/* we also update some system flags as in user mode */
|
1123 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK32) | |
1124 |
(eflags & FL_UPDATE_MASK32); |
1125 |
} |
1126 |
|
1127 |
void OPPROTO op_movw_eflags_T0(void) |
1128 |
{ |
1129 |
int eflags;
|
1130 |
eflags = T0; |
1131 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1132 |
DF = 1 - (2 * ((eflags >> 10) & 1)); |
1133 |
/* we also update some system flags as in user mode */
|
1134 |
env->eflags = (env->eflags & ~FL_UPDATE_MASK16) | |
1135 |
(eflags & FL_UPDATE_MASK16); |
1136 |
} |
1137 |
|
1138 |
void OPPROTO op_movl_eflags_T0_cpl0(void) |
1139 |
{ |
1140 |
load_eflags(T0, FL_UPDATE_CPL0_MASK); |
1141 |
} |
1142 |
|
1143 |
void OPPROTO op_movw_eflags_T0_cpl0(void) |
1144 |
{ |
1145 |
load_eflags(T0, FL_UPDATE_CPL0_MASK & 0xffff);
|
1146 |
} |
1147 |
|
1148 |
#if 0
|
1149 |
/* vm86plus version */
|
1150 |
void OPPROTO op_movw_eflags_T0_vm(void)
|
1151 |
{
|
1152 |
int eflags;
|
1153 |
eflags = T0;
|
1154 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1155 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1156 |
/* we also update some system flags as in user mode */
|
1157 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
|
1158 |
(eflags & FL_UPDATE_MASK16);
|
1159 |
if (eflags & IF_MASK) {
|
1160 |
env->eflags |= VIF_MASK;
|
1161 |
if (env->eflags & VIP_MASK) {
|
1162 |
EIP = PARAM1;
|
1163 |
raise_exception(EXCP0D_GPF);
|
1164 |
}
|
1165 |
}
|
1166 |
FORCE_RET();
|
1167 |
}
|
1168 |
|
1169 |
void OPPROTO op_movl_eflags_T0_vm(void)
|
1170 |
{
|
1171 |
int eflags;
|
1172 |
eflags = T0;
|
1173 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1174 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1175 |
/* we also update some system flags as in user mode */
|
1176 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
|
1177 |
(eflags & FL_UPDATE_MASK32);
|
1178 |
if (eflags & IF_MASK) {
|
1179 |
env->eflags |= VIF_MASK;
|
1180 |
if (env->eflags & VIP_MASK) {
|
1181 |
EIP = PARAM1;
|
1182 |
raise_exception(EXCP0D_GPF);
|
1183 |
}
|
1184 |
}
|
1185 |
FORCE_RET();
|
1186 |
}
|
1187 |
#endif
|
1188 |
|
1189 |
/* XXX: compute only O flag */
|
1190 |
void OPPROTO op_movb_eflags_T0(void) |
1191 |
{ |
1192 |
int of;
|
1193 |
of = cc_table[CC_OP].compute_all() & CC_O; |
1194 |
CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of; |
1195 |
} |
1196 |
|
1197 |
void OPPROTO op_movl_T0_eflags(void) |
1198 |
{ |
1199 |
int eflags;
|
1200 |
eflags = cc_table[CC_OP].compute_all(); |
1201 |
eflags |= (DF & DF_MASK); |
1202 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK); |
1203 |
T0 = eflags; |
1204 |
} |
1205 |
|
1206 |
/* vm86plus version */
|
1207 |
#if 0
|
1208 |
void OPPROTO op_movl_T0_eflags_vm(void)
|
1209 |
{
|
1210 |
int eflags;
|
1211 |
eflags = cc_table[CC_OP].compute_all();
|
1212 |
eflags |= (DF & DF_MASK);
|
1213 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
|
1214 |
if (env->eflags & VIF_MASK)
|
1215 |
eflags |= IF_MASK;
|
1216 |
T0 = eflags;
|
1217 |
}
|
1218 |
#endif
|
1219 |
|
1220 |
void OPPROTO op_cld(void) |
1221 |
{ |
1222 |
DF = 1;
|
1223 |
} |
1224 |
|
1225 |
void OPPROTO op_std(void) |
1226 |
{ |
1227 |
DF = -1;
|
1228 |
} |
1229 |
|
1230 |
void OPPROTO op_clc(void) |
1231 |
{ |
1232 |
int eflags;
|
1233 |
eflags = cc_table[CC_OP].compute_all(); |
1234 |
eflags &= ~CC_C; |
1235 |
CC_SRC = eflags; |
1236 |
} |
1237 |
|
1238 |
void OPPROTO op_stc(void) |
1239 |
{ |
1240 |
int eflags;
|
1241 |
eflags = cc_table[CC_OP].compute_all(); |
1242 |
eflags |= CC_C; |
1243 |
CC_SRC = eflags; |
1244 |
} |
1245 |
|
1246 |
void OPPROTO op_cmc(void) |
1247 |
{ |
1248 |
int eflags;
|
1249 |
eflags = cc_table[CC_OP].compute_all(); |
1250 |
eflags ^= CC_C; |
1251 |
CC_SRC = eflags; |
1252 |
} |
1253 |
|
1254 |
void OPPROTO op_salc(void) |
1255 |
{ |
1256 |
int cf;
|
1257 |
cf = cc_table[CC_OP].compute_c(); |
1258 |
EAX = (EAX & ~0xff) | ((-cf) & 0xff); |
1259 |
} |
1260 |
|
1261 |
static int compute_all_eflags(void) |
1262 |
{ |
1263 |
return CC_SRC;
|
1264 |
} |
1265 |
|
1266 |
static int compute_c_eflags(void) |
1267 |
{ |
1268 |
return CC_SRC & CC_C;
|
1269 |
} |
1270 |
|
1271 |
static int compute_c_mul(void) |
1272 |
{ |
1273 |
int cf;
|
1274 |
cf = (CC_SRC != 0);
|
1275 |
return cf;
|
1276 |
} |
1277 |
|
1278 |
static int compute_all_mul(void) |
1279 |
{ |
1280 |
int cf, pf, af, zf, sf, of;
|
1281 |
cf = (CC_SRC != 0);
|
1282 |
pf = 0; /* undefined */ |
1283 |
af = 0; /* undefined */ |
1284 |
zf = 0; /* undefined */ |
1285 |
sf = 0; /* undefined */ |
1286 |
of = cf << 11;
|
1287 |
return cf | pf | af | zf | sf | of;
|
1288 |
} |
1289 |
|
1290 |
CCTable cc_table[CC_OP_NB] = { |
1291 |
[CC_OP_DYNAMIC] = { /* should never happen */ },
|
1292 |
|
1293 |
[CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags }, |
1294 |
|
1295 |
[CC_OP_MUL] = { compute_all_mul, compute_c_mul }, |
1296 |
|
1297 |
[CC_OP_ADDB] = { compute_all_addb, compute_c_addb }, |
1298 |
[CC_OP_ADDW] = { compute_all_addw, compute_c_addw }, |
1299 |
[CC_OP_ADDL] = { compute_all_addl, compute_c_addl }, |
1300 |
|
1301 |
[CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb }, |
1302 |
[CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw }, |
1303 |
[CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl }, |
1304 |
|
1305 |
[CC_OP_SUBB] = { compute_all_subb, compute_c_subb }, |
1306 |
[CC_OP_SUBW] = { compute_all_subw, compute_c_subw }, |
1307 |
[CC_OP_SUBL] = { compute_all_subl, compute_c_subl }, |
1308 |
|
1309 |
[CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb }, |
1310 |
[CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw }, |
1311 |
[CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl }, |
1312 |
|
1313 |
[CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb }, |
1314 |
[CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw }, |
1315 |
[CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl }, |
1316 |
|
1317 |
[CC_OP_INCB] = { compute_all_incb, compute_c_incl }, |
1318 |
[CC_OP_INCW] = { compute_all_incw, compute_c_incl }, |
1319 |
[CC_OP_INCL] = { compute_all_incl, compute_c_incl }, |
1320 |
|
1321 |
[CC_OP_DECB] = { compute_all_decb, compute_c_incl }, |
1322 |
[CC_OP_DECW] = { compute_all_decw, compute_c_incl }, |
1323 |
[CC_OP_DECL] = { compute_all_decl, compute_c_incl }, |
1324 |
|
1325 |
[CC_OP_SHLB] = { compute_all_shlb, compute_c_shlb }, |
1326 |
[CC_OP_SHLW] = { compute_all_shlw, compute_c_shlw }, |
1327 |
[CC_OP_SHLL] = { compute_all_shll, compute_c_shll }, |
1328 |
|
1329 |
[CC_OP_SARB] = { compute_all_sarb, compute_c_sarl }, |
1330 |
[CC_OP_SARW] = { compute_all_sarw, compute_c_sarl }, |
1331 |
[CC_OP_SARL] = { compute_all_sarl, compute_c_sarl }, |
1332 |
}; |
1333 |
|
1334 |
/* floating point support. Some of the code for complicated x87
|
1335 |
functions comes from the LGPL'ed x86 emulator found in the Willows
|
1336 |
TWIN windows emulator. */
|
1337 |
|
1338 |
#if defined(__powerpc__)
|
1339 |
extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
|
1340 |
|
1341 |
/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
1342 |
double qemu_rint(double x) |
1343 |
{ |
1344 |
double y = 4503599627370496.0; |
1345 |
if (fabs(x) >= y)
|
1346 |
return x;
|
1347 |
if (x < 0) |
1348 |
y = -y; |
1349 |
y = (x + y) - y; |
1350 |
if (y == 0.0) |
1351 |
y = copysign(y, x); |
1352 |
return y;
|
1353 |
} |
1354 |
|
1355 |
#define rint qemu_rint
|
1356 |
#endif
|
1357 |
|
1358 |
/* fp load FT0 */
|
1359 |
|
1360 |
void OPPROTO op_flds_FT0_A0(void) |
1361 |
{ |
1362 |
#ifdef USE_FP_CONVERT
|
1363 |
FP_CONVERT.i32 = ldl((void *)A0);
|
1364 |
FT0 = FP_CONVERT.f; |
1365 |
#else
|
1366 |
FT0 = ldfl((void *)A0);
|
1367 |
#endif
|
1368 |
} |
1369 |
|
1370 |
void OPPROTO op_fldl_FT0_A0(void) |
1371 |
{ |
1372 |
#ifdef USE_FP_CONVERT
|
1373 |
FP_CONVERT.i64 = ldq((void *)A0);
|
1374 |
FT0 = FP_CONVERT.d; |
1375 |
#else
|
1376 |
FT0 = ldfq((void *)A0);
|
1377 |
#endif
|
1378 |
} |
1379 |
|
1380 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1381 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1382 |
|
1383 |
void helper_fild_FT0_A0(void) |
1384 |
{ |
1385 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1386 |
} |
1387 |
|
1388 |
void helper_fildl_FT0_A0(void) |
1389 |
{ |
1390 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1391 |
} |
1392 |
|
1393 |
void helper_fildll_FT0_A0(void) |
1394 |
{ |
1395 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1396 |
} |
1397 |
|
1398 |
void OPPROTO op_fild_FT0_A0(void) |
1399 |
{ |
1400 |
helper_fild_FT0_A0(); |
1401 |
} |
1402 |
|
1403 |
void OPPROTO op_fildl_FT0_A0(void) |
1404 |
{ |
1405 |
helper_fildl_FT0_A0(); |
1406 |
} |
1407 |
|
1408 |
void OPPROTO op_fildll_FT0_A0(void) |
1409 |
{ |
1410 |
helper_fildll_FT0_A0(); |
1411 |
} |
1412 |
|
1413 |
#else
|
1414 |
|
1415 |
void OPPROTO op_fild_FT0_A0(void) |
1416 |
{ |
1417 |
#ifdef USE_FP_CONVERT
|
1418 |
FP_CONVERT.i32 = ldsw((void *)A0);
|
1419 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1420 |
#else
|
1421 |
FT0 = (CPU86_LDouble)ldsw((void *)A0);
|
1422 |
#endif
|
1423 |
} |
1424 |
|
1425 |
void OPPROTO op_fildl_FT0_A0(void) |
1426 |
{ |
1427 |
#ifdef USE_FP_CONVERT
|
1428 |
FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
|
1429 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1430 |
#else
|
1431 |
FT0 = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1432 |
#endif
|
1433 |
} |
1434 |
|
1435 |
void OPPROTO op_fildll_FT0_A0(void) |
1436 |
{ |
1437 |
#ifdef USE_FP_CONVERT
|
1438 |
FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
|
1439 |
FT0 = (CPU86_LDouble)FP_CONVERT.i64; |
1440 |
#else
|
1441 |
FT0 = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1442 |
#endif
|
1443 |
} |
1444 |
#endif
|
1445 |
|
1446 |
/* fp load ST0 */
|
1447 |
|
1448 |
void OPPROTO op_flds_ST0_A0(void) |
1449 |
{ |
1450 |
int new_fpstt;
|
1451 |
new_fpstt = (env->fpstt - 1) & 7; |
1452 |
#ifdef USE_FP_CONVERT
|
1453 |
FP_CONVERT.i32 = ldl((void *)A0);
|
1454 |
env->fpregs[new_fpstt] = FP_CONVERT.f; |
1455 |
#else
|
1456 |
env->fpregs[new_fpstt] = ldfl((void *)A0);
|
1457 |
#endif
|
1458 |
env->fpstt = new_fpstt; |
1459 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1460 |
} |
1461 |
|
1462 |
void OPPROTO op_fldl_ST0_A0(void) |
1463 |
{ |
1464 |
int new_fpstt;
|
1465 |
new_fpstt = (env->fpstt - 1) & 7; |
1466 |
#ifdef USE_FP_CONVERT
|
1467 |
FP_CONVERT.i64 = ldq((void *)A0);
|
1468 |
env->fpregs[new_fpstt] = FP_CONVERT.d; |
1469 |
#else
|
1470 |
env->fpregs[new_fpstt] = ldfq((void *)A0);
|
1471 |
#endif
|
1472 |
env->fpstt = new_fpstt; |
1473 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1474 |
} |
1475 |
|
1476 |
#ifdef USE_X86LDOUBLE
|
1477 |
void OPPROTO op_fldt_ST0_A0(void) |
1478 |
{ |
1479 |
int new_fpstt;
|
1480 |
new_fpstt = (env->fpstt - 1) & 7; |
1481 |
env->fpregs[new_fpstt] = *(long double *)A0; |
1482 |
env->fpstt = new_fpstt; |
1483 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1484 |
} |
1485 |
#else
|
1486 |
void OPPROTO op_fldt_ST0_A0(void) |
1487 |
{ |
1488 |
helper_fldt_ST0_A0(); |
1489 |
} |
1490 |
#endif
|
1491 |
|
1492 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1493 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1494 |
|
1495 |
void helper_fild_ST0_A0(void) |
1496 |
{ |
1497 |
int new_fpstt;
|
1498 |
new_fpstt = (env->fpstt - 1) & 7; |
1499 |
env->fpregs[new_fpstt] = (CPU86_LDouble)ldsw((void *)A0);
|
1500 |
env->fpstt = new_fpstt; |
1501 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1502 |
} |
1503 |
|
1504 |
void helper_fildl_ST0_A0(void) |
1505 |
{ |
1506 |
int new_fpstt;
|
1507 |
new_fpstt = (env->fpstt - 1) & 7; |
1508 |
env->fpregs[new_fpstt] = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1509 |
env->fpstt = new_fpstt; |
1510 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1511 |
} |
1512 |
|
1513 |
void helper_fildll_ST0_A0(void) |
1514 |
{ |
1515 |
int new_fpstt;
|
1516 |
new_fpstt = (env->fpstt - 1) & 7; |
1517 |
env->fpregs[new_fpstt] = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1518 |
env->fpstt = new_fpstt; |
1519 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1520 |
} |
1521 |
|
1522 |
void OPPROTO op_fild_ST0_A0(void) |
1523 |
{ |
1524 |
helper_fild_ST0_A0(); |
1525 |
} |
1526 |
|
1527 |
void OPPROTO op_fildl_ST0_A0(void) |
1528 |
{ |
1529 |
helper_fildl_ST0_A0(); |
1530 |
} |
1531 |
|
1532 |
void OPPROTO op_fildll_ST0_A0(void) |
1533 |
{ |
1534 |
helper_fildll_ST0_A0(); |
1535 |
} |
1536 |
|
1537 |
#else
|
1538 |
|
1539 |
void OPPROTO op_fild_ST0_A0(void) |
1540 |
{ |
1541 |
int new_fpstt;
|
1542 |
new_fpstt = (env->fpstt - 1) & 7; |
1543 |
#ifdef USE_FP_CONVERT
|
1544 |
FP_CONVERT.i32 = ldsw((void *)A0);
|
1545 |
env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i32; |
1546 |
#else
|
1547 |
env->fpregs[new_fpstt] = (CPU86_LDouble)ldsw((void *)A0);
|
1548 |
#endif
|
1549 |
env->fpstt = new_fpstt; |
1550 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1551 |
} |
1552 |
|
1553 |
void OPPROTO op_fildl_ST0_A0(void) |
1554 |
{ |
1555 |
int new_fpstt;
|
1556 |
new_fpstt = (env->fpstt - 1) & 7; |
1557 |
#ifdef USE_FP_CONVERT
|
1558 |
FP_CONVERT.i32 = (int32_t) ldl((void *)A0);
|
1559 |
env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i32; |
1560 |
#else
|
1561 |
env->fpregs[new_fpstt] = (CPU86_LDouble)((int32_t)ldl((void *)A0));
|
1562 |
#endif
|
1563 |
env->fpstt = new_fpstt; |
1564 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1565 |
} |
1566 |
|
1567 |
void OPPROTO op_fildll_ST0_A0(void) |
1568 |
{ |
1569 |
int new_fpstt;
|
1570 |
new_fpstt = (env->fpstt - 1) & 7; |
1571 |
#ifdef USE_FP_CONVERT
|
1572 |
FP_CONVERT.i64 = (int64_t) ldq((void *)A0);
|
1573 |
env->fpregs[new_fpstt] = (CPU86_LDouble)FP_CONVERT.i64; |
1574 |
#else
|
1575 |
env->fpregs[new_fpstt] = (CPU86_LDouble)((int64_t)ldq((void *)A0));
|
1576 |
#endif
|
1577 |
env->fpstt = new_fpstt; |
1578 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1579 |
} |
1580 |
|
1581 |
#endif
|
1582 |
|
1583 |
/* fp store */
|
1584 |
|
1585 |
void OPPROTO op_fsts_ST0_A0(void) |
1586 |
{ |
1587 |
#ifdef USE_FP_CONVERT
|
1588 |
FP_CONVERT.f = (float)ST0;
|
1589 |
stfl((void *)A0, FP_CONVERT.f);
|
1590 |
#else
|
1591 |
stfl((void *)A0, (float)ST0); |
1592 |
#endif
|
1593 |
} |
1594 |
|
1595 |
void OPPROTO op_fstl_ST0_A0(void) |
1596 |
{ |
1597 |
stfq((void *)A0, (double)ST0); |
1598 |
} |
1599 |
|
1600 |
#ifdef USE_X86LDOUBLE
|
1601 |
void OPPROTO op_fstt_ST0_A0(void) |
1602 |
{ |
1603 |
*(long double *)A0 = ST0; |
1604 |
} |
1605 |
#else
|
1606 |
void OPPROTO op_fstt_ST0_A0(void) |
1607 |
{ |
1608 |
helper_fstt_ST0_A0(); |
1609 |
} |
1610 |
#endif
|
1611 |
|
1612 |
void OPPROTO op_fist_ST0_A0(void) |
1613 |
{ |
1614 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1615 |
register CPU86_LDouble d asm("o0"); |
1616 |
#else
|
1617 |
CPU86_LDouble d; |
1618 |
#endif
|
1619 |
int val;
|
1620 |
|
1621 |
d = ST0; |
1622 |
val = lrint(d); |
1623 |
if (val != (int16_t)val)
|
1624 |
val = -32768;
|
1625 |
stw((void *)A0, val);
|
1626 |
} |
1627 |
|
1628 |
void OPPROTO op_fistl_ST0_A0(void) |
1629 |
{ |
1630 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1631 |
register CPU86_LDouble d asm("o0"); |
1632 |
#else
|
1633 |
CPU86_LDouble d; |
1634 |
#endif
|
1635 |
int val;
|
1636 |
|
1637 |
d = ST0; |
1638 |
val = lrint(d); |
1639 |
stl((void *)A0, val);
|
1640 |
} |
1641 |
|
1642 |
void OPPROTO op_fistll_ST0_A0(void) |
1643 |
{ |
1644 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1645 |
register CPU86_LDouble d asm("o0"); |
1646 |
#else
|
1647 |
CPU86_LDouble d; |
1648 |
#endif
|
1649 |
int64_t val; |
1650 |
|
1651 |
d = ST0; |
1652 |
val = llrint(d); |
1653 |
stq((void *)A0, val);
|
1654 |
} |
1655 |
|
1656 |
void OPPROTO op_fbld_ST0_A0(void) |
1657 |
{ |
1658 |
helper_fbld_ST0_A0(); |
1659 |
} |
1660 |
|
1661 |
void OPPROTO op_fbst_ST0_A0(void) |
1662 |
{ |
1663 |
helper_fbst_ST0_A0(); |
1664 |
} |
1665 |
|
1666 |
/* FPU move */
|
1667 |
|
1668 |
void OPPROTO op_fpush(void) |
1669 |
{ |
1670 |
fpush(); |
1671 |
} |
1672 |
|
1673 |
void OPPROTO op_fpop(void) |
1674 |
{ |
1675 |
fpop(); |
1676 |
} |
1677 |
|
1678 |
void OPPROTO op_fdecstp(void) |
1679 |
{ |
1680 |
env->fpstt = (env->fpstt - 1) & 7; |
1681 |
env->fpus &= (~0x4700);
|
1682 |
} |
1683 |
|
1684 |
void OPPROTO op_fincstp(void) |
1685 |
{ |
1686 |
env->fpstt = (env->fpstt + 1) & 7; |
1687 |
env->fpus &= (~0x4700);
|
1688 |
} |
1689 |
|
1690 |
void OPPROTO op_fmov_ST0_FT0(void) |
1691 |
{ |
1692 |
ST0 = FT0; |
1693 |
} |
1694 |
|
1695 |
void OPPROTO op_fmov_FT0_STN(void) |
1696 |
{ |
1697 |
FT0 = ST(PARAM1); |
1698 |
} |
1699 |
|
1700 |
void OPPROTO op_fmov_ST0_STN(void) |
1701 |
{ |
1702 |
ST0 = ST(PARAM1); |
1703 |
} |
1704 |
|
1705 |
void OPPROTO op_fmov_STN_ST0(void) |
1706 |
{ |
1707 |
ST(PARAM1) = ST0; |
1708 |
} |
1709 |
|
1710 |
void OPPROTO op_fxchg_ST0_STN(void) |
1711 |
{ |
1712 |
CPU86_LDouble tmp; |
1713 |
tmp = ST(PARAM1); |
1714 |
ST(PARAM1) = ST0; |
1715 |
ST0 = tmp; |
1716 |
} |
1717 |
|
1718 |
/* FPU operations */
|
1719 |
|
1720 |
/* XXX: handle nans */
|
1721 |
void OPPROTO op_fcom_ST0_FT0(void) |
1722 |
{ |
1723 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1724 |
if (ST0 < FT0)
|
1725 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1726 |
else if (ST0 == FT0) |
1727 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1728 |
FORCE_RET(); |
1729 |
} |
1730 |
|
1731 |
/* XXX: handle nans */
|
1732 |
void OPPROTO op_fucom_ST0_FT0(void) |
1733 |
{ |
1734 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1735 |
if (ST0 < FT0)
|
1736 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1737 |
else if (ST0 == FT0) |
1738 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1739 |
FORCE_RET(); |
1740 |
} |
1741 |
|
1742 |
/* XXX: handle nans */
|
1743 |
void OPPROTO op_fcomi_ST0_FT0(void) |
1744 |
{ |
1745 |
int eflags;
|
1746 |
eflags = cc_table[CC_OP].compute_all(); |
1747 |
eflags &= ~(CC_Z | CC_P | CC_C); |
1748 |
if (ST0 < FT0)
|
1749 |
eflags |= CC_C; |
1750 |
else if (ST0 == FT0) |
1751 |
eflags |= CC_Z; |
1752 |
CC_SRC = eflags; |
1753 |
FORCE_RET(); |
1754 |
} |
1755 |
|
1756 |
/* XXX: handle nans */
|
1757 |
void OPPROTO op_fucomi_ST0_FT0(void) |
1758 |
{ |
1759 |
int eflags;
|
1760 |
eflags = cc_table[CC_OP].compute_all(); |
1761 |
eflags &= ~(CC_Z | CC_P | CC_C); |
1762 |
if (ST0 < FT0)
|
1763 |
eflags |= CC_C; |
1764 |
else if (ST0 == FT0) |
1765 |
eflags |= CC_Z; |
1766 |
CC_SRC = eflags; |
1767 |
FORCE_RET(); |
1768 |
} |
1769 |
|
1770 |
void OPPROTO op_fadd_ST0_FT0(void) |
1771 |
{ |
1772 |
ST0 += FT0; |
1773 |
} |
1774 |
|
1775 |
void OPPROTO op_fmul_ST0_FT0(void) |
1776 |
{ |
1777 |
ST0 *= FT0; |
1778 |
} |
1779 |
|
1780 |
void OPPROTO op_fsub_ST0_FT0(void) |
1781 |
{ |
1782 |
ST0 -= FT0; |
1783 |
} |
1784 |
|
1785 |
void OPPROTO op_fsubr_ST0_FT0(void) |
1786 |
{ |
1787 |
ST0 = FT0 - ST0; |
1788 |
} |
1789 |
|
1790 |
void OPPROTO op_fdiv_ST0_FT0(void) |
1791 |
{ |
1792 |
ST0 /= FT0; |
1793 |
} |
1794 |
|
1795 |
void OPPROTO op_fdivr_ST0_FT0(void) |
1796 |
{ |
1797 |
ST0 = FT0 / ST0; |
1798 |
} |
1799 |
|
1800 |
/* fp operations between STN and ST0 */
|
1801 |
|
1802 |
void OPPROTO op_fadd_STN_ST0(void) |
1803 |
{ |
1804 |
ST(PARAM1) += ST0; |
1805 |
} |
1806 |
|
1807 |
void OPPROTO op_fmul_STN_ST0(void) |
1808 |
{ |
1809 |
ST(PARAM1) *= ST0; |
1810 |
} |
1811 |
|
1812 |
void OPPROTO op_fsub_STN_ST0(void) |
1813 |
{ |
1814 |
ST(PARAM1) -= ST0; |
1815 |
} |
1816 |
|
1817 |
void OPPROTO op_fsubr_STN_ST0(void) |
1818 |
{ |
1819 |
CPU86_LDouble *p; |
1820 |
p = &ST(PARAM1); |
1821 |
*p = ST0 - *p; |
1822 |
} |
1823 |
|
1824 |
void OPPROTO op_fdiv_STN_ST0(void) |
1825 |
{ |
1826 |
ST(PARAM1) /= ST0; |
1827 |
} |
1828 |
|
1829 |
void OPPROTO op_fdivr_STN_ST0(void) |
1830 |
{ |
1831 |
CPU86_LDouble *p; |
1832 |
p = &ST(PARAM1); |
1833 |
*p = ST0 / *p; |
1834 |
} |
1835 |
|
1836 |
/* misc FPU operations */
|
1837 |
void OPPROTO op_fchs_ST0(void) |
1838 |
{ |
1839 |
ST0 = -ST0; |
1840 |
} |
1841 |
|
1842 |
void OPPROTO op_fabs_ST0(void) |
1843 |
{ |
1844 |
ST0 = fabs(ST0); |
1845 |
} |
1846 |
|
1847 |
void OPPROTO op_fxam_ST0(void) |
1848 |
{ |
1849 |
helper_fxam_ST0(); |
1850 |
} |
1851 |
|
1852 |
void OPPROTO op_fld1_ST0(void) |
1853 |
{ |
1854 |
ST0 = f15rk[1];
|
1855 |
} |
1856 |
|
1857 |
void OPPROTO op_fldl2t_ST0(void) |
1858 |
{ |
1859 |
ST0 = f15rk[6];
|
1860 |
} |
1861 |
|
1862 |
void OPPROTO op_fldl2e_ST0(void) |
1863 |
{ |
1864 |
ST0 = f15rk[5];
|
1865 |
} |
1866 |
|
1867 |
void OPPROTO op_fldpi_ST0(void) |
1868 |
{ |
1869 |
ST0 = f15rk[2];
|
1870 |
} |
1871 |
|
1872 |
void OPPROTO op_fldlg2_ST0(void) |
1873 |
{ |
1874 |
ST0 = f15rk[3];
|
1875 |
} |
1876 |
|
1877 |
void OPPROTO op_fldln2_ST0(void) |
1878 |
{ |
1879 |
ST0 = f15rk[4];
|
1880 |
} |
1881 |
|
1882 |
void OPPROTO op_fldz_ST0(void) |
1883 |
{ |
1884 |
ST0 = f15rk[0];
|
1885 |
} |
1886 |
|
1887 |
void OPPROTO op_fldz_FT0(void) |
1888 |
{ |
1889 |
ST0 = f15rk[0];
|
1890 |
} |
1891 |
|
1892 |
/* associated heplers to reduce generated code length and to simplify
|
1893 |
relocation (FP constants are usually stored in .rodata section) */
|
1894 |
|
1895 |
void OPPROTO op_f2xm1(void) |
1896 |
{ |
1897 |
helper_f2xm1(); |
1898 |
} |
1899 |
|
1900 |
void OPPROTO op_fyl2x(void) |
1901 |
{ |
1902 |
helper_fyl2x(); |
1903 |
} |
1904 |
|
1905 |
void OPPROTO op_fptan(void) |
1906 |
{ |
1907 |
helper_fptan(); |
1908 |
} |
1909 |
|
1910 |
void OPPROTO op_fpatan(void) |
1911 |
{ |
1912 |
helper_fpatan(); |
1913 |
} |
1914 |
|
1915 |
void OPPROTO op_fxtract(void) |
1916 |
{ |
1917 |
helper_fxtract(); |
1918 |
} |
1919 |
|
1920 |
void OPPROTO op_fprem1(void) |
1921 |
{ |
1922 |
helper_fprem1(); |
1923 |
} |
1924 |
|
1925 |
|
1926 |
void OPPROTO op_fprem(void) |
1927 |
{ |
1928 |
helper_fprem(); |
1929 |
} |
1930 |
|
1931 |
void OPPROTO op_fyl2xp1(void) |
1932 |
{ |
1933 |
helper_fyl2xp1(); |
1934 |
} |
1935 |
|
1936 |
void OPPROTO op_fsqrt(void) |
1937 |
{ |
1938 |
helper_fsqrt(); |
1939 |
} |
1940 |
|
1941 |
void OPPROTO op_fsincos(void) |
1942 |
{ |
1943 |
helper_fsincos(); |
1944 |
} |
1945 |
|
1946 |
void OPPROTO op_frndint(void) |
1947 |
{ |
1948 |
helper_frndint(); |
1949 |
} |
1950 |
|
1951 |
void OPPROTO op_fscale(void) |
1952 |
{ |
1953 |
helper_fscale(); |
1954 |
} |
1955 |
|
1956 |
void OPPROTO op_fsin(void) |
1957 |
{ |
1958 |
helper_fsin(); |
1959 |
} |
1960 |
|
1961 |
void OPPROTO op_fcos(void) |
1962 |
{ |
1963 |
helper_fcos(); |
1964 |
} |
1965 |
|
1966 |
void OPPROTO op_fnstsw_A0(void) |
1967 |
{ |
1968 |
int fpus;
|
1969 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
1970 |
stw((void *)A0, fpus);
|
1971 |
} |
1972 |
|
1973 |
void OPPROTO op_fnstsw_EAX(void) |
1974 |
{ |
1975 |
int fpus;
|
1976 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
1977 |
EAX = (EAX & 0xffff0000) | fpus;
|
1978 |
} |
1979 |
|
1980 |
void OPPROTO op_fnstcw_A0(void) |
1981 |
{ |
1982 |
stw((void *)A0, env->fpuc);
|
1983 |
} |
1984 |
|
1985 |
void OPPROTO op_fldcw_A0(void) |
1986 |
{ |
1987 |
int rnd_type;
|
1988 |
env->fpuc = lduw((void *)A0);
|
1989 |
/* set rounding mode */
|
1990 |
switch(env->fpuc & RC_MASK) {
|
1991 |
default:
|
1992 |
case RC_NEAR:
|
1993 |
rnd_type = FE_TONEAREST; |
1994 |
break;
|
1995 |
case RC_DOWN:
|
1996 |
rnd_type = FE_DOWNWARD; |
1997 |
break;
|
1998 |
case RC_UP:
|
1999 |
rnd_type = FE_UPWARD; |
2000 |
break;
|
2001 |
case RC_CHOP:
|
2002 |
rnd_type = FE_TOWARDZERO; |
2003 |
break;
|
2004 |
} |
2005 |
fesetround(rnd_type); |
2006 |
} |
2007 |
|
2008 |
void OPPROTO op_fclex(void) |
2009 |
{ |
2010 |
env->fpus &= 0x7f00;
|
2011 |
} |
2012 |
|
2013 |
void OPPROTO op_fninit(void) |
2014 |
{ |
2015 |
env->fpus = 0;
|
2016 |
env->fpstt = 0;
|
2017 |
env->fpuc = 0x37f;
|
2018 |
env->fptags[0] = 1; |
2019 |
env->fptags[1] = 1; |
2020 |
env->fptags[2] = 1; |
2021 |
env->fptags[3] = 1; |
2022 |
env->fptags[4] = 1; |
2023 |
env->fptags[5] = 1; |
2024 |
env->fptags[6] = 1; |
2025 |
env->fptags[7] = 1; |
2026 |
} |
2027 |
|
2028 |
void OPPROTO op_fnstenv_A0(void) |
2029 |
{ |
2030 |
helper_fstenv((uint8_t *)A0, PARAM1); |
2031 |
} |
2032 |
|
2033 |
void OPPROTO op_fldenv_A0(void) |
2034 |
{ |
2035 |
helper_fldenv((uint8_t *)A0, PARAM1); |
2036 |
} |
2037 |
|
2038 |
void OPPROTO op_fnsave_A0(void) |
2039 |
{ |
2040 |
helper_fsave((uint8_t *)A0, PARAM1); |
2041 |
} |
2042 |
|
2043 |
void OPPROTO op_frstor_A0(void) |
2044 |
{ |
2045 |
helper_frstor((uint8_t *)A0, PARAM1); |
2046 |
} |
2047 |
|
2048 |
/* threading support */
|
2049 |
void OPPROTO op_lock(void) |
2050 |
{ |
2051 |
cpu_lock(); |
2052 |
} |
2053 |
|
2054 |
void OPPROTO op_unlock(void) |
2055 |
{ |
2056 |
cpu_unlock(); |
2057 |
} |
2058 |
|