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"
40 #include "trace-tcg.h"
46 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
48 # define LOG_DIS(...) do { } while (0)
52 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
53 #define BUG_ON(x) ({if (x) BUG();})
56 * Target-specific is_jmp field values
58 /* Only pc was modified dynamically */
59 #define DISAS_JUMP DISAS_TARGET_0
60 /* Cpu state was modified dynamically, including pc */
61 #define DISAS_UPDATE DISAS_TARGET_1
62 /* Cpu state was modified dynamically, excluding pc -- use npc */
63 #define DISAS_UPDATE_NEXT DISAS_TARGET_2
64 /* PC update for delayed branch, see cpustate_changed otherwise */
65 #define DISAS_DBRANCH DISAS_TARGET_3
67 /* Used by the decoder. */
68 #define EXTRACT_FIELD(src, start, end) \
69 (((src) >> start) & ((1 << (end - start + 1)) - 1))
71 #define CC_MASK_NZ 0xc
72 #define CC_MASK_NZV 0xe
73 #define CC_MASK_NZVC 0xf
74 #define CC_MASK_RNZV 0x10e
76 static TCGv cpu_R
[16];
77 static TCGv cpu_PR
[16];
81 static TCGv cc_result
;
86 static TCGv env_btaken
;
87 static TCGv env_btarget
;
90 #include "exec/gen-icount.h"
92 /* This is the state at translation time. */
93 typedef struct DisasContext
{
94 DisasContextBase base
;
100 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
105 unsigned int zsize
, zzsize
;
107 unsigned int postinc
;
119 int cc_size_uptodate
; /* -1 invalid or last written value. */
121 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not up-to-date. */
122 int flags_uptodate
; /* Whether or not $ccs is up-to-date. */
125 int clear_x
; /* Clear x after this insn? */
126 int clear_prefix
; /* Clear prefix after this insn? */
127 int clear_locked_irq
; /* Clear the irq lockout. */
128 int cpustate_changed
;
129 unsigned int tb_flags
; /* tb dependent flags. */
133 #define JMP_DIRECT_CC 2
134 #define JMP_INDIRECT 3
135 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
141 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
143 cpu_abort(CPU(dc
->cpu
), "%s:%d pc=%x\n", file
, line
, dc
->pc
);
146 static const char * const regnames_v32
[] =
148 "$r0", "$r1", "$r2", "$r3",
149 "$r4", "$r5", "$r6", "$r7",
150 "$r8", "$r9", "$r10", "$r11",
151 "$r12", "$r13", "$sp", "$acr",
154 static const char * const pregnames_v32
[] =
156 "$bz", "$vr", "$pid", "$srs",
157 "$wz", "$exs", "$eda", "$mof",
158 "$dz", "$ebp", "$erp", "$srp",
159 "$nrp", "$ccs", "$usp", "$spc",
162 /* We need this table to handle preg-moves with implicit width. */
163 static const int preg_sizes
[] = {
174 #define t_gen_mov_TN_env(tn, member) \
175 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
176 #define t_gen_mov_env_TN(member, tn) \
177 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
178 #define t_gen_movi_env_TN(member, c) \
180 TCGv tc = tcg_const_tl(c); \
181 t_gen_mov_env_TN(member, tc); \
185 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
187 assert(r
>= 0 && r
<= 15);
188 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
189 tcg_gen_movi_tl(tn
, 0);
190 } else if (r
== PR_VR
) {
191 tcg_gen_movi_tl(tn
, 32);
193 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
196 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
198 assert(r
>= 0 && r
<= 15);
199 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
201 } else if (r
== PR_SRS
) {
202 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
205 gen_helper_tlb_flush_pid(cpu_env
, tn
);
207 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
208 gen_helper_spc_write(cpu_env
, tn
);
209 } else if (r
== PR_CCS
) {
210 dc
->cpustate_changed
= 1;
212 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
216 /* Sign extend at translation time. */
217 static int sign_extend(unsigned int val
, unsigned int width
)
229 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
230 unsigned int size
, unsigned int sign
)
237 r
= cpu_ldl_code(env
, addr
);
243 r
= cpu_ldsw_code(env
, addr
);
245 r
= cpu_lduw_code(env
, addr
);
252 r
= cpu_ldsb_code(env
, addr
);
254 r
= cpu_ldub_code(env
, addr
);
259 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
265 static void cris_lock_irq(DisasContext
*dc
)
267 dc
->clear_locked_irq
= 0;
268 t_gen_movi_env_TN(locked_irq
, 1);
271 static inline void t_gen_raise_exception(uint32_t index
)
273 TCGv_i32 tmp
= tcg_const_i32(index
);
274 gen_helper_raise_exception(cpu_env
, tmp
);
275 tcg_temp_free_i32(tmp
);
278 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
283 t_31
= tcg_const_tl(31);
284 tcg_gen_shl_tl(d
, a
, b
);
286 tcg_gen_sub_tl(t0
, t_31
, b
);
287 tcg_gen_sar_tl(t0
, t0
, t_31
);
288 tcg_gen_and_tl(t0
, t0
, d
);
289 tcg_gen_xor_tl(d
, d
, t0
);
294 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
299 t_31
= tcg_temp_new();
300 tcg_gen_shr_tl(d
, a
, b
);
302 tcg_gen_movi_tl(t_31
, 31);
303 tcg_gen_sub_tl(t0
, t_31
, b
);
304 tcg_gen_sar_tl(t0
, t0
, t_31
);
305 tcg_gen_and_tl(t0
, t0
, d
);
306 tcg_gen_xor_tl(d
, d
, t0
);
311 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
316 t_31
= tcg_temp_new();
317 tcg_gen_sar_tl(d
, a
, b
);
319 tcg_gen_movi_tl(t_31
, 31);
320 tcg_gen_sub_tl(t0
, t_31
, b
);
321 tcg_gen_sar_tl(t0
, t0
, t_31
);
322 tcg_gen_or_tl(d
, d
, t0
);
327 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
329 TCGv t
= tcg_temp_new();
336 tcg_gen_shli_tl(d
, a
, 1);
337 tcg_gen_sub_tl(t
, d
, b
);
338 tcg_gen_movcond_tl(TCG_COND_GEU
, d
, d
, b
, t
, d
);
342 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
352 tcg_gen_shli_tl(d
, a
, 1);
353 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
354 tcg_gen_sari_tl(t
, t
, 31);
355 tcg_gen_and_tl(t
, t
, b
);
356 tcg_gen_add_tl(d
, d
, t
);
360 /* Extended arithmetics on CRIS. */
361 static inline void t_gen_add_flag(TCGv d
, int flag
)
366 t_gen_mov_TN_preg(c
, PR_CCS
);
367 /* Propagate carry into d. */
368 tcg_gen_andi_tl(c
, c
, 1 << flag
);
370 tcg_gen_shri_tl(c
, c
, flag
);
372 tcg_gen_add_tl(d
, d
, c
);
376 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
379 TCGv c
= tcg_temp_new();
381 t_gen_mov_TN_preg(c
, PR_CCS
);
382 /* C flag is already at bit 0. */
383 tcg_gen_andi_tl(c
, c
, C_FLAG
);
384 tcg_gen_add_tl(d
, d
, c
);
389 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
392 TCGv c
= tcg_temp_new();
394 t_gen_mov_TN_preg(c
, PR_CCS
);
395 /* C flag is already at bit 0. */
396 tcg_gen_andi_tl(c
, c
, C_FLAG
);
397 tcg_gen_sub_tl(d
, d
, c
);
402 /* Swap the two bytes within each half word of the s operand.
403 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
404 static inline void t_gen_swapb(TCGv d
, TCGv s
)
409 org_s
= tcg_temp_new();
411 /* d and s may refer to the same object. */
412 tcg_gen_mov_tl(org_s
, s
);
413 tcg_gen_shli_tl(t
, org_s
, 8);
414 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
415 tcg_gen_shri_tl(t
, org_s
, 8);
416 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
417 tcg_gen_or_tl(d
, d
, t
);
419 tcg_temp_free(org_s
);
422 /* Swap the halfwords of the s operand. */
423 static inline void t_gen_swapw(TCGv d
, TCGv s
)
426 /* d and s refer the same object. */
428 tcg_gen_mov_tl(t
, s
);
429 tcg_gen_shli_tl(d
, t
, 16);
430 tcg_gen_shri_tl(t
, t
, 16);
431 tcg_gen_or_tl(d
, d
, t
);
435 /* Reverse the within each byte.
436 T0 = (((T0 << 7) & 0x80808080) |
437 ((T0 << 5) & 0x40404040) |
438 ((T0 << 3) & 0x20202020) |
439 ((T0 << 1) & 0x10101010) |
440 ((T0 >> 1) & 0x08080808) |
441 ((T0 >> 3) & 0x04040404) |
442 ((T0 >> 5) & 0x02020202) |
443 ((T0 >> 7) & 0x01010101));
445 static void t_gen_swapr(TCGv d
, TCGv s
)
447 static const struct {
448 int shift
; /* LSL when positive, LSR when negative. */
463 /* d and s refer the same object. */
465 org_s
= tcg_temp_new();
466 tcg_gen_mov_tl(org_s
, s
);
468 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
469 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
470 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
471 if (bitrev
[i
].shift
>= 0) {
472 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
474 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
476 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
477 tcg_gen_or_tl(d
, d
, t
);
480 tcg_temp_free(org_s
);
483 static bool use_goto_tb(DisasContext
*dc
, target_ulong dest
)
485 return ((dest
^ dc
->base
.pc_first
) & TARGET_PAGE_MASK
) == 0;
488 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
490 if (use_goto_tb(dc
, dest
)) {
492 tcg_gen_movi_tl(env_pc
, dest
);
493 tcg_gen_exit_tb(dc
->base
.tb
, n
);
495 tcg_gen_movi_tl(env_pc
, dest
);
496 tcg_gen_lookup_and_goto_ptr();
500 static inline void cris_clear_x_flag(DisasContext
*dc
)
503 dc
->flags_uptodate
= 0;
508 static void cris_flush_cc_state(DisasContext
*dc
)
510 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
511 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
512 dc
->cc_size_uptodate
= dc
->cc_size
;
514 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
515 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
518 static void cris_evaluate_flags(DisasContext
*dc
)
520 if (dc
->flags_uptodate
) {
524 cris_flush_cc_state(dc
);
528 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
529 cpu_PR
[PR_CCS
], cc_src
,
533 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
534 cpu_PR
[PR_CCS
], cc_result
,
538 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
539 cpu_PR
[PR_CCS
], cc_result
,
549 switch (dc
->cc_size
) {
551 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
552 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
555 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
556 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
559 gen_helper_evaluate_flags(cpu_env
);
568 if (dc
->cc_size
== 4) {
569 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
570 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
572 gen_helper_evaluate_flags(cpu_env
);
577 switch (dc
->cc_size
) {
579 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
580 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
583 gen_helper_evaluate_flags(cpu_env
);
590 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
591 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
592 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
594 dc
->flags_uptodate
= 1;
597 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
606 /* Check if we need to evaluate the condition codes due to
608 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
610 /* TODO: optimize this case. It trigs all the time. */
611 cris_evaluate_flags(dc
);
617 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
621 dc
->flags_uptodate
= 0;
624 static inline void cris_update_cc_x(DisasContext
*dc
)
626 /* Save the x flag state at the time of the cc snapshot. */
627 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
630 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
631 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
634 /* Update cc prior to executing ALU op. Needs source operands untouched. */
635 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
636 TCGv dst
, TCGv src
, int size
)
639 cris_update_cc_op(dc
, op
, size
);
640 tcg_gen_mov_tl(cc_src
, src
);
648 && op
!= CC_OP_LSL
) {
649 tcg_gen_mov_tl(cc_dest
, dst
);
652 cris_update_cc_x(dc
);
656 /* Update cc after executing ALU op. needs the result. */
657 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
660 tcg_gen_mov_tl(cc_result
, res
);
664 /* Returns one if the write back stage should execute. */
665 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
666 TCGv dst
, TCGv a
, TCGv b
, int size
)
668 /* Emit the ALU insns. */
671 tcg_gen_add_tl(dst
, a
, b
);
672 /* Extended arithmetics. */
673 t_gen_addx_carry(dc
, dst
);
676 tcg_gen_add_tl(dst
, a
, b
);
677 t_gen_add_flag(dst
, 0); /* C_FLAG. */
680 tcg_gen_add_tl(dst
, a
, b
);
681 t_gen_add_flag(dst
, 8); /* R_FLAG. */
684 tcg_gen_sub_tl(dst
, a
, b
);
685 /* Extended arithmetics. */
686 t_gen_subx_carry(dc
, dst
);
689 tcg_gen_mov_tl(dst
, b
);
692 tcg_gen_or_tl(dst
, a
, b
);
695 tcg_gen_and_tl(dst
, a
, b
);
698 tcg_gen_xor_tl(dst
, a
, b
);
701 t_gen_lsl(dst
, a
, b
);
704 t_gen_lsr(dst
, a
, b
);
707 t_gen_asr(dst
, a
, b
);
710 tcg_gen_neg_tl(dst
, b
);
711 /* Extended arithmetics. */
712 t_gen_subx_carry(dc
, dst
);
715 tcg_gen_clzi_tl(dst
, b
, TARGET_LONG_BITS
);
718 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
721 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
724 t_gen_cris_dstep(dst
, a
, b
);
727 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
730 tcg_gen_movcond_tl(TCG_COND_LEU
, dst
, a
, b
, a
, b
);
733 tcg_gen_sub_tl(dst
, a
, b
);
734 /* Extended arithmetics. */
735 t_gen_subx_carry(dc
, dst
);
738 qemu_log_mask(LOG_GUEST_ERROR
, "illegal ALU op.\n");
744 tcg_gen_andi_tl(dst
, dst
, 0xff);
745 } else if (size
== 2) {
746 tcg_gen_andi_tl(dst
, dst
, 0xffff);
750 static void cris_alu(DisasContext
*dc
, int op
,
751 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
758 if (op
== CC_OP_CMP
) {
759 tmp
= tcg_temp_new();
761 } else if (size
== 4) {
765 tmp
= tcg_temp_new();
769 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
770 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
771 cris_update_result(dc
, tmp
);
776 tcg_gen_andi_tl(d
, d
, ~0xff);
778 tcg_gen_andi_tl(d
, d
, ~0xffff);
780 tcg_gen_or_tl(d
, d
, tmp
);
787 static int arith_cc(DisasContext
*dc
)
791 case CC_OP_ADDC
: return 1;
792 case CC_OP_ADD
: return 1;
793 case CC_OP_SUB
: return 1;
794 case CC_OP_DSTEP
: return 1;
795 case CC_OP_LSL
: return 1;
796 case CC_OP_LSR
: return 1;
797 case CC_OP_ASR
: return 1;
798 case CC_OP_CMP
: return 1;
799 case CC_OP_NEG
: return 1;
800 case CC_OP_OR
: return 1;
801 case CC_OP_AND
: return 1;
802 case CC_OP_XOR
: return 1;
803 case CC_OP_MULU
: return 1;
804 case CC_OP_MULS
: return 1;
812 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
814 int arith_opt
, move_opt
;
816 /* TODO: optimize more condition codes. */
819 * If the flags are live, we've gotta look into the bits of CCS.
820 * Otherwise, if we just did an arithmetic operation we try to
821 * evaluate the condition code faster.
823 * When this function is done, T0 should be non-zero if the condition
826 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
827 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
830 if ((arith_opt
|| move_opt
)
831 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
832 tcg_gen_setcondi_tl(TCG_COND_EQ
, cc
, cc_result
, 0);
834 cris_evaluate_flags(dc
);
836 cpu_PR
[PR_CCS
], Z_FLAG
);
840 if ((arith_opt
|| move_opt
)
841 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
842 tcg_gen_mov_tl(cc
, cc_result
);
844 cris_evaluate_flags(dc
);
845 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
847 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
851 cris_evaluate_flags(dc
);
852 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
855 cris_evaluate_flags(dc
);
856 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
857 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
860 cris_evaluate_flags(dc
);
861 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
864 cris_evaluate_flags(dc
);
865 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
867 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
870 if (arith_opt
|| move_opt
) {
873 if (dc
->cc_size
== 1) {
875 } else if (dc
->cc_size
== 2) {
879 tcg_gen_shri_tl(cc
, cc_result
, bits
);
880 tcg_gen_xori_tl(cc
, cc
, 1);
882 cris_evaluate_flags(dc
);
883 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
885 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
889 if (arith_opt
|| move_opt
) {
892 if (dc
->cc_size
== 1) {
894 } else if (dc
->cc_size
== 2) {
898 tcg_gen_shri_tl(cc
, cc_result
, bits
);
899 tcg_gen_andi_tl(cc
, cc
, 1);
901 cris_evaluate_flags(dc
);
902 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
907 cris_evaluate_flags(dc
);
908 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
912 cris_evaluate_flags(dc
);
916 tmp
= tcg_temp_new();
917 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
919 /* Overlay the C flag on top of the Z. */
920 tcg_gen_shli_tl(cc
, tmp
, 2);
921 tcg_gen_and_tl(cc
, tmp
, cc
);
922 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
928 cris_evaluate_flags(dc
);
929 /* Overlay the V flag on top of the N. */
930 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
933 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
934 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
937 cris_evaluate_flags(dc
);
938 /* Overlay the V flag on top of the N. */
939 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
942 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
945 cris_evaluate_flags(dc
);
952 /* To avoid a shift we overlay everything on
954 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
955 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
957 tcg_gen_xori_tl(z
, z
, 2);
959 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
960 tcg_gen_xori_tl(n
, n
, 2);
961 tcg_gen_and_tl(cc
, z
, n
);
962 tcg_gen_andi_tl(cc
, cc
, 2);
969 cris_evaluate_flags(dc
);
976 /* To avoid a shift we overlay everything on
978 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
979 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
981 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
982 tcg_gen_or_tl(cc
, z
, n
);
983 tcg_gen_andi_tl(cc
, cc
, 2);
990 cris_evaluate_flags(dc
);
991 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
994 tcg_gen_movi_tl(cc
, 1);
1002 static void cris_store_direct_jmp(DisasContext
*dc
)
1004 /* Store the direct jmp state into the cpu-state. */
1005 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1006 if (dc
->jmp
== JMP_DIRECT
) {
1007 tcg_gen_movi_tl(env_btaken
, 1);
1009 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1010 dc
->jmp
= JMP_INDIRECT
;
1014 static void cris_prepare_cc_branch (DisasContext
*dc
,
1015 int offset
, int cond
)
1017 /* This helps us re-schedule the micro-code to insns in delay-slots
1018 before the actual jump. */
1019 dc
->delayed_branch
= 2;
1020 dc
->jmp
= JMP_DIRECT_CC
;
1021 dc
->jmp_pc
= dc
->pc
+ offset
;
1023 gen_tst_cc(dc
, env_btaken
, cond
);
1024 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1028 /* jumps, when the dest is in a live reg for example. Direct should be set
1029 when the dest addr is constant to allow tb chaining. */
1030 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1032 /* This helps us re-schedule the micro-code to insns in delay-slots
1033 before the actual jump. */
1034 dc
->delayed_branch
= 2;
1036 if (type
== JMP_INDIRECT
) {
1037 tcg_gen_movi_tl(env_btaken
, 1);
1041 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1043 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1045 /* If we get a fault on a delayslot we must keep the jmp state in
1046 the cpu-state to be able to re-execute the jmp. */
1047 if (dc
->delayed_branch
== 1) {
1048 cris_store_direct_jmp(dc
);
1051 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1054 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1055 unsigned int size
, int sign
)
1057 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1059 /* If we get a fault on a delayslot we must keep the jmp state in
1060 the cpu-state to be able to re-execute the jmp. */
1061 if (dc
->delayed_branch
== 1) {
1062 cris_store_direct_jmp(dc
);
1065 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1066 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1069 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1072 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1074 /* If we get a fault on a delayslot we must keep the jmp state in
1075 the cpu-state to be able to re-execute the jmp. */
1076 if (dc
->delayed_branch
== 1) {
1077 cris_store_direct_jmp(dc
);
1081 /* Conditional writes. We only support the kind were X and P are known
1082 at translation time. */
1083 if (dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1085 cris_evaluate_flags(dc
);
1086 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1090 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1093 cris_evaluate_flags(dc
);
1094 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1098 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1101 tcg_gen_ext8s_i32(d
, s
);
1102 } else if (size
== 2) {
1103 tcg_gen_ext16s_i32(d
, s
);
1105 tcg_gen_mov_tl(d
, s
);
1109 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1112 tcg_gen_ext8u_i32(d
, s
);
1113 } else if (size
== 2) {
1114 tcg_gen_ext16u_i32(d
, s
);
1116 tcg_gen_mov_tl(d
, s
);
1121 static char memsize_char(int size
)
1133 static inline unsigned int memsize_z(DisasContext
*dc
)
1135 return dc
->zsize
+ 1;
1138 static inline unsigned int memsize_zz(DisasContext
*dc
)
1140 switch (dc
->zzsize
) {
1148 static inline void do_postinc (DisasContext
*dc
, int size
)
1151 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1155 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1156 int size
, int s_ext
, TCGv dst
)
1159 t_gen_sext(dst
, cpu_R
[rs
], size
);
1161 t_gen_zext(dst
, cpu_R
[rs
], size
);
1165 /* Prepare T0 and T1 for a register alu operation.
1166 s_ext decides if the operand1 should be sign-extended or zero-extended when
1168 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1169 int size
, int s_ext
, TCGv dst
, TCGv src
)
1171 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1174 t_gen_sext(dst
, cpu_R
[rd
], size
);
1176 t_gen_zext(dst
, cpu_R
[rd
], size
);
1180 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1181 int s_ext
, int memsize
, TCGv dst
)
1189 is_imm
= rs
== 15 && dc
->postinc
;
1191 /* Load [$rs] onto T1. */
1193 insn_len
= 2 + memsize
;
1198 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1199 tcg_gen_movi_tl(dst
, imm
);
1202 cris_flush_cc_state(dc
);
1203 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1205 t_gen_sext(dst
, dst
, memsize
);
1207 t_gen_zext(dst
, dst
, memsize
);
1213 /* Prepare T0 and T1 for a memory + alu operation.
1214 s_ext decides if the operand1 should be sign-extended or zero-extended when
1216 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1217 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1221 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1222 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1227 static const char *cc_name(int cc
)
1229 static const char * const cc_names
[16] = {
1230 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1231 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1234 return cc_names
[cc
];
1238 /* Start of insn decoders. */
1240 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1244 uint32_t cond
= dc
->op2
;
1246 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1247 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1250 offset
|= sign
<< 8;
1251 offset
= sign_extend(offset
, 8);
1253 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1255 /* op2 holds the condition-code. */
1256 cris_cc_mask(dc
, 0);
1257 cris_prepare_cc_branch(dc
, offset
, cond
);
1260 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1264 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1265 imm
= sign_extend(dc
->op1
, 7);
1267 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1268 cris_cc_mask(dc
, 0);
1269 /* Fetch register operand, */
1270 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1274 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1277 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1279 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1281 cris_cc_mask(dc
, CC_MASK_NZVC
);
1283 c
= tcg_const_tl(dc
->op1
);
1284 cris_alu(dc
, CC_OP_ADD
,
1285 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1289 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1293 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1294 imm
= sign_extend(dc
->op1
, 5);
1295 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1297 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1300 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1303 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1305 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1307 cris_cc_mask(dc
, CC_MASK_NZVC
);
1308 c
= tcg_const_tl(dc
->op1
);
1309 cris_alu(dc
, CC_OP_SUB
,
1310 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1314 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1318 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1319 imm
= sign_extend(dc
->op1
, 5);
1321 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1322 cris_cc_mask(dc
, CC_MASK_NZVC
);
1324 c
= tcg_const_tl(imm
);
1325 cris_alu(dc
, CC_OP_CMP
,
1326 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1330 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1334 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1335 imm
= sign_extend(dc
->op1
, 5);
1337 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1338 cris_cc_mask(dc
, CC_MASK_NZ
);
1340 c
= tcg_const_tl(imm
);
1341 cris_alu(dc
, CC_OP_AND
,
1342 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1346 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1350 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1351 imm
= sign_extend(dc
->op1
, 5);
1352 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1353 cris_cc_mask(dc
, CC_MASK_NZ
);
1355 c
= tcg_const_tl(imm
);
1356 cris_alu(dc
, CC_OP_OR
,
1357 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], c
, 4);
1361 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1364 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1365 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1367 cris_cc_mask(dc
, CC_MASK_NZ
);
1368 c
= tcg_const_tl(dc
->op1
);
1369 cris_evaluate_flags(dc
);
1370 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1373 cris_alu(dc
, CC_OP_MOVE
,
1374 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1375 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1376 dc
->flags_uptodate
= 1;
1379 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1381 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1382 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1383 cris_cc_mask(dc
, CC_MASK_NZ
);
1385 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1386 cris_alu(dc
, CC_OP_MOVE
,
1388 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1391 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1393 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1394 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1396 cris_cc_mask(dc
, CC_MASK_NZ
);
1398 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1400 cris_alu(dc
, CC_OP_MOVE
,
1402 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1405 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1407 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1408 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1410 cris_cc_mask(dc
, CC_MASK_NZ
);
1412 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1413 cris_alu(dc
, CC_OP_MOVE
,
1415 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1419 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1421 int size
= memsize_zz(dc
);
1423 LOG_DIS("move.%c $r%u, $r%u\n",
1424 memsize_char(size
), dc
->op1
, dc
->op2
);
1426 cris_cc_mask(dc
, CC_MASK_NZ
);
1428 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1429 cris_cc_mask(dc
, CC_MASK_NZ
);
1430 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1431 cris_update_cc_x(dc
);
1432 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1436 t0
= tcg_temp_new();
1437 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1438 cris_alu(dc
, CC_OP_MOVE
,
1440 cpu_R
[dc
->op2
], t0
, size
);
1446 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1450 LOG_DIS("s%s $r%u\n",
1451 cc_name(cond
), dc
->op1
);
1453 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1454 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], 0);
1456 cris_cc_mask(dc
, 0);
1460 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1463 t
[0] = cpu_R
[dc
->op2
];
1464 t
[1] = cpu_R
[dc
->op1
];
1466 t
[0] = tcg_temp_new();
1467 t
[1] = tcg_temp_new();
1471 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1474 tcg_temp_free(t
[0]);
1475 tcg_temp_free(t
[1]);
1479 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1482 int size
= memsize_zz(dc
);
1484 LOG_DIS("and.%c $r%u, $r%u\n",
1485 memsize_char(size
), dc
->op1
, dc
->op2
);
1487 cris_cc_mask(dc
, CC_MASK_NZ
);
1489 cris_alu_alloc_temps(dc
, size
, t
);
1490 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1491 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1492 cris_alu_free_temps(dc
, size
, t
);
1496 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1499 LOG_DIS("lz $r%u, $r%u\n",
1501 cris_cc_mask(dc
, CC_MASK_NZ
);
1502 t0
= tcg_temp_new();
1503 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1504 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1509 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1512 int size
= memsize_zz(dc
);
1514 LOG_DIS("lsl.%c $r%u, $r%u\n",
1515 memsize_char(size
), dc
->op1
, dc
->op2
);
1517 cris_cc_mask(dc
, CC_MASK_NZ
);
1518 cris_alu_alloc_temps(dc
, size
, t
);
1519 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1520 tcg_gen_andi_tl(t
[1], t
[1], 63);
1521 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1522 cris_alu_free_temps(dc
, size
, t
);
1526 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1529 int size
= memsize_zz(dc
);
1531 LOG_DIS("lsr.%c $r%u, $r%u\n",
1532 memsize_char(size
), dc
->op1
, dc
->op2
);
1534 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 tcg_gen_andi_tl(t
[1], t
[1], 63);
1538 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1539 cris_alu_free_temps(dc
, size
, t
);
1543 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1546 int size
= memsize_zz(dc
);
1548 LOG_DIS("asr.%c $r%u, $r%u\n",
1549 memsize_char(size
), dc
->op1
, dc
->op2
);
1551 cris_cc_mask(dc
, CC_MASK_NZ
);
1552 cris_alu_alloc_temps(dc
, size
, t
);
1553 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1554 tcg_gen_andi_tl(t
[1], t
[1], 63);
1555 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1556 cris_alu_free_temps(dc
, size
, t
);
1560 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1563 int size
= memsize_zz(dc
);
1565 LOG_DIS("muls.%c $r%u, $r%u\n",
1566 memsize_char(size
), dc
->op1
, dc
->op2
);
1567 cris_cc_mask(dc
, CC_MASK_NZV
);
1568 cris_alu_alloc_temps(dc
, size
, t
);
1569 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1571 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1572 cris_alu_free_temps(dc
, size
, t
);
1576 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1579 int size
= memsize_zz(dc
);
1581 LOG_DIS("mulu.%c $r%u, $r%u\n",
1582 memsize_char(size
), dc
->op1
, dc
->op2
);
1583 cris_cc_mask(dc
, CC_MASK_NZV
);
1584 cris_alu_alloc_temps(dc
, size
, t
);
1585 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1587 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1588 cris_alu_free_temps(dc
, size
, t
);
1593 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1595 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1596 cris_cc_mask(dc
, CC_MASK_NZ
);
1597 cris_alu(dc
, CC_OP_DSTEP
,
1598 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1602 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1605 int size
= memsize_zz(dc
);
1606 LOG_DIS("xor.%c $r%u, $r%u\n",
1607 memsize_char(size
), dc
->op1
, dc
->op2
);
1608 BUG_ON(size
!= 4); /* xor is dword. */
1609 cris_cc_mask(dc
, CC_MASK_NZ
);
1610 cris_alu_alloc_temps(dc
, size
, t
);
1611 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1613 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1614 cris_alu_free_temps(dc
, size
, t
);
1618 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1621 int size
= memsize_zz(dc
);
1622 LOG_DIS("bound.%c $r%u, $r%u\n",
1623 memsize_char(size
), dc
->op1
, dc
->op2
);
1624 cris_cc_mask(dc
, CC_MASK_NZ
);
1625 l0
= tcg_temp_local_new();
1626 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1627 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1632 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1635 int size
= memsize_zz(dc
);
1636 LOG_DIS("cmp.%c $r%u, $r%u\n",
1637 memsize_char(size
), dc
->op1
, dc
->op2
);
1638 cris_cc_mask(dc
, CC_MASK_NZVC
);
1639 cris_alu_alloc_temps(dc
, size
, t
);
1640 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1642 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1643 cris_alu_free_temps(dc
, size
, t
);
1647 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1649 LOG_DIS("abs $r%u, $r%u\n",
1651 cris_cc_mask(dc
, CC_MASK_NZ
);
1653 tcg_gen_abs_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
]);
1654 cris_alu(dc
, CC_OP_MOVE
,
1655 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1659 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1662 int size
= memsize_zz(dc
);
1663 LOG_DIS("add.%c $r%u, $r%u\n",
1664 memsize_char(size
), dc
->op1
, dc
->op2
);
1665 cris_cc_mask(dc
, CC_MASK_NZVC
);
1666 cris_alu_alloc_temps(dc
, size
, t
);
1667 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1669 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1670 cris_alu_free_temps(dc
, size
, t
);
1674 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1676 LOG_DIS("addc $r%u, $r%u\n",
1678 cris_evaluate_flags(dc
);
1680 /* Set for this insn. */
1681 dc
->flags_x
= X_FLAG
;
1683 cris_cc_mask(dc
, CC_MASK_NZVC
);
1684 cris_alu(dc
, CC_OP_ADDC
,
1685 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1689 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1691 LOG_DIS("mcp $p%u, $r%u\n",
1693 cris_evaluate_flags(dc
);
1694 cris_cc_mask(dc
, CC_MASK_RNZV
);
1695 cris_alu(dc
, CC_OP_MCP
,
1696 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1701 static char * swapmode_name(int mode
, char *modename
) {
1704 modename
[i
++] = 'n';
1707 modename
[i
++] = 'w';
1710 modename
[i
++] = 'b';
1713 modename
[i
++] = 'r';
1720 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1726 LOG_DIS("swap%s $r%u\n",
1727 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1729 cris_cc_mask(dc
, CC_MASK_NZ
);
1730 t0
= tcg_temp_new();
1731 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1733 tcg_gen_not_tl(t0
, t0
);
1736 t_gen_swapw(t0
, t0
);
1739 t_gen_swapb(t0
, t0
);
1742 t_gen_swapr(t0
, t0
);
1744 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1749 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1752 int size
= memsize_zz(dc
);
1753 LOG_DIS("or.%c $r%u, $r%u\n",
1754 memsize_char(size
), dc
->op1
, dc
->op2
);
1755 cris_cc_mask(dc
, CC_MASK_NZ
);
1756 cris_alu_alloc_temps(dc
, size
, t
);
1757 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1758 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1759 cris_alu_free_temps(dc
, size
, t
);
1763 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1766 LOG_DIS("addi.%c $r%u, $r%u\n",
1767 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1768 cris_cc_mask(dc
, 0);
1769 t0
= tcg_temp_new();
1770 tcg_gen_shli_tl(t0
, cpu_R
[dc
->op2
], dc
->zzsize
);
1771 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1776 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1779 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1780 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1781 cris_cc_mask(dc
, 0);
1782 t0
= tcg_temp_new();
1783 tcg_gen_shli_tl(t0
, cpu_R
[dc
->op2
], dc
->zzsize
);
1784 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1789 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1792 int size
= memsize_zz(dc
);
1793 LOG_DIS("neg.%c $r%u, $r%u\n",
1794 memsize_char(size
), dc
->op1
, dc
->op2
);
1795 cris_cc_mask(dc
, CC_MASK_NZVC
);
1796 cris_alu_alloc_temps(dc
, size
, t
);
1797 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1799 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1800 cris_alu_free_temps(dc
, size
, t
);
1804 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1806 LOG_DIS("btst $r%u, $r%u\n",
1808 cris_cc_mask(dc
, CC_MASK_NZ
);
1809 cris_evaluate_flags(dc
);
1810 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1811 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1812 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1813 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1814 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1815 dc
->flags_uptodate
= 1;
1819 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1822 int size
= memsize_zz(dc
);
1823 LOG_DIS("sub.%c $r%u, $r%u\n",
1824 memsize_char(size
), dc
->op1
, dc
->op2
);
1825 cris_cc_mask(dc
, CC_MASK_NZVC
);
1826 cris_alu_alloc_temps(dc
, size
, t
);
1827 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1828 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1829 cris_alu_free_temps(dc
, size
, t
);
1833 /* Zero extension. From size to dword. */
1834 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1837 int size
= memsize_z(dc
);
1838 LOG_DIS("movu.%c $r%u, $r%u\n",
1842 cris_cc_mask(dc
, CC_MASK_NZ
);
1843 t0
= tcg_temp_new();
1844 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1845 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1850 /* Sign extension. From size to dword. */
1851 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1854 int size
= memsize_z(dc
);
1855 LOG_DIS("movs.%c $r%u, $r%u\n",
1859 cris_cc_mask(dc
, CC_MASK_NZ
);
1860 t0
= tcg_temp_new();
1861 /* Size can only be qi or hi. */
1862 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1863 cris_alu(dc
, CC_OP_MOVE
,
1864 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1869 /* zero extension. From size to dword. */
1870 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1873 int size
= memsize_z(dc
);
1874 LOG_DIS("addu.%c $r%u, $r%u\n",
1878 cris_cc_mask(dc
, CC_MASK_NZVC
);
1879 t0
= tcg_temp_new();
1880 /* Size can only be qi or hi. */
1881 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1882 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1887 /* Sign extension. From size to dword. */
1888 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1891 int size
= memsize_z(dc
);
1892 LOG_DIS("adds.%c $r%u, $r%u\n",
1896 cris_cc_mask(dc
, CC_MASK_NZVC
);
1897 t0
= tcg_temp_new();
1898 /* Size can only be qi or hi. */
1899 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1900 cris_alu(dc
, CC_OP_ADD
,
1901 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1906 /* Zero extension. From size to dword. */
1907 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1910 int size
= memsize_z(dc
);
1911 LOG_DIS("subu.%c $r%u, $r%u\n",
1915 cris_cc_mask(dc
, CC_MASK_NZVC
);
1916 t0
= tcg_temp_new();
1917 /* Size can only be qi or hi. */
1918 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1919 cris_alu(dc
, CC_OP_SUB
,
1920 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1925 /* Sign extension. From size to dword. */
1926 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1929 int size
= memsize_z(dc
);
1930 LOG_DIS("subs.%c $r%u, $r%u\n",
1934 cris_cc_mask(dc
, CC_MASK_NZVC
);
1935 t0
= tcg_temp_new();
1936 /* Size can only be qi or hi. */
1937 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1938 cris_alu(dc
, CC_OP_SUB
,
1939 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1944 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
1947 int set
= (~dc
->opcode
>> 2) & 1;
1950 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1951 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1952 if (set
&& flags
== 0) {
1955 } else if (!set
&& (flags
& 0x20)) {
1958 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
1961 /* User space is not allowed to touch these. Silently ignore. */
1962 if (dc
->tb_flags
& U_FLAG
) {
1963 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
1966 if (flags
& X_FLAG
) {
1968 dc
->flags_x
= X_FLAG
;
1974 /* Break the TB if any of the SPI flag changes. */
1975 if (flags
& (P_FLAG
| S_FLAG
)) {
1976 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
1977 dc
->base
.is_jmp
= DISAS_UPDATE
;
1978 dc
->cpustate_changed
= 1;
1981 /* For the I flag, only act on posedge. */
1982 if ((flags
& I_FLAG
)) {
1983 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
1984 dc
->base
.is_jmp
= DISAS_UPDATE
;
1985 dc
->cpustate_changed
= 1;
1989 /* Simply decode the flags. */
1990 cris_evaluate_flags(dc
);
1991 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1992 cris_update_cc_x(dc
);
1993 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
1996 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
1997 /* Enter user mode. */
1998 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
1999 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2000 dc
->cpustate_changed
= 1;
2002 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2004 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2007 dc
->flags_uptodate
= 1;
2012 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2015 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2016 c1
= tcg_const_tl(dc
->op1
);
2017 c2
= tcg_const_tl(dc
->op2
);
2018 cris_cc_mask(dc
, 0);
2019 gen_helper_movl_sreg_reg(cpu_env
, c2
, c1
);
2024 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2027 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2028 c1
= tcg_const_tl(dc
->op1
);
2029 c2
= tcg_const_tl(dc
->op2
);
2030 cris_cc_mask(dc
, 0);
2031 gen_helper_movl_reg_sreg(cpu_env
, c1
, c2
);
2037 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2040 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2041 cris_cc_mask(dc
, 0);
2043 t
[0] = tcg_temp_new();
2044 if (dc
->op2
== PR_CCS
) {
2045 cris_evaluate_flags(dc
);
2046 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2047 if (dc
->tb_flags
& U_FLAG
) {
2048 t
[1] = tcg_temp_new();
2049 /* User space is not allowed to touch all flags. */
2050 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2051 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2052 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2053 tcg_temp_free(t
[1]);
2056 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2059 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2060 if (dc
->op2
== PR_CCS
) {
2061 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2062 dc
->flags_uptodate
= 1;
2064 tcg_temp_free(t
[0]);
2067 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2070 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2071 cris_cc_mask(dc
, 0);
2073 if (dc
->op2
== PR_CCS
) {
2074 cris_evaluate_flags(dc
);
2077 if (dc
->op2
== PR_DZ
) {
2078 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2080 t0
= tcg_temp_new();
2081 t_gen_mov_TN_preg(t0
, dc
->op2
);
2082 cris_alu(dc
, CC_OP_MOVE
,
2083 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2084 preg_sizes
[dc
->op2
]);
2090 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2092 int memsize
= memsize_zz(dc
);
2094 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2095 memsize_char(memsize
),
2096 dc
->op1
, dc
->postinc
? "+]" : "]",
2100 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2101 cris_cc_mask(dc
, CC_MASK_NZ
);
2102 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2103 cris_update_cc_x(dc
);
2104 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2108 t0
= tcg_temp_new();
2109 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2110 cris_cc_mask(dc
, CC_MASK_NZ
);
2111 cris_alu(dc
, CC_OP_MOVE
,
2112 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2115 do_postinc(dc
, memsize
);
2119 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2121 t
[0] = tcg_temp_new();
2122 t
[1] = tcg_temp_new();
2125 static inline void cris_alu_m_free_temps(TCGv
*t
)
2127 tcg_temp_free(t
[0]);
2128 tcg_temp_free(t
[1]);
2131 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2134 int memsize
= memsize_z(dc
);
2136 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2137 memsize_char(memsize
),
2138 dc
->op1
, dc
->postinc
? "+]" : "]",
2141 cris_alu_m_alloc_temps(t
);
2143 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2144 cris_cc_mask(dc
, CC_MASK_NZ
);
2145 cris_alu(dc
, CC_OP_MOVE
,
2146 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2147 do_postinc(dc
, memsize
);
2148 cris_alu_m_free_temps(t
);
2152 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2155 int memsize
= memsize_z(dc
);
2157 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2158 memsize_char(memsize
),
2159 dc
->op1
, dc
->postinc
? "+]" : "]",
2162 cris_alu_m_alloc_temps(t
);
2164 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2165 cris_cc_mask(dc
, CC_MASK_NZVC
);
2166 cris_alu(dc
, CC_OP_ADD
,
2167 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2168 do_postinc(dc
, memsize
);
2169 cris_alu_m_free_temps(t
);
2173 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2176 int memsize
= memsize_z(dc
);
2178 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2179 memsize_char(memsize
),
2180 dc
->op1
, dc
->postinc
? "+]" : "]",
2183 cris_alu_m_alloc_temps(t
);
2185 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2186 cris_cc_mask(dc
, CC_MASK_NZVC
);
2187 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2188 do_postinc(dc
, memsize
);
2189 cris_alu_m_free_temps(t
);
2193 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2196 int memsize
= memsize_z(dc
);
2198 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2199 memsize_char(memsize
),
2200 dc
->op1
, dc
->postinc
? "+]" : "]",
2203 cris_alu_m_alloc_temps(t
);
2205 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2206 cris_cc_mask(dc
, CC_MASK_NZVC
);
2207 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2208 do_postinc(dc
, memsize
);
2209 cris_alu_m_free_temps(t
);
2213 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2216 int memsize
= memsize_z(dc
);
2218 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2219 memsize_char(memsize
),
2220 dc
->op1
, dc
->postinc
? "+]" : "]",
2223 cris_alu_m_alloc_temps(t
);
2225 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2226 cris_cc_mask(dc
, CC_MASK_NZVC
);
2227 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2228 do_postinc(dc
, memsize
);
2229 cris_alu_m_free_temps(t
);
2233 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2236 int memsize
= memsize_z(dc
);
2239 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2240 memsize_char(memsize
),
2241 dc
->op1
, dc
->postinc
? "+]" : "]",
2244 cris_alu_m_alloc_temps(t
);
2245 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2246 cris_cc_mask(dc
, CC_MASK_NZ
);
2247 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2248 do_postinc(dc
, memsize
);
2249 cris_alu_m_free_temps(t
);
2253 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2256 int memsize
= memsize_z(dc
);
2258 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2259 memsize_char(memsize
),
2260 dc
->op1
, dc
->postinc
? "+]" : "]",
2263 cris_alu_m_alloc_temps(t
);
2264 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2265 cris_cc_mask(dc
, CC_MASK_NZVC
);
2266 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2267 do_postinc(dc
, memsize
);
2268 cris_alu_m_free_temps(t
);
2272 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2275 int memsize
= memsize_z(dc
);
2277 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2278 memsize_char(memsize
),
2279 dc
->op1
, dc
->postinc
? "+]" : "]",
2282 cris_alu_m_alloc_temps(t
);
2283 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2284 cris_cc_mask(dc
, CC_MASK_NZVC
);
2285 cris_alu(dc
, CC_OP_CMP
,
2286 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2288 do_postinc(dc
, memsize
);
2289 cris_alu_m_free_temps(t
);
2293 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2296 int memsize
= memsize_zz(dc
);
2298 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2299 memsize_char(memsize
),
2300 dc
->op1
, dc
->postinc
? "+]" : "]",
2303 cris_alu_m_alloc_temps(t
);
2304 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2305 cris_cc_mask(dc
, CC_MASK_NZVC
);
2306 cris_alu(dc
, CC_OP_CMP
,
2307 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2309 do_postinc(dc
, memsize
);
2310 cris_alu_m_free_temps(t
);
2314 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2317 int memsize
= memsize_zz(dc
);
2319 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2320 memsize_char(memsize
),
2321 dc
->op1
, dc
->postinc
? "+]" : "]",
2324 cris_evaluate_flags(dc
);
2326 cris_alu_m_alloc_temps(t
);
2327 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2328 cris_cc_mask(dc
, CC_MASK_NZ
);
2329 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2331 c
= tcg_const_tl(0);
2332 cris_alu(dc
, CC_OP_CMP
,
2333 cpu_R
[dc
->op2
], t
[1], c
, memsize_zz(dc
));
2335 do_postinc(dc
, memsize
);
2336 cris_alu_m_free_temps(t
);
2340 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2343 int memsize
= memsize_zz(dc
);
2345 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2346 memsize_char(memsize
),
2347 dc
->op1
, dc
->postinc
? "+]" : "]",
2350 cris_alu_m_alloc_temps(t
);
2351 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2352 cris_cc_mask(dc
, CC_MASK_NZ
);
2353 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2354 do_postinc(dc
, memsize
);
2355 cris_alu_m_free_temps(t
);
2359 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2362 int memsize
= memsize_zz(dc
);
2364 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2365 memsize_char(memsize
),
2366 dc
->op1
, dc
->postinc
? "+]" : "]",
2369 cris_alu_m_alloc_temps(t
);
2370 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2371 cris_cc_mask(dc
, CC_MASK_NZVC
);
2372 cris_alu(dc
, CC_OP_ADD
,
2373 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2374 do_postinc(dc
, memsize
);
2375 cris_alu_m_free_temps(t
);
2379 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2382 int memsize
= memsize_zz(dc
);
2384 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2385 memsize_char(memsize
),
2386 dc
->op1
, dc
->postinc
? "+]" : "]",
2389 cris_alu_m_alloc_temps(t
);
2390 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2391 cris_cc_mask(dc
, 0);
2392 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2393 do_postinc(dc
, memsize
);
2394 cris_alu_m_free_temps(t
);
2398 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2401 int memsize
= memsize_zz(dc
);
2403 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2404 memsize_char(memsize
),
2405 dc
->op1
, dc
->postinc
? "+]" : "]",
2408 l
[0] = tcg_temp_local_new();
2409 l
[1] = tcg_temp_local_new();
2410 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2411 cris_cc_mask(dc
, CC_MASK_NZ
);
2412 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2413 do_postinc(dc
, memsize
);
2414 tcg_temp_free(l
[0]);
2415 tcg_temp_free(l
[1]);
2419 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2423 LOG_DIS("addc [$r%u%s, $r%u\n",
2424 dc
->op1
, dc
->postinc
? "+]" : "]",
2427 cris_evaluate_flags(dc
);
2429 /* Set for this insn. */
2430 dc
->flags_x
= X_FLAG
;
2432 cris_alu_m_alloc_temps(t
);
2433 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2434 cris_cc_mask(dc
, CC_MASK_NZVC
);
2435 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2437 cris_alu_m_free_temps(t
);
2441 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2444 int memsize
= memsize_zz(dc
);
2446 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2447 memsize_char(memsize
),
2448 dc
->op1
, dc
->postinc
? "+]" : "]",
2449 dc
->op2
, dc
->ir
, dc
->zzsize
);
2451 cris_alu_m_alloc_temps(t
);
2452 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2453 cris_cc_mask(dc
, CC_MASK_NZVC
);
2454 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2455 do_postinc(dc
, memsize
);
2456 cris_alu_m_free_temps(t
);
2460 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2463 int memsize
= memsize_zz(dc
);
2465 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2466 memsize_char(memsize
),
2467 dc
->op1
, dc
->postinc
? "+]" : "]",
2470 cris_alu_m_alloc_temps(t
);
2471 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2472 cris_cc_mask(dc
, CC_MASK_NZ
);
2473 cris_alu(dc
, CC_OP_OR
,
2474 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2475 do_postinc(dc
, memsize
);
2476 cris_alu_m_free_temps(t
);
2480 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2483 int memsize
= memsize_zz(dc
);
2486 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2487 memsize_char(memsize
),
2489 dc
->postinc
? "+]" : "]",
2492 cris_alu_m_alloc_temps(t
);
2493 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2494 cris_cc_mask(dc
, 0);
2495 if (dc
->op2
== PR_CCS
) {
2496 cris_evaluate_flags(dc
);
2497 if (dc
->tb_flags
& U_FLAG
) {
2498 /* User space is not allowed to touch all flags. */
2499 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2500 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2501 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2505 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2507 do_postinc(dc
, memsize
);
2508 cris_alu_m_free_temps(t
);
2512 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2517 memsize
= preg_sizes
[dc
->op2
];
2519 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2520 memsize_char(memsize
),
2521 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2523 /* prepare store. Address in T0, value in T1. */
2524 if (dc
->op2
== PR_CCS
) {
2525 cris_evaluate_flags(dc
);
2527 t0
= tcg_temp_new();
2528 t_gen_mov_TN_preg(t0
, dc
->op2
);
2529 cris_flush_cc_state(dc
);
2530 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2533 cris_cc_mask(dc
, 0);
2535 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2540 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2546 int nr
= dc
->op2
+ 1;
2548 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2549 dc
->postinc
? "+]" : "]", dc
->op2
);
2551 addr
= tcg_temp_new();
2552 /* There are probably better ways of doing this. */
2553 cris_flush_cc_state(dc
);
2554 for (i
= 0; i
< (nr
>> 1); i
++) {
2555 tmp
[i
] = tcg_temp_new_i64();
2556 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2557 gen_load64(dc
, tmp
[i
], addr
);
2560 tmp32
= tcg_temp_new_i32();
2561 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2562 gen_load(dc
, tmp32
, addr
, 4, 0);
2566 tcg_temp_free(addr
);
2568 for (i
= 0; i
< (nr
>> 1); i
++) {
2569 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2570 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2571 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2572 tcg_temp_free_i64(tmp
[i
]);
2575 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2576 tcg_temp_free(tmp32
);
2579 /* writeback the updated pointer value. */
2581 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2584 /* gen_load might want to evaluate the previous insns flags. */
2585 cris_cc_mask(dc
, 0);
2589 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2595 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2596 dc
->postinc
? "+]" : "]");
2598 cris_flush_cc_state(dc
);
2600 tmp
= tcg_temp_new();
2601 addr
= tcg_temp_new();
2602 tcg_gen_movi_tl(tmp
, 4);
2603 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2604 for (i
= 0; i
<= dc
->op2
; i
++) {
2605 /* Displace addr. */
2606 /* Perform the store. */
2607 gen_store(dc
, addr
, cpu_R
[i
], 4);
2608 tcg_gen_add_tl(addr
, addr
, tmp
);
2611 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2613 cris_cc_mask(dc
, 0);
2615 tcg_temp_free(addr
);
2619 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2623 memsize
= memsize_zz(dc
);
2625 LOG_DIS("move.%c $r%u, [$r%u]\n",
2626 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2628 /* prepare store. */
2629 cris_flush_cc_state(dc
);
2630 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2633 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2635 cris_cc_mask(dc
, 0);
2639 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2641 LOG_DIS("lapcq %x, $r%u\n",
2642 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2643 cris_cc_mask(dc
, 0);
2644 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2648 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2656 cris_cc_mask(dc
, 0);
2657 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2658 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2662 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2666 /* Jump to special reg. */
2667 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2669 LOG_DIS("jump $p%u\n", dc
->op2
);
2671 if (dc
->op2
== PR_CCS
) {
2672 cris_evaluate_flags(dc
);
2674 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2675 /* rete will often have low bit set to indicate delayslot. */
2676 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2677 cris_cc_mask(dc
, 0);
2678 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2682 /* Jump and save. */
2683 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2686 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2687 cris_cc_mask(dc
, 0);
2688 /* Store the return address in Pd. */
2689 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2693 c
= tcg_const_tl(dc
->pc
+ 4);
2694 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2697 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2701 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2706 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2708 LOG_DIS("jas 0x%x\n", imm
);
2709 cris_cc_mask(dc
, 0);
2710 c
= tcg_const_tl(dc
->pc
+ 8);
2711 /* Store the return address in Pd. */
2712 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2716 cris_prepare_jmp(dc
, JMP_DIRECT
);
2720 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2725 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2727 LOG_DIS("jasc 0x%x\n", imm
);
2728 cris_cc_mask(dc
, 0);
2729 c
= tcg_const_tl(dc
->pc
+ 8 + 4);
2730 /* Store the return address in Pd. */
2731 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2735 cris_prepare_jmp(dc
, JMP_DIRECT
);
2739 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2742 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2743 cris_cc_mask(dc
, 0);
2744 /* Store the return address in Pd. */
2745 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2746 c
= tcg_const_tl(dc
->pc
+ 4 + 4);
2747 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2749 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2753 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2756 uint32_t cond
= dc
->op2
;
2758 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2760 LOG_DIS("b%s %d pc=%x dst=%x\n",
2761 cc_name(cond
), offset
,
2762 dc
->pc
, dc
->pc
+ offset
);
2764 cris_cc_mask(dc
, 0);
2765 /* op2 holds the condition-code. */
2766 cris_prepare_cc_branch(dc
, offset
, cond
);
2770 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2775 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2777 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2778 cris_cc_mask(dc
, 0);
2779 c
= tcg_const_tl(dc
->pc
+ 8);
2780 /* Store the return address in Pd. */
2781 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2784 dc
->jmp_pc
= dc
->pc
+ simm
;
2785 cris_prepare_jmp(dc
, JMP_DIRECT
);
2789 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2793 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2795 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2796 cris_cc_mask(dc
, 0);
2797 c
= tcg_const_tl(dc
->pc
+ 12);
2798 /* Store the return address in Pd. */
2799 t_gen_mov_preg_TN(dc
, dc
->op2
, c
);
2802 dc
->jmp_pc
= dc
->pc
+ simm
;
2803 cris_prepare_jmp(dc
, JMP_DIRECT
);
2807 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2809 cris_cc_mask(dc
, 0);
2811 if (dc
->op2
== 15) {
2812 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2813 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2814 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2815 t_gen_raise_exception(EXCP_HLT
);
2816 dc
->base
.is_jmp
= DISAS_NORETURN
;
2820 switch (dc
->op2
& 7) {
2824 cris_evaluate_flags(dc
);
2825 gen_helper_rfe(cpu_env
);
2826 dc
->base
.is_jmp
= DISAS_UPDATE
;
2827 dc
->cpustate_changed
= true;
2832 cris_evaluate_flags(dc
);
2833 gen_helper_rfn(cpu_env
);
2834 dc
->base
.is_jmp
= DISAS_UPDATE
;
2835 dc
->cpustate_changed
= true;
2838 LOG_DIS("break %d\n", dc
->op1
);
2839 cris_evaluate_flags(dc
);
2841 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2843 /* Breaks start at 16 in the exception vector. */
2844 t_gen_movi_env_TN(trap_vector
, dc
->op1
+ 16);
2845 t_gen_raise_exception(EXCP_BREAK
);
2846 dc
->base
.is_jmp
= DISAS_NORETURN
;
2849 printf("op2=%x\n", dc
->op2
);
2857 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2862 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2867 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2869 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2870 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2876 static const struct decoder_info
{
2881 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2883 /* Order matters here. */
2884 {DEC_MOVEQ
, dec_moveq
},
2885 {DEC_BTSTQ
, dec_btstq
},
2886 {DEC_CMPQ
, dec_cmpq
},
2887 {DEC_ADDOQ
, dec_addoq
},
2888 {DEC_ADDQ
, dec_addq
},
2889 {DEC_SUBQ
, dec_subq
},
2890 {DEC_ANDQ
, dec_andq
},
2892 {DEC_ASRQ
, dec_asrq
},
2893 {DEC_LSLQ
, dec_lslq
},
2894 {DEC_LSRQ
, dec_lsrq
},
2895 {DEC_BCCQ
, dec_bccq
},
2897 {DEC_BCC_IM
, dec_bcc_im
},
2898 {DEC_JAS_IM
, dec_jas_im
},
2899 {DEC_JAS_R
, dec_jas_r
},
2900 {DEC_JASC_IM
, dec_jasc_im
},
2901 {DEC_JASC_R
, dec_jasc_r
},
2902 {DEC_BAS_IM
, dec_bas_im
},
2903 {DEC_BASC_IM
, dec_basc_im
},
2904 {DEC_JUMP_P
, dec_jump_p
},
2905 {DEC_LAPC_IM
, dec_lapc_im
},
2906 {DEC_LAPCQ
, dec_lapcq
},
2908 {DEC_RFE_ETC
, dec_rfe_etc
},
2909 {DEC_ADDC_MR
, dec_addc_mr
},
2911 {DEC_MOVE_MP
, dec_move_mp
},
2912 {DEC_MOVE_PM
, dec_move_pm
},
2913 {DEC_MOVEM_MR
, dec_movem_mr
},
2914 {DEC_MOVEM_RM
, dec_movem_rm
},
2915 {DEC_MOVE_PR
, dec_move_pr
},
2916 {DEC_SCC_R
, dec_scc_r
},
2917 {DEC_SETF
, dec_setclrf
},
2918 {DEC_CLEARF
, dec_setclrf
},
2920 {DEC_MOVE_SR
, dec_move_sr
},
2921 {DEC_MOVE_RP
, dec_move_rp
},
2922 {DEC_SWAP_R
, dec_swap_r
},
2923 {DEC_ABS_R
, dec_abs_r
},
2924 {DEC_LZ_R
, dec_lz_r
},
2925 {DEC_MOVE_RS
, dec_move_rs
},
2926 {DEC_BTST_R
, dec_btst_r
},
2927 {DEC_ADDC_R
, dec_addc_r
},
2929 {DEC_DSTEP_R
, dec_dstep_r
},
2930 {DEC_XOR_R
, dec_xor_r
},
2931 {DEC_MCP_R
, dec_mcp_r
},
2932 {DEC_CMP_R
, dec_cmp_r
},
2934 {DEC_ADDI_R
, dec_addi_r
},
2935 {DEC_ADDI_ACR
, dec_addi_acr
},
2937 {DEC_ADD_R
, dec_add_r
},
2938 {DEC_SUB_R
, dec_sub_r
},
2940 {DEC_ADDU_R
, dec_addu_r
},
2941 {DEC_ADDS_R
, dec_adds_r
},
2942 {DEC_SUBU_R
, dec_subu_r
},
2943 {DEC_SUBS_R
, dec_subs_r
},
2944 {DEC_LSL_R
, dec_lsl_r
},
2946 {DEC_AND_R
, dec_and_r
},
2947 {DEC_OR_R
, dec_or_r
},
2948 {DEC_BOUND_R
, dec_bound_r
},
2949 {DEC_ASR_R
, dec_asr_r
},
2950 {DEC_LSR_R
, dec_lsr_r
},
2952 {DEC_MOVU_R
, dec_movu_r
},
2953 {DEC_MOVS_R
, dec_movs_r
},
2954 {DEC_NEG_R
, dec_neg_r
},
2955 {DEC_MOVE_R
, dec_move_r
},
2957 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2958 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2960 {DEC_MULS_R
, dec_muls_r
},
2961 {DEC_MULU_R
, dec_mulu_r
},
2963 {DEC_ADDU_M
, dec_addu_m
},
2964 {DEC_ADDS_M
, dec_adds_m
},
2965 {DEC_SUBU_M
, dec_subu_m
},
2966 {DEC_SUBS_M
, dec_subs_m
},
2968 {DEC_CMPU_M
, dec_cmpu_m
},
2969 {DEC_CMPS_M
, dec_cmps_m
},
2970 {DEC_MOVU_M
, dec_movu_m
},
2971 {DEC_MOVS_M
, dec_movs_m
},
2973 {DEC_CMP_M
, dec_cmp_m
},
2974 {DEC_ADDO_M
, dec_addo_m
},
2975 {DEC_BOUND_M
, dec_bound_m
},
2976 {DEC_ADD_M
, dec_add_m
},
2977 {DEC_SUB_M
, dec_sub_m
},
2978 {DEC_AND_M
, dec_and_m
},
2979 {DEC_OR_M
, dec_or_m
},
2980 {DEC_MOVE_RM
, dec_move_rm
},
2981 {DEC_TEST_M
, dec_test_m
},
2982 {DEC_MOVE_MR
, dec_move_mr
},
2987 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
2992 /* Load a halfword onto the instruction register. */
2993 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
2995 /* Now decode it. */
2996 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
2997 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
2998 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
2999 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3000 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3001 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3003 /* Large switch for all insns. */
3004 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3005 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3006 insn_len
= decinfo
[i
].dec(env
, dc
);
3011 #if !defined(CONFIG_USER_ONLY)
3012 /* Single-stepping ? */
3013 if (dc
->tb_flags
& S_FLAG
) {
3014 TCGLabel
*l1
= gen_new_label();
3015 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3016 /* We treat SPC as a break with an odd trap vector. */
3017 cris_evaluate_flags(dc
);
3018 t_gen_movi_env_TN(trap_vector
, 3);
3019 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3020 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3021 t_gen_raise_exception(EXCP_BREAK
);
3028 #include "translate_v10.c.inc"
3031 * Delay slots on QEMU/CRIS.
3033 * If an exception hits on a delayslot, the core will let ERP (the Exception
3034 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3035 * to give SW a hint that the exception actually hit on the dslot.
3037 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3038 * the core and any jmp to an odd addresses will mask off that lsb. It is
3039 * simply there to let sw know there was an exception on a dslot.
3041 * When the software returns from an exception, the branch will re-execute.
3042 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3043 * and the branch and delayslot don't share pages.
3045 * The TB contaning the branch insn will set up env->btarget and evaluate
3046 * env->btaken. When the translation loop exits we will note that the branch
3047 * sequence is broken and let env->dslot be the size of the branch insn (those
3050 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3051 * set). It will also expect to have env->dslot setup with the size of the
3052 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3053 * will execute the dslot and take the branch, either to btarget or just one
3056 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3057 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3058 * branch and set lsb). Then env->dslot gets cleared so that the exception
3059 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3060 * masked off and we will reexecute the branch insn.
3064 static void cris_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
3066 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3067 CPUCRISState
*env
= cs
->env_ptr
;
3068 uint32_t tb_flags
= dc
->base
.tb
->flags
;
3071 if (env
->pregs
[PR_VR
] == 32) {
3072 dc
->decoder
= crisv32_decoder
;
3073 dc
->clear_locked_irq
= 0;
3075 dc
->decoder
= crisv10_decoder
;
3076 dc
->clear_locked_irq
= 1;
3080 * Odd PC indicates that branch is rexecuting due to exception in the
3081 * delayslot, like in real hw.
3083 pc_start
= dc
->base
.pc_first
& ~1;
3084 dc
->base
.pc_first
= pc_start
;
3085 dc
->base
.pc_next
= pc_start
;
3087 dc
->cpu
= env_archcpu(env
);
3090 dc
->flags_uptodate
= 1;
3091 dc
->flags_x
= tb_flags
& X_FLAG
;
3092 dc
->cc_x_uptodate
= 0;
3095 dc
->clear_prefix
= 0;
3096 dc
->cpustate_changed
= 0;
3098 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3099 dc
->cc_size_uptodate
= -1;
3101 /* Decode TB flags. */
3102 dc
->tb_flags
= tb_flags
& (S_FLAG
| P_FLAG
| U_FLAG
| X_FLAG
| PFIX_FLAG
);
3103 dc
->delayed_branch
= !!(tb_flags
& 7);
3104 if (dc
->delayed_branch
) {
3105 dc
->jmp
= JMP_INDIRECT
;
3107 dc
->jmp
= JMP_NOJMP
;
3111 static void cris_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
3115 static void cris_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
3117 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3119 tcg_gen_insn_start(dc
->delayed_branch
== 1 ? dc
->ppc
| 1 : dc
->pc
);
3122 static bool cris_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
3123 const CPUBreakpoint
*bp
)
3125 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3127 cris_evaluate_flags(dc
);
3128 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3129 t_gen_raise_exception(EXCP_DEBUG
);
3130 dc
->base
.is_jmp
= DISAS_NORETURN
;
3132 * The address covered by the breakpoint must be included in
3133 * [tb->pc, tb->pc + tb->size) in order to for it to be
3134 * properly cleared -- thus we increment the PC here so that
3135 * the logic setting tb->size below does the right thing.
3141 static void cris_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
3143 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3144 CPUCRISState
*env
= cs
->env_ptr
;
3145 unsigned int insn_len
;
3148 LOG_DIS("%8.8x:\t", dc
->pc
);
3152 insn_len
= dc
->decoder(env
, dc
);
3155 dc
->base
.pc_next
+= insn_len
;
3157 if (dc
->base
.is_jmp
== DISAS_NORETURN
) {
3162 cris_clear_x_flag(dc
);
3166 * All branches are delayed branches, handled immediately below.
3167 * We don't expect to see odd combinations of exit conditions.
3169 assert(dc
->base
.is_jmp
== DISAS_NEXT
|| dc
->cpustate_changed
);
3171 if (dc
->delayed_branch
&& --dc
->delayed_branch
== 0) {
3172 dc
->base
.is_jmp
= DISAS_DBRANCH
;
3176 if (dc
->base
.is_jmp
!= DISAS_NEXT
) {
3180 /* Force an update if the per-tb cpu state has changed. */
3181 if (dc
->cpustate_changed
) {
3182 dc
->base
.is_jmp
= DISAS_UPDATE_NEXT
;
3187 * FIXME: Only the first insn in the TB should cross a page boundary.
3188 * If we can detect the length of the next insn easily, we should.
3189 * In the meantime, simply stop when we do cross.
3191 if ((dc
->pc
^ dc
->base
.pc_first
) & TARGET_PAGE_MASK
) {
3192 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
3196 static void cris_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
3198 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
3199 DisasJumpType is_jmp
= dc
->base
.is_jmp
;
3200 target_ulong npc
= dc
->pc
;
3202 if (is_jmp
== DISAS_NORETURN
) {
3203 /* If we have a broken branch+delayslot sequence, it's too late. */
3204 assert(dc
->delayed_branch
!= 1);
3208 if (dc
->clear_locked_irq
) {
3209 t_gen_movi_env_TN(locked_irq
, 0);
3212 /* Broken branch+delayslot sequence. */
3213 if (dc
->delayed_branch
== 1) {
3214 /* Set env->dslot to the size of the branch insn. */
3215 t_gen_movi_env_TN(dslot
, dc
->pc
- dc
->ppc
);
3216 cris_store_direct_jmp(dc
);
3219 cris_evaluate_flags(dc
);
3221 /* Evaluate delayed branch destination and fold to another is_jmp case. */
3222 if (is_jmp
== DISAS_DBRANCH
) {
3223 if (dc
->base
.tb
->flags
& 7) {
3224 t_gen_movi_env_TN(dslot
, 0);
3230 is_jmp
= dc
->cpustate_changed
? DISAS_UPDATE_NEXT
: DISAS_TOO_MANY
;
3235 * Use a conditional branch if either taken or not-taken path
3236 * can use goto_tb. If neither can, then treat it as indirect.
3238 if (likely(!dc
->base
.singlestep_enabled
)
3239 && likely(!dc
->cpustate_changed
)
3240 && (use_goto_tb(dc
, dc
->jmp_pc
) || use_goto_tb(dc
, npc
))) {
3241 TCGLabel
*not_taken
= gen_new_label();
3243 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, not_taken
);
3244 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3245 gen_set_label(not_taken
);
3247 /* not-taken case handled below. */
3248 is_jmp
= DISAS_TOO_MANY
;
3251 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
3255 tcg_gen_movcond_tl(TCG_COND_NE
, env_pc
,
3256 env_btaken
, tcg_constant_tl(0),
3257 env_btarget
, tcg_constant_tl(npc
));
3258 is_jmp
= dc
->cpustate_changed
? DISAS_UPDATE
: DISAS_JUMP
;
3261 * We have now consumed btaken and btarget. Hint to the
3262 * tcg compiler that the writeback to env may be dropped.
3264 tcg_gen_discard_tl(env_btaken
);
3265 tcg_gen_discard_tl(env_btarget
);
3269 g_assert_not_reached();
3273 if (unlikely(dc
->base
.singlestep_enabled
)) {
3275 case DISAS_TOO_MANY
:
3276 case DISAS_UPDATE_NEXT
:
3277 tcg_gen_movi_tl(env_pc
, npc
);
3281 t_gen_raise_exception(EXCP_DEBUG
);
3286 g_assert_not_reached();
3290 case DISAS_TOO_MANY
:
3291 gen_goto_tb(dc
, 0, npc
);
3293 case DISAS_UPDATE_NEXT
:
3294 tcg_gen_movi_tl(env_pc
, npc
);
3297 tcg_gen_lookup_and_goto_ptr();
3300 /* Indicate that interupts must be re-evaluated before the next TB. */
3301 tcg_gen_exit_tb(NULL
, 0);
3304 g_assert_not_reached();
3308 static void cris_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cpu
)
3311 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
3312 log_target_disas(cpu
, dcbase
->pc_first
, dcbase
->tb
->size
);
3316 static const TranslatorOps cris_tr_ops
= {
3317 .init_disas_context
= cris_tr_init_disas_context
,
3318 .tb_start
= cris_tr_tb_start
,
3319 .insn_start
= cris_tr_insn_start
,
3320 .breakpoint_check
= cris_tr_breakpoint_check
,
3321 .translate_insn
= cris_tr_translate_insn
,
3322 .tb_stop
= cris_tr_tb_stop
,
3323 .disas_log
= cris_tr_disas_log
,
3326 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
3329 translator_loop(&cris_tr_ops
, &dc
.base
, cs
, tb
, max_insns
);
3332 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
3334 CRISCPU
*cpu
= CRIS_CPU(cs
);
3335 CPUCRISState
*env
= &cpu
->env
;
3336 const char * const *regnames
;
3337 const char * const *pregnames
;
3343 if (env
->pregs
[PR_VR
] < 32) {
3344 pregnames
= pregnames_v10
;
3345 regnames
= regnames_v10
;
3347 pregnames
= pregnames_v32
;
3348 regnames
= regnames_v32
;
3351 qemu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3352 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3353 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3355 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3358 for (i
= 0; i
< 16; i
++) {
3359 qemu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3360 if ((i
+ 1) % 4 == 0) {
3361 qemu_fprintf(f
, "\n");
3364 qemu_fprintf(f
, "\nspecial regs:\n");
3365 for (i
= 0; i
< 16; i
++) {
3366 qemu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3367 if ((i
+ 1) % 4 == 0) {
3368 qemu_fprintf(f
, "\n");
3371 if (env
->pregs
[PR_VR
] >= 32) {
3372 uint32_t srs
= env
->pregs
[PR_SRS
];
3373 qemu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3374 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3375 for (i
= 0; i
< 16; i
++) {
3376 qemu_fprintf(f
, "s%2.2d=%8.8x ",
3377 i
, env
->sregs
[srs
][i
]);
3378 if ((i
+ 1) % 4 == 0) {
3379 qemu_fprintf(f
, "\n");
3384 qemu_fprintf(f
, "\n\n");
3388 void cris_initialize_tcg(void)
3392 cc_x
= tcg_global_mem_new(cpu_env
,
3393 offsetof(CPUCRISState
, cc_x
), "cc_x");
3394 cc_src
= tcg_global_mem_new(cpu_env
,
3395 offsetof(CPUCRISState
, cc_src
), "cc_src");
3396 cc_dest
= tcg_global_mem_new(cpu_env
,
3397 offsetof(CPUCRISState
, cc_dest
),
3399 cc_result
= tcg_global_mem_new(cpu_env
,
3400 offsetof(CPUCRISState
, cc_result
),
3402 cc_op
= tcg_global_mem_new(cpu_env
,
3403 offsetof(CPUCRISState
, cc_op
), "cc_op");
3404 cc_size
= tcg_global_mem_new(cpu_env
,
3405 offsetof(CPUCRISState
, cc_size
),
3407 cc_mask
= tcg_global_mem_new(cpu_env
,
3408 offsetof(CPUCRISState
, cc_mask
),
3411 env_pc
= tcg_global_mem_new(cpu_env
,
3412 offsetof(CPUCRISState
, pc
),
3414 env_btarget
= tcg_global_mem_new(cpu_env
,
3415 offsetof(CPUCRISState
, btarget
),
3417 env_btaken
= tcg_global_mem_new(cpu_env
,
3418 offsetof(CPUCRISState
, btaken
),
3420 for (i
= 0; i
< 16; i
++) {
3421 cpu_R
[i
] = tcg_global_mem_new(cpu_env
,
3422 offsetof(CPUCRISState
, regs
[i
]),
3425 for (i
= 0; i
< 16; i
++) {
3426 cpu_PR
[i
] = tcg_global_mem_new(cpu_env
,
3427 offsetof(CPUCRISState
, pregs
[i
]),
3432 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
,