2 * CRIS emulation for qemu: main translation routines.
4 * Copyright (c) 2008 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
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, see <http://www.gnu.org/licenses/>.
23 * The condition code translation is in need of attention.
38 #include "crisv32-decode.h"
39 #include "qemu-common.h"
46 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
48 # define LOG_DIS(...) do { } while (0)
52 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
53 #define BUG_ON(x) ({if (x) BUG();})
57 /* Used by the decoder. */
58 #define EXTRACT_FIELD(src, start, end) \
59 (((src) >> start) & ((1 << (end - start + 1)) - 1))
61 #define CC_MASK_NZ 0xc
62 #define CC_MASK_NZV 0xe
63 #define CC_MASK_NZVC 0xf
64 #define CC_MASK_RNZV 0x10e
66 static TCGv_ptr cpu_env
;
67 static TCGv cpu_R
[16];
68 static TCGv cpu_PR
[16];
72 static TCGv cc_result
;
77 static TCGv env_btaken
;
78 static TCGv env_btarget
;
81 #include "gen-icount.h"
83 /* This is the state at translation time. */
84 typedef struct DisasContext
{
89 unsigned int (*decoder
)(struct DisasContext
*dc
);
94 unsigned int zsize
, zzsize
;
108 int cc_size_uptodate
; /* -1 invalid or last written value. */
110 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
111 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
112 int flagx_known
; /* Wether or not flags_x has the x flag known at
116 int clear_x
; /* Clear x after this insn? */
117 int clear_prefix
; /* Clear prefix after this insn? */
118 int clear_locked_irq
; /* Clear the irq lockout. */
119 int cpustate_changed
;
120 unsigned int tb_flags
; /* tb dependent flags. */
125 #define JMP_DIRECT_CC 2
126 #define JMP_INDIRECT 3
127 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
132 struct TranslationBlock
*tb
;
133 int singlestep_enabled
;
136 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
138 printf ("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
139 qemu_log("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
140 cpu_abort(dc
->env
, "%s:%d\n", file
, line
);
143 static const char *regnames
[] =
145 "$r0", "$r1", "$r2", "$r3",
146 "$r4", "$r5", "$r6", "$r7",
147 "$r8", "$r9", "$r10", "$r11",
148 "$r12", "$r13", "$sp", "$acr",
150 static const char *pregnames
[] =
152 "$bz", "$vr", "$pid", "$srs",
153 "$wz", "$exs", "$eda", "$mof",
154 "$dz", "$ebp", "$erp", "$srp",
155 "$nrp", "$ccs", "$usp", "$spc",
158 /* We need this table to handle preg-moves with implicit width. */
159 static int preg_sizes
[] = {
170 #define t_gen_mov_TN_env(tn, member) \
171 _t_gen_mov_TN_env((tn), offsetof(CPUState, member))
172 #define t_gen_mov_env_TN(member, tn) \
173 _t_gen_mov_env_TN(offsetof(CPUState, member), (tn))
175 static inline void t_gen_mov_TN_reg(TCGv tn
, int r
)
178 fprintf(stderr
, "wrong register read $r%d\n", r
);
179 tcg_gen_mov_tl(tn
, cpu_R
[r
]);
181 static inline void t_gen_mov_reg_TN(int r
, TCGv tn
)
184 fprintf(stderr
, "wrong register write $r%d\n", r
);
185 tcg_gen_mov_tl(cpu_R
[r
], tn
);
188 static inline void _t_gen_mov_TN_env(TCGv tn
, int offset
)
190 if (offset
> sizeof (CPUState
))
191 fprintf(stderr
, "wrong load from env from off=%d\n", offset
);
192 tcg_gen_ld_tl(tn
, cpu_env
, offset
);
194 static inline void _t_gen_mov_env_TN(int offset
, TCGv tn
)
196 if (offset
> sizeof (CPUState
))
197 fprintf(stderr
, "wrong store to env at off=%d\n", offset
);
198 tcg_gen_st_tl(tn
, cpu_env
, offset
);
201 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
204 fprintf(stderr
, "wrong register read $p%d\n", r
);
205 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
206 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
208 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
210 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
212 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
215 fprintf(stderr
, "wrong register write $p%d\n", r
);
216 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
218 else if (r
== PR_SRS
)
219 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
222 gen_helper_tlb_flush_pid(tn
);
223 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
)
224 gen_helper_spc_write(tn
);
225 else if (r
== PR_CCS
)
226 dc
->cpustate_changed
= 1;
227 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
231 /* Sign extend at translation time. */
232 static int sign_extend(unsigned int val
, unsigned int width
)
244 static int cris_fetch(DisasContext
*dc
, uint32_t addr
,
245 unsigned int size
, unsigned int sign
)
274 cpu_abort(dc
->env
, "Invalid fetch size %d\n", size
);
280 static void cris_lock_irq(DisasContext
*dc
)
282 dc
->clear_locked_irq
= 0;
283 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
286 static inline void t_gen_raise_exception(uint32_t index
)
288 TCGv_i32 tmp
= tcg_const_i32(index
);
289 gen_helper_raise_exception(tmp
);
290 tcg_temp_free_i32(tmp
);
293 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
298 t_31
= tcg_const_tl(31);
299 tcg_gen_shl_tl(d
, a
, b
);
301 tcg_gen_sub_tl(t0
, t_31
, b
);
302 tcg_gen_sar_tl(t0
, t0
, t_31
);
303 tcg_gen_and_tl(t0
, t0
, d
);
304 tcg_gen_xor_tl(d
, d
, t0
);
309 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
314 t_31
= tcg_temp_new();
315 tcg_gen_shr_tl(d
, a
, b
);
317 tcg_gen_movi_tl(t_31
, 31);
318 tcg_gen_sub_tl(t0
, t_31
, b
);
319 tcg_gen_sar_tl(t0
, t0
, t_31
);
320 tcg_gen_and_tl(t0
, t0
, d
);
321 tcg_gen_xor_tl(d
, d
, t0
);
326 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
331 t_31
= tcg_temp_new();
332 tcg_gen_sar_tl(d
, a
, b
);
334 tcg_gen_movi_tl(t_31
, 31);
335 tcg_gen_sub_tl(t0
, t_31
, b
);
336 tcg_gen_sar_tl(t0
, t0
, t_31
);
337 tcg_gen_or_tl(d
, d
, t0
);
342 /* 64-bit signed mul, lower result in d and upper in d2. */
343 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
347 t0
= tcg_temp_new_i64();
348 t1
= tcg_temp_new_i64();
350 tcg_gen_ext_i32_i64(t0
, a
);
351 tcg_gen_ext_i32_i64(t1
, b
);
352 tcg_gen_mul_i64(t0
, t0
, t1
);
354 tcg_gen_trunc_i64_i32(d
, t0
);
355 tcg_gen_shri_i64(t0
, t0
, 32);
356 tcg_gen_trunc_i64_i32(d2
, t0
);
358 tcg_temp_free_i64(t0
);
359 tcg_temp_free_i64(t1
);
362 /* 64-bit unsigned muls, lower result in d and upper in d2. */
363 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
367 t0
= tcg_temp_new_i64();
368 t1
= tcg_temp_new_i64();
370 tcg_gen_extu_i32_i64(t0
, a
);
371 tcg_gen_extu_i32_i64(t1
, b
);
372 tcg_gen_mul_i64(t0
, t0
, t1
);
374 tcg_gen_trunc_i64_i32(d
, t0
);
375 tcg_gen_shri_i64(t0
, t0
, 32);
376 tcg_gen_trunc_i64_i32(d2
, t0
);
378 tcg_temp_free_i64(t0
);
379 tcg_temp_free_i64(t1
);
382 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
386 l1
= gen_new_label();
393 tcg_gen_shli_tl(d
, a
, 1);
394 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
395 tcg_gen_sub_tl(d
, d
, b
);
399 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
409 tcg_gen_shli_tl(d
, a
, 1);
410 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
411 tcg_gen_sari_tl(t
, t
, 31);
412 tcg_gen_and_tl(t
, t
, b
);
413 tcg_gen_add_tl(d
, d
, t
);
417 /* Extended arithmetics on CRIS. */
418 static inline void t_gen_add_flag(TCGv d
, int flag
)
423 t_gen_mov_TN_preg(c
, PR_CCS
);
424 /* Propagate carry into d. */
425 tcg_gen_andi_tl(c
, c
, 1 << flag
);
427 tcg_gen_shri_tl(c
, c
, flag
);
428 tcg_gen_add_tl(d
, d
, c
);
432 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
434 if (dc
->flagx_known
) {
439 t_gen_mov_TN_preg(c
, PR_CCS
);
440 /* C flag is already at bit 0. */
441 tcg_gen_andi_tl(c
, c
, C_FLAG
);
442 tcg_gen_add_tl(d
, d
, c
);
450 t_gen_mov_TN_preg(x
, PR_CCS
);
451 tcg_gen_mov_tl(c
, x
);
453 /* Propagate carry into d if X is set. Branch free. */
454 tcg_gen_andi_tl(c
, c
, C_FLAG
);
455 tcg_gen_andi_tl(x
, x
, X_FLAG
);
456 tcg_gen_shri_tl(x
, x
, 4);
458 tcg_gen_and_tl(x
, x
, c
);
459 tcg_gen_add_tl(d
, d
, x
);
465 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
467 if (dc
->flagx_known
) {
472 t_gen_mov_TN_preg(c
, PR_CCS
);
473 /* C flag is already at bit 0. */
474 tcg_gen_andi_tl(c
, c
, C_FLAG
);
475 tcg_gen_sub_tl(d
, d
, c
);
483 t_gen_mov_TN_preg(x
, PR_CCS
);
484 tcg_gen_mov_tl(c
, x
);
486 /* Propagate carry into d if X is set. Branch free. */
487 tcg_gen_andi_tl(c
, c
, C_FLAG
);
488 tcg_gen_andi_tl(x
, x
, X_FLAG
);
489 tcg_gen_shri_tl(x
, x
, 4);
491 tcg_gen_and_tl(x
, x
, c
);
492 tcg_gen_sub_tl(d
, d
, x
);
498 /* Swap the two bytes within each half word of the s operand.
499 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
500 static inline void t_gen_swapb(TCGv d
, TCGv s
)
505 org_s
= tcg_temp_new();
507 /* d and s may refer to the same object. */
508 tcg_gen_mov_tl(org_s
, s
);
509 tcg_gen_shli_tl(t
, org_s
, 8);
510 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
511 tcg_gen_shri_tl(t
, org_s
, 8);
512 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
513 tcg_gen_or_tl(d
, d
, t
);
515 tcg_temp_free(org_s
);
518 /* Swap the halfwords of the s operand. */
519 static inline void t_gen_swapw(TCGv d
, TCGv s
)
522 /* d and s refer the same object. */
524 tcg_gen_mov_tl(t
, s
);
525 tcg_gen_shli_tl(d
, t
, 16);
526 tcg_gen_shri_tl(t
, t
, 16);
527 tcg_gen_or_tl(d
, d
, t
);
531 /* Reverse the within each byte.
532 T0 = (((T0 << 7) & 0x80808080) |
533 ((T0 << 5) & 0x40404040) |
534 ((T0 << 3) & 0x20202020) |
535 ((T0 << 1) & 0x10101010) |
536 ((T0 >> 1) & 0x08080808) |
537 ((T0 >> 3) & 0x04040404) |
538 ((T0 >> 5) & 0x02020202) |
539 ((T0 >> 7) & 0x01010101));
541 static inline void t_gen_swapr(TCGv d
, TCGv s
)
544 int shift
; /* LSL when positive, LSR when negative. */
559 /* d and s refer the same object. */
561 org_s
= tcg_temp_new();
562 tcg_gen_mov_tl(org_s
, s
);
564 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
565 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
566 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
567 if (bitrev
[i
].shift
>= 0) {
568 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
570 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
572 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
573 tcg_gen_or_tl(d
, d
, t
);
576 tcg_temp_free(org_s
);
579 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
583 l1
= gen_new_label();
585 /* Conditional jmp. */
586 tcg_gen_mov_tl(env_pc
, pc_false
);
587 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
588 tcg_gen_mov_tl(env_pc
, pc_true
);
592 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
594 TranslationBlock
*tb
;
596 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
598 tcg_gen_movi_tl(env_pc
, dest
);
599 tcg_gen_exit_tb((long)tb
+ n
);
601 tcg_gen_movi_tl(env_pc
, dest
);
606 static inline void cris_clear_x_flag(DisasContext
*dc
)
608 if (dc
->flagx_known
&& dc
->flags_x
)
609 dc
->flags_uptodate
= 0;
615 static void cris_flush_cc_state(DisasContext
*dc
)
617 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
618 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
619 dc
->cc_size_uptodate
= dc
->cc_size
;
621 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
622 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
625 static void cris_evaluate_flags(DisasContext
*dc
)
627 if (dc
->flags_uptodate
)
630 cris_flush_cc_state(dc
);
635 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
],
636 cpu_PR
[PR_CCS
], cc_src
,
640 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
],
641 cpu_PR
[PR_CCS
], cc_result
,
645 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
],
646 cpu_PR
[PR_CCS
], cc_result
,
659 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
660 cpu_PR
[PR_CCS
], cc_result
);
663 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
664 cpu_PR
[PR_CCS
], cc_result
);
667 gen_helper_evaluate_flags();
676 if (dc
->cc_size
== 4)
677 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
],
678 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
680 gen_helper_evaluate_flags();
687 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
],
688 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
691 gen_helper_evaluate_flags();
697 if (dc
->flagx_known
) {
699 tcg_gen_ori_tl(cpu_PR
[PR_CCS
],
700 cpu_PR
[PR_CCS
], X_FLAG
);
701 else if (dc
->cc_op
== CC_OP_FLAGS
)
702 tcg_gen_andi_tl(cpu_PR
[PR_CCS
],
703 cpu_PR
[PR_CCS
], ~X_FLAG
);
705 dc
->flags_uptodate
= 1;
708 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
717 /* Check if we need to evaluate the condition codes due to
719 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
721 /* TODO: optimize this case. It trigs all the time. */
722 cris_evaluate_flags (dc
);
728 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
732 dc
->flags_uptodate
= 0;
735 static inline void cris_update_cc_x(DisasContext
*dc
)
737 /* Save the x flag state at the time of the cc snapshot. */
738 if (dc
->flagx_known
) {
739 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
))
741 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
742 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
745 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
746 dc
->cc_x_uptodate
= 1;
750 /* Update cc prior to executing ALU op. Needs source operands untouched. */
751 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
752 TCGv dst
, TCGv src
, int size
)
755 cris_update_cc_op(dc
, op
, size
);
756 tcg_gen_mov_tl(cc_src
, src
);
765 tcg_gen_mov_tl(cc_dest
, dst
);
767 cris_update_cc_x(dc
);
771 /* Update cc after executing ALU op. needs the result. */
772 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
775 tcg_gen_mov_tl(cc_result
, res
);
778 /* Returns one if the write back stage should execute. */
779 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
780 TCGv dst
, TCGv a
, TCGv b
, int size
)
782 /* Emit the ALU insns. */
786 tcg_gen_add_tl(dst
, a
, b
);
787 /* Extended arithmetics. */
788 t_gen_addx_carry(dc
, dst
);
791 tcg_gen_add_tl(dst
, a
, b
);
792 t_gen_add_flag(dst
, 0); /* C_FLAG. */
795 tcg_gen_add_tl(dst
, a
, b
);
796 t_gen_add_flag(dst
, 8); /* R_FLAG. */
799 tcg_gen_sub_tl(dst
, a
, b
);
800 /* Extended arithmetics. */
801 t_gen_subx_carry(dc
, dst
);
804 tcg_gen_mov_tl(dst
, b
);
807 tcg_gen_or_tl(dst
, a
, b
);
810 tcg_gen_and_tl(dst
, a
, b
);
813 tcg_gen_xor_tl(dst
, a
, b
);
816 t_gen_lsl(dst
, a
, b
);
819 t_gen_lsr(dst
, a
, b
);
822 t_gen_asr(dst
, a
, b
);
825 tcg_gen_neg_tl(dst
, b
);
826 /* Extended arithmetics. */
827 t_gen_subx_carry(dc
, dst
);
830 gen_helper_lz(dst
, b
);
833 t_gen_muls(dst
, cpu_PR
[PR_MOF
], a
, b
);
836 t_gen_mulu(dst
, cpu_PR
[PR_MOF
], a
, b
);
839 t_gen_cris_dstep(dst
, a
, b
);
842 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
847 l1
= gen_new_label();
848 tcg_gen_mov_tl(dst
, a
);
849 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
850 tcg_gen_mov_tl(dst
, b
);
855 tcg_gen_sub_tl(dst
, a
, b
);
856 /* Extended arithmetics. */
857 t_gen_subx_carry(dc
, dst
);
860 qemu_log("illegal ALU op.\n");
866 tcg_gen_andi_tl(dst
, dst
, 0xff);
868 tcg_gen_andi_tl(dst
, dst
, 0xffff);
871 static void cris_alu(DisasContext
*dc
, int op
,
872 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
879 if (op
== CC_OP_CMP
) {
880 tmp
= tcg_temp_new();
882 } else if (size
== 4) {
886 tmp
= tcg_temp_new();
889 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
890 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
891 cris_update_result(dc
, tmp
);
896 tcg_gen_andi_tl(d
, d
, ~0xff);
898 tcg_gen_andi_tl(d
, d
, ~0xffff);
899 tcg_gen_or_tl(d
, d
, tmp
);
901 if (!TCGV_EQUAL(tmp
, d
))
905 static int arith_cc(DisasContext
*dc
)
909 case CC_OP_ADDC
: return 1;
910 case CC_OP_ADD
: return 1;
911 case CC_OP_SUB
: return 1;
912 case CC_OP_DSTEP
: return 1;
913 case CC_OP_LSL
: return 1;
914 case CC_OP_LSR
: return 1;
915 case CC_OP_ASR
: return 1;
916 case CC_OP_CMP
: return 1;
917 case CC_OP_NEG
: return 1;
918 case CC_OP_OR
: return 1;
919 case CC_OP_AND
: return 1;
920 case CC_OP_XOR
: return 1;
921 case CC_OP_MULU
: return 1;
922 case CC_OP_MULS
: return 1;
930 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
932 int arith_opt
, move_opt
;
934 /* TODO: optimize more condition codes. */
937 * If the flags are live, we've gotta look into the bits of CCS.
938 * Otherwise, if we just did an arithmetic operation we try to
939 * evaluate the condition code faster.
941 * When this function is done, T0 should be non-zero if the condition
944 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
945 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
948 if ((arith_opt
|| move_opt
)
949 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
950 /* If cc_result is zero, T0 should be
951 non-zero otherwise T0 should be zero. */
953 l1
= gen_new_label();
954 tcg_gen_movi_tl(cc
, 0);
955 tcg_gen_brcondi_tl(TCG_COND_NE
, cc_result
,
957 tcg_gen_movi_tl(cc
, 1);
961 cris_evaluate_flags(dc
);
963 cpu_PR
[PR_CCS
], Z_FLAG
);
967 if ((arith_opt
|| move_opt
)
968 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
969 tcg_gen_mov_tl(cc
, cc_result
);
971 cris_evaluate_flags(dc
);
972 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
974 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
978 cris_evaluate_flags(dc
);
979 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
982 cris_evaluate_flags(dc
);
983 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
984 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
987 cris_evaluate_flags(dc
);
988 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
991 cris_evaluate_flags(dc
);
992 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
994 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
997 if (arith_opt
|| move_opt
) {
1000 if (dc
->cc_size
== 1)
1002 else if (dc
->cc_size
== 2)
1005 tcg_gen_shri_tl(cc
, cc_result
, bits
);
1006 tcg_gen_xori_tl(cc
, cc
, 1);
1008 cris_evaluate_flags(dc
);
1009 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
1011 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1015 if (arith_opt
|| move_opt
) {
1018 if (dc
->cc_size
== 1)
1020 else if (dc
->cc_size
== 2)
1023 tcg_gen_shri_tl(cc
, cc_result
, bits
);
1024 tcg_gen_andi_tl(cc
, cc
, 1);
1027 cris_evaluate_flags(dc
);
1028 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
1033 cris_evaluate_flags(dc
);
1034 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
1038 cris_evaluate_flags(dc
);
1042 tmp
= tcg_temp_new();
1043 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
1045 /* Overlay the C flag on top of the Z. */
1046 tcg_gen_shli_tl(cc
, tmp
, 2);
1047 tcg_gen_and_tl(cc
, tmp
, cc
);
1048 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
1054 cris_evaluate_flags(dc
);
1055 /* Overlay the V flag on top of the N. */
1056 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1058 cpu_PR
[PR_CCS
], cc
);
1059 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1060 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
1063 cris_evaluate_flags(dc
);
1064 /* Overlay the V flag on top of the N. */
1065 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1067 cpu_PR
[PR_CCS
], cc
);
1068 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1071 cris_evaluate_flags(dc
);
1078 /* To avoid a shift we overlay everything on
1080 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1081 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1083 tcg_gen_xori_tl(z
, z
, 2);
1085 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1086 tcg_gen_xori_tl(n
, n
, 2);
1087 tcg_gen_and_tl(cc
, z
, n
);
1088 tcg_gen_andi_tl(cc
, cc
, 2);
1095 cris_evaluate_flags(dc
);
1102 /* To avoid a shift we overlay everything on
1104 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1105 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1107 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1108 tcg_gen_or_tl(cc
, z
, n
);
1109 tcg_gen_andi_tl(cc
, cc
, 2);
1116 cris_evaluate_flags(dc
);
1117 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1120 tcg_gen_movi_tl(cc
, 1);
1128 static void cris_store_direct_jmp(DisasContext
*dc
)
1130 /* Store the direct jmp state into the cpu-state. */
1131 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1132 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1133 dc
->jmp
= JMP_INDIRECT
;
1137 static void cris_prepare_cc_branch (DisasContext
*dc
,
1138 int offset
, int cond
)
1140 /* This helps us re-schedule the micro-code to insns in delay-slots
1141 before the actual jump. */
1142 dc
->delayed_branch
= 2;
1143 dc
->jmp
= JMP_DIRECT_CC
;
1144 dc
->jmp_pc
= dc
->pc
+ offset
;
1146 gen_tst_cc (dc
, env_btaken
, cond
);
1147 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1151 /* jumps, when the dest is in a live reg for example. Direct should be set
1152 when the dest addr is constant to allow tb chaining. */
1153 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1155 /* This helps us re-schedule the micro-code to insns in delay-slots
1156 before the actual jump. */
1157 dc
->delayed_branch
= 2;
1159 if (type
== JMP_INDIRECT
) {
1160 tcg_gen_movi_tl(env_btaken
, 1);
1164 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1166 int mem_index
= cpu_mmu_index(dc
->env
);
1168 /* If we get a fault on a delayslot we must keep the jmp state in
1169 the cpu-state to be able to re-execute the jmp. */
1170 if (dc
->delayed_branch
== 1)
1171 cris_store_direct_jmp(dc
);
1173 tcg_gen_qemu_ld64(dst
, addr
, mem_index
);
1176 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1177 unsigned int size
, int sign
)
1179 int mem_index
= cpu_mmu_index(dc
->env
);
1181 /* If we get a fault on a delayslot we must keep the jmp state in
1182 the cpu-state to be able to re-execute the jmp. */
1183 if (dc
->delayed_branch
== 1)
1184 cris_store_direct_jmp(dc
);
1188 tcg_gen_qemu_ld8s(dst
, addr
, mem_index
);
1190 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
1192 else if (size
== 2) {
1194 tcg_gen_qemu_ld16s(dst
, addr
, mem_index
);
1196 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
1198 else if (size
== 4) {
1199 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
1206 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1209 int mem_index
= cpu_mmu_index(dc
->env
);
1211 /* If we get a fault on a delayslot we must keep the jmp state in
1212 the cpu-state to be able to re-execute the jmp. */
1213 if (dc
->delayed_branch
== 1)
1214 cris_store_direct_jmp(dc
);
1217 /* Conditional writes. We only support the kind were X and P are known
1218 at translation time. */
1219 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1221 cris_evaluate_flags(dc
);
1222 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1227 tcg_gen_qemu_st8(val
, addr
, mem_index
);
1229 tcg_gen_qemu_st16(val
, addr
, mem_index
);
1231 tcg_gen_qemu_st32(val
, addr
, mem_index
);
1233 if (dc
->flagx_known
&& dc
->flags_x
) {
1234 cris_evaluate_flags(dc
);
1235 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1239 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1242 tcg_gen_ext8s_i32(d
, s
);
1244 tcg_gen_ext16s_i32(d
, s
);
1245 else if(!TCGV_EQUAL(d
, s
))
1246 tcg_gen_mov_tl(d
, s
);
1249 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1252 tcg_gen_ext8u_i32(d
, s
);
1254 tcg_gen_ext16u_i32(d
, s
);
1255 else if (!TCGV_EQUAL(d
, s
))
1256 tcg_gen_mov_tl(d
, s
);
1260 static char memsize_char(int size
)
1264 case 1: return 'b'; break;
1265 case 2: return 'w'; break;
1266 case 4: return 'd'; break;
1274 static inline unsigned int memsize_z(DisasContext
*dc
)
1276 return dc
->zsize
+ 1;
1279 static inline unsigned int memsize_zz(DisasContext
*dc
)
1290 static inline void do_postinc (DisasContext
*dc
, int size
)
1293 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1296 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1297 int size
, int s_ext
, TCGv dst
)
1300 t_gen_sext(dst
, cpu_R
[rs
], size
);
1302 t_gen_zext(dst
, cpu_R
[rs
], size
);
1305 /* Prepare T0 and T1 for a register alu operation.
1306 s_ext decides if the operand1 should be sign-extended or zero-extended when
1308 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1309 int size
, int s_ext
, TCGv dst
, TCGv src
)
1311 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1314 t_gen_sext(dst
, cpu_R
[rd
], size
);
1316 t_gen_zext(dst
, cpu_R
[rd
], size
);
1319 static int dec_prep_move_m(DisasContext
*dc
, int s_ext
, int memsize
,
1328 is_imm
= rs
== 15 && dc
->postinc
;
1330 /* Load [$rs] onto T1. */
1332 insn_len
= 2 + memsize
;
1336 imm
= cris_fetch(dc
, dc
->pc
+ 2, memsize
, s_ext
);
1337 tcg_gen_movi_tl(dst
, imm
);
1340 cris_flush_cc_state(dc
);
1341 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1343 t_gen_sext(dst
, dst
, memsize
);
1345 t_gen_zext(dst
, dst
, memsize
);
1350 /* Prepare T0 and T1 for a memory + alu operation.
1351 s_ext decides if the operand1 should be sign-extended or zero-extended when
1353 static int dec_prep_alu_m(DisasContext
*dc
, int s_ext
, int memsize
,
1358 insn_len
= dec_prep_move_m(dc
, s_ext
, memsize
, src
);
1359 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1364 static const char *cc_name(int cc
)
1366 static const char *cc_names
[16] = {
1367 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1368 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1371 return cc_names
[cc
];
1375 /* Start of insn decoders. */
1377 static int dec_bccq(DisasContext
*dc
)
1381 uint32_t cond
= dc
->op2
;
1383 offset
= EXTRACT_FIELD (dc
->ir
, 1, 7);
1384 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1387 offset
|= sign
<< 8;
1388 offset
= sign_extend(offset
, 8);
1390 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1392 /* op2 holds the condition-code. */
1393 cris_cc_mask(dc
, 0);
1394 cris_prepare_cc_branch (dc
, offset
, cond
);
1397 static int dec_addoq(DisasContext
*dc
)
1401 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1402 imm
= sign_extend(dc
->op1
, 7);
1404 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1405 cris_cc_mask(dc
, 0);
1406 /* Fetch register operand, */
1407 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1411 static int dec_addq(DisasContext
*dc
)
1413 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1415 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1417 cris_cc_mask(dc
, CC_MASK_NZVC
);
1419 cris_alu(dc
, CC_OP_ADD
,
1420 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1423 static int dec_moveq(DisasContext
*dc
)
1427 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1428 imm
= sign_extend(dc
->op1
, 5);
1429 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1431 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1434 static int dec_subq(DisasContext
*dc
)
1436 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1438 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1440 cris_cc_mask(dc
, CC_MASK_NZVC
);
1441 cris_alu(dc
, CC_OP_SUB
,
1442 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1445 static int dec_cmpq(DisasContext
*dc
)
1448 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1449 imm
= sign_extend(dc
->op1
, 5);
1451 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1452 cris_cc_mask(dc
, CC_MASK_NZVC
);
1454 cris_alu(dc
, CC_OP_CMP
,
1455 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1458 static int dec_andq(DisasContext
*dc
)
1461 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1462 imm
= sign_extend(dc
->op1
, 5);
1464 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1465 cris_cc_mask(dc
, CC_MASK_NZ
);
1467 cris_alu(dc
, CC_OP_AND
,
1468 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1471 static int dec_orq(DisasContext
*dc
)
1474 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1475 imm
= sign_extend(dc
->op1
, 5);
1476 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1477 cris_cc_mask(dc
, CC_MASK_NZ
);
1479 cris_alu(dc
, CC_OP_OR
,
1480 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1483 static int dec_btstq(DisasContext
*dc
)
1485 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1486 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1488 cris_cc_mask(dc
, CC_MASK_NZ
);
1489 cris_evaluate_flags(dc
);
1490 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->op2
],
1491 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1492 cris_alu(dc
, CC_OP_MOVE
,
1493 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1494 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1495 dc
->flags_uptodate
= 1;
1498 static int dec_asrq(DisasContext
*dc
)
1500 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1501 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1502 cris_cc_mask(dc
, CC_MASK_NZ
);
1504 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1505 cris_alu(dc
, CC_OP_MOVE
,
1507 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1510 static int dec_lslq(DisasContext
*dc
)
1512 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1513 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1515 cris_cc_mask(dc
, CC_MASK_NZ
);
1517 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1519 cris_alu(dc
, CC_OP_MOVE
,
1521 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1524 static int dec_lsrq(DisasContext
*dc
)
1526 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1527 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1529 cris_cc_mask(dc
, CC_MASK_NZ
);
1531 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1532 cris_alu(dc
, CC_OP_MOVE
,
1534 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1538 static int dec_move_r(DisasContext
*dc
)
1540 int size
= memsize_zz(dc
);
1542 LOG_DIS("move.%c $r%u, $r%u\n",
1543 memsize_char(size
), dc
->op1
, dc
->op2
);
1545 cris_cc_mask(dc
, CC_MASK_NZ
);
1547 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1548 cris_cc_mask(dc
, CC_MASK_NZ
);
1549 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1550 cris_update_cc_x(dc
);
1551 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1556 t0
= tcg_temp_new();
1557 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1558 cris_alu(dc
, CC_OP_MOVE
,
1560 cpu_R
[dc
->op2
], t0
, size
);
1566 static int dec_scc_r(DisasContext
*dc
)
1570 LOG_DIS("s%s $r%u\n",
1571 cc_name(cond
), dc
->op1
);
1577 gen_tst_cc (dc
, cpu_R
[dc
->op1
], cond
);
1578 l1
= gen_new_label();
1579 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1580 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1584 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1586 cris_cc_mask(dc
, 0);
1590 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1593 t
[0] = cpu_R
[dc
->op2
];
1594 t
[1] = cpu_R
[dc
->op1
];
1596 t
[0] = tcg_temp_new();
1597 t
[1] = tcg_temp_new();
1601 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1604 tcg_temp_free(t
[0]);
1605 tcg_temp_free(t
[1]);
1609 static int dec_and_r(DisasContext
*dc
)
1612 int size
= memsize_zz(dc
);
1614 LOG_DIS("and.%c $r%u, $r%u\n",
1615 memsize_char(size
), dc
->op1
, dc
->op2
);
1617 cris_cc_mask(dc
, CC_MASK_NZ
);
1619 cris_alu_alloc_temps(dc
, size
, t
);
1620 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1621 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1622 cris_alu_free_temps(dc
, size
, t
);
1626 static int dec_lz_r(DisasContext
*dc
)
1629 LOG_DIS("lz $r%u, $r%u\n",
1631 cris_cc_mask(dc
, CC_MASK_NZ
);
1632 t0
= tcg_temp_new();
1633 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1634 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1639 static int dec_lsl_r(DisasContext
*dc
)
1642 int size
= memsize_zz(dc
);
1644 LOG_DIS("lsl.%c $r%u, $r%u\n",
1645 memsize_char(size
), dc
->op1
, dc
->op2
);
1647 cris_cc_mask(dc
, CC_MASK_NZ
);
1648 cris_alu_alloc_temps(dc
, size
, t
);
1649 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1650 tcg_gen_andi_tl(t
[1], t
[1], 63);
1651 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1652 cris_alu_alloc_temps(dc
, size
, t
);
1656 static int dec_lsr_r(DisasContext
*dc
)
1659 int size
= memsize_zz(dc
);
1661 LOG_DIS("lsr.%c $r%u, $r%u\n",
1662 memsize_char(size
), dc
->op1
, dc
->op2
);
1664 cris_cc_mask(dc
, CC_MASK_NZ
);
1665 cris_alu_alloc_temps(dc
, size
, t
);
1666 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1667 tcg_gen_andi_tl(t
[1], t
[1], 63);
1668 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1669 cris_alu_free_temps(dc
, size
, t
);
1673 static int dec_asr_r(DisasContext
*dc
)
1676 int size
= memsize_zz(dc
);
1678 LOG_DIS("asr.%c $r%u, $r%u\n",
1679 memsize_char(size
), dc
->op1
, dc
->op2
);
1681 cris_cc_mask(dc
, CC_MASK_NZ
);
1682 cris_alu_alloc_temps(dc
, size
, t
);
1683 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1684 tcg_gen_andi_tl(t
[1], t
[1], 63);
1685 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1686 cris_alu_free_temps(dc
, size
, t
);
1690 static int dec_muls_r(DisasContext
*dc
)
1693 int size
= memsize_zz(dc
);
1695 LOG_DIS("muls.%c $r%u, $r%u\n",
1696 memsize_char(size
), dc
->op1
, dc
->op2
);
1697 cris_cc_mask(dc
, CC_MASK_NZV
);
1698 cris_alu_alloc_temps(dc
, size
, t
);
1699 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1701 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1702 cris_alu_free_temps(dc
, size
, t
);
1706 static int dec_mulu_r(DisasContext
*dc
)
1709 int size
= memsize_zz(dc
);
1711 LOG_DIS("mulu.%c $r%u, $r%u\n",
1712 memsize_char(size
), dc
->op1
, dc
->op2
);
1713 cris_cc_mask(dc
, CC_MASK_NZV
);
1714 cris_alu_alloc_temps(dc
, size
, t
);
1715 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1717 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1718 cris_alu_alloc_temps(dc
, size
, t
);
1723 static int dec_dstep_r(DisasContext
*dc
)
1725 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1726 cris_cc_mask(dc
, CC_MASK_NZ
);
1727 cris_alu(dc
, CC_OP_DSTEP
,
1728 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1732 static int dec_xor_r(DisasContext
*dc
)
1735 int size
= memsize_zz(dc
);
1736 LOG_DIS("xor.%c $r%u, $r%u\n",
1737 memsize_char(size
), dc
->op1
, dc
->op2
);
1738 BUG_ON(size
!= 4); /* xor is dword. */
1739 cris_cc_mask(dc
, CC_MASK_NZ
);
1740 cris_alu_alloc_temps(dc
, size
, t
);
1741 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1743 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1744 cris_alu_free_temps(dc
, size
, t
);
1748 static int dec_bound_r(DisasContext
*dc
)
1751 int size
= memsize_zz(dc
);
1752 LOG_DIS("bound.%c $r%u, $r%u\n",
1753 memsize_char(size
), dc
->op1
, dc
->op2
);
1754 cris_cc_mask(dc
, CC_MASK_NZ
);
1755 l0
= tcg_temp_local_new();
1756 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1757 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1762 static int dec_cmp_r(DisasContext
*dc
)
1765 int size
= memsize_zz(dc
);
1766 LOG_DIS("cmp.%c $r%u, $r%u\n",
1767 memsize_char(size
), dc
->op1
, dc
->op2
);
1768 cris_cc_mask(dc
, CC_MASK_NZVC
);
1769 cris_alu_alloc_temps(dc
, size
, t
);
1770 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1772 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1773 cris_alu_free_temps(dc
, size
, t
);
1777 static int dec_abs_r(DisasContext
*dc
)
1781 LOG_DIS("abs $r%u, $r%u\n",
1783 cris_cc_mask(dc
, CC_MASK_NZ
);
1785 t0
= tcg_temp_new();
1786 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1787 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1788 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1791 cris_alu(dc
, CC_OP_MOVE
,
1792 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1796 static int dec_add_r(DisasContext
*dc
)
1799 int size
= memsize_zz(dc
);
1800 LOG_DIS("add.%c $r%u, $r%u\n",
1801 memsize_char(size
), dc
->op1
, dc
->op2
);
1802 cris_cc_mask(dc
, CC_MASK_NZVC
);
1803 cris_alu_alloc_temps(dc
, size
, t
);
1804 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1806 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1807 cris_alu_free_temps(dc
, size
, t
);
1811 static int dec_addc_r(DisasContext
*dc
)
1813 LOG_DIS("addc $r%u, $r%u\n",
1815 cris_evaluate_flags(dc
);
1816 /* Set for this insn. */
1817 dc
->flagx_known
= 1;
1818 dc
->flags_x
= X_FLAG
;
1820 cris_cc_mask(dc
, CC_MASK_NZVC
);
1821 cris_alu(dc
, CC_OP_ADDC
,
1822 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1826 static int dec_mcp_r(DisasContext
*dc
)
1828 LOG_DIS("mcp $p%u, $r%u\n",
1830 cris_evaluate_flags(dc
);
1831 cris_cc_mask(dc
, CC_MASK_RNZV
);
1832 cris_alu(dc
, CC_OP_MCP
,
1833 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1838 static char * swapmode_name(int mode
, char *modename
) {
1841 modename
[i
++] = 'n';
1843 modename
[i
++] = 'w';
1845 modename
[i
++] = 'b';
1847 modename
[i
++] = 'r';
1853 static int dec_swap_r(DisasContext
*dc
)
1859 LOG_DIS("swap%s $r%u\n",
1860 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1862 cris_cc_mask(dc
, CC_MASK_NZ
);
1863 t0
= tcg_temp_new();
1864 t_gen_mov_TN_reg(t0
, dc
->op1
);
1866 tcg_gen_not_tl(t0
, t0
);
1868 t_gen_swapw(t0
, t0
);
1870 t_gen_swapb(t0
, t0
);
1872 t_gen_swapr(t0
, t0
);
1873 cris_alu(dc
, CC_OP_MOVE
,
1874 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1879 static int dec_or_r(DisasContext
*dc
)
1882 int size
= memsize_zz(dc
);
1883 LOG_DIS("or.%c $r%u, $r%u\n",
1884 memsize_char(size
), dc
->op1
, dc
->op2
);
1885 cris_cc_mask(dc
, CC_MASK_NZ
);
1886 cris_alu_alloc_temps(dc
, size
, t
);
1887 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1888 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1889 cris_alu_free_temps(dc
, size
, t
);
1893 static int dec_addi_r(DisasContext
*dc
)
1896 LOG_DIS("addi.%c $r%u, $r%u\n",
1897 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1898 cris_cc_mask(dc
, 0);
1899 t0
= tcg_temp_new();
1900 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1901 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1906 static int dec_addi_acr(DisasContext
*dc
)
1909 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1910 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1911 cris_cc_mask(dc
, 0);
1912 t0
= tcg_temp_new();
1913 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1914 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1919 static int dec_neg_r(DisasContext
*dc
)
1922 int size
= memsize_zz(dc
);
1923 LOG_DIS("neg.%c $r%u, $r%u\n",
1924 memsize_char(size
), dc
->op1
, dc
->op2
);
1925 cris_cc_mask(dc
, CC_MASK_NZVC
);
1926 cris_alu_alloc_temps(dc
, size
, t
);
1927 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1929 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1930 cris_alu_free_temps(dc
, size
, t
);
1934 static int dec_btst_r(DisasContext
*dc
)
1936 LOG_DIS("btst $r%u, $r%u\n",
1938 cris_cc_mask(dc
, CC_MASK_NZ
);
1939 cris_evaluate_flags(dc
);
1940 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->op2
],
1941 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1942 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1943 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1944 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1945 dc
->flags_uptodate
= 1;
1949 static int dec_sub_r(DisasContext
*dc
)
1952 int size
= memsize_zz(dc
);
1953 LOG_DIS("sub.%c $r%u, $r%u\n",
1954 memsize_char(size
), dc
->op1
, dc
->op2
);
1955 cris_cc_mask(dc
, CC_MASK_NZVC
);
1956 cris_alu_alloc_temps(dc
, size
, t
);
1957 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1958 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1959 cris_alu_free_temps(dc
, size
, t
);
1963 /* Zero extension. From size to dword. */
1964 static int dec_movu_r(DisasContext
*dc
)
1967 int size
= memsize_z(dc
);
1968 LOG_DIS("movu.%c $r%u, $r%u\n",
1972 cris_cc_mask(dc
, CC_MASK_NZ
);
1973 t0
= tcg_temp_new();
1974 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1975 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1980 /* Sign extension. From size to dword. */
1981 static int dec_movs_r(DisasContext
*dc
)
1984 int size
= memsize_z(dc
);
1985 LOG_DIS("movs.%c $r%u, $r%u\n",
1989 cris_cc_mask(dc
, CC_MASK_NZ
);
1990 t0
= tcg_temp_new();
1991 /* Size can only be qi or hi. */
1992 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1993 cris_alu(dc
, CC_OP_MOVE
,
1994 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1999 /* zero extension. From size to dword. */
2000 static int dec_addu_r(DisasContext
*dc
)
2003 int size
= memsize_z(dc
);
2004 LOG_DIS("addu.%c $r%u, $r%u\n",
2008 cris_cc_mask(dc
, CC_MASK_NZVC
);
2009 t0
= tcg_temp_new();
2010 /* Size can only be qi or hi. */
2011 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
2012 cris_alu(dc
, CC_OP_ADD
,
2013 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2018 /* Sign extension. From size to dword. */
2019 static int dec_adds_r(DisasContext
*dc
)
2022 int size
= memsize_z(dc
);
2023 LOG_DIS("adds.%c $r%u, $r%u\n",
2027 cris_cc_mask(dc
, CC_MASK_NZVC
);
2028 t0
= tcg_temp_new();
2029 /* Size can only be qi or hi. */
2030 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2031 cris_alu(dc
, CC_OP_ADD
,
2032 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2037 /* Zero extension. From size to dword. */
2038 static int dec_subu_r(DisasContext
*dc
)
2041 int size
= memsize_z(dc
);
2042 LOG_DIS("subu.%c $r%u, $r%u\n",
2046 cris_cc_mask(dc
, CC_MASK_NZVC
);
2047 t0
= tcg_temp_new();
2048 /* Size can only be qi or hi. */
2049 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
2050 cris_alu(dc
, CC_OP_SUB
,
2051 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2056 /* Sign extension. From size to dword. */
2057 static int dec_subs_r(DisasContext
*dc
)
2060 int size
= memsize_z(dc
);
2061 LOG_DIS("subs.%c $r%u, $r%u\n",
2065 cris_cc_mask(dc
, CC_MASK_NZVC
);
2066 t0
= tcg_temp_new();
2067 /* Size can only be qi or hi. */
2068 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2069 cris_alu(dc
, CC_OP_SUB
,
2070 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2075 static int dec_setclrf(DisasContext
*dc
)
2078 int set
= (~dc
->opcode
>> 2) & 1;
2081 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2082 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2083 if (set
&& flags
== 0) {
2086 } else if (!set
&& (flags
& 0x20)) {
2091 set
? "set" : "clr",
2095 /* User space is not allowed to touch these. Silently ignore. */
2096 if (dc
->tb_flags
& U_FLAG
) {
2097 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2100 if (flags
& X_FLAG
) {
2101 dc
->flagx_known
= 1;
2103 dc
->flags_x
= X_FLAG
;
2108 /* Break the TB if any of the SPI flag changes. */
2109 if (flags
& (P_FLAG
| S_FLAG
)) {
2110 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2111 dc
->is_jmp
= DISAS_UPDATE
;
2112 dc
->cpustate_changed
= 1;
2115 /* For the I flag, only act on posedge. */
2116 if ((flags
& I_FLAG
)) {
2117 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2118 dc
->is_jmp
= DISAS_UPDATE
;
2119 dc
->cpustate_changed
= 1;
2123 /* Simply decode the flags. */
2124 cris_evaluate_flags (dc
);
2125 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2126 cris_update_cc_x(dc
);
2127 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2130 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2131 /* Enter user mode. */
2132 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2133 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2134 dc
->cpustate_changed
= 1;
2136 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2139 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2141 dc
->flags_uptodate
= 1;
2146 static int dec_move_rs(DisasContext
*dc
)
2148 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2149 cris_cc_mask(dc
, 0);
2150 gen_helper_movl_sreg_reg(tcg_const_tl(dc
->op2
), tcg_const_tl(dc
->op1
));
2153 static int dec_move_sr(DisasContext
*dc
)
2155 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2156 cris_cc_mask(dc
, 0);
2157 gen_helper_movl_reg_sreg(tcg_const_tl(dc
->op1
), tcg_const_tl(dc
->op2
));
2161 static int dec_move_rp(DisasContext
*dc
)
2164 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2165 cris_cc_mask(dc
, 0);
2167 t
[0] = tcg_temp_new();
2168 if (dc
->op2
== PR_CCS
) {
2169 cris_evaluate_flags(dc
);
2170 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2171 if (dc
->tb_flags
& U_FLAG
) {
2172 t
[1] = tcg_temp_new();
2173 /* User space is not allowed to touch all flags. */
2174 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2175 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2176 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2177 tcg_temp_free(t
[1]);
2181 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2183 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2184 if (dc
->op2
== PR_CCS
) {
2185 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2186 dc
->flags_uptodate
= 1;
2188 tcg_temp_free(t
[0]);
2191 static int dec_move_pr(DisasContext
*dc
)
2194 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2195 cris_cc_mask(dc
, 0);
2197 if (dc
->op2
== PR_CCS
)
2198 cris_evaluate_flags(dc
);
2200 if (dc
->op2
== PR_DZ
) {
2201 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2203 t0
= tcg_temp_new();
2204 t_gen_mov_TN_preg(t0
, dc
->op2
);
2205 cris_alu(dc
, CC_OP_MOVE
,
2206 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2207 preg_sizes
[dc
->op2
]);
2213 static int dec_move_mr(DisasContext
*dc
)
2215 int memsize
= memsize_zz(dc
);
2217 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2218 memsize_char(memsize
),
2219 dc
->op1
, dc
->postinc
? "+]" : "]",
2223 insn_len
= dec_prep_move_m(dc
, 0, 4, cpu_R
[dc
->op2
]);
2224 cris_cc_mask(dc
, CC_MASK_NZ
);
2225 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2226 cris_update_cc_x(dc
);
2227 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2232 t0
= tcg_temp_new();
2233 insn_len
= dec_prep_move_m(dc
, 0, memsize
, t0
);
2234 cris_cc_mask(dc
, CC_MASK_NZ
);
2235 cris_alu(dc
, CC_OP_MOVE
,
2236 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2239 do_postinc(dc
, memsize
);
2243 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2245 t
[0] = tcg_temp_new();
2246 t
[1] = tcg_temp_new();
2249 static inline void cris_alu_m_free_temps(TCGv
*t
)
2251 tcg_temp_free(t
[0]);
2252 tcg_temp_free(t
[1]);
2255 static int dec_movs_m(DisasContext
*dc
)
2258 int memsize
= memsize_z(dc
);
2260 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2261 memsize_char(memsize
),
2262 dc
->op1
, dc
->postinc
? "+]" : "]",
2265 cris_alu_m_alloc_temps(t
);
2267 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2268 cris_cc_mask(dc
, CC_MASK_NZ
);
2269 cris_alu(dc
, CC_OP_MOVE
,
2270 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2271 do_postinc(dc
, memsize
);
2272 cris_alu_m_free_temps(t
);
2276 static int dec_addu_m(DisasContext
*dc
)
2279 int memsize
= memsize_z(dc
);
2281 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2282 memsize_char(memsize
),
2283 dc
->op1
, dc
->postinc
? "+]" : "]",
2286 cris_alu_m_alloc_temps(t
);
2288 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2289 cris_cc_mask(dc
, CC_MASK_NZVC
);
2290 cris_alu(dc
, CC_OP_ADD
,
2291 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2292 do_postinc(dc
, memsize
);
2293 cris_alu_m_free_temps(t
);
2297 static int dec_adds_m(DisasContext
*dc
)
2300 int memsize
= memsize_z(dc
);
2302 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2303 memsize_char(memsize
),
2304 dc
->op1
, dc
->postinc
? "+]" : "]",
2307 cris_alu_m_alloc_temps(t
);
2309 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2310 cris_cc_mask(dc
, CC_MASK_NZVC
);
2311 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2312 do_postinc(dc
, memsize
);
2313 cris_alu_m_free_temps(t
);
2317 static int dec_subu_m(DisasContext
*dc
)
2320 int memsize
= memsize_z(dc
);
2322 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2323 memsize_char(memsize
),
2324 dc
->op1
, dc
->postinc
? "+]" : "]",
2327 cris_alu_m_alloc_temps(t
);
2329 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2330 cris_cc_mask(dc
, CC_MASK_NZVC
);
2331 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2332 do_postinc(dc
, memsize
);
2333 cris_alu_m_free_temps(t
);
2337 static int dec_subs_m(DisasContext
*dc
)
2340 int memsize
= memsize_z(dc
);
2342 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2343 memsize_char(memsize
),
2344 dc
->op1
, dc
->postinc
? "+]" : "]",
2347 cris_alu_m_alloc_temps(t
);
2349 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2350 cris_cc_mask(dc
, CC_MASK_NZVC
);
2351 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2352 do_postinc(dc
, memsize
);
2353 cris_alu_m_free_temps(t
);
2357 static int dec_movu_m(DisasContext
*dc
)
2360 int memsize
= memsize_z(dc
);
2363 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2364 memsize_char(memsize
),
2365 dc
->op1
, dc
->postinc
? "+]" : "]",
2368 cris_alu_m_alloc_temps(t
);
2369 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2370 cris_cc_mask(dc
, CC_MASK_NZ
);
2371 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2372 do_postinc(dc
, memsize
);
2373 cris_alu_m_free_temps(t
);
2377 static int dec_cmpu_m(DisasContext
*dc
)
2380 int memsize
= memsize_z(dc
);
2382 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2383 memsize_char(memsize
),
2384 dc
->op1
, dc
->postinc
? "+]" : "]",
2387 cris_alu_m_alloc_temps(t
);
2388 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2389 cris_cc_mask(dc
, CC_MASK_NZVC
);
2390 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2391 do_postinc(dc
, memsize
);
2392 cris_alu_m_free_temps(t
);
2396 static int dec_cmps_m(DisasContext
*dc
)
2399 int memsize
= memsize_z(dc
);
2401 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2402 memsize_char(memsize
),
2403 dc
->op1
, dc
->postinc
? "+]" : "]",
2406 cris_alu_m_alloc_temps(t
);
2407 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2408 cris_cc_mask(dc
, CC_MASK_NZVC
);
2409 cris_alu(dc
, CC_OP_CMP
,
2410 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2412 do_postinc(dc
, memsize
);
2413 cris_alu_m_free_temps(t
);
2417 static int dec_cmp_m(DisasContext
*dc
)
2420 int memsize
= memsize_zz(dc
);
2422 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2423 memsize_char(memsize
),
2424 dc
->op1
, dc
->postinc
? "+]" : "]",
2427 cris_alu_m_alloc_temps(t
);
2428 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2429 cris_cc_mask(dc
, CC_MASK_NZVC
);
2430 cris_alu(dc
, CC_OP_CMP
,
2431 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2433 do_postinc(dc
, memsize
);
2434 cris_alu_m_free_temps(t
);
2438 static int dec_test_m(DisasContext
*dc
)
2441 int memsize
= memsize_zz(dc
);
2443 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2444 memsize_char(memsize
),
2445 dc
->op1
, dc
->postinc
? "+]" : "]",
2448 cris_evaluate_flags(dc
);
2450 cris_alu_m_alloc_temps(t
);
2451 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2452 cris_cc_mask(dc
, CC_MASK_NZ
);
2453 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2455 cris_alu(dc
, CC_OP_CMP
,
2456 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2457 do_postinc(dc
, memsize
);
2458 cris_alu_m_free_temps(t
);
2462 static int dec_and_m(DisasContext
*dc
)
2465 int memsize
= memsize_zz(dc
);
2467 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2468 memsize_char(memsize
),
2469 dc
->op1
, dc
->postinc
? "+]" : "]",
2472 cris_alu_m_alloc_temps(t
);
2473 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2474 cris_cc_mask(dc
, CC_MASK_NZ
);
2475 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2476 do_postinc(dc
, memsize
);
2477 cris_alu_m_free_temps(t
);
2481 static int dec_add_m(DisasContext
*dc
)
2484 int memsize
= memsize_zz(dc
);
2486 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2487 memsize_char(memsize
),
2488 dc
->op1
, dc
->postinc
? "+]" : "]",
2491 cris_alu_m_alloc_temps(t
);
2492 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2493 cris_cc_mask(dc
, CC_MASK_NZVC
);
2494 cris_alu(dc
, CC_OP_ADD
,
2495 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2496 do_postinc(dc
, memsize
);
2497 cris_alu_m_free_temps(t
);
2501 static int dec_addo_m(DisasContext
*dc
)
2504 int memsize
= memsize_zz(dc
);
2506 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2507 memsize_char(memsize
),
2508 dc
->op1
, dc
->postinc
? "+]" : "]",
2511 cris_alu_m_alloc_temps(t
);
2512 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2513 cris_cc_mask(dc
, 0);
2514 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2515 do_postinc(dc
, memsize
);
2516 cris_alu_m_free_temps(t
);
2520 static int dec_bound_m(DisasContext
*dc
)
2523 int memsize
= memsize_zz(dc
);
2525 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2526 memsize_char(memsize
),
2527 dc
->op1
, dc
->postinc
? "+]" : "]",
2530 l
[0] = tcg_temp_local_new();
2531 l
[1] = tcg_temp_local_new();
2532 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, l
[0], l
[1]);
2533 cris_cc_mask(dc
, CC_MASK_NZ
);
2534 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2535 do_postinc(dc
, memsize
);
2536 tcg_temp_free(l
[0]);
2537 tcg_temp_free(l
[1]);
2541 static int dec_addc_mr(DisasContext
*dc
)
2545 LOG_DIS("addc [$r%u%s, $r%u\n",
2546 dc
->op1
, dc
->postinc
? "+]" : "]",
2549 cris_evaluate_flags(dc
);
2551 /* Set for this insn. */
2552 dc
->flagx_known
= 1;
2553 dc
->flags_x
= X_FLAG
;
2555 cris_alu_m_alloc_temps(t
);
2556 insn_len
= dec_prep_alu_m(dc
, 0, 4, t
[0], t
[1]);
2557 cris_cc_mask(dc
, CC_MASK_NZVC
);
2558 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2560 cris_alu_m_free_temps(t
);
2564 static int dec_sub_m(DisasContext
*dc
)
2567 int memsize
= memsize_zz(dc
);
2569 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2570 memsize_char(memsize
),
2571 dc
->op1
, dc
->postinc
? "+]" : "]",
2572 dc
->op2
, dc
->ir
, dc
->zzsize
);
2574 cris_alu_m_alloc_temps(t
);
2575 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2576 cris_cc_mask(dc
, CC_MASK_NZVC
);
2577 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2578 do_postinc(dc
, memsize
);
2579 cris_alu_m_free_temps(t
);
2583 static int dec_or_m(DisasContext
*dc
)
2586 int memsize
= memsize_zz(dc
);
2588 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2589 memsize_char(memsize
),
2590 dc
->op1
, dc
->postinc
? "+]" : "]",
2593 cris_alu_m_alloc_temps(t
);
2594 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2595 cris_cc_mask(dc
, CC_MASK_NZ
);
2596 cris_alu(dc
, CC_OP_OR
,
2597 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2598 do_postinc(dc
, memsize
);
2599 cris_alu_m_free_temps(t
);
2603 static int dec_move_mp(DisasContext
*dc
)
2606 int memsize
= memsize_zz(dc
);
2609 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2610 memsize_char(memsize
),
2612 dc
->postinc
? "+]" : "]",
2615 cris_alu_m_alloc_temps(t
);
2616 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2617 cris_cc_mask(dc
, 0);
2618 if (dc
->op2
== PR_CCS
) {
2619 cris_evaluate_flags(dc
);
2620 if (dc
->tb_flags
& U_FLAG
) {
2621 /* User space is not allowed to touch all flags. */
2622 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2623 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2624 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2628 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2630 do_postinc(dc
, memsize
);
2631 cris_alu_m_free_temps(t
);
2635 static int dec_move_pm(DisasContext
*dc
)
2640 memsize
= preg_sizes
[dc
->op2
];
2642 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2643 memsize_char(memsize
),
2644 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2646 /* prepare store. Address in T0, value in T1. */
2647 if (dc
->op2
== PR_CCS
)
2648 cris_evaluate_flags(dc
);
2649 t0
= tcg_temp_new();
2650 t_gen_mov_TN_preg(t0
, dc
->op2
);
2651 cris_flush_cc_state(dc
);
2652 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2655 cris_cc_mask(dc
, 0);
2657 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2661 static int dec_movem_mr(DisasContext
*dc
)
2667 int nr
= dc
->op2
+ 1;
2669 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2670 dc
->postinc
? "+]" : "]", dc
->op2
);
2672 addr
= tcg_temp_new();
2673 /* There are probably better ways of doing this. */
2674 cris_flush_cc_state(dc
);
2675 for (i
= 0; i
< (nr
>> 1); i
++) {
2676 tmp
[i
] = tcg_temp_new_i64();
2677 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2678 gen_load64(dc
, tmp
[i
], addr
);
2681 tmp32
= tcg_temp_new_i32();
2682 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2683 gen_load(dc
, tmp32
, addr
, 4, 0);
2686 tcg_temp_free(addr
);
2688 for (i
= 0; i
< (nr
>> 1); i
++) {
2689 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2690 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2691 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2692 tcg_temp_free_i64(tmp
[i
]);
2695 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2696 tcg_temp_free(tmp32
);
2699 /* writeback the updated pointer value. */
2701 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2703 /* gen_load might want to evaluate the previous insns flags. */
2704 cris_cc_mask(dc
, 0);
2708 static int dec_movem_rm(DisasContext
*dc
)
2714 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2715 dc
->postinc
? "+]" : "]");
2717 cris_flush_cc_state(dc
);
2719 tmp
= tcg_temp_new();
2720 addr
= tcg_temp_new();
2721 tcg_gen_movi_tl(tmp
, 4);
2722 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2723 for (i
= 0; i
<= dc
->op2
; i
++) {
2724 /* Displace addr. */
2725 /* Perform the store. */
2726 gen_store(dc
, addr
, cpu_R
[i
], 4);
2727 tcg_gen_add_tl(addr
, addr
, tmp
);
2730 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2731 cris_cc_mask(dc
, 0);
2733 tcg_temp_free(addr
);
2737 static int dec_move_rm(DisasContext
*dc
)
2741 memsize
= memsize_zz(dc
);
2743 LOG_DIS("move.%c $r%u, [$r%u]\n",
2744 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2746 /* prepare store. */
2747 cris_flush_cc_state(dc
);
2748 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2751 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2752 cris_cc_mask(dc
, 0);
2756 static int dec_lapcq(DisasContext
*dc
)
2758 LOG_DIS("lapcq %x, $r%u\n",
2759 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2760 cris_cc_mask(dc
, 0);
2761 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2765 static int dec_lapc_im(DisasContext
*dc
)
2773 cris_cc_mask(dc
, 0);
2774 imm
= cris_fetch(dc
, dc
->pc
+ 2, 4, 0);
2775 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2779 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2783 /* Jump to special reg. */
2784 static int dec_jump_p(DisasContext
*dc
)
2786 LOG_DIS("jump $p%u\n", dc
->op2
);
2788 if (dc
->op2
== PR_CCS
)
2789 cris_evaluate_flags(dc
);
2790 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2791 /* rete will often have low bit set to indicate delayslot. */
2792 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2793 cris_cc_mask(dc
, 0);
2794 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2798 /* Jump and save. */
2799 static int dec_jas_r(DisasContext
*dc
)
2801 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2802 cris_cc_mask(dc
, 0);
2803 /* Store the return address in Pd. */
2804 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2807 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2809 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2813 static int dec_jas_im(DisasContext
*dc
)
2817 imm
= cris_fetch(dc
, dc
->pc
+ 2, 4, 0);
2819 LOG_DIS("jas 0x%x\n", imm
);
2820 cris_cc_mask(dc
, 0);
2821 /* Store the return address in Pd. */
2822 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2825 cris_prepare_jmp(dc
, JMP_DIRECT
);
2829 static int dec_jasc_im(DisasContext
*dc
)
2833 imm
= cris_fetch(dc
, dc
->pc
+ 2, 4, 0);
2835 LOG_DIS("jasc 0x%x\n", imm
);
2836 cris_cc_mask(dc
, 0);
2837 /* Store the return address in Pd. */
2838 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2841 cris_prepare_jmp(dc
, JMP_DIRECT
);
2845 static int dec_jasc_r(DisasContext
*dc
)
2847 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2848 cris_cc_mask(dc
, 0);
2849 /* Store the return address in Pd. */
2850 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2851 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2852 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2856 static int dec_bcc_im(DisasContext
*dc
)
2859 uint32_t cond
= dc
->op2
;
2861 offset
= cris_fetch(dc
, dc
->pc
+ 2, 2, 1);
2863 LOG_DIS("b%s %d pc=%x dst=%x\n",
2864 cc_name(cond
), offset
,
2865 dc
->pc
, dc
->pc
+ offset
);
2867 cris_cc_mask(dc
, 0);
2868 /* op2 holds the condition-code. */
2869 cris_prepare_cc_branch (dc
, offset
, cond
);
2873 static int dec_bas_im(DisasContext
*dc
)
2878 simm
= cris_fetch(dc
, dc
->pc
+ 2, 4, 0);
2880 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2881 cris_cc_mask(dc
, 0);
2882 /* Store the return address in Pd. */
2883 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2885 dc
->jmp_pc
= dc
->pc
+ simm
;
2886 cris_prepare_jmp(dc
, JMP_DIRECT
);
2890 static int dec_basc_im(DisasContext
*dc
)
2893 simm
= cris_fetch(dc
, dc
->pc
+ 2, 4, 0);
2895 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2896 cris_cc_mask(dc
, 0);
2897 /* Store the return address in Pd. */
2898 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2900 dc
->jmp_pc
= dc
->pc
+ simm
;
2901 cris_prepare_jmp(dc
, JMP_DIRECT
);
2905 static int dec_rfe_etc(DisasContext
*dc
)
2907 cris_cc_mask(dc
, 0);
2909 if (dc
->op2
== 15) {
2910 t_gen_mov_env_TN(halted
, tcg_const_tl(1));
2911 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2912 t_gen_raise_exception(EXCP_HLT
);
2916 switch (dc
->op2
& 7) {
2920 cris_evaluate_flags(dc
);
2922 dc
->is_jmp
= DISAS_UPDATE
;
2927 cris_evaluate_flags(dc
);
2929 dc
->is_jmp
= DISAS_UPDATE
;
2932 LOG_DIS("break %d\n", dc
->op1
);
2933 cris_evaluate_flags (dc
);
2935 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2937 /* Breaks start at 16 in the exception vector. */
2938 t_gen_mov_env_TN(trap_vector
,
2939 tcg_const_tl(dc
->op1
+ 16));
2940 t_gen_raise_exception(EXCP_BREAK
);
2941 dc
->is_jmp
= DISAS_UPDATE
;
2944 printf ("op2=%x\n", dc
->op2
);
2952 static int dec_ftag_fidx_d_m(DisasContext
*dc
)
2957 static int dec_ftag_fidx_i_m(DisasContext
*dc
)
2962 static int dec_null(DisasContext
*dc
)
2964 printf ("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2965 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2971 static struct decoder_info
{
2976 int (*dec
)(DisasContext
*dc
);
2978 /* Order matters here. */
2979 {DEC_MOVEQ
, dec_moveq
},
2980 {DEC_BTSTQ
, dec_btstq
},
2981 {DEC_CMPQ
, dec_cmpq
},
2982 {DEC_ADDOQ
, dec_addoq
},
2983 {DEC_ADDQ
, dec_addq
},
2984 {DEC_SUBQ
, dec_subq
},
2985 {DEC_ANDQ
, dec_andq
},
2987 {DEC_ASRQ
, dec_asrq
},
2988 {DEC_LSLQ
, dec_lslq
},
2989 {DEC_LSRQ
, dec_lsrq
},
2990 {DEC_BCCQ
, dec_bccq
},
2992 {DEC_BCC_IM
, dec_bcc_im
},
2993 {DEC_JAS_IM
, dec_jas_im
},
2994 {DEC_JAS_R
, dec_jas_r
},
2995 {DEC_JASC_IM
, dec_jasc_im
},
2996 {DEC_JASC_R
, dec_jasc_r
},
2997 {DEC_BAS_IM
, dec_bas_im
},
2998 {DEC_BASC_IM
, dec_basc_im
},
2999 {DEC_JUMP_P
, dec_jump_p
},
3000 {DEC_LAPC_IM
, dec_lapc_im
},
3001 {DEC_LAPCQ
, dec_lapcq
},
3003 {DEC_RFE_ETC
, dec_rfe_etc
},
3004 {DEC_ADDC_MR
, dec_addc_mr
},
3006 {DEC_MOVE_MP
, dec_move_mp
},
3007 {DEC_MOVE_PM
, dec_move_pm
},
3008 {DEC_MOVEM_MR
, dec_movem_mr
},
3009 {DEC_MOVEM_RM
, dec_movem_rm
},
3010 {DEC_MOVE_PR
, dec_move_pr
},
3011 {DEC_SCC_R
, dec_scc_r
},
3012 {DEC_SETF
, dec_setclrf
},
3013 {DEC_CLEARF
, dec_setclrf
},
3015 {DEC_MOVE_SR
, dec_move_sr
},
3016 {DEC_MOVE_RP
, dec_move_rp
},
3017 {DEC_SWAP_R
, dec_swap_r
},
3018 {DEC_ABS_R
, dec_abs_r
},
3019 {DEC_LZ_R
, dec_lz_r
},
3020 {DEC_MOVE_RS
, dec_move_rs
},
3021 {DEC_BTST_R
, dec_btst_r
},
3022 {DEC_ADDC_R
, dec_addc_r
},
3024 {DEC_DSTEP_R
, dec_dstep_r
},
3025 {DEC_XOR_R
, dec_xor_r
},
3026 {DEC_MCP_R
, dec_mcp_r
},
3027 {DEC_CMP_R
, dec_cmp_r
},
3029 {DEC_ADDI_R
, dec_addi_r
},
3030 {DEC_ADDI_ACR
, dec_addi_acr
},
3032 {DEC_ADD_R
, dec_add_r
},
3033 {DEC_SUB_R
, dec_sub_r
},
3035 {DEC_ADDU_R
, dec_addu_r
},
3036 {DEC_ADDS_R
, dec_adds_r
},
3037 {DEC_SUBU_R
, dec_subu_r
},
3038 {DEC_SUBS_R
, dec_subs_r
},
3039 {DEC_LSL_R
, dec_lsl_r
},
3041 {DEC_AND_R
, dec_and_r
},
3042 {DEC_OR_R
, dec_or_r
},
3043 {DEC_BOUND_R
, dec_bound_r
},
3044 {DEC_ASR_R
, dec_asr_r
},
3045 {DEC_LSR_R
, dec_lsr_r
},
3047 {DEC_MOVU_R
, dec_movu_r
},
3048 {DEC_MOVS_R
, dec_movs_r
},
3049 {DEC_NEG_R
, dec_neg_r
},
3050 {DEC_MOVE_R
, dec_move_r
},
3052 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
3053 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
3055 {DEC_MULS_R
, dec_muls_r
},
3056 {DEC_MULU_R
, dec_mulu_r
},
3058 {DEC_ADDU_M
, dec_addu_m
},
3059 {DEC_ADDS_M
, dec_adds_m
},
3060 {DEC_SUBU_M
, dec_subu_m
},
3061 {DEC_SUBS_M
, dec_subs_m
},
3063 {DEC_CMPU_M
, dec_cmpu_m
},
3064 {DEC_CMPS_M
, dec_cmps_m
},
3065 {DEC_MOVU_M
, dec_movu_m
},
3066 {DEC_MOVS_M
, dec_movs_m
},
3068 {DEC_CMP_M
, dec_cmp_m
},
3069 {DEC_ADDO_M
, dec_addo_m
},
3070 {DEC_BOUND_M
, dec_bound_m
},
3071 {DEC_ADD_M
, dec_add_m
},
3072 {DEC_SUB_M
, dec_sub_m
},
3073 {DEC_AND_M
, dec_and_m
},
3074 {DEC_OR_M
, dec_or_m
},
3075 {DEC_MOVE_RM
, dec_move_rm
},
3076 {DEC_TEST_M
, dec_test_m
},
3077 {DEC_MOVE_MR
, dec_move_mr
},
3082 static unsigned int crisv32_decoder(DisasContext
*dc
)
3087 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
3088 tcg_gen_debug_insn_start(dc
->pc
);
3090 /* Load a halfword onto the instruction register. */
3091 dc
->ir
= cris_fetch(dc
, dc
->pc
, 2, 0);
3093 /* Now decode it. */
3094 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3095 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3096 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3097 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3098 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3099 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3101 /* Large switch for all insns. */
3102 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3103 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
)
3105 insn_len
= decinfo
[i
].dec(dc
);
3110 #if !defined(CONFIG_USER_ONLY)
3111 /* Single-stepping ? */
3112 if (dc
->tb_flags
& S_FLAG
) {
3115 l1
= gen_new_label();
3116 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3117 /* We treat SPC as a break with an odd trap vector. */
3118 cris_evaluate_flags (dc
);
3119 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3120 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3121 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3122 t_gen_raise_exception(EXCP_BREAK
);
3129 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
3133 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
3134 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
3135 if (bp
->pc
== dc
->pc
) {
3136 cris_evaluate_flags (dc
);
3137 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3138 t_gen_raise_exception(EXCP_DEBUG
);
3139 dc
->is_jmp
= DISAS_UPDATE
;
3145 #include "translate_v10.c"
3148 * Delay slots on QEMU/CRIS.
3150 * If an exception hits on a delayslot, the core will let ERP (the Exception
3151 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3152 * to give SW a hint that the exception actually hit on the dslot.
3154 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3155 * the core and any jmp to an odd addresses will mask off that lsb. It is
3156 * simply there to let sw know there was an exception on a dslot.
3158 * When the software returns from an exception, the branch will re-execute.
3159 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3160 * and the branch and delayslot dont share pages.
3162 * The TB contaning the branch insn will set up env->btarget and evaluate
3163 * env->btaken. When the translation loop exits we will note that the branch
3164 * sequence is broken and let env->dslot be the size of the branch insn (those
3167 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3168 * set). It will also expect to have env->dslot setup with the size of the
3169 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3170 * will execute the dslot and take the branch, either to btarget or just one
3173 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3174 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3175 * branch and set lsb). Then env->dslot gets cleared so that the exception
3176 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3177 * masked off and we will reexecute the branch insn.
3181 /* generate intermediate code for basic block 'tb'. */
3183 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
3186 uint16_t *gen_opc_end
;
3188 unsigned int insn_len
;
3190 struct DisasContext ctx
;
3191 struct DisasContext
*dc
= &ctx
;
3192 uint32_t next_page_start
;
3197 qemu_log_try_set_file(stderr
);
3199 if (env
->pregs
[PR_VR
] == 32) {
3200 dc
->decoder
= crisv32_decoder
;
3201 dc
->clear_locked_irq
= 0;
3203 dc
->decoder
= crisv10_decoder
;
3204 dc
->clear_locked_irq
= 1;
3207 /* Odd PC indicates that branch is rexecuting due to exception in the
3208 * delayslot, like in real hw.
3210 pc_start
= tb
->pc
& ~1;
3214 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3216 dc
->is_jmp
= DISAS_NEXT
;
3219 dc
->singlestep_enabled
= env
->singlestep_enabled
;
3220 dc
->flags_uptodate
= 1;
3221 dc
->flagx_known
= 1;
3222 dc
->flags_x
= tb
->flags
& X_FLAG
;
3223 dc
->cc_x_uptodate
= 0;
3226 dc
->clear_prefix
= 0;
3228 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3229 dc
->cc_size_uptodate
= -1;
3231 /* Decode TB flags. */
3232 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3233 | X_FLAG
| PFIX_FLAG
);
3234 dc
->delayed_branch
= !!(tb
->flags
& 7);
3235 if (dc
->delayed_branch
)
3236 dc
->jmp
= JMP_INDIRECT
;
3238 dc
->jmp
= JMP_NOJMP
;
3240 dc
->cpustate_changed
= 0;
3242 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3244 "srch=%d pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3250 search_pc
, dc
->pc
, dc
->ppc
,
3251 (uint64_t)tb
->flags
,
3252 env
->btarget
, (unsigned)tb
->flags
& 7,
3254 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3255 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3256 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3257 env
->regs
[8], env
->regs
[9],
3258 env
->regs
[10], env
->regs
[11],
3259 env
->regs
[12], env
->regs
[13],
3260 env
->regs
[14], env
->regs
[15]);
3261 qemu_log("--------------\n");
3262 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3265 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3268 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3270 max_insns
= CF_COUNT_MASK
;
3275 check_breakpoint(env
, dc
);
3278 j
= gen_opc_ptr
- gen_opc_buf
;
3282 gen_opc_instr_start
[lj
++] = 0;
3284 if (dc
->delayed_branch
== 1)
3285 gen_opc_pc
[lj
] = dc
->ppc
| 1;
3287 gen_opc_pc
[lj
] = dc
->pc
;
3288 gen_opc_instr_start
[lj
] = 1;
3289 gen_opc_icount
[lj
] = num_insns
;
3293 LOG_DIS("%8.8x:\t", dc
->pc
);
3295 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3299 insn_len
= dc
->decoder(dc
);
3303 cris_clear_x_flag(dc
);
3306 /* Check for delayed branches here. If we do it before
3307 actually generating any host code, the simulator will just
3308 loop doing nothing for on this program location. */
3309 if (dc
->delayed_branch
) {
3310 dc
->delayed_branch
--;
3311 if (dc
->delayed_branch
== 0)
3314 t_gen_mov_env_TN(dslot
,
3316 if (dc
->cpustate_changed
|| !dc
->flagx_known
3317 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3318 cris_store_direct_jmp(dc
);
3321 if (dc
->clear_locked_irq
) {
3322 dc
->clear_locked_irq
= 0;
3323 t_gen_mov_env_TN(locked_irq
,
3327 if (dc
->jmp
== JMP_DIRECT_CC
) {
3330 l1
= gen_new_label();
3331 cris_evaluate_flags(dc
);
3333 /* Conditional jmp. */
3334 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3336 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3338 gen_goto_tb(dc
, 0, dc
->pc
);
3339 dc
->is_jmp
= DISAS_TB_JUMP
;
3340 dc
->jmp
= JMP_NOJMP
;
3341 } else if (dc
->jmp
== JMP_DIRECT
) {
3342 cris_evaluate_flags(dc
);
3343 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3344 dc
->is_jmp
= DISAS_TB_JUMP
;
3345 dc
->jmp
= JMP_NOJMP
;
3347 t_gen_cc_jmp(env_btarget
,
3348 tcg_const_tl(dc
->pc
));
3349 dc
->is_jmp
= DISAS_JUMP
;
3355 /* If we are rexecuting a branch due to exceptions on
3356 delay slots dont break. */
3357 if (!(tb
->pc
& 1) && env
->singlestep_enabled
)
3359 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3360 && gen_opc_ptr
< gen_opc_end
3362 && (dc
->pc
< next_page_start
)
3363 && num_insns
< max_insns
);
3365 if (dc
->clear_locked_irq
)
3366 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3370 if (tb
->cflags
& CF_LAST_IO
)
3372 /* Force an update if the per-tb cpu state has changed. */
3373 if (dc
->is_jmp
== DISAS_NEXT
3374 && (dc
->cpustate_changed
|| !dc
->flagx_known
3375 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3376 dc
->is_jmp
= DISAS_UPDATE
;
3377 tcg_gen_movi_tl(env_pc
, npc
);
3379 /* Broken branch+delayslot sequence. */
3380 if (dc
->delayed_branch
== 1) {
3381 /* Set env->dslot to the size of the branch insn. */
3382 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3383 cris_store_direct_jmp(dc
);
3386 cris_evaluate_flags (dc
);
3388 if (unlikely(env
->singlestep_enabled
)) {
3389 if (dc
->is_jmp
== DISAS_NEXT
)
3390 tcg_gen_movi_tl(env_pc
, npc
);
3391 t_gen_raise_exception(EXCP_DEBUG
);
3393 switch(dc
->is_jmp
) {
3395 gen_goto_tb(dc
, 1, npc
);
3400 /* indicate that the hash table must be used
3401 to find the next TB */
3406 /* nothing more to generate */
3410 gen_icount_end(tb
, num_insns
);
3411 *gen_opc_ptr
= INDEX_op_end
;
3413 j
= gen_opc_ptr
- gen_opc_buf
;
3416 gen_opc_instr_start
[lj
++] = 0;
3418 tb
->size
= dc
->pc
- pc_start
;
3419 tb
->icount
= num_insns
;
3424 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3425 log_target_disas(pc_start
, dc
->pc
- pc_start
,
3426 dc
->env
->pregs
[PR_VR
]);
3427 qemu_log("\nisize=%d osize=%td\n",
3428 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
3434 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3436 gen_intermediate_code_internal(env
, tb
, 0);
3439 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3441 gen_intermediate_code_internal(env
, tb
, 1);
3444 void cpu_dump_state (CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
3453 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3454 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3455 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3457 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3460 for (i
= 0; i
< 16; i
++) {
3461 cpu_fprintf(f
, "%s=%8.8x ",regnames
[i
], env
->regs
[i
]);
3462 if ((i
+ 1) % 4 == 0)
3463 cpu_fprintf(f
, "\n");
3465 cpu_fprintf(f
, "\nspecial regs:\n");
3466 for (i
= 0; i
< 16; i
++) {
3467 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3468 if ((i
+ 1) % 4 == 0)
3469 cpu_fprintf(f
, "\n");
3471 srs
= env
->pregs
[PR_SRS
];
3472 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3474 for (i
= 0; i
< 16; i
++) {
3475 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3476 i
, env
->sregs
[srs
][i
]);
3477 if ((i
+ 1) % 4 == 0)
3478 cpu_fprintf(f
, "\n");
3481 cpu_fprintf(f
, "\n\n");
3497 void cris_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
3501 (*cpu_fprintf
)(f
, "Available CPUs:\n");
3502 for (i
= 0; i
< ARRAY_SIZE(cris_cores
); i
++) {
3503 (*cpu_fprintf
)(f
, " %s\n", cris_cores
[i
].name
);
3507 static uint32_t vr_by_name(const char *name
)
3510 for (i
= 0; i
< ARRAY_SIZE(cris_cores
); i
++) {
3511 if (strcmp(name
, cris_cores
[i
].name
) == 0) {
3512 return cris_cores
[i
].vr
;
3518 CPUCRISState
*cpu_cris_init (const char *cpu_model
)
3521 static int tcg_initialized
= 0;
3524 env
= qemu_mallocz(sizeof(CPUCRISState
));
3526 env
->pregs
[PR_VR
] = vr_by_name(cpu_model
);
3529 qemu_init_vcpu(env
);
3531 if (tcg_initialized
)
3534 tcg_initialized
= 1;
3536 #define GEN_HELPER 2
3539 if (env
->pregs
[PR_VR
] < 32) {
3540 cpu_crisv10_init(env
);
3545 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3546 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3547 offsetof(CPUState
, cc_x
), "cc_x");
3548 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3549 offsetof(CPUState
, cc_src
), "cc_src");
3550 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3551 offsetof(CPUState
, cc_dest
),
3553 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3554 offsetof(CPUState
, cc_result
),
3556 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3557 offsetof(CPUState
, cc_op
), "cc_op");
3558 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3559 offsetof(CPUState
, cc_size
),
3561 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3562 offsetof(CPUState
, cc_mask
),
3565 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3566 offsetof(CPUState
, pc
),
3568 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3569 offsetof(CPUState
, btarget
),
3571 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3572 offsetof(CPUState
, btaken
),
3574 for (i
= 0; i
< 16; i
++) {
3575 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3576 offsetof(CPUState
, regs
[i
]),
3579 for (i
= 0; i
< 16; i
++) {
3580 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3581 offsetof(CPUState
, pregs
[i
]),
3588 void cpu_reset (CPUCRISState
*env
)
3592 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
3593 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
3594 log_cpu_state(env
, 0);
3597 vr
= env
->pregs
[PR_VR
];
3598 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));
3599 env
->pregs
[PR_VR
] = vr
;
3602 #if defined(CONFIG_USER_ONLY)
3603 /* start in user mode with interrupts enabled. */
3604 env
->pregs
[PR_CCS
] |= U_FLAG
| I_FLAG
| P_FLAG
;
3607 env
->pregs
[PR_CCS
] = 0;
3611 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
3612 unsigned long searched_pc
, int pc_pos
, void *puc
)
3614 env
->pc
= gen_opc_pc
[pc_pos
];