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