2 * i386 micro operations
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
20 #include "exec-i386.h"
22 /* NOTE: data are not static to force relocation generation by GCC */
24 uint8_t parity_table
[256] = {
25 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
26 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
27 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
28 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
29 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
30 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
31 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
32 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
33 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
34 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
35 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
36 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
37 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
38 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
39 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
40 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
41 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
42 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
43 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
44 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
45 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
46 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
47 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
48 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
49 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
50 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
51 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
52 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
53 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
54 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
55 CC_P
, 0, 0, CC_P
, 0, CC_P
, CC_P
, 0,
56 0, CC_P
, CC_P
, 0, CC_P
, 0, 0, CC_P
,
60 const uint8_t rclw_table
[32] = {
61 0, 1, 2, 3, 4, 5, 6, 7,
62 8, 9,10,11,12,13,14,15,
63 16, 0, 1, 2, 3, 4, 5, 6,
64 7, 8, 9,10,11,12,13,14,
68 const uint8_t rclb_table
[32] = {
69 0, 1, 2, 3, 4, 5, 6, 7,
70 8, 0, 1, 2, 3, 4, 5, 6,
71 7, 8, 0, 1, 2, 3, 4, 5,
72 6, 7, 8, 0, 1, 2, 3, 4,
76 /* an array of Intel 80-bit FP constants, to be loaded via integer ops */
77 typedef unsigned short f15ld
[5];
80 /*0*/ {0x0000,0x0000,0x0000,0x0000,0x0000},
81 /*1*/ {0x0000,0x0000,0x0000,0x8000,0x3fff},
82 /*pi*/ {0xc235,0x2168,0xdaa2,0xc90f,0x4000},
83 /*lg2*/ {0xf799,0xfbcf,0x9a84,0x9a20,0x3ffd},
84 /*ln2*/ {0x79ac,0xd1cf,0x17f7,0xb172,0x3ffe},
85 /*l2e*/ {0xf0bc,0x5c17,0x3b29,0xb8aa,0x3fff},
86 /*l2t*/ {0x8afe,0xcd1b,0x784b,0xd49a,0x4000}
89 /* the same, 64-bit version */
90 typedef unsigned short f15ld
[4];
93 #ifndef WORDS_BIGENDIAN
94 /*0*/ {0x0000,0x0000,0x0000,0x0000},
95 /*1*/ {0x0000,0x0000,0x0000,0x3ff0},
96 /*pi*/ {0x2d18,0x5444,0x21fb,0x4009},
97 /*lg2*/ {0x79ff,0x509f,0x4413,0x3fd3},
98 /*ln2*/ {0x39ef,0xfefa,0x2e42,0x3fe6},
99 /*l2e*/ {0x82fe,0x652b,0x1547,0x3ff7},
100 /*l2t*/ {0xa371,0x0979,0x934f,0x400a}
102 /*0*/ {0x0000,0x0000,0x0000,0x0000},
103 /*1*/ {0x3ff0,0x0000,0x0000,0x0000},
104 /*pi*/ {0x4009,0x21fb,0x5444,0x2d18},
105 /*lg2*/ {0x3fd3,0x4413,0x509f,0x79ff},
106 /*ln2*/ {0x3fe6,0x2e42,0xfefa,0x39ef},
107 /*l2e*/ {0x3ff7,0x1547,0x652b,0x82fe},
108 /*l2t*/ {0x400a,0x934f,0x0979,0xa371}
113 /* n must be a constant to be efficient */
114 static inline int lshift(int x
, int n
)
122 /* we define the various pieces of code used by the JIT */
126 #include "opreg_template.h"
132 #include "opreg_template.h"
138 #include "opreg_template.h"
144 #include "opreg_template.h"
150 #include "opreg_template.h"
156 #include "opreg_template.h"
162 #include "opreg_template.h"
168 #include "opreg_template.h"
172 /* operations with flags */
174 void OPPROTO
op_addl_T0_T1_cc(void)
181 void OPPROTO
op_orl_T0_T1_cc(void)
187 void OPPROTO
op_andl_T0_T1_cc(void)
193 void OPPROTO
op_subl_T0_T1_cc(void)
200 void OPPROTO
op_xorl_T0_T1_cc(void)
206 void OPPROTO
op_cmpl_T0_T1_cc(void)
212 void OPPROTO
op_negl_T0_cc(void)
219 void OPPROTO
op_incl_T0_cc(void)
221 CC_SRC
= cc_table
[CC_OP
].compute_c();
226 void OPPROTO
op_decl_T0_cc(void)
228 CC_SRC
= cc_table
[CC_OP
].compute_c();
233 void OPPROTO
op_testl_T0_T1_cc(void)
238 /* operations without flags */
240 void OPPROTO
op_addl_T0_T1(void)
245 void OPPROTO
op_orl_T0_T1(void)
250 void OPPROTO
op_andl_T0_T1(void)
255 void OPPROTO
op_subl_T0_T1(void)
260 void OPPROTO
op_xorl_T0_T1(void)
265 void OPPROTO
op_negl_T0(void)
270 void OPPROTO
op_incl_T0(void)
275 void OPPROTO
op_decl_T0(void)
280 void OPPROTO
op_notl_T0(void)
285 void OPPROTO
op_bswapl_T0(void)
290 /* multiply/divide */
291 void OPPROTO
op_mulb_AL_T0(void)
294 res
= (uint8_t)EAX
* (uint8_t)T0
;
295 EAX
= (EAX
& 0xffff0000) | res
;
296 CC_SRC
= (res
& 0xff00);
299 void OPPROTO
op_imulb_AL_T0(void)
302 res
= (int8_t)EAX
* (int8_t)T0
;
303 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
304 CC_SRC
= (res
!= (int8_t)res
);
307 void OPPROTO
op_mulw_AX_T0(void)
310 res
= (uint16_t)EAX
* (uint16_t)T0
;
311 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
312 EDX
= (EDX
& 0xffff0000) | ((res
>> 16) & 0xffff);
316 void OPPROTO
op_imulw_AX_T0(void)
319 res
= (int16_t)EAX
* (int16_t)T0
;
320 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
321 EDX
= (EDX
& 0xffff0000) | ((res
>> 16) & 0xffff);
322 CC_SRC
= (res
!= (int16_t)res
);
325 void OPPROTO
op_mull_EAX_T0(void)
328 res
= (uint64_t)((uint32_t)EAX
) * (uint64_t)((uint32_t)T0
);
334 void OPPROTO
op_imull_EAX_T0(void)
337 res
= (int64_t)((int32_t)EAX
) * (int64_t)((int32_t)T0
);
340 CC_SRC
= (res
!= (int32_t)res
);
343 void OPPROTO
op_imulw_T0_T1(void)
346 res
= (int16_t)T0
* (int16_t)T1
;
348 CC_SRC
= (res
!= (int16_t)res
);
351 void OPPROTO
op_imull_T0_T1(void)
354 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
356 CC_SRC
= (res
!= (int32_t)res
);
359 /* division, flags are undefined */
360 /* XXX: add exceptions for overflow */
361 void OPPROTO
op_divb_AL_T0(void)
363 unsigned int num
, den
, q
, r
;
365 num
= (EAX
& 0xffff);
368 raise_exception(EXCP00_DIVZ
);
369 q
= (num
/ den
) & 0xff;
370 r
= (num
% den
) & 0xff;
371 EAX
= (EAX
& 0xffff0000) | (r
<< 8) | q
;
374 void OPPROTO
op_idivb_AL_T0(void)
381 raise_exception(EXCP00_DIVZ
);
382 q
= (num
/ den
) & 0xff;
383 r
= (num
% den
) & 0xff;
384 EAX
= (EAX
& 0xffff0000) | (r
<< 8) | q
;
387 void OPPROTO
op_divw_AX_T0(void)
389 unsigned int num
, den
, q
, r
;
391 num
= (EAX
& 0xffff) | ((EDX
& 0xffff) << 16);
394 raise_exception(EXCP00_DIVZ
);
395 q
= (num
/ den
) & 0xffff;
396 r
= (num
% den
) & 0xffff;
397 EAX
= (EAX
& 0xffff0000) | q
;
398 EDX
= (EDX
& 0xffff0000) | r
;
401 void OPPROTO
op_idivw_AX_T0(void)
405 num
= (EAX
& 0xffff) | ((EDX
& 0xffff) << 16);
408 raise_exception(EXCP00_DIVZ
);
409 q
= (num
/ den
) & 0xffff;
410 r
= (num
% den
) & 0xffff;
411 EAX
= (EAX
& 0xffff0000) | q
;
412 EDX
= (EDX
& 0xffff0000) | r
;
415 #ifdef BUGGY_GCC_DIV64
416 /* gcc 2.95.4 on PowerPC does not seem to like using __udivdi3, so we
417 call it from another function */
418 uint32_t div64(uint32_t *q_ptr
, uint64_t num
, uint32_t den
)
424 int32_t idiv64(int32_t *q_ptr
, int64_t num
, int32_t den
)
431 void OPPROTO
op_divl_EAX_T0(void)
433 unsigned int den
, q
, r
;
436 num
= EAX
| ((uint64_t)EDX
<< 32);
439 raise_exception(EXCP00_DIVZ
);
440 #ifdef BUGGY_GCC_DIV64
441 r
= div64(&q
, num
, den
);
450 void OPPROTO
op_idivl_EAX_T0(void)
455 num
= EAX
| ((uint64_t)EDX
<< 32);
458 raise_exception(EXCP00_DIVZ
);
459 #ifdef BUGGY_GCC_DIV64
460 r
= idiv64(&q
, num
, den
);
469 /* constant load & misc op */
471 void OPPROTO
op_movl_T0_im(void)
476 void OPPROTO
op_addl_T0_im(void)
481 void OPPROTO
op_andl_T0_ffff(void)
486 void OPPROTO
op_movl_T0_T1(void)
491 void OPPROTO
op_movl_T1_im(void)
496 void OPPROTO
op_addl_T1_im(void)
501 void OPPROTO
op_movl_T1_A0(void)
506 void OPPROTO
op_movl_A0_im(void)
511 void OPPROTO
op_addl_A0_im(void)
516 void OPPROTO
op_addl_A0_AL(void)
521 void OPPROTO
op_andl_A0_ffff(void)
528 void OPPROTO
op_ldub_T0_A0(void)
530 T0
= ldub((uint8_t *)A0
);
533 void OPPROTO
op_ldsb_T0_A0(void)
535 T0
= ldsb((int8_t *)A0
);
538 void OPPROTO
op_lduw_T0_A0(void)
540 T0
= lduw((uint8_t *)A0
);
543 void OPPROTO
op_ldsw_T0_A0(void)
545 T0
= ldsw((int8_t *)A0
);
548 void OPPROTO
op_ldl_T0_A0(void)
550 T0
= ldl((uint8_t *)A0
);
553 void OPPROTO
op_ldub_T1_A0(void)
555 T1
= ldub((uint8_t *)A0
);
558 void OPPROTO
op_ldsb_T1_A0(void)
560 T1
= ldsb((int8_t *)A0
);
563 void OPPROTO
op_lduw_T1_A0(void)
565 T1
= lduw((uint8_t *)A0
);
568 void OPPROTO
op_ldsw_T1_A0(void)
570 T1
= ldsw((int8_t *)A0
);
573 void OPPROTO
op_ldl_T1_A0(void)
575 T1
= ldl((uint8_t *)A0
);
578 void OPPROTO
op_stb_T0_A0(void)
580 stb((uint8_t *)A0
, T0
);
583 void OPPROTO
op_stw_T0_A0(void)
585 stw((uint8_t *)A0
, T0
);
588 void OPPROTO
op_stl_T0_A0(void)
590 stl((uint8_t *)A0
, T0
);
593 /* used for bit operations */
595 void OPPROTO
op_add_bitw_A0_T1(void)
597 A0
+= ((int32_t)T1
>> 4) << 1;
600 void OPPROTO
op_add_bitl_A0_T1(void)
602 A0
+= ((int32_t)T1
>> 5) << 2;
607 void OPPROTO
op_jmp_T0(void)
612 void OPPROTO
op_jmp_im(void)
617 void OPPROTO
op_int_im(void)
620 raise_exception(EXCP0D_GPF
);
623 void OPPROTO
op_int3(void)
626 raise_exception(EXCP03_INT3
);
629 void OPPROTO
op_into(void)
632 eflags
= cc_table
[CC_OP
].compute_all();
634 raise_exception(EXCP04_INTO
);
638 /* XXX: add IOPL/CPL tests */
639 void OPPROTO
op_cli(void)
641 raise_exception(EXCP0D_GPF
);
644 /* XXX: add IOPL/CPL tests */
645 void OPPROTO
op_sti(void)
647 raise_exception(EXCP0D_GPF
);
650 /* vm86plus instructions */
652 void OPPROTO
op_cli_vm(void)
654 env
->eflags
&= ~VIF_MASK
;
657 void OPPROTO
op_sti_vm(void)
659 env
->eflags
|= VIF_MASK
;
660 if (env
->eflags
& VIP_MASK
) {
662 raise_exception(EXCP0D_GPF
);
667 void OPPROTO
op_boundw(void)
670 low
= ldsw((uint8_t *)A0
);
671 high
= ldsw((uint8_t *)A0
+ 2);
673 if (v
< low
|| v
> high
)
674 raise_exception(EXCP05_BOUND
);
678 void OPPROTO
op_boundl(void)
681 low
= ldl((uint8_t *)A0
);
682 high
= ldl((uint8_t *)A0
+ 4);
684 if (v
< low
|| v
> high
)
685 raise_exception(EXCP05_BOUND
);
689 void OPPROTO
op_cmpxchg8b(void)
694 eflags
= cc_table
[CC_OP
].compute_all();
695 d
= ldq((uint8_t *)A0
);
696 if (d
== (((uint64_t)EDX
<< 32) | EAX
)) {
697 stq((uint8_t *)A0
, ((uint64_t)ECX
<< 32) | EBX
);
713 #include "ops_template.h"
717 #include "ops_template.h"
721 #include "ops_template.h"
726 void OPPROTO
op_movsbl_T0_T0(void)
731 void OPPROTO
op_movzbl_T0_T0(void)
736 void OPPROTO
op_movswl_T0_T0(void)
741 void OPPROTO
op_movzwl_T0_T0(void)
746 void OPPROTO
op_movswl_EAX_AX(void)
751 void OPPROTO
op_movsbw_AX_AL(void)
753 EAX
= (EAX
& 0xffff0000) | ((int8_t)EAX
& 0xffff);
756 void OPPROTO
op_movslq_EDX_EAX(void)
758 EDX
= (int32_t)EAX
>> 31;
761 void OPPROTO
op_movswl_DX_AX(void)
763 EDX
= (EDX
& 0xffff0000) | (((int16_t)EAX
>> 15) & 0xffff);
768 void op_pushl_T0(void)
772 stl((void *)offset
, T0
);
773 /* modify ESP after to handle exceptions correctly */
777 void op_pushw_T0(void)
781 stw((void *)offset
, T0
);
782 /* modify ESP after to handle exceptions correctly */
786 void op_pushl_ss32_T0(void)
790 stl(env
->seg_cache
[R_SS
].base
+ offset
, T0
);
791 /* modify ESP after to handle exceptions correctly */
795 void op_pushw_ss32_T0(void)
799 stw(env
->seg_cache
[R_SS
].base
+ offset
, T0
);
800 /* modify ESP after to handle exceptions correctly */
804 void op_pushl_ss16_T0(void)
807 offset
= (ESP
- 4) & 0xffff;
808 stl(env
->seg_cache
[R_SS
].base
+ offset
, T0
);
809 /* modify ESP after to handle exceptions correctly */
810 ESP
= (ESP
& ~0xffff) | offset
;
813 void op_pushw_ss16_T0(void)
816 offset
= (ESP
- 2) & 0xffff;
817 stw(env
->seg_cache
[R_SS
].base
+ offset
, T0
);
818 /* modify ESP after to handle exceptions correctly */
819 ESP
= (ESP
& ~0xffff) | offset
;
822 /* NOTE: ESP update is done after */
823 void op_popl_T0(void)
825 T0
= ldl((void *)ESP
);
828 void op_popw_T0(void)
830 T0
= lduw((void *)ESP
);
833 void op_popl_ss32_T0(void)
835 T0
= ldl(env
->seg_cache
[R_SS
].base
+ ESP
);
838 void op_popw_ss32_T0(void)
840 T0
= lduw(env
->seg_cache
[R_SS
].base
+ ESP
);
843 void op_popl_ss16_T0(void)
845 T0
= ldl(env
->seg_cache
[R_SS
].base
+ (ESP
& 0xffff));
848 void op_popw_ss16_T0(void)
850 T0
= lduw(env
->seg_cache
[R_SS
].base
+ (ESP
& 0xffff));
853 void op_addl_ESP_4(void)
858 void op_addl_ESP_2(void)
863 void op_addw_ESP_4(void)
865 ESP
= (ESP
& ~0xffff) | ((ESP
+ 4) & 0xffff);
868 void op_addw_ESP_2(void)
870 ESP
= (ESP
& ~0xffff) | ((ESP
+ 2) & 0xffff);
873 void op_addl_ESP_im(void)
878 void op_addw_ESP_im(void)
880 ESP
= (ESP
& ~0xffff) | ((ESP
+ PARAM1
) & 0xffff);
888 void OPPROTO
op_rdtsc(void)
892 asm("rdtsc" : "=A" (val
));
894 /* better than nothing: the time increases */
901 /* We simulate a pre-MMX pentium as in valgrind */
902 #define CPUID_FP87 (1 << 0)
903 #define CPUID_VME (1 << 1)
904 #define CPUID_DE (1 << 2)
905 #define CPUID_PSE (1 << 3)
906 #define CPUID_TSC (1 << 4)
907 #define CPUID_MSR (1 << 5)
908 #define CPUID_PAE (1 << 6)
909 #define CPUID_MCE (1 << 7)
910 #define CPUID_CX8 (1 << 8)
911 #define CPUID_APIC (1 << 9)
912 #define CPUID_SEP (1 << 11) /* sysenter/sysexit */
913 #define CPUID_MTRR (1 << 12)
914 #define CPUID_PGE (1 << 13)
915 #define CPUID_MCA (1 << 14)
916 #define CPUID_CMOV (1 << 15)
918 #define CPUID_MMX (1 << 23)
919 #define CPUID_FXSR (1 << 24)
920 #define CPUID_SSE (1 << 25)
921 #define CPUID_SSE2 (1 << 26)
923 void helper_cpuid(void)
926 EAX
= 1; /* max EAX index supported */
935 EDX
= CPUID_FP87
| CPUID_VME
| CPUID_DE
| CPUID_PSE
|
936 CPUID_TSC
| CPUID_MSR
| CPUID_MCE
|
941 void OPPROTO
op_cpuid(void)
949 void OPPROTO
op_aam(void)
956 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
960 void OPPROTO
op_aad(void)
965 ah
= (EAX
>> 8) & 0xff;
966 al
= ((ah
* base
) + al
) & 0xff;
967 EAX
= (EAX
& ~0xffff) | al
;
971 void OPPROTO
op_aaa(void)
977 eflags
= cc_table
[CC_OP
].compute_all();
980 ah
= (EAX
>> 8) & 0xff;
982 icarry
= (al
> 0xf9);
983 if (((al
& 0x0f) > 9 ) || af
) {
984 al
= (al
+ 6) & 0x0f;
985 ah
= (ah
+ 1 + icarry
) & 0xff;
986 eflags
|= CC_C
| CC_A
;
988 eflags
&= ~(CC_C
| CC_A
);
991 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
995 void OPPROTO
op_aas(void)
1001 eflags
= cc_table
[CC_OP
].compute_all();
1004 ah
= (EAX
>> 8) & 0xff;
1007 if (((al
& 0x0f) > 9 ) || af
) {
1008 al
= (al
- 6) & 0x0f;
1009 ah
= (ah
- 1 - icarry
) & 0xff;
1010 eflags
|= CC_C
| CC_A
;
1012 eflags
&= ~(CC_C
| CC_A
);
1015 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
1019 void OPPROTO
op_daa(void)
1024 eflags
= cc_table
[CC_OP
].compute_all();
1030 if (((al
& 0x0f) > 9 ) || af
) {
1031 al
= (al
+ 6) & 0xff;
1034 if ((al
> 0x9f) || cf
) {
1035 al
= (al
+ 0x60) & 0xff;
1038 EAX
= (EAX
& ~0xff) | al
;
1039 /* well, speed is not an issue here, so we compute the flags by hand */
1040 eflags
|= (al
== 0) << 6; /* zf */
1041 eflags
|= parity_table
[al
]; /* pf */
1042 eflags
|= (al
& 0x80); /* sf */
1046 void OPPROTO
op_das(void)
1048 int al
, al1
, af
, cf
;
1051 eflags
= cc_table
[CC_OP
].compute_all();
1058 if (((al
& 0x0f) > 9 ) || af
) {
1062 al
= (al
- 6) & 0xff;
1064 if ((al1
> 0x99) || cf
) {
1065 al
= (al
- 0x60) & 0xff;
1068 EAX
= (EAX
& ~0xff) | al
;
1069 /* well, speed is not an issue here, so we compute the flags by hand */
1070 eflags
|= (al
== 0) << 6; /* zf */
1071 eflags
|= parity_table
[al
]; /* pf */
1072 eflags
|= (al
& 0x80); /* sf */
1076 /* segment handling */
1078 /* XXX: use static VM86 information */
1079 void load_seg(int seg_reg
, int selector
)
1082 SegmentDescriptorTable
*dt
;
1087 env
->segs
[seg_reg
] = selector
;
1088 sc
= &env
->seg_cache
[seg_reg
];
1089 if (env
->eflags
& VM_MASK
) {
1090 sc
->base
= (void *)(selector
<< 4);
1098 index
= selector
& ~7;
1099 if ((index
+ 7) > dt
->limit
)
1100 raise_exception(EXCP0D_GPF
);
1101 ptr
= dt
->base
+ index
;
1104 sc
->base
= (void *)((e1
>> 16) | ((e2
& 0xff) << 16) | (e2
& 0xff000000));
1105 sc
->limit
= (e1
& 0xffff) | (e2
& 0x000f0000);
1107 sc
->limit
= (sc
->limit
<< 12) | 0xfff;
1108 sc
->seg_32bit
= (e2
>> 22) & 1;
1110 fprintf(logfile
, "load_seg: sel=0x%04x base=0x%08lx limit=0x%08lx seg_32bit=%d\n",
1111 selector
, (unsigned long)sc
->base
, sc
->limit
, sc
->seg_32bit
);
1116 void OPPROTO
op_movl_seg_T0(void)
1118 load_seg(PARAM1
, T0
& 0xffff);
1121 void OPPROTO
op_movl_T0_seg(void)
1123 T0
= env
->segs
[PARAM1
];
1126 void OPPROTO
op_movl_A0_seg(void)
1128 A0
= *(unsigned long *)((char *)env
+ PARAM1
);
1131 void OPPROTO
op_addl_A0_seg(void)
1133 A0
+= *(unsigned long *)((char *)env
+ PARAM1
);
1136 /* flags handling */
1138 /* slow jumps cases (compute x86 flags) */
1139 void OPPROTO
op_jo_cc(void)
1142 eflags
= cc_table
[CC_OP
].compute_all();
1150 void OPPROTO
op_jb_cc(void)
1152 if (cc_table
[CC_OP
].compute_c())
1159 void OPPROTO
op_jz_cc(void)
1162 eflags
= cc_table
[CC_OP
].compute_all();
1170 void OPPROTO
op_jbe_cc(void)
1173 eflags
= cc_table
[CC_OP
].compute_all();
1174 if (eflags
& (CC_Z
| CC_C
))
1181 void OPPROTO
op_js_cc(void)
1184 eflags
= cc_table
[CC_OP
].compute_all();
1192 void OPPROTO
op_jp_cc(void)
1195 eflags
= cc_table
[CC_OP
].compute_all();
1203 void OPPROTO
op_jl_cc(void)
1206 eflags
= cc_table
[CC_OP
].compute_all();
1207 if ((eflags
^ (eflags
>> 4)) & 0x80)
1214 void OPPROTO
op_jle_cc(void)
1217 eflags
= cc_table
[CC_OP
].compute_all();
1218 if (((eflags
^ (eflags
>> 4)) & 0x80) || (eflags
& CC_Z
))
1225 /* slow set cases (compute x86 flags) */
1226 void OPPROTO
op_seto_T0_cc(void)
1229 eflags
= cc_table
[CC_OP
].compute_all();
1230 T0
= (eflags
>> 11) & 1;
1233 void OPPROTO
op_setb_T0_cc(void)
1235 T0
= cc_table
[CC_OP
].compute_c();
1238 void OPPROTO
op_setz_T0_cc(void)
1241 eflags
= cc_table
[CC_OP
].compute_all();
1242 T0
= (eflags
>> 6) & 1;
1245 void OPPROTO
op_setbe_T0_cc(void)
1248 eflags
= cc_table
[CC_OP
].compute_all();
1249 T0
= (eflags
& (CC_Z
| CC_C
)) != 0;
1252 void OPPROTO
op_sets_T0_cc(void)
1255 eflags
= cc_table
[CC_OP
].compute_all();
1256 T0
= (eflags
>> 7) & 1;
1259 void OPPROTO
op_setp_T0_cc(void)
1262 eflags
= cc_table
[CC_OP
].compute_all();
1263 T0
= (eflags
>> 2) & 1;
1266 void OPPROTO
op_setl_T0_cc(void)
1269 eflags
= cc_table
[CC_OP
].compute_all();
1270 T0
= ((eflags
^ (eflags
>> 4)) >> 7) & 1;
1273 void OPPROTO
op_setle_T0_cc(void)
1276 eflags
= cc_table
[CC_OP
].compute_all();
1277 T0
= (((eflags
^ (eflags
>> 4)) & 0x80) || (eflags
& CC_Z
)) != 0;
1280 void OPPROTO
op_xor_T0_1(void)
1285 void OPPROTO
op_set_cc_op(void)
1290 #define FL_UPDATE_MASK32 (TF_MASK | AC_MASK | ID_MASK)
1291 #define FL_UPDATE_MASK16 (TF_MASK)
1293 void OPPROTO
op_movl_eflags_T0(void)
1297 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1298 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1299 /* we also update some system flags as in user mode */
1300 env
->eflags
= (env
->eflags
& ~FL_UPDATE_MASK32
) | (eflags
& FL_UPDATE_MASK32
);
1303 void OPPROTO
op_movw_eflags_T0(void)
1307 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1308 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1309 /* we also update some system flags as in user mode */
1310 env
->eflags
= (env
->eflags
& ~FL_UPDATE_MASK16
) | (eflags
& FL_UPDATE_MASK16
);
1314 void OPPROTO
op_movw_eflags_T0_vm(void)
1318 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1319 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1320 /* we also update some system flags as in user mode */
1321 env
->eflags
= (env
->eflags
& ~(FL_UPDATE_MASK16
| VIF_MASK
)) |
1322 (eflags
& FL_UPDATE_MASK16
);
1323 if (eflags
& IF_MASK
) {
1324 env
->eflags
|= VIF_MASK
;
1325 if (env
->eflags
& VIP_MASK
) {
1327 raise_exception(EXCP0D_GPF
);
1333 void OPPROTO
op_movl_eflags_T0_vm(void)
1337 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1338 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1339 /* we also update some system flags as in user mode */
1340 env
->eflags
= (env
->eflags
& ~(FL_UPDATE_MASK32
| VIF_MASK
)) |
1341 (eflags
& FL_UPDATE_MASK32
);
1342 if (eflags
& IF_MASK
) {
1343 env
->eflags
|= VIF_MASK
;
1344 if (env
->eflags
& VIP_MASK
) {
1346 raise_exception(EXCP0D_GPF
);
1352 /* XXX: compute only O flag */
1353 void OPPROTO
op_movb_eflags_T0(void)
1356 of
= cc_table
[CC_OP
].compute_all() & CC_O
;
1357 CC_SRC
= (T0
& (CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
)) | of
;
1360 void OPPROTO
op_movl_T0_eflags(void)
1363 eflags
= cc_table
[CC_OP
].compute_all();
1364 eflags
|= (DF
& DF_MASK
);
1365 eflags
|= env
->eflags
& ~(VM_MASK
| RF_MASK
);
1370 void OPPROTO
op_movl_T0_eflags_vm(void)
1373 eflags
= cc_table
[CC_OP
].compute_all();
1374 eflags
|= (DF
& DF_MASK
);
1375 eflags
|= env
->eflags
& ~(VM_MASK
| RF_MASK
| IF_MASK
);
1376 if (env
->eflags
& VIF_MASK
)
1381 void OPPROTO
op_cld(void)
1386 void OPPROTO
op_std(void)
1391 void OPPROTO
op_clc(void)
1394 eflags
= cc_table
[CC_OP
].compute_all();
1399 void OPPROTO
op_stc(void)
1402 eflags
= cc_table
[CC_OP
].compute_all();
1407 void OPPROTO
op_cmc(void)
1410 eflags
= cc_table
[CC_OP
].compute_all();
1415 void OPPROTO
op_salc(void)
1418 cf
= cc_table
[CC_OP
].compute_c();
1419 EAX
= (EAX
& ~0xff) | ((-cf
) & 0xff);
1422 static int compute_all_eflags(void)
1427 static int compute_c_eflags(void)
1429 return CC_SRC
& CC_C
;
1432 static int compute_c_mul(void)
1439 static int compute_all_mul(void)
1441 int cf
, pf
, af
, zf
, sf
, of
;
1443 pf
= 0; /* undefined */
1444 af
= 0; /* undefined */
1445 zf
= 0; /* undefined */
1446 sf
= 0; /* undefined */
1448 return cf
| pf
| af
| zf
| sf
| of
;
1451 CCTable cc_table
[CC_OP_NB
] = {
1452 [CC_OP_DYNAMIC
] = { /* should never happen */ },
1454 [CC_OP_EFLAGS
] = { compute_all_eflags
, compute_c_eflags
},
1456 [CC_OP_MUL
] = { compute_all_mul
, compute_c_mul
},
1458 [CC_OP_ADDB
] = { compute_all_addb
, compute_c_addb
},
1459 [CC_OP_ADDW
] = { compute_all_addw
, compute_c_addw
},
1460 [CC_OP_ADDL
] = { compute_all_addl
, compute_c_addl
},
1462 [CC_OP_ADCB
] = { compute_all_adcb
, compute_c_adcb
},
1463 [CC_OP_ADCW
] = { compute_all_adcw
, compute_c_adcw
},
1464 [CC_OP_ADCL
] = { compute_all_adcl
, compute_c_adcl
},
1466 [CC_OP_SUBB
] = { compute_all_subb
, compute_c_subb
},
1467 [CC_OP_SUBW
] = { compute_all_subw
, compute_c_subw
},
1468 [CC_OP_SUBL
] = { compute_all_subl
, compute_c_subl
},
1470 [CC_OP_SBBB
] = { compute_all_sbbb
, compute_c_sbbb
},
1471 [CC_OP_SBBW
] = { compute_all_sbbw
, compute_c_sbbw
},
1472 [CC_OP_SBBL
] = { compute_all_sbbl
, compute_c_sbbl
},
1474 [CC_OP_LOGICB
] = { compute_all_logicb
, compute_c_logicb
},
1475 [CC_OP_LOGICW
] = { compute_all_logicw
, compute_c_logicw
},
1476 [CC_OP_LOGICL
] = { compute_all_logicl
, compute_c_logicl
},
1478 [CC_OP_INCB
] = { compute_all_incb
, compute_c_incl
},
1479 [CC_OP_INCW
] = { compute_all_incw
, compute_c_incl
},
1480 [CC_OP_INCL
] = { compute_all_incl
, compute_c_incl
},
1482 [CC_OP_DECB
] = { compute_all_decb
, compute_c_incl
},
1483 [CC_OP_DECW
] = { compute_all_decw
, compute_c_incl
},
1484 [CC_OP_DECL
] = { compute_all_decl
, compute_c_incl
},
1486 [CC_OP_SHLB
] = { compute_all_shlb
, compute_c_shll
},
1487 [CC_OP_SHLW
] = { compute_all_shlw
, compute_c_shll
},
1488 [CC_OP_SHLL
] = { compute_all_shll
, compute_c_shll
},
1490 [CC_OP_SARB
] = { compute_all_sarb
, compute_c_shll
},
1491 [CC_OP_SARW
] = { compute_all_sarw
, compute_c_shll
},
1492 [CC_OP_SARL
] = { compute_all_sarl
, compute_c_shll
},
1495 /* floating point support. Some of the code for complicated x87
1496 functions comes from the LGPL'ed x86 emulator found in the Willows
1497 TWIN windows emulator. */
1499 #ifdef USE_X86LDOUBLE
1500 /* use long double functions */
1501 #define lrint lrintl
1502 #define llrint llrintl
1510 #define atan2 atan2l
1511 #define floor floorl
1516 extern int lrint(CPU86_LDouble x
);
1517 extern int64_t llrint(CPU86_LDouble x
);
1518 extern CPU86_LDouble
fabs(CPU86_LDouble x
);
1519 extern CPU86_LDouble
sin(CPU86_LDouble x
);
1520 extern CPU86_LDouble
cos(CPU86_LDouble x
);
1521 extern CPU86_LDouble
sqrt(CPU86_LDouble x
);
1522 extern CPU86_LDouble
pow(CPU86_LDouble
, CPU86_LDouble
);
1523 extern CPU86_LDouble
log(CPU86_LDouble x
);
1524 extern CPU86_LDouble
tan(CPU86_LDouble x
);
1525 extern CPU86_LDouble
atan2(CPU86_LDouble
, CPU86_LDouble
);
1526 extern CPU86_LDouble
floor(CPU86_LDouble x
);
1527 extern CPU86_LDouble
ceil(CPU86_LDouble x
);
1528 extern CPU86_LDouble
rint(CPU86_LDouble x
);
1530 #if defined(__powerpc__)
1531 extern CPU86_LDouble
copysign(CPU86_LDouble
, CPU86_LDouble
);
1533 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
1534 double qemu_rint(double x
)
1536 double y
= 4503599627370496.0;
1547 #define rint qemu_rint
1550 #define RC_MASK 0xc00
1551 #define RC_NEAR 0x000
1552 #define RC_DOWN 0x400
1554 #define RC_CHOP 0xc00
1556 #define MAXTAN 9223372036854775808.0
1558 #ifdef USE_X86LDOUBLE
1564 unsigned long long lower
;
1565 unsigned short upper
;
1569 /* the following deal with x86 long double-precision numbers */
1570 #define MAXEXPD 0x7fff
1571 #define EXPBIAS 16383
1572 #define EXPD(fp) (fp.l.upper & 0x7fff)
1573 #define SIGND(fp) ((fp.l.upper) & 0x8000)
1574 #define MANTD(fp) (fp.l.lower)
1575 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
1581 #ifndef WORDS_BIGENDIAN
1583 unsigned long lower
;
1589 unsigned long lower
;
1595 /* the following deal with IEEE double-precision numbers */
1596 #define MAXEXPD 0x7ff
1597 #define EXPBIAS 1023
1598 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
1599 #define SIGND(fp) ((fp.l.upper) & 0x80000000)
1600 #define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
1601 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
1606 void OPPROTO
op_flds_FT0_A0(void)
1608 FT0
= ldfl((void *)A0
);
1611 void OPPROTO
op_fldl_FT0_A0(void)
1613 FT0
= ldfq((void *)A0
);
1616 /* helpers are needed to avoid static constant reference. XXX: find a better way */
1617 #ifdef USE_INT_TO_FLOAT_HELPERS
1619 void helper_fild_FT0_A0(void)
1621 FT0
= (CPU86_LDouble
)ldsw((void *)A0
);
1624 void helper_fildl_FT0_A0(void)
1626 FT0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1629 void helper_fildll_FT0_A0(void)
1631 FT0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1634 void OPPROTO
op_fild_FT0_A0(void)
1636 helper_fild_FT0_A0();
1639 void OPPROTO
op_fildl_FT0_A0(void)
1641 helper_fildl_FT0_A0();
1644 void OPPROTO
op_fildll_FT0_A0(void)
1646 helper_fildll_FT0_A0();
1651 void OPPROTO
op_fild_FT0_A0(void)
1653 FT0
= (CPU86_LDouble
)ldsw((void *)A0
);
1656 void OPPROTO
op_fildl_FT0_A0(void)
1658 FT0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1661 void OPPROTO
op_fildll_FT0_A0(void)
1663 FT0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1669 void OPPROTO
op_flds_ST0_A0(void)
1671 ST0
= ldfl((void *)A0
);
1674 void OPPROTO
op_fldl_ST0_A0(void)
1676 ST0
= ldfq((void *)A0
);
1679 #ifdef USE_X86LDOUBLE
1680 void OPPROTO
op_fldt_ST0_A0(void)
1682 ST0
= *(long double *)A0
;
1685 void helper_fldt_ST0_A0(void)
1687 CPU86_LDoubleU temp
;
1690 upper
= lduw((uint8_t *)A0
+ 8);
1691 /* XXX: handle overflow ? */
1692 e
= (upper
& 0x7fff) - 16383 + EXPBIAS
; /* exponent */
1693 e
|= (upper
>> 4) & 0x800; /* sign */
1694 temp
.ll
= ((ldq((void *)A0
) >> 11) & ((1LL << 52) - 1)) | ((uint64_t)e
<< 52);
1698 void OPPROTO
op_fldt_ST0_A0(void)
1700 helper_fldt_ST0_A0();
1704 /* helpers are needed to avoid static constant reference. XXX: find a better way */
1705 #ifdef USE_INT_TO_FLOAT_HELPERS
1707 void helper_fild_ST0_A0(void)
1709 ST0
= (CPU86_LDouble
)ldsw((void *)A0
);
1712 void helper_fildl_ST0_A0(void)
1714 ST0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1717 void helper_fildll_ST0_A0(void)
1719 ST0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1722 void OPPROTO
op_fild_ST0_A0(void)
1724 helper_fild_ST0_A0();
1727 void OPPROTO
op_fildl_ST0_A0(void)
1729 helper_fildl_ST0_A0();
1732 void OPPROTO
op_fildll_ST0_A0(void)
1734 helper_fildll_ST0_A0();
1739 void OPPROTO
op_fild_ST0_A0(void)
1741 ST0
= (CPU86_LDouble
)ldsw((void *)A0
);
1744 void OPPROTO
op_fildl_ST0_A0(void)
1746 ST0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1749 void OPPROTO
op_fildll_ST0_A0(void)
1751 ST0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1758 void OPPROTO
op_fsts_ST0_A0(void)
1760 stfl((void *)A0
, (float)ST0
);
1763 void OPPROTO
op_fstl_ST0_A0(void)
1765 stfq((void *)A0
, (double)ST0
);
1768 #ifdef USE_X86LDOUBLE
1769 void OPPROTO
op_fstt_ST0_A0(void)
1771 *(long double *)A0
= ST0
;
1774 void helper_fstt_ST0_A0(void)
1776 CPU86_LDoubleU temp
;
1780 stq((void *)A0
, (MANTD(temp
) << 11) | (1LL << 63));
1781 /* exponent + sign */
1782 e
= EXPD(temp
) - EXPBIAS
+ 16383;
1783 e
|= SIGND(temp
) >> 16;
1784 stw((uint8_t *)A0
+ 8, e
);
1787 void OPPROTO
op_fstt_ST0_A0(void)
1789 helper_fstt_ST0_A0();
1793 void OPPROTO
op_fist_ST0_A0(void)
1797 stw((void *)A0
, val
);
1800 void OPPROTO
op_fistl_ST0_A0(void)
1804 stl((void *)A0
, val
);
1807 void OPPROTO
op_fistll_ST0_A0(void)
1811 stq((void *)A0
, val
);
1816 #define MUL10(iv) ( iv + iv + (iv << 3) )
1818 void helper_fbld_ST0_A0(void)
1821 CPU86_LDouble fpsrcop
;
1825 /* in this code, seg/m32i will be used as temporary ptr/int */
1826 seg
= (uint8_t *)A0
+ 8;
1828 /* XXX: raise exception */
1832 /* XXX: raise exception */
1833 if ((v
& 0xf0) != 0)
1835 m32i
= v
; /* <-- d14 */
1837 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d13 */
1838 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d12 */
1840 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d11 */
1841 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d10 */
1843 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d9 */
1844 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d8 */
1845 fpsrcop
= ((CPU86_LDouble
)m32i
) * 100000000.0;
1848 m32i
= (v
>> 4); /* <-- d7 */
1849 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d6 */
1851 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d5 */
1852 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d4 */
1854 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d3 */
1855 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d2 */
1857 m32i
= MUL10(m32i
) + (v
>> 4); /* <-- val * 10 + d1 */
1858 m32i
= MUL10(m32i
) + (v
& 0xf); /* <-- val * 10 + d0 */
1859 fpsrcop
+= ((CPU86_LDouble
)m32i
);
1860 if ( ldub(seg
+9) & 0x80 )
1865 void OPPROTO
op_fbld_ST0_A0(void)
1867 helper_fbld_ST0_A0();
1870 void helper_fbst_ST0_A0(void)
1872 CPU86_LDouble fptemp
;
1873 CPU86_LDouble fpsrcop
;
1875 uint8_t *mem_ref
, *mem_end
;
1877 fpsrcop
= rint(ST0
);
1878 mem_ref
= (uint8_t *)A0
;
1879 mem_end
= mem_ref
+ 8;
1880 if ( fpsrcop
< 0.0 ) {
1881 stw(mem_end
, 0x8000);
1884 stw(mem_end
, 0x0000);
1886 while (mem_ref
< mem_end
) {
1889 fptemp
= floor(fpsrcop
/10.0);
1890 v
= ((int)(fpsrcop
- fptemp
*10.0));
1891 if (fptemp
== 0.0) {
1896 fptemp
= floor(fpsrcop
/10.0);
1897 v
|= (((int)(fpsrcop
- fptemp
*10.0)) << 4);
1901 while (mem_ref
< mem_end
) {
1906 void OPPROTO
op_fbst_ST0_A0(void)
1908 helper_fbst_ST0_A0();
1913 static inline void fpush(void)
1915 env
->fpstt
= (env
->fpstt
- 1) & 7;
1916 env
->fptags
[env
->fpstt
] = 0; /* validate stack entry */
1919 static inline void fpop(void)
1921 env
->fptags
[env
->fpstt
] = 1; /* invvalidate stack entry */
1922 env
->fpstt
= (env
->fpstt
+ 1) & 7;
1925 void OPPROTO
op_fpush(void)
1930 void OPPROTO
op_fpop(void)
1935 void OPPROTO
op_fdecstp(void)
1937 env
->fpstt
= (env
->fpstt
- 1) & 7;
1938 env
->fpus
&= (~0x4700);
1941 void OPPROTO
op_fincstp(void)
1943 env
->fpstt
= (env
->fpstt
+ 1) & 7;
1944 env
->fpus
&= (~0x4700);
1947 void OPPROTO
op_fmov_ST0_FT0(void)
1952 void OPPROTO
op_fmov_FT0_STN(void)
1957 void OPPROTO
op_fmov_ST0_STN(void)
1962 void OPPROTO
op_fmov_STN_ST0(void)
1967 void OPPROTO
op_fxchg_ST0_STN(void)
1975 /* FPU operations */
1977 /* XXX: handle nans */
1978 void OPPROTO
op_fcom_ST0_FT0(void)
1980 env
->fpus
&= (~0x4500); /* (C3,C2,C0) <-- 000 */
1982 env
->fpus
|= 0x100; /* (C3,C2,C0) <-- 001 */
1983 else if (ST0
== FT0
)
1984 env
->fpus
|= 0x4000; /* (C3,C2,C0) <-- 100 */
1988 /* XXX: handle nans */
1989 void OPPROTO
op_fucom_ST0_FT0(void)
1991 env
->fpus
&= (~0x4500); /* (C3,C2,C0) <-- 000 */
1993 env
->fpus
|= 0x100; /* (C3,C2,C0) <-- 001 */
1994 else if (ST0
== FT0
)
1995 env
->fpus
|= 0x4000; /* (C3,C2,C0) <-- 100 */
1999 void OPPROTO
op_fadd_ST0_FT0(void)
2004 void OPPROTO
op_fmul_ST0_FT0(void)
2009 void OPPROTO
op_fsub_ST0_FT0(void)
2014 void OPPROTO
op_fsubr_ST0_FT0(void)
2019 void OPPROTO
op_fdiv_ST0_FT0(void)
2024 void OPPROTO
op_fdivr_ST0_FT0(void)
2029 /* fp operations between STN and ST0 */
2031 void OPPROTO
op_fadd_STN_ST0(void)
2036 void OPPROTO
op_fmul_STN_ST0(void)
2041 void OPPROTO
op_fsub_STN_ST0(void)
2046 void OPPROTO
op_fsubr_STN_ST0(void)
2053 void OPPROTO
op_fdiv_STN_ST0(void)
2058 void OPPROTO
op_fdivr_STN_ST0(void)
2065 /* misc FPU operations */
2066 void OPPROTO
op_fchs_ST0(void)
2071 void OPPROTO
op_fabs_ST0(void)
2076 void helper_fxam_ST0(void)
2078 CPU86_LDoubleU temp
;
2083 env
->fpus
&= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
2085 env
->fpus
|= 0x200; /* C1 <-- 1 */
2087 expdif
= EXPD(temp
);
2088 if (expdif
== MAXEXPD
) {
2089 if (MANTD(temp
) == 0)
2090 env
->fpus
|= 0x500 /*Infinity*/;
2092 env
->fpus
|= 0x100 /*NaN*/;
2093 } else if (expdif
== 0) {
2094 if (MANTD(temp
) == 0)
2095 env
->fpus
|= 0x4000 /*Zero*/;
2097 env
->fpus
|= 0x4400 /*Denormal*/;
2103 void OPPROTO
op_fxam_ST0(void)
2108 void OPPROTO
op_fld1_ST0(void)
2110 ST0
= *(CPU86_LDouble
*)&f15rk
[1];
2113 void OPPROTO
op_fldl2t_ST0(void)
2115 ST0
= *(CPU86_LDouble
*)&f15rk
[6];
2118 void OPPROTO
op_fldl2e_ST0(void)
2120 ST0
= *(CPU86_LDouble
*)&f15rk
[5];
2123 void OPPROTO
op_fldpi_ST0(void)
2125 ST0
= *(CPU86_LDouble
*)&f15rk
[2];
2128 void OPPROTO
op_fldlg2_ST0(void)
2130 ST0
= *(CPU86_LDouble
*)&f15rk
[3];
2133 void OPPROTO
op_fldln2_ST0(void)
2135 ST0
= *(CPU86_LDouble
*)&f15rk
[4];
2138 void OPPROTO
op_fldz_ST0(void)
2140 ST0
= *(CPU86_LDouble
*)&f15rk
[0];
2143 void OPPROTO
op_fldz_FT0(void)
2145 ST0
= *(CPU86_LDouble
*)&f15rk
[0];
2148 void helper_f2xm1(void)
2150 ST0
= pow(2.0,ST0
) - 1.0;
2153 void helper_fyl2x(void)
2155 CPU86_LDouble fptemp
;
2159 fptemp
= log(fptemp
)/log(2.0); /* log2(ST) */
2163 env
->fpus
&= (~0x4700);
2168 void helper_fptan(void)
2170 CPU86_LDouble fptemp
;
2173 if((fptemp
> MAXTAN
)||(fptemp
< -MAXTAN
)) {
2179 env
->fpus
&= (~0x400); /* C2 <-- 0 */
2180 /* the above code is for |arg| < 2**52 only */
2184 void helper_fpatan(void)
2186 CPU86_LDouble fptemp
, fpsrcop
;
2190 ST1
= atan2(fpsrcop
,fptemp
);
2194 void helper_fxtract(void)
2196 CPU86_LDoubleU temp
;
2197 unsigned int expdif
;
2200 expdif
= EXPD(temp
) - EXPBIAS
;
2201 /*DP exponent bias*/
2208 void helper_fprem1(void)
2210 CPU86_LDouble dblq
, fpsrcop
, fptemp
;
2211 CPU86_LDoubleU fpsrcop1
, fptemp1
;
2217 fpsrcop1
.d
= fpsrcop
;
2219 expdif
= EXPD(fpsrcop1
) - EXPD(fptemp1
);
2221 dblq
= fpsrcop
/ fptemp
;
2222 dblq
= (dblq
< 0.0)? ceil(dblq
): floor(dblq
);
2223 ST0
= fpsrcop
- fptemp
*dblq
;
2224 q
= (int)dblq
; /* cutting off top bits is assumed here */
2225 env
->fpus
&= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
2226 /* (C0,C1,C3) <-- (q2,q1,q0) */
2227 env
->fpus
|= (q
&0x4) << 6; /* (C0) <-- q2 */
2228 env
->fpus
|= (q
&0x2) << 8; /* (C1) <-- q1 */
2229 env
->fpus
|= (q
&0x1) << 14; /* (C3) <-- q0 */
2231 env
->fpus
|= 0x400; /* C2 <-- 1 */
2232 fptemp
= pow(2.0, expdif
-50);
2233 fpsrcop
= (ST0
/ ST1
) / fptemp
;
2234 /* fpsrcop = integer obtained by rounding to the nearest */
2235 fpsrcop
= (fpsrcop
-floor(fpsrcop
) < ceil(fpsrcop
)-fpsrcop
)?
2236 floor(fpsrcop
): ceil(fpsrcop
);
2237 ST0
-= (ST1
* fpsrcop
* fptemp
);
2241 void helper_fprem(void)
2243 CPU86_LDouble dblq
, fpsrcop
, fptemp
;
2244 CPU86_LDoubleU fpsrcop1
, fptemp1
;
2250 fpsrcop1
.d
= fpsrcop
;
2252 expdif
= EXPD(fpsrcop1
) - EXPD(fptemp1
);
2253 if ( expdif
< 53 ) {
2254 dblq
= fpsrcop
/ fptemp
;
2255 dblq
= (dblq
< 0.0)? ceil(dblq
): floor(dblq
);
2256 ST0
= fpsrcop
- fptemp
*dblq
;
2257 q
= (int)dblq
; /* cutting off top bits is assumed here */
2258 env
->fpus
&= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
2259 /* (C0,C1,C3) <-- (q2,q1,q0) */
2260 env
->fpus
|= (q
&0x4) << 6; /* (C0) <-- q2 */
2261 env
->fpus
|= (q
&0x2) << 8; /* (C1) <-- q1 */
2262 env
->fpus
|= (q
&0x1) << 14; /* (C3) <-- q0 */
2264 env
->fpus
|= 0x400; /* C2 <-- 1 */
2265 fptemp
= pow(2.0, expdif
-50);
2266 fpsrcop
= (ST0
/ ST1
) / fptemp
;
2267 /* fpsrcop = integer obtained by chopping */
2268 fpsrcop
= (fpsrcop
< 0.0)?
2269 -(floor(fabs(fpsrcop
))): floor(fpsrcop
);
2270 ST0
-= (ST1
* fpsrcop
* fptemp
);
2274 void helper_fyl2xp1(void)
2276 CPU86_LDouble fptemp
;
2279 if ((fptemp
+1.0)>0.0) {
2280 fptemp
= log(fptemp
+1.0) / log(2.0); /* log2(ST+1.0) */
2284 env
->fpus
&= (~0x4700);
2289 void helper_fsqrt(void)
2291 CPU86_LDouble fptemp
;
2295 env
->fpus
&= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
2301 void helper_fsincos(void)
2303 CPU86_LDouble fptemp
;
2306 if ((fptemp
> MAXTAN
)||(fptemp
< -MAXTAN
)) {
2312 env
->fpus
&= (~0x400); /* C2 <-- 0 */
2313 /* the above code is for |arg| < 2**63 only */
2317 void helper_frndint(void)
2322 void helper_fscale(void)
2324 CPU86_LDouble fpsrcop
, fptemp
;
2327 fptemp
= pow(fpsrcop
,ST1
);
2331 void helper_fsin(void)
2333 CPU86_LDouble fptemp
;
2336 if ((fptemp
> MAXTAN
)||(fptemp
< -MAXTAN
)) {
2340 env
->fpus
&= (~0x400); /* C2 <-- 0 */
2341 /* the above code is for |arg| < 2**53 only */
2345 void helper_fcos(void)
2347 CPU86_LDouble fptemp
;
2350 if((fptemp
> MAXTAN
)||(fptemp
< -MAXTAN
)) {
2354 env
->fpus
&= (~0x400); /* C2 <-- 0 */
2355 /* the above code is for |arg5 < 2**63 only */
2359 /* associated heplers to reduce generated code length and to simplify
2360 relocation (FP constants are usually stored in .rodata section) */
2362 void OPPROTO
op_f2xm1(void)
2367 void OPPROTO
op_fyl2x(void)
2372 void OPPROTO
op_fptan(void)
2377 void OPPROTO
op_fpatan(void)
2382 void OPPROTO
op_fxtract(void)
2387 void OPPROTO
op_fprem1(void)
2393 void OPPROTO
op_fprem(void)
2398 void OPPROTO
op_fyl2xp1(void)
2403 void OPPROTO
op_fsqrt(void)
2408 void OPPROTO
op_fsincos(void)
2413 void OPPROTO
op_frndint(void)
2418 void OPPROTO
op_fscale(void)
2423 void OPPROTO
op_fsin(void)
2428 void OPPROTO
op_fcos(void)
2433 void OPPROTO
op_fnstsw_A0(void)
2436 fpus
= (env
->fpus
& ~0x3800) | (env
->fpstt
& 0x7) << 11;
2437 stw((void *)A0
, fpus
);
2440 void OPPROTO
op_fnstsw_EAX(void)
2443 fpus
= (env
->fpus
& ~0x3800) | (env
->fpstt
& 0x7) << 11;
2444 EAX
= (EAX
& 0xffff0000) | fpus
;
2447 void OPPROTO
op_fnstcw_A0(void)
2449 stw((void *)A0
, env
->fpuc
);
2452 void OPPROTO
op_fldcw_A0(void)
2455 env
->fpuc
= lduw((void *)A0
);
2456 /* set rounding mode */
2457 switch(env
->fpuc
& RC_MASK
) {
2460 rnd_type
= FE_TONEAREST
;
2463 rnd_type
= FE_DOWNWARD
;
2466 rnd_type
= FE_UPWARD
;
2469 rnd_type
= FE_TOWARDZERO
;
2472 fesetround(rnd_type
);
2475 void OPPROTO
op_fclex(void)
2477 env
->fpus
&= 0x7f00;
2480 void OPPROTO
op_fninit(void)
2495 /* threading support */
2496 void OPPROTO
op_lock(void)
2501 void OPPROTO
op_unlock(void)