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_T0_T1(void)
109 void OPPROTO
op_movl_T1_im(void)
114 void OPPROTO
op_mov_CF_T1(void)
116 env
->CF
= ((uint32_t)T1
) >> 31;
119 void OPPROTO
op_movl_T2_im(void)
124 void OPPROTO
op_addl_T1_im(void)
129 void OPPROTO
op_addl_T1_T2(void)
134 void OPPROTO
op_subl_T1_T2(void)
139 void OPPROTO
op_addl_T0_T1(void)
144 void OPPROTO
op_addl_T0_T1_cc(void)
151 env
->VF
= (src1
^ T1
^ -1) & (src1
^ T0
);
154 void OPPROTO
op_adcl_T0_T1(void)
159 void OPPROTO
op_adcl_T0_T1_cc(void)
168 env
->CF
= T0
<= src1
;
170 env
->VF
= (src1
^ T1
^ -1) & (src1
^ T0
);
175 #define OPSUB(sub, sbc, res, T0, T1) \
177 void OPPROTO op_ ## sub ## l_T0_T1(void) \
182 void OPPROTO op_ ## sub ## l_T0_T1_cc(void) \
188 env->CF = src1 >= T1; \
189 env->VF = (src1 ^ T1) & (src1 ^ T0); \
193 void OPPROTO op_ ## sbc ## l_T0_T1(void) \
195 res = T0 - T1 + env->CF - 1; \
198 void OPPROTO op_ ## sbc ## l_T0_T1_cc(void) \
204 env->CF = src1 > T1; \
207 env->CF = src1 >= T1; \
209 env->VF = (src1 ^ T1) & (src1 ^ T0); \
215 OPSUB(sub
, sbc
, T0
, T0
, T1
)
217 OPSUB(rsb
, rsc
, T0
, T1
, T0
)
219 void OPPROTO
op_andl_T0_T1(void)
224 void OPPROTO
op_xorl_T0_T1(void)
229 void OPPROTO
op_orl_T0_T1(void)
234 void OPPROTO
op_bicl_T0_T1(void)
239 void OPPROTO
op_notl_T1(void)
244 void OPPROTO
op_logic_T0_cc(void)
249 void OPPROTO
op_logic_T1_cc(void)
254 #define EIP (env->regs[15])
256 void OPPROTO
op_test_eq(void)
259 GOTO_LABEL_PARAM(1);;
263 void OPPROTO
op_test_ne(void)
266 GOTO_LABEL_PARAM(1);;
270 void OPPROTO
op_test_cs(void)
277 void OPPROTO
op_test_cc(void)
284 void OPPROTO
op_test_mi(void)
286 if ((env
->NZF
& 0x80000000) != 0)
291 void OPPROTO
op_test_pl(void)
293 if ((env
->NZF
& 0x80000000) == 0)
298 void OPPROTO
op_test_vs(void)
300 if ((env
->VF
& 0x80000000) != 0)
305 void OPPROTO
op_test_vc(void)
307 if ((env
->VF
& 0x80000000) == 0)
312 void OPPROTO
op_test_hi(void)
314 if (env
->CF
!= 0 && env
->NZF
!= 0)
319 void OPPROTO
op_test_ls(void)
321 if (env
->CF
== 0 || env
->NZF
== 0)
326 void OPPROTO
op_test_ge(void)
328 if (((env
->VF
^ env
->NZF
) & 0x80000000) == 0)
333 void OPPROTO
op_test_lt(void)
335 if (((env
->VF
^ env
->NZF
) & 0x80000000) != 0)
340 void OPPROTO
op_test_gt(void)
342 if (env
->NZF
!= 0 && ((env
->VF
^ env
->NZF
) & 0x80000000) == 0)
347 void OPPROTO
op_test_le(void)
349 if (env
->NZF
== 0 || ((env
->VF
^ env
->NZF
) & 0x80000000) != 0)
354 void OPPROTO
op_goto_tb0(void)
356 GOTO_TB(op_goto_tb0
, PARAM1
, 0);
359 void OPPROTO
op_goto_tb1(void)
361 GOTO_TB(op_goto_tb1
, PARAM1
, 1);
364 void OPPROTO
op_exit_tb(void)
369 void OPPROTO
op_movl_T0_cpsr(void)
375 void OPPROTO
op_movl_T0_spsr(void)
380 void OPPROTO
op_movl_spsr_T0(void)
382 uint32_t mask
= PARAM1
;
383 env
->spsr
= (env
->spsr
& ~mask
) | (T0
& mask
);
386 void OPPROTO
op_movl_cpsr_T0(void)
388 cpsr_write(env
, T0
, PARAM1
);
392 void OPPROTO
op_mul_T0_T1(void)
397 /* 64 bit unsigned mul */
398 void OPPROTO
op_mull_T0_T1(void)
401 res
= (uint64_t)T0
* (uint64_t)T1
;
406 /* 64 bit signed mul */
407 void OPPROTO
op_imull_T0_T1(void)
410 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
415 /* 48 bit signed mul, top 32 bits */
416 void OPPROTO
op_imulw_T0_T1(void)
419 res
= (int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
);
423 void OPPROTO
op_addq_T0_T1(void)
426 res
= ((uint64_t)T1
<< 32) | T0
;
427 res
+= ((uint64_t)(env
->regs
[PARAM2
]) << 32) | (env
->regs
[PARAM1
]);
432 void OPPROTO
op_addq_lo_T0_T1(void)
435 res
= ((uint64_t)T1
<< 32) | T0
;
436 res
+= (uint64_t)(env
->regs
[PARAM1
]);
441 void OPPROTO
op_logicq_cc(void)
443 env
->NZF
= (T1
& 0x80000000) | ((T0
| T1
) != 0);
448 #define MEMSUFFIX _raw
451 #if !defined(CONFIG_USER_ONLY)
452 #define MEMSUFFIX _user
454 #define MEMSUFFIX _kernel
462 void OPPROTO
op_shll_T1_im(void)
467 void OPPROTO
op_shrl_T1_im(void)
469 T1
= (uint32_t)T1
>> PARAM1
;
472 void OPPROTO
op_shrl_T1_0(void)
477 void OPPROTO
op_sarl_T1_im(void)
479 T1
= (int32_t)T1
>> PARAM1
;
482 void OPPROTO
op_sarl_T1_0(void)
484 T1
= (int32_t)T1
>> 31;
487 void OPPROTO
op_rorl_T1_im(void)
491 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
494 void OPPROTO
op_rrxl_T1(void)
496 T1
= ((uint32_t)T1
>> 1) | ((uint32_t)env
->CF
<< 31);
499 /* T1 based, set C flag */
500 void OPPROTO
op_shll_T1_im_cc(void)
502 env
->CF
= (T1
>> (32 - PARAM1
)) & 1;
506 void OPPROTO
op_shrl_T1_im_cc(void)
508 env
->CF
= (T1
>> (PARAM1
- 1)) & 1;
509 T1
= (uint32_t)T1
>> PARAM1
;
512 void OPPROTO
op_shrl_T1_0_cc(void)
514 env
->CF
= (T1
>> 31) & 1;
518 void OPPROTO
op_sarl_T1_im_cc(void)
520 env
->CF
= (T1
>> (PARAM1
- 1)) & 1;
521 T1
= (int32_t)T1
>> PARAM1
;
524 void OPPROTO
op_sarl_T1_0_cc(void)
526 env
->CF
= (T1
>> 31) & 1;
527 T1
= (int32_t)T1
>> 31;
530 void OPPROTO
op_rorl_T1_im_cc(void)
534 env
->CF
= (T1
>> (shift
- 1)) & 1;
535 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
538 void OPPROTO
op_rrxl_T1_cc(void)
542 T1
= ((uint32_t)T1
>> 1) | ((uint32_t)env
->CF
<< 31);
547 void OPPROTO
op_shll_T2_im(void)
552 void OPPROTO
op_shrl_T2_im(void)
554 T2
= (uint32_t)T2
>> PARAM1
;
557 void OPPROTO
op_shrl_T2_0(void)
562 void OPPROTO
op_sarl_T2_im(void)
564 T2
= (int32_t)T2
>> PARAM1
;
567 void OPPROTO
op_sarl_T2_0(void)
569 T2
= (int32_t)T2
>> 31;
572 void OPPROTO
op_rorl_T2_im(void)
576 T2
= ((uint32_t)T2
>> shift
) | (T2
<< (32 - shift
));
579 void OPPROTO
op_rrxl_T2(void)
581 T2
= ((uint32_t)T2
>> 1) | ((uint32_t)env
->CF
<< 31);
584 /* T1 based, use T0 as shift count */
586 void OPPROTO
op_shll_T1_T0(void)
597 void OPPROTO
op_shrl_T1_T0(void)
604 T1
= (uint32_t)T1
>> shift
;
608 void OPPROTO
op_sarl_T1_T0(void)
614 T1
= (int32_t)T1
>> shift
;
617 void OPPROTO
op_rorl_T1_T0(void)
622 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
627 /* T1 based, use T0 as shift count and compute CF */
629 void OPPROTO
op_shll_T1_T0_cc(void)
639 } else if (shift
!= 0) {
640 env
->CF
= (T1
>> (32 - shift
)) & 1;
646 void OPPROTO
op_shrl_T1_T0_cc(void)
652 env
->CF
= (T1
>> 31) & 1;
656 } else if (shift
!= 0) {
657 env
->CF
= (T1
>> (shift
- 1)) & 1;
658 T1
= (uint32_t)T1
>> shift
;
663 void OPPROTO
op_sarl_T1_T0_cc(void)
668 env
->CF
= (T1
>> 31) & 1;
669 T1
= (int32_t)T1
>> 31;
671 env
->CF
= (T1
>> (shift
- 1)) & 1;
672 T1
= (int32_t)T1
>> shift
;
677 void OPPROTO
op_rorl_T1_T0_cc(void)
681 shift
= shift1
& 0x1f;
684 env
->CF
= (T1
>> 31) & 1;
686 env
->CF
= (T1
>> (shift
- 1)) & 1;
687 T1
= ((uint32_t)T1
>> shift
) | (T1
<< (32 - shift
));
693 void OPPROTO
op_clz_T0(void)
696 for (count
= 32; T0
> 0; count
--)
702 void OPPROTO
op_sarl_T0_im(void)
704 T0
= (int32_t)T0
>> PARAM1
;
707 /* Sign/zero extend */
708 void OPPROTO
op_sxth_T0(void)
713 void OPPROTO
op_sxth_T1(void)
718 void OPPROTO
op_sxtb_T1(void)
723 void OPPROTO
op_uxtb_T1(void)
728 void OPPROTO
op_uxth_T1(void)
733 void OPPROTO
op_sxtb16_T1(void)
736 res
= (uint16_t)(int8_t)T1
;
737 res
|= (uint32_t)(int8_t)(T1
>> 16) << 16;
741 void OPPROTO
op_uxtb16_T1(void)
744 res
= (uint16_t)(uint8_t)T1
;
745 res
|= (uint32_t)(uint8_t)(T1
>> 16) << 16;
749 #define SIGNBIT (uint32_t)0x80000000
750 /* saturating arithmetic */
751 void OPPROTO
op_addl_T0_T1_setq(void)
756 if (((res
^ T0
) & SIGNBIT
) && !((T0
^ T1
) & SIGNBIT
))
763 void OPPROTO
op_addl_T0_T1_saturate(void)
768 if (((res
^ T0
) & SIGNBIT
) && !((T0
^ T1
) & SIGNBIT
)) {
781 void OPPROTO
op_subl_T0_T1_saturate(void)
786 if (((res
^ T0
) & SIGNBIT
) && ((T0
^ T1
) & SIGNBIT
)) {
799 void OPPROTO
op_double_T1_saturate(void)
804 if (val
>= 0x40000000) {
807 } else if (val
<= (int32_t)0xc0000000) {
816 /* thumb shift by immediate */
817 void OPPROTO
op_shll_T0_im_thumb(void)
822 env
->CF
= (T1
>> (32 - shift
)) & 1;
829 void OPPROTO
op_shrl_T0_im_thumb(void)
835 env
->CF
= ((uint32_t)shift
) >> 31;
838 env
->CF
= (T0
>> (shift
- 1)) & 1;
845 void OPPROTO
op_sarl_T0_im_thumb(void)
851 T0
= ((int32_t)T0
) >> 31;
854 env
->CF
= (T0
>> (shift
- 1)) & 1;
855 T0
= ((int32_t)T0
) >> shift
;
863 void OPPROTO
op_swi(void)
865 env
->exception_index
= EXCP_SWI
;
869 void OPPROTO
op_undef_insn(void)
871 env
->exception_index
= EXCP_UDEF
;
875 void OPPROTO
op_debug(void)
877 env
->exception_index
= EXCP_DEBUG
;
881 void OPPROTO
op_wfi(void)
883 env
->exception_index
= EXCP_HLT
;
888 void OPPROTO
op_bkpt(void)
890 env
->exception_index
= EXCP_BKPT
;
894 /* VFP support. We follow the convention used for VFP instrunctions:
895 Single precition routines have a "s" suffix, double precision a
898 #define VFP_OP(name, p) void OPPROTO op_vfp_##name##p(void)
900 #define VFP_BINOP(name) \
903 FT0s = float32_ ## name (FT0s, FT1s, &env->vfp.fp_status); \
907 FT0d = float64_ ## name (FT0d, FT1d, &env->vfp.fp_status); \
915 #define VFP_HELPER(name) \
918 do_vfp_##name##s(); \
922 do_vfp_##name##d(); \
930 /* XXX: Will this do the right thing for NANs. Should invert the signbit
931 without looking at the rest of the value. */
934 FT0s
= float32_chs(FT0s
);
939 FT0d
= float64_chs(FT0d
);
962 /* Helper routines to perform bitwise copies between float and int. */
963 static inline float32
vfp_itos(uint32_t i
)
974 static inline uint32_t vfp_stoi(float32 s
)
985 /* Integer to float conversion. */
988 FT0s
= uint32_to_float32(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
993 FT0d
= uint32_to_float64(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
998 FT0s
= int32_to_float32(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
1003 FT0d
= int32_to_float64(vfp_stoi(FT0s
), &env
->vfp
.fp_status
);
1006 /* Float to integer conversion. */
1009 FT0s
= vfp_itos(float32_to_uint32(FT0s
, &env
->vfp
.fp_status
));
1014 FT0s
= vfp_itos(float64_to_uint32(FT0d
, &env
->vfp
.fp_status
));
1019 FT0s
= vfp_itos(float32_to_int32(FT0s
, &env
->vfp
.fp_status
));
1024 FT0s
= vfp_itos(float64_to_int32(FT0d
, &env
->vfp
.fp_status
));
1027 /* TODO: Set rounding mode properly. */
1030 FT0s
= vfp_itos(float32_to_uint32_round_to_zero(FT0s
, &env
->vfp
.fp_status
));
1035 FT0s
= vfp_itos(float64_to_uint32_round_to_zero(FT0d
, &env
->vfp
.fp_status
));
1040 FT0s
= vfp_itos(float32_to_int32_round_to_zero(FT0s
, &env
->vfp
.fp_status
));
1045 FT0s
= vfp_itos(float64_to_int32_round_to_zero(FT0d
, &env
->vfp
.fp_status
));
1048 /* floating point conversion */
1051 FT0d
= float32_to_float64(FT0s
, &env
->vfp
.fp_status
);
1056 FT0s
= float64_to_float32(FT0d
, &env
->vfp
.fp_status
);
1059 /* Get and Put values from registers. */
1060 VFP_OP(getreg_F0
, d
)
1062 FT0d
= *(float64
*)((char *) env
+ PARAM1
);
1065 VFP_OP(getreg_F0
, s
)
1067 FT0s
= *(float32
*)((char *) env
+ PARAM1
);
1070 VFP_OP(getreg_F1
, d
)
1072 FT1d
= *(float64
*)((char *) env
+ PARAM1
);
1075 VFP_OP(getreg_F1
, s
)
1077 FT1s
= *(float32
*)((char *) env
+ PARAM1
);
1080 VFP_OP(setreg_F0
, d
)
1082 *(float64
*)((char *) env
+ PARAM1
) = FT0d
;
1085 VFP_OP(setreg_F0
, s
)
1087 *(float32
*)((char *) env
+ PARAM1
) = FT0s
;
1090 void OPPROTO
op_vfp_movl_T0_fpscr(void)
1092 do_vfp_get_fpscr ();
1095 void OPPROTO
op_vfp_movl_T0_fpscr_flags(void)
1097 T0
= env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (0xf << 28);
1100 void OPPROTO
op_vfp_movl_fpscr_T0(void)
1105 void OPPROTO
op_vfp_movl_T0_xreg(void)
1107 T0
= env
->vfp
.xregs
[PARAM1
];
1110 void OPPROTO
op_vfp_movl_xreg_T0(void)
1112 env
->vfp
.xregs
[PARAM1
] = T0
;
1115 /* Move between FT0s to T0 */
1116 void OPPROTO
op_vfp_mrs(void)
1118 T0
= vfp_stoi(FT0s
);
1121 void OPPROTO
op_vfp_msr(void)
1123 FT0s
= vfp_itos(T0
);
1126 /* Move between FT0d and {T0,T1} */
1127 void OPPROTO
op_vfp_mrrd(void)
1136 void OPPROTO
op_vfp_mdrr(void)
1145 /* Copy the most significant bit to T0 to all bits of T1. */
1146 void OPPROTO
op_signbit_T1_T0(void)
1148 T1
= (int32_t)T0
>> 31;
1151 void OPPROTO
op_movl_cp15_T0(void)
1153 helper_set_cp15(env
, PARAM1
, T0
);
1157 void OPPROTO
op_movl_T0_cp15(void)
1159 T0
= helper_get_cp15(env
, PARAM1
);
1163 /* Access to user mode registers from privileged modes. */
1164 void OPPROTO
op_movl_T0_user(void)
1168 T0
= env
->banked_r13
[0];
1169 } else if (regno
== 14) {
1170 T0
= env
->banked_r14
[0];
1171 } else if ((env
->uncached_cpsr
& 0x1f) == ARM_CPU_MODE_FIQ
) {
1172 T0
= env
->usr_regs
[regno
- 8];
1174 T0
= env
->regs
[regno
];
1180 void OPPROTO
op_movl_user_T0(void)
1184 env
->banked_r13
[0] = T0
;
1185 } else if (regno
== 14) {
1186 env
->banked_r14
[0] = T0
;
1187 } else if ((env
->uncached_cpsr
& 0x1f) == ARM_CPU_MODE_FIQ
) {
1188 env
->usr_regs
[regno
- 8] = T0
;
1190 env
->regs
[regno
] = T0
;
1195 void OPPROTO
op_movl_T2_T0(void)
1200 void OPPROTO
op_movl_T0_T2(void)