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.1 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"
30 #include "tcg/tcg-op.h"
31 #include "exec/helper-proto.h"
33 #include "exec/cpu_ldst.h"
34 #include "exec/translator.h"
35 #include "crisv32-decode.h"
36 #include "qemu/qemu-print.h"
38 #include "exec/helper-gen.h"
45 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
47 # define LOG_DIS(...) do { } while (0)
51 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
52 #define BUG_ON(x) ({if (x) BUG();})
55 * Target-specific is_jmp field values
57 /* Only pc was modified dynamically */
58 #define DISAS_JUMP DISAS_TARGET_0
59 /* Cpu state was modified dynamically, including pc */
60 #define DISAS_UPDATE DISAS_TARGET_1
61 /* Cpu state was modified dynamically, excluding pc -- use npc */
62 #define DISAS_UPDATE_NEXT DISAS_TARGET_2
63 /* PC update for delayed branch, see cpustate_changed otherwise */
64 #define DISAS_DBRANCH DISAS_TARGET_3
66 /* Used by the decoder. */
67 #define EXTRACT_FIELD(src, start, end) \
68 (((src) >> start) & ((1 << (end - start + 1)) - 1))
70 #define CC_MASK_NZ 0xc
71 #define CC_MASK_NZV 0xe
72 #define CC_MASK_NZVC 0xf
73 #define CC_MASK_RNZV 0x10e
75 static TCGv cpu_R
[16];
76 static TCGv cpu_PR
[16];
80 static TCGv cc_result
;
85 static TCGv env_btaken
;
86 static TCGv env_btarget
;
89 #include "exec/gen-icount.h"
91 /* This is the state at translation time. */
92 typedef struct DisasContext
{
93 DisasContextBase base
;
99 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
104 unsigned int zsize
, zzsize
;
106 unsigned int postinc
;
118 int cc_size_uptodate
; /* -1 invalid or last written value. */
120 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not up-to-date. */
121 int flags_uptodate
; /* Whether or not $ccs is up-to-date. */
124 int clear_x
; /* Clear x after this insn? */
125 int clear_prefix
; /* Clear prefix after this insn? */
126 int clear_locked_irq
; /* Clear the irq lockout. */
127 int cpustate_changed
;
128 unsigned int tb_flags
; /* tb dependent flags. */
132 #define JMP_DIRECT_CC 2
133 #define JMP_INDIRECT 3
134 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
140 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
142 cpu_abort(CPU(dc
->cpu
), "%s:%d pc=%x\n", file
, line
, dc
->pc
);
145 static const char * const regnames_v32
[] =
147 "$r0", "$r1", "$r2", "$r3",
148 "$r4", "$r5", "$r6", "$r7",
149 "$r8", "$r9", "$r10", "$r11",
150 "$r12", "$r13", "$sp", "$acr",
153 static const char * const pregnames_v32
[] =
155 "$bz", "$vr", "$pid", "$srs",
156 "$wz", "$exs", "$eda", "$mof",
157 "$dz", "$ebp", "$erp", "$srp",
158 "$nrp", "$ccs", "$usp", "$spc",
161 /* We need this table to handle preg-moves with implicit width. */
162 static const int preg_sizes
[] = {
173 #define t_gen_mov_TN_env(tn, member) \
174 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
175 #define t_gen_mov_env_TN(member, tn) \
176 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
177 #define t_gen_movi_env_TN(member, c) \
179 TCGv tc = tcg_const_tl(c); \
180 t_gen_mov_env_TN(member, tc); \
184 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
186 assert(r
>= 0 && r
<= 15);
187 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
188 tcg_gen_movi_tl(tn
, 0);
189 } else if (r
== PR_VR
) {
190 tcg_gen_movi_tl(tn
, 32);
192 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
195 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
197 assert(r
>= 0 && r
<= 15);
198 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
200 } else if (r
== PR_SRS
) {
201 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
204 gen_helper_tlb_flush_pid(cpu_env
, tn
);
206 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
207 gen_helper_spc_write(cpu_env
, tn
);
208 } else if (r
== PR_CCS
) {
209 dc
->cpustate_changed
= 1;
211 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
215 /* Sign extend at translation time. */
216 static int sign_extend(unsigned int val
, unsigned int width
)
228 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
229 unsigned int size
, unsigned int sign
)
236 r
= cpu_ldl_code(env
, addr
);
242 r
= cpu_ldsw_code(env
, addr
);
244 r
= cpu_lduw_code(env
, addr
);
251 r
= cpu_ldsb_code(env
, addr
);
253 r
= cpu_ldub_code(env
, addr
);
258 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
264 static void cris_lock_irq(DisasContext
*dc
)
266 dc
->clear_locked_irq
= 0;
267 t_gen_movi_env_TN(locked_irq
, 1);
270 static inline void t_gen_raise_exception(uint32_t index
)
272 TCGv_i32 tmp
= tcg_const_i32(index
);
273 gen_helper_raise_exception(cpu_env
, tmp
);
274 tcg_temp_free_i32(tmp
);
277 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
282 t_31
= tcg_const_tl(31);
283 tcg_gen_shl_tl(d
, a
, b
);
285 tcg_gen_sub_tl(t0
, t_31
, b
);
286 tcg_gen_sar_tl(t0
, t0
, t_31
);
287 tcg_gen_and_tl(t0
, t0
, d
);
288 tcg_gen_xor_tl(d
, d
, t0
);
293 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
298 t_31
= tcg_temp_new();
299 tcg_gen_shr_tl(d
, a
, b
);
301 tcg_gen_movi_tl(t_31
, 31);
302 tcg_gen_sub_tl(t0
, t_31
, b
);
303 tcg_gen_sar_tl(t0
, t0
, t_31
);
304 tcg_gen_and_tl(t0
, t0
, d
);
305 tcg_gen_xor_tl(d
, d
, t0
);
310 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
315 t_31
= tcg_temp_new();
316 tcg_gen_sar_tl(d
, a
, b
);
318 tcg_gen_movi_tl(t_31
, 31);
319 tcg_gen_sub_tl(t0
, t_31
, b
);
320 tcg_gen_sar_tl(t0
, t0
, t_31
);
321 tcg_gen_or_tl(d
, d
, t0
);
326 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
328 TCGv t
= tcg_temp_new();
335 tcg_gen_shli_tl(d
, a
, 1);
336 tcg_gen_sub_tl(t
, d
, b
);
337 tcg_gen_movcond_tl(TCG_COND_GEU
, d
, d
, b
, t
, d
);
341 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
351 tcg_gen_shli_tl(d
, a
, 1);
352 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
353 tcg_gen_sari_tl(t
, t
, 31);
354 tcg_gen_and_tl(t
, t
, b
);
355 tcg_gen_add_tl(d
, d
, t
);
359 /* Extended arithmetics on CRIS. */
360 static inline void t_gen_add_flag(TCGv d
, int flag
)
365 t_gen_mov_TN_preg(c
, PR_CCS
);
366 /* Propagate carry into d. */
367 tcg_gen_andi_tl(c
, c
, 1 << flag
);
369 tcg_gen_shri_tl(c
, c
, flag
);
371 tcg_gen_add_tl(d
, d
, c
);
375 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
378 TCGv c
= tcg_temp_new();
380 t_gen_mov_TN_preg(c
, PR_CCS
);
381 /* C flag is already at bit 0. */
382 tcg_gen_andi_tl(c
, c
, C_FLAG
);
383 tcg_gen_add_tl(d
, d
, c
);
388 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
391 TCGv c
= tcg_temp_new();
393 t_gen_mov_TN_preg(c
, PR_CCS
);
394 /* C flag is already at bit 0. */
395 tcg_gen_andi_tl(c
, c
, C_FLAG
);
396 tcg_gen_sub_tl(d
, d
, c
);
401 /* Swap the two bytes within each half word of the s operand.
402 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
403 static inline void t_gen_swapb(TCGv d
, TCGv s
)
408 org_s
= tcg_temp_new();
410 /* d and s may refer to the same object. */
411 tcg_gen_mov_tl(org_s
, s
);
412 tcg_gen_shli_tl(t
, org_s
, 8);
413 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
414 tcg_gen_shri_tl(t
, org_s
, 8);
415 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
416 tcg_gen_or_tl(d
, d
, t
);
418 tcg_temp_free(org_s
);
421 /* Swap the halfwords of the s operand. */
422 static inline void t_gen_swapw(TCGv d
, TCGv s
)
425 /* d and s refer the same object. */
427 tcg_gen_mov_tl(t
, s
);
428 tcg_gen_shli_tl(d
, t
, 16);
429 tcg_gen_shri_tl(t
, t
, 16);
430 tcg_gen_or_tl(d
, d
, t
);
434 /* Reverse the within each byte.
435 T0 = (((T0 << 7) & 0x80808080) |
436 ((T0 << 5) & 0x40404040) |
437 ((T0 << 3) & 0x20202020) |
438 ((T0 << 1) & 0x10101010) |
439 ((T0 >> 1) & 0x08080808) |
440 ((T0 >> 3) & 0x04040404) |
441 ((T0 >> 5) & 0x02020202) |
442 ((T0 >> 7) & 0x01010101));
444 static void t_gen_swapr(TCGv d
, TCGv s
)
446 static const struct {
447 int shift
; /* LSL when positive, LSR when negative. */
462 /* d and s refer the same object. */
464 org_s
= tcg_temp_new();
465 tcg_gen_mov_tl(org_s
, s
);
467 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
468 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
469 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
470 if (bitrev
[i
].shift
>= 0) {
471 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
473 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
475 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
476 tcg_gen_or_tl(d
, d
, t
);
479 tcg_temp_free(org_s
);
482 static bool use_goto_tb(DisasContext
*dc
, target_ulong dest
)
484 return translator_use_goto_tb(&dc
->base
, dest
);
487 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
489 if (use_goto_tb(dc
, dest
)) {
491 tcg_gen_movi_tl(env_pc
, dest
);
492 tcg_gen_exit_tb(dc
->base
.tb
, n
);
494 tcg_gen_movi_tl(env_pc
, dest
);
495 tcg_gen_lookup_and_goto_ptr();
499 static inline void cris_clear_x_flag(DisasContext
*dc
)
502 dc
->flags_uptodate
= 0;
507 static void cris_flush_cc_state(DisasContext
*dc
)
509 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
510 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
511 dc
->cc_size_uptodate
= dc
->cc_size
;
513 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
514 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
517 static void cris_evaluate_flags(DisasContext
*dc
)
519 if (dc
->flags_uptodate
) {
523 cris_flush_cc_state(dc
);
527 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
528 cpu_PR
[PR_CCS
], cc_src
,
532 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
533 cpu_PR
[PR_CCS
], cc_result
,
537 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
538 cpu_PR
[PR_CCS
], cc_result
,
548 switch (dc
->cc_size
) {
550 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
551 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
554 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
555 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
558 gen_helper_evaluate_flags(cpu_env
);
567 if (dc
->cc_size
== 4) {
568 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
569 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
571 gen_helper_evaluate_flags(cpu_env
);
576 switch (dc
->cc_size
) {
578 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
579 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
582 gen_helper_evaluate_flags(cpu_env
);
589 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
590 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
591 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
593 dc
->flags_uptodate
= 1;
596 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
605 /* Check if we need to evaluate the condition codes due to
607 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
609 /* TODO: optimize this case. It trigs all the time. */
610 cris_evaluate_flags(dc
);
616 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
620 dc
->flags_uptodate
= 0;
623 static inline void cris_update_cc_x(DisasContext
*dc
)
625 /* Save the x flag state at the time of the cc snapshot. */
626 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
629 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
630 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
633 /* Update cc prior to executing ALU op. Needs source operands untouched. */
634 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
635 TCGv dst
, TCGv src
, int size
)
638 cris_update_cc_op(dc
, op
, size
);
639 tcg_gen_mov_tl(cc_src
, src
);
647 && op
!= CC_OP_LSL
) {
648 tcg_gen_mov_tl(cc_dest
, dst
);
651 cris_update_cc_x(dc
);
655 /* Update cc after executing ALU op. needs the result. */
656 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
659 tcg_gen_mov_tl(cc_result
, res
);
663 /* Returns one if the write back stage should execute. */
664 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
665 TCGv dst
, TCGv a
, TCGv b
, int size
)
667 /* Emit the ALU insns. */
670 tcg_gen_add_tl(dst
, a
, b
);
671 /* Extended arithmetics. */
672 t_gen_addx_carry(dc
, dst
);
675 tcg_gen_add_tl(dst
, a
, b
);
676 t_gen_add_flag(dst
, 0); /* C_FLAG. */
679 tcg_gen_add_tl(dst
, a
, b
);
680 t_gen_add_flag(dst
, 8); /* R_FLAG. */
683 tcg_gen_sub_tl(dst
, a
, b
);
684 /* Extended arithmetics. */
685 t_gen_subx_carry(dc
, dst
);
688 tcg_gen_mov_tl(dst
, b
);
691 tcg_gen_or_tl(dst
, a
, b
);
694 tcg_gen_and_tl(dst
, a
, b
);
697 tcg_gen_xor_tl(dst
, a
, b
);
700 t_gen_lsl(dst
, a
, b
);
703 t_gen_lsr(dst
, a
, b
);
706 t_gen_asr(dst
, a
, b
);
709 tcg_gen_neg_tl(dst
, b
);
710 /* Extended arithmetics. */
711 t_gen_subx_carry(dc
, dst
);
714 tcg_gen_clzi_tl(dst
, b
, TARGET_LONG_BITS
);
717 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
720 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
723 t_gen_cris_dstep(dst
, a
, b
);
726 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
729 tcg_gen_movcond_tl(TCG_COND_LEU
, dst
, a
, b
, a
, b
);
732 tcg_gen_sub_tl(dst
, a
, b
);
733 /* Extended arithmetics. */
734 t_gen_subx_carry(dc
, dst
);
737 qemu_log_mask(LOG_GUEST_ERROR
, "illegal ALU op.\n");
743 tcg_gen_andi_tl(dst
, dst
, 0xff);
744 } else if (size
== 2) {
745 tcg_gen_andi_tl(dst
, dst
, 0xffff);
749 static void cris_alu(DisasContext
*dc
, int op
,
750 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
757 if (op
== CC_OP_CMP
) {
758 tmp
= tcg_temp_new();
760 } else if (size
== 4) {
764 tmp
= tcg_temp_new();
768 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
769 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
770 cris_update_result(dc
, tmp
);
775 tcg_gen_andi_tl(d
, d
, ~0xff);
777 tcg_gen_andi_tl(d
, d
, ~0xffff);
779 tcg_gen_or_tl(d
, d
, tmp
);
786 static int arith_cc(DisasContext
*dc
)
790 case CC_OP_ADDC
: return 1;
791 case CC_OP_ADD
: return 1;
792 case CC_OP_SUB
: return 1;
793 case CC_OP_DSTEP
: return 1;
794 case CC_OP_LSL
: return 1;
795 case CC_OP_LSR
: return 1;
796 case CC_OP_ASR
: return 1;
797 case CC_OP_CMP
: return 1;
798 case CC_OP_NEG
: return 1;
799 case CC_OP_OR
: return 1;
800 case CC_OP_AND
: return 1;
801 case CC_OP_XOR
: return 1;
802 case CC_OP_MULU
: return 1;
803 case CC_OP_MULS
: return 1;
811 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
813 int arith_opt
, move_opt
;
815 /* TODO: optimize more condition codes. */
818 * If the flags are live, we've gotta look into the bits of CCS.
819 * Otherwise, if we just did an arithmetic operation we try to
820 * evaluate the condition code faster.
822 * When this function is done, T0 should be non-zero if the condition
825 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
826 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
829 if ((arith_opt
|| move_opt
)
830 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
831 tcg_gen_setcondi_tl(TCG_COND_EQ
, cc
, cc_result
, 0);
833 cris_evaluate_flags(dc
);
835 cpu_PR
[PR_CCS
], Z_FLAG
);
839 if ((arith_opt
|| move_opt
)
840 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
841 tcg_gen_mov_tl(cc
, cc_result
);
843 cris_evaluate_flags(dc
);
844 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
846 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
850 cris_evaluate_flags(dc
);
851 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
854 cris_evaluate_flags(dc
);
855 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
856 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
859 cris_evaluate_flags(dc
);
860 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
863 cris_evaluate_flags(dc
);
864 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
866 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
869 if (arith_opt
|| move_opt
) {
872 if (dc
->cc_size
== 1) {
874 } else if (dc
->cc_size
== 2) {
878 tcg_gen_shri_tl(cc
, cc_result
, bits
);
879 tcg_gen_xori_tl(cc
, cc
, 1);
881 cris_evaluate_flags(dc
);
882 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
884 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
888 if (arith_opt
|| move_opt
) {
891 if (dc
->cc_size
== 1) {
893 } else if (dc
->cc_size
== 2) {
897 tcg_gen_shri_tl(cc
, cc_result
, bits
);
898 tcg_gen_andi_tl(cc
, cc
, 1);
900 cris_evaluate_flags(dc
);
901 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
906 cris_evaluate_flags(dc
);
907 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
911 cris_evaluate_flags(dc
);
915 tmp
= tcg_temp_new();
916 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
918 /* Overlay the C flag on top of the Z. */
919 tcg_gen_shli_tl(cc
, tmp
, 2);
920 tcg_gen_and_tl(cc
, tmp
, cc
);
921 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
927 cris_evaluate_flags(dc
);
928 /* Overlay the V flag on top of the N. */
929 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
932 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
933 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
936 cris_evaluate_flags(dc
);
937 /* Overlay the V flag on top of the N. */
938 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
941 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
944 cris_evaluate_flags(dc
);
951 /* To avoid a shift we overlay everything on
953 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
954 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
956 tcg_gen_xori_tl(z
, z
, 2);
958 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
959 tcg_gen_xori_tl(n
, n
, 2);
960 tcg_gen_and_tl(cc
, z
, n
);
961 tcg_gen_andi_tl(cc
, cc
, 2);
968 cris_evaluate_flags(dc
);
975 /* To avoid a shift we overlay everything on
977 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
978 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
980 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
981 tcg_gen_or_tl(cc
, z
, n
);
982 tcg_gen_andi_tl(cc
, cc
, 2);
989 cris_evaluate_flags(dc
);
990 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
993 tcg_gen_movi_tl(cc
, 1);
1001 static void cris_store_direct_jmp(DisasContext
*dc
)
1003 /* Store the direct jmp state into the cpu-state. */
1004 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1005 if (dc
->jmp
== JMP_DIRECT
) {
1006 tcg_gen_movi_tl(env_btaken
, 1);
1008 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1009 dc
->jmp
= JMP_INDIRECT
;
1013 static void cris_prepare_cc_branch (DisasContext
*dc
,
1014 int offset
, int cond
)
1016 /* This helps us re-schedule the micro-code to insns in delay-slots
1017 before the actual jump. */
1018 dc
->delayed_branch
= 2;
1019 dc
->jmp
= JMP_DIRECT_CC
;
1020 dc
->jmp_pc
= dc
->pc
+ offset
;
1022 gen_tst_cc(dc
, env_btaken
, cond
);
1023 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1027 /* jumps, when the dest is in a live reg for example. Direct should be set
1028 when the dest addr is constant to allow tb chaining. */
1029 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1031 /* This helps us re-schedule the micro-code to insns in delay-slots
1032 before the actual jump. */
1033 dc
->delayed_branch
= 2;
1035 if (type
== JMP_INDIRECT
) {
1036 tcg_gen_movi_tl(env_btaken
, 1);
1040 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1042 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1044 /* If we get a fault on a delayslot we must keep the jmp state in
1045 the cpu-state to be able to re-execute the jmp. */
1046 if (dc
->delayed_branch
== 1) {
1047 cris_store_direct_jmp(dc
);
1050 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1053 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1054 unsigned int size
, int sign
)
1056 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1058 /* If we get a fault on a delayslot we must keep the jmp state in
1059 the cpu-state to be able to re-execute the jmp. */
1060 if (dc
->delayed_branch
== 1) {
1061 cris_store_direct_jmp(dc
);
1064 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1065 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1068 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1071 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1073 /* If we get a fault on a delayslot we must keep the jmp state in
1074 the cpu-state to be able to re-execute the jmp. */
1075 if (dc
->delayed_branch
== 1) {
1076 cris_store_direct_jmp(dc
);
1080 /* Conditional writes. We only support the kind were X and P are known
1081 at translation time. */
1082 if (dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1084 cris_evaluate_flags(dc
);
1085 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1089 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1092 cris_evaluate_flags(dc
);
1093 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1097 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1100 tcg_gen_ext8s_i32(d
, s
);
1101 } else if (size
== 2) {
1102 tcg_gen_ext16s_i32(d
, s
);
1104 tcg_gen_mov_tl(d
, s
);
1108 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1111 tcg_gen_ext8u_i32(d
, s
);
1112 } else if (size
== 2) {
1113 tcg_gen_ext16u_i32(d
, s
);
1115 tcg_gen_mov_tl(d
, s
);
1120 static char memsize_char(int size
)
1132 static inline unsigned int memsize_z(DisasContext
*dc
)
1134 return dc
->zsize
+ 1;
1137 static inline unsigned int memsize_zz(DisasContext
*dc
)
1139 switch (dc
->zzsize
) {
1147 static inline void do_postinc (DisasContext
*dc
, int size
)
1150 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1154 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1155 int size
, int s_ext
, TCGv dst
)
1158 t_gen_sext(dst
, cpu_R
[rs
], size
);
1160 t_gen_zext(dst
, cpu_R
[rs
], size
);
1164 /* Prepare T0 and T1 for a register alu operation.
1165 s_ext decides if the operand1 should be sign-extended or zero-extended when
1167 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1168 int size
, int s_ext
, TCGv dst
, TCGv src
)
1170 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1173 t_gen_sext(dst
, cpu_R
[rd
], size
);
1175 t_gen_zext(dst
, cpu_R
[rd
], size
);
1179 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1180 int s_ext
, int memsize
, TCGv dst
)
1188 is_imm
= rs
== 15 && dc
->postinc
;
1190 /* Load [$rs] onto T1. */
1192 insn_len
= 2 + memsize
;
1197 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1198 tcg_gen_movi_tl(dst
, imm
);
1201 cris_flush_cc_state(dc
);
1202 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1204 t_gen_sext(dst
, dst
, memsize
);
1206 t_gen_zext(dst
, dst
, memsize
);
1212 /* Prepare T0 and T1 for a memory + alu operation.
1213 s_ext decides if the operand1 should be sign-extended or zero-extended when
1215 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1216 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1220 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1221 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1226 static const char *cc_name(int cc
)
1228 static const char * const cc_names
[16] = {
1229 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1230 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1233 return cc_names
[cc
];
1237 /* Start of insn decoders. */
1239 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1243 uint32_t cond
= dc
->op2
;
1245 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1246 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1249 offset
|= sign
<< 8;
1250 offset
= sign_extend(offset
, 8);
1252 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1254 /* op2 holds the condition-code. */
1255 cris_cc_mask(dc
, 0);
1256 cris_prepare_cc_branch(dc
, offset
, cond
);
1259 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1263 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1264 imm
= sign_extend(dc
->op1
, 7);
1266 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1267 cris_cc_mask(dc
, 0);
1268 /* Fetch register operand, */
1269 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1273 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1276 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1278 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1280 cris_cc_mask(dc
, CC_MASK_NZVC
);
1282 c
= tcg_const_tl(dc
->op1
);
1283 cris_alu(dc
, CC_OP_ADD
,
1284 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1288 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1292 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1293 imm
= sign_extend(dc
->op1
, 5);
1294 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1296 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1299 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1302 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1304 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1306 cris_cc_mask(dc
, CC_MASK_NZVC
);
1307 c
= tcg_const_tl(dc
->op1
);
1308 cris_alu(dc
, CC_OP_SUB
,
1309 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1313 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1317 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1318 imm
= sign_extend(dc
->op1
, 5);
1320 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1321 cris_cc_mask(dc
, CC_MASK_NZVC
);
1323 c
= tcg_const_tl(imm
);
1324 cris_alu(dc
, CC_OP_CMP
,
1325 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1329 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1333 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1334 imm
= sign_extend(dc
->op1
, 5);
1336 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1337 cris_cc_mask(dc
, CC_MASK_NZ
);
1339 c
= tcg_const_tl(imm
);
1340 cris_alu(dc
, CC_OP_AND
,
1341 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1345 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1349 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1350 imm
= sign_extend(dc
->op1
, 5);
1351 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1352 cris_cc_mask(dc
, CC_MASK_NZ
);
1354 c
= tcg_const_tl(imm
);
1355 cris_alu(dc
, CC_OP_OR
,
1356 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1360 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1363 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1364 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1366 cris_cc_mask(dc
, CC_MASK_NZ
);
1367 c
= tcg_const_tl(dc
->op1
);
1368 cris_evaluate_flags(dc
);
1369 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1372 cris_alu(dc
, CC_OP_MOVE
,
1373 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1374 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1375 dc
->flags_uptodate
= 1;
1378 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1380 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1381 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1382 cris_cc_mask(dc
, CC_MASK_NZ
);
1384 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1385 cris_alu(dc
, CC_OP_MOVE
,
1387 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1390 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1392 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1393 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1395 cris_cc_mask(dc
, CC_MASK_NZ
);
1397 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1399 cris_alu(dc
, CC_OP_MOVE
,
1401 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1404 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1406 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1407 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1409 cris_cc_mask(dc
, CC_MASK_NZ
);
1411 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1412 cris_alu(dc
, CC_OP_MOVE
,
1414 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1418 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1420 int size
= memsize_zz(dc
);
1422 LOG_DIS("move.%c $r%u, $r%u\n",
1423 memsize_char(size
), dc
->op1
, dc
->op2
);
1425 cris_cc_mask(dc
, CC_MASK_NZ
);
1427 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1428 cris_cc_mask(dc
, CC_MASK_NZ
);
1429 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1430 cris_update_cc_x(dc
);
1431 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1435 t0
= tcg_temp_new();
1436 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1437 cris_alu(dc
, CC_OP_MOVE
,
1439 cpu_R
[dc
->op2
], t0
, size
);
1445 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1449 LOG_DIS("s%s $r%u\n",
1450 cc_name(cond
), dc
->op1
);
1452 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1453 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], 0);
1455 cris_cc_mask(dc
, 0);
1459 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1462 t
[0] = cpu_R
[dc
->op2
];
1463 t
[1] = cpu_R
[dc
->op1
];
1465 t
[0] = tcg_temp_new();
1466 t
[1] = tcg_temp_new();
1470 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1473 tcg_temp_free(t
[0]);
1474 tcg_temp_free(t
[1]);
1478 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1481 int size
= memsize_zz(dc
);
1483 LOG_DIS("and.%c $r%u, $r%u\n",
1484 memsize_char(size
), dc
->op1
, dc
->op2
);
1486 cris_cc_mask(dc
, CC_MASK_NZ
);
1488 cris_alu_alloc_temps(dc
, size
, t
);
1489 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1490 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1491 cris_alu_free_temps(dc
, size
, t
);
1495 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1498 LOG_DIS("lz $r%u, $r%u\n",
1500 cris_cc_mask(dc
, CC_MASK_NZ
);
1501 t0
= tcg_temp_new();
1502 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1503 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1508 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1511 int size
= memsize_zz(dc
);
1513 LOG_DIS("lsl.%c $r%u, $r%u\n",
1514 memsize_char(size
), dc
->op1
, dc
->op2
);
1516 cris_cc_mask(dc
, CC_MASK_NZ
);
1517 cris_alu_alloc_temps(dc
, size
, t
);
1518 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1519 tcg_gen_andi_tl(t
[1], t
[1], 63);
1520 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1521 cris_alu_free_temps(dc
, size
, t
);
1525 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1528 int size
= memsize_zz(dc
);
1530 LOG_DIS("lsr.%c $r%u, $r%u\n",
1531 memsize_char(size
), dc
->op1
, dc
->op2
);
1533 cris_cc_mask(dc
, CC_MASK_NZ
);
1534 cris_alu_alloc_temps(dc
, size
, t
);
1535 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1536 tcg_gen_andi_tl(t
[1], t
[1], 63);
1537 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1538 cris_alu_free_temps(dc
, size
, t
);
1542 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1545 int size
= memsize_zz(dc
);
1547 LOG_DIS("asr.%c $r%u, $r%u\n",
1548 memsize_char(size
), dc
->op1
, dc
->op2
);
1550 cris_cc_mask(dc
, CC_MASK_NZ
);
1551 cris_alu_alloc_temps(dc
, size
, t
);
1552 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1553 tcg_gen_andi_tl(t
[1], t
[1], 63);
1554 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1555 cris_alu_free_temps(dc
, size
, t
);
1559 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1562 int size
= memsize_zz(dc
);
1564 LOG_DIS("muls.%c $r%u, $r%u\n",
1565 memsize_char(size
), dc
->op1
, dc
->op2
);
1566 cris_cc_mask(dc
, CC_MASK_NZV
);
1567 cris_alu_alloc_temps(dc
, size
, t
);
1568 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1570 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1571 cris_alu_free_temps(dc
, size
, t
);
1575 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1578 int size
= memsize_zz(dc
);
1580 LOG_DIS("mulu.%c $r%u, $r%u\n",
1581 memsize_char(size
), dc
->op1
, dc
->op2
);
1582 cris_cc_mask(dc
, CC_MASK_NZV
);
1583 cris_alu_alloc_temps(dc
, size
, t
);
1584 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1586 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1587 cris_alu_free_temps(dc
, size
, t
);
1592 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1594 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1595 cris_cc_mask(dc
, CC_MASK_NZ
);
1596 cris_alu(dc
, CC_OP_DSTEP
,
1597 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1601 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1604 int size
= memsize_zz(dc
);
1605 LOG_DIS("xor.%c $r%u, $r%u\n",
1606 memsize_char(size
), dc
->op1
, dc
->op2
);
1607 BUG_ON(size
!= 4); /* xor is dword. */
1608 cris_cc_mask(dc
, CC_MASK_NZ
);
1609 cris_alu_alloc_temps(dc
, size
, t
);
1610 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1612 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1613 cris_alu_free_temps(dc
, size
, t
);
1617 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1620 int size
= memsize_zz(dc
);
1621 LOG_DIS("bound.%c $r%u, $r%u\n",
1622 memsize_char(size
), dc
->op1
, dc
->op2
);
1623 cris_cc_mask(dc
, CC_MASK_NZ
);
1624 l0
= tcg_temp_local_new();
1625 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1626 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1631 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1634 int size
= memsize_zz(dc
);
1635 LOG_DIS("cmp.%c $r%u, $r%u\n",
1636 memsize_char(size
), dc
->op1
, dc
->op2
);
1637 cris_cc_mask(dc
, CC_MASK_NZVC
);
1638 cris_alu_alloc_temps(dc
, size
, t
);
1639 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1641 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1642 cris_alu_free_temps(dc
, size
, t
);
1646 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1648 LOG_DIS("abs $r%u, $r%u\n",
1650 cris_cc_mask(dc
, CC_MASK_NZ
);
1652 tcg_gen_abs_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
]);
1653 cris_alu(dc
, CC_OP_MOVE
,
1654 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1658 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1661 int size
= memsize_zz(dc
);
1662 LOG_DIS("add.%c $r%u, $r%u\n",
1663 memsize_char(size
), dc
->op1
, dc
->op2
);
1664 cris_cc_mask(dc
, CC_MASK_NZVC
);
1665 cris_alu_alloc_temps(dc
, size
, t
);
1666 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1668 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1669 cris_alu_free_temps(dc
, size
, t
);
1673 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1675 LOG_DIS("addc $r%u, $r%u\n",
1677 cris_evaluate_flags(dc
);
1679 /* Set for this insn. */
1680 dc
->flags_x
= X_FLAG
;
1682 cris_cc_mask(dc
, CC_MASK_NZVC
);
1683 cris_alu(dc
, CC_OP_ADDC
,
1684 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1688 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1690 LOG_DIS("mcp $p%u, $r%u\n",
1692 cris_evaluate_flags(dc
);
1693 cris_cc_mask(dc
, CC_MASK_RNZV
);
1694 cris_alu(dc
, CC_OP_MCP
,
1695 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1700 static char * swapmode_name(int mode
, char *modename
) {
1703 modename
[i
++] = 'n';
1706 modename
[i
++] = 'w';
1709 modename
[i
++] = 'b';
1712 modename
[i
++] = 'r';
1719 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1725 LOG_DIS("swap%s $r%u\n",
1726 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1728 cris_cc_mask(dc
, CC_MASK_NZ
);
1729 t0
= tcg_temp_new();
1730 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1732 tcg_gen_not_tl(t0
, t0
);
1735 t_gen_swapw(t0
, t0
);
1738 t_gen_swapb(t0
, t0
);
1741 t_gen_swapr(t0
, t0
);
1743 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1748 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1751 int size
= memsize_zz(dc
);
1752 LOG_DIS("or.%c $r%u, $r%u\n",
1753 memsize_char(size
), dc
->op1
, dc
->op2
);
1754 cris_cc_mask(dc
, CC_MASK_NZ
);
1755 cris_alu_alloc_temps(dc
, size
, t
);
1756 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1757 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1758 cris_alu_free_temps(dc
, size
, t
);
1762 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1765 LOG_DIS("addi.%c $r%u, $r%u\n",
1766 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1767 cris_cc_mask(dc
, 0);
1768 t0
= tcg_temp_new();
1769 tcg_gen_shli_tl(t0
, cpu_R
[dc
->op2
], dc
->zzsize
);
1770 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1775 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1778 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1779 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1780 cris_cc_mask(dc
, 0);
1781 t0
= tcg_temp_new();
1782 tcg_gen_shli_tl(t0
, cpu_R
[dc
->op2
], dc
->zzsize
);
1783 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1788 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1791 int size
= memsize_zz(dc
);
1792 LOG_DIS("neg.%c $r%u, $r%u\n",
1793 memsize_char(size
), dc
->op1
, dc
->op2
);
1794 cris_cc_mask(dc
, CC_MASK_NZVC
);
1795 cris_alu_alloc_temps(dc
, size
, t
);
1796 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1798 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1799 cris_alu_free_temps(dc
, size
, t
);
1803 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1805 LOG_DIS("btst $r%u, $r%u\n",
1807 cris_cc_mask(dc
, CC_MASK_NZ
);
1808 cris_evaluate_flags(dc
);
1809 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1810 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1811 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1812 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1813 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1814 dc
->flags_uptodate
= 1;
1818 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1821 int size
= memsize_zz(dc
);
1822 LOG_DIS("sub.%c $r%u, $r%u\n",
1823 memsize_char(size
), dc
->op1
, dc
->op2
);
1824 cris_cc_mask(dc
, CC_MASK_NZVC
);
1825 cris_alu_alloc_temps(dc
, size
, t
);
1826 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1827 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1828 cris_alu_free_temps(dc
, size
, t
);
1832 /* Zero extension. From size to dword. */
1833 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1836 int size
= memsize_z(dc
);
1837 LOG_DIS("movu.%c $r%u, $r%u\n",
1841 cris_cc_mask(dc
, CC_MASK_NZ
);
1842 t0
= tcg_temp_new();
1843 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1844 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1849 /* Sign extension. From size to dword. */
1850 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1853 int size
= memsize_z(dc
);
1854 LOG_DIS("movs.%c $r%u, $r%u\n",
1858 cris_cc_mask(dc
, CC_MASK_NZ
);
1859 t0
= tcg_temp_new();
1860 /* Size can only be qi or hi. */
1861 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1862 cris_alu(dc
, CC_OP_MOVE
,
1863 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1868 /* zero extension. From size to dword. */
1869 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1872 int size
= memsize_z(dc
);
1873 LOG_DIS("addu.%c $r%u, $r%u\n",
1877 cris_cc_mask(dc
, CC_MASK_NZVC
);
1878 t0
= tcg_temp_new();
1879 /* Size can only be qi or hi. */
1880 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1881 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1886 /* Sign extension. From size to dword. */
1887 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1890 int size
= memsize_z(dc
);
1891 LOG_DIS("adds.%c $r%u, $r%u\n",
1895 cris_cc_mask(dc
, CC_MASK_NZVC
);
1896 t0
= tcg_temp_new();
1897 /* Size can only be qi or hi. */
1898 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1899 cris_alu(dc
, CC_OP_ADD
,
1900 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1905 /* Zero extension. From size to dword. */
1906 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1909 int size
= memsize_z(dc
);
1910 LOG_DIS("subu.%c $r%u, $r%u\n",
1914 cris_cc_mask(dc
, CC_MASK_NZVC
);
1915 t0
= tcg_temp_new();
1916 /* Size can only be qi or hi. */
1917 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1918 cris_alu(dc
, CC_OP_SUB
,
1919 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1924 /* Sign extension. From size to dword. */
1925 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1928 int size
= memsize_z(dc
);
1929 LOG_DIS("subs.%c $r%u, $r%u\n",
1933 cris_cc_mask(dc
, CC_MASK_NZVC
);
1934 t0
= tcg_temp_new();
1935 /* Size can only be qi or hi. */
1936 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1937 cris_alu(dc
, CC_OP_SUB
,
1938 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1943 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
1946 int set
= (~dc
->opcode
>> 2) & 1;
1949 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1950 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1951 if (set
&& flags
== 0) {
1954 } else if (!set
&& (flags
& 0x20)) {
1957 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
1960 /* User space is not allowed to touch these. Silently ignore. */
1961 if (dc
->tb_flags
& U_FLAG
) {
1962 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
1965 if (flags
& X_FLAG
) {
1967 dc
->flags_x
= X_FLAG
;
1973 /* Break the TB if any of the SPI flag changes. */
1974 if (flags
& (P_FLAG
| S_FLAG
)) {
1975 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
1976 dc
->base
.is_jmp
= DISAS_UPDATE
;
1977 dc
->cpustate_changed
= 1;
1980 /* For the I flag, only act on posedge. */
1981 if ((flags
& I_FLAG
)) {
1982 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
1983 dc
->base
.is_jmp
= DISAS_UPDATE
;
1984 dc
->cpustate_changed
= 1;
1988 /* Simply decode the flags. */
1989 cris_evaluate_flags(dc
);
1990 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1991 cris_update_cc_x(dc
);
1992 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
1995 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
1996 /* Enter user mode. */
1997 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
1998 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
1999 dc
->cpustate_changed
= 1;
2001 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2003 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2006 dc
->flags_uptodate
= 1;
2011 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2014 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2015 c1
= tcg_const_tl(dc
->op1
);
2016 c2
= tcg_const_tl(dc
->op2
);
2017 cris_cc_mask(dc
, 0);
2018 gen_helper_movl_sreg_reg(cpu_env
, c2
, c1
);
2023 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2026 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2027 c1
= tcg_const_tl(dc
->op1
);
2028 c2
= tcg_const_tl(dc
->op2
);
2029 cris_cc_mask(dc
, 0);
2030 gen_helper_movl_reg_sreg(cpu_env
, c1
, c2
);
2036 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2039 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2040 cris_cc_mask(dc
, 0);
2042 t
[0] = tcg_temp_new();
2043 if (dc
->op2
== PR_CCS
) {
2044 cris_evaluate_flags(dc
);
2045 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2046 if (dc
->tb_flags
& U_FLAG
) {
2047 t
[1] = tcg_temp_new();
2048 /* User space is not allowed to touch all flags. */
2049 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2050 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2051 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2052 tcg_temp_free(t
[1]);
2055 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2058 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2059 if (dc
->op2
== PR_CCS
) {
2060 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2061 dc
->flags_uptodate
= 1;
2063 tcg_temp_free(t
[0]);
2066 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2069 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2070 cris_cc_mask(dc
, 0);
2072 if (dc
->op2
== PR_CCS
) {
2073 cris_evaluate_flags(dc
);
2076 if (dc
->op2
== PR_DZ
) {
2077 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2079 t0
= tcg_temp_new();
2080 t_gen_mov_TN_preg(t0
, dc
->op2
);
2081 cris_alu(dc
, CC_OP_MOVE
,
2082 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2083 preg_sizes
[dc
->op2
]);
2089 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2091 int memsize
= memsize_zz(dc
);
2093 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2094 memsize_char(memsize
),
2095 dc
->op1
, dc
->postinc
? "+]" : "]",
2099 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2100 cris_cc_mask(dc
, CC_MASK_NZ
);
2101 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2102 cris_update_cc_x(dc
);
2103 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2107 t0
= tcg_temp_new();
2108 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2109 cris_cc_mask(dc
, CC_MASK_NZ
);
2110 cris_alu(dc
, CC_OP_MOVE
,
2111 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2114 do_postinc(dc
, memsize
);
2118 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2120 t
[0] = tcg_temp_new();
2121 t
[1] = tcg_temp_new();
2124 static inline void cris_alu_m_free_temps(TCGv
*t
)
2126 tcg_temp_free(t
[0]);
2127 tcg_temp_free(t
[1]);
2130 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2133 int memsize
= memsize_z(dc
);
2135 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2136 memsize_char(memsize
),
2137 dc
->op1
, dc
->postinc
? "+]" : "]",
2140 cris_alu_m_alloc_temps(t
);
2142 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2143 cris_cc_mask(dc
, CC_MASK_NZ
);
2144 cris_alu(dc
, CC_OP_MOVE
,
2145 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2146 do_postinc(dc
, memsize
);
2147 cris_alu_m_free_temps(t
);
2151 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2154 int memsize
= memsize_z(dc
);
2156 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2157 memsize_char(memsize
),
2158 dc
->op1
, dc
->postinc
? "+]" : "]",
2161 cris_alu_m_alloc_temps(t
);
2163 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2164 cris_cc_mask(dc
, CC_MASK_NZVC
);
2165 cris_alu(dc
, CC_OP_ADD
,
2166 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2167 do_postinc(dc
, memsize
);
2168 cris_alu_m_free_temps(t
);
2172 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2175 int memsize
= memsize_z(dc
);
2177 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2178 memsize_char(memsize
),
2179 dc
->op1
, dc
->postinc
? "+]" : "]",
2182 cris_alu_m_alloc_temps(t
);
2184 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2185 cris_cc_mask(dc
, CC_MASK_NZVC
);
2186 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2187 do_postinc(dc
, memsize
);
2188 cris_alu_m_free_temps(t
);
2192 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2195 int memsize
= memsize_z(dc
);
2197 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2198 memsize_char(memsize
),
2199 dc
->op1
, dc
->postinc
? "+]" : "]",
2202 cris_alu_m_alloc_temps(t
);
2204 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2205 cris_cc_mask(dc
, CC_MASK_NZVC
);
2206 cris_alu(dc
, CC_OP_SUB
, 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_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2215 int memsize
= memsize_z(dc
);
2217 LOG_DIS("subs.%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_SUB
, 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_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2235 int memsize
= memsize_z(dc
);
2238 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2239 memsize_char(memsize
),
2240 dc
->op1
, dc
->postinc
? "+]" : "]",
2243 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_NZ
);
2246 cris_alu(dc
, CC_OP_MOVE
, 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_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2255 int memsize
= memsize_z(dc
);
2257 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2258 memsize_char(memsize
),
2259 dc
->op1
, dc
->postinc
? "+]" : "]",
2262 cris_alu_m_alloc_temps(t
);
2263 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2264 cris_cc_mask(dc
, CC_MASK_NZVC
);
2265 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2266 do_postinc(dc
, memsize
);
2267 cris_alu_m_free_temps(t
);
2271 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2274 int memsize
= memsize_z(dc
);
2276 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2277 memsize_char(memsize
),
2278 dc
->op1
, dc
->postinc
? "+]" : "]",
2281 cris_alu_m_alloc_temps(t
);
2282 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2283 cris_cc_mask(dc
, CC_MASK_NZVC
);
2284 cris_alu(dc
, CC_OP_CMP
,
2285 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2287 do_postinc(dc
, memsize
);
2288 cris_alu_m_free_temps(t
);
2292 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2295 int memsize
= memsize_zz(dc
);
2297 LOG_DIS("cmp.%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
,
2306 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2308 do_postinc(dc
, memsize
);
2309 cris_alu_m_free_temps(t
);
2313 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2316 int memsize
= memsize_zz(dc
);
2318 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2319 memsize_char(memsize
),
2320 dc
->op1
, dc
->postinc
? "+]" : "]",
2323 cris_evaluate_flags(dc
);
2325 cris_alu_m_alloc_temps(t
);
2326 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2327 cris_cc_mask(dc
, CC_MASK_NZ
);
2328 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2330 c
= tcg_const_tl(0);
2331 cris_alu(dc
, CC_OP_CMP
,
2332 cpu_R
[dc
->op2
], t
[1], c
, memsize_zz(dc
));
2334 do_postinc(dc
, memsize
);
2335 cris_alu_m_free_temps(t
);
2339 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2342 int memsize
= memsize_zz(dc
);
2344 LOG_DIS("and.%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_NZ
);
2352 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2353 do_postinc(dc
, memsize
);
2354 cris_alu_m_free_temps(t
);
2358 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2361 int memsize
= memsize_zz(dc
);
2363 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2364 memsize_char(memsize
),
2365 dc
->op1
, dc
->postinc
? "+]" : "]",
2368 cris_alu_m_alloc_temps(t
);
2369 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2370 cris_cc_mask(dc
, CC_MASK_NZVC
);
2371 cris_alu(dc
, CC_OP_ADD
,
2372 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2373 do_postinc(dc
, memsize
);
2374 cris_alu_m_free_temps(t
);
2378 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2381 int memsize
= memsize_zz(dc
);
2383 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2384 memsize_char(memsize
),
2385 dc
->op1
, dc
->postinc
? "+]" : "]",
2388 cris_alu_m_alloc_temps(t
);
2389 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2390 cris_cc_mask(dc
, 0);
2391 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2392 do_postinc(dc
, memsize
);
2393 cris_alu_m_free_temps(t
);
2397 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2400 int memsize
= memsize_zz(dc
);
2402 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2403 memsize_char(memsize
),
2404 dc
->op1
, dc
->postinc
? "+]" : "]",
2407 l
[0] = tcg_temp_local_new();
2408 l
[1] = tcg_temp_local_new();
2409 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2410 cris_cc_mask(dc
, CC_MASK_NZ
);
2411 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2412 do_postinc(dc
, memsize
);
2413 tcg_temp_free(l
[0]);
2414 tcg_temp_free(l
[1]);
2418 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2422 LOG_DIS("addc [$r%u%s, $r%u\n",
2423 dc
->op1
, dc
->postinc
? "+]" : "]",
2426 cris_evaluate_flags(dc
);
2428 /* Set for this insn. */
2429 dc
->flags_x
= X_FLAG
;
2431 cris_alu_m_alloc_temps(t
);
2432 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2433 cris_cc_mask(dc
, CC_MASK_NZVC
);
2434 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2436 cris_alu_m_free_temps(t
);
2440 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2443 int memsize
= memsize_zz(dc
);
2445 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2446 memsize_char(memsize
),
2447 dc
->op1
, dc
->postinc
? "+]" : "]",
2448 dc
->op2
, dc
->ir
, dc
->zzsize
);
2450 cris_alu_m_alloc_temps(t
);
2451 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2452 cris_cc_mask(dc
, CC_MASK_NZVC
);
2453 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2454 do_postinc(dc
, memsize
);
2455 cris_alu_m_free_temps(t
);
2459 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2462 int memsize
= memsize_zz(dc
);
2464 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2465 memsize_char(memsize
),
2466 dc
->op1
, dc
->postinc
? "+]" : "]",
2469 cris_alu_m_alloc_temps(t
);
2470 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2471 cris_cc_mask(dc
, CC_MASK_NZ
);
2472 cris_alu(dc
, CC_OP_OR
,
2473 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2474 do_postinc(dc
, memsize
);
2475 cris_alu_m_free_temps(t
);
2479 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2482 int memsize
= memsize_zz(dc
);
2485 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2486 memsize_char(memsize
),
2488 dc
->postinc
? "+]" : "]",
2491 cris_alu_m_alloc_temps(t
);
2492 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2493 cris_cc_mask(dc
, 0);
2494 if (dc
->op2
== PR_CCS
) {
2495 cris_evaluate_flags(dc
);
2496 if (dc
->tb_flags
& U_FLAG
) {
2497 /* User space is not allowed to touch all flags. */
2498 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2499 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2500 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2504 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2506 do_postinc(dc
, memsize
);
2507 cris_alu_m_free_temps(t
);
2511 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2516 memsize
= preg_sizes
[dc
->op2
];
2518 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2519 memsize_char(memsize
),
2520 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2522 /* prepare store. Address in T0, value in T1. */
2523 if (dc
->op2
== PR_CCS
) {
2524 cris_evaluate_flags(dc
);
2526 t0
= tcg_temp_new();
2527 t_gen_mov_TN_preg(t0
, dc
->op2
);
2528 cris_flush_cc_state(dc
);
2529 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2532 cris_cc_mask(dc
, 0);
2534 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2539 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2545 int nr
= dc
->op2
+ 1;
2547 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2548 dc
->postinc
? "+]" : "]", dc
->op2
);
2550 addr
= tcg_temp_new();
2551 /* There are probably better ways of doing this. */
2552 cris_flush_cc_state(dc
);
2553 for (i
= 0; i
< (nr
>> 1); i
++) {
2554 tmp
[i
] = tcg_temp_new_i64();
2555 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2556 gen_load64(dc
, tmp
[i
], addr
);
2559 tmp32
= tcg_temp_new_i32();
2560 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2561 gen_load(dc
, tmp32
, addr
, 4, 0);
2565 tcg_temp_free(addr
);
2567 for (i
= 0; i
< (nr
>> 1); i
++) {
2568 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2569 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2570 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2571 tcg_temp_free_i64(tmp
[i
]);
2574 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2575 tcg_temp_free(tmp32
);
2578 /* writeback the updated pointer value. */
2580 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2583 /* gen_load might want to evaluate the previous insns flags. */
2584 cris_cc_mask(dc
, 0);
2588 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2594 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2595 dc
->postinc
? "+]" : "]");
2597 cris_flush_cc_state(dc
);
2599 tmp
= tcg_temp_new();
2600 addr
= tcg_temp_new();
2601 tcg_gen_movi_tl(tmp
, 4);
2602 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2603 for (i
= 0; i
<= dc
->op2
; i
++) {
2604 /* Displace addr. */
2605 /* Perform the store. */
2606 gen_store(dc
, addr
, cpu_R
[i
], 4);
2607 tcg_gen_add_tl(addr
, addr
, tmp
);
2610 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2612 cris_cc_mask(dc
, 0);
2614 tcg_temp_free(addr
);
2618 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2622 memsize
= memsize_zz(dc
);
2624 LOG_DIS("move.%c $r%u, [$r%u]\n",
2625 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2627 /* prepare store. */
2628 cris_flush_cc_state(dc
);
2629 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2632 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2634 cris_cc_mask(dc
, 0);
2638 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2640 LOG_DIS("lapcq %x, $r%u\n",
2641 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2642 cris_cc_mask(dc
, 0);
2643 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2647 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2655 cris_cc_mask(dc
, 0);
2656 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2657 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2661 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2665 /* Jump to special reg. */
2666 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2668 LOG_DIS("jump $p%u\n", dc
->op2
);
2670 if (dc
->op2
== PR_CCS
) {
2671 cris_evaluate_flags(dc
);
2673 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2674 /* rete will often have low bit set to indicate delayslot. */
2675 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2676 cris_cc_mask(dc
, 0);
2677 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2681 /* Jump and save. */
2682 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2685 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2686 cris_cc_mask(dc
, 0);
2687 /* Store the return address in Pd. */
2688 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2692 c
= tcg_const_tl(dc
->pc
+ 4);
2693 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2696 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2700 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2705 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2707 LOG_DIS("jas 0x%x\n", imm
);
2708 cris_cc_mask(dc
, 0);
2709 c
= tcg_const_tl(dc
->pc
+ 8);
2710 /* Store the return address in Pd. */
2711 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2715 cris_prepare_jmp(dc
, JMP_DIRECT
);
2719 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2724 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2726 LOG_DIS("jasc 0x%x\n", imm
);
2727 cris_cc_mask(dc
, 0);
2728 c
= tcg_const_tl(dc
->pc
+ 8 + 4);
2729 /* Store the return address in Pd. */
2730 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2734 cris_prepare_jmp(dc
, JMP_DIRECT
);
2738 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2741 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2742 cris_cc_mask(dc
, 0);
2743 /* Store the return address in Pd. */
2744 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2745 c
= tcg_const_tl(dc
->pc
+ 4 + 4);
2746 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2748 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2752 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2755 uint32_t cond
= dc
->op2
;
2757 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2759 LOG_DIS("b%s %d pc=%x dst=%x\n",
2760 cc_name(cond
), offset
,
2761 dc
->pc
, dc
->pc
+ offset
);
2763 cris_cc_mask(dc
, 0);
2764 /* op2 holds the condition-code. */
2765 cris_prepare_cc_branch(dc
, offset
, cond
);
2769 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2774 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2776 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2777 cris_cc_mask(dc
, 0);
2778 c
= tcg_const_tl(dc
->pc
+ 8);
2779 /* Store the return address in Pd. */
2780 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2783 dc
->jmp_pc
= dc
->pc
+ simm
;
2784 cris_prepare_jmp(dc
, JMP_DIRECT
);
2788 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2792 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2794 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2795 cris_cc_mask(dc
, 0);
2796 c
= tcg_const_tl(dc
->pc
+ 12);
2797 /* Store the return address in Pd. */
2798 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2801 dc
->jmp_pc
= dc
->pc
+ simm
;
2802 cris_prepare_jmp(dc
, JMP_DIRECT
);
2806 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2808 cris_cc_mask(dc
, 0);
2810 if (dc
->op2
== 15) {
2811 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2812 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2813 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2814 t_gen_raise_exception(EXCP_HLT
);
2815 dc
->base
.is_jmp
= DISAS_NORETURN
;
2819 switch (dc
->op2
& 7) {
2823 cris_evaluate_flags(dc
);
2824 gen_helper_rfe(cpu_env
);
2825 dc
->base
.is_jmp
= DISAS_UPDATE
;
2826 dc
->cpustate_changed
= true;
2831 cris_evaluate_flags(dc
);
2832 gen_helper_rfn(cpu_env
);
2833 dc
->base
.is_jmp
= DISAS_UPDATE
;
2834 dc
->cpustate_changed
= true;
2837 LOG_DIS("break %d\n", dc
->op1
);
2838 cris_evaluate_flags(dc
);
2840 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2842 /* Breaks start at 16 in the exception vector. */
2843 t_gen_movi_env_TN(trap_vector
, dc
->op1
+ 16);
2844 t_gen_raise_exception(EXCP_BREAK
);
2845 dc
->base
.is_jmp
= DISAS_NORETURN
;
2848 printf("op2=%x\n", dc
->op2
);
2856 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2861 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2866 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2868 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2869 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2875 static const struct decoder_info
{
2880 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2882 /* Order matters here. */
2883 {DEC_MOVEQ
, dec_moveq
},
2884 {DEC_BTSTQ
, dec_btstq
},
2885 {DEC_CMPQ
, dec_cmpq
},
2886 {DEC_ADDOQ
, dec_addoq
},
2887 {DEC_ADDQ
, dec_addq
},
2888 {DEC_SUBQ
, dec_subq
},
2889 {DEC_ANDQ
, dec_andq
},
2891 {DEC_ASRQ
, dec_asrq
},
2892 {DEC_LSLQ
, dec_lslq
},
2893 {DEC_LSRQ
, dec_lsrq
},
2894 {DEC_BCCQ
, dec_bccq
},
2896 {DEC_BCC_IM
, dec_bcc_im
},
2897 {DEC_JAS_IM
, dec_jas_im
},
2898 {DEC_JAS_R
, dec_jas_r
},
2899 {DEC_JASC_IM
, dec_jasc_im
},
2900 {DEC_JASC_R
, dec_jasc_r
},
2901 {DEC_BAS_IM
, dec_bas_im
},
2902 {DEC_BASC_IM
, dec_basc_im
},
2903 {DEC_JUMP_P
, dec_jump_p
},
2904 {DEC_LAPC_IM
, dec_lapc_im
},
2905 {DEC_LAPCQ
, dec_lapcq
},
2907 {DEC_RFE_ETC
, dec_rfe_etc
},
2908 {DEC_ADDC_MR
, dec_addc_mr
},
2910 {DEC_MOVE_MP
, dec_move_mp
},
2911 {DEC_MOVE_PM
, dec_move_pm
},
2912 {DEC_MOVEM_MR
, dec_movem_mr
},
2913 {DEC_MOVEM_RM
, dec_movem_rm
},
2914 {DEC_MOVE_PR
, dec_move_pr
},
2915 {DEC_SCC_R
, dec_scc_r
},
2916 {DEC_SETF
, dec_setclrf
},
2917 {DEC_CLEARF
, dec_setclrf
},
2919 {DEC_MOVE_SR
, dec_move_sr
},
2920 {DEC_MOVE_RP
, dec_move_rp
},
2921 {DEC_SWAP_R
, dec_swap_r
},
2922 {DEC_ABS_R
, dec_abs_r
},
2923 {DEC_LZ_R
, dec_lz_r
},
2924 {DEC_MOVE_RS
, dec_move_rs
},
2925 {DEC_BTST_R
, dec_btst_r
},
2926 {DEC_ADDC_R
, dec_addc_r
},
2928 {DEC_DSTEP_R
, dec_dstep_r
},
2929 {DEC_XOR_R
, dec_xor_r
},
2930 {DEC_MCP_R
, dec_mcp_r
},
2931 {DEC_CMP_R
, dec_cmp_r
},
2933 {DEC_ADDI_R
, dec_addi_r
},
2934 {DEC_ADDI_ACR
, dec_addi_acr
},
2936 {DEC_ADD_R
, dec_add_r
},
2937 {DEC_SUB_R
, dec_sub_r
},
2939 {DEC_ADDU_R
, dec_addu_r
},
2940 {DEC_ADDS_R
, dec_adds_r
},
2941 {DEC_SUBU_R
, dec_subu_r
},
2942 {DEC_SUBS_R
, dec_subs_r
},
2943 {DEC_LSL_R
, dec_lsl_r
},
2945 {DEC_AND_R
, dec_and_r
},
2946 {DEC_OR_R
, dec_or_r
},
2947 {DEC_BOUND_R
, dec_bound_r
},
2948 {DEC_ASR_R
, dec_asr_r
},
2949 {DEC_LSR_R
, dec_lsr_r
},
2951 {DEC_MOVU_R
, dec_movu_r
},
2952 {DEC_MOVS_R
, dec_movs_r
},
2953 {DEC_NEG_R
, dec_neg_r
},
2954 {DEC_MOVE_R
, dec_move_r
},
2956 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2957 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2959 {DEC_MULS_R
, dec_muls_r
},
2960 {DEC_MULU_R
, dec_mulu_r
},
2962 {DEC_ADDU_M
, dec_addu_m
},
2963 {DEC_ADDS_M
, dec_adds_m
},
2964 {DEC_SUBU_M
, dec_subu_m
},
2965 {DEC_SUBS_M
, dec_subs_m
},
2967 {DEC_CMPU_M
, dec_cmpu_m
},
2968 {DEC_CMPS_M
, dec_cmps_m
},
2969 {DEC_MOVU_M
, dec_movu_m
},
2970 {DEC_MOVS_M
, dec_movs_m
},
2972 {DEC_CMP_M
, dec_cmp_m
},
2973 {DEC_ADDO_M
, dec_addo_m
},
2974 {DEC_BOUND_M
, dec_bound_m
},
2975 {DEC_ADD_M
, dec_add_m
},
2976 {DEC_SUB_M
, dec_sub_m
},
2977 {DEC_AND_M
, dec_and_m
},
2978 {DEC_OR_M
, dec_or_m
},
2979 {DEC_MOVE_RM
, dec_move_rm
},
2980 {DEC_TEST_M
, dec_test_m
},
2981 {DEC_MOVE_MR
, dec_move_mr
},
2986 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
2991 /* Load a halfword onto the instruction register. */
2992 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
2994 /* Now decode it. */
2995 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
2996 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
2997 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
2998 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
2999 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3000 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3002 /* Large switch for all insns. */
3003 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3004 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3005 insn_len
= decinfo
[i
].dec(env
, dc
);
3010 #if !defined(CONFIG_USER_ONLY)
3011 /* Single-stepping ? */
3012 if (dc
->tb_flags
& S_FLAG
) {
3013 TCGLabel
*l1
= gen_new_label();
3014 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3015 /* We treat SPC as a break with an odd trap vector. */
3016 cris_evaluate_flags(dc
);
3017 t_gen_movi_env_TN(trap_vector
, 3);
3018 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3019 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3020 t_gen_raise_exception(EXCP_BREAK
);
3027 #include "translate_v10.c.inc"
3030 * Delay slots on QEMU/CRIS.
3032 * If an exception hits on a delayslot, the core will let ERP (the Exception
3033 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3034 * to give SW a hint that the exception actually hit on the dslot.
3036 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3037 * the core and any jmp to an odd addresses will mask off that lsb. It is
3038 * simply there to let sw know there was an exception on a dslot.
3040 * When the software returns from an exception, the branch will re-execute.
3041 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3042 * and the branch and delayslot don't share pages.
3044 * The TB contaning the branch insn will set up env->btarget and evaluate
3045 * env->btaken. When the translation loop exits we will note that the branch
3046 * sequence is broken and let env->dslot be the size of the branch insn (those
3049 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3050 * set). It will also expect to have env->dslot setup with the size of the
3051 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3052 * will execute the dslot and take the branch, either to btarget or just one
3055 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3056 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3057 * branch and set lsb). Then env->dslot gets cleared so that the exception
3058 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3059 * masked off and we will reexecute the branch insn.
3063 static void cris_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
3065 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3066 CPUCRISState
*env
= cs
->env_ptr
;
3067 uint32_t tb_flags
= dc
->base
.tb
->flags
;
3070 if (env
->pregs
[PR_VR
] == 32) {
3071 dc
->decoder
= crisv32_decoder
;
3072 dc
->clear_locked_irq
= 0;
3074 dc
->decoder
= crisv10_decoder
;
3075 dc
->clear_locked_irq
= 1;
3079 * Odd PC indicates that branch is rexecuting due to exception in the
3080 * delayslot, like in real hw.
3082 pc_start
= dc
->base
.pc_first
& ~1;
3083 dc
->base
.pc_first
= pc_start
;
3084 dc
->base
.pc_next
= pc_start
;
3086 dc
->cpu
= env_archcpu(env
);
3089 dc
->flags_uptodate
= 1;
3090 dc
->flags_x
= tb_flags
& X_FLAG
;
3091 dc
->cc_x_uptodate
= 0;
3094 dc
->clear_prefix
= 0;
3095 dc
->cpustate_changed
= 0;
3097 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3098 dc
->cc_size_uptodate
= -1;
3100 /* Decode TB flags. */
3101 dc
->tb_flags
= tb_flags
& (S_FLAG
| P_FLAG
| U_FLAG
| X_FLAG
| PFIX_FLAG
);
3102 dc
->delayed_branch
= !!(tb_flags
& 7);
3103 if (dc
->delayed_branch
) {
3104 dc
->jmp
= JMP_INDIRECT
;
3106 dc
->jmp
= JMP_NOJMP
;
3110 static void cris_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
3114 static void cris_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
3116 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3118 tcg_gen_insn_start(dc
->delayed_branch
== 1 ? dc
->ppc
| 1 : dc
->pc
);
3121 static void cris_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
3123 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3124 CPUCRISState
*env
= cs
->env_ptr
;
3125 unsigned int insn_len
;
3128 LOG_DIS("%8.8x:\t", dc
->pc
);
3132 insn_len
= dc
->decoder(env
, dc
);
3135 dc
->base
.pc_next
+= insn_len
;
3137 if (dc
->base
.is_jmp
== DISAS_NORETURN
) {
3142 cris_clear_x_flag(dc
);
3146 * All branches are delayed branches, handled immediately below.
3147 * We don't expect to see odd combinations of exit conditions.
3149 assert(dc
->base
.is_jmp
== DISAS_NEXT
|| dc
->cpustate_changed
);
3151 if (dc
->delayed_branch
&& --dc
->delayed_branch
== 0) {
3152 dc
->base
.is_jmp
= DISAS_DBRANCH
;
3156 if (dc
->base
.is_jmp
!= DISAS_NEXT
) {
3160 /* Force an update if the per-tb cpu state has changed. */
3161 if (dc
->cpustate_changed
) {
3162 dc
->base
.is_jmp
= DISAS_UPDATE_NEXT
;
3167 * FIXME: Only the first insn in the TB should cross a page boundary.
3168 * If we can detect the length of the next insn easily, we should.
3169 * In the meantime, simply stop when we do cross.
3171 if ((dc
->pc
^ dc
->base
.pc_first
) & TARGET_PAGE_MASK
) {
3172 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
3176 static void cris_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
3178 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3179 DisasJumpType is_jmp
= dc
->base
.is_jmp
;
3180 target_ulong npc
= dc
->pc
;
3182 if (is_jmp
== DISAS_NORETURN
) {
3183 /* If we have a broken branch+delayslot sequence, it's too late. */
3184 assert(dc
->delayed_branch
!= 1);
3188 if (dc
->clear_locked_irq
) {
3189 t_gen_movi_env_TN(locked_irq
, 0);
3192 /* Broken branch+delayslot sequence. */
3193 if (dc
->delayed_branch
== 1) {
3194 /* Set env->dslot to the size of the branch insn. */
3195 t_gen_movi_env_TN(dslot
, dc
->pc
- dc
->ppc
);
3196 cris_store_direct_jmp(dc
);
3199 cris_evaluate_flags(dc
);
3201 /* Evaluate delayed branch destination and fold to another is_jmp case. */
3202 if (is_jmp
== DISAS_DBRANCH
) {
3203 if (dc
->base
.tb
->flags
& 7) {
3204 t_gen_movi_env_TN(dslot
, 0);
3210 is_jmp
= dc
->cpustate_changed
? DISAS_UPDATE_NEXT
: DISAS_TOO_MANY
;
3215 * Use a conditional branch if either taken or not-taken path
3216 * can use goto_tb. If neither can, then treat it as indirect.
3218 if (likely(!dc
->cpustate_changed
)
3219 && (use_goto_tb(dc
, dc
->jmp_pc
) || use_goto_tb(dc
, npc
))) {
3220 TCGLabel
*not_taken
= gen_new_label();
3222 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, not_taken
);
3223 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3224 gen_set_label(not_taken
);
3226 /* not-taken case handled below. */
3227 is_jmp
= DISAS_TOO_MANY
;
3230 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
3234 tcg_gen_movcond_tl(TCG_COND_NE
, env_pc
,
3235 env_btaken
, tcg_constant_tl(0),
3236 env_btarget
, tcg_constant_tl(npc
));
3237 is_jmp
= dc
->cpustate_changed
? DISAS_UPDATE
: DISAS_JUMP
;
3240 * We have now consumed btaken and btarget. Hint to the
3241 * tcg compiler that the writeback to env may be dropped.
3243 tcg_gen_discard_tl(env_btaken
);
3244 tcg_gen_discard_tl(env_btarget
);
3248 g_assert_not_reached();
3252 if (unlikely(dc
->base
.singlestep_enabled
)) {
3254 case DISAS_TOO_MANY
:
3255 case DISAS_UPDATE_NEXT
:
3256 tcg_gen_movi_tl(env_pc
, npc
);
3260 t_gen_raise_exception(EXCP_DEBUG
);
3265 g_assert_not_reached();
3269 case DISAS_TOO_MANY
:
3270 gen_goto_tb(dc
, 0, npc
);
3272 case DISAS_UPDATE_NEXT
:
3273 tcg_gen_movi_tl(env_pc
, npc
);
3276 tcg_gen_lookup_and_goto_ptr();
3279 /* Indicate that interupts must be re-evaluated before the next TB. */
3280 tcg_gen_exit_tb(NULL
, 0);
3283 g_assert_not_reached();
3287 static void cris_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cpu
)
3290 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
3291 log_target_disas(cpu
, dcbase
->pc_first
, dcbase
->tb
->size
);
3295 static const TranslatorOps cris_tr_ops
= {
3296 .init_disas_context
= cris_tr_init_disas_context
,
3297 .tb_start
= cris_tr_tb_start
,
3298 .insn_start
= cris_tr_insn_start
,
3299 .translate_insn
= cris_tr_translate_insn
,
3300 .tb_stop
= cris_tr_tb_stop
,
3301 .disas_log
= cris_tr_disas_log
,
3304 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
3307 translator_loop(&cris_tr_ops
, &dc
.base
, cs
, tb
, max_insns
);
3310 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
3312 CRISCPU
*cpu
= CRIS_CPU(cs
);
3313 CPUCRISState
*env
= &cpu
->env
;
3314 const char * const *regnames
;
3315 const char * const *pregnames
;
3321 if (env
->pregs
[PR_VR
] < 32) {
3322 pregnames
= pregnames_v10
;
3323 regnames
= regnames_v10
;
3325 pregnames
= pregnames_v32
;
3326 regnames
= regnames_v32
;
3329 qemu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3330 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3331 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3333 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3336 for (i
= 0; i
< 16; i
++) {
3337 qemu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3338 if ((i
+ 1) % 4 == 0) {
3339 qemu_fprintf(f
, "\n");
3342 qemu_fprintf(f
, "\nspecial regs:\n");
3343 for (i
= 0; i
< 16; i
++) {
3344 qemu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3345 if ((i
+ 1) % 4 == 0) {
3346 qemu_fprintf(f
, "\n");
3349 if (env
->pregs
[PR_VR
] >= 32) {
3350 uint32_t srs
= env
->pregs
[PR_SRS
];
3351 qemu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3352 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3353 for (i
= 0; i
< 16; i
++) {
3354 qemu_fprintf(f
, "s%2.2d=%8.8x ",
3355 i
, env
->sregs
[srs
][i
]);
3356 if ((i
+ 1) % 4 == 0) {
3357 qemu_fprintf(f
, "\n");
3362 qemu_fprintf(f
, "\n\n");
3366 void cris_initialize_tcg(void)
3370 cc_x
= tcg_global_mem_new(cpu_env
,
3371 offsetof(CPUCRISState
, cc_x
), "cc_x");
3372 cc_src
= tcg_global_mem_new(cpu_env
,
3373 offsetof(CPUCRISState
, cc_src
), "cc_src");
3374 cc_dest
= tcg_global_mem_new(cpu_env
,
3375 offsetof(CPUCRISState
, cc_dest
),
3377 cc_result
= tcg_global_mem_new(cpu_env
,
3378 offsetof(CPUCRISState
, cc_result
),
3380 cc_op
= tcg_global_mem_new(cpu_env
,
3381 offsetof(CPUCRISState
, cc_op
), "cc_op");
3382 cc_size
= tcg_global_mem_new(cpu_env
,
3383 offsetof(CPUCRISState
, cc_size
),
3385 cc_mask
= tcg_global_mem_new(cpu_env
,
3386 offsetof(CPUCRISState
, cc_mask
),
3389 env_pc
= tcg_global_mem_new(cpu_env
,
3390 offsetof(CPUCRISState
, pc
),
3392 env_btarget
= tcg_global_mem_new(cpu_env
,
3393 offsetof(CPUCRISState
, btarget
),
3395 env_btaken
= tcg_global_mem_new(cpu_env
,
3396 offsetof(CPUCRISState
, btaken
),
3398 for (i
= 0; i
< 16; i
++) {
3399 cpu_R
[i
] = tcg_global_mem_new(cpu_env
,
3400 offsetof(CPUCRISState
, regs
[i
]),
3403 for (i
= 0; i
< 16; i
++) {
3404 cpu_PR
[i
] = tcg_global_mem_new(cpu_env
,
3405 offsetof(CPUCRISState
, pregs
[i
]),
3410 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
,