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 GOTO_LABEL_PARAM(1);;
258 void OPPROTO op_test_ne(void)
261 GOTO_LABEL_PARAM(1);;
265 void OPPROTO op_test_cs(void)
272 void OPPROTO op_test_cc(void)
279 void OPPROTO op_test_mi(void)
281 if ((env->NZF & 0x80000000) != 0)
286 void OPPROTO op_test_pl(void)
288 if ((env->NZF & 0x80000000) == 0)
293 void OPPROTO op_test_vs(void)
295 if ((env->VF & 0x80000000) != 0)
300 void OPPROTO op_test_vc(void)
302 if ((env->VF & 0x80000000) == 0)
307 void OPPROTO op_test_hi(void)
309 if (env->CF != 0 && env->NZF != 0)
314 void OPPROTO op_test_ls(void)
316 if (env->CF == 0 || env->NZF == 0)
321 void OPPROTO op_test_ge(void)
323 if (((env->VF ^ env->NZF) & 0x80000000) == 0)
328 void OPPROTO op_test_lt(void)
330 if (((env->VF ^ env->NZF) & 0x80000000) != 0)
335 void OPPROTO op_test_gt(void)
337 if (env->NZF != 0 && ((env->VF ^ env->NZF) & 0x80000000) == 0)
342 void OPPROTO op_test_le(void)
344 if (env->NZF == 0 || ((env->VF ^ env->NZF) & 0x80000000) != 0)
349 void OPPROTO op_jmp0(void)
351 JUMP_TB(op_jmp0, PARAM1, 0, PARAM2);
354 void OPPROTO op_jmp1(void)
356 JUMP_TB(op_jmp1, PARAM1, 1, PARAM2);
359 void OPPROTO op_exit_tb(void)
364 void OPPROTO op_movl_T0_psr(void)
369 /* NOTE: N = 1 and Z = 1 cannot be stored currently */
370 void OPPROTO op_movl_psr_T0(void)
374 env->CF = (psr >> 29) & 1;
375 env->NZF = (psr & 0xc0000000) ^ 0x40000000;
376 env->VF = (psr << 3) & 0x80000000;
377 /* for user mode we do not update other state info */
380 void OPPROTO op_mul_T0_T1(void)
385 /* 64 bit unsigned mul */
386 void OPPROTO op_mull_T0_T1(void)
389 res = (uint64_t)T0 * (uint64_t)T1;
394 /* 64 bit signed mul */
395 void OPPROTO op_imull_T0_T1(void)
398 res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
403 /* 48 bit signed mul, top 32 bits */
404 void OPPROTO op_imulw_T0_T1(void)
407 res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
411 void OPPROTO op_addq_T0_T1(void)
414 res = ((uint64_t)T1 << 32) | T0;
415 res += ((uint64_t)(env->regs[PARAM2]) << 32) | (env->regs[PARAM1]);
420 void OPPROTO op_addq_lo_T0_T1(void)
423 res = ((uint64_t)T1 << 32) | T0;
424 res += (uint64_t)(env->regs[PARAM1]);
429 void OPPROTO op_logicq_cc(void)
431 env->NZF = (T1 & 0x80000000) | ((T0 | T1) != 0);
436 void OPPROTO op_ldub_T0_T1(void)
438 T0 = ldub((void *)T1);
441 void OPPROTO op_ldsb_T0_T1(void)
443 T0 = ldsb((void *)T1);
446 void OPPROTO op_lduw_T0_T1(void)
448 T0 = lduw((void *)T1);
451 void OPPROTO op_ldsw_T0_T1(void)
453 T0 = ldsw((void *)T1);
456 void OPPROTO op_ldl_T0_T1(void)
458 T0 = ldl((void *)T1);
461 void OPPROTO op_stb_T0_T1(void)
466 void OPPROTO op_stw_T0_T1(void)
471 void OPPROTO op_stl_T0_T1(void)
476 void OPPROTO op_swpb_T0_T1(void)
481 tmp = ldub((void *)T1);
487 void OPPROTO op_swpl_T0_T1(void)
492 tmp = ldl((void *)T1);
502 void OPPROTO op_shll_T1_im(void)
507 void OPPROTO op_shrl_T1_im(void)
509 T1 = (uint32_t)T1 >> PARAM1;
512 void OPPROTO op_shrl_T1_0(void)
517 void OPPROTO op_sarl_T1_im(void)
519 T1 = (int32_t)T1 >> PARAM1;
522 void OPPROTO op_sarl_T1_0(void)
524 T1 = (int32_t)T1 >> 31;
527 void OPPROTO op_rorl_T1_im(void)
531 T1 = ((uint32_t)T1 >> shift) | (T1 << (32 - shift));
534 void OPPROTO op_rrxl_T1(void)
536 T1 = ((uint32_t)T1 >> 1) | ((uint32_t)env->CF << 31);
539 /* T1 based, set C flag */
540 void OPPROTO op_shll_T1_im_cc(void)
542 env->CF = (T1 >> (32 - PARAM1)) & 1;
546 void OPPROTO op_shrl_T1_im_cc(void)
548 env->CF = (T1 >> (PARAM1 - 1)) & 1;
549 T1 = (uint32_t)T1 >> PARAM1;
552 void OPPROTO op_shrl_T1_0_cc(void)
554 env->CF = (T1 >> 31) & 1;
558 void OPPROTO op_sarl_T1_im_cc(void)
560 env->CF = (T1 >> (PARAM1 - 1)) & 1;
561 T1 = (int32_t)T1 >> PARAM1;
564 void OPPROTO op_sarl_T1_0_cc(void)
566 env->CF = (T1 >> 31) & 1;
567 T1 = (int32_t)T1 >> 31;
570 void OPPROTO op_rorl_T1_im_cc(void)
574 env->CF = (T1 >> (shift - 1)) & 1;
575 T1 = ((uint32_t)T1 >> shift) | (T1 << (32 - shift));
578 void OPPROTO op_rrxl_T1_cc(void)
582 T1 = ((uint32_t)T1 >> 1) | ((uint32_t)env->CF << 31);
587 void OPPROTO op_shll_T2_im(void)
592 void OPPROTO op_shrl_T2_im(void)
594 T2 = (uint32_t)T2 >> PARAM1;
597 void OPPROTO op_shrl_T2_0(void)
602 void OPPROTO op_sarl_T2_im(void)
604 T2 = (int32_t)T2 >> PARAM1;
607 void OPPROTO op_sarl_T2_0(void)
609 T2 = (int32_t)T2 >> 31;
612 void OPPROTO op_rorl_T2_im(void)
616 T2 = ((uint32_t)T2 >> shift) | (T2 << (32 - shift));
619 void OPPROTO op_rrxl_T2(void)
621 T2 = ((uint32_t)T2 >> 1) | ((uint32_t)env->CF << 31);
624 /* T1 based, use T0 as shift count */
626 void OPPROTO op_shll_T1_T0(void)
637 void OPPROTO op_shrl_T1_T0(void)
644 T1 = (uint32_t)T1 >> shift;
648 void OPPROTO op_sarl_T1_T0(void)
654 T1 = (int32_t)T1 >> shift;
657 void OPPROTO op_rorl_T1_T0(void)
662 T1 = ((uint32_t)T1 >> shift) | (T1 << (32 - shift));
667 /* T1 based, use T0 as shift count and compute CF */
669 void OPPROTO op_shll_T1_T0_cc(void)
679 } else if (shift != 0) {
680 env->CF = (T1 >> (32 - shift)) & 1;
686 void OPPROTO op_shrl_T1_T0_cc(void)
692 env->CF = (T1 >> 31) & 1;
696 } else if (shift != 0) {
697 env->CF = (T1 >> (shift - 1)) & 1;
698 T1 = (uint32_t)T1 >> shift;
703 void OPPROTO op_sarl_T1_T0_cc(void)
708 env->CF = (T1 >> 31) & 1;
709 T1 = (int32_t)T1 >> 31;
711 env->CF = (T1 >> (shift - 1)) & 1;
712 T1 = (int32_t)T1 >> shift;
717 void OPPROTO op_rorl_T1_T0_cc(void)
721 shift = shift1 & 0x1f;
724 env->CF = (T1 >> 31) & 1;
726 env->CF = (T1 >> (shift - 1)) & 1;
727 T1 = ((uint32_t)T1 >> shift) | (T1 << (32 - shift));
733 void OPPROTO op_clz_T0(void)
736 for (count = 32; T0 > 0; count--)
742 void OPPROTO op_sarl_T0_im(void)
744 T0 = (int32_t)T0 >> PARAM1;
747 /* 16->32 Sign extend */
748 void OPPROTO op_sxl_T0(void)
753 void OPPROTO op_sxl_T1(void)
758 #define SIGNBIT (uint32_t)0x80000000
759 /* saturating arithmetic */
760 void OPPROTO op_addl_T0_T1_setq(void)
765 if (((res ^ T0) & SIGNBIT) && !((T0 ^ T1) & SIGNBIT))
772 void OPPROTO op_addl_T0_T1_saturate(void)
777 if (((res ^ T0) & SIGNBIT) && !((T0 ^ T1) & SIGNBIT)) {
790 void OPPROTO op_subl_T0_T1_saturate(void)
795 if (((res ^ T0) & SIGNBIT) && ((T0 ^ T1) & SIGNBIT)) {
808 void OPPROTO op_double_T1_saturate(void)
813 if (val >= 0x40000000) {
816 } else if (val <= (int32_t)0xc0000000) {
825 /* thumb shift by immediate */
826 void OPPROTO op_shll_T0_im_thumb(void)
831 env->CF = (T1 >> (32 - shift)) & 1;
838 void OPPROTO op_shrl_T0_im_thumb(void)
844 env->CF = ((uint32_t)shift) >> 31;
847 env->CF = (T0 >> (shift - 1)) & 1;
854 void OPPROTO op_sarl_T0_im_thumb(void)
860 T0 = ((int32_t)T0) >> 31;
863 env->CF = (T0 >> (shift - 1)) & 1;
864 T0 = ((int32_t)T0) >> shift;
872 void OPPROTO op_swi(void)
874 env->exception_index = EXCP_SWI;
878 void OPPROTO op_undef_insn(void)
880 env->exception_index = EXCP_UDEF;
884 void OPPROTO op_debug(void)
886 env->exception_index = EXCP_DEBUG;
890 /* VFP support. We follow the convention used for VFP instrunctions:
891 Single precition routines have a "s" suffix, double precision a
894 #define VFP_OP(name, p) void OPPROTO op_vfp_##name##p(void)
896 #define VFP_BINOP(name) \
899 FT0s = float32_ ## name (FT0s, FT1s, &env->vfp.fp_status); \
903 FT0d = float64_ ## name (FT0d, FT1d, &env->vfp.fp_status); \
911 #define VFP_HELPER(name) \
914 do_vfp_##name##s(); \
918 do_vfp_##name##d(); \
926 /* XXX: Will this do the right thing for NANs. Should invert the signbit
927 without looking at the rest of the value. */
930 FT0s = float32_chs(FT0s);
935 FT0d = float64_chs(FT0d);
958 /* Helper routines to perform bitwise copies between float and int. */
959 static inline float32 vfp_itos(uint32_t i)
970 static inline uint32_t vfp_stoi(float32 s)
981 /* Integer to float conversion. */
984 FT0s = uint32_to_float32(vfp_stoi(FT0s), &env->vfp.fp_status);
989 FT0d = uint32_to_float64(vfp_stoi(FT0s), &env->vfp.fp_status);
994 FT0s = int32_to_float32(vfp_stoi(FT0s), &env->vfp.fp_status);
999 FT0d = int32_to_float64(vfp_stoi(FT0s), &env->vfp.fp_status);
1002 /* Float to integer conversion. */
1005 FT0s = vfp_itos(float32_to_uint32(FT0s, &env->vfp.fp_status));
1010 FT0s = vfp_itos(float64_to_uint32(FT0d, &env->vfp.fp_status));
1015 FT0s = vfp_itos(float32_to_int32(FT0s, &env->vfp.fp_status));
1020 FT0s = vfp_itos(float64_to_int32(FT0d, &env->vfp.fp_status));
1023 /* TODO: Set rounding mode properly. */
1026 FT0s = vfp_itos(float32_to_uint32_round_to_zero(FT0s, &env->vfp.fp_status));
1031 FT0s = vfp_itos(float64_to_uint32_round_to_zero(FT0d, &env->vfp.fp_status));
1036 FT0s = vfp_itos(float32_to_int32_round_to_zero(FT0s, &env->vfp.fp_status));
1041 FT0s = vfp_itos(float64_to_int32_round_to_zero(FT0d, &env->vfp.fp_status));
1044 /* floating point conversion */
1047 FT0d = float32_to_float64(FT0s, &env->vfp.fp_status);
1052 FT0s = float64_to_float32(FT0d, &env->vfp.fp_status);
1055 /* Get and Put values from registers. */
1056 VFP_OP(getreg_F0, d)
1058 FT0d = *(float64 *)((char *) env + PARAM1);
1061 VFP_OP(getreg_F0, s)
1063 FT0s = *(float32 *)((char *) env + PARAM1);
1066 VFP_OP(getreg_F1, d)
1068 FT1d = *(float64 *)((char *) env + PARAM1);
1071 VFP_OP(getreg_F1, s)
1073 FT1s = *(float32 *)((char *) env + PARAM1);
1076 VFP_OP(setreg_F0, d)
1078 *(float64 *)((char *) env + PARAM1) = FT0d;
1081 VFP_OP(setreg_F0, s)
1083 *(float32 *)((char *) env + PARAM1) = FT0s;
1086 void OPPROTO op_vfp_movl_T0_fpscr(void)
1088 do_vfp_get_fpscr ();
1091 void OPPROTO op_vfp_movl_T0_fpscr_flags(void)
1093 T0 = env->vfp.fpscr & (0xf << 28);
1096 void OPPROTO op_vfp_movl_fpscr_T0(void)
1101 /* Move between FT0s to T0 */
1102 void OPPROTO op_vfp_mrs(void)
1104 T0 = vfp_stoi(FT0s);
1107 void OPPROTO op_vfp_msr(void)
1109 FT0s = vfp_itos(T0);
1112 /* Move between FT0d and {T0,T1} */
1113 void OPPROTO op_vfp_mrrd(void)
1122 void OPPROTO op_vfp_mdrr(void)
1131 /* Floating point load/store. Address is in T1 */
1132 void OPPROTO op_vfp_lds(void)
1134 FT0s = ldfl((void *)T1);
1137 void OPPROTO op_vfp_ldd(void)
1139 FT0d = ldfq((void *)T1);
1142 void OPPROTO op_vfp_sts(void)
1144 stfl((void *)T1, FT0s);
1147 void OPPROTO op_vfp_std(void)
1149 stfq((void *)T1, FT0d);