2 * CRIS emulation for qemu: main translation routines.
4 * Copyright (c) 2008 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 * The condition code translation is in need of attention.
27 #include "disas/disas.h"
29 #include "exec/helper-proto.h"
31 #include "exec/cpu_ldst.h"
32 #include "crisv32-decode.h"
34 #include "exec/helper-gen.h"
36 #include "trace-tcg.h"
41 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
43 # define LOG_DIS(...) do { } while (0)
47 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
48 #define BUG_ON(x) ({if (x) BUG();})
52 /* Used by the decoder. */
53 #define EXTRACT_FIELD(src, start, end) \
54 (((src) >> start) & ((1 << (end - start + 1)) - 1))
56 #define CC_MASK_NZ 0xc
57 #define CC_MASK_NZV 0xe
58 #define CC_MASK_NZVC 0xf
59 #define CC_MASK_RNZV 0x10e
61 static TCGv_ptr cpu_env
;
62 static TCGv cpu_R
[16];
63 static TCGv cpu_PR
[16];
67 static TCGv cc_result
;
72 static TCGv env_btaken
;
73 static TCGv env_btarget
;
76 #include "exec/gen-icount.h"
78 /* This is the state at translation time. */
79 typedef struct DisasContext
{
84 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
89 unsigned int zsize
, zzsize
;
103 int cc_size_uptodate
; /* -1 invalid or last written value. */
105 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
106 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
107 int flagx_known
; /* Wether or not flags_x has the x flag known at
111 int clear_x
; /* Clear x after this insn? */
112 int clear_prefix
; /* Clear prefix after this insn? */
113 int clear_locked_irq
; /* Clear the irq lockout. */
114 int cpustate_changed
;
115 unsigned int tb_flags
; /* tb dependent flags. */
120 #define JMP_DIRECT_CC 2
121 #define JMP_INDIRECT 3
122 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
127 struct TranslationBlock
*tb
;
128 int singlestep_enabled
;
131 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
133 printf("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
134 qemu_log("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
135 cpu_abort(CPU(dc
->cpu
), "%s:%d\n", file
, line
);
138 static const char *regnames
[] =
140 "$r0", "$r1", "$r2", "$r3",
141 "$r4", "$r5", "$r6", "$r7",
142 "$r8", "$r9", "$r10", "$r11",
143 "$r12", "$r13", "$sp", "$acr",
145 static const char *pregnames
[] =
147 "$bz", "$vr", "$pid", "$srs",
148 "$wz", "$exs", "$eda", "$mof",
149 "$dz", "$ebp", "$erp", "$srp",
150 "$nrp", "$ccs", "$usp", "$spc",
153 /* We need this table to handle preg-moves with implicit width. */
154 static int preg_sizes
[] = {
165 #define t_gen_mov_TN_env(tn, member) \
166 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
167 #define t_gen_mov_env_TN(member, tn) \
168 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
170 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
172 if (r
< 0 || r
> 15) {
173 fprintf(stderr
, "wrong register read $p%d\n", r
);
175 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
176 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
177 } else if (r
== PR_VR
) {
178 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
180 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
183 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
185 if (r
< 0 || r
> 15) {
186 fprintf(stderr
, "wrong register write $p%d\n", r
);
188 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
190 } else if (r
== PR_SRS
) {
191 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
194 gen_helper_tlb_flush_pid(cpu_env
, tn
);
196 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
197 gen_helper_spc_write(cpu_env
, tn
);
198 } else if (r
== PR_CCS
) {
199 dc
->cpustate_changed
= 1;
201 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
205 /* Sign extend at translation time. */
206 static int sign_extend(unsigned int val
, unsigned int width
)
218 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
219 unsigned int size
, unsigned int sign
)
226 r
= cpu_ldl_code(env
, addr
);
232 r
= cpu_ldsw_code(env
, addr
);
234 r
= cpu_lduw_code(env
, addr
);
241 r
= cpu_ldsb_code(env
, addr
);
243 r
= cpu_ldub_code(env
, addr
);
248 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
254 static void cris_lock_irq(DisasContext
*dc
)
256 dc
->clear_locked_irq
= 0;
257 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
260 static inline void t_gen_raise_exception(uint32_t index
)
262 TCGv_i32 tmp
= tcg_const_i32(index
);
263 gen_helper_raise_exception(cpu_env
, tmp
);
264 tcg_temp_free_i32(tmp
);
267 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
272 t_31
= tcg_const_tl(31);
273 tcg_gen_shl_tl(d
, a
, b
);
275 tcg_gen_sub_tl(t0
, t_31
, b
);
276 tcg_gen_sar_tl(t0
, t0
, t_31
);
277 tcg_gen_and_tl(t0
, t0
, d
);
278 tcg_gen_xor_tl(d
, d
, t0
);
283 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
288 t_31
= tcg_temp_new();
289 tcg_gen_shr_tl(d
, a
, b
);
291 tcg_gen_movi_tl(t_31
, 31);
292 tcg_gen_sub_tl(t0
, t_31
, b
);
293 tcg_gen_sar_tl(t0
, t0
, t_31
);
294 tcg_gen_and_tl(t0
, t0
, d
);
295 tcg_gen_xor_tl(d
, d
, t0
);
300 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
305 t_31
= tcg_temp_new();
306 tcg_gen_sar_tl(d
, a
, b
);
308 tcg_gen_movi_tl(t_31
, 31);
309 tcg_gen_sub_tl(t0
, t_31
, b
);
310 tcg_gen_sar_tl(t0
, t0
, t_31
);
311 tcg_gen_or_tl(d
, d
, t0
);
316 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
320 l1
= gen_new_label();
327 tcg_gen_shli_tl(d
, a
, 1);
328 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
329 tcg_gen_sub_tl(d
, d
, b
);
333 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
343 tcg_gen_shli_tl(d
, a
, 1);
344 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
345 tcg_gen_sari_tl(t
, t
, 31);
346 tcg_gen_and_tl(t
, t
, b
);
347 tcg_gen_add_tl(d
, d
, t
);
351 /* Extended arithmetics on CRIS. */
352 static inline void t_gen_add_flag(TCGv d
, int flag
)
357 t_gen_mov_TN_preg(c
, PR_CCS
);
358 /* Propagate carry into d. */
359 tcg_gen_andi_tl(c
, c
, 1 << flag
);
361 tcg_gen_shri_tl(c
, c
, flag
);
363 tcg_gen_add_tl(d
, d
, c
);
367 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
369 if (dc
->flagx_known
) {
374 t_gen_mov_TN_preg(c
, PR_CCS
);
375 /* C flag is already at bit 0. */
376 tcg_gen_andi_tl(c
, c
, C_FLAG
);
377 tcg_gen_add_tl(d
, d
, c
);
385 t_gen_mov_TN_preg(x
, PR_CCS
);
386 tcg_gen_mov_tl(c
, x
);
388 /* Propagate carry into d if X is set. Branch free. */
389 tcg_gen_andi_tl(c
, c
, C_FLAG
);
390 tcg_gen_andi_tl(x
, x
, X_FLAG
);
391 tcg_gen_shri_tl(x
, x
, 4);
393 tcg_gen_and_tl(x
, x
, c
);
394 tcg_gen_add_tl(d
, d
, x
);
400 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
402 if (dc
->flagx_known
) {
407 t_gen_mov_TN_preg(c
, PR_CCS
);
408 /* C flag is already at bit 0. */
409 tcg_gen_andi_tl(c
, c
, C_FLAG
);
410 tcg_gen_sub_tl(d
, d
, c
);
418 t_gen_mov_TN_preg(x
, PR_CCS
);
419 tcg_gen_mov_tl(c
, x
);
421 /* Propagate carry into d if X is set. Branch free. */
422 tcg_gen_andi_tl(c
, c
, C_FLAG
);
423 tcg_gen_andi_tl(x
, x
, X_FLAG
);
424 tcg_gen_shri_tl(x
, x
, 4);
426 tcg_gen_and_tl(x
, x
, c
);
427 tcg_gen_sub_tl(d
, d
, x
);
433 /* Swap the two bytes within each half word of the s operand.
434 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
435 static inline void t_gen_swapb(TCGv d
, TCGv s
)
440 org_s
= tcg_temp_new();
442 /* d and s may refer to the same object. */
443 tcg_gen_mov_tl(org_s
, s
);
444 tcg_gen_shli_tl(t
, org_s
, 8);
445 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
446 tcg_gen_shri_tl(t
, org_s
, 8);
447 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
448 tcg_gen_or_tl(d
, d
, t
);
450 tcg_temp_free(org_s
);
453 /* Swap the halfwords of the s operand. */
454 static inline void t_gen_swapw(TCGv d
, TCGv s
)
457 /* d and s refer the same object. */
459 tcg_gen_mov_tl(t
, s
);
460 tcg_gen_shli_tl(d
, t
, 16);
461 tcg_gen_shri_tl(t
, t
, 16);
462 tcg_gen_or_tl(d
, d
, t
);
466 /* Reverse the within each byte.
467 T0 = (((T0 << 7) & 0x80808080) |
468 ((T0 << 5) & 0x40404040) |
469 ((T0 << 3) & 0x20202020) |
470 ((T0 << 1) & 0x10101010) |
471 ((T0 >> 1) & 0x08080808) |
472 ((T0 >> 3) & 0x04040404) |
473 ((T0 >> 5) & 0x02020202) |
474 ((T0 >> 7) & 0x01010101));
476 static inline void t_gen_swapr(TCGv d
, TCGv s
)
479 int shift
; /* LSL when positive, LSR when negative. */
494 /* d and s refer the same object. */
496 org_s
= tcg_temp_new();
497 tcg_gen_mov_tl(org_s
, s
);
499 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
500 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
501 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
502 if (bitrev
[i
].shift
>= 0) {
503 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
505 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
507 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
508 tcg_gen_or_tl(d
, d
, t
);
511 tcg_temp_free(org_s
);
514 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
518 l1
= gen_new_label();
520 /* Conditional jmp. */
521 tcg_gen_mov_tl(env_pc
, pc_false
);
522 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
523 tcg_gen_mov_tl(env_pc
, pc_true
);
527 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
529 TranslationBlock
*tb
;
531 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
533 tcg_gen_movi_tl(env_pc
, dest
);
534 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
536 tcg_gen_movi_tl(env_pc
, dest
);
541 static inline void cris_clear_x_flag(DisasContext
*dc
)
543 if (dc
->flagx_known
&& dc
->flags_x
) {
544 dc
->flags_uptodate
= 0;
551 static void cris_flush_cc_state(DisasContext
*dc
)
553 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
554 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
555 dc
->cc_size_uptodate
= dc
->cc_size
;
557 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
558 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
561 static void cris_evaluate_flags(DisasContext
*dc
)
563 if (dc
->flags_uptodate
) {
567 cris_flush_cc_state(dc
);
571 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
572 cpu_PR
[PR_CCS
], cc_src
,
576 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
577 cpu_PR
[PR_CCS
], cc_result
,
581 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
582 cpu_PR
[PR_CCS
], cc_result
,
592 switch (dc
->cc_size
) {
594 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
595 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
598 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
599 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
602 gen_helper_evaluate_flags(cpu_env
);
611 if (dc
->cc_size
== 4) {
612 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
613 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
615 gen_helper_evaluate_flags(cpu_env
);
620 switch (dc
->cc_size
) {
622 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
623 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
626 gen_helper_evaluate_flags(cpu_env
);
632 if (dc
->flagx_known
) {
634 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
635 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
636 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
639 dc
->flags_uptodate
= 1;
642 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
651 /* Check if we need to evaluate the condition codes due to
653 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
655 /* TODO: optimize this case. It trigs all the time. */
656 cris_evaluate_flags(dc
);
662 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
666 dc
->flags_uptodate
= 0;
669 static inline void cris_update_cc_x(DisasContext
*dc
)
671 /* Save the x flag state at the time of the cc snapshot. */
672 if (dc
->flagx_known
) {
673 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
676 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
677 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
679 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
680 dc
->cc_x_uptodate
= 1;
684 /* Update cc prior to executing ALU op. Needs source operands untouched. */
685 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
686 TCGv dst
, TCGv src
, int size
)
689 cris_update_cc_op(dc
, op
, size
);
690 tcg_gen_mov_tl(cc_src
, src
);
698 && op
!= CC_OP_LSL
) {
699 tcg_gen_mov_tl(cc_dest
, dst
);
702 cris_update_cc_x(dc
);
706 /* Update cc after executing ALU op. needs the result. */
707 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
710 tcg_gen_mov_tl(cc_result
, res
);
714 /* Returns one if the write back stage should execute. */
715 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
716 TCGv dst
, TCGv a
, TCGv b
, int size
)
718 /* Emit the ALU insns. */
721 tcg_gen_add_tl(dst
, a
, b
);
722 /* Extended arithmetics. */
723 t_gen_addx_carry(dc
, dst
);
726 tcg_gen_add_tl(dst
, a
, b
);
727 t_gen_add_flag(dst
, 0); /* C_FLAG. */
730 tcg_gen_add_tl(dst
, a
, b
);
731 t_gen_add_flag(dst
, 8); /* R_FLAG. */
734 tcg_gen_sub_tl(dst
, a
, b
);
735 /* Extended arithmetics. */
736 t_gen_subx_carry(dc
, dst
);
739 tcg_gen_mov_tl(dst
, b
);
742 tcg_gen_or_tl(dst
, a
, b
);
745 tcg_gen_and_tl(dst
, a
, b
);
748 tcg_gen_xor_tl(dst
, a
, b
);
751 t_gen_lsl(dst
, a
, b
);
754 t_gen_lsr(dst
, a
, b
);
757 t_gen_asr(dst
, a
, b
);
760 tcg_gen_neg_tl(dst
, b
);
761 /* Extended arithmetics. */
762 t_gen_subx_carry(dc
, dst
);
765 gen_helper_lz(dst
, b
);
768 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
771 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
774 t_gen_cris_dstep(dst
, a
, b
);
777 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
782 l1
= gen_new_label();
783 tcg_gen_mov_tl(dst
, a
);
784 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
785 tcg_gen_mov_tl(dst
, b
);
790 tcg_gen_sub_tl(dst
, a
, b
);
791 /* Extended arithmetics. */
792 t_gen_subx_carry(dc
, dst
);
795 qemu_log("illegal ALU op.\n");
801 tcg_gen_andi_tl(dst
, dst
, 0xff);
802 } else if (size
== 2) {
803 tcg_gen_andi_tl(dst
, dst
, 0xffff);
807 static void cris_alu(DisasContext
*dc
, int op
,
808 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
815 if (op
== CC_OP_CMP
) {
816 tmp
= tcg_temp_new();
818 } else if (size
== 4) {
822 tmp
= tcg_temp_new();
826 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
827 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
828 cris_update_result(dc
, tmp
);
833 tcg_gen_andi_tl(d
, d
, ~0xff);
835 tcg_gen_andi_tl(d
, d
, ~0xffff);
837 tcg_gen_or_tl(d
, d
, tmp
);
839 if (!TCGV_EQUAL(tmp
, d
)) {
844 static int arith_cc(DisasContext
*dc
)
848 case CC_OP_ADDC
: return 1;
849 case CC_OP_ADD
: return 1;
850 case CC_OP_SUB
: return 1;
851 case CC_OP_DSTEP
: return 1;
852 case CC_OP_LSL
: return 1;
853 case CC_OP_LSR
: return 1;
854 case CC_OP_ASR
: return 1;
855 case CC_OP_CMP
: return 1;
856 case CC_OP_NEG
: return 1;
857 case CC_OP_OR
: return 1;
858 case CC_OP_AND
: return 1;
859 case CC_OP_XOR
: return 1;
860 case CC_OP_MULU
: return 1;
861 case CC_OP_MULS
: return 1;
869 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
871 int arith_opt
, move_opt
;
873 /* TODO: optimize more condition codes. */
876 * If the flags are live, we've gotta look into the bits of CCS.
877 * Otherwise, if we just did an arithmetic operation we try to
878 * evaluate the condition code faster.
880 * When this function is done, T0 should be non-zero if the condition
883 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
884 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
887 if ((arith_opt
|| move_opt
)
888 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
889 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
890 cc_result
, tcg_const_tl(0));
892 cris_evaluate_flags(dc
);
894 cpu_PR
[PR_CCS
], Z_FLAG
);
898 if ((arith_opt
|| move_opt
)
899 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
900 tcg_gen_mov_tl(cc
, cc_result
);
902 cris_evaluate_flags(dc
);
903 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
905 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
909 cris_evaluate_flags(dc
);
910 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
913 cris_evaluate_flags(dc
);
914 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
915 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
918 cris_evaluate_flags(dc
);
919 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
922 cris_evaluate_flags(dc
);
923 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
925 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
928 if (arith_opt
|| move_opt
) {
931 if (dc
->cc_size
== 1) {
933 } else if (dc
->cc_size
== 2) {
937 tcg_gen_shri_tl(cc
, cc_result
, bits
);
938 tcg_gen_xori_tl(cc
, cc
, 1);
940 cris_evaluate_flags(dc
);
941 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
943 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
947 if (arith_opt
|| move_opt
) {
950 if (dc
->cc_size
== 1) {
952 } else if (dc
->cc_size
== 2) {
956 tcg_gen_shri_tl(cc
, cc_result
, bits
);
957 tcg_gen_andi_tl(cc
, cc
, 1);
959 cris_evaluate_flags(dc
);
960 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
965 cris_evaluate_flags(dc
);
966 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
970 cris_evaluate_flags(dc
);
974 tmp
= tcg_temp_new();
975 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
977 /* Overlay the C flag on top of the Z. */
978 tcg_gen_shli_tl(cc
, tmp
, 2);
979 tcg_gen_and_tl(cc
, tmp
, cc
);
980 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
986 cris_evaluate_flags(dc
);
987 /* Overlay the V flag on top of the N. */
988 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
991 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
992 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
995 cris_evaluate_flags(dc
);
996 /* Overlay the V flag on top of the N. */
997 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1000 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1003 cris_evaluate_flags(dc
);
1010 /* To avoid a shift we overlay everything on
1012 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1013 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1015 tcg_gen_xori_tl(z
, z
, 2);
1017 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1018 tcg_gen_xori_tl(n
, n
, 2);
1019 tcg_gen_and_tl(cc
, z
, n
);
1020 tcg_gen_andi_tl(cc
, cc
, 2);
1027 cris_evaluate_flags(dc
);
1034 /* To avoid a shift we overlay everything on
1036 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1037 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1039 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1040 tcg_gen_or_tl(cc
, z
, n
);
1041 tcg_gen_andi_tl(cc
, cc
, 2);
1048 cris_evaluate_flags(dc
);
1049 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1052 tcg_gen_movi_tl(cc
, 1);
1060 static void cris_store_direct_jmp(DisasContext
*dc
)
1062 /* Store the direct jmp state into the cpu-state. */
1063 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1064 if (dc
->jmp
== JMP_DIRECT
) {
1065 tcg_gen_movi_tl(env_btaken
, 1);
1067 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1068 dc
->jmp
= JMP_INDIRECT
;
1072 static void cris_prepare_cc_branch (DisasContext
*dc
,
1073 int offset
, int cond
)
1075 /* This helps us re-schedule the micro-code to insns in delay-slots
1076 before the actual jump. */
1077 dc
->delayed_branch
= 2;
1078 dc
->jmp
= JMP_DIRECT_CC
;
1079 dc
->jmp_pc
= dc
->pc
+ offset
;
1081 gen_tst_cc(dc
, env_btaken
, cond
);
1082 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1086 /* jumps, when the dest is in a live reg for example. Direct should be set
1087 when the dest addr is constant to allow tb chaining. */
1088 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1090 /* This helps us re-schedule the micro-code to insns in delay-slots
1091 before the actual jump. */
1092 dc
->delayed_branch
= 2;
1094 if (type
== JMP_INDIRECT
) {
1095 tcg_gen_movi_tl(env_btaken
, 1);
1099 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1101 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1103 /* If we get a fault on a delayslot we must keep the jmp state in
1104 the cpu-state to be able to re-execute the jmp. */
1105 if (dc
->delayed_branch
== 1) {
1106 cris_store_direct_jmp(dc
);
1109 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1112 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1113 unsigned int size
, int sign
)
1115 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1117 /* If we get a fault on a delayslot we must keep the jmp state in
1118 the cpu-state to be able to re-execute the jmp. */
1119 if (dc
->delayed_branch
== 1) {
1120 cris_store_direct_jmp(dc
);
1123 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1124 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1127 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1130 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1132 /* If we get a fault on a delayslot we must keep the jmp state in
1133 the cpu-state to be able to re-execute the jmp. */
1134 if (dc
->delayed_branch
== 1) {
1135 cris_store_direct_jmp(dc
);
1139 /* Conditional writes. We only support the kind were X and P are known
1140 at translation time. */
1141 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1143 cris_evaluate_flags(dc
);
1144 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1148 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1150 if (dc
->flagx_known
&& dc
->flags_x
) {
1151 cris_evaluate_flags(dc
);
1152 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1156 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1159 tcg_gen_ext8s_i32(d
, s
);
1160 } else if (size
== 2) {
1161 tcg_gen_ext16s_i32(d
, s
);
1162 } else if (!TCGV_EQUAL(d
, s
)) {
1163 tcg_gen_mov_tl(d
, s
);
1167 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1170 tcg_gen_ext8u_i32(d
, s
);
1171 } else if (size
== 2) {
1172 tcg_gen_ext16u_i32(d
, s
);
1173 } else if (!TCGV_EQUAL(d
, s
)) {
1174 tcg_gen_mov_tl(d
, s
);
1179 static char memsize_char(int size
)
1182 case 1: return 'b'; break;
1183 case 2: return 'w'; break;
1184 case 4: return 'd'; break;
1192 static inline unsigned int memsize_z(DisasContext
*dc
)
1194 return dc
->zsize
+ 1;
1197 static inline unsigned int memsize_zz(DisasContext
*dc
)
1199 switch (dc
->zzsize
) {
1207 static inline void do_postinc (DisasContext
*dc
, int size
)
1210 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1214 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1215 int size
, int s_ext
, TCGv dst
)
1218 t_gen_sext(dst
, cpu_R
[rs
], size
);
1220 t_gen_zext(dst
, cpu_R
[rs
], size
);
1224 /* Prepare T0 and T1 for a register alu operation.
1225 s_ext decides if the operand1 should be sign-extended or zero-extended when
1227 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1228 int size
, int s_ext
, TCGv dst
, TCGv src
)
1230 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1233 t_gen_sext(dst
, cpu_R
[rd
], size
);
1235 t_gen_zext(dst
, cpu_R
[rd
], size
);
1239 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1240 int s_ext
, int memsize
, TCGv dst
)
1248 is_imm
= rs
== 15 && dc
->postinc
;
1250 /* Load [$rs] onto T1. */
1252 insn_len
= 2 + memsize
;
1257 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1258 tcg_gen_movi_tl(dst
, imm
);
1261 cris_flush_cc_state(dc
);
1262 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1264 t_gen_sext(dst
, dst
, memsize
);
1266 t_gen_zext(dst
, dst
, memsize
);
1272 /* Prepare T0 and T1 for a memory + alu operation.
1273 s_ext decides if the operand1 should be sign-extended or zero-extended when
1275 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1276 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1280 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1281 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1286 static const char *cc_name(int cc
)
1288 static const char *cc_names
[16] = {
1289 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1290 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1293 return cc_names
[cc
];
1297 /* Start of insn decoders. */
1299 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1303 uint32_t cond
= dc
->op2
;
1305 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1306 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1309 offset
|= sign
<< 8;
1310 offset
= sign_extend(offset
, 8);
1312 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1314 /* op2 holds the condition-code. */
1315 cris_cc_mask(dc
, 0);
1316 cris_prepare_cc_branch(dc
, offset
, cond
);
1319 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1323 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1324 imm
= sign_extend(dc
->op1
, 7);
1326 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1327 cris_cc_mask(dc
, 0);
1328 /* Fetch register operand, */
1329 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1333 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1335 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1337 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1339 cris_cc_mask(dc
, CC_MASK_NZVC
);
1341 cris_alu(dc
, CC_OP_ADD
,
1342 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1345 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1349 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1350 imm
= sign_extend(dc
->op1
, 5);
1351 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1353 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1356 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1358 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1360 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1362 cris_cc_mask(dc
, CC_MASK_NZVC
);
1363 cris_alu(dc
, CC_OP_SUB
,
1364 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1367 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1370 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1371 imm
= sign_extend(dc
->op1
, 5);
1373 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1374 cris_cc_mask(dc
, CC_MASK_NZVC
);
1376 cris_alu(dc
, CC_OP_CMP
,
1377 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1380 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1383 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1384 imm
= sign_extend(dc
->op1
, 5);
1386 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1387 cris_cc_mask(dc
, CC_MASK_NZ
);
1389 cris_alu(dc
, CC_OP_AND
,
1390 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1393 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1396 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1397 imm
= sign_extend(dc
->op1
, 5);
1398 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1399 cris_cc_mask(dc
, CC_MASK_NZ
);
1401 cris_alu(dc
, CC_OP_OR
,
1402 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1405 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1407 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1408 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1410 cris_cc_mask(dc
, CC_MASK_NZ
);
1411 cris_evaluate_flags(dc
);
1412 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1413 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1414 cris_alu(dc
, CC_OP_MOVE
,
1415 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1416 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1417 dc
->flags_uptodate
= 1;
1420 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1422 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1423 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1424 cris_cc_mask(dc
, CC_MASK_NZ
);
1426 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1427 cris_alu(dc
, CC_OP_MOVE
,
1429 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1432 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1434 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1435 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1437 cris_cc_mask(dc
, CC_MASK_NZ
);
1439 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1441 cris_alu(dc
, CC_OP_MOVE
,
1443 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1446 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1448 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1449 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1451 cris_cc_mask(dc
, CC_MASK_NZ
);
1453 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1454 cris_alu(dc
, CC_OP_MOVE
,
1456 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1460 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1462 int size
= memsize_zz(dc
);
1464 LOG_DIS("move.%c $r%u, $r%u\n",
1465 memsize_char(size
), dc
->op1
, dc
->op2
);
1467 cris_cc_mask(dc
, CC_MASK_NZ
);
1469 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1470 cris_cc_mask(dc
, CC_MASK_NZ
);
1471 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1472 cris_update_cc_x(dc
);
1473 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1477 t0
= tcg_temp_new();
1478 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1479 cris_alu(dc
, CC_OP_MOVE
,
1481 cpu_R
[dc
->op2
], t0
, size
);
1487 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1491 LOG_DIS("s%s $r%u\n",
1492 cc_name(cond
), dc
->op1
);
1497 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1498 l1
= gen_new_label();
1499 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1500 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1503 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1506 cris_cc_mask(dc
, 0);
1510 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1513 t
[0] = cpu_R
[dc
->op2
];
1514 t
[1] = cpu_R
[dc
->op1
];
1516 t
[0] = tcg_temp_new();
1517 t
[1] = tcg_temp_new();
1521 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1524 tcg_temp_free(t
[0]);
1525 tcg_temp_free(t
[1]);
1529 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1532 int size
= memsize_zz(dc
);
1534 LOG_DIS("and.%c $r%u, $r%u\n",
1535 memsize_char(size
), dc
->op1
, dc
->op2
);
1537 cris_cc_mask(dc
, CC_MASK_NZ
);
1539 cris_alu_alloc_temps(dc
, size
, t
);
1540 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1541 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1542 cris_alu_free_temps(dc
, size
, t
);
1546 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1549 LOG_DIS("lz $r%u, $r%u\n",
1551 cris_cc_mask(dc
, CC_MASK_NZ
);
1552 t0
= tcg_temp_new();
1553 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1554 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1559 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1562 int size
= memsize_zz(dc
);
1564 LOG_DIS("lsl.%c $r%u, $r%u\n",
1565 memsize_char(size
), dc
->op1
, dc
->op2
);
1567 cris_cc_mask(dc
, CC_MASK_NZ
);
1568 cris_alu_alloc_temps(dc
, size
, t
);
1569 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1570 tcg_gen_andi_tl(t
[1], t
[1], 63);
1571 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1572 cris_alu_alloc_temps(dc
, size
, t
);
1576 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1579 int size
= memsize_zz(dc
);
1581 LOG_DIS("lsr.%c $r%u, $r%u\n",
1582 memsize_char(size
), dc
->op1
, dc
->op2
);
1584 cris_cc_mask(dc
, CC_MASK_NZ
);
1585 cris_alu_alloc_temps(dc
, size
, t
);
1586 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1587 tcg_gen_andi_tl(t
[1], t
[1], 63);
1588 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1589 cris_alu_free_temps(dc
, size
, t
);
1593 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1596 int size
= memsize_zz(dc
);
1598 LOG_DIS("asr.%c $r%u, $r%u\n",
1599 memsize_char(size
), dc
->op1
, dc
->op2
);
1601 cris_cc_mask(dc
, CC_MASK_NZ
);
1602 cris_alu_alloc_temps(dc
, size
, t
);
1603 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1604 tcg_gen_andi_tl(t
[1], t
[1], 63);
1605 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1606 cris_alu_free_temps(dc
, size
, t
);
1610 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1613 int size
= memsize_zz(dc
);
1615 LOG_DIS("muls.%c $r%u, $r%u\n",
1616 memsize_char(size
), dc
->op1
, dc
->op2
);
1617 cris_cc_mask(dc
, CC_MASK_NZV
);
1618 cris_alu_alloc_temps(dc
, size
, t
);
1619 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1621 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1622 cris_alu_free_temps(dc
, size
, t
);
1626 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1629 int size
= memsize_zz(dc
);
1631 LOG_DIS("mulu.%c $r%u, $r%u\n",
1632 memsize_char(size
), dc
->op1
, dc
->op2
);
1633 cris_cc_mask(dc
, CC_MASK_NZV
);
1634 cris_alu_alloc_temps(dc
, size
, t
);
1635 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1637 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1638 cris_alu_alloc_temps(dc
, size
, t
);
1643 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1645 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1646 cris_cc_mask(dc
, CC_MASK_NZ
);
1647 cris_alu(dc
, CC_OP_DSTEP
,
1648 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1652 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1655 int size
= memsize_zz(dc
);
1656 LOG_DIS("xor.%c $r%u, $r%u\n",
1657 memsize_char(size
), dc
->op1
, dc
->op2
);
1658 BUG_ON(size
!= 4); /* xor is dword. */
1659 cris_cc_mask(dc
, CC_MASK_NZ
);
1660 cris_alu_alloc_temps(dc
, size
, t
);
1661 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1663 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1664 cris_alu_free_temps(dc
, size
, t
);
1668 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1671 int size
= memsize_zz(dc
);
1672 LOG_DIS("bound.%c $r%u, $r%u\n",
1673 memsize_char(size
), dc
->op1
, dc
->op2
);
1674 cris_cc_mask(dc
, CC_MASK_NZ
);
1675 l0
= tcg_temp_local_new();
1676 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1677 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1682 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1685 int size
= memsize_zz(dc
);
1686 LOG_DIS("cmp.%c $r%u, $r%u\n",
1687 memsize_char(size
), dc
->op1
, dc
->op2
);
1688 cris_cc_mask(dc
, CC_MASK_NZVC
);
1689 cris_alu_alloc_temps(dc
, size
, t
);
1690 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1692 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1693 cris_alu_free_temps(dc
, size
, t
);
1697 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1701 LOG_DIS("abs $r%u, $r%u\n",
1703 cris_cc_mask(dc
, CC_MASK_NZ
);
1705 t0
= tcg_temp_new();
1706 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1707 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1708 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1711 cris_alu(dc
, CC_OP_MOVE
,
1712 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1716 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1719 int size
= memsize_zz(dc
);
1720 LOG_DIS("add.%c $r%u, $r%u\n",
1721 memsize_char(size
), dc
->op1
, dc
->op2
);
1722 cris_cc_mask(dc
, CC_MASK_NZVC
);
1723 cris_alu_alloc_temps(dc
, size
, t
);
1724 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1726 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1727 cris_alu_free_temps(dc
, size
, t
);
1731 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1733 LOG_DIS("addc $r%u, $r%u\n",
1735 cris_evaluate_flags(dc
);
1736 /* Set for this insn. */
1737 dc
->flagx_known
= 1;
1738 dc
->flags_x
= X_FLAG
;
1740 cris_cc_mask(dc
, CC_MASK_NZVC
);
1741 cris_alu(dc
, CC_OP_ADDC
,
1742 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1746 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1748 LOG_DIS("mcp $p%u, $r%u\n",
1750 cris_evaluate_flags(dc
);
1751 cris_cc_mask(dc
, CC_MASK_RNZV
);
1752 cris_alu(dc
, CC_OP_MCP
,
1753 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1758 static char * swapmode_name(int mode
, char *modename
) {
1761 modename
[i
++] = 'n';
1764 modename
[i
++] = 'w';
1767 modename
[i
++] = 'b';
1770 modename
[i
++] = 'r';
1777 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1783 LOG_DIS("swap%s $r%u\n",
1784 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1786 cris_cc_mask(dc
, CC_MASK_NZ
);
1787 t0
= tcg_temp_new();
1788 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1790 tcg_gen_not_tl(t0
, t0
);
1793 t_gen_swapw(t0
, t0
);
1796 t_gen_swapb(t0
, t0
);
1799 t_gen_swapr(t0
, t0
);
1801 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1806 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1809 int size
= memsize_zz(dc
);
1810 LOG_DIS("or.%c $r%u, $r%u\n",
1811 memsize_char(size
), dc
->op1
, dc
->op2
);
1812 cris_cc_mask(dc
, CC_MASK_NZ
);
1813 cris_alu_alloc_temps(dc
, size
, t
);
1814 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1815 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1816 cris_alu_free_temps(dc
, size
, t
);
1820 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1823 LOG_DIS("addi.%c $r%u, $r%u\n",
1824 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1825 cris_cc_mask(dc
, 0);
1826 t0
= tcg_temp_new();
1827 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1828 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1833 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1836 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1837 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1838 cris_cc_mask(dc
, 0);
1839 t0
= tcg_temp_new();
1840 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1841 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1846 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1849 int size
= memsize_zz(dc
);
1850 LOG_DIS("neg.%c $r%u, $r%u\n",
1851 memsize_char(size
), dc
->op1
, dc
->op2
);
1852 cris_cc_mask(dc
, CC_MASK_NZVC
);
1853 cris_alu_alloc_temps(dc
, size
, t
);
1854 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1856 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1857 cris_alu_free_temps(dc
, size
, t
);
1861 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1863 LOG_DIS("btst $r%u, $r%u\n",
1865 cris_cc_mask(dc
, CC_MASK_NZ
);
1866 cris_evaluate_flags(dc
);
1867 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1868 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1869 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1870 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1871 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1872 dc
->flags_uptodate
= 1;
1876 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1879 int size
= memsize_zz(dc
);
1880 LOG_DIS("sub.%c $r%u, $r%u\n",
1881 memsize_char(size
), dc
->op1
, dc
->op2
);
1882 cris_cc_mask(dc
, CC_MASK_NZVC
);
1883 cris_alu_alloc_temps(dc
, size
, t
);
1884 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1885 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1886 cris_alu_free_temps(dc
, size
, t
);
1890 /* Zero extension. From size to dword. */
1891 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1894 int size
= memsize_z(dc
);
1895 LOG_DIS("movu.%c $r%u, $r%u\n",
1899 cris_cc_mask(dc
, CC_MASK_NZ
);
1900 t0
= tcg_temp_new();
1901 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1902 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1907 /* Sign extension. From size to dword. */
1908 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1911 int size
= memsize_z(dc
);
1912 LOG_DIS("movs.%c $r%u, $r%u\n",
1916 cris_cc_mask(dc
, CC_MASK_NZ
);
1917 t0
= tcg_temp_new();
1918 /* Size can only be qi or hi. */
1919 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1920 cris_alu(dc
, CC_OP_MOVE
,
1921 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1926 /* zero extension. From size to dword. */
1927 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1930 int size
= memsize_z(dc
);
1931 LOG_DIS("addu.%c $r%u, $r%u\n",
1935 cris_cc_mask(dc
, CC_MASK_NZVC
);
1936 t0
= tcg_temp_new();
1937 /* Size can only be qi or hi. */
1938 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1939 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1944 /* Sign extension. From size to dword. */
1945 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1948 int size
= memsize_z(dc
);
1949 LOG_DIS("adds.%c $r%u, $r%u\n",
1953 cris_cc_mask(dc
, CC_MASK_NZVC
);
1954 t0
= tcg_temp_new();
1955 /* Size can only be qi or hi. */
1956 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1957 cris_alu(dc
, CC_OP_ADD
,
1958 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1963 /* Zero extension. From size to dword. */
1964 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1967 int size
= memsize_z(dc
);
1968 LOG_DIS("subu.%c $r%u, $r%u\n",
1972 cris_cc_mask(dc
, CC_MASK_NZVC
);
1973 t0
= tcg_temp_new();
1974 /* Size can only be qi or hi. */
1975 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1976 cris_alu(dc
, CC_OP_SUB
,
1977 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1982 /* Sign extension. From size to dword. */
1983 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1986 int size
= memsize_z(dc
);
1987 LOG_DIS("subs.%c $r%u, $r%u\n",
1991 cris_cc_mask(dc
, CC_MASK_NZVC
);
1992 t0
= tcg_temp_new();
1993 /* Size can only be qi or hi. */
1994 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1995 cris_alu(dc
, CC_OP_SUB
,
1996 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2001 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
2004 int set
= (~dc
->opcode
>> 2) & 1;
2007 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2008 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2009 if (set
&& flags
== 0) {
2012 } else if (!set
&& (flags
& 0x20)) {
2015 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2018 /* User space is not allowed to touch these. Silently ignore. */
2019 if (dc
->tb_flags
& U_FLAG
) {
2020 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2023 if (flags
& X_FLAG
) {
2024 dc
->flagx_known
= 1;
2026 dc
->flags_x
= X_FLAG
;
2032 /* Break the TB if any of the SPI flag changes. */
2033 if (flags
& (P_FLAG
| S_FLAG
)) {
2034 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2035 dc
->is_jmp
= DISAS_UPDATE
;
2036 dc
->cpustate_changed
= 1;
2039 /* For the I flag, only act on posedge. */
2040 if ((flags
& I_FLAG
)) {
2041 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2042 dc
->is_jmp
= DISAS_UPDATE
;
2043 dc
->cpustate_changed
= 1;
2047 /* Simply decode the flags. */
2048 cris_evaluate_flags(dc
);
2049 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2050 cris_update_cc_x(dc
);
2051 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2054 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2055 /* Enter user mode. */
2056 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2057 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2058 dc
->cpustate_changed
= 1;
2060 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2062 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2065 dc
->flags_uptodate
= 1;
2070 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2072 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2073 cris_cc_mask(dc
, 0);
2074 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2075 tcg_const_tl(dc
->op1
));
2078 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2080 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2081 cris_cc_mask(dc
, 0);
2082 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2083 tcg_const_tl(dc
->op2
));
2087 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2090 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2091 cris_cc_mask(dc
, 0);
2093 t
[0] = tcg_temp_new();
2094 if (dc
->op2
== PR_CCS
) {
2095 cris_evaluate_flags(dc
);
2096 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2097 if (dc
->tb_flags
& U_FLAG
) {
2098 t
[1] = tcg_temp_new();
2099 /* User space is not allowed to touch all flags. */
2100 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2101 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2102 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2103 tcg_temp_free(t
[1]);
2106 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2109 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2110 if (dc
->op2
== PR_CCS
) {
2111 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2112 dc
->flags_uptodate
= 1;
2114 tcg_temp_free(t
[0]);
2117 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2120 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2121 cris_cc_mask(dc
, 0);
2123 if (dc
->op2
== PR_CCS
) {
2124 cris_evaluate_flags(dc
);
2127 if (dc
->op2
== PR_DZ
) {
2128 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2130 t0
= tcg_temp_new();
2131 t_gen_mov_TN_preg(t0
, dc
->op2
);
2132 cris_alu(dc
, CC_OP_MOVE
,
2133 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2134 preg_sizes
[dc
->op2
]);
2140 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2142 int memsize
= memsize_zz(dc
);
2144 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2145 memsize_char(memsize
),
2146 dc
->op1
, dc
->postinc
? "+]" : "]",
2150 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2151 cris_cc_mask(dc
, CC_MASK_NZ
);
2152 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2153 cris_update_cc_x(dc
);
2154 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2158 t0
= tcg_temp_new();
2159 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2160 cris_cc_mask(dc
, CC_MASK_NZ
);
2161 cris_alu(dc
, CC_OP_MOVE
,
2162 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2165 do_postinc(dc
, memsize
);
2169 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2171 t
[0] = tcg_temp_new();
2172 t
[1] = tcg_temp_new();
2175 static inline void cris_alu_m_free_temps(TCGv
*t
)
2177 tcg_temp_free(t
[0]);
2178 tcg_temp_free(t
[1]);
2181 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2184 int memsize
= memsize_z(dc
);
2186 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2187 memsize_char(memsize
),
2188 dc
->op1
, dc
->postinc
? "+]" : "]",
2191 cris_alu_m_alloc_temps(t
);
2193 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2194 cris_cc_mask(dc
, CC_MASK_NZ
);
2195 cris_alu(dc
, CC_OP_MOVE
,
2196 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2197 do_postinc(dc
, memsize
);
2198 cris_alu_m_free_temps(t
);
2202 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2205 int memsize
= memsize_z(dc
);
2207 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2208 memsize_char(memsize
),
2209 dc
->op1
, dc
->postinc
? "+]" : "]",
2212 cris_alu_m_alloc_temps(t
);
2214 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2215 cris_cc_mask(dc
, CC_MASK_NZVC
);
2216 cris_alu(dc
, CC_OP_ADD
,
2217 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2218 do_postinc(dc
, memsize
);
2219 cris_alu_m_free_temps(t
);
2223 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2226 int memsize
= memsize_z(dc
);
2228 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2229 memsize_char(memsize
),
2230 dc
->op1
, dc
->postinc
? "+]" : "]",
2233 cris_alu_m_alloc_temps(t
);
2235 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2236 cris_cc_mask(dc
, CC_MASK_NZVC
);
2237 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2238 do_postinc(dc
, memsize
);
2239 cris_alu_m_free_temps(t
);
2243 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2246 int memsize
= memsize_z(dc
);
2248 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2249 memsize_char(memsize
),
2250 dc
->op1
, dc
->postinc
? "+]" : "]",
2253 cris_alu_m_alloc_temps(t
);
2255 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2256 cris_cc_mask(dc
, CC_MASK_NZVC
);
2257 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2258 do_postinc(dc
, memsize
);
2259 cris_alu_m_free_temps(t
);
2263 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2266 int memsize
= memsize_z(dc
);
2268 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2269 memsize_char(memsize
),
2270 dc
->op1
, dc
->postinc
? "+]" : "]",
2273 cris_alu_m_alloc_temps(t
);
2275 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2276 cris_cc_mask(dc
, CC_MASK_NZVC
);
2277 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2278 do_postinc(dc
, memsize
);
2279 cris_alu_m_free_temps(t
);
2283 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2286 int memsize
= memsize_z(dc
);
2289 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2290 memsize_char(memsize
),
2291 dc
->op1
, dc
->postinc
? "+]" : "]",
2294 cris_alu_m_alloc_temps(t
);
2295 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2296 cris_cc_mask(dc
, CC_MASK_NZ
);
2297 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2298 do_postinc(dc
, memsize
);
2299 cris_alu_m_free_temps(t
);
2303 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2306 int memsize
= memsize_z(dc
);
2308 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2309 memsize_char(memsize
),
2310 dc
->op1
, dc
->postinc
? "+]" : "]",
2313 cris_alu_m_alloc_temps(t
);
2314 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2315 cris_cc_mask(dc
, CC_MASK_NZVC
);
2316 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2317 do_postinc(dc
, memsize
);
2318 cris_alu_m_free_temps(t
);
2322 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2325 int memsize
= memsize_z(dc
);
2327 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2328 memsize_char(memsize
),
2329 dc
->op1
, dc
->postinc
? "+]" : "]",
2332 cris_alu_m_alloc_temps(t
);
2333 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2334 cris_cc_mask(dc
, CC_MASK_NZVC
);
2335 cris_alu(dc
, CC_OP_CMP
,
2336 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2338 do_postinc(dc
, memsize
);
2339 cris_alu_m_free_temps(t
);
2343 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2346 int memsize
= memsize_zz(dc
);
2348 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2349 memsize_char(memsize
),
2350 dc
->op1
, dc
->postinc
? "+]" : "]",
2353 cris_alu_m_alloc_temps(t
);
2354 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2355 cris_cc_mask(dc
, CC_MASK_NZVC
);
2356 cris_alu(dc
, CC_OP_CMP
,
2357 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2359 do_postinc(dc
, memsize
);
2360 cris_alu_m_free_temps(t
);
2364 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2367 int memsize
= memsize_zz(dc
);
2369 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2370 memsize_char(memsize
),
2371 dc
->op1
, dc
->postinc
? "+]" : "]",
2374 cris_evaluate_flags(dc
);
2376 cris_alu_m_alloc_temps(t
);
2377 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2378 cris_cc_mask(dc
, CC_MASK_NZ
);
2379 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2381 cris_alu(dc
, CC_OP_CMP
,
2382 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2383 do_postinc(dc
, memsize
);
2384 cris_alu_m_free_temps(t
);
2388 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2391 int memsize
= memsize_zz(dc
);
2393 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2394 memsize_char(memsize
),
2395 dc
->op1
, dc
->postinc
? "+]" : "]",
2398 cris_alu_m_alloc_temps(t
);
2399 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2400 cris_cc_mask(dc
, CC_MASK_NZ
);
2401 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2402 do_postinc(dc
, memsize
);
2403 cris_alu_m_free_temps(t
);
2407 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2410 int memsize
= memsize_zz(dc
);
2412 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2413 memsize_char(memsize
),
2414 dc
->op1
, dc
->postinc
? "+]" : "]",
2417 cris_alu_m_alloc_temps(t
);
2418 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2419 cris_cc_mask(dc
, CC_MASK_NZVC
);
2420 cris_alu(dc
, CC_OP_ADD
,
2421 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2422 do_postinc(dc
, memsize
);
2423 cris_alu_m_free_temps(t
);
2427 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2430 int memsize
= memsize_zz(dc
);
2432 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2433 memsize_char(memsize
),
2434 dc
->op1
, dc
->postinc
? "+]" : "]",
2437 cris_alu_m_alloc_temps(t
);
2438 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2439 cris_cc_mask(dc
, 0);
2440 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2441 do_postinc(dc
, memsize
);
2442 cris_alu_m_free_temps(t
);
2446 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2449 int memsize
= memsize_zz(dc
);
2451 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2452 memsize_char(memsize
),
2453 dc
->op1
, dc
->postinc
? "+]" : "]",
2456 l
[0] = tcg_temp_local_new();
2457 l
[1] = tcg_temp_local_new();
2458 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2459 cris_cc_mask(dc
, CC_MASK_NZ
);
2460 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2461 do_postinc(dc
, memsize
);
2462 tcg_temp_free(l
[0]);
2463 tcg_temp_free(l
[1]);
2467 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2471 LOG_DIS("addc [$r%u%s, $r%u\n",
2472 dc
->op1
, dc
->postinc
? "+]" : "]",
2475 cris_evaluate_flags(dc
);
2477 /* Set for this insn. */
2478 dc
->flagx_known
= 1;
2479 dc
->flags_x
= X_FLAG
;
2481 cris_alu_m_alloc_temps(t
);
2482 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2483 cris_cc_mask(dc
, CC_MASK_NZVC
);
2484 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2486 cris_alu_m_free_temps(t
);
2490 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2493 int memsize
= memsize_zz(dc
);
2495 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2496 memsize_char(memsize
),
2497 dc
->op1
, dc
->postinc
? "+]" : "]",
2498 dc
->op2
, dc
->ir
, dc
->zzsize
);
2500 cris_alu_m_alloc_temps(t
);
2501 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2502 cris_cc_mask(dc
, CC_MASK_NZVC
);
2503 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2504 do_postinc(dc
, memsize
);
2505 cris_alu_m_free_temps(t
);
2509 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2512 int memsize
= memsize_zz(dc
);
2514 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2515 memsize_char(memsize
),
2516 dc
->op1
, dc
->postinc
? "+]" : "]",
2519 cris_alu_m_alloc_temps(t
);
2520 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2521 cris_cc_mask(dc
, CC_MASK_NZ
);
2522 cris_alu(dc
, CC_OP_OR
,
2523 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2524 do_postinc(dc
, memsize
);
2525 cris_alu_m_free_temps(t
);
2529 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2532 int memsize
= memsize_zz(dc
);
2535 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2536 memsize_char(memsize
),
2538 dc
->postinc
? "+]" : "]",
2541 cris_alu_m_alloc_temps(t
);
2542 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2543 cris_cc_mask(dc
, 0);
2544 if (dc
->op2
== PR_CCS
) {
2545 cris_evaluate_flags(dc
);
2546 if (dc
->tb_flags
& U_FLAG
) {
2547 /* User space is not allowed to touch all flags. */
2548 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2549 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2550 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2554 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2556 do_postinc(dc
, memsize
);
2557 cris_alu_m_free_temps(t
);
2561 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2566 memsize
= preg_sizes
[dc
->op2
];
2568 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2569 memsize_char(memsize
),
2570 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2572 /* prepare store. Address in T0, value in T1. */
2573 if (dc
->op2
== PR_CCS
) {
2574 cris_evaluate_flags(dc
);
2576 t0
= tcg_temp_new();
2577 t_gen_mov_TN_preg(t0
, dc
->op2
);
2578 cris_flush_cc_state(dc
);
2579 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2582 cris_cc_mask(dc
, 0);
2584 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2589 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2595 int nr
= dc
->op2
+ 1;
2597 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2598 dc
->postinc
? "+]" : "]", dc
->op2
);
2600 addr
= tcg_temp_new();
2601 /* There are probably better ways of doing this. */
2602 cris_flush_cc_state(dc
);
2603 for (i
= 0; i
< (nr
>> 1); i
++) {
2604 tmp
[i
] = tcg_temp_new_i64();
2605 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2606 gen_load64(dc
, tmp
[i
], addr
);
2609 tmp32
= tcg_temp_new_i32();
2610 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2611 gen_load(dc
, tmp32
, addr
, 4, 0);
2615 tcg_temp_free(addr
);
2617 for (i
= 0; i
< (nr
>> 1); i
++) {
2618 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2619 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2620 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2621 tcg_temp_free_i64(tmp
[i
]);
2624 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2625 tcg_temp_free(tmp32
);
2628 /* writeback the updated pointer value. */
2630 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2633 /* gen_load might want to evaluate the previous insns flags. */
2634 cris_cc_mask(dc
, 0);
2638 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2644 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2645 dc
->postinc
? "+]" : "]");
2647 cris_flush_cc_state(dc
);
2649 tmp
= tcg_temp_new();
2650 addr
= tcg_temp_new();
2651 tcg_gen_movi_tl(tmp
, 4);
2652 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2653 for (i
= 0; i
<= dc
->op2
; i
++) {
2654 /* Displace addr. */
2655 /* Perform the store. */
2656 gen_store(dc
, addr
, cpu_R
[i
], 4);
2657 tcg_gen_add_tl(addr
, addr
, tmp
);
2660 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2662 cris_cc_mask(dc
, 0);
2664 tcg_temp_free(addr
);
2668 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2672 memsize
= memsize_zz(dc
);
2674 LOG_DIS("move.%c $r%u, [$r%u]\n",
2675 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2677 /* prepare store. */
2678 cris_flush_cc_state(dc
);
2679 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2682 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2684 cris_cc_mask(dc
, 0);
2688 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2690 LOG_DIS("lapcq %x, $r%u\n",
2691 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2692 cris_cc_mask(dc
, 0);
2693 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2697 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2705 cris_cc_mask(dc
, 0);
2706 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2707 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2711 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2715 /* Jump to special reg. */
2716 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2718 LOG_DIS("jump $p%u\n", dc
->op2
);
2720 if (dc
->op2
== PR_CCS
) {
2721 cris_evaluate_flags(dc
);
2723 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2724 /* rete will often have low bit set to indicate delayslot. */
2725 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2726 cris_cc_mask(dc
, 0);
2727 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2731 /* Jump and save. */
2732 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2734 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2735 cris_cc_mask(dc
, 0);
2736 /* Store the return address in Pd. */
2737 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2741 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2743 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2747 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2751 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2753 LOG_DIS("jas 0x%x\n", imm
);
2754 cris_cc_mask(dc
, 0);
2755 /* Store the return address in Pd. */
2756 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2759 cris_prepare_jmp(dc
, JMP_DIRECT
);
2763 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2767 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2769 LOG_DIS("jasc 0x%x\n", imm
);
2770 cris_cc_mask(dc
, 0);
2771 /* Store the return address in Pd. */
2772 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2775 cris_prepare_jmp(dc
, JMP_DIRECT
);
2779 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2781 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2782 cris_cc_mask(dc
, 0);
2783 /* Store the return address in Pd. */
2784 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2785 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2786 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2790 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2793 uint32_t cond
= dc
->op2
;
2795 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2797 LOG_DIS("b%s %d pc=%x dst=%x\n",
2798 cc_name(cond
), offset
,
2799 dc
->pc
, dc
->pc
+ offset
);
2801 cris_cc_mask(dc
, 0);
2802 /* op2 holds the condition-code. */
2803 cris_prepare_cc_branch(dc
, offset
, cond
);
2807 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2811 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2813 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2814 cris_cc_mask(dc
, 0);
2815 /* Store the return address in Pd. */
2816 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2818 dc
->jmp_pc
= dc
->pc
+ simm
;
2819 cris_prepare_jmp(dc
, JMP_DIRECT
);
2823 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2826 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2828 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2829 cris_cc_mask(dc
, 0);
2830 /* Store the return address in Pd. */
2831 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2833 dc
->jmp_pc
= dc
->pc
+ simm
;
2834 cris_prepare_jmp(dc
, JMP_DIRECT
);
2838 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2840 cris_cc_mask(dc
, 0);
2842 if (dc
->op2
== 15) {
2843 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2844 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2845 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2846 t_gen_raise_exception(EXCP_HLT
);
2850 switch (dc
->op2
& 7) {
2854 cris_evaluate_flags(dc
);
2855 gen_helper_rfe(cpu_env
);
2856 dc
->is_jmp
= DISAS_UPDATE
;
2861 cris_evaluate_flags(dc
);
2862 gen_helper_rfn(cpu_env
);
2863 dc
->is_jmp
= DISAS_UPDATE
;
2866 LOG_DIS("break %d\n", dc
->op1
);
2867 cris_evaluate_flags(dc
);
2869 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2871 /* Breaks start at 16 in the exception vector. */
2872 t_gen_mov_env_TN(trap_vector
,
2873 tcg_const_tl(dc
->op1
+ 16));
2874 t_gen_raise_exception(EXCP_BREAK
);
2875 dc
->is_jmp
= DISAS_UPDATE
;
2878 printf("op2=%x\n", dc
->op2
);
2886 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2891 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2896 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2898 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2899 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2905 static struct decoder_info
{
2910 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2912 /* Order matters here. */
2913 {DEC_MOVEQ
, dec_moveq
},
2914 {DEC_BTSTQ
, dec_btstq
},
2915 {DEC_CMPQ
, dec_cmpq
},
2916 {DEC_ADDOQ
, dec_addoq
},
2917 {DEC_ADDQ
, dec_addq
},
2918 {DEC_SUBQ
, dec_subq
},
2919 {DEC_ANDQ
, dec_andq
},
2921 {DEC_ASRQ
, dec_asrq
},
2922 {DEC_LSLQ
, dec_lslq
},
2923 {DEC_LSRQ
, dec_lsrq
},
2924 {DEC_BCCQ
, dec_bccq
},
2926 {DEC_BCC_IM
, dec_bcc_im
},
2927 {DEC_JAS_IM
, dec_jas_im
},
2928 {DEC_JAS_R
, dec_jas_r
},
2929 {DEC_JASC_IM
, dec_jasc_im
},
2930 {DEC_JASC_R
, dec_jasc_r
},
2931 {DEC_BAS_IM
, dec_bas_im
},
2932 {DEC_BASC_IM
, dec_basc_im
},
2933 {DEC_JUMP_P
, dec_jump_p
},
2934 {DEC_LAPC_IM
, dec_lapc_im
},
2935 {DEC_LAPCQ
, dec_lapcq
},
2937 {DEC_RFE_ETC
, dec_rfe_etc
},
2938 {DEC_ADDC_MR
, dec_addc_mr
},
2940 {DEC_MOVE_MP
, dec_move_mp
},
2941 {DEC_MOVE_PM
, dec_move_pm
},
2942 {DEC_MOVEM_MR
, dec_movem_mr
},
2943 {DEC_MOVEM_RM
, dec_movem_rm
},
2944 {DEC_MOVE_PR
, dec_move_pr
},
2945 {DEC_SCC_R
, dec_scc_r
},
2946 {DEC_SETF
, dec_setclrf
},
2947 {DEC_CLEARF
, dec_setclrf
},
2949 {DEC_MOVE_SR
, dec_move_sr
},
2950 {DEC_MOVE_RP
, dec_move_rp
},
2951 {DEC_SWAP_R
, dec_swap_r
},
2952 {DEC_ABS_R
, dec_abs_r
},
2953 {DEC_LZ_R
, dec_lz_r
},
2954 {DEC_MOVE_RS
, dec_move_rs
},
2955 {DEC_BTST_R
, dec_btst_r
},
2956 {DEC_ADDC_R
, dec_addc_r
},
2958 {DEC_DSTEP_R
, dec_dstep_r
},
2959 {DEC_XOR_R
, dec_xor_r
},
2960 {DEC_MCP_R
, dec_mcp_r
},
2961 {DEC_CMP_R
, dec_cmp_r
},
2963 {DEC_ADDI_R
, dec_addi_r
},
2964 {DEC_ADDI_ACR
, dec_addi_acr
},
2966 {DEC_ADD_R
, dec_add_r
},
2967 {DEC_SUB_R
, dec_sub_r
},
2969 {DEC_ADDU_R
, dec_addu_r
},
2970 {DEC_ADDS_R
, dec_adds_r
},
2971 {DEC_SUBU_R
, dec_subu_r
},
2972 {DEC_SUBS_R
, dec_subs_r
},
2973 {DEC_LSL_R
, dec_lsl_r
},
2975 {DEC_AND_R
, dec_and_r
},
2976 {DEC_OR_R
, dec_or_r
},
2977 {DEC_BOUND_R
, dec_bound_r
},
2978 {DEC_ASR_R
, dec_asr_r
},
2979 {DEC_LSR_R
, dec_lsr_r
},
2981 {DEC_MOVU_R
, dec_movu_r
},
2982 {DEC_MOVS_R
, dec_movs_r
},
2983 {DEC_NEG_R
, dec_neg_r
},
2984 {DEC_MOVE_R
, dec_move_r
},
2986 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2987 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2989 {DEC_MULS_R
, dec_muls_r
},
2990 {DEC_MULU_R
, dec_mulu_r
},
2992 {DEC_ADDU_M
, dec_addu_m
},
2993 {DEC_ADDS_M
, dec_adds_m
},
2994 {DEC_SUBU_M
, dec_subu_m
},
2995 {DEC_SUBS_M
, dec_subs_m
},
2997 {DEC_CMPU_M
, dec_cmpu_m
},
2998 {DEC_CMPS_M
, dec_cmps_m
},
2999 {DEC_MOVU_M
, dec_movu_m
},
3000 {DEC_MOVS_M
, dec_movs_m
},
3002 {DEC_CMP_M
, dec_cmp_m
},
3003 {DEC_ADDO_M
, dec_addo_m
},
3004 {DEC_BOUND_M
, dec_bound_m
},
3005 {DEC_ADD_M
, dec_add_m
},
3006 {DEC_SUB_M
, dec_sub_m
},
3007 {DEC_AND_M
, dec_and_m
},
3008 {DEC_OR_M
, dec_or_m
},
3009 {DEC_MOVE_RM
, dec_move_rm
},
3010 {DEC_TEST_M
, dec_test_m
},
3011 {DEC_MOVE_MR
, dec_move_mr
},
3016 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3021 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3022 tcg_gen_debug_insn_start(dc
->pc
);
3025 /* Load a halfword onto the instruction register. */
3026 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3028 /* Now decode it. */
3029 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3030 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3031 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3032 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3033 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3034 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3036 /* Large switch for all insns. */
3037 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3038 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3039 insn_len
= decinfo
[i
].dec(env
, dc
);
3044 #if !defined(CONFIG_USER_ONLY)
3045 /* Single-stepping ? */
3046 if (dc
->tb_flags
& S_FLAG
) {
3049 l1
= gen_new_label();
3050 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3051 /* We treat SPC as a break with an odd trap vector. */
3052 cris_evaluate_flags(dc
);
3053 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3054 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3055 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3056 t_gen_raise_exception(EXCP_BREAK
);
3063 static void check_breakpoint(CPUCRISState
*env
, DisasContext
*dc
)
3065 CPUState
*cs
= CPU(cris_env_get_cpu(env
));
3068 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
3069 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
3070 if (bp
->pc
== dc
->pc
) {
3071 cris_evaluate_flags(dc
);
3072 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3073 t_gen_raise_exception(EXCP_DEBUG
);
3074 dc
->is_jmp
= DISAS_UPDATE
;
3080 #include "translate_v10.c"
3083 * Delay slots on QEMU/CRIS.
3085 * If an exception hits on a delayslot, the core will let ERP (the Exception
3086 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3087 * to give SW a hint that the exception actually hit on the dslot.
3089 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3090 * the core and any jmp to an odd addresses will mask off that lsb. It is
3091 * simply there to let sw know there was an exception on a dslot.
3093 * When the software returns from an exception, the branch will re-execute.
3094 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3095 * and the branch and delayslot dont share pages.
3097 * The TB contaning the branch insn will set up env->btarget and evaluate
3098 * env->btaken. When the translation loop exits we will note that the branch
3099 * sequence is broken and let env->dslot be the size of the branch insn (those
3102 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3103 * set). It will also expect to have env->dslot setup with the size of the
3104 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3105 * will execute the dslot and take the branch, either to btarget or just one
3108 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3109 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3110 * branch and set lsb). Then env->dslot gets cleared so that the exception
3111 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3112 * masked off and we will reexecute the branch insn.
3116 /* generate intermediate code for basic block 'tb'. */
3118 gen_intermediate_code_internal(CRISCPU
*cpu
, TranslationBlock
*tb
,
3121 CPUState
*cs
= CPU(cpu
);
3122 CPUCRISState
*env
= &cpu
->env
;
3123 uint16_t *gen_opc_end
;
3125 unsigned int insn_len
;
3127 struct DisasContext ctx
;
3128 struct DisasContext
*dc
= &ctx
;
3129 uint32_t next_page_start
;
3134 if (env
->pregs
[PR_VR
] == 32) {
3135 dc
->decoder
= crisv32_decoder
;
3136 dc
->clear_locked_irq
= 0;
3138 dc
->decoder
= crisv10_decoder
;
3139 dc
->clear_locked_irq
= 1;
3142 /* Odd PC indicates that branch is rexecuting due to exception in the
3143 * delayslot, like in real hw.
3145 pc_start
= tb
->pc
& ~1;
3149 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
3151 dc
->is_jmp
= DISAS_NEXT
;
3154 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3155 dc
->flags_uptodate
= 1;
3156 dc
->flagx_known
= 1;
3157 dc
->flags_x
= tb
->flags
& X_FLAG
;
3158 dc
->cc_x_uptodate
= 0;
3161 dc
->clear_prefix
= 0;
3163 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3164 dc
->cc_size_uptodate
= -1;
3166 /* Decode TB flags. */
3167 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3168 | X_FLAG
| PFIX_FLAG
);
3169 dc
->delayed_branch
= !!(tb
->flags
& 7);
3170 if (dc
->delayed_branch
) {
3171 dc
->jmp
= JMP_INDIRECT
;
3173 dc
->jmp
= JMP_NOJMP
;
3176 dc
->cpustate_changed
= 0;
3178 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3180 "srch=%d pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3186 search_pc
, dc
->pc
, dc
->ppc
,
3187 (uint64_t)tb
->flags
,
3188 env
->btarget
, (unsigned)tb
->flags
& 7,
3190 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3191 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3192 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3193 env
->regs
[8], env
->regs
[9],
3194 env
->regs
[10], env
->regs
[11],
3195 env
->regs
[12], env
->regs
[13],
3196 env
->regs
[14], env
->regs
[15]);
3197 qemu_log("--------------\n");
3198 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3201 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3204 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3205 if (max_insns
== 0) {
3206 max_insns
= CF_COUNT_MASK
;
3211 check_breakpoint(env
, dc
);
3214 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3218 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3221 if (dc
->delayed_branch
== 1) {
3222 tcg_ctx
.gen_opc_pc
[lj
] = dc
->ppc
| 1;
3224 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
3226 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3227 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
3231 LOG_DIS("%8.8x:\t", dc
->pc
);
3233 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3238 insn_len
= dc
->decoder(env
, dc
);
3242 cris_clear_x_flag(dc
);
3246 /* Check for delayed branches here. If we do it before
3247 actually generating any host code, the simulator will just
3248 loop doing nothing for on this program location. */
3249 if (dc
->delayed_branch
) {
3250 dc
->delayed_branch
--;
3251 if (dc
->delayed_branch
== 0) {
3252 if (tb
->flags
& 7) {
3253 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3255 if (dc
->cpustate_changed
|| !dc
->flagx_known
3256 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3257 cris_store_direct_jmp(dc
);
3260 if (dc
->clear_locked_irq
) {
3261 dc
->clear_locked_irq
= 0;
3262 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3265 if (dc
->jmp
== JMP_DIRECT_CC
) {
3268 l1
= gen_new_label();
3269 cris_evaluate_flags(dc
);
3271 /* Conditional jmp. */
3272 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3274 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3276 gen_goto_tb(dc
, 0, dc
->pc
);
3277 dc
->is_jmp
= DISAS_TB_JUMP
;
3278 dc
->jmp
= JMP_NOJMP
;
3279 } else if (dc
->jmp
== JMP_DIRECT
) {
3280 cris_evaluate_flags(dc
);
3281 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3282 dc
->is_jmp
= DISAS_TB_JUMP
;
3283 dc
->jmp
= JMP_NOJMP
;
3285 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3286 dc
->is_jmp
= DISAS_JUMP
;
3292 /* If we are rexecuting a branch due to exceptions on
3293 delay slots dont break. */
3294 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3297 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3298 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
3300 && (dc
->pc
< next_page_start
)
3301 && num_insns
< max_insns
);
3303 if (dc
->clear_locked_irq
) {
3304 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3309 if (tb
->cflags
& CF_LAST_IO
)
3311 /* Force an update if the per-tb cpu state has changed. */
3312 if (dc
->is_jmp
== DISAS_NEXT
3313 && (dc
->cpustate_changed
|| !dc
->flagx_known
3314 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3315 dc
->is_jmp
= DISAS_UPDATE
;
3316 tcg_gen_movi_tl(env_pc
, npc
);
3318 /* Broken branch+delayslot sequence. */
3319 if (dc
->delayed_branch
== 1) {
3320 /* Set env->dslot to the size of the branch insn. */
3321 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3322 cris_store_direct_jmp(dc
);
3325 cris_evaluate_flags(dc
);
3327 if (unlikely(cs
->singlestep_enabled
)) {
3328 if (dc
->is_jmp
== DISAS_NEXT
) {
3329 tcg_gen_movi_tl(env_pc
, npc
);
3331 t_gen_raise_exception(EXCP_DEBUG
);
3333 switch (dc
->is_jmp
) {
3335 gen_goto_tb(dc
, 1, npc
);
3340 /* indicate that the hash table must be used
3341 to find the next TB */
3346 /* nothing more to generate */
3350 gen_tb_end(tb
, num_insns
);
3351 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3353 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3356 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3359 tb
->size
= dc
->pc
- pc_start
;
3360 tb
->icount
= num_insns
;
3365 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3366 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
3368 qemu_log("\nisize=%d osize=%td\n",
3369 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
);
3375 void gen_intermediate_code (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3377 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, false);
3380 void gen_intermediate_code_pc (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3382 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, true);
3385 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
3388 CRISCPU
*cpu
= CRIS_CPU(cs
);
3389 CPUCRISState
*env
= &cpu
->env
;
3397 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3398 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3399 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3401 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3404 for (i
= 0; i
< 16; i
++) {
3405 cpu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3406 if ((i
+ 1) % 4 == 0) {
3407 cpu_fprintf(f
, "\n");
3410 cpu_fprintf(f
, "\nspecial regs:\n");
3411 for (i
= 0; i
< 16; i
++) {
3412 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3413 if ((i
+ 1) % 4 == 0) {
3414 cpu_fprintf(f
, "\n");
3417 srs
= env
->pregs
[PR_SRS
];
3418 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3419 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3420 for (i
= 0; i
< 16; i
++) {
3421 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3422 i
, env
->sregs
[srs
][i
]);
3423 if ((i
+ 1) % 4 == 0) {
3424 cpu_fprintf(f
, "\n");
3428 cpu_fprintf(f
, "\n\n");
3432 void cris_initialize_tcg(void)
3436 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3437 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3438 offsetof(CPUCRISState
, cc_x
), "cc_x");
3439 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3440 offsetof(CPUCRISState
, cc_src
), "cc_src");
3441 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3442 offsetof(CPUCRISState
, cc_dest
),
3444 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3445 offsetof(CPUCRISState
, cc_result
),
3447 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3448 offsetof(CPUCRISState
, cc_op
), "cc_op");
3449 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3450 offsetof(CPUCRISState
, cc_size
),
3452 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3453 offsetof(CPUCRISState
, cc_mask
),
3456 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3457 offsetof(CPUCRISState
, pc
),
3459 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3460 offsetof(CPUCRISState
, btarget
),
3462 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3463 offsetof(CPUCRISState
, btaken
),
3465 for (i
= 0; i
< 16; i
++) {
3466 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3467 offsetof(CPUCRISState
, regs
[i
]),
3470 for (i
= 0; i
< 16; i
++) {
3471 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3472 offsetof(CPUCRISState
, pregs
[i
]),
3477 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
, int pc_pos
)
3479 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];