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