]>
git.proxmox.com Git - qemu.git/blob - op-i386.c
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 /* n must be a constant to be efficient */
23 static inline int lshift(int x
, int n
)
31 /* we define the various pieces of code used by the JIT */
35 #include "opreg_template.h"
41 #include "opreg_template.h"
47 #include "opreg_template.h"
53 #include "opreg_template.h"
59 #include "opreg_template.h"
65 #include "opreg_template.h"
71 #include "opreg_template.h"
77 #include "opreg_template.h"
81 /* operations with flags */
83 /* update flags with T0 and T1 (add/sub case) */
84 void OPPROTO
op_update2_cc(void)
90 /* update flags with T0 (logic operation case) */
91 void OPPROTO
op_update1_cc(void)
96 void OPPROTO
op_update_neg_cc(void)
102 void OPPROTO
op_cmpl_T0_T1_cc(void)
108 void OPPROTO
op_update_inc_cc(void)
110 CC_SRC
= cc_table
[CC_OP
].compute_c();
114 void OPPROTO
op_testl_T0_T1_cc(void)
119 /* operations without flags */
121 void OPPROTO
op_addl_T0_T1(void)
126 void OPPROTO
op_orl_T0_T1(void)
131 void OPPROTO
op_andl_T0_T1(void)
136 void OPPROTO
op_subl_T0_T1(void)
141 void OPPROTO
op_xorl_T0_T1(void)
146 void OPPROTO
op_negl_T0(void)
151 void OPPROTO
op_incl_T0(void)
156 void OPPROTO
op_decl_T0(void)
161 void OPPROTO
op_notl_T0(void)
166 void OPPROTO
op_bswapl_T0(void)
171 /* multiply/divide */
172 void OPPROTO
op_mulb_AL_T0(void)
175 res
= (uint8_t)EAX
* (uint8_t)T0
;
176 EAX
= (EAX
& 0xffff0000) | res
;
177 CC_SRC
= (res
& 0xff00);
180 void OPPROTO
op_imulb_AL_T0(void)
183 res
= (int8_t)EAX
* (int8_t)T0
;
184 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
185 CC_SRC
= (res
!= (int8_t)res
);
188 void OPPROTO
op_mulw_AX_T0(void)
191 res
= (uint16_t)EAX
* (uint16_t)T0
;
192 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
193 EDX
= (EDX
& 0xffff0000) | ((res
>> 16) & 0xffff);
197 void OPPROTO
op_imulw_AX_T0(void)
200 res
= (int16_t)EAX
* (int16_t)T0
;
201 EAX
= (EAX
& 0xffff0000) | (res
& 0xffff);
202 EDX
= (EDX
& 0xffff0000) | ((res
>> 16) & 0xffff);
203 CC_SRC
= (res
!= (int16_t)res
);
206 void OPPROTO
op_mull_EAX_T0(void)
209 res
= (uint64_t)((uint32_t)EAX
) * (uint64_t)((uint32_t)T0
);
215 void OPPROTO
op_imull_EAX_T0(void)
218 res
= (int64_t)((int32_t)EAX
) * (int64_t)((int32_t)T0
);
221 CC_SRC
= (res
!= (int32_t)res
);
224 void OPPROTO
op_imulw_T0_T1(void)
227 res
= (int16_t)T0
* (int16_t)T1
;
229 CC_SRC
= (res
!= (int16_t)res
);
232 void OPPROTO
op_imull_T0_T1(void)
235 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
237 CC_SRC
= (res
!= (int32_t)res
);
240 /* division, flags are undefined */
241 /* XXX: add exceptions for overflow */
243 void OPPROTO
op_divb_AL_T0(void)
245 unsigned int num
, den
, q
, r
;
247 num
= (EAX
& 0xffff);
251 raise_exception(EXCP00_DIVZ
);
253 q
= (num
/ den
) & 0xff;
254 r
= (num
% den
) & 0xff;
255 EAX
= (EAX
& 0xffff0000) | (r
<< 8) | q
;
258 void OPPROTO
op_idivb_AL_T0(void)
266 raise_exception(EXCP00_DIVZ
);
268 q
= (num
/ den
) & 0xff;
269 r
= (num
% den
) & 0xff;
270 EAX
= (EAX
& 0xffff0000) | (r
<< 8) | q
;
273 void OPPROTO
op_divw_AX_T0(void)
275 unsigned int num
, den
, q
, r
;
277 num
= (EAX
& 0xffff) | ((EDX
& 0xffff) << 16);
281 raise_exception(EXCP00_DIVZ
);
283 q
= (num
/ den
) & 0xffff;
284 r
= (num
% den
) & 0xffff;
285 EAX
= (EAX
& 0xffff0000) | q
;
286 EDX
= (EDX
& 0xffff0000) | r
;
289 void OPPROTO
op_idivw_AX_T0(void)
293 num
= (EAX
& 0xffff) | ((EDX
& 0xffff) << 16);
297 raise_exception(EXCP00_DIVZ
);
299 q
= (num
/ den
) & 0xffff;
300 r
= (num
% den
) & 0xffff;
301 EAX
= (EAX
& 0xffff0000) | q
;
302 EDX
= (EDX
& 0xffff0000) | r
;
305 void OPPROTO
op_divl_EAX_T0(void)
307 helper_divl_EAX_T0(PARAM1
);
310 void OPPROTO
op_idivl_EAX_T0(void)
312 helper_idivl_EAX_T0(PARAM1
);
315 /* constant load & misc op */
317 void OPPROTO
op_movl_T0_im(void)
322 void OPPROTO
op_addl_T0_im(void)
327 void OPPROTO
op_andl_T0_ffff(void)
332 void OPPROTO
op_andl_T0_im(void)
337 void OPPROTO
op_movl_T0_T1(void)
342 void OPPROTO
op_movl_T1_im(void)
347 void OPPROTO
op_addl_T1_im(void)
352 void OPPROTO
op_movl_T1_A0(void)
357 void OPPROTO
op_movl_A0_im(void)
362 void OPPROTO
op_addl_A0_im(void)
367 void OPPROTO
op_addl_A0_AL(void)
372 void OPPROTO
op_andl_A0_ffff(void)
379 void OPPROTO
op_ldub_T0_A0(void)
381 T0
= ldub((uint8_t *)A0
);
384 void OPPROTO
op_ldsb_T0_A0(void)
386 T0
= ldsb((int8_t *)A0
);
389 void OPPROTO
op_lduw_T0_A0(void)
391 T0
= lduw((uint8_t *)A0
);
394 void OPPROTO
op_ldsw_T0_A0(void)
396 T0
= ldsw((int8_t *)A0
);
399 void OPPROTO
op_ldl_T0_A0(void)
401 T0
= ldl((uint8_t *)A0
);
404 void OPPROTO
op_ldub_T1_A0(void)
406 T1
= ldub((uint8_t *)A0
);
409 void OPPROTO
op_ldsb_T1_A0(void)
411 T1
= ldsb((int8_t *)A0
);
414 void OPPROTO
op_lduw_T1_A0(void)
416 T1
= lduw((uint8_t *)A0
);
419 void OPPROTO
op_ldsw_T1_A0(void)
421 T1
= ldsw((int8_t *)A0
);
424 void OPPROTO
op_ldl_T1_A0(void)
426 T1
= ldl((uint8_t *)A0
);
429 void OPPROTO
op_stb_T0_A0(void)
431 stb((uint8_t *)A0
, T0
);
434 void OPPROTO
op_stw_T0_A0(void)
436 stw((uint8_t *)A0
, T0
);
439 void OPPROTO
op_stl_T0_A0(void)
441 stl((uint8_t *)A0
, T0
);
444 /* used for bit operations */
446 void OPPROTO
op_add_bitw_A0_T1(void)
448 A0
+= ((int32_t)T1
>> 4) << 1;
451 void OPPROTO
op_add_bitl_A0_T1(void)
453 A0
+= ((int32_t)T1
>> 5) << 2;
458 void OPPROTO
op_jmp_T0(void)
463 void OPPROTO
op_jmp_im(void)
468 void OPPROTO
op_hlt(void)
470 env
->exception_index
= EXCP_HLT
;
474 void OPPROTO
op_raise_interrupt(void)
477 unsigned int next_eip
;
480 raise_interrupt(intno
, 1, 0, next_eip
);
483 void OPPROTO
op_raise_exception(void)
486 exception_index
= PARAM1
;
487 raise_exception(exception_index
);
490 void OPPROTO
op_into(void)
493 eflags
= cc_table
[CC_OP
].compute_all();
495 raise_interrupt(EXCP04_INTO
, 1, 0, PARAM1
);
500 void OPPROTO
op_cli(void)
502 env
->eflags
&= ~IF_MASK
;
505 void OPPROTO
op_sti(void)
507 env
->eflags
|= IF_MASK
;
511 /* vm86plus instructions */
512 void OPPROTO
op_cli_vm(void)
514 env
->eflags
&= ~VIF_MASK
;
517 void OPPROTO
op_sti_vm(void)
519 env
->eflags
|= VIF_MASK
;
520 if (env
->eflags
& VIP_MASK
) {
522 raise_exception(EXCP0D_GPF
);
528 void OPPROTO
op_boundw(void)
531 low
= ldsw((uint8_t *)A0
);
532 high
= ldsw((uint8_t *)A0
+ 2);
534 if (v
< low
|| v
> high
) {
536 raise_exception(EXCP05_BOUND
);
541 void OPPROTO
op_boundl(void)
544 low
= ldl((uint8_t *)A0
);
545 high
= ldl((uint8_t *)A0
+ 4);
547 if (v
< low
|| v
> high
) {
549 raise_exception(EXCP05_BOUND
);
554 void OPPROTO
op_cmpxchg8b(void)
559 void OPPROTO
op_jmp_tb_next(void)
561 JUMP_TB(PARAM1
, 0, PARAM2
);
564 void OPPROTO
op_movl_T0_0(void)
569 /* multiple size ops */
574 #include "ops_template.h"
578 #include "ops_template.h"
582 #include "ops_template.h"
587 void OPPROTO
op_movsbl_T0_T0(void)
592 void OPPROTO
op_movzbl_T0_T0(void)
597 void OPPROTO
op_movswl_T0_T0(void)
602 void OPPROTO
op_movzwl_T0_T0(void)
607 void OPPROTO
op_movswl_EAX_AX(void)
612 void OPPROTO
op_movsbw_AX_AL(void)
614 EAX
= (EAX
& 0xffff0000) | ((int8_t)EAX
& 0xffff);
617 void OPPROTO
op_movslq_EDX_EAX(void)
619 EDX
= (int32_t)EAX
>> 31;
622 void OPPROTO
op_movswl_DX_AX(void)
624 EDX
= (EDX
& 0xffff0000) | (((int16_t)EAX
>> 15) & 0xffff);
629 void op_pushl_T0(void)
633 stl((void *)offset
, T0
);
634 /* modify ESP after to handle exceptions correctly */
638 void op_pushw_T0(void)
642 stw((void *)offset
, T0
);
643 /* modify ESP after to handle exceptions correctly */
647 void op_pushl_ss32_T0(void)
651 stl(env
->segs
[R_SS
].base
+ offset
, T0
);
652 /* modify ESP after to handle exceptions correctly */
656 void op_pushw_ss32_T0(void)
660 stw(env
->segs
[R_SS
].base
+ offset
, T0
);
661 /* modify ESP after to handle exceptions correctly */
665 void op_pushl_ss16_T0(void)
668 offset
= (ESP
- 4) & 0xffff;
669 stl(env
->segs
[R_SS
].base
+ offset
, T0
);
670 /* modify ESP after to handle exceptions correctly */
671 ESP
= (ESP
& ~0xffff) | offset
;
674 void op_pushw_ss16_T0(void)
677 offset
= (ESP
- 2) & 0xffff;
678 stw(env
->segs
[R_SS
].base
+ offset
, T0
);
679 /* modify ESP after to handle exceptions correctly */
680 ESP
= (ESP
& ~0xffff) | offset
;
683 /* NOTE: ESP update is done after */
684 void op_popl_T0(void)
686 T0
= ldl((void *)ESP
);
689 void op_popw_T0(void)
691 T0
= lduw((void *)ESP
);
694 void op_popl_ss32_T0(void)
696 T0
= ldl(env
->segs
[R_SS
].base
+ ESP
);
699 void op_popw_ss32_T0(void)
701 T0
= lduw(env
->segs
[R_SS
].base
+ ESP
);
704 void op_popl_ss16_T0(void)
706 T0
= ldl(env
->segs
[R_SS
].base
+ (ESP
& 0xffff));
709 void op_popw_ss16_T0(void)
711 T0
= lduw(env
->segs
[R_SS
].base
+ (ESP
& 0xffff));
714 void op_addl_ESP_4(void)
719 void op_addl_ESP_2(void)
724 void op_addw_ESP_4(void)
726 ESP
= (ESP
& ~0xffff) | ((ESP
+ 4) & 0xffff);
729 void op_addw_ESP_2(void)
731 ESP
= (ESP
& ~0xffff) | ((ESP
+ 2) & 0xffff);
734 void op_addl_ESP_im(void)
739 void op_addw_ESP_im(void)
741 ESP
= (ESP
& ~0xffff) | ((ESP
+ PARAM1
) & 0xffff);
744 void OPPROTO
op_rdtsc(void)
749 void OPPROTO
op_cpuid(void)
757 void OPPROTO
op_aam(void)
764 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
768 void OPPROTO
op_aad(void)
773 ah
= (EAX
>> 8) & 0xff;
774 al
= ((ah
* base
) + al
) & 0xff;
775 EAX
= (EAX
& ~0xffff) | al
;
779 void OPPROTO
op_aaa(void)
785 eflags
= cc_table
[CC_OP
].compute_all();
788 ah
= (EAX
>> 8) & 0xff;
790 icarry
= (al
> 0xf9);
791 if (((al
& 0x0f) > 9 ) || af
) {
792 al
= (al
+ 6) & 0x0f;
793 ah
= (ah
+ 1 + icarry
) & 0xff;
794 eflags
|= CC_C
| CC_A
;
796 eflags
&= ~(CC_C
| CC_A
);
799 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
803 void OPPROTO
op_aas(void)
809 eflags
= cc_table
[CC_OP
].compute_all();
812 ah
= (EAX
>> 8) & 0xff;
815 if (((al
& 0x0f) > 9 ) || af
) {
816 al
= (al
- 6) & 0x0f;
817 ah
= (ah
- 1 - icarry
) & 0xff;
818 eflags
|= CC_C
| CC_A
;
820 eflags
&= ~(CC_C
| CC_A
);
823 EAX
= (EAX
& ~0xffff) | al
| (ah
<< 8);
827 void OPPROTO
op_daa(void)
832 eflags
= cc_table
[CC_OP
].compute_all();
838 if (((al
& 0x0f) > 9 ) || af
) {
839 al
= (al
+ 6) & 0xff;
842 if ((al
> 0x9f) || cf
) {
843 al
= (al
+ 0x60) & 0xff;
846 EAX
= (EAX
& ~0xff) | al
;
847 /* well, speed is not an issue here, so we compute the flags by hand */
848 eflags
|= (al
== 0) << 6; /* zf */
849 eflags
|= parity_table
[al
]; /* pf */
850 eflags
|= (al
& 0x80); /* sf */
854 void OPPROTO
op_das(void)
859 eflags
= cc_table
[CC_OP
].compute_all();
866 if (((al
& 0x0f) > 9 ) || af
) {
870 al
= (al
- 6) & 0xff;
872 if ((al1
> 0x99) || cf
) {
873 al
= (al
- 0x60) & 0xff;
876 EAX
= (EAX
& ~0xff) | al
;
877 /* well, speed is not an issue here, so we compute the flags by hand */
878 eflags
|= (al
== 0) << 6; /* zf */
879 eflags
|= parity_table
[al
]; /* pf */
880 eflags
|= (al
& 0x80); /* sf */
884 /* segment handling */
886 void OPPROTO
op_movl_seg_T0(void)
888 load_seg(PARAM1
, T0
& 0xffff, PARAM2
);
891 /* faster VM86 version */
892 void OPPROTO
op_movl_seg_T0_vm(void)
897 selector
= T0
& 0xffff;
898 /* env->segs[] access */
899 sc
= (SegmentCache
*)((char *)env
+ PARAM1
);
900 sc
->selector
= selector
;
901 sc
->base
= (void *)(selector
<< 4);
904 void OPPROTO
op_movl_T0_seg(void)
906 T0
= env
->segs
[PARAM1
].selector
;
909 void OPPROTO
op_movl_A0_seg(void)
911 A0
= *(unsigned long *)((char *)env
+ PARAM1
);
914 void OPPROTO
op_addl_A0_seg(void)
916 A0
+= *(unsigned long *)((char *)env
+ PARAM1
);
919 void OPPROTO
op_lsl(void)
924 void OPPROTO
op_lar(void)
929 /* T0: segment, T1:eip */
930 void OPPROTO
op_ljmp_T0_T1(void)
932 jmp_seg(T0
& 0xffff, T1
);
935 void OPPROTO
op_iret_protected(void)
937 helper_iret_protected(PARAM1
);
940 void OPPROTO
op_lldt_T0(void)
945 void OPPROTO
op_ltr_T0(void)
950 /* CR registers access */
951 void OPPROTO
op_movl_crN_T0(void)
953 helper_movl_crN_T0(PARAM1
);
956 /* DR registers access */
957 void OPPROTO
op_movl_drN_T0(void)
959 helper_movl_drN_T0(PARAM1
);
962 void OPPROTO
op_lmsw_T0(void)
964 /* only 4 lower bits of CR0 are modified */
965 T0
= (env
->cr
[0] & ~0xf) | (T0
& 0xf);
966 helper_movl_crN_T0(0);
969 void OPPROTO
op_invlpg_A0(void)
974 void OPPROTO
op_movl_T0_env(void)
976 T0
= *(uint32_t *)((char *)env
+ PARAM1
);
979 void OPPROTO
op_movl_env_T0(void)
981 *(uint32_t *)((char *)env
+ PARAM1
) = T0
;
984 void OPPROTO
op_movl_env_T1(void)
986 *(uint32_t *)((char *)env
+ PARAM1
) = T1
;
989 void OPPROTO
op_clts(void)
991 env
->cr
[0] &= ~CR0_TS_MASK
;
996 /* slow jumps cases : in order to avoid calling a function with a
997 pointer (which can generate a stack frame on PowerPC), we use
998 op_setcc to set T0 and then call op_jcc. */
999 void OPPROTO
op_jcc(void)
1002 JUMP_TB(PARAM1
, 0, PARAM2
);
1004 JUMP_TB(PARAM1
, 1, PARAM3
);
1008 /* slow set cases (compute x86 flags) */
1009 void OPPROTO
op_seto_T0_cc(void)
1012 eflags
= cc_table
[CC_OP
].compute_all();
1013 T0
= (eflags
>> 11) & 1;
1016 void OPPROTO
op_setb_T0_cc(void)
1018 T0
= cc_table
[CC_OP
].compute_c();
1021 void OPPROTO
op_setz_T0_cc(void)
1024 eflags
= cc_table
[CC_OP
].compute_all();
1025 T0
= (eflags
>> 6) & 1;
1028 void OPPROTO
op_setbe_T0_cc(void)
1031 eflags
= cc_table
[CC_OP
].compute_all();
1032 T0
= (eflags
& (CC_Z
| CC_C
)) != 0;
1035 void OPPROTO
op_sets_T0_cc(void)
1038 eflags
= cc_table
[CC_OP
].compute_all();
1039 T0
= (eflags
>> 7) & 1;
1042 void OPPROTO
op_setp_T0_cc(void)
1045 eflags
= cc_table
[CC_OP
].compute_all();
1046 T0
= (eflags
>> 2) & 1;
1049 void OPPROTO
op_setl_T0_cc(void)
1052 eflags
= cc_table
[CC_OP
].compute_all();
1053 T0
= ((eflags
^ (eflags
>> 4)) >> 7) & 1;
1056 void OPPROTO
op_setle_T0_cc(void)
1059 eflags
= cc_table
[CC_OP
].compute_all();
1060 T0
= (((eflags
^ (eflags
>> 4)) & 0x80) || (eflags
& CC_Z
)) != 0;
1063 void OPPROTO
op_xor_T0_1(void)
1068 void OPPROTO
op_set_cc_op(void)
1073 #define FL_UPDATE_MASK16 (FL_UPDATE_MASK32 & 0xffff)
1075 void OPPROTO
op_movl_eflags_T0(void)
1079 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1080 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1081 /* we also update some system flags as in user mode */
1082 env
->eflags
= (env
->eflags
& ~FL_UPDATE_MASK32
) |
1083 (eflags
& FL_UPDATE_MASK32
);
1086 void OPPROTO
op_movw_eflags_T0(void)
1090 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1091 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1092 /* we also update some system flags as in user mode */
1093 env
->eflags
= (env
->eflags
& ~FL_UPDATE_MASK16
) |
1094 (eflags
& FL_UPDATE_MASK16
);
1097 void OPPROTO
op_movl_eflags_T0_cpl0(void)
1099 load_eflags(T0
, FL_UPDATE_CPL0_MASK
);
1102 void OPPROTO
op_movw_eflags_T0_cpl0(void)
1104 load_eflags(T0
, FL_UPDATE_CPL0_MASK
& 0xffff);
1108 /* vm86plus version */
1109 void OPPROTO
op_movw_eflags_T0_vm(void)
1113 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1114 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1115 /* we also update some system flags as in user mode */
1116 env
->eflags
= (env
->eflags
& ~(FL_UPDATE_MASK16
| VIF_MASK
)) |
1117 (eflags
& FL_UPDATE_MASK16
);
1118 if (eflags
& IF_MASK
) {
1119 env
->eflags
|= VIF_MASK
;
1120 if (env
->eflags
& VIP_MASK
) {
1122 raise_exception(EXCP0D_GPF
);
1128 void OPPROTO
op_movl_eflags_T0_vm(void)
1132 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
1133 DF
= 1 - (2 * ((eflags
>> 10) & 1));
1134 /* we also update some system flags as in user mode */
1135 env
->eflags
= (env
->eflags
& ~(FL_UPDATE_MASK32
| VIF_MASK
)) |
1136 (eflags
& FL_UPDATE_MASK32
);
1137 if (eflags
& IF_MASK
) {
1138 env
->eflags
|= VIF_MASK
;
1139 if (env
->eflags
& VIP_MASK
) {
1141 raise_exception(EXCP0D_GPF
);
1148 /* XXX: compute only O flag */
1149 void OPPROTO
op_movb_eflags_T0(void)
1152 of
= cc_table
[CC_OP
].compute_all() & CC_O
;
1153 CC_SRC
= (T0
& (CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
)) | of
;
1156 void OPPROTO
op_movl_T0_eflags(void)
1159 eflags
= cc_table
[CC_OP
].compute_all();
1160 eflags
|= (DF
& DF_MASK
);
1161 eflags
|= env
->eflags
& ~(VM_MASK
| RF_MASK
);
1165 /* vm86plus version */
1167 void OPPROTO
op_movl_T0_eflags_vm(void)
1170 eflags
= cc_table
[CC_OP
].compute_all();
1171 eflags
|= (DF
& DF_MASK
);
1172 eflags
|= env
->eflags
& ~(VM_MASK
| RF_MASK
| IF_MASK
);
1173 if (env
->eflags
& VIF_MASK
)
1179 void OPPROTO
op_cld(void)
1184 void OPPROTO
op_std(void)
1189 void OPPROTO
op_clc(void)
1192 eflags
= cc_table
[CC_OP
].compute_all();
1197 void OPPROTO
op_stc(void)
1200 eflags
= cc_table
[CC_OP
].compute_all();
1205 void OPPROTO
op_cmc(void)
1208 eflags
= cc_table
[CC_OP
].compute_all();
1213 void OPPROTO
op_salc(void)
1216 cf
= cc_table
[CC_OP
].compute_c();
1217 EAX
= (EAX
& ~0xff) | ((-cf
) & 0xff);
1220 static int compute_all_eflags(void)
1225 static int compute_c_eflags(void)
1227 return CC_SRC
& CC_C
;
1230 static int compute_c_mul(void)
1237 static int compute_all_mul(void)
1239 int cf
, pf
, af
, zf
, sf
, of
;
1241 pf
= 0; /* undefined */
1242 af
= 0; /* undefined */
1243 zf
= 0; /* undefined */
1244 sf
= 0; /* undefined */
1246 return cf
| pf
| af
| zf
| sf
| of
;
1249 CCTable cc_table
[CC_OP_NB
] = {
1250 [CC_OP_DYNAMIC
] = { /* should never happen */ },
1252 [CC_OP_EFLAGS
] = { compute_all_eflags
, compute_c_eflags
},
1254 [CC_OP_MUL
] = { compute_all_mul
, compute_c_mul
},
1256 [CC_OP_ADDB
] = { compute_all_addb
, compute_c_addb
},
1257 [CC_OP_ADDW
] = { compute_all_addw
, compute_c_addw
},
1258 [CC_OP_ADDL
] = { compute_all_addl
, compute_c_addl
},
1260 [CC_OP_ADCB
] = { compute_all_adcb
, compute_c_adcb
},
1261 [CC_OP_ADCW
] = { compute_all_adcw
, compute_c_adcw
},
1262 [CC_OP_ADCL
] = { compute_all_adcl
, compute_c_adcl
},
1264 [CC_OP_SUBB
] = { compute_all_subb
, compute_c_subb
},
1265 [CC_OP_SUBW
] = { compute_all_subw
, compute_c_subw
},
1266 [CC_OP_SUBL
] = { compute_all_subl
, compute_c_subl
},
1268 [CC_OP_SBBB
] = { compute_all_sbbb
, compute_c_sbbb
},
1269 [CC_OP_SBBW
] = { compute_all_sbbw
, compute_c_sbbw
},
1270 [CC_OP_SBBL
] = { compute_all_sbbl
, compute_c_sbbl
},
1272 [CC_OP_LOGICB
] = { compute_all_logicb
, compute_c_logicb
},
1273 [CC_OP_LOGICW
] = { compute_all_logicw
, compute_c_logicw
},
1274 [CC_OP_LOGICL
] = { compute_all_logicl
, compute_c_logicl
},
1276 [CC_OP_INCB
] = { compute_all_incb
, compute_c_incl
},
1277 [CC_OP_INCW
] = { compute_all_incw
, compute_c_incl
},
1278 [CC_OP_INCL
] = { compute_all_incl
, compute_c_incl
},
1280 [CC_OP_DECB
] = { compute_all_decb
, compute_c_incl
},
1281 [CC_OP_DECW
] = { compute_all_decw
, compute_c_incl
},
1282 [CC_OP_DECL
] = { compute_all_decl
, compute_c_incl
},
1284 [CC_OP_SHLB
] = { compute_all_shlb
, compute_c_shlb
},
1285 [CC_OP_SHLW
] = { compute_all_shlw
, compute_c_shlw
},
1286 [CC_OP_SHLL
] = { compute_all_shll
, compute_c_shll
},
1288 [CC_OP_SARB
] = { compute_all_sarb
, compute_c_sarl
},
1289 [CC_OP_SARW
] = { compute_all_sarw
, compute_c_sarl
},
1290 [CC_OP_SARL
] = { compute_all_sarl
, compute_c_sarl
},
1293 /* floating point support. Some of the code for complicated x87
1294 functions comes from the LGPL'ed x86 emulator found in the Willows
1295 TWIN windows emulator. */
1297 #if defined(__powerpc__)
1298 extern CPU86_LDouble
copysign(CPU86_LDouble
, CPU86_LDouble
);
1300 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
1301 double qemu_rint(double x
)
1303 double y
= 4503599627370496.0;
1314 #define rint qemu_rint
1319 void OPPROTO
op_flds_FT0_A0(void)
1321 #ifdef USE_FP_CONVERT
1322 FP_CONVERT
.i32
= ldl((void *)A0
);
1325 FT0
= ldfl((void *)A0
);
1329 void OPPROTO
op_fldl_FT0_A0(void)
1331 #ifdef USE_FP_CONVERT
1332 FP_CONVERT
.i64
= ldq((void *)A0
);
1335 FT0
= ldfq((void *)A0
);
1339 /* helpers are needed to avoid static constant reference. XXX: find a better way */
1340 #ifdef USE_INT_TO_FLOAT_HELPERS
1342 void helper_fild_FT0_A0(void)
1344 FT0
= (CPU86_LDouble
)ldsw((void *)A0
);
1347 void helper_fildl_FT0_A0(void)
1349 FT0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1352 void helper_fildll_FT0_A0(void)
1354 FT0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1357 void OPPROTO
op_fild_FT0_A0(void)
1359 helper_fild_FT0_A0();
1362 void OPPROTO
op_fildl_FT0_A0(void)
1364 helper_fildl_FT0_A0();
1367 void OPPROTO
op_fildll_FT0_A0(void)
1369 helper_fildll_FT0_A0();
1374 void OPPROTO
op_fild_FT0_A0(void)
1376 #ifdef USE_FP_CONVERT
1377 FP_CONVERT
.i32
= ldsw((void *)A0
);
1378 FT0
= (CPU86_LDouble
)FP_CONVERT
.i32
;
1380 FT0
= (CPU86_LDouble
)ldsw((void *)A0
);
1384 void OPPROTO
op_fildl_FT0_A0(void)
1386 #ifdef USE_FP_CONVERT
1387 FP_CONVERT
.i32
= (int32_t) ldl((void *)A0
);
1388 FT0
= (CPU86_LDouble
)FP_CONVERT
.i32
;
1390 FT0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1394 void OPPROTO
op_fildll_FT0_A0(void)
1396 #ifdef USE_FP_CONVERT
1397 FP_CONVERT
.i64
= (int64_t) ldq((void *)A0
);
1398 FT0
= (CPU86_LDouble
)FP_CONVERT
.i64
;
1400 FT0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1407 void OPPROTO
op_flds_ST0_A0(void)
1409 #ifdef USE_FP_CONVERT
1410 FP_CONVERT
.i32
= ldl((void *)A0
);
1413 ST0
= ldfl((void *)A0
);
1417 void OPPROTO
op_fldl_ST0_A0(void)
1419 #ifdef USE_FP_CONVERT
1420 FP_CONVERT
.i64
= ldq((void *)A0
);
1423 ST0
= ldfq((void *)A0
);
1427 #ifdef USE_X86LDOUBLE
1428 void OPPROTO
op_fldt_ST0_A0(void)
1430 ST0
= *(long double *)A0
;
1433 void OPPROTO
op_fldt_ST0_A0(void)
1435 helper_fldt_ST0_A0();
1439 /* helpers are needed to avoid static constant reference. XXX: find a better way */
1440 #ifdef USE_INT_TO_FLOAT_HELPERS
1442 void helper_fild_ST0_A0(void)
1444 ST0
= (CPU86_LDouble
)ldsw((void *)A0
);
1447 void helper_fildl_ST0_A0(void)
1449 ST0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1452 void helper_fildll_ST0_A0(void)
1454 ST0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1457 void OPPROTO
op_fild_ST0_A0(void)
1459 helper_fild_ST0_A0();
1462 void OPPROTO
op_fildl_ST0_A0(void)
1464 helper_fildl_ST0_A0();
1467 void OPPROTO
op_fildll_ST0_A0(void)
1469 helper_fildll_ST0_A0();
1474 void OPPROTO
op_fild_ST0_A0(void)
1476 #ifdef USE_FP_CONVERT
1477 FP_CONVERT
.i32
= ldsw((void *)A0
);
1478 ST0
= (CPU86_LDouble
)FP_CONVERT
.i32
;
1480 ST0
= (CPU86_LDouble
)ldsw((void *)A0
);
1484 void OPPROTO
op_fildl_ST0_A0(void)
1486 #ifdef USE_FP_CONVERT
1487 FP_CONVERT
.i32
= (int32_t) ldl((void *)A0
);
1488 ST0
= (CPU86_LDouble
)FP_CONVERT
.i32
;
1490 ST0
= (CPU86_LDouble
)((int32_t)ldl((void *)A0
));
1494 void OPPROTO
op_fildll_ST0_A0(void)
1496 #ifdef USE_FP_CONVERT
1497 FP_CONVERT
.i64
= (int64_t) ldq((void *)A0
);
1498 ST0
= (CPU86_LDouble
)FP_CONVERT
.i64
;
1500 ST0
= (CPU86_LDouble
)((int64_t)ldq((void *)A0
));
1508 void OPPROTO
op_fsts_ST0_A0(void)
1510 #ifdef USE_FP_CONVERT
1511 FP_CONVERT
.f
= (float)ST0
;
1512 stfl((void *)A0
, FP_CONVERT
.f
);
1514 stfl((void *)A0
, (float)ST0
);
1518 void OPPROTO
op_fstl_ST0_A0(void)
1520 stfq((void *)A0
, (double)ST0
);
1523 #ifdef USE_X86LDOUBLE
1524 void OPPROTO
op_fstt_ST0_A0(void)
1526 *(long double *)A0
= ST0
;
1529 void OPPROTO
op_fstt_ST0_A0(void)
1531 helper_fstt_ST0_A0();
1535 void OPPROTO
op_fist_ST0_A0(void)
1537 #if defined(__sparc__) && !defined(__sparc_v9__)
1538 register CPU86_LDouble d
asm("o0");
1546 if (val
!= (int16_t)val
)
1548 stw((void *)A0
, val
);
1551 void OPPROTO
op_fistl_ST0_A0(void)
1553 #if defined(__sparc__) && !defined(__sparc_v9__)
1554 register CPU86_LDouble d
asm("o0");
1562 stl((void *)A0
, val
);
1565 void OPPROTO
op_fistll_ST0_A0(void)
1567 #if defined(__sparc__) && !defined(__sparc_v9__)
1568 register CPU86_LDouble d
asm("o0");
1576 stq((void *)A0
, val
);
1579 void OPPROTO
op_fbld_ST0_A0(void)
1581 helper_fbld_ST0_A0();
1584 void OPPROTO
op_fbst_ST0_A0(void)
1586 helper_fbst_ST0_A0();
1591 void OPPROTO
op_fpush(void)
1596 void OPPROTO
op_fpop(void)
1601 void OPPROTO
op_fdecstp(void)
1603 env
->fpstt
= (env
->fpstt
- 1) & 7;
1604 env
->fpus
&= (~0x4700);
1607 void OPPROTO
op_fincstp(void)
1609 env
->fpstt
= (env
->fpstt
+ 1) & 7;
1610 env
->fpus
&= (~0x4700);
1613 void OPPROTO
op_fmov_ST0_FT0(void)
1618 void OPPROTO
op_fmov_FT0_STN(void)
1623 void OPPROTO
op_fmov_ST0_STN(void)
1628 void OPPROTO
op_fmov_STN_ST0(void)
1633 void OPPROTO
op_fxchg_ST0_STN(void)
1641 /* FPU operations */
1643 /* XXX: handle nans */
1644 void OPPROTO
op_fcom_ST0_FT0(void)
1646 env
->fpus
&= (~0x4500); /* (C3,C2,C0) <-- 000 */
1648 env
->fpus
|= 0x100; /* (C3,C2,C0) <-- 001 */
1649 else if (ST0
== FT0
)
1650 env
->fpus
|= 0x4000; /* (C3,C2,C0) <-- 100 */
1654 /* XXX: handle nans */
1655 void OPPROTO
op_fucom_ST0_FT0(void)
1657 env
->fpus
&= (~0x4500); /* (C3,C2,C0) <-- 000 */
1659 env
->fpus
|= 0x100; /* (C3,C2,C0) <-- 001 */
1660 else if (ST0
== FT0
)
1661 env
->fpus
|= 0x4000; /* (C3,C2,C0) <-- 100 */
1665 /* XXX: handle nans */
1666 void OPPROTO
op_fcomi_ST0_FT0(void)
1669 eflags
= cc_table
[CC_OP
].compute_all();
1670 eflags
&= ~(CC_Z
| CC_P
| CC_C
);
1673 else if (ST0
== FT0
)
1679 /* XXX: handle nans */
1680 void OPPROTO
op_fucomi_ST0_FT0(void)
1683 eflags
= cc_table
[CC_OP
].compute_all();
1684 eflags
&= ~(CC_Z
| CC_P
| CC_C
);
1687 else if (ST0
== FT0
)
1693 void OPPROTO
op_fadd_ST0_FT0(void)
1698 void OPPROTO
op_fmul_ST0_FT0(void)
1703 void OPPROTO
op_fsub_ST0_FT0(void)
1708 void OPPROTO
op_fsubr_ST0_FT0(void)
1713 void OPPROTO
op_fdiv_ST0_FT0(void)
1718 void OPPROTO
op_fdivr_ST0_FT0(void)
1723 /* fp operations between STN and ST0 */
1725 void OPPROTO
op_fadd_STN_ST0(void)
1730 void OPPROTO
op_fmul_STN_ST0(void)
1735 void OPPROTO
op_fsub_STN_ST0(void)
1740 void OPPROTO
op_fsubr_STN_ST0(void)
1747 void OPPROTO
op_fdiv_STN_ST0(void)
1752 void OPPROTO
op_fdivr_STN_ST0(void)
1759 /* misc FPU operations */
1760 void OPPROTO
op_fchs_ST0(void)
1765 void OPPROTO
op_fabs_ST0(void)
1770 void OPPROTO
op_fxam_ST0(void)
1775 void OPPROTO
op_fld1_ST0(void)
1780 void OPPROTO
op_fldl2t_ST0(void)
1785 void OPPROTO
op_fldl2e_ST0(void)
1790 void OPPROTO
op_fldpi_ST0(void)
1795 void OPPROTO
op_fldlg2_ST0(void)
1800 void OPPROTO
op_fldln2_ST0(void)
1805 void OPPROTO
op_fldz_ST0(void)
1810 void OPPROTO
op_fldz_FT0(void)
1815 /* associated heplers to reduce generated code length and to simplify
1816 relocation (FP constants are usually stored in .rodata section) */
1818 void OPPROTO
op_f2xm1(void)
1823 void OPPROTO
op_fyl2x(void)
1828 void OPPROTO
op_fptan(void)
1833 void OPPROTO
op_fpatan(void)
1838 void OPPROTO
op_fxtract(void)
1843 void OPPROTO
op_fprem1(void)
1849 void OPPROTO
op_fprem(void)
1854 void OPPROTO
op_fyl2xp1(void)
1859 void OPPROTO
op_fsqrt(void)
1864 void OPPROTO
op_fsincos(void)
1869 void OPPROTO
op_frndint(void)
1874 void OPPROTO
op_fscale(void)
1879 void OPPROTO
op_fsin(void)
1884 void OPPROTO
op_fcos(void)
1889 void OPPROTO
op_fnstsw_A0(void)
1892 fpus
= (env
->fpus
& ~0x3800) | (env
->fpstt
& 0x7) << 11;
1893 stw((void *)A0
, fpus
);
1896 void OPPROTO
op_fnstsw_EAX(void)
1899 fpus
= (env
->fpus
& ~0x3800) | (env
->fpstt
& 0x7) << 11;
1900 EAX
= (EAX
& 0xffff0000) | fpus
;
1903 void OPPROTO
op_fnstcw_A0(void)
1905 stw((void *)A0
, env
->fpuc
);
1908 void OPPROTO
op_fldcw_A0(void)
1911 env
->fpuc
= lduw((void *)A0
);
1912 /* set rounding mode */
1913 switch(env
->fpuc
& RC_MASK
) {
1916 rnd_type
= FE_TONEAREST
;
1919 rnd_type
= FE_DOWNWARD
;
1922 rnd_type
= FE_UPWARD
;
1925 rnd_type
= FE_TOWARDZERO
;
1928 fesetround(rnd_type
);
1931 void OPPROTO
op_fclex(void)
1933 env
->fpus
&= 0x7f00;
1936 void OPPROTO
op_fninit(void)
1951 void OPPROTO
op_fnstenv_A0(void)
1953 helper_fstenv((uint8_t *)A0
, PARAM1
);
1956 void OPPROTO
op_fldenv_A0(void)
1958 helper_fldenv((uint8_t *)A0
, PARAM1
);
1961 void OPPROTO
op_fnsave_A0(void)
1963 helper_fsave((uint8_t *)A0
, PARAM1
);
1966 void OPPROTO
op_frstor_A0(void)
1968 helper_frstor((uint8_t *)A0
, PARAM1
);
1971 /* threading support */
1972 void OPPROTO
op_lock(void)
1977 void OPPROTO
op_unlock(void)