4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2005 CodeSourcery, LLC
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define REG (env->regs[0])
25 #include "op_template.h"
28 #define REG (env->regs[1])
29 #include "op_template.h"
32 #define REG (env->regs[2])
33 #include "op_template.h"
36 #define REG (env->regs[3])
37 #include "op_template.h"
40 #define REG (env->regs[4])
41 #include "op_template.h"
44 #define REG (env->regs[5])
45 #include "op_template.h"
48 #define REG (env->regs[6])
49 #include "op_template.h"
52 #define REG (env->regs[7])
53 #include "op_template.h"
56 #define REG (env->regs[8])
57 #include "op_template.h"
60 #define REG (env->regs[9])
61 #include "op_template.h"
64 #define REG (env->regs[10])
65 #include "op_template.h"
68 #define REG (env->regs[11])
69 #include "op_template.h"
72 #define REG (env->regs[12])
73 #include "op_template.h"
76 #define REG (env->regs[13])
77 #include "op_template.h"
80 #define REG (env->regs[14])
81 #include "op_template.h"
84 #define REG (env->regs[15])
85 #define SET_REG(x) REG = x & ~(uint32_t)1
86 #include "op_template.h"
88 void OPPROTO
op_bx_T0(void)
90 env
->regs
[15] = T0
& ~(uint32_t)1;
91 env
->thumb
= (T0
& 1) != 0;
94 void OPPROTO
op_movl_T0_0(void)
99 void OPPROTO
op_movl_T0_im(void)
104 void OPPROTO
op_movl_T1_im(void)
109 void OPPROTO
op_mov_CF_T1(void)
111 env
->CF
= ((uint32_t)T1
) >> 31;
114 void OPPROTO
op_movl_T2_im(void)
119 void OPPROTO
op_addl_T1_im(void)
124 void OPPROTO
op_addl_T1_T2(void)
129 void OPPROTO
op_subl_T1_T2(void)
134 void OPPROTO
op_addl_T0_T1(void)
139 void OPPROTO
op_addl_T0_T1_cc(void)
146 env
->VF
= (src1
^ T1
^ -1) & (src1
^ T0
);
149 void OPPROTO
op_adcl_T0_T1(void)
154 void OPPROTO
op_adcl_T0_T1_cc(void)
163 env
->CF
= T0
<= src1
;
165 env
->VF
= (src1
^ T1
^ -1) & (src1
^ T0
);
170 #define OPSUB(sub, sbc, res, T0, T1) \
172 void OPPROTO op_ ## sub ## l_T0_T1(void) \
177 void OPPROTO op_ ## sub ## l_T0_T1_cc(void) \
183 env->CF = src1 >= T1; \
184 env->VF = (src1 ^ T1) & (src1 ^ T0); \
188 void OPPROTO op_ ## sbc ## l_T0_T1(void) \
190 res = T0 - T1 + env->CF - 1; \
193 void OPPROTO op_ ## sbc ## l_T0_T1_cc(void) \
199 env->CF = src1 > T1; \
202 env->CF = src1 >= T1; \
204 env->VF = (src1 ^ T1) & (src1 ^ T0); \
210 OPSUB(sub
, sbc
, T0
, T0
, T1
)
212 OPSUB(rsb
, rsc
, T0
, T1
, T0
)
214 void OPPROTO
op_andl_T0_T1(void)
219 void OPPROTO
op_xorl_T0_T1(void)
224 void OPPROTO
op_orl_T0_T1(void)
229 void OPPROTO
op_bicl_T0_T1(void)
234 void OPPROTO
op_notl_T1(void)
239 void OPPROTO
op_logic_T0_cc(void)
244 void OPPROTO
op_logic_T1_cc(void)
249 #define EIP (env->regs[15])
251 void OPPROTO
op_test_eq(void)
254 JUMP_TB(op_test_eq
, PARAM1
, 0, PARAM2
);
258 void OPPROTO
op_test_ne(void)
261 JUMP_TB(op_test_ne
, PARAM1
, 0, PARAM2
);
265 void OPPROTO
op_test_cs(void)
268 JUMP_TB(op_test_cs
, PARAM1
, 0, PARAM2
);
272 void OPPROTO
op_test_cc(void)
275 JUMP_TB(op_test_cc
, PARAM1
, 0, PARAM2
);
279 void OPPROTO
op_test_mi(void)
281 if ((env
->NZF
& 0x80000000) != 0)
282 JUMP_TB(op_test_mi
, PARAM1
, 0, PARAM2
);
286 void OPPROTO
op_test_pl(void)
288 if ((env
->NZF
& 0x80000000) == 0)
289 JUMP_TB(op_test_pl
, PARAM1
, 0, PARAM2
);
293 void OPPROTO
op_test_vs(void)
295 if ((env
->VF
& 0x80000000) != 0)
296 JUMP_TB(op_test_vs
, PARAM1
, 0, PARAM2
);
300 void OPPROTO
op_test_vc(void)
302 if ((env
->VF
& 0x80000000) == 0)
303 JUMP_TB(op_test_vc
, PARAM1
, 0, PARAM2
);
307 void OPPROTO
op_test_hi(void)
309 if (env
->CF
!= 0 && env
->NZF
!= 0)
310 JUMP_TB(op_test_hi
, PARAM1
, 0, PARAM2
);
314 void OPPROTO
op_test_ls(void)
316 if (env
->CF
== 0 || env
->NZF
== 0)
317 JUMP_TB(op_test_ls
, PARAM1
, 0, PARAM2
);
321 void OPPROTO
op_test_ge(void)
323 if (((env
->VF
^ env
->NZF
) & 0x80000000) == 0)
324 JUMP_TB(op_test_ge
, PARAM1
, 0, PARAM2
);
328 void OPPROTO
op_test_lt(void)
330 if (((env
->VF
^ env
->NZF
) & 0x80000000) != 0)
331 JUMP_TB(op_test_lt
, PARAM1
, 0, PARAM2
);
335 void OPPROTO
op_test_gt(void)
337 if (env
->NZF
!= 0 && ((env
->VF
^ env
->NZF
) & 0x80000000) == 0)
338 JUMP_TB(op_test_gt
, PARAM1
, 0, PARAM2
);
342 void OPPROTO
op_test_le(void)
344 if (env
->NZF
== 0 || ((env
->VF
^ env
->NZF
) & 0x80000000) != 0)
345 JUMP_TB(op_test_le
, PARAM1
, 0, PARAM2
);
349 void OPPROTO
op_jmp(void)
351 JUMP_TB(op_jmp
, PARAM1
, 1, PARAM2
);
354 void OPPROTO
op_exit_tb(void)
359 void OPPROTO
op_movl_T0_psr(void)
364 /* NOTE: N = 1 and Z = 1 cannot be stored currently */
365 void OPPROTO
op_movl_psr_T0(void)
369 env
->CF
= (psr
>> 29) & 1;
370 env
->NZF
= (psr
& 0xc0000000) ^ 0x40000000;
371 env
->VF
= (psr
<< 3) & 0x80000000;
372 /* for user mode we do not update other state info */
375 void OPPROTO
op_mul_T0_T1(void)
380 /* 64 bit unsigned mul */
381 void OPPROTO
op_mull_T0_T1(void)
384 res
= (uint64_t)T0
* (uint64_t)T1
;
389 /* 64 bit signed mul */
390 void OPPROTO
op_imull_T0_T1(void)
393 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
398 /* 48 bit signed mul, top 32 bits */
399 void OPPROTO
op_imulw_T0_T1(void)
402 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
406 void OPPROTO
op_addq_T0_T1(void)
409 res
= ((uint64_t)T1
<< 32) | T0
;
410 res
+= ((uint64_t)(env
->regs
[PARAM2
]) << 32) | (env
->regs
[PARAM1
]);
415 void OPPROTO
op_addq_lo_T0_T1(void)
418 res
= ((uint64_t)T1
<< 32) | T0
;
419 res
+= (uint64_t)(env
->regs
[PARAM1
]);
424 void OPPROTO
op_logicq_cc(void)
426 env
->NZF
= (T1
& 0x80000000) | ((T0
| T1
) != 0);
431 void OPPROTO
op_ldub_T0_T1(void)
433 T0
= ldub((void *)T1
);
436 void OPPROTO
op_ldsb_T0_T1(void)
438 T0
= ldsb((void *)T1
);
441 void OPPROTO
op_lduw_T0_T1(void)
443 T0
= lduw((void *)T1
);
446 void OPPROTO
op_ldsw_T0_T1(void)
448 T0
= ldsw((void *)T1
);
451 void OPPROTO
op_ldl_T0_T1(void)
453 T0
= ldl((void *)T1
);
456 void OPPROTO
op_stb_T0_T1(void)
461 void OPPROTO
op_stw_T0_T1(void)
466 void OPPROTO
op_stl_T0_T1(void)
471 void OPPROTO
op_swpb_T0_T1(void)
476 tmp
= ldub((void *)T1
);
482 void OPPROTO
op_swpl_T0_T1(void)
487 tmp
= ldl((void *)T1
);
497 void OPPROTO
op_shll_T1_im(void)
502 void OPPROTO
op_shrl_T1_im(void)
504 T1
= (uint32_t)T1
>> PARAM1
;
507 void OPPROTO
op_shrl_T1_0(void)
512 void OPPROTO
op_sarl_T1_im(void)
514 T1
= (int32_t)T1
>> PARAM1
;
517 void OPPROTO
op_sarl_T1_0(void)
519 T1
= (int32_t)T1
>> 31;
522 void OPPROTO
op_rorl_T1_im(void)
526 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
529 void OPPROTO
op_rrxl_T1(void)
531 T1
= ((uint32_t)T1
>> 1) | ((uint32_t)env
->CF
<< 31);
534 /* T1 based, set C flag */
535 void OPPROTO
op_shll_T1_im_cc(void)
537 env
->CF
= (T1
>> (32 - PARAM1
)) & 1;
541 void OPPROTO
op_shrl_T1_im_cc(void)
543 env
->CF
= (T1
>> (PARAM1
- 1)) & 1;
544 T1
= (uint32_t)T1
>> PARAM1
;
547 void OPPROTO
op_shrl_T1_0_cc(void)
549 env
->CF
= (T1
>> 31) & 1;
553 void OPPROTO
op_sarl_T1_im_cc(void)
555 env
->CF
= (T1
>> (PARAM1
- 1)) & 1;
556 T1
= (int32_t)T1
>> PARAM1
;
559 void OPPROTO
op_sarl_T1_0_cc(void)
561 env
->CF
= (T1
>> 31) & 1;
562 T1
= (int32_t)T1
>> 31;
565 void OPPROTO
op_rorl_T1_im_cc(void)
569 env
->CF
= (T1
>> (shift
- 1)) & 1;
570 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
573 void OPPROTO
op_rrxl_T1_cc(void)
577 T1
= ((uint32_t)T1
>> 1) | ((uint32_t)env
->CF
<< 31);
582 void OPPROTO
op_shll_T2_im(void)
587 void OPPROTO
op_shrl_T2_im(void)
589 T2
= (uint32_t)T2
>> PARAM1
;
592 void OPPROTO
op_shrl_T2_0(void)
597 void OPPROTO
op_sarl_T2_im(void)
599 T2
= (int32_t)T2
>> PARAM1
;
602 void OPPROTO
op_sarl_T2_0(void)
604 T2
= (int32_t)T2
>> 31;
607 void OPPROTO
op_rorl_T2_im(void)
611 T2
= ((uint32_t)T2
>> shift
) | (T2
<< (32 - shift
));
614 void OPPROTO
op_rrxl_T2(void)
616 T2
= ((uint32_t)T2
>> 1) | ((uint32_t)env
->CF
<< 31);
619 /* T1 based, use T0 as shift count */
621 void OPPROTO
op_shll_T1_T0(void)
632 void OPPROTO
op_shrl_T1_T0(void)
639 T1
= (uint32_t)T1
>> shift
;
643 void OPPROTO
op_sarl_T1_T0(void)
649 T1
= (int32_t)T1
>> shift
;
652 void OPPROTO
op_rorl_T1_T0(void)
657 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
662 /* T1 based, use T0 as shift count and compute CF */
664 void OPPROTO
op_shll_T1_T0_cc(void)
674 } else if (shift
!= 0) {
675 env
->CF
= (T1
>> (32 - shift
)) & 1;
681 void OPPROTO
op_shrl_T1_T0_cc(void)
687 env
->CF
= (T1
>> 31) & 1;
691 } else if (shift
!= 0) {
692 env
->CF
= (T1
>> (shift
- 1)) & 1;
693 T1
= (uint32_t)T1
>> shift
;
698 void OPPROTO
op_sarl_T1_T0_cc(void)
703 env
->CF
= (T1
>> 31) & 1;
704 T1
= (int32_t)T1
>> 31;
706 env
->CF
= (T1
>> (shift
- 1)) & 1;
707 T1
= (int32_t)T1
>> shift
;
712 void OPPROTO
op_rorl_T1_T0_cc(void)
716 shift
= shift1
& 0x1f;
719 env
->CF
= (T1
>> 31) & 1;
721 env
->CF
= (T1
>> (shift
- 1)) & 1;
722 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
728 void OPPROTO
op_clz_T0(void)
731 for (count
= 32; T0
> 0; count
--)
737 void OPPROTO
op_sarl_T0_im(void)
739 T0
= (int32_t)T0
>> PARAM1
;
742 /* 16->32 Sign extend */
743 void OPPROTO
op_sxl_T0(void)
748 void OPPROTO
op_sxl_T1(void)
753 #define SIGNBIT (uint32_t)0x80000000
754 /* saturating arithmetic */
755 void OPPROTO
op_addl_T0_T1_setq(void)
760 if (((res
^ T0
) & SIGNBIT
) && !((T0
^ T1
) & SIGNBIT
))
767 void OPPROTO
op_addl_T0_T1_saturate(void)
772 if (((res
^ T0
) & SIGNBIT
) && !((T0
^ T1
) & SIGNBIT
)) {
785 void OPPROTO
op_subl_T0_T1_saturate(void)
790 if (((res
^ T0
) & SIGNBIT
) && ((T0
^ T1
) & SIGNBIT
)) {
803 /* thumb shift by immediate */
804 void OPPROTO
op_shll_T0_im_thumb(void)
809 env
->CF
= (T1
>> (32 - shift
)) & 1;
816 void OPPROTO
op_shrl_T0_im_thumb(void)
825 env
->CF
= (T0
>> (shift
- 1)) & 1;
831 void OPPROTO
op_sarl_T0_im_thumb(void)
837 T0
= ((int32_t)T0
) >> 31;
840 env
->CF
= (T0
>> (shift
- 1)) & 1;
841 T0
= ((int32_t)T0
) >> shift
;
849 void OPPROTO
op_swi(void)
851 env
->exception_index
= EXCP_SWI
;
855 void OPPROTO
op_undef_insn(void)
857 env
->exception_index
= EXCP_UDEF
;
861 void OPPROTO
op_debug(void)
863 env
->exception_index
= EXCP_DEBUG
;
867 /* VFP support. We follow the convention used for VFP instrunctions:
868 Single precition routines have a "s" suffix, double precision a
871 #define VFP_OP(name, p) void OPPROTO op_vfp_##name##p(void)
873 #define VFP_BINOP(name) \
876 FT0s = float32_ ## name (FT0s, FT1s, &env->vfp.fp_status); \
880 FT0d = float64_ ## name (FT0d, FT1d, &env->vfp.fp_status); \
888 #define VFP_HELPER(name) \
891 do_vfp_##name##s(); \
895 do_vfp_##name##d(); \
903 /* XXX: Will this do the right thing for NANs. Should invert the signbit
904 without looking at the rest of the value. */
907 FT0s
= float32_chs(FT0s
);
912 FT0d
= float64_chs(FT0d
);
935 /* Helper routines to perform bitwise copies between float and int. */
936 static inline float32
vfp_itos(uint32_t i
)
947 static inline uint32_t vfp_stoi(float32 s
)
958 /* Integer to float conversion. */
961 FT0s
= uint32_to_float32(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
966 FT0d
= uint32_to_float64(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
971 FT0s
= int32_to_float32(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
976 FT0d
= int32_to_float64(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
979 /* Float to integer conversion. */
982 FT0s
= vfp_itos(float32_to_uint32(FT0s
, &env
->vfp
.fp_status
));
987 FT0s
= vfp_itos(float64_to_uint32(FT0d
, &env
->vfp
.fp_status
));
992 FT0s
= vfp_itos(float32_to_int32(FT0s
, &env
->vfp
.fp_status
));
997 FT0s
= vfp_itos(float64_to_int32(FT0d
, &env
->vfp
.fp_status
));
1000 /* TODO: Set rounding mode properly. */
1003 FT0s
= vfp_itos(float32_to_uint32_round_to_zero(FT0s
, &env
->vfp
.fp_status
));
1008 FT0s
= vfp_itos(float64_to_uint32_round_to_zero(FT0d
, &env
->vfp
.fp_status
));
1013 FT0s
= vfp_itos(float32_to_int32_round_to_zero(FT0s
, &env
->vfp
.fp_status
));
1018 FT0s
= vfp_itos(float64_to_int32_round_to_zero(FT0d
, &env
->vfp
.fp_status
));
1021 /* floating point conversion */
1024 FT0d
= float32_to_float64(FT0s
, &env
->vfp
.fp_status
);
1029 FT0s
= float64_to_float32(FT0d
, &env
->vfp
.fp_status
);
1032 /* Get and Put values from registers. */
1033 VFP_OP(getreg_F0
, d
)
1035 FT0d
= *(float64
*)((char *) env
+ PARAM1
);
1038 VFP_OP(getreg_F0
, s
)
1040 FT0s
= *(float32
*)((char *) env
+ PARAM1
);
1043 VFP_OP(getreg_F1
, d
)
1045 FT1d
= *(float64
*)((char *) env
+ PARAM1
);
1048 VFP_OP(getreg_F1
, s
)
1050 FT1s
= *(float32
*)((char *) env
+ PARAM1
);
1053 VFP_OP(setreg_F0
, d
)
1055 *(float64
*)((char *) env
+ PARAM1
) = FT0d
;
1058 VFP_OP(setreg_F0
, s
)
1060 *(float32
*)((char *) env
+ PARAM1
) = FT0s
;
1063 void OPPROTO
op_vfp_movl_T0_fpscr(void)
1065 do_vfp_get_fpscr ();
1068 void OPPROTO
op_vfp_movl_T0_fpscr_flags(void)
1070 T0
= env
->vfp
.fpscr
& (0xf << 28);
1073 void OPPROTO
op_vfp_movl_fpscr_T0(void)
1078 /* Move between FT0s to T0 */
1079 void OPPROTO
op_vfp_mrs(void)
1081 T0
= vfp_stoi(FT0s
);
1084 void OPPROTO
op_vfp_msr(void)
1086 FT0s
= vfp_itos(T0
);
1089 /* Move between FT0d and {T0,T1} */
1090 void OPPROTO
op_vfp_mrrd(void)
1099 void OPPROTO
op_vfp_mdrr(void)
1108 /* Floating point load/store. Address is in T1 */
1109 void OPPROTO
op_vfp_lds(void)
1111 FT0s
= ldfl((void *)T1
);
1114 void OPPROTO
op_vfp_ldd(void)
1116 FT0d
= ldfq((void *)T1
);
1119 void OPPROTO
op_vfp_sts(void)
1121 stfl((void *)T1
, FT0s
);
1124 void OPPROTO
op_vfp_std(void)
1126 stfq((void *)T1
, FT0d
);