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.
27 #include "disas/disas.h"
29 #include "exec/helper-proto.h"
31 #include "exec/cpu_ldst.h"
32 #include "crisv32-decode.h"
34 #include "exec/helper-gen.h"
36 #include "trace-tcg.h"
41 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
43 # define LOG_DIS(...) do { } while (0)
47 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
48 #define BUG_ON(x) ({if (x) BUG();})
52 /* Used by the decoder. */
53 #define EXTRACT_FIELD(src, start, end) \
54 (((src) >> start) & ((1 << (end - start + 1)) - 1))
56 #define CC_MASK_NZ 0xc
57 #define CC_MASK_NZV 0xe
58 #define CC_MASK_NZVC 0xf
59 #define CC_MASK_RNZV 0x10e
61 static TCGv_ptr cpu_env
;
62 static TCGv cpu_R
[16];
63 static TCGv cpu_PR
[16];
67 static TCGv cc_result
;
72 static TCGv env_btaken
;
73 static TCGv env_btarget
;
76 #include "exec/gen-icount.h"
78 /* This is the state at translation time. */
79 typedef struct DisasContext
{
84 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
89 unsigned int zsize
, zzsize
;
103 int cc_size_uptodate
; /* -1 invalid or last written value. */
105 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
106 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
107 int flagx_known
; /* Wether or not flags_x has the x flag known at
111 int clear_x
; /* Clear x after this insn? */
112 int clear_prefix
; /* Clear prefix after this insn? */
113 int clear_locked_irq
; /* Clear the irq lockout. */
114 int cpustate_changed
;
115 unsigned int tb_flags
; /* tb dependent flags. */
120 #define JMP_DIRECT_CC 2
121 #define JMP_INDIRECT 3
122 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
127 struct TranslationBlock
*tb
;
128 int singlestep_enabled
;
131 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
133 printf("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
134 qemu_log("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
135 cpu_abort(CPU(dc
->cpu
), "%s:%d\n", file
, line
);
138 static const char *regnames
[] =
140 "$r0", "$r1", "$r2", "$r3",
141 "$r4", "$r5", "$r6", "$r7",
142 "$r8", "$r9", "$r10", "$r11",
143 "$r12", "$r13", "$sp", "$acr",
145 static const char *pregnames
[] =
147 "$bz", "$vr", "$pid", "$srs",
148 "$wz", "$exs", "$eda", "$mof",
149 "$dz", "$ebp", "$erp", "$srp",
150 "$nrp", "$ccs", "$usp", "$spc",
153 /* We need this table to handle preg-moves with implicit width. */
154 static int preg_sizes
[] = {
165 #define t_gen_mov_TN_env(tn, member) \
166 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
167 #define t_gen_mov_env_TN(member, tn) \
168 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
170 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
172 assert(r
>= 0 && r
<= 15);
173 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
174 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
175 } else if (r
== PR_VR
) {
176 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
178 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
181 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
183 assert(r
>= 0 && r
<= 15);
184 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
186 } else if (r
== PR_SRS
) {
187 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
190 gen_helper_tlb_flush_pid(cpu_env
, tn
);
192 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
193 gen_helper_spc_write(cpu_env
, tn
);
194 } else if (r
== PR_CCS
) {
195 dc
->cpustate_changed
= 1;
197 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
201 /* Sign extend at translation time. */
202 static int sign_extend(unsigned int val
, unsigned int width
)
214 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
215 unsigned int size
, unsigned int sign
)
222 r
= cpu_ldl_code(env
, addr
);
228 r
= cpu_ldsw_code(env
, addr
);
230 r
= cpu_lduw_code(env
, addr
);
237 r
= cpu_ldsb_code(env
, addr
);
239 r
= cpu_ldub_code(env
, addr
);
244 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
250 static void cris_lock_irq(DisasContext
*dc
)
252 dc
->clear_locked_irq
= 0;
253 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
256 static inline void t_gen_raise_exception(uint32_t index
)
258 TCGv_i32 tmp
= tcg_const_i32(index
);
259 gen_helper_raise_exception(cpu_env
, tmp
);
260 tcg_temp_free_i32(tmp
);
263 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
268 t_31
= tcg_const_tl(31);
269 tcg_gen_shl_tl(d
, a
, b
);
271 tcg_gen_sub_tl(t0
, t_31
, b
);
272 tcg_gen_sar_tl(t0
, t0
, t_31
);
273 tcg_gen_and_tl(t0
, t0
, d
);
274 tcg_gen_xor_tl(d
, d
, t0
);
279 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
284 t_31
= tcg_temp_new();
285 tcg_gen_shr_tl(d
, a
, b
);
287 tcg_gen_movi_tl(t_31
, 31);
288 tcg_gen_sub_tl(t0
, t_31
, b
);
289 tcg_gen_sar_tl(t0
, t0
, t_31
);
290 tcg_gen_and_tl(t0
, t0
, d
);
291 tcg_gen_xor_tl(d
, d
, t0
);
296 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
301 t_31
= tcg_temp_new();
302 tcg_gen_sar_tl(d
, a
, b
);
304 tcg_gen_movi_tl(t_31
, 31);
305 tcg_gen_sub_tl(t0
, t_31
, b
);
306 tcg_gen_sar_tl(t0
, t0
, t_31
);
307 tcg_gen_or_tl(d
, d
, t0
);
312 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
316 l1
= gen_new_label();
323 tcg_gen_shli_tl(d
, a
, 1);
324 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
325 tcg_gen_sub_tl(d
, d
, b
);
329 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
339 tcg_gen_shli_tl(d
, a
, 1);
340 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
341 tcg_gen_sari_tl(t
, t
, 31);
342 tcg_gen_and_tl(t
, t
, b
);
343 tcg_gen_add_tl(d
, d
, t
);
347 /* Extended arithmetics on CRIS. */
348 static inline void t_gen_add_flag(TCGv d
, int flag
)
353 t_gen_mov_TN_preg(c
, PR_CCS
);
354 /* Propagate carry into d. */
355 tcg_gen_andi_tl(c
, c
, 1 << flag
);
357 tcg_gen_shri_tl(c
, c
, flag
);
359 tcg_gen_add_tl(d
, d
, c
);
363 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
365 if (dc
->flagx_known
) {
370 t_gen_mov_TN_preg(c
, PR_CCS
);
371 /* C flag is already at bit 0. */
372 tcg_gen_andi_tl(c
, c
, C_FLAG
);
373 tcg_gen_add_tl(d
, d
, c
);
381 t_gen_mov_TN_preg(x
, PR_CCS
);
382 tcg_gen_mov_tl(c
, x
);
384 /* Propagate carry into d if X is set. Branch free. */
385 tcg_gen_andi_tl(c
, c
, C_FLAG
);
386 tcg_gen_andi_tl(x
, x
, X_FLAG
);
387 tcg_gen_shri_tl(x
, x
, 4);
389 tcg_gen_and_tl(x
, x
, c
);
390 tcg_gen_add_tl(d
, d
, x
);
396 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
398 if (dc
->flagx_known
) {
403 t_gen_mov_TN_preg(c
, PR_CCS
);
404 /* C flag is already at bit 0. */
405 tcg_gen_andi_tl(c
, c
, C_FLAG
);
406 tcg_gen_sub_tl(d
, d
, c
);
414 t_gen_mov_TN_preg(x
, PR_CCS
);
415 tcg_gen_mov_tl(c
, x
);
417 /* Propagate carry into d if X is set. Branch free. */
418 tcg_gen_andi_tl(c
, c
, C_FLAG
);
419 tcg_gen_andi_tl(x
, x
, X_FLAG
);
420 tcg_gen_shri_tl(x
, x
, 4);
422 tcg_gen_and_tl(x
, x
, c
);
423 tcg_gen_sub_tl(d
, d
, x
);
429 /* Swap the two bytes within each half word of the s operand.
430 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
431 static inline void t_gen_swapb(TCGv d
, TCGv s
)
436 org_s
= tcg_temp_new();
438 /* d and s may refer to the same object. */
439 tcg_gen_mov_tl(org_s
, s
);
440 tcg_gen_shli_tl(t
, org_s
, 8);
441 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
442 tcg_gen_shri_tl(t
, org_s
, 8);
443 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
444 tcg_gen_or_tl(d
, d
, t
);
446 tcg_temp_free(org_s
);
449 /* Swap the halfwords of the s operand. */
450 static inline void t_gen_swapw(TCGv d
, TCGv s
)
453 /* d and s refer the same object. */
455 tcg_gen_mov_tl(t
, s
);
456 tcg_gen_shli_tl(d
, t
, 16);
457 tcg_gen_shri_tl(t
, t
, 16);
458 tcg_gen_or_tl(d
, d
, t
);
462 /* Reverse the within each byte.
463 T0 = (((T0 << 7) & 0x80808080) |
464 ((T0 << 5) & 0x40404040) |
465 ((T0 << 3) & 0x20202020) |
466 ((T0 << 1) & 0x10101010) |
467 ((T0 >> 1) & 0x08080808) |
468 ((T0 >> 3) & 0x04040404) |
469 ((T0 >> 5) & 0x02020202) |
470 ((T0 >> 7) & 0x01010101));
472 static inline void t_gen_swapr(TCGv d
, TCGv s
)
475 int shift
; /* LSL when positive, LSR when negative. */
490 /* d and s refer the same object. */
492 org_s
= tcg_temp_new();
493 tcg_gen_mov_tl(org_s
, s
);
495 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
496 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
497 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
498 if (bitrev
[i
].shift
>= 0) {
499 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
501 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
503 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
504 tcg_gen_or_tl(d
, d
, t
);
507 tcg_temp_free(org_s
);
510 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
514 l1
= gen_new_label();
516 /* Conditional jmp. */
517 tcg_gen_mov_tl(env_pc
, pc_false
);
518 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
519 tcg_gen_mov_tl(env_pc
, pc_true
);
523 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
525 TranslationBlock
*tb
;
527 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
529 tcg_gen_movi_tl(env_pc
, dest
);
530 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
532 tcg_gen_movi_tl(env_pc
, dest
);
537 static inline void cris_clear_x_flag(DisasContext
*dc
)
539 if (dc
->flagx_known
&& dc
->flags_x
) {
540 dc
->flags_uptodate
= 0;
547 static void cris_flush_cc_state(DisasContext
*dc
)
549 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
550 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
551 dc
->cc_size_uptodate
= dc
->cc_size
;
553 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
554 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
557 static void cris_evaluate_flags(DisasContext
*dc
)
559 if (dc
->flags_uptodate
) {
563 cris_flush_cc_state(dc
);
567 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
568 cpu_PR
[PR_CCS
], cc_src
,
572 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
573 cpu_PR
[PR_CCS
], cc_result
,
577 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
578 cpu_PR
[PR_CCS
], cc_result
,
588 switch (dc
->cc_size
) {
590 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
591 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
594 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
595 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
598 gen_helper_evaluate_flags(cpu_env
);
607 if (dc
->cc_size
== 4) {
608 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
609 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
611 gen_helper_evaluate_flags(cpu_env
);
616 switch (dc
->cc_size
) {
618 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
619 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
622 gen_helper_evaluate_flags(cpu_env
);
628 if (dc
->flagx_known
) {
630 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
631 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
632 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
635 dc
->flags_uptodate
= 1;
638 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
647 /* Check if we need to evaluate the condition codes due to
649 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
651 /* TODO: optimize this case. It trigs all the time. */
652 cris_evaluate_flags(dc
);
658 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
662 dc
->flags_uptodate
= 0;
665 static inline void cris_update_cc_x(DisasContext
*dc
)
667 /* Save the x flag state at the time of the cc snapshot. */
668 if (dc
->flagx_known
) {
669 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
672 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
673 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
675 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
676 dc
->cc_x_uptodate
= 1;
680 /* Update cc prior to executing ALU op. Needs source operands untouched. */
681 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
682 TCGv dst
, TCGv src
, int size
)
685 cris_update_cc_op(dc
, op
, size
);
686 tcg_gen_mov_tl(cc_src
, src
);
694 && op
!= CC_OP_LSL
) {
695 tcg_gen_mov_tl(cc_dest
, dst
);
698 cris_update_cc_x(dc
);
702 /* Update cc after executing ALU op. needs the result. */
703 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
706 tcg_gen_mov_tl(cc_result
, res
);
710 /* Returns one if the write back stage should execute. */
711 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
712 TCGv dst
, TCGv a
, TCGv b
, int size
)
714 /* Emit the ALU insns. */
717 tcg_gen_add_tl(dst
, a
, b
);
718 /* Extended arithmetics. */
719 t_gen_addx_carry(dc
, dst
);
722 tcg_gen_add_tl(dst
, a
, b
);
723 t_gen_add_flag(dst
, 0); /* C_FLAG. */
726 tcg_gen_add_tl(dst
, a
, b
);
727 t_gen_add_flag(dst
, 8); /* R_FLAG. */
730 tcg_gen_sub_tl(dst
, a
, b
);
731 /* Extended arithmetics. */
732 t_gen_subx_carry(dc
, dst
);
735 tcg_gen_mov_tl(dst
, b
);
738 tcg_gen_or_tl(dst
, a
, b
);
741 tcg_gen_and_tl(dst
, a
, b
);
744 tcg_gen_xor_tl(dst
, a
, b
);
747 t_gen_lsl(dst
, a
, b
);
750 t_gen_lsr(dst
, a
, b
);
753 t_gen_asr(dst
, a
, b
);
756 tcg_gen_neg_tl(dst
, b
);
757 /* Extended arithmetics. */
758 t_gen_subx_carry(dc
, dst
);
761 gen_helper_lz(dst
, b
);
764 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
767 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
770 t_gen_cris_dstep(dst
, a
, b
);
773 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
778 l1
= gen_new_label();
779 tcg_gen_mov_tl(dst
, a
);
780 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
781 tcg_gen_mov_tl(dst
, b
);
786 tcg_gen_sub_tl(dst
, a
, b
);
787 /* Extended arithmetics. */
788 t_gen_subx_carry(dc
, dst
);
791 qemu_log("illegal ALU op.\n");
797 tcg_gen_andi_tl(dst
, dst
, 0xff);
798 } else if (size
== 2) {
799 tcg_gen_andi_tl(dst
, dst
, 0xffff);
803 static void cris_alu(DisasContext
*dc
, int op
,
804 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
811 if (op
== CC_OP_CMP
) {
812 tmp
= tcg_temp_new();
814 } else if (size
== 4) {
818 tmp
= tcg_temp_new();
822 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
823 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
824 cris_update_result(dc
, tmp
);
829 tcg_gen_andi_tl(d
, d
, ~0xff);
831 tcg_gen_andi_tl(d
, d
, ~0xffff);
833 tcg_gen_or_tl(d
, d
, tmp
);
835 if (!TCGV_EQUAL(tmp
, d
)) {
840 static int arith_cc(DisasContext
*dc
)
844 case CC_OP_ADDC
: return 1;
845 case CC_OP_ADD
: return 1;
846 case CC_OP_SUB
: return 1;
847 case CC_OP_DSTEP
: return 1;
848 case CC_OP_LSL
: return 1;
849 case CC_OP_LSR
: return 1;
850 case CC_OP_ASR
: return 1;
851 case CC_OP_CMP
: return 1;
852 case CC_OP_NEG
: return 1;
853 case CC_OP_OR
: return 1;
854 case CC_OP_AND
: return 1;
855 case CC_OP_XOR
: return 1;
856 case CC_OP_MULU
: return 1;
857 case CC_OP_MULS
: return 1;
865 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
867 int arith_opt
, move_opt
;
869 /* TODO: optimize more condition codes. */
872 * If the flags are live, we've gotta look into the bits of CCS.
873 * Otherwise, if we just did an arithmetic operation we try to
874 * evaluate the condition code faster.
876 * When this function is done, T0 should be non-zero if the condition
879 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
880 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
883 if ((arith_opt
|| move_opt
)
884 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
885 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
886 cc_result
, tcg_const_tl(0));
888 cris_evaluate_flags(dc
);
890 cpu_PR
[PR_CCS
], Z_FLAG
);
894 if ((arith_opt
|| move_opt
)
895 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
896 tcg_gen_mov_tl(cc
, cc_result
);
898 cris_evaluate_flags(dc
);
899 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
901 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
905 cris_evaluate_flags(dc
);
906 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
909 cris_evaluate_flags(dc
);
910 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
911 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
914 cris_evaluate_flags(dc
);
915 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
918 cris_evaluate_flags(dc
);
919 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
921 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
924 if (arith_opt
|| move_opt
) {
927 if (dc
->cc_size
== 1) {
929 } else if (dc
->cc_size
== 2) {
933 tcg_gen_shri_tl(cc
, cc_result
, bits
);
934 tcg_gen_xori_tl(cc
, cc
, 1);
936 cris_evaluate_flags(dc
);
937 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
939 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
943 if (arith_opt
|| move_opt
) {
946 if (dc
->cc_size
== 1) {
948 } else if (dc
->cc_size
== 2) {
952 tcg_gen_shri_tl(cc
, cc_result
, bits
);
953 tcg_gen_andi_tl(cc
, cc
, 1);
955 cris_evaluate_flags(dc
);
956 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
961 cris_evaluate_flags(dc
);
962 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
966 cris_evaluate_flags(dc
);
970 tmp
= tcg_temp_new();
971 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
973 /* Overlay the C flag on top of the Z. */
974 tcg_gen_shli_tl(cc
, tmp
, 2);
975 tcg_gen_and_tl(cc
, tmp
, cc
);
976 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
982 cris_evaluate_flags(dc
);
983 /* Overlay the V flag on top of the N. */
984 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
987 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
988 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
991 cris_evaluate_flags(dc
);
992 /* Overlay the V flag on top of the N. */
993 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
996 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
999 cris_evaluate_flags(dc
);
1006 /* To avoid a shift we overlay everything on
1008 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1009 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1011 tcg_gen_xori_tl(z
, z
, 2);
1013 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1014 tcg_gen_xori_tl(n
, n
, 2);
1015 tcg_gen_and_tl(cc
, z
, n
);
1016 tcg_gen_andi_tl(cc
, cc
, 2);
1023 cris_evaluate_flags(dc
);
1030 /* To avoid a shift we overlay everything on
1032 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1033 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1035 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1036 tcg_gen_or_tl(cc
, z
, n
);
1037 tcg_gen_andi_tl(cc
, cc
, 2);
1044 cris_evaluate_flags(dc
);
1045 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1048 tcg_gen_movi_tl(cc
, 1);
1056 static void cris_store_direct_jmp(DisasContext
*dc
)
1058 /* Store the direct jmp state into the cpu-state. */
1059 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1060 if (dc
->jmp
== JMP_DIRECT
) {
1061 tcg_gen_movi_tl(env_btaken
, 1);
1063 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1064 dc
->jmp
= JMP_INDIRECT
;
1068 static void cris_prepare_cc_branch (DisasContext
*dc
,
1069 int offset
, int cond
)
1071 /* This helps us re-schedule the micro-code to insns in delay-slots
1072 before the actual jump. */
1073 dc
->delayed_branch
= 2;
1074 dc
->jmp
= JMP_DIRECT_CC
;
1075 dc
->jmp_pc
= dc
->pc
+ offset
;
1077 gen_tst_cc(dc
, env_btaken
, cond
);
1078 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1082 /* jumps, when the dest is in a live reg for example. Direct should be set
1083 when the dest addr is constant to allow tb chaining. */
1084 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1086 /* This helps us re-schedule the micro-code to insns in delay-slots
1087 before the actual jump. */
1088 dc
->delayed_branch
= 2;
1090 if (type
== JMP_INDIRECT
) {
1091 tcg_gen_movi_tl(env_btaken
, 1);
1095 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1097 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1099 /* If we get a fault on a delayslot we must keep the jmp state in
1100 the cpu-state to be able to re-execute the jmp. */
1101 if (dc
->delayed_branch
== 1) {
1102 cris_store_direct_jmp(dc
);
1105 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1108 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1109 unsigned int size
, int sign
)
1111 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1113 /* If we get a fault on a delayslot we must keep the jmp state in
1114 the cpu-state to be able to re-execute the jmp. */
1115 if (dc
->delayed_branch
== 1) {
1116 cris_store_direct_jmp(dc
);
1119 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1120 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1123 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1126 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1128 /* If we get a fault on a delayslot we must keep the jmp state in
1129 the cpu-state to be able to re-execute the jmp. */
1130 if (dc
->delayed_branch
== 1) {
1131 cris_store_direct_jmp(dc
);
1135 /* Conditional writes. We only support the kind were X and P are known
1136 at translation time. */
1137 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1139 cris_evaluate_flags(dc
);
1140 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1144 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1146 if (dc
->flagx_known
&& dc
->flags_x
) {
1147 cris_evaluate_flags(dc
);
1148 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1152 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1155 tcg_gen_ext8s_i32(d
, s
);
1156 } else if (size
== 2) {
1157 tcg_gen_ext16s_i32(d
, s
);
1158 } else if (!TCGV_EQUAL(d
, s
)) {
1159 tcg_gen_mov_tl(d
, s
);
1163 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1166 tcg_gen_ext8u_i32(d
, s
);
1167 } else if (size
== 2) {
1168 tcg_gen_ext16u_i32(d
, s
);
1169 } else if (!TCGV_EQUAL(d
, s
)) {
1170 tcg_gen_mov_tl(d
, s
);
1175 static char memsize_char(int size
)
1178 case 1: return 'b'; break;
1179 case 2: return 'w'; break;
1180 case 4: return 'd'; break;
1188 static inline unsigned int memsize_z(DisasContext
*dc
)
1190 return dc
->zsize
+ 1;
1193 static inline unsigned int memsize_zz(DisasContext
*dc
)
1195 switch (dc
->zzsize
) {
1203 static inline void do_postinc (DisasContext
*dc
, int size
)
1206 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1210 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1211 int size
, int s_ext
, TCGv dst
)
1214 t_gen_sext(dst
, cpu_R
[rs
], size
);
1216 t_gen_zext(dst
, cpu_R
[rs
], size
);
1220 /* Prepare T0 and T1 for a register alu operation.
1221 s_ext decides if the operand1 should be sign-extended or zero-extended when
1223 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1224 int size
, int s_ext
, TCGv dst
, TCGv src
)
1226 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1229 t_gen_sext(dst
, cpu_R
[rd
], size
);
1231 t_gen_zext(dst
, cpu_R
[rd
], size
);
1235 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1236 int s_ext
, int memsize
, TCGv dst
)
1244 is_imm
= rs
== 15 && dc
->postinc
;
1246 /* Load [$rs] onto T1. */
1248 insn_len
= 2 + memsize
;
1253 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1254 tcg_gen_movi_tl(dst
, imm
);
1257 cris_flush_cc_state(dc
);
1258 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1260 t_gen_sext(dst
, dst
, memsize
);
1262 t_gen_zext(dst
, dst
, memsize
);
1268 /* Prepare T0 and T1 for a memory + alu operation.
1269 s_ext decides if the operand1 should be sign-extended or zero-extended when
1271 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1272 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1276 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1277 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1282 static const char *cc_name(int cc
)
1284 static const char *cc_names
[16] = {
1285 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1286 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1289 return cc_names
[cc
];
1293 /* Start of insn decoders. */
1295 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1299 uint32_t cond
= dc
->op2
;
1301 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1302 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1305 offset
|= sign
<< 8;
1306 offset
= sign_extend(offset
, 8);
1308 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1310 /* op2 holds the condition-code. */
1311 cris_cc_mask(dc
, 0);
1312 cris_prepare_cc_branch(dc
, offset
, cond
);
1315 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1319 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1320 imm
= sign_extend(dc
->op1
, 7);
1322 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1323 cris_cc_mask(dc
, 0);
1324 /* Fetch register operand, */
1325 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1329 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1331 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1333 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1335 cris_cc_mask(dc
, CC_MASK_NZVC
);
1337 cris_alu(dc
, CC_OP_ADD
,
1338 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1341 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1345 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1346 imm
= sign_extend(dc
->op1
, 5);
1347 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1349 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1352 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1354 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1356 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1358 cris_cc_mask(dc
, CC_MASK_NZVC
);
1359 cris_alu(dc
, CC_OP_SUB
,
1360 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1363 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1366 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1367 imm
= sign_extend(dc
->op1
, 5);
1369 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1370 cris_cc_mask(dc
, CC_MASK_NZVC
);
1372 cris_alu(dc
, CC_OP_CMP
,
1373 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1376 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1379 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1380 imm
= sign_extend(dc
->op1
, 5);
1382 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1383 cris_cc_mask(dc
, CC_MASK_NZ
);
1385 cris_alu(dc
, CC_OP_AND
,
1386 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1389 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1392 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1393 imm
= sign_extend(dc
->op1
, 5);
1394 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1395 cris_cc_mask(dc
, CC_MASK_NZ
);
1397 cris_alu(dc
, CC_OP_OR
,
1398 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1401 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1403 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1404 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1406 cris_cc_mask(dc
, CC_MASK_NZ
);
1407 cris_evaluate_flags(dc
);
1408 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1409 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1410 cris_alu(dc
, CC_OP_MOVE
,
1411 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1412 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1413 dc
->flags_uptodate
= 1;
1416 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1418 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1419 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1420 cris_cc_mask(dc
, CC_MASK_NZ
);
1422 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1423 cris_alu(dc
, CC_OP_MOVE
,
1425 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1428 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1430 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1431 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1433 cris_cc_mask(dc
, CC_MASK_NZ
);
1435 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1437 cris_alu(dc
, CC_OP_MOVE
,
1439 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1442 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1444 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1445 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1447 cris_cc_mask(dc
, CC_MASK_NZ
);
1449 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1450 cris_alu(dc
, CC_OP_MOVE
,
1452 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1456 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1458 int size
= memsize_zz(dc
);
1460 LOG_DIS("move.%c $r%u, $r%u\n",
1461 memsize_char(size
), dc
->op1
, dc
->op2
);
1463 cris_cc_mask(dc
, CC_MASK_NZ
);
1465 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1466 cris_cc_mask(dc
, CC_MASK_NZ
);
1467 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1468 cris_update_cc_x(dc
);
1469 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1473 t0
= tcg_temp_new();
1474 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1475 cris_alu(dc
, CC_OP_MOVE
,
1477 cpu_R
[dc
->op2
], t0
, size
);
1483 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1487 LOG_DIS("s%s $r%u\n",
1488 cc_name(cond
), dc
->op1
);
1493 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1494 l1
= gen_new_label();
1495 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1496 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1499 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1502 cris_cc_mask(dc
, 0);
1506 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1509 t
[0] = cpu_R
[dc
->op2
];
1510 t
[1] = cpu_R
[dc
->op1
];
1512 t
[0] = tcg_temp_new();
1513 t
[1] = tcg_temp_new();
1517 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1520 tcg_temp_free(t
[0]);
1521 tcg_temp_free(t
[1]);
1525 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1528 int size
= memsize_zz(dc
);
1530 LOG_DIS("and.%c $r%u, $r%u\n",
1531 memsize_char(size
), dc
->op1
, dc
->op2
);
1533 cris_cc_mask(dc
, CC_MASK_NZ
);
1535 cris_alu_alloc_temps(dc
, size
, t
);
1536 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1537 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1538 cris_alu_free_temps(dc
, size
, t
);
1542 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1545 LOG_DIS("lz $r%u, $r%u\n",
1547 cris_cc_mask(dc
, CC_MASK_NZ
);
1548 t0
= tcg_temp_new();
1549 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1550 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1555 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1558 int size
= memsize_zz(dc
);
1560 LOG_DIS("lsl.%c $r%u, $r%u\n",
1561 memsize_char(size
), dc
->op1
, dc
->op2
);
1563 cris_cc_mask(dc
, CC_MASK_NZ
);
1564 cris_alu_alloc_temps(dc
, size
, t
);
1565 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1566 tcg_gen_andi_tl(t
[1], t
[1], 63);
1567 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1568 cris_alu_alloc_temps(dc
, size
, t
);
1572 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1575 int size
= memsize_zz(dc
);
1577 LOG_DIS("lsr.%c $r%u, $r%u\n",
1578 memsize_char(size
), dc
->op1
, dc
->op2
);
1580 cris_cc_mask(dc
, CC_MASK_NZ
);
1581 cris_alu_alloc_temps(dc
, size
, t
);
1582 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1583 tcg_gen_andi_tl(t
[1], t
[1], 63);
1584 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1585 cris_alu_free_temps(dc
, size
, t
);
1589 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1592 int size
= memsize_zz(dc
);
1594 LOG_DIS("asr.%c $r%u, $r%u\n",
1595 memsize_char(size
), dc
->op1
, dc
->op2
);
1597 cris_cc_mask(dc
, CC_MASK_NZ
);
1598 cris_alu_alloc_temps(dc
, size
, t
);
1599 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1600 tcg_gen_andi_tl(t
[1], t
[1], 63);
1601 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1602 cris_alu_free_temps(dc
, size
, t
);
1606 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1609 int size
= memsize_zz(dc
);
1611 LOG_DIS("muls.%c $r%u, $r%u\n",
1612 memsize_char(size
), dc
->op1
, dc
->op2
);
1613 cris_cc_mask(dc
, CC_MASK_NZV
);
1614 cris_alu_alloc_temps(dc
, size
, t
);
1615 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1617 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1618 cris_alu_free_temps(dc
, size
, t
);
1622 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1625 int size
= memsize_zz(dc
);
1627 LOG_DIS("mulu.%c $r%u, $r%u\n",
1628 memsize_char(size
), dc
->op1
, dc
->op2
);
1629 cris_cc_mask(dc
, CC_MASK_NZV
);
1630 cris_alu_alloc_temps(dc
, size
, t
);
1631 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1633 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1634 cris_alu_alloc_temps(dc
, size
, t
);
1639 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1641 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1642 cris_cc_mask(dc
, CC_MASK_NZ
);
1643 cris_alu(dc
, CC_OP_DSTEP
,
1644 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1648 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1651 int size
= memsize_zz(dc
);
1652 LOG_DIS("xor.%c $r%u, $r%u\n",
1653 memsize_char(size
), dc
->op1
, dc
->op2
);
1654 BUG_ON(size
!= 4); /* xor is dword. */
1655 cris_cc_mask(dc
, CC_MASK_NZ
);
1656 cris_alu_alloc_temps(dc
, size
, t
);
1657 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1659 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1660 cris_alu_free_temps(dc
, size
, t
);
1664 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1667 int size
= memsize_zz(dc
);
1668 LOG_DIS("bound.%c $r%u, $r%u\n",
1669 memsize_char(size
), dc
->op1
, dc
->op2
);
1670 cris_cc_mask(dc
, CC_MASK_NZ
);
1671 l0
= tcg_temp_local_new();
1672 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1673 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1678 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1681 int size
= memsize_zz(dc
);
1682 LOG_DIS("cmp.%c $r%u, $r%u\n",
1683 memsize_char(size
), dc
->op1
, dc
->op2
);
1684 cris_cc_mask(dc
, CC_MASK_NZVC
);
1685 cris_alu_alloc_temps(dc
, size
, t
);
1686 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1688 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1689 cris_alu_free_temps(dc
, size
, t
);
1693 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1697 LOG_DIS("abs $r%u, $r%u\n",
1699 cris_cc_mask(dc
, CC_MASK_NZ
);
1701 t0
= tcg_temp_new();
1702 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1703 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1704 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1707 cris_alu(dc
, CC_OP_MOVE
,
1708 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1712 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1715 int size
= memsize_zz(dc
);
1716 LOG_DIS("add.%c $r%u, $r%u\n",
1717 memsize_char(size
), dc
->op1
, dc
->op2
);
1718 cris_cc_mask(dc
, CC_MASK_NZVC
);
1719 cris_alu_alloc_temps(dc
, size
, t
);
1720 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1722 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1723 cris_alu_free_temps(dc
, size
, t
);
1727 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1729 LOG_DIS("addc $r%u, $r%u\n",
1731 cris_evaluate_flags(dc
);
1732 /* Set for this insn. */
1733 dc
->flagx_known
= 1;
1734 dc
->flags_x
= X_FLAG
;
1736 cris_cc_mask(dc
, CC_MASK_NZVC
);
1737 cris_alu(dc
, CC_OP_ADDC
,
1738 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1742 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1744 LOG_DIS("mcp $p%u, $r%u\n",
1746 cris_evaluate_flags(dc
);
1747 cris_cc_mask(dc
, CC_MASK_RNZV
);
1748 cris_alu(dc
, CC_OP_MCP
,
1749 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1754 static char * swapmode_name(int mode
, char *modename
) {
1757 modename
[i
++] = 'n';
1760 modename
[i
++] = 'w';
1763 modename
[i
++] = 'b';
1766 modename
[i
++] = 'r';
1773 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1779 LOG_DIS("swap%s $r%u\n",
1780 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1782 cris_cc_mask(dc
, CC_MASK_NZ
);
1783 t0
= tcg_temp_new();
1784 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1786 tcg_gen_not_tl(t0
, t0
);
1789 t_gen_swapw(t0
, t0
);
1792 t_gen_swapb(t0
, t0
);
1795 t_gen_swapr(t0
, t0
);
1797 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1802 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1805 int size
= memsize_zz(dc
);
1806 LOG_DIS("or.%c $r%u, $r%u\n",
1807 memsize_char(size
), dc
->op1
, dc
->op2
);
1808 cris_cc_mask(dc
, CC_MASK_NZ
);
1809 cris_alu_alloc_temps(dc
, size
, t
);
1810 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1811 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1812 cris_alu_free_temps(dc
, size
, t
);
1816 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1819 LOG_DIS("addi.%c $r%u, $r%u\n",
1820 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1821 cris_cc_mask(dc
, 0);
1822 t0
= tcg_temp_new();
1823 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1824 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1829 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1832 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1833 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1834 cris_cc_mask(dc
, 0);
1835 t0
= tcg_temp_new();
1836 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1837 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1842 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1845 int size
= memsize_zz(dc
);
1846 LOG_DIS("neg.%c $r%u, $r%u\n",
1847 memsize_char(size
), dc
->op1
, dc
->op2
);
1848 cris_cc_mask(dc
, CC_MASK_NZVC
);
1849 cris_alu_alloc_temps(dc
, size
, t
);
1850 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1852 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1853 cris_alu_free_temps(dc
, size
, t
);
1857 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1859 LOG_DIS("btst $r%u, $r%u\n",
1861 cris_cc_mask(dc
, CC_MASK_NZ
);
1862 cris_evaluate_flags(dc
);
1863 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1864 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1865 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1866 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1867 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1868 dc
->flags_uptodate
= 1;
1872 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1875 int size
= memsize_zz(dc
);
1876 LOG_DIS("sub.%c $r%u, $r%u\n",
1877 memsize_char(size
), dc
->op1
, dc
->op2
);
1878 cris_cc_mask(dc
, CC_MASK_NZVC
);
1879 cris_alu_alloc_temps(dc
, size
, t
);
1880 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1881 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1882 cris_alu_free_temps(dc
, size
, t
);
1886 /* Zero extension. From size to dword. */
1887 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1890 int size
= memsize_z(dc
);
1891 LOG_DIS("movu.%c $r%u, $r%u\n",
1895 cris_cc_mask(dc
, CC_MASK_NZ
);
1896 t0
= tcg_temp_new();
1897 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1898 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1903 /* Sign extension. From size to dword. */
1904 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1907 int size
= memsize_z(dc
);
1908 LOG_DIS("movs.%c $r%u, $r%u\n",
1912 cris_cc_mask(dc
, CC_MASK_NZ
);
1913 t0
= tcg_temp_new();
1914 /* Size can only be qi or hi. */
1915 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1916 cris_alu(dc
, CC_OP_MOVE
,
1917 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1922 /* zero extension. From size to dword. */
1923 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1926 int size
= memsize_z(dc
);
1927 LOG_DIS("addu.%c $r%u, $r%u\n",
1931 cris_cc_mask(dc
, CC_MASK_NZVC
);
1932 t0
= tcg_temp_new();
1933 /* Size can only be qi or hi. */
1934 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1935 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1940 /* Sign extension. From size to dword. */
1941 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1944 int size
= memsize_z(dc
);
1945 LOG_DIS("adds.%c $r%u, $r%u\n",
1949 cris_cc_mask(dc
, CC_MASK_NZVC
);
1950 t0
= tcg_temp_new();
1951 /* Size can only be qi or hi. */
1952 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1953 cris_alu(dc
, CC_OP_ADD
,
1954 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1959 /* Zero extension. From size to dword. */
1960 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1963 int size
= memsize_z(dc
);
1964 LOG_DIS("subu.%c $r%u, $r%u\n",
1968 cris_cc_mask(dc
, CC_MASK_NZVC
);
1969 t0
= tcg_temp_new();
1970 /* Size can only be qi or hi. */
1971 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1972 cris_alu(dc
, CC_OP_SUB
,
1973 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1978 /* Sign extension. From size to dword. */
1979 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1982 int size
= memsize_z(dc
);
1983 LOG_DIS("subs.%c $r%u, $r%u\n",
1987 cris_cc_mask(dc
, CC_MASK_NZVC
);
1988 t0
= tcg_temp_new();
1989 /* Size can only be qi or hi. */
1990 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1991 cris_alu(dc
, CC_OP_SUB
,
1992 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1997 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
2000 int set
= (~dc
->opcode
>> 2) & 1;
2003 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2004 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2005 if (set
&& flags
== 0) {
2008 } else if (!set
&& (flags
& 0x20)) {
2011 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2014 /* User space is not allowed to touch these. Silently ignore. */
2015 if (dc
->tb_flags
& U_FLAG
) {
2016 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2019 if (flags
& X_FLAG
) {
2020 dc
->flagx_known
= 1;
2022 dc
->flags_x
= X_FLAG
;
2028 /* Break the TB if any of the SPI flag changes. */
2029 if (flags
& (P_FLAG
| S_FLAG
)) {
2030 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2031 dc
->is_jmp
= DISAS_UPDATE
;
2032 dc
->cpustate_changed
= 1;
2035 /* For the I flag, only act on posedge. */
2036 if ((flags
& I_FLAG
)) {
2037 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2038 dc
->is_jmp
= DISAS_UPDATE
;
2039 dc
->cpustate_changed
= 1;
2043 /* Simply decode the flags. */
2044 cris_evaluate_flags(dc
);
2045 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2046 cris_update_cc_x(dc
);
2047 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2050 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2051 /* Enter user mode. */
2052 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2053 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2054 dc
->cpustate_changed
= 1;
2056 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2058 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2061 dc
->flags_uptodate
= 1;
2066 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2068 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2069 cris_cc_mask(dc
, 0);
2070 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2071 tcg_const_tl(dc
->op1
));
2074 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2076 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2077 cris_cc_mask(dc
, 0);
2078 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2079 tcg_const_tl(dc
->op2
));
2083 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2086 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2087 cris_cc_mask(dc
, 0);
2089 t
[0] = tcg_temp_new();
2090 if (dc
->op2
== PR_CCS
) {
2091 cris_evaluate_flags(dc
);
2092 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2093 if (dc
->tb_flags
& U_FLAG
) {
2094 t
[1] = tcg_temp_new();
2095 /* User space is not allowed to touch all flags. */
2096 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2097 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2098 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2099 tcg_temp_free(t
[1]);
2102 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2105 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2106 if (dc
->op2
== PR_CCS
) {
2107 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2108 dc
->flags_uptodate
= 1;
2110 tcg_temp_free(t
[0]);
2113 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2116 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2117 cris_cc_mask(dc
, 0);
2119 if (dc
->op2
== PR_CCS
) {
2120 cris_evaluate_flags(dc
);
2123 if (dc
->op2
== PR_DZ
) {
2124 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2126 t0
= tcg_temp_new();
2127 t_gen_mov_TN_preg(t0
, dc
->op2
);
2128 cris_alu(dc
, CC_OP_MOVE
,
2129 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2130 preg_sizes
[dc
->op2
]);
2136 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2138 int memsize
= memsize_zz(dc
);
2140 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2141 memsize_char(memsize
),
2142 dc
->op1
, dc
->postinc
? "+]" : "]",
2146 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2147 cris_cc_mask(dc
, CC_MASK_NZ
);
2148 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2149 cris_update_cc_x(dc
);
2150 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2154 t0
= tcg_temp_new();
2155 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2156 cris_cc_mask(dc
, CC_MASK_NZ
);
2157 cris_alu(dc
, CC_OP_MOVE
,
2158 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2161 do_postinc(dc
, memsize
);
2165 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2167 t
[0] = tcg_temp_new();
2168 t
[1] = tcg_temp_new();
2171 static inline void cris_alu_m_free_temps(TCGv
*t
)
2173 tcg_temp_free(t
[0]);
2174 tcg_temp_free(t
[1]);
2177 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2180 int memsize
= memsize_z(dc
);
2182 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2183 memsize_char(memsize
),
2184 dc
->op1
, dc
->postinc
? "+]" : "]",
2187 cris_alu_m_alloc_temps(t
);
2189 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2190 cris_cc_mask(dc
, CC_MASK_NZ
);
2191 cris_alu(dc
, CC_OP_MOVE
,
2192 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2193 do_postinc(dc
, memsize
);
2194 cris_alu_m_free_temps(t
);
2198 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2201 int memsize
= memsize_z(dc
);
2203 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2204 memsize_char(memsize
),
2205 dc
->op1
, dc
->postinc
? "+]" : "]",
2208 cris_alu_m_alloc_temps(t
);
2210 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2211 cris_cc_mask(dc
, CC_MASK_NZVC
);
2212 cris_alu(dc
, CC_OP_ADD
,
2213 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2214 do_postinc(dc
, memsize
);
2215 cris_alu_m_free_temps(t
);
2219 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2222 int memsize
= memsize_z(dc
);
2224 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2225 memsize_char(memsize
),
2226 dc
->op1
, dc
->postinc
? "+]" : "]",
2229 cris_alu_m_alloc_temps(t
);
2231 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2232 cris_cc_mask(dc
, CC_MASK_NZVC
);
2233 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2234 do_postinc(dc
, memsize
);
2235 cris_alu_m_free_temps(t
);
2239 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2242 int memsize
= memsize_z(dc
);
2244 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2245 memsize_char(memsize
),
2246 dc
->op1
, dc
->postinc
? "+]" : "]",
2249 cris_alu_m_alloc_temps(t
);
2251 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2252 cris_cc_mask(dc
, CC_MASK_NZVC
);
2253 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2254 do_postinc(dc
, memsize
);
2255 cris_alu_m_free_temps(t
);
2259 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2262 int memsize
= memsize_z(dc
);
2264 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2265 memsize_char(memsize
),
2266 dc
->op1
, dc
->postinc
? "+]" : "]",
2269 cris_alu_m_alloc_temps(t
);
2271 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2272 cris_cc_mask(dc
, CC_MASK_NZVC
);
2273 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2274 do_postinc(dc
, memsize
);
2275 cris_alu_m_free_temps(t
);
2279 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2282 int memsize
= memsize_z(dc
);
2285 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2286 memsize_char(memsize
),
2287 dc
->op1
, dc
->postinc
? "+]" : "]",
2290 cris_alu_m_alloc_temps(t
);
2291 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2292 cris_cc_mask(dc
, CC_MASK_NZ
);
2293 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2294 do_postinc(dc
, memsize
);
2295 cris_alu_m_free_temps(t
);
2299 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2302 int memsize
= memsize_z(dc
);
2304 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2305 memsize_char(memsize
),
2306 dc
->op1
, dc
->postinc
? "+]" : "]",
2309 cris_alu_m_alloc_temps(t
);
2310 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2311 cris_cc_mask(dc
, CC_MASK_NZVC
);
2312 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2313 do_postinc(dc
, memsize
);
2314 cris_alu_m_free_temps(t
);
2318 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2321 int memsize
= memsize_z(dc
);
2323 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2324 memsize_char(memsize
),
2325 dc
->op1
, dc
->postinc
? "+]" : "]",
2328 cris_alu_m_alloc_temps(t
);
2329 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2330 cris_cc_mask(dc
, CC_MASK_NZVC
);
2331 cris_alu(dc
, CC_OP_CMP
,
2332 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2334 do_postinc(dc
, memsize
);
2335 cris_alu_m_free_temps(t
);
2339 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2342 int memsize
= memsize_zz(dc
);
2344 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2345 memsize_char(memsize
),
2346 dc
->op1
, dc
->postinc
? "+]" : "]",
2349 cris_alu_m_alloc_temps(t
);
2350 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2351 cris_cc_mask(dc
, CC_MASK_NZVC
);
2352 cris_alu(dc
, CC_OP_CMP
,
2353 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2355 do_postinc(dc
, memsize
);
2356 cris_alu_m_free_temps(t
);
2360 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2363 int memsize
= memsize_zz(dc
);
2365 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2366 memsize_char(memsize
),
2367 dc
->op1
, dc
->postinc
? "+]" : "]",
2370 cris_evaluate_flags(dc
);
2372 cris_alu_m_alloc_temps(t
);
2373 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2374 cris_cc_mask(dc
, CC_MASK_NZ
);
2375 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2377 cris_alu(dc
, CC_OP_CMP
,
2378 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2379 do_postinc(dc
, memsize
);
2380 cris_alu_m_free_temps(t
);
2384 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2387 int memsize
= memsize_zz(dc
);
2389 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2390 memsize_char(memsize
),
2391 dc
->op1
, dc
->postinc
? "+]" : "]",
2394 cris_alu_m_alloc_temps(t
);
2395 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2396 cris_cc_mask(dc
, CC_MASK_NZ
);
2397 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2398 do_postinc(dc
, memsize
);
2399 cris_alu_m_free_temps(t
);
2403 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2406 int memsize
= memsize_zz(dc
);
2408 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2409 memsize_char(memsize
),
2410 dc
->op1
, dc
->postinc
? "+]" : "]",
2413 cris_alu_m_alloc_temps(t
);
2414 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2415 cris_cc_mask(dc
, CC_MASK_NZVC
);
2416 cris_alu(dc
, CC_OP_ADD
,
2417 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2418 do_postinc(dc
, memsize
);
2419 cris_alu_m_free_temps(t
);
2423 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2426 int memsize
= memsize_zz(dc
);
2428 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2429 memsize_char(memsize
),
2430 dc
->op1
, dc
->postinc
? "+]" : "]",
2433 cris_alu_m_alloc_temps(t
);
2434 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2435 cris_cc_mask(dc
, 0);
2436 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2437 do_postinc(dc
, memsize
);
2438 cris_alu_m_free_temps(t
);
2442 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2445 int memsize
= memsize_zz(dc
);
2447 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2448 memsize_char(memsize
),
2449 dc
->op1
, dc
->postinc
? "+]" : "]",
2452 l
[0] = tcg_temp_local_new();
2453 l
[1] = tcg_temp_local_new();
2454 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2455 cris_cc_mask(dc
, CC_MASK_NZ
);
2456 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2457 do_postinc(dc
, memsize
);
2458 tcg_temp_free(l
[0]);
2459 tcg_temp_free(l
[1]);
2463 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2467 LOG_DIS("addc [$r%u%s, $r%u\n",
2468 dc
->op1
, dc
->postinc
? "+]" : "]",
2471 cris_evaluate_flags(dc
);
2473 /* Set for this insn. */
2474 dc
->flagx_known
= 1;
2475 dc
->flags_x
= X_FLAG
;
2477 cris_alu_m_alloc_temps(t
);
2478 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2479 cris_cc_mask(dc
, CC_MASK_NZVC
);
2480 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2482 cris_alu_m_free_temps(t
);
2486 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2489 int memsize
= memsize_zz(dc
);
2491 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2492 memsize_char(memsize
),
2493 dc
->op1
, dc
->postinc
? "+]" : "]",
2494 dc
->op2
, dc
->ir
, dc
->zzsize
);
2496 cris_alu_m_alloc_temps(t
);
2497 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2498 cris_cc_mask(dc
, CC_MASK_NZVC
);
2499 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2500 do_postinc(dc
, memsize
);
2501 cris_alu_m_free_temps(t
);
2505 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2508 int memsize
= memsize_zz(dc
);
2510 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2511 memsize_char(memsize
),
2512 dc
->op1
, dc
->postinc
? "+]" : "]",
2515 cris_alu_m_alloc_temps(t
);
2516 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2517 cris_cc_mask(dc
, CC_MASK_NZ
);
2518 cris_alu(dc
, CC_OP_OR
,
2519 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2520 do_postinc(dc
, memsize
);
2521 cris_alu_m_free_temps(t
);
2525 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2528 int memsize
= memsize_zz(dc
);
2531 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2532 memsize_char(memsize
),
2534 dc
->postinc
? "+]" : "]",
2537 cris_alu_m_alloc_temps(t
);
2538 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2539 cris_cc_mask(dc
, 0);
2540 if (dc
->op2
== PR_CCS
) {
2541 cris_evaluate_flags(dc
);
2542 if (dc
->tb_flags
& U_FLAG
) {
2543 /* User space is not allowed to touch all flags. */
2544 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2545 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2546 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2550 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2552 do_postinc(dc
, memsize
);
2553 cris_alu_m_free_temps(t
);
2557 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2562 memsize
= preg_sizes
[dc
->op2
];
2564 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2565 memsize_char(memsize
),
2566 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2568 /* prepare store. Address in T0, value in T1. */
2569 if (dc
->op2
== PR_CCS
) {
2570 cris_evaluate_flags(dc
);
2572 t0
= tcg_temp_new();
2573 t_gen_mov_TN_preg(t0
, dc
->op2
);
2574 cris_flush_cc_state(dc
);
2575 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2578 cris_cc_mask(dc
, 0);
2580 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2585 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2591 int nr
= dc
->op2
+ 1;
2593 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2594 dc
->postinc
? "+]" : "]", dc
->op2
);
2596 addr
= tcg_temp_new();
2597 /* There are probably better ways of doing this. */
2598 cris_flush_cc_state(dc
);
2599 for (i
= 0; i
< (nr
>> 1); i
++) {
2600 tmp
[i
] = tcg_temp_new_i64();
2601 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2602 gen_load64(dc
, tmp
[i
], addr
);
2605 tmp32
= tcg_temp_new_i32();
2606 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2607 gen_load(dc
, tmp32
, addr
, 4, 0);
2611 tcg_temp_free(addr
);
2613 for (i
= 0; i
< (nr
>> 1); i
++) {
2614 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2615 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2616 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2617 tcg_temp_free_i64(tmp
[i
]);
2620 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2621 tcg_temp_free(tmp32
);
2624 /* writeback the updated pointer value. */
2626 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2629 /* gen_load might want to evaluate the previous insns flags. */
2630 cris_cc_mask(dc
, 0);
2634 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2640 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2641 dc
->postinc
? "+]" : "]");
2643 cris_flush_cc_state(dc
);
2645 tmp
= tcg_temp_new();
2646 addr
= tcg_temp_new();
2647 tcg_gen_movi_tl(tmp
, 4);
2648 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2649 for (i
= 0; i
<= dc
->op2
; i
++) {
2650 /* Displace addr. */
2651 /* Perform the store. */
2652 gen_store(dc
, addr
, cpu_R
[i
], 4);
2653 tcg_gen_add_tl(addr
, addr
, tmp
);
2656 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2658 cris_cc_mask(dc
, 0);
2660 tcg_temp_free(addr
);
2664 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2668 memsize
= memsize_zz(dc
);
2670 LOG_DIS("move.%c $r%u, [$r%u]\n",
2671 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2673 /* prepare store. */
2674 cris_flush_cc_state(dc
);
2675 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2678 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2680 cris_cc_mask(dc
, 0);
2684 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2686 LOG_DIS("lapcq %x, $r%u\n",
2687 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2688 cris_cc_mask(dc
, 0);
2689 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2693 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2701 cris_cc_mask(dc
, 0);
2702 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2703 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2707 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2711 /* Jump to special reg. */
2712 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2714 LOG_DIS("jump $p%u\n", dc
->op2
);
2716 if (dc
->op2
== PR_CCS
) {
2717 cris_evaluate_flags(dc
);
2719 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2720 /* rete will often have low bit set to indicate delayslot. */
2721 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2722 cris_cc_mask(dc
, 0);
2723 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2727 /* Jump and save. */
2728 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2730 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2731 cris_cc_mask(dc
, 0);
2732 /* Store the return address in Pd. */
2733 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2737 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2739 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2743 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2747 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2749 LOG_DIS("jas 0x%x\n", imm
);
2750 cris_cc_mask(dc
, 0);
2751 /* Store the return address in Pd. */
2752 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2755 cris_prepare_jmp(dc
, JMP_DIRECT
);
2759 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2763 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2765 LOG_DIS("jasc 0x%x\n", imm
);
2766 cris_cc_mask(dc
, 0);
2767 /* Store the return address in Pd. */
2768 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2771 cris_prepare_jmp(dc
, JMP_DIRECT
);
2775 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2777 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2778 cris_cc_mask(dc
, 0);
2779 /* Store the return address in Pd. */
2780 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2781 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2782 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2786 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2789 uint32_t cond
= dc
->op2
;
2791 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2793 LOG_DIS("b%s %d pc=%x dst=%x\n",
2794 cc_name(cond
), offset
,
2795 dc
->pc
, dc
->pc
+ offset
);
2797 cris_cc_mask(dc
, 0);
2798 /* op2 holds the condition-code. */
2799 cris_prepare_cc_branch(dc
, offset
, cond
);
2803 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2807 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2809 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2810 cris_cc_mask(dc
, 0);
2811 /* Store the return address in Pd. */
2812 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2814 dc
->jmp_pc
= dc
->pc
+ simm
;
2815 cris_prepare_jmp(dc
, JMP_DIRECT
);
2819 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2822 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2824 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2825 cris_cc_mask(dc
, 0);
2826 /* Store the return address in Pd. */
2827 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2829 dc
->jmp_pc
= dc
->pc
+ simm
;
2830 cris_prepare_jmp(dc
, JMP_DIRECT
);
2834 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2836 cris_cc_mask(dc
, 0);
2838 if (dc
->op2
== 15) {
2839 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2840 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2841 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2842 t_gen_raise_exception(EXCP_HLT
);
2846 switch (dc
->op2
& 7) {
2850 cris_evaluate_flags(dc
);
2851 gen_helper_rfe(cpu_env
);
2852 dc
->is_jmp
= DISAS_UPDATE
;
2857 cris_evaluate_flags(dc
);
2858 gen_helper_rfn(cpu_env
);
2859 dc
->is_jmp
= DISAS_UPDATE
;
2862 LOG_DIS("break %d\n", dc
->op1
);
2863 cris_evaluate_flags(dc
);
2865 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2867 /* Breaks start at 16 in the exception vector. */
2868 t_gen_mov_env_TN(trap_vector
,
2869 tcg_const_tl(dc
->op1
+ 16));
2870 t_gen_raise_exception(EXCP_BREAK
);
2871 dc
->is_jmp
= DISAS_UPDATE
;
2874 printf("op2=%x\n", dc
->op2
);
2882 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2887 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2892 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2894 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2895 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2901 static struct decoder_info
{
2906 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2908 /* Order matters here. */
2909 {DEC_MOVEQ
, dec_moveq
},
2910 {DEC_BTSTQ
, dec_btstq
},
2911 {DEC_CMPQ
, dec_cmpq
},
2912 {DEC_ADDOQ
, dec_addoq
},
2913 {DEC_ADDQ
, dec_addq
},
2914 {DEC_SUBQ
, dec_subq
},
2915 {DEC_ANDQ
, dec_andq
},
2917 {DEC_ASRQ
, dec_asrq
},
2918 {DEC_LSLQ
, dec_lslq
},
2919 {DEC_LSRQ
, dec_lsrq
},
2920 {DEC_BCCQ
, dec_bccq
},
2922 {DEC_BCC_IM
, dec_bcc_im
},
2923 {DEC_JAS_IM
, dec_jas_im
},
2924 {DEC_JAS_R
, dec_jas_r
},
2925 {DEC_JASC_IM
, dec_jasc_im
},
2926 {DEC_JASC_R
, dec_jasc_r
},
2927 {DEC_BAS_IM
, dec_bas_im
},
2928 {DEC_BASC_IM
, dec_basc_im
},
2929 {DEC_JUMP_P
, dec_jump_p
},
2930 {DEC_LAPC_IM
, dec_lapc_im
},
2931 {DEC_LAPCQ
, dec_lapcq
},
2933 {DEC_RFE_ETC
, dec_rfe_etc
},
2934 {DEC_ADDC_MR
, dec_addc_mr
},
2936 {DEC_MOVE_MP
, dec_move_mp
},
2937 {DEC_MOVE_PM
, dec_move_pm
},
2938 {DEC_MOVEM_MR
, dec_movem_mr
},
2939 {DEC_MOVEM_RM
, dec_movem_rm
},
2940 {DEC_MOVE_PR
, dec_move_pr
},
2941 {DEC_SCC_R
, dec_scc_r
},
2942 {DEC_SETF
, dec_setclrf
},
2943 {DEC_CLEARF
, dec_setclrf
},
2945 {DEC_MOVE_SR
, dec_move_sr
},
2946 {DEC_MOVE_RP
, dec_move_rp
},
2947 {DEC_SWAP_R
, dec_swap_r
},
2948 {DEC_ABS_R
, dec_abs_r
},
2949 {DEC_LZ_R
, dec_lz_r
},
2950 {DEC_MOVE_RS
, dec_move_rs
},
2951 {DEC_BTST_R
, dec_btst_r
},
2952 {DEC_ADDC_R
, dec_addc_r
},
2954 {DEC_DSTEP_R
, dec_dstep_r
},
2955 {DEC_XOR_R
, dec_xor_r
},
2956 {DEC_MCP_R
, dec_mcp_r
},
2957 {DEC_CMP_R
, dec_cmp_r
},
2959 {DEC_ADDI_R
, dec_addi_r
},
2960 {DEC_ADDI_ACR
, dec_addi_acr
},
2962 {DEC_ADD_R
, dec_add_r
},
2963 {DEC_SUB_R
, dec_sub_r
},
2965 {DEC_ADDU_R
, dec_addu_r
},
2966 {DEC_ADDS_R
, dec_adds_r
},
2967 {DEC_SUBU_R
, dec_subu_r
},
2968 {DEC_SUBS_R
, dec_subs_r
},
2969 {DEC_LSL_R
, dec_lsl_r
},
2971 {DEC_AND_R
, dec_and_r
},
2972 {DEC_OR_R
, dec_or_r
},
2973 {DEC_BOUND_R
, dec_bound_r
},
2974 {DEC_ASR_R
, dec_asr_r
},
2975 {DEC_LSR_R
, dec_lsr_r
},
2977 {DEC_MOVU_R
, dec_movu_r
},
2978 {DEC_MOVS_R
, dec_movs_r
},
2979 {DEC_NEG_R
, dec_neg_r
},
2980 {DEC_MOVE_R
, dec_move_r
},
2982 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2983 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2985 {DEC_MULS_R
, dec_muls_r
},
2986 {DEC_MULU_R
, dec_mulu_r
},
2988 {DEC_ADDU_M
, dec_addu_m
},
2989 {DEC_ADDS_M
, dec_adds_m
},
2990 {DEC_SUBU_M
, dec_subu_m
},
2991 {DEC_SUBS_M
, dec_subs_m
},
2993 {DEC_CMPU_M
, dec_cmpu_m
},
2994 {DEC_CMPS_M
, dec_cmps_m
},
2995 {DEC_MOVU_M
, dec_movu_m
},
2996 {DEC_MOVS_M
, dec_movs_m
},
2998 {DEC_CMP_M
, dec_cmp_m
},
2999 {DEC_ADDO_M
, dec_addo_m
},
3000 {DEC_BOUND_M
, dec_bound_m
},
3001 {DEC_ADD_M
, dec_add_m
},
3002 {DEC_SUB_M
, dec_sub_m
},
3003 {DEC_AND_M
, dec_and_m
},
3004 {DEC_OR_M
, dec_or_m
},
3005 {DEC_MOVE_RM
, dec_move_rm
},
3006 {DEC_TEST_M
, dec_test_m
},
3007 {DEC_MOVE_MR
, dec_move_mr
},
3012 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3017 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3018 tcg_gen_debug_insn_start(dc
->pc
);
3021 /* Load a halfword onto the instruction register. */
3022 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3024 /* Now decode it. */
3025 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3026 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3027 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3028 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3029 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3030 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3032 /* Large switch for all insns. */
3033 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3034 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3035 insn_len
= decinfo
[i
].dec(env
, dc
);
3040 #if !defined(CONFIG_USER_ONLY)
3041 /* Single-stepping ? */
3042 if (dc
->tb_flags
& S_FLAG
) {
3045 l1
= gen_new_label();
3046 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3047 /* We treat SPC as a break with an odd trap vector. */
3048 cris_evaluate_flags(dc
);
3049 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3050 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3051 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3052 t_gen_raise_exception(EXCP_BREAK
);
3059 static void check_breakpoint(CPUCRISState
*env
, DisasContext
*dc
)
3061 CPUState
*cs
= CPU(cris_env_get_cpu(env
));
3064 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
3065 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
3066 if (bp
->pc
== dc
->pc
) {
3067 cris_evaluate_flags(dc
);
3068 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3069 t_gen_raise_exception(EXCP_DEBUG
);
3070 dc
->is_jmp
= DISAS_UPDATE
;
3076 #include "translate_v10.c"
3079 * Delay slots on QEMU/CRIS.
3081 * If an exception hits on a delayslot, the core will let ERP (the Exception
3082 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3083 * to give SW a hint that the exception actually hit on the dslot.
3085 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3086 * the core and any jmp to an odd addresses will mask off that lsb. It is
3087 * simply there to let sw know there was an exception on a dslot.
3089 * When the software returns from an exception, the branch will re-execute.
3090 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3091 * and the branch and delayslot dont share pages.
3093 * The TB contaning the branch insn will set up env->btarget and evaluate
3094 * env->btaken. When the translation loop exits we will note that the branch
3095 * sequence is broken and let env->dslot be the size of the branch insn (those
3098 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3099 * set). It will also expect to have env->dslot setup with the size of the
3100 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3101 * will execute the dslot and take the branch, either to btarget or just one
3104 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3105 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3106 * branch and set lsb). Then env->dslot gets cleared so that the exception
3107 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3108 * masked off and we will reexecute the branch insn.
3112 /* generate intermediate code for basic block 'tb'. */
3114 gen_intermediate_code_internal(CRISCPU
*cpu
, TranslationBlock
*tb
,
3117 CPUState
*cs
= CPU(cpu
);
3118 CPUCRISState
*env
= &cpu
->env
;
3119 uint16_t *gen_opc_end
;
3121 unsigned int insn_len
;
3123 struct DisasContext ctx
;
3124 struct DisasContext
*dc
= &ctx
;
3125 uint32_t next_page_start
;
3130 if (env
->pregs
[PR_VR
] == 32) {
3131 dc
->decoder
= crisv32_decoder
;
3132 dc
->clear_locked_irq
= 0;
3134 dc
->decoder
= crisv10_decoder
;
3135 dc
->clear_locked_irq
= 1;
3138 /* Odd PC indicates that branch is rexecuting due to exception in the
3139 * delayslot, like in real hw.
3141 pc_start
= tb
->pc
& ~1;
3145 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
3147 dc
->is_jmp
= DISAS_NEXT
;
3150 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3151 dc
->flags_uptodate
= 1;
3152 dc
->flagx_known
= 1;
3153 dc
->flags_x
= tb
->flags
& X_FLAG
;
3154 dc
->cc_x_uptodate
= 0;
3157 dc
->clear_prefix
= 0;
3159 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3160 dc
->cc_size_uptodate
= -1;
3162 /* Decode TB flags. */
3163 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3164 | X_FLAG
| PFIX_FLAG
);
3165 dc
->delayed_branch
= !!(tb
->flags
& 7);
3166 if (dc
->delayed_branch
) {
3167 dc
->jmp
= JMP_INDIRECT
;
3169 dc
->jmp
= JMP_NOJMP
;
3172 dc
->cpustate_changed
= 0;
3174 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3176 "srch=%d pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3182 search_pc
, dc
->pc
, dc
->ppc
,
3183 (uint64_t)tb
->flags
,
3184 env
->btarget
, (unsigned)tb
->flags
& 7,
3186 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3187 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3188 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3189 env
->regs
[8], env
->regs
[9],
3190 env
->regs
[10], env
->regs
[11],
3191 env
->regs
[12], env
->regs
[13],
3192 env
->regs
[14], env
->regs
[15]);
3193 qemu_log("--------------\n");
3194 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3197 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3200 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3201 if (max_insns
== 0) {
3202 max_insns
= CF_COUNT_MASK
;
3207 check_breakpoint(env
, dc
);
3210 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3214 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3217 if (dc
->delayed_branch
== 1) {
3218 tcg_ctx
.gen_opc_pc
[lj
] = dc
->ppc
| 1;
3220 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
3222 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3223 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
3227 LOG_DIS("%8.8x:\t", dc
->pc
);
3229 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3234 insn_len
= dc
->decoder(env
, dc
);
3238 cris_clear_x_flag(dc
);
3242 /* Check for delayed branches here. If we do it before
3243 actually generating any host code, the simulator will just
3244 loop doing nothing for on this program location. */
3245 if (dc
->delayed_branch
) {
3246 dc
->delayed_branch
--;
3247 if (dc
->delayed_branch
== 0) {
3248 if (tb
->flags
& 7) {
3249 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3251 if (dc
->cpustate_changed
|| !dc
->flagx_known
3252 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3253 cris_store_direct_jmp(dc
);
3256 if (dc
->clear_locked_irq
) {
3257 dc
->clear_locked_irq
= 0;
3258 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3261 if (dc
->jmp
== JMP_DIRECT_CC
) {
3264 l1
= gen_new_label();
3265 cris_evaluate_flags(dc
);
3267 /* Conditional jmp. */
3268 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3270 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3272 gen_goto_tb(dc
, 0, dc
->pc
);
3273 dc
->is_jmp
= DISAS_TB_JUMP
;
3274 dc
->jmp
= JMP_NOJMP
;
3275 } else if (dc
->jmp
== JMP_DIRECT
) {
3276 cris_evaluate_flags(dc
);
3277 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3278 dc
->is_jmp
= DISAS_TB_JUMP
;
3279 dc
->jmp
= JMP_NOJMP
;
3281 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3282 dc
->is_jmp
= DISAS_JUMP
;
3288 /* If we are rexecuting a branch due to exceptions on
3289 delay slots dont break. */
3290 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3293 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3294 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
3296 && (dc
->pc
< next_page_start
)
3297 && num_insns
< max_insns
);
3299 if (dc
->clear_locked_irq
) {
3300 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3305 if (tb
->cflags
& CF_LAST_IO
)
3307 /* Force an update if the per-tb cpu state has changed. */
3308 if (dc
->is_jmp
== DISAS_NEXT
3309 && (dc
->cpustate_changed
|| !dc
->flagx_known
3310 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3311 dc
->is_jmp
= DISAS_UPDATE
;
3312 tcg_gen_movi_tl(env_pc
, npc
);
3314 /* Broken branch+delayslot sequence. */
3315 if (dc
->delayed_branch
== 1) {
3316 /* Set env->dslot to the size of the branch insn. */
3317 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3318 cris_store_direct_jmp(dc
);
3321 cris_evaluate_flags(dc
);
3323 if (unlikely(cs
->singlestep_enabled
)) {
3324 if (dc
->is_jmp
== DISAS_NEXT
) {
3325 tcg_gen_movi_tl(env_pc
, npc
);
3327 t_gen_raise_exception(EXCP_DEBUG
);
3329 switch (dc
->is_jmp
) {
3331 gen_goto_tb(dc
, 1, npc
);
3336 /* indicate that the hash table must be used
3337 to find the next TB */
3342 /* nothing more to generate */
3346 gen_tb_end(tb
, num_insns
);
3347 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3349 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3352 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3355 tb
->size
= dc
->pc
- pc_start
;
3356 tb
->icount
= num_insns
;
3361 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3362 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
3364 qemu_log("\nisize=%d osize=%td\n",
3365 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
);
3371 void gen_intermediate_code (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3373 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, false);
3376 void gen_intermediate_code_pc (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3378 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, true);
3381 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
3384 CRISCPU
*cpu
= CRIS_CPU(cs
);
3385 CPUCRISState
*env
= &cpu
->env
;
3393 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3394 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3395 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3397 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3400 for (i
= 0; i
< 16; i
++) {
3401 cpu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3402 if ((i
+ 1) % 4 == 0) {
3403 cpu_fprintf(f
, "\n");
3406 cpu_fprintf(f
, "\nspecial regs:\n");
3407 for (i
= 0; i
< 16; i
++) {
3408 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3409 if ((i
+ 1) % 4 == 0) {
3410 cpu_fprintf(f
, "\n");
3413 srs
= env
->pregs
[PR_SRS
];
3414 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3415 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3416 for (i
= 0; i
< 16; i
++) {
3417 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3418 i
, env
->sregs
[srs
][i
]);
3419 if ((i
+ 1) % 4 == 0) {
3420 cpu_fprintf(f
, "\n");
3424 cpu_fprintf(f
, "\n\n");
3428 void cris_initialize_tcg(void)
3432 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3433 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3434 offsetof(CPUCRISState
, cc_x
), "cc_x");
3435 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3436 offsetof(CPUCRISState
, cc_src
), "cc_src");
3437 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3438 offsetof(CPUCRISState
, cc_dest
),
3440 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3441 offsetof(CPUCRISState
, cc_result
),
3443 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3444 offsetof(CPUCRISState
, cc_op
), "cc_op");
3445 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3446 offsetof(CPUCRISState
, cc_size
),
3448 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3449 offsetof(CPUCRISState
, cc_mask
),
3452 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3453 offsetof(CPUCRISState
, pc
),
3455 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3456 offsetof(CPUCRISState
, btarget
),
3458 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3459 offsetof(CPUCRISState
, btaken
),
3461 for (i
= 0; i
< 16; i
++) {
3462 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3463 offsetof(CPUCRISState
, regs
[i
]),
3466 for (i
= 0; i
< 16; i
++) {
3467 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3468 offsetof(CPUCRISState
, pregs
[i
]),
3473 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
, int pc_pos
)
3475 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];