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.
26 #include "qemu/osdep.h"
28 #include "disas/disas.h"
29 #include "exec/exec-all.h"
31 #include "exec/helper-proto.h"
33 #include "exec/cpu_ldst.h"
34 #include "crisv32-decode.h"
36 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
44 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
46 # define LOG_DIS(...) do { } while (0)
50 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
51 #define BUG_ON(x) ({if (x) BUG();})
55 /* Used by the decoder. */
56 #define EXTRACT_FIELD(src, start, end) \
57 (((src) >> start) & ((1 << (end - start + 1)) - 1))
59 #define CC_MASK_NZ 0xc
60 #define CC_MASK_NZV 0xe
61 #define CC_MASK_NZVC 0xf
62 #define CC_MASK_RNZV 0x10e
64 static TCGv_env cpu_env
;
65 static TCGv cpu_R
[16];
66 static TCGv cpu_PR
[16];
70 static TCGv cc_result
;
75 static TCGv env_btaken
;
76 static TCGv env_btarget
;
79 #include "exec/gen-icount.h"
81 /* This is the state at translation time. */
82 typedef struct DisasContext
{
87 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
92 unsigned int zsize
, zzsize
;
106 int cc_size_uptodate
; /* -1 invalid or last written value. */
108 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not up-to-date. */
109 int flags_uptodate
; /* Whether or not $ccs is up-to-date. */
110 int flagx_known
; /* Whether or not flags_x has the x flag known at
114 int clear_x
; /* Clear x after this insn? */
115 int clear_prefix
; /* Clear prefix after this insn? */
116 int clear_locked_irq
; /* Clear the irq lockout. */
117 int cpustate_changed
;
118 unsigned int tb_flags
; /* tb dependent flags. */
123 #define JMP_DIRECT_CC 2
124 #define JMP_INDIRECT 3
125 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
130 struct TranslationBlock
*tb
;
131 int singlestep_enabled
;
134 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
136 fprintf(stderr
, "BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
137 if (qemu_log_separate()) {
138 qemu_log("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
140 cpu_abort(CPU(dc
->cpu
), "%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 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
172 #define t_gen_mov_env_TN(member, tn) \
173 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
175 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
177 assert(r
>= 0 && r
<= 15);
178 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
179 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
180 } else if (r
== PR_VR
) {
181 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
183 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
186 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
188 assert(r
>= 0 && r
<= 15);
189 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
191 } else if (r
== PR_SRS
) {
192 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
195 gen_helper_tlb_flush_pid(cpu_env
, tn
);
197 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
198 gen_helper_spc_write(cpu_env
, tn
);
199 } else if (r
== PR_CCS
) {
200 dc
->cpustate_changed
= 1;
202 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
206 /* Sign extend at translation time. */
207 static int sign_extend(unsigned int val
, unsigned int width
)
219 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
220 unsigned int size
, unsigned int sign
)
227 r
= cpu_ldl_code(env
, addr
);
233 r
= cpu_ldsw_code(env
, addr
);
235 r
= cpu_lduw_code(env
, addr
);
242 r
= cpu_ldsb_code(env
, addr
);
244 r
= cpu_ldub_code(env
, addr
);
249 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
255 static void cris_lock_irq(DisasContext
*dc
)
257 dc
->clear_locked_irq
= 0;
258 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
261 static inline void t_gen_raise_exception(uint32_t index
)
263 TCGv_i32 tmp
= tcg_const_i32(index
);
264 gen_helper_raise_exception(cpu_env
, tmp
);
265 tcg_temp_free_i32(tmp
);
268 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
273 t_31
= tcg_const_tl(31);
274 tcg_gen_shl_tl(d
, a
, b
);
276 tcg_gen_sub_tl(t0
, t_31
, b
);
277 tcg_gen_sar_tl(t0
, t0
, t_31
);
278 tcg_gen_and_tl(t0
, t0
, d
);
279 tcg_gen_xor_tl(d
, d
, t0
);
284 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
289 t_31
= tcg_temp_new();
290 tcg_gen_shr_tl(d
, a
, b
);
292 tcg_gen_movi_tl(t_31
, 31);
293 tcg_gen_sub_tl(t0
, t_31
, b
);
294 tcg_gen_sar_tl(t0
, t0
, t_31
);
295 tcg_gen_and_tl(t0
, t0
, d
);
296 tcg_gen_xor_tl(d
, d
, t0
);
301 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
306 t_31
= tcg_temp_new();
307 tcg_gen_sar_tl(d
, a
, b
);
309 tcg_gen_movi_tl(t_31
, 31);
310 tcg_gen_sub_tl(t0
, t_31
, b
);
311 tcg_gen_sar_tl(t0
, t0
, t_31
);
312 tcg_gen_or_tl(d
, d
, t0
);
317 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
319 TCGv t
= tcg_temp_new();
326 tcg_gen_shli_tl(d
, a
, 1);
327 tcg_gen_sub_tl(t
, d
, b
);
328 tcg_gen_movcond_tl(TCG_COND_GEU
, d
, d
, b
, t
, d
);
332 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
342 tcg_gen_shli_tl(d
, a
, 1);
343 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
344 tcg_gen_sari_tl(t
, t
, 31);
345 tcg_gen_and_tl(t
, t
, b
);
346 tcg_gen_add_tl(d
, d
, t
);
350 /* Extended arithmetics on CRIS. */
351 static inline void t_gen_add_flag(TCGv d
, int flag
)
356 t_gen_mov_TN_preg(c
, PR_CCS
);
357 /* Propagate carry into d. */
358 tcg_gen_andi_tl(c
, c
, 1 << flag
);
360 tcg_gen_shri_tl(c
, c
, flag
);
362 tcg_gen_add_tl(d
, d
, c
);
366 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
368 if (dc
->flagx_known
) {
373 t_gen_mov_TN_preg(c
, PR_CCS
);
374 /* C flag is already at bit 0. */
375 tcg_gen_andi_tl(c
, c
, C_FLAG
);
376 tcg_gen_add_tl(d
, d
, c
);
384 t_gen_mov_TN_preg(x
, PR_CCS
);
385 tcg_gen_mov_tl(c
, x
);
387 /* Propagate carry into d if X is set. Branch free. */
388 tcg_gen_andi_tl(c
, c
, C_FLAG
);
389 tcg_gen_andi_tl(x
, x
, X_FLAG
);
390 tcg_gen_shri_tl(x
, x
, 4);
392 tcg_gen_and_tl(x
, x
, c
);
393 tcg_gen_add_tl(d
, d
, x
);
399 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
401 if (dc
->flagx_known
) {
406 t_gen_mov_TN_preg(c
, PR_CCS
);
407 /* C flag is already at bit 0. */
408 tcg_gen_andi_tl(c
, c
, C_FLAG
);
409 tcg_gen_sub_tl(d
, d
, c
);
417 t_gen_mov_TN_preg(x
, PR_CCS
);
418 tcg_gen_mov_tl(c
, x
);
420 /* Propagate carry into d if X is set. Branch free. */
421 tcg_gen_andi_tl(c
, c
, C_FLAG
);
422 tcg_gen_andi_tl(x
, x
, X_FLAG
);
423 tcg_gen_shri_tl(x
, x
, 4);
425 tcg_gen_and_tl(x
, x
, c
);
426 tcg_gen_sub_tl(d
, d
, x
);
432 /* Swap the two bytes within each half word of the s operand.
433 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
434 static inline void t_gen_swapb(TCGv d
, TCGv s
)
439 org_s
= tcg_temp_new();
441 /* d and s may refer to the same object. */
442 tcg_gen_mov_tl(org_s
, s
);
443 tcg_gen_shli_tl(t
, org_s
, 8);
444 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
445 tcg_gen_shri_tl(t
, org_s
, 8);
446 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
447 tcg_gen_or_tl(d
, d
, t
);
449 tcg_temp_free(org_s
);
452 /* Swap the halfwords of the s operand. */
453 static inline void t_gen_swapw(TCGv d
, TCGv s
)
456 /* d and s refer the same object. */
458 tcg_gen_mov_tl(t
, s
);
459 tcg_gen_shli_tl(d
, t
, 16);
460 tcg_gen_shri_tl(t
, t
, 16);
461 tcg_gen_or_tl(d
, d
, t
);
465 /* Reverse the within each byte.
466 T0 = (((T0 << 7) & 0x80808080) |
467 ((T0 << 5) & 0x40404040) |
468 ((T0 << 3) & 0x20202020) |
469 ((T0 << 1) & 0x10101010) |
470 ((T0 >> 1) & 0x08080808) |
471 ((T0 >> 3) & 0x04040404) |
472 ((T0 >> 5) & 0x02020202) |
473 ((T0 >> 7) & 0x01010101));
475 static inline void t_gen_swapr(TCGv d
, TCGv s
)
478 int shift
; /* LSL when positive, LSR when negative. */
493 /* d and s refer the same object. */
495 org_s
= tcg_temp_new();
496 tcg_gen_mov_tl(org_s
, s
);
498 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
499 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
500 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
501 if (bitrev
[i
].shift
>= 0) {
502 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
504 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
506 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
507 tcg_gen_or_tl(d
, d
, t
);
510 tcg_temp_free(org_s
);
513 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
515 TCGLabel
*l1
= gen_new_label();
517 /* Conditional jmp. */
518 tcg_gen_mov_tl(env_pc
, pc_false
);
519 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
520 tcg_gen_mov_tl(env_pc
, pc_true
);
524 static inline bool use_goto_tb(DisasContext
*dc
, target_ulong dest
)
526 #ifndef CONFIG_USER_ONLY
527 return (dc
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) ||
528 (dc
->ppc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
534 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
536 if (use_goto_tb(dc
, dest
)) {
538 tcg_gen_movi_tl(env_pc
, dest
);
539 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ n
);
541 tcg_gen_movi_tl(env_pc
, dest
);
546 static inline void cris_clear_x_flag(DisasContext
*dc
)
548 if (dc
->flagx_known
&& dc
->flags_x
) {
549 dc
->flags_uptodate
= 0;
556 static void cris_flush_cc_state(DisasContext
*dc
)
558 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
559 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
560 dc
->cc_size_uptodate
= dc
->cc_size
;
562 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
563 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
566 static void cris_evaluate_flags(DisasContext
*dc
)
568 if (dc
->flags_uptodate
) {
572 cris_flush_cc_state(dc
);
576 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
577 cpu_PR
[PR_CCS
], cc_src
,
581 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
582 cpu_PR
[PR_CCS
], cc_result
,
586 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
587 cpu_PR
[PR_CCS
], cc_result
,
597 switch (dc
->cc_size
) {
599 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
600 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
603 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
604 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
607 gen_helper_evaluate_flags(cpu_env
);
616 if (dc
->cc_size
== 4) {
617 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
618 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
620 gen_helper_evaluate_flags(cpu_env
);
625 switch (dc
->cc_size
) {
627 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
628 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
631 gen_helper_evaluate_flags(cpu_env
);
637 if (dc
->flagx_known
) {
639 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
640 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
641 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
644 dc
->flags_uptodate
= 1;
647 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
656 /* Check if we need to evaluate the condition codes due to
658 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
660 /* TODO: optimize this case. It trigs all the time. */
661 cris_evaluate_flags(dc
);
667 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
671 dc
->flags_uptodate
= 0;
674 static inline void cris_update_cc_x(DisasContext
*dc
)
676 /* Save the x flag state at the time of the cc snapshot. */
677 if (dc
->flagx_known
) {
678 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
681 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
682 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
684 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
685 dc
->cc_x_uptodate
= 1;
689 /* Update cc prior to executing ALU op. Needs source operands untouched. */
690 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
691 TCGv dst
, TCGv src
, int size
)
694 cris_update_cc_op(dc
, op
, size
);
695 tcg_gen_mov_tl(cc_src
, src
);
703 && op
!= CC_OP_LSL
) {
704 tcg_gen_mov_tl(cc_dest
, dst
);
707 cris_update_cc_x(dc
);
711 /* Update cc after executing ALU op. needs the result. */
712 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
715 tcg_gen_mov_tl(cc_result
, res
);
719 /* Returns one if the write back stage should execute. */
720 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
721 TCGv dst
, TCGv a
, TCGv b
, int size
)
723 /* Emit the ALU insns. */
726 tcg_gen_add_tl(dst
, a
, b
);
727 /* Extended arithmetics. */
728 t_gen_addx_carry(dc
, dst
);
731 tcg_gen_add_tl(dst
, a
, b
);
732 t_gen_add_flag(dst
, 0); /* C_FLAG. */
735 tcg_gen_add_tl(dst
, a
, b
);
736 t_gen_add_flag(dst
, 8); /* R_FLAG. */
739 tcg_gen_sub_tl(dst
, a
, b
);
740 /* Extended arithmetics. */
741 t_gen_subx_carry(dc
, dst
);
744 tcg_gen_mov_tl(dst
, b
);
747 tcg_gen_or_tl(dst
, a
, b
);
750 tcg_gen_and_tl(dst
, a
, b
);
753 tcg_gen_xor_tl(dst
, a
, b
);
756 t_gen_lsl(dst
, a
, b
);
759 t_gen_lsr(dst
, a
, b
);
762 t_gen_asr(dst
, a
, b
);
765 tcg_gen_neg_tl(dst
, b
);
766 /* Extended arithmetics. */
767 t_gen_subx_carry(dc
, dst
);
770 gen_helper_lz(dst
, b
);
773 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
776 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
779 t_gen_cris_dstep(dst
, a
, b
);
782 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
785 tcg_gen_movcond_tl(TCG_COND_LEU
, dst
, a
, b
, a
, b
);
788 tcg_gen_sub_tl(dst
, a
, b
);
789 /* Extended arithmetics. */
790 t_gen_subx_carry(dc
, dst
);
793 qemu_log_mask(LOG_GUEST_ERROR
, "illegal ALU op.\n");
799 tcg_gen_andi_tl(dst
, dst
, 0xff);
800 } else if (size
== 2) {
801 tcg_gen_andi_tl(dst
, dst
, 0xffff);
805 static void cris_alu(DisasContext
*dc
, int op
,
806 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
813 if (op
== CC_OP_CMP
) {
814 tmp
= tcg_temp_new();
816 } else if (size
== 4) {
820 tmp
= tcg_temp_new();
824 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
825 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
826 cris_update_result(dc
, tmp
);
831 tcg_gen_andi_tl(d
, d
, ~0xff);
833 tcg_gen_andi_tl(d
, d
, ~0xffff);
835 tcg_gen_or_tl(d
, d
, tmp
);
837 if (!TCGV_EQUAL(tmp
, d
)) {
842 static int arith_cc(DisasContext
*dc
)
846 case CC_OP_ADDC
: return 1;
847 case CC_OP_ADD
: return 1;
848 case CC_OP_SUB
: return 1;
849 case CC_OP_DSTEP
: return 1;
850 case CC_OP_LSL
: return 1;
851 case CC_OP_LSR
: return 1;
852 case CC_OP_ASR
: return 1;
853 case CC_OP_CMP
: return 1;
854 case CC_OP_NEG
: return 1;
855 case CC_OP_OR
: return 1;
856 case CC_OP_AND
: return 1;
857 case CC_OP_XOR
: return 1;
858 case CC_OP_MULU
: return 1;
859 case CC_OP_MULS
: return 1;
867 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
869 int arith_opt
, move_opt
;
871 /* TODO: optimize more condition codes. */
874 * If the flags are live, we've gotta look into the bits of CCS.
875 * Otherwise, if we just did an arithmetic operation we try to
876 * evaluate the condition code faster.
878 * When this function is done, T0 should be non-zero if the condition
881 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
882 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
885 if ((arith_opt
|| move_opt
)
886 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
887 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
888 cc_result
, tcg_const_tl(0));
890 cris_evaluate_flags(dc
);
892 cpu_PR
[PR_CCS
], Z_FLAG
);
896 if ((arith_opt
|| move_opt
)
897 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
898 tcg_gen_mov_tl(cc
, cc_result
);
900 cris_evaluate_flags(dc
);
901 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
903 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
907 cris_evaluate_flags(dc
);
908 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
911 cris_evaluate_flags(dc
);
912 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
913 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
916 cris_evaluate_flags(dc
);
917 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
920 cris_evaluate_flags(dc
);
921 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
923 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
926 if (arith_opt
|| move_opt
) {
929 if (dc
->cc_size
== 1) {
931 } else if (dc
->cc_size
== 2) {
935 tcg_gen_shri_tl(cc
, cc_result
, bits
);
936 tcg_gen_xori_tl(cc
, cc
, 1);
938 cris_evaluate_flags(dc
);
939 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
941 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
945 if (arith_opt
|| move_opt
) {
948 if (dc
->cc_size
== 1) {
950 } else if (dc
->cc_size
== 2) {
954 tcg_gen_shri_tl(cc
, cc_result
, bits
);
955 tcg_gen_andi_tl(cc
, cc
, 1);
957 cris_evaluate_flags(dc
);
958 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
963 cris_evaluate_flags(dc
);
964 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
968 cris_evaluate_flags(dc
);
972 tmp
= tcg_temp_new();
973 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
975 /* Overlay the C flag on top of the Z. */
976 tcg_gen_shli_tl(cc
, tmp
, 2);
977 tcg_gen_and_tl(cc
, tmp
, cc
);
978 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
984 cris_evaluate_flags(dc
);
985 /* Overlay the V flag on top of the N. */
986 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
989 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
990 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
993 cris_evaluate_flags(dc
);
994 /* Overlay the V flag on top of the N. */
995 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
998 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1001 cris_evaluate_flags(dc
);
1008 /* To avoid a shift we overlay everything on
1010 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1011 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1013 tcg_gen_xori_tl(z
, z
, 2);
1015 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1016 tcg_gen_xori_tl(n
, n
, 2);
1017 tcg_gen_and_tl(cc
, z
, n
);
1018 tcg_gen_andi_tl(cc
, cc
, 2);
1025 cris_evaluate_flags(dc
);
1032 /* To avoid a shift we overlay everything on
1034 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1035 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1037 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1038 tcg_gen_or_tl(cc
, z
, n
);
1039 tcg_gen_andi_tl(cc
, cc
, 2);
1046 cris_evaluate_flags(dc
);
1047 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1050 tcg_gen_movi_tl(cc
, 1);
1058 static void cris_store_direct_jmp(DisasContext
*dc
)
1060 /* Store the direct jmp state into the cpu-state. */
1061 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1062 if (dc
->jmp
== JMP_DIRECT
) {
1063 tcg_gen_movi_tl(env_btaken
, 1);
1065 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1066 dc
->jmp
= JMP_INDIRECT
;
1070 static void cris_prepare_cc_branch (DisasContext
*dc
,
1071 int offset
, int cond
)
1073 /* This helps us re-schedule the micro-code to insns in delay-slots
1074 before the actual jump. */
1075 dc
->delayed_branch
= 2;
1076 dc
->jmp
= JMP_DIRECT_CC
;
1077 dc
->jmp_pc
= dc
->pc
+ offset
;
1079 gen_tst_cc(dc
, env_btaken
, cond
);
1080 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1084 /* jumps, when the dest is in a live reg for example. Direct should be set
1085 when the dest addr is constant to allow tb chaining. */
1086 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1088 /* This helps us re-schedule the micro-code to insns in delay-slots
1089 before the actual jump. */
1090 dc
->delayed_branch
= 2;
1092 if (type
== JMP_INDIRECT
) {
1093 tcg_gen_movi_tl(env_btaken
, 1);
1097 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1099 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1101 /* If we get a fault on a delayslot we must keep the jmp state in
1102 the cpu-state to be able to re-execute the jmp. */
1103 if (dc
->delayed_branch
== 1) {
1104 cris_store_direct_jmp(dc
);
1107 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1110 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1111 unsigned int size
, int sign
)
1113 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1115 /* If we get a fault on a delayslot we must keep the jmp state in
1116 the cpu-state to be able to re-execute the jmp. */
1117 if (dc
->delayed_branch
== 1) {
1118 cris_store_direct_jmp(dc
);
1121 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1122 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1125 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1128 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1130 /* If we get a fault on a delayslot we must keep the jmp state in
1131 the cpu-state to be able to re-execute the jmp. */
1132 if (dc
->delayed_branch
== 1) {
1133 cris_store_direct_jmp(dc
);
1137 /* Conditional writes. We only support the kind were X and P are known
1138 at translation time. */
1139 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1141 cris_evaluate_flags(dc
);
1142 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1146 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1148 if (dc
->flagx_known
&& dc
->flags_x
) {
1149 cris_evaluate_flags(dc
);
1150 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1154 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1157 tcg_gen_ext8s_i32(d
, s
);
1158 } else if (size
== 2) {
1159 tcg_gen_ext16s_i32(d
, s
);
1160 } else if (!TCGV_EQUAL(d
, s
)) {
1161 tcg_gen_mov_tl(d
, s
);
1165 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1168 tcg_gen_ext8u_i32(d
, s
);
1169 } else if (size
== 2) {
1170 tcg_gen_ext16u_i32(d
, s
);
1171 } else if (!TCGV_EQUAL(d
, s
)) {
1172 tcg_gen_mov_tl(d
, s
);
1177 static char memsize_char(int size
)
1180 case 1: return 'b'; break;
1181 case 2: return 'w'; break;
1182 case 4: return 'd'; break;
1190 static inline unsigned int memsize_z(DisasContext
*dc
)
1192 return dc
->zsize
+ 1;
1195 static inline unsigned int memsize_zz(DisasContext
*dc
)
1197 switch (dc
->zzsize
) {
1205 static inline void do_postinc (DisasContext
*dc
, int size
)
1208 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1212 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1213 int size
, int s_ext
, TCGv dst
)
1216 t_gen_sext(dst
, cpu_R
[rs
], size
);
1218 t_gen_zext(dst
, cpu_R
[rs
], size
);
1222 /* Prepare T0 and T1 for a register alu operation.
1223 s_ext decides if the operand1 should be sign-extended or zero-extended when
1225 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1226 int size
, int s_ext
, TCGv dst
, TCGv src
)
1228 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1231 t_gen_sext(dst
, cpu_R
[rd
], size
);
1233 t_gen_zext(dst
, cpu_R
[rd
], size
);
1237 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1238 int s_ext
, int memsize
, TCGv dst
)
1246 is_imm
= rs
== 15 && dc
->postinc
;
1248 /* Load [$rs] onto T1. */
1250 insn_len
= 2 + memsize
;
1255 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1256 tcg_gen_movi_tl(dst
, imm
);
1259 cris_flush_cc_state(dc
);
1260 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1262 t_gen_sext(dst
, dst
, memsize
);
1264 t_gen_zext(dst
, dst
, memsize
);
1270 /* Prepare T0 and T1 for a memory + alu operation.
1271 s_ext decides if the operand1 should be sign-extended or zero-extended when
1273 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1274 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1278 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1279 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1284 static const char *cc_name(int cc
)
1286 static const char *cc_names
[16] = {
1287 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1288 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1291 return cc_names
[cc
];
1295 /* Start of insn decoders. */
1297 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1301 uint32_t cond
= dc
->op2
;
1303 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1304 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1307 offset
|= sign
<< 8;
1308 offset
= sign_extend(offset
, 8);
1310 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1312 /* op2 holds the condition-code. */
1313 cris_cc_mask(dc
, 0);
1314 cris_prepare_cc_branch(dc
, offset
, cond
);
1317 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1321 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1322 imm
= sign_extend(dc
->op1
, 7);
1324 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1325 cris_cc_mask(dc
, 0);
1326 /* Fetch register operand, */
1327 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1331 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1333 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1335 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1337 cris_cc_mask(dc
, CC_MASK_NZVC
);
1339 cris_alu(dc
, CC_OP_ADD
,
1340 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1343 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1347 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1348 imm
= sign_extend(dc
->op1
, 5);
1349 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1351 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1354 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1356 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1358 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1360 cris_cc_mask(dc
, CC_MASK_NZVC
);
1361 cris_alu(dc
, CC_OP_SUB
,
1362 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1365 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1368 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1369 imm
= sign_extend(dc
->op1
, 5);
1371 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1372 cris_cc_mask(dc
, CC_MASK_NZVC
);
1374 cris_alu(dc
, CC_OP_CMP
,
1375 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1378 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1381 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1382 imm
= sign_extend(dc
->op1
, 5);
1384 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1385 cris_cc_mask(dc
, CC_MASK_NZ
);
1387 cris_alu(dc
, CC_OP_AND
,
1388 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1391 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1394 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1395 imm
= sign_extend(dc
->op1
, 5);
1396 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1397 cris_cc_mask(dc
, CC_MASK_NZ
);
1399 cris_alu(dc
, CC_OP_OR
,
1400 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1403 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1405 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1406 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1408 cris_cc_mask(dc
, CC_MASK_NZ
);
1409 cris_evaluate_flags(dc
);
1410 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1411 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1412 cris_alu(dc
, CC_OP_MOVE
,
1413 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1414 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1415 dc
->flags_uptodate
= 1;
1418 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1420 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1421 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1422 cris_cc_mask(dc
, CC_MASK_NZ
);
1424 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1425 cris_alu(dc
, CC_OP_MOVE
,
1427 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1430 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1432 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1433 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1435 cris_cc_mask(dc
, CC_MASK_NZ
);
1437 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1439 cris_alu(dc
, CC_OP_MOVE
,
1441 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1444 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1446 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1447 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1449 cris_cc_mask(dc
, CC_MASK_NZ
);
1451 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1452 cris_alu(dc
, CC_OP_MOVE
,
1454 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1458 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1460 int size
= memsize_zz(dc
);
1462 LOG_DIS("move.%c $r%u, $r%u\n",
1463 memsize_char(size
), dc
->op1
, dc
->op2
);
1465 cris_cc_mask(dc
, CC_MASK_NZ
);
1467 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1468 cris_cc_mask(dc
, CC_MASK_NZ
);
1469 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1470 cris_update_cc_x(dc
);
1471 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1475 t0
= tcg_temp_new();
1476 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1477 cris_alu(dc
, CC_OP_MOVE
,
1479 cpu_R
[dc
->op2
], t0
, size
);
1485 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1489 LOG_DIS("s%s $r%u\n",
1490 cc_name(cond
), dc
->op1
);
1492 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1493 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], 0);
1495 cris_cc_mask(dc
, 0);
1499 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1502 t
[0] = cpu_R
[dc
->op2
];
1503 t
[1] = cpu_R
[dc
->op1
];
1505 t
[0] = tcg_temp_new();
1506 t
[1] = tcg_temp_new();
1510 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1513 tcg_temp_free(t
[0]);
1514 tcg_temp_free(t
[1]);
1518 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1521 int size
= memsize_zz(dc
);
1523 LOG_DIS("and.%c $r%u, $r%u\n",
1524 memsize_char(size
), dc
->op1
, dc
->op2
);
1526 cris_cc_mask(dc
, CC_MASK_NZ
);
1528 cris_alu_alloc_temps(dc
, size
, t
);
1529 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1530 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1531 cris_alu_free_temps(dc
, size
, t
);
1535 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1538 LOG_DIS("lz $r%u, $r%u\n",
1540 cris_cc_mask(dc
, CC_MASK_NZ
);
1541 t0
= tcg_temp_new();
1542 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1543 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1548 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1551 int size
= memsize_zz(dc
);
1553 LOG_DIS("lsl.%c $r%u, $r%u\n",
1554 memsize_char(size
), dc
->op1
, dc
->op2
);
1556 cris_cc_mask(dc
, CC_MASK_NZ
);
1557 cris_alu_alloc_temps(dc
, size
, t
);
1558 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1559 tcg_gen_andi_tl(t
[1], t
[1], 63);
1560 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1561 cris_alu_alloc_temps(dc
, size
, t
);
1565 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1568 int size
= memsize_zz(dc
);
1570 LOG_DIS("lsr.%c $r%u, $r%u\n",
1571 memsize_char(size
), dc
->op1
, dc
->op2
);
1573 cris_cc_mask(dc
, CC_MASK_NZ
);
1574 cris_alu_alloc_temps(dc
, size
, t
);
1575 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1576 tcg_gen_andi_tl(t
[1], t
[1], 63);
1577 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1578 cris_alu_free_temps(dc
, size
, t
);
1582 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1585 int size
= memsize_zz(dc
);
1587 LOG_DIS("asr.%c $r%u, $r%u\n",
1588 memsize_char(size
), dc
->op1
, dc
->op2
);
1590 cris_cc_mask(dc
, CC_MASK_NZ
);
1591 cris_alu_alloc_temps(dc
, size
, t
);
1592 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1593 tcg_gen_andi_tl(t
[1], t
[1], 63);
1594 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1595 cris_alu_free_temps(dc
, size
, t
);
1599 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1602 int size
= memsize_zz(dc
);
1604 LOG_DIS("muls.%c $r%u, $r%u\n",
1605 memsize_char(size
), dc
->op1
, dc
->op2
);
1606 cris_cc_mask(dc
, CC_MASK_NZV
);
1607 cris_alu_alloc_temps(dc
, size
, t
);
1608 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1610 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1611 cris_alu_free_temps(dc
, size
, t
);
1615 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1618 int size
= memsize_zz(dc
);
1620 LOG_DIS("mulu.%c $r%u, $r%u\n",
1621 memsize_char(size
), dc
->op1
, dc
->op2
);
1622 cris_cc_mask(dc
, CC_MASK_NZV
);
1623 cris_alu_alloc_temps(dc
, size
, t
);
1624 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1626 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1627 cris_alu_alloc_temps(dc
, size
, t
);
1632 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1634 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1635 cris_cc_mask(dc
, CC_MASK_NZ
);
1636 cris_alu(dc
, CC_OP_DSTEP
,
1637 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1641 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1644 int size
= memsize_zz(dc
);
1645 LOG_DIS("xor.%c $r%u, $r%u\n",
1646 memsize_char(size
), dc
->op1
, dc
->op2
);
1647 BUG_ON(size
!= 4); /* xor is dword. */
1648 cris_cc_mask(dc
, CC_MASK_NZ
);
1649 cris_alu_alloc_temps(dc
, size
, t
);
1650 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1652 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1653 cris_alu_free_temps(dc
, size
, t
);
1657 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1660 int size
= memsize_zz(dc
);
1661 LOG_DIS("bound.%c $r%u, $r%u\n",
1662 memsize_char(size
), dc
->op1
, dc
->op2
);
1663 cris_cc_mask(dc
, CC_MASK_NZ
);
1664 l0
= tcg_temp_local_new();
1665 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1666 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1671 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1674 int size
= memsize_zz(dc
);
1675 LOG_DIS("cmp.%c $r%u, $r%u\n",
1676 memsize_char(size
), dc
->op1
, dc
->op2
);
1677 cris_cc_mask(dc
, CC_MASK_NZVC
);
1678 cris_alu_alloc_temps(dc
, size
, t
);
1679 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1681 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1682 cris_alu_free_temps(dc
, size
, t
);
1686 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1690 LOG_DIS("abs $r%u, $r%u\n",
1692 cris_cc_mask(dc
, CC_MASK_NZ
);
1694 t0
= tcg_temp_new();
1695 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1696 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1697 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1700 cris_alu(dc
, CC_OP_MOVE
,
1701 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1705 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1708 int size
= memsize_zz(dc
);
1709 LOG_DIS("add.%c $r%u, $r%u\n",
1710 memsize_char(size
), dc
->op1
, dc
->op2
);
1711 cris_cc_mask(dc
, CC_MASK_NZVC
);
1712 cris_alu_alloc_temps(dc
, size
, t
);
1713 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1715 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1716 cris_alu_free_temps(dc
, size
, t
);
1720 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1722 LOG_DIS("addc $r%u, $r%u\n",
1724 cris_evaluate_flags(dc
);
1725 /* Set for this insn. */
1726 dc
->flagx_known
= 1;
1727 dc
->flags_x
= X_FLAG
;
1729 cris_cc_mask(dc
, CC_MASK_NZVC
);
1730 cris_alu(dc
, CC_OP_ADDC
,
1731 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1735 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1737 LOG_DIS("mcp $p%u, $r%u\n",
1739 cris_evaluate_flags(dc
);
1740 cris_cc_mask(dc
, CC_MASK_RNZV
);
1741 cris_alu(dc
, CC_OP_MCP
,
1742 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1747 static char * swapmode_name(int mode
, char *modename
) {
1750 modename
[i
++] = 'n';
1753 modename
[i
++] = 'w';
1756 modename
[i
++] = 'b';
1759 modename
[i
++] = 'r';
1766 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1772 LOG_DIS("swap%s $r%u\n",
1773 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1775 cris_cc_mask(dc
, CC_MASK_NZ
);
1776 t0
= tcg_temp_new();
1777 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1779 tcg_gen_not_tl(t0
, t0
);
1782 t_gen_swapw(t0
, t0
);
1785 t_gen_swapb(t0
, t0
);
1788 t_gen_swapr(t0
, t0
);
1790 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1795 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1798 int size
= memsize_zz(dc
);
1799 LOG_DIS("or.%c $r%u, $r%u\n",
1800 memsize_char(size
), dc
->op1
, dc
->op2
);
1801 cris_cc_mask(dc
, CC_MASK_NZ
);
1802 cris_alu_alloc_temps(dc
, size
, t
);
1803 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1804 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1805 cris_alu_free_temps(dc
, size
, t
);
1809 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1812 LOG_DIS("addi.%c $r%u, $r%u\n",
1813 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1814 cris_cc_mask(dc
, 0);
1815 t0
= tcg_temp_new();
1816 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1817 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1822 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1825 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1826 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1827 cris_cc_mask(dc
, 0);
1828 t0
= tcg_temp_new();
1829 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1830 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1835 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1838 int size
= memsize_zz(dc
);
1839 LOG_DIS("neg.%c $r%u, $r%u\n",
1840 memsize_char(size
), dc
->op1
, dc
->op2
);
1841 cris_cc_mask(dc
, CC_MASK_NZVC
);
1842 cris_alu_alloc_temps(dc
, size
, t
);
1843 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1845 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1846 cris_alu_free_temps(dc
, size
, t
);
1850 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1852 LOG_DIS("btst $r%u, $r%u\n",
1854 cris_cc_mask(dc
, CC_MASK_NZ
);
1855 cris_evaluate_flags(dc
);
1856 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1857 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1858 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1859 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1860 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1861 dc
->flags_uptodate
= 1;
1865 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1868 int size
= memsize_zz(dc
);
1869 LOG_DIS("sub.%c $r%u, $r%u\n",
1870 memsize_char(size
), dc
->op1
, dc
->op2
);
1871 cris_cc_mask(dc
, CC_MASK_NZVC
);
1872 cris_alu_alloc_temps(dc
, size
, t
);
1873 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1874 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1875 cris_alu_free_temps(dc
, size
, t
);
1879 /* Zero extension. From size to dword. */
1880 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1883 int size
= memsize_z(dc
);
1884 LOG_DIS("movu.%c $r%u, $r%u\n",
1888 cris_cc_mask(dc
, CC_MASK_NZ
);
1889 t0
= tcg_temp_new();
1890 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1891 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1896 /* Sign extension. From size to dword. */
1897 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1900 int size
= memsize_z(dc
);
1901 LOG_DIS("movs.%c $r%u, $r%u\n",
1905 cris_cc_mask(dc
, CC_MASK_NZ
);
1906 t0
= tcg_temp_new();
1907 /* Size can only be qi or hi. */
1908 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1909 cris_alu(dc
, CC_OP_MOVE
,
1910 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1915 /* zero extension. From size to dword. */
1916 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1919 int size
= memsize_z(dc
);
1920 LOG_DIS("addu.%c $r%u, $r%u\n",
1924 cris_cc_mask(dc
, CC_MASK_NZVC
);
1925 t0
= tcg_temp_new();
1926 /* Size can only be qi or hi. */
1927 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1928 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1933 /* Sign extension. From size to dword. */
1934 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1937 int size
= memsize_z(dc
);
1938 LOG_DIS("adds.%c $r%u, $r%u\n",
1942 cris_cc_mask(dc
, CC_MASK_NZVC
);
1943 t0
= tcg_temp_new();
1944 /* Size can only be qi or hi. */
1945 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1946 cris_alu(dc
, CC_OP_ADD
,
1947 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1952 /* Zero extension. From size to dword. */
1953 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1956 int size
= memsize_z(dc
);
1957 LOG_DIS("subu.%c $r%u, $r%u\n",
1961 cris_cc_mask(dc
, CC_MASK_NZVC
);
1962 t0
= tcg_temp_new();
1963 /* Size can only be qi or hi. */
1964 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1965 cris_alu(dc
, CC_OP_SUB
,
1966 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1971 /* Sign extension. From size to dword. */
1972 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1975 int size
= memsize_z(dc
);
1976 LOG_DIS("subs.%c $r%u, $r%u\n",
1980 cris_cc_mask(dc
, CC_MASK_NZVC
);
1981 t0
= tcg_temp_new();
1982 /* Size can only be qi or hi. */
1983 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1984 cris_alu(dc
, CC_OP_SUB
,
1985 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1990 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
1993 int set
= (~dc
->opcode
>> 2) & 1;
1996 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1997 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1998 if (set
&& flags
== 0) {
2001 } else if (!set
&& (flags
& 0x20)) {
2004 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2007 /* User space is not allowed to touch these. Silently ignore. */
2008 if (dc
->tb_flags
& U_FLAG
) {
2009 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2012 if (flags
& X_FLAG
) {
2013 dc
->flagx_known
= 1;
2015 dc
->flags_x
= X_FLAG
;
2021 /* Break the TB if any of the SPI flag changes. */
2022 if (flags
& (P_FLAG
| S_FLAG
)) {
2023 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2024 dc
->is_jmp
= DISAS_UPDATE
;
2025 dc
->cpustate_changed
= 1;
2028 /* For the I flag, only act on posedge. */
2029 if ((flags
& I_FLAG
)) {
2030 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2031 dc
->is_jmp
= DISAS_UPDATE
;
2032 dc
->cpustate_changed
= 1;
2036 /* Simply decode the flags. */
2037 cris_evaluate_flags(dc
);
2038 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2039 cris_update_cc_x(dc
);
2040 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2043 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2044 /* Enter user mode. */
2045 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2046 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2047 dc
->cpustate_changed
= 1;
2049 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2051 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2054 dc
->flags_uptodate
= 1;
2059 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2061 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2062 cris_cc_mask(dc
, 0);
2063 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2064 tcg_const_tl(dc
->op1
));
2067 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2069 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2070 cris_cc_mask(dc
, 0);
2071 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2072 tcg_const_tl(dc
->op2
));
2076 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2079 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2080 cris_cc_mask(dc
, 0);
2082 t
[0] = tcg_temp_new();
2083 if (dc
->op2
== PR_CCS
) {
2084 cris_evaluate_flags(dc
);
2085 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2086 if (dc
->tb_flags
& U_FLAG
) {
2087 t
[1] = tcg_temp_new();
2088 /* User space is not allowed to touch all flags. */
2089 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2090 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2091 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2092 tcg_temp_free(t
[1]);
2095 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2098 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2099 if (dc
->op2
== PR_CCS
) {
2100 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2101 dc
->flags_uptodate
= 1;
2103 tcg_temp_free(t
[0]);
2106 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2109 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2110 cris_cc_mask(dc
, 0);
2112 if (dc
->op2
== PR_CCS
) {
2113 cris_evaluate_flags(dc
);
2116 if (dc
->op2
== PR_DZ
) {
2117 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2119 t0
= tcg_temp_new();
2120 t_gen_mov_TN_preg(t0
, dc
->op2
);
2121 cris_alu(dc
, CC_OP_MOVE
,
2122 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2123 preg_sizes
[dc
->op2
]);
2129 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2131 int memsize
= memsize_zz(dc
);
2133 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2134 memsize_char(memsize
),
2135 dc
->op1
, dc
->postinc
? "+]" : "]",
2139 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2140 cris_cc_mask(dc
, CC_MASK_NZ
);
2141 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2142 cris_update_cc_x(dc
);
2143 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2147 t0
= tcg_temp_new();
2148 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2149 cris_cc_mask(dc
, CC_MASK_NZ
);
2150 cris_alu(dc
, CC_OP_MOVE
,
2151 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2154 do_postinc(dc
, memsize
);
2158 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2160 t
[0] = tcg_temp_new();
2161 t
[1] = tcg_temp_new();
2164 static inline void cris_alu_m_free_temps(TCGv
*t
)
2166 tcg_temp_free(t
[0]);
2167 tcg_temp_free(t
[1]);
2170 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2173 int memsize
= memsize_z(dc
);
2175 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2176 memsize_char(memsize
),
2177 dc
->op1
, dc
->postinc
? "+]" : "]",
2180 cris_alu_m_alloc_temps(t
);
2182 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2183 cris_cc_mask(dc
, CC_MASK_NZ
);
2184 cris_alu(dc
, CC_OP_MOVE
,
2185 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2186 do_postinc(dc
, memsize
);
2187 cris_alu_m_free_temps(t
);
2191 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2194 int memsize
= memsize_z(dc
);
2196 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2197 memsize_char(memsize
),
2198 dc
->op1
, dc
->postinc
? "+]" : "]",
2201 cris_alu_m_alloc_temps(t
);
2203 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2204 cris_cc_mask(dc
, CC_MASK_NZVC
);
2205 cris_alu(dc
, CC_OP_ADD
,
2206 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2207 do_postinc(dc
, memsize
);
2208 cris_alu_m_free_temps(t
);
2212 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2215 int memsize
= memsize_z(dc
);
2217 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2218 memsize_char(memsize
),
2219 dc
->op1
, dc
->postinc
? "+]" : "]",
2222 cris_alu_m_alloc_temps(t
);
2224 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2225 cris_cc_mask(dc
, CC_MASK_NZVC
);
2226 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2227 do_postinc(dc
, memsize
);
2228 cris_alu_m_free_temps(t
);
2232 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2235 int memsize
= memsize_z(dc
);
2237 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2238 memsize_char(memsize
),
2239 dc
->op1
, dc
->postinc
? "+]" : "]",
2242 cris_alu_m_alloc_temps(t
);
2244 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2245 cris_cc_mask(dc
, CC_MASK_NZVC
);
2246 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2247 do_postinc(dc
, memsize
);
2248 cris_alu_m_free_temps(t
);
2252 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2255 int memsize
= memsize_z(dc
);
2257 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2258 memsize_char(memsize
),
2259 dc
->op1
, dc
->postinc
? "+]" : "]",
2262 cris_alu_m_alloc_temps(t
);
2264 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2265 cris_cc_mask(dc
, CC_MASK_NZVC
);
2266 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2267 do_postinc(dc
, memsize
);
2268 cris_alu_m_free_temps(t
);
2272 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2275 int memsize
= memsize_z(dc
);
2278 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2279 memsize_char(memsize
),
2280 dc
->op1
, dc
->postinc
? "+]" : "]",
2283 cris_alu_m_alloc_temps(t
);
2284 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2285 cris_cc_mask(dc
, CC_MASK_NZ
);
2286 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2287 do_postinc(dc
, memsize
);
2288 cris_alu_m_free_temps(t
);
2292 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2295 int memsize
= memsize_z(dc
);
2297 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2298 memsize_char(memsize
),
2299 dc
->op1
, dc
->postinc
? "+]" : "]",
2302 cris_alu_m_alloc_temps(t
);
2303 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2304 cris_cc_mask(dc
, CC_MASK_NZVC
);
2305 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2306 do_postinc(dc
, memsize
);
2307 cris_alu_m_free_temps(t
);
2311 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2314 int memsize
= memsize_z(dc
);
2316 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2317 memsize_char(memsize
),
2318 dc
->op1
, dc
->postinc
? "+]" : "]",
2321 cris_alu_m_alloc_temps(t
);
2322 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2323 cris_cc_mask(dc
, CC_MASK_NZVC
);
2324 cris_alu(dc
, CC_OP_CMP
,
2325 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2327 do_postinc(dc
, memsize
);
2328 cris_alu_m_free_temps(t
);
2332 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2335 int memsize
= memsize_zz(dc
);
2337 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2338 memsize_char(memsize
),
2339 dc
->op1
, dc
->postinc
? "+]" : "]",
2342 cris_alu_m_alloc_temps(t
);
2343 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2344 cris_cc_mask(dc
, CC_MASK_NZVC
);
2345 cris_alu(dc
, CC_OP_CMP
,
2346 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2348 do_postinc(dc
, memsize
);
2349 cris_alu_m_free_temps(t
);
2353 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2356 int memsize
= memsize_zz(dc
);
2358 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2359 memsize_char(memsize
),
2360 dc
->op1
, dc
->postinc
? "+]" : "]",
2363 cris_evaluate_flags(dc
);
2365 cris_alu_m_alloc_temps(t
);
2366 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2367 cris_cc_mask(dc
, CC_MASK_NZ
);
2368 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2370 cris_alu(dc
, CC_OP_CMP
,
2371 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2372 do_postinc(dc
, memsize
);
2373 cris_alu_m_free_temps(t
);
2377 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2380 int memsize
= memsize_zz(dc
);
2382 LOG_DIS("and.%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(env
, dc
, 0, memsize
, t
[0], t
[1]);
2389 cris_cc_mask(dc
, CC_MASK_NZ
);
2390 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2391 do_postinc(dc
, memsize
);
2392 cris_alu_m_free_temps(t
);
2396 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2399 int memsize
= memsize_zz(dc
);
2401 LOG_DIS("add.%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(env
, dc
, 0, memsize
, t
[0], t
[1]);
2408 cris_cc_mask(dc
, CC_MASK_NZVC
);
2409 cris_alu(dc
, CC_OP_ADD
,
2410 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2411 do_postinc(dc
, memsize
);
2412 cris_alu_m_free_temps(t
);
2416 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2419 int memsize
= memsize_zz(dc
);
2421 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2422 memsize_char(memsize
),
2423 dc
->op1
, dc
->postinc
? "+]" : "]",
2426 cris_alu_m_alloc_temps(t
);
2427 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2428 cris_cc_mask(dc
, 0);
2429 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2430 do_postinc(dc
, memsize
);
2431 cris_alu_m_free_temps(t
);
2435 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2438 int memsize
= memsize_zz(dc
);
2440 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2441 memsize_char(memsize
),
2442 dc
->op1
, dc
->postinc
? "+]" : "]",
2445 l
[0] = tcg_temp_local_new();
2446 l
[1] = tcg_temp_local_new();
2447 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2448 cris_cc_mask(dc
, CC_MASK_NZ
);
2449 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2450 do_postinc(dc
, memsize
);
2451 tcg_temp_free(l
[0]);
2452 tcg_temp_free(l
[1]);
2456 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2460 LOG_DIS("addc [$r%u%s, $r%u\n",
2461 dc
->op1
, dc
->postinc
? "+]" : "]",
2464 cris_evaluate_flags(dc
);
2466 /* Set for this insn. */
2467 dc
->flagx_known
= 1;
2468 dc
->flags_x
= X_FLAG
;
2470 cris_alu_m_alloc_temps(t
);
2471 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2472 cris_cc_mask(dc
, CC_MASK_NZVC
);
2473 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2475 cris_alu_m_free_temps(t
);
2479 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2482 int memsize
= memsize_zz(dc
);
2484 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2485 memsize_char(memsize
),
2486 dc
->op1
, dc
->postinc
? "+]" : "]",
2487 dc
->op2
, dc
->ir
, dc
->zzsize
);
2489 cris_alu_m_alloc_temps(t
);
2490 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2491 cris_cc_mask(dc
, CC_MASK_NZVC
);
2492 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2493 do_postinc(dc
, memsize
);
2494 cris_alu_m_free_temps(t
);
2498 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2501 int memsize
= memsize_zz(dc
);
2503 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2504 memsize_char(memsize
),
2505 dc
->op1
, dc
->postinc
? "+]" : "]",
2508 cris_alu_m_alloc_temps(t
);
2509 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2510 cris_cc_mask(dc
, CC_MASK_NZ
);
2511 cris_alu(dc
, CC_OP_OR
,
2512 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2513 do_postinc(dc
, memsize
);
2514 cris_alu_m_free_temps(t
);
2518 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2521 int memsize
= memsize_zz(dc
);
2524 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2525 memsize_char(memsize
),
2527 dc
->postinc
? "+]" : "]",
2530 cris_alu_m_alloc_temps(t
);
2531 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2532 cris_cc_mask(dc
, 0);
2533 if (dc
->op2
== PR_CCS
) {
2534 cris_evaluate_flags(dc
);
2535 if (dc
->tb_flags
& U_FLAG
) {
2536 /* User space is not allowed to touch all flags. */
2537 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2538 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2539 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2543 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2545 do_postinc(dc
, memsize
);
2546 cris_alu_m_free_temps(t
);
2550 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2555 memsize
= preg_sizes
[dc
->op2
];
2557 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2558 memsize_char(memsize
),
2559 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2561 /* prepare store. Address in T0, value in T1. */
2562 if (dc
->op2
== PR_CCS
) {
2563 cris_evaluate_flags(dc
);
2565 t0
= tcg_temp_new();
2566 t_gen_mov_TN_preg(t0
, dc
->op2
);
2567 cris_flush_cc_state(dc
);
2568 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2571 cris_cc_mask(dc
, 0);
2573 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2578 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2584 int nr
= dc
->op2
+ 1;
2586 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2587 dc
->postinc
? "+]" : "]", dc
->op2
);
2589 addr
= tcg_temp_new();
2590 /* There are probably better ways of doing this. */
2591 cris_flush_cc_state(dc
);
2592 for (i
= 0; i
< (nr
>> 1); i
++) {
2593 tmp
[i
] = tcg_temp_new_i64();
2594 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2595 gen_load64(dc
, tmp
[i
], addr
);
2598 tmp32
= tcg_temp_new_i32();
2599 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2600 gen_load(dc
, tmp32
, addr
, 4, 0);
2604 tcg_temp_free(addr
);
2606 for (i
= 0; i
< (nr
>> 1); i
++) {
2607 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2608 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2609 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2610 tcg_temp_free_i64(tmp
[i
]);
2613 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2614 tcg_temp_free(tmp32
);
2617 /* writeback the updated pointer value. */
2619 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2622 /* gen_load might want to evaluate the previous insns flags. */
2623 cris_cc_mask(dc
, 0);
2627 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2633 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2634 dc
->postinc
? "+]" : "]");
2636 cris_flush_cc_state(dc
);
2638 tmp
= tcg_temp_new();
2639 addr
= tcg_temp_new();
2640 tcg_gen_movi_tl(tmp
, 4);
2641 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2642 for (i
= 0; i
<= dc
->op2
; i
++) {
2643 /* Displace addr. */
2644 /* Perform the store. */
2645 gen_store(dc
, addr
, cpu_R
[i
], 4);
2646 tcg_gen_add_tl(addr
, addr
, tmp
);
2649 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2651 cris_cc_mask(dc
, 0);
2653 tcg_temp_free(addr
);
2657 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2661 memsize
= memsize_zz(dc
);
2663 LOG_DIS("move.%c $r%u, [$r%u]\n",
2664 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2666 /* prepare store. */
2667 cris_flush_cc_state(dc
);
2668 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2671 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2673 cris_cc_mask(dc
, 0);
2677 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2679 LOG_DIS("lapcq %x, $r%u\n",
2680 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2681 cris_cc_mask(dc
, 0);
2682 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2686 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2694 cris_cc_mask(dc
, 0);
2695 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2696 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2700 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2704 /* Jump to special reg. */
2705 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2707 LOG_DIS("jump $p%u\n", dc
->op2
);
2709 if (dc
->op2
== PR_CCS
) {
2710 cris_evaluate_flags(dc
);
2712 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2713 /* rete will often have low bit set to indicate delayslot. */
2714 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2715 cris_cc_mask(dc
, 0);
2716 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2720 /* Jump and save. */
2721 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2723 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2724 cris_cc_mask(dc
, 0);
2725 /* Store the return address in Pd. */
2726 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2730 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2732 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2736 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2740 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2742 LOG_DIS("jas 0x%x\n", imm
);
2743 cris_cc_mask(dc
, 0);
2744 /* Store the return address in Pd. */
2745 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2748 cris_prepare_jmp(dc
, JMP_DIRECT
);
2752 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2756 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2758 LOG_DIS("jasc 0x%x\n", imm
);
2759 cris_cc_mask(dc
, 0);
2760 /* Store the return address in Pd. */
2761 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2764 cris_prepare_jmp(dc
, JMP_DIRECT
);
2768 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2770 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2771 cris_cc_mask(dc
, 0);
2772 /* Store the return address in Pd. */
2773 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2774 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2775 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2779 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2782 uint32_t cond
= dc
->op2
;
2784 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2786 LOG_DIS("b%s %d pc=%x dst=%x\n",
2787 cc_name(cond
), offset
,
2788 dc
->pc
, dc
->pc
+ offset
);
2790 cris_cc_mask(dc
, 0);
2791 /* op2 holds the condition-code. */
2792 cris_prepare_cc_branch(dc
, offset
, cond
);
2796 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2800 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2802 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2803 cris_cc_mask(dc
, 0);
2804 /* Store the return address in Pd. */
2805 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2807 dc
->jmp_pc
= dc
->pc
+ simm
;
2808 cris_prepare_jmp(dc
, JMP_DIRECT
);
2812 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2815 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2817 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2818 cris_cc_mask(dc
, 0);
2819 /* Store the return address in Pd. */
2820 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2822 dc
->jmp_pc
= dc
->pc
+ simm
;
2823 cris_prepare_jmp(dc
, JMP_DIRECT
);
2827 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2829 cris_cc_mask(dc
, 0);
2831 if (dc
->op2
== 15) {
2832 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2833 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2834 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2835 t_gen_raise_exception(EXCP_HLT
);
2839 switch (dc
->op2
& 7) {
2843 cris_evaluate_flags(dc
);
2844 gen_helper_rfe(cpu_env
);
2845 dc
->is_jmp
= DISAS_UPDATE
;
2850 cris_evaluate_flags(dc
);
2851 gen_helper_rfn(cpu_env
);
2852 dc
->is_jmp
= DISAS_UPDATE
;
2855 LOG_DIS("break %d\n", dc
->op1
);
2856 cris_evaluate_flags(dc
);
2858 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2860 /* Breaks start at 16 in the exception vector. */
2861 t_gen_mov_env_TN(trap_vector
,
2862 tcg_const_tl(dc
->op1
+ 16));
2863 t_gen_raise_exception(EXCP_BREAK
);
2864 dc
->is_jmp
= DISAS_UPDATE
;
2867 printf("op2=%x\n", dc
->op2
);
2875 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2880 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2885 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2887 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2888 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2894 static struct decoder_info
{
2899 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2901 /* Order matters here. */
2902 {DEC_MOVEQ
, dec_moveq
},
2903 {DEC_BTSTQ
, dec_btstq
},
2904 {DEC_CMPQ
, dec_cmpq
},
2905 {DEC_ADDOQ
, dec_addoq
},
2906 {DEC_ADDQ
, dec_addq
},
2907 {DEC_SUBQ
, dec_subq
},
2908 {DEC_ANDQ
, dec_andq
},
2910 {DEC_ASRQ
, dec_asrq
},
2911 {DEC_LSLQ
, dec_lslq
},
2912 {DEC_LSRQ
, dec_lsrq
},
2913 {DEC_BCCQ
, dec_bccq
},
2915 {DEC_BCC_IM
, dec_bcc_im
},
2916 {DEC_JAS_IM
, dec_jas_im
},
2917 {DEC_JAS_R
, dec_jas_r
},
2918 {DEC_JASC_IM
, dec_jasc_im
},
2919 {DEC_JASC_R
, dec_jasc_r
},
2920 {DEC_BAS_IM
, dec_bas_im
},
2921 {DEC_BASC_IM
, dec_basc_im
},
2922 {DEC_JUMP_P
, dec_jump_p
},
2923 {DEC_LAPC_IM
, dec_lapc_im
},
2924 {DEC_LAPCQ
, dec_lapcq
},
2926 {DEC_RFE_ETC
, dec_rfe_etc
},
2927 {DEC_ADDC_MR
, dec_addc_mr
},
2929 {DEC_MOVE_MP
, dec_move_mp
},
2930 {DEC_MOVE_PM
, dec_move_pm
},
2931 {DEC_MOVEM_MR
, dec_movem_mr
},
2932 {DEC_MOVEM_RM
, dec_movem_rm
},
2933 {DEC_MOVE_PR
, dec_move_pr
},
2934 {DEC_SCC_R
, dec_scc_r
},
2935 {DEC_SETF
, dec_setclrf
},
2936 {DEC_CLEARF
, dec_setclrf
},
2938 {DEC_MOVE_SR
, dec_move_sr
},
2939 {DEC_MOVE_RP
, dec_move_rp
},
2940 {DEC_SWAP_R
, dec_swap_r
},
2941 {DEC_ABS_R
, dec_abs_r
},
2942 {DEC_LZ_R
, dec_lz_r
},
2943 {DEC_MOVE_RS
, dec_move_rs
},
2944 {DEC_BTST_R
, dec_btst_r
},
2945 {DEC_ADDC_R
, dec_addc_r
},
2947 {DEC_DSTEP_R
, dec_dstep_r
},
2948 {DEC_XOR_R
, dec_xor_r
},
2949 {DEC_MCP_R
, dec_mcp_r
},
2950 {DEC_CMP_R
, dec_cmp_r
},
2952 {DEC_ADDI_R
, dec_addi_r
},
2953 {DEC_ADDI_ACR
, dec_addi_acr
},
2955 {DEC_ADD_R
, dec_add_r
},
2956 {DEC_SUB_R
, dec_sub_r
},
2958 {DEC_ADDU_R
, dec_addu_r
},
2959 {DEC_ADDS_R
, dec_adds_r
},
2960 {DEC_SUBU_R
, dec_subu_r
},
2961 {DEC_SUBS_R
, dec_subs_r
},
2962 {DEC_LSL_R
, dec_lsl_r
},
2964 {DEC_AND_R
, dec_and_r
},
2965 {DEC_OR_R
, dec_or_r
},
2966 {DEC_BOUND_R
, dec_bound_r
},
2967 {DEC_ASR_R
, dec_asr_r
},
2968 {DEC_LSR_R
, dec_lsr_r
},
2970 {DEC_MOVU_R
, dec_movu_r
},
2971 {DEC_MOVS_R
, dec_movs_r
},
2972 {DEC_NEG_R
, dec_neg_r
},
2973 {DEC_MOVE_R
, dec_move_r
},
2975 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2976 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2978 {DEC_MULS_R
, dec_muls_r
},
2979 {DEC_MULU_R
, dec_mulu_r
},
2981 {DEC_ADDU_M
, dec_addu_m
},
2982 {DEC_ADDS_M
, dec_adds_m
},
2983 {DEC_SUBU_M
, dec_subu_m
},
2984 {DEC_SUBS_M
, dec_subs_m
},
2986 {DEC_CMPU_M
, dec_cmpu_m
},
2987 {DEC_CMPS_M
, dec_cmps_m
},
2988 {DEC_MOVU_M
, dec_movu_m
},
2989 {DEC_MOVS_M
, dec_movs_m
},
2991 {DEC_CMP_M
, dec_cmp_m
},
2992 {DEC_ADDO_M
, dec_addo_m
},
2993 {DEC_BOUND_M
, dec_bound_m
},
2994 {DEC_ADD_M
, dec_add_m
},
2995 {DEC_SUB_M
, dec_sub_m
},
2996 {DEC_AND_M
, dec_and_m
},
2997 {DEC_OR_M
, dec_or_m
},
2998 {DEC_MOVE_RM
, dec_move_rm
},
2999 {DEC_TEST_M
, dec_test_m
},
3000 {DEC_MOVE_MR
, dec_move_mr
},
3005 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3010 /* Load a halfword onto the instruction register. */
3011 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3013 /* Now decode it. */
3014 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3015 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3016 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3017 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3018 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3019 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3021 /* Large switch for all insns. */
3022 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3023 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3024 insn_len
= decinfo
[i
].dec(env
, dc
);
3029 #if !defined(CONFIG_USER_ONLY)
3030 /* Single-stepping ? */
3031 if (dc
->tb_flags
& S_FLAG
) {
3032 TCGLabel
*l1
= gen_new_label();
3033 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3034 /* We treat SPC as a break with an odd trap vector. */
3035 cris_evaluate_flags(dc
);
3036 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3037 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3038 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3039 t_gen_raise_exception(EXCP_BREAK
);
3046 #include "translate_v10.c"
3049 * Delay slots on QEMU/CRIS.
3051 * If an exception hits on a delayslot, the core will let ERP (the Exception
3052 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3053 * to give SW a hint that the exception actually hit on the dslot.
3055 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3056 * the core and any jmp to an odd addresses will mask off that lsb. It is
3057 * simply there to let sw know there was an exception on a dslot.
3059 * When the software returns from an exception, the branch will re-execute.
3060 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3061 * and the branch and delayslot don't share pages.
3063 * The TB contaning the branch insn will set up env->btarget and evaluate
3064 * env->btaken. When the translation loop exits we will note that the branch
3065 * sequence is broken and let env->dslot be the size of the branch insn (those
3068 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3069 * set). It will also expect to have env->dslot setup with the size of the
3070 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3071 * will execute the dslot and take the branch, either to btarget or just one
3074 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3075 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3076 * branch and set lsb). Then env->dslot gets cleared so that the exception
3077 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3078 * masked off and we will reexecute the branch insn.
3082 /* generate intermediate code for basic block 'tb'. */
3083 void gen_intermediate_code(CPUCRISState
*env
, struct TranslationBlock
*tb
)
3085 CRISCPU
*cpu
= cris_env_get_cpu(env
);
3086 CPUState
*cs
= CPU(cpu
);
3088 unsigned int insn_len
;
3089 struct DisasContext ctx
;
3090 struct DisasContext
*dc
= &ctx
;
3091 uint32_t next_page_start
;
3096 if (env
->pregs
[PR_VR
] == 32) {
3097 dc
->decoder
= crisv32_decoder
;
3098 dc
->clear_locked_irq
= 0;
3100 dc
->decoder
= crisv10_decoder
;
3101 dc
->clear_locked_irq
= 1;
3104 /* Odd PC indicates that branch is rexecuting due to exception in the
3105 * delayslot, like in real hw.
3107 pc_start
= tb
->pc
& ~1;
3111 dc
->is_jmp
= DISAS_NEXT
;
3114 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3115 dc
->flags_uptodate
= 1;
3116 dc
->flagx_known
= 1;
3117 dc
->flags_x
= tb
->flags
& X_FLAG
;
3118 dc
->cc_x_uptodate
= 0;
3121 dc
->clear_prefix
= 0;
3123 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3124 dc
->cc_size_uptodate
= -1;
3126 /* Decode TB flags. */
3127 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3128 | X_FLAG
| PFIX_FLAG
);
3129 dc
->delayed_branch
= !!(tb
->flags
& 7);
3130 if (dc
->delayed_branch
) {
3131 dc
->jmp
= JMP_INDIRECT
;
3133 dc
->jmp
= JMP_NOJMP
;
3136 dc
->cpustate_changed
= 0;
3138 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3140 "pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3147 (uint64_t)tb
->flags
,
3148 env
->btarget
, (unsigned)tb
->flags
& 7,
3150 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3151 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3152 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3153 env
->regs
[8], env
->regs
[9],
3154 env
->regs
[10], env
->regs
[11],
3155 env
->regs
[12], env
->regs
[13],
3156 env
->regs
[14], env
->regs
[15]);
3157 qemu_log("--------------\n");
3158 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3161 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3163 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3164 if (max_insns
== 0) {
3165 max_insns
= CF_COUNT_MASK
;
3167 if (max_insns
> TCG_MAX_INSNS
) {
3168 max_insns
= TCG_MAX_INSNS
;
3173 tcg_gen_insn_start(dc
->delayed_branch
== 1
3174 ? dc
->ppc
| 1 : dc
->pc
);
3177 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
3178 cris_evaluate_flags(dc
);
3179 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3180 t_gen_raise_exception(EXCP_DEBUG
);
3181 dc
->is_jmp
= DISAS_UPDATE
;
3182 /* The address covered by the breakpoint must be included in
3183 [tb->pc, tb->pc + tb->size) in order to for it to be
3184 properly cleared -- thus we increment the PC here so that
3185 the logic setting tb->size below does the right thing. */
3191 LOG_DIS("%8.8x:\t", dc
->pc
);
3193 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3198 insn_len
= dc
->decoder(env
, dc
);
3202 cris_clear_x_flag(dc
);
3205 /* Check for delayed branches here. If we do it before
3206 actually generating any host code, the simulator will just
3207 loop doing nothing for on this program location. */
3208 if (dc
->delayed_branch
) {
3209 dc
->delayed_branch
--;
3210 if (dc
->delayed_branch
== 0) {
3211 if (tb
->flags
& 7) {
3212 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3214 if (dc
->cpustate_changed
|| !dc
->flagx_known
3215 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3216 cris_store_direct_jmp(dc
);
3219 if (dc
->clear_locked_irq
) {
3220 dc
->clear_locked_irq
= 0;
3221 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3224 if (dc
->jmp
== JMP_DIRECT_CC
) {
3225 TCGLabel
*l1
= gen_new_label();
3226 cris_evaluate_flags(dc
);
3228 /* Conditional jmp. */
3229 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3231 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3233 gen_goto_tb(dc
, 0, dc
->pc
);
3234 dc
->is_jmp
= DISAS_TB_JUMP
;
3235 dc
->jmp
= JMP_NOJMP
;
3236 } else if (dc
->jmp
== JMP_DIRECT
) {
3237 cris_evaluate_flags(dc
);
3238 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3239 dc
->is_jmp
= DISAS_TB_JUMP
;
3240 dc
->jmp
= JMP_NOJMP
;
3242 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3243 dc
->is_jmp
= DISAS_JUMP
;
3249 /* If we are rexecuting a branch due to exceptions on
3250 delay slots don't break. */
3251 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3254 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3255 && !tcg_op_buf_full()
3257 && (dc
->pc
< next_page_start
)
3258 && num_insns
< max_insns
);
3260 if (dc
->clear_locked_irq
) {
3261 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3266 if (tb
->cflags
& CF_LAST_IO
)
3268 /* Force an update if the per-tb cpu state has changed. */
3269 if (dc
->is_jmp
== DISAS_NEXT
3270 && (dc
->cpustate_changed
|| !dc
->flagx_known
3271 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3272 dc
->is_jmp
= DISAS_UPDATE
;
3273 tcg_gen_movi_tl(env_pc
, npc
);
3275 /* Broken branch+delayslot sequence. */
3276 if (dc
->delayed_branch
== 1) {
3277 /* Set env->dslot to the size of the branch insn. */
3278 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3279 cris_store_direct_jmp(dc
);
3282 cris_evaluate_flags(dc
);
3284 if (unlikely(cs
->singlestep_enabled
)) {
3285 if (dc
->is_jmp
== DISAS_NEXT
) {
3286 tcg_gen_movi_tl(env_pc
, npc
);
3288 t_gen_raise_exception(EXCP_DEBUG
);
3290 switch (dc
->is_jmp
) {
3292 gen_goto_tb(dc
, 1, npc
);
3297 /* indicate that the hash table must be used
3298 to find the next TB */
3303 /* nothing more to generate */
3307 gen_tb_end(tb
, num_insns
);
3309 tb
->size
= dc
->pc
- pc_start
;
3310 tb
->icount
= num_insns
;
3314 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3315 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
3317 qemu_log("\nisize=%d osize=%d\n",
3318 dc
->pc
- pc_start
, tcg_op_buf_count());
3324 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
3327 CRISCPU
*cpu
= CRIS_CPU(cs
);
3328 CPUCRISState
*env
= &cpu
->env
;
3336 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3337 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3338 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3340 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3343 for (i
= 0; i
< 16; i
++) {
3344 cpu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3345 if ((i
+ 1) % 4 == 0) {
3346 cpu_fprintf(f
, "\n");
3349 cpu_fprintf(f
, "\nspecial regs:\n");
3350 for (i
= 0; i
< 16; i
++) {
3351 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3352 if ((i
+ 1) % 4 == 0) {
3353 cpu_fprintf(f
, "\n");
3356 srs
= env
->pregs
[PR_SRS
];
3357 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3358 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3359 for (i
= 0; i
< 16; i
++) {
3360 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3361 i
, env
->sregs
[srs
][i
]);
3362 if ((i
+ 1) % 4 == 0) {
3363 cpu_fprintf(f
, "\n");
3367 cpu_fprintf(f
, "\n\n");
3371 void cris_initialize_tcg(void)
3375 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3376 cc_x
= tcg_global_mem_new(cpu_env
,
3377 offsetof(CPUCRISState
, cc_x
), "cc_x");
3378 cc_src
= tcg_global_mem_new(cpu_env
,
3379 offsetof(CPUCRISState
, cc_src
), "cc_src");
3380 cc_dest
= tcg_global_mem_new(cpu_env
,
3381 offsetof(CPUCRISState
, cc_dest
),
3383 cc_result
= tcg_global_mem_new(cpu_env
,
3384 offsetof(CPUCRISState
, cc_result
),
3386 cc_op
= tcg_global_mem_new(cpu_env
,
3387 offsetof(CPUCRISState
, cc_op
), "cc_op");
3388 cc_size
= tcg_global_mem_new(cpu_env
,
3389 offsetof(CPUCRISState
, cc_size
),
3391 cc_mask
= tcg_global_mem_new(cpu_env
,
3392 offsetof(CPUCRISState
, cc_mask
),
3395 env_pc
= tcg_global_mem_new(cpu_env
,
3396 offsetof(CPUCRISState
, pc
),
3398 env_btarget
= tcg_global_mem_new(cpu_env
,
3399 offsetof(CPUCRISState
, btarget
),
3401 env_btaken
= tcg_global_mem_new(cpu_env
,
3402 offsetof(CPUCRISState
, btaken
),
3404 for (i
= 0; i
< 16; i
++) {
3405 cpu_R
[i
] = tcg_global_mem_new(cpu_env
,
3406 offsetof(CPUCRISState
, regs
[i
]),
3409 for (i
= 0; i
< 16; i
++) {
3410 cpu_PR
[i
] = tcg_global_mem_new(cpu_env
,
3411 offsetof(CPUCRISState
, pregs
[i
]),
3416 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
,