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"
31 #include "crisv32-decode.h"
38 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
40 # define LOG_DIS(...) do { } while (0)
44 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
45 #define BUG_ON(x) ({if (x) BUG();})
49 /* Used by the decoder. */
50 #define EXTRACT_FIELD(src, start, end) \
51 (((src) >> start) & ((1 << (end - start + 1)) - 1))
53 #define CC_MASK_NZ 0xc
54 #define CC_MASK_NZV 0xe
55 #define CC_MASK_NZVC 0xf
56 #define CC_MASK_RNZV 0x10e
58 static TCGv_ptr cpu_env
;
59 static TCGv cpu_R
[16];
60 static TCGv cpu_PR
[16];
64 static TCGv cc_result
;
69 static TCGv env_btaken
;
70 static TCGv env_btarget
;
73 #include "exec/gen-icount.h"
75 /* This is the state at translation time. */
76 typedef struct DisasContext
{
81 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
86 unsigned int zsize
, zzsize
;
100 int cc_size_uptodate
; /* -1 invalid or last written value. */
102 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
103 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
104 int flagx_known
; /* Wether or not flags_x has the x flag known at
108 int clear_x
; /* Clear x after this insn? */
109 int clear_prefix
; /* Clear prefix after this insn? */
110 int clear_locked_irq
; /* Clear the irq lockout. */
111 int cpustate_changed
;
112 unsigned int tb_flags
; /* tb dependent flags. */
117 #define JMP_DIRECT_CC 2
118 #define JMP_INDIRECT 3
119 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
124 struct TranslationBlock
*tb
;
125 int singlestep_enabled
;
128 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
130 printf("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
131 qemu_log("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
132 cpu_abort(CPU(dc
->cpu
), "%s:%d\n", file
, line
);
135 static const char *regnames
[] =
137 "$r0", "$r1", "$r2", "$r3",
138 "$r4", "$r5", "$r6", "$r7",
139 "$r8", "$r9", "$r10", "$r11",
140 "$r12", "$r13", "$sp", "$acr",
142 static const char *pregnames
[] =
144 "$bz", "$vr", "$pid", "$srs",
145 "$wz", "$exs", "$eda", "$mof",
146 "$dz", "$ebp", "$erp", "$srp",
147 "$nrp", "$ccs", "$usp", "$spc",
150 /* We need this table to handle preg-moves with implicit width. */
151 static int preg_sizes
[] = {
162 #define t_gen_mov_TN_env(tn, member) \
163 _t_gen_mov_TN_env((tn), offsetof(CPUCRISState, member))
164 #define t_gen_mov_env_TN(member, tn) \
165 _t_gen_mov_env_TN(offsetof(CPUCRISState, member), (tn))
167 static inline void t_gen_mov_TN_reg(TCGv tn
, int r
)
169 if (r
< 0 || r
> 15) {
170 fprintf(stderr
, "wrong register read $r%d\n", r
);
172 tcg_gen_mov_tl(tn
, cpu_R
[r
]);
174 static inline void t_gen_mov_reg_TN(int r
, TCGv tn
)
176 if (r
< 0 || r
> 15) {
177 fprintf(stderr
, "wrong register write $r%d\n", r
);
179 tcg_gen_mov_tl(cpu_R
[r
], tn
);
182 static inline void _t_gen_mov_TN_env(TCGv tn
, int offset
)
184 if (offset
> sizeof(CPUCRISState
)) {
185 fprintf(stderr
, "wrong load from env from off=%d\n", offset
);
187 tcg_gen_ld_tl(tn
, cpu_env
, offset
);
189 static inline void _t_gen_mov_env_TN(int offset
, TCGv tn
)
191 if (offset
> sizeof(CPUCRISState
)) {
192 fprintf(stderr
, "wrong store to env at off=%d\n", offset
);
194 tcg_gen_st_tl(tn
, cpu_env
, offset
);
197 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
199 if (r
< 0 || r
> 15) {
200 fprintf(stderr
, "wrong register read $p%d\n", r
);
202 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
203 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
204 } else if (r
== PR_VR
) {
205 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
207 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
210 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
212 if (r
< 0 || r
> 15) {
213 fprintf(stderr
, "wrong register write $p%d\n", r
);
215 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
217 } else if (r
== PR_SRS
) {
218 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
221 gen_helper_tlb_flush_pid(cpu_env
, tn
);
223 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
224 gen_helper_spc_write(cpu_env
, tn
);
225 } else if (r
== PR_CCS
) {
226 dc
->cpustate_changed
= 1;
228 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
232 /* Sign extend at translation time. */
233 static int sign_extend(unsigned int val
, unsigned int width
)
245 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
246 unsigned int size
, unsigned int sign
)
253 r
= cpu_ldl_code(env
, addr
);
259 r
= cpu_ldsw_code(env
, addr
);
261 r
= cpu_lduw_code(env
, addr
);
268 r
= cpu_ldsb_code(env
, addr
);
270 r
= cpu_ldub_code(env
, addr
);
275 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
281 static void cris_lock_irq(DisasContext
*dc
)
283 dc
->clear_locked_irq
= 0;
284 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
287 static inline void t_gen_raise_exception(uint32_t index
)
289 TCGv_i32 tmp
= tcg_const_i32(index
);
290 gen_helper_raise_exception(cpu_env
, tmp
);
291 tcg_temp_free_i32(tmp
);
294 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
299 t_31
= tcg_const_tl(31);
300 tcg_gen_shl_tl(d
, a
, b
);
302 tcg_gen_sub_tl(t0
, t_31
, b
);
303 tcg_gen_sar_tl(t0
, t0
, t_31
);
304 tcg_gen_and_tl(t0
, t0
, d
);
305 tcg_gen_xor_tl(d
, d
, t0
);
310 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
315 t_31
= tcg_temp_new();
316 tcg_gen_shr_tl(d
, a
, b
);
318 tcg_gen_movi_tl(t_31
, 31);
319 tcg_gen_sub_tl(t0
, t_31
, b
);
320 tcg_gen_sar_tl(t0
, t0
, t_31
);
321 tcg_gen_and_tl(t0
, t0
, d
);
322 tcg_gen_xor_tl(d
, d
, t0
);
327 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
332 t_31
= tcg_temp_new();
333 tcg_gen_sar_tl(d
, a
, b
);
335 tcg_gen_movi_tl(t_31
, 31);
336 tcg_gen_sub_tl(t0
, t_31
, b
);
337 tcg_gen_sar_tl(t0
, t0
, t_31
);
338 tcg_gen_or_tl(d
, d
, t0
);
343 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
347 l1
= gen_new_label();
354 tcg_gen_shli_tl(d
, a
, 1);
355 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
356 tcg_gen_sub_tl(d
, d
, b
);
360 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
370 tcg_gen_shli_tl(d
, a
, 1);
371 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
372 tcg_gen_sari_tl(t
, t
, 31);
373 tcg_gen_and_tl(t
, t
, b
);
374 tcg_gen_add_tl(d
, d
, t
);
378 /* Extended arithmetics on CRIS. */
379 static inline void t_gen_add_flag(TCGv d
, int flag
)
384 t_gen_mov_TN_preg(c
, PR_CCS
);
385 /* Propagate carry into d. */
386 tcg_gen_andi_tl(c
, c
, 1 << flag
);
388 tcg_gen_shri_tl(c
, c
, flag
);
390 tcg_gen_add_tl(d
, d
, c
);
394 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
396 if (dc
->flagx_known
) {
401 t_gen_mov_TN_preg(c
, PR_CCS
);
402 /* C flag is already at bit 0. */
403 tcg_gen_andi_tl(c
, c
, C_FLAG
);
404 tcg_gen_add_tl(d
, d
, c
);
412 t_gen_mov_TN_preg(x
, PR_CCS
);
413 tcg_gen_mov_tl(c
, x
);
415 /* Propagate carry into d if X is set. Branch free. */
416 tcg_gen_andi_tl(c
, c
, C_FLAG
);
417 tcg_gen_andi_tl(x
, x
, X_FLAG
);
418 tcg_gen_shri_tl(x
, x
, 4);
420 tcg_gen_and_tl(x
, x
, c
);
421 tcg_gen_add_tl(d
, d
, x
);
427 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
429 if (dc
->flagx_known
) {
434 t_gen_mov_TN_preg(c
, PR_CCS
);
435 /* C flag is already at bit 0. */
436 tcg_gen_andi_tl(c
, c
, C_FLAG
);
437 tcg_gen_sub_tl(d
, d
, c
);
445 t_gen_mov_TN_preg(x
, PR_CCS
);
446 tcg_gen_mov_tl(c
, x
);
448 /* Propagate carry into d if X is set. Branch free. */
449 tcg_gen_andi_tl(c
, c
, C_FLAG
);
450 tcg_gen_andi_tl(x
, x
, X_FLAG
);
451 tcg_gen_shri_tl(x
, x
, 4);
453 tcg_gen_and_tl(x
, x
, c
);
454 tcg_gen_sub_tl(d
, d
, x
);
460 /* Swap the two bytes within each half word of the s operand.
461 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
462 static inline void t_gen_swapb(TCGv d
, TCGv s
)
467 org_s
= tcg_temp_new();
469 /* d and s may refer to the same object. */
470 tcg_gen_mov_tl(org_s
, s
);
471 tcg_gen_shli_tl(t
, org_s
, 8);
472 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
473 tcg_gen_shri_tl(t
, org_s
, 8);
474 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
475 tcg_gen_or_tl(d
, d
, t
);
477 tcg_temp_free(org_s
);
480 /* Swap the halfwords of the s operand. */
481 static inline void t_gen_swapw(TCGv d
, TCGv s
)
484 /* d and s refer the same object. */
486 tcg_gen_mov_tl(t
, s
);
487 tcg_gen_shli_tl(d
, t
, 16);
488 tcg_gen_shri_tl(t
, t
, 16);
489 tcg_gen_or_tl(d
, d
, t
);
493 /* Reverse the within each byte.
494 T0 = (((T0 << 7) & 0x80808080) |
495 ((T0 << 5) & 0x40404040) |
496 ((T0 << 3) & 0x20202020) |
497 ((T0 << 1) & 0x10101010) |
498 ((T0 >> 1) & 0x08080808) |
499 ((T0 >> 3) & 0x04040404) |
500 ((T0 >> 5) & 0x02020202) |
501 ((T0 >> 7) & 0x01010101));
503 static inline void t_gen_swapr(TCGv d
, TCGv s
)
506 int shift
; /* LSL when positive, LSR when negative. */
521 /* d and s refer the same object. */
523 org_s
= tcg_temp_new();
524 tcg_gen_mov_tl(org_s
, s
);
526 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
527 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
528 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
529 if (bitrev
[i
].shift
>= 0) {
530 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
532 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
534 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
535 tcg_gen_or_tl(d
, d
, t
);
538 tcg_temp_free(org_s
);
541 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
545 l1
= gen_new_label();
547 /* Conditional jmp. */
548 tcg_gen_mov_tl(env_pc
, pc_false
);
549 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
550 tcg_gen_mov_tl(env_pc
, pc_true
);
554 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
556 TranslationBlock
*tb
;
558 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
560 tcg_gen_movi_tl(env_pc
, dest
);
561 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
563 tcg_gen_movi_tl(env_pc
, dest
);
568 static inline void cris_clear_x_flag(DisasContext
*dc
)
570 if (dc
->flagx_known
&& dc
->flags_x
) {
571 dc
->flags_uptodate
= 0;
578 static void cris_flush_cc_state(DisasContext
*dc
)
580 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
581 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
582 dc
->cc_size_uptodate
= dc
->cc_size
;
584 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
585 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
588 static void cris_evaluate_flags(DisasContext
*dc
)
590 if (dc
->flags_uptodate
) {
594 cris_flush_cc_state(dc
);
598 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
599 cpu_PR
[PR_CCS
], cc_src
,
603 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
604 cpu_PR
[PR_CCS
], cc_result
,
608 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
609 cpu_PR
[PR_CCS
], cc_result
,
619 switch (dc
->cc_size
) {
621 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
622 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
625 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
626 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
629 gen_helper_evaluate_flags(cpu_env
);
638 if (dc
->cc_size
== 4) {
639 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
640 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
642 gen_helper_evaluate_flags(cpu_env
);
647 switch (dc
->cc_size
) {
649 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
650 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
653 gen_helper_evaluate_flags(cpu_env
);
659 if (dc
->flagx_known
) {
661 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
662 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
663 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
666 dc
->flags_uptodate
= 1;
669 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
678 /* Check if we need to evaluate the condition codes due to
680 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
682 /* TODO: optimize this case. It trigs all the time. */
683 cris_evaluate_flags(dc
);
689 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
693 dc
->flags_uptodate
= 0;
696 static inline void cris_update_cc_x(DisasContext
*dc
)
698 /* Save the x flag state at the time of the cc snapshot. */
699 if (dc
->flagx_known
) {
700 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
703 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
704 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
706 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
707 dc
->cc_x_uptodate
= 1;
711 /* Update cc prior to executing ALU op. Needs source operands untouched. */
712 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
713 TCGv dst
, TCGv src
, int size
)
716 cris_update_cc_op(dc
, op
, size
);
717 tcg_gen_mov_tl(cc_src
, src
);
725 && op
!= CC_OP_LSL
) {
726 tcg_gen_mov_tl(cc_dest
, dst
);
729 cris_update_cc_x(dc
);
733 /* Update cc after executing ALU op. needs the result. */
734 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
737 tcg_gen_mov_tl(cc_result
, res
);
741 /* Returns one if the write back stage should execute. */
742 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
743 TCGv dst
, TCGv a
, TCGv b
, int size
)
745 /* Emit the ALU insns. */
748 tcg_gen_add_tl(dst
, a
, b
);
749 /* Extended arithmetics. */
750 t_gen_addx_carry(dc
, dst
);
753 tcg_gen_add_tl(dst
, a
, b
);
754 t_gen_add_flag(dst
, 0); /* C_FLAG. */
757 tcg_gen_add_tl(dst
, a
, b
);
758 t_gen_add_flag(dst
, 8); /* R_FLAG. */
761 tcg_gen_sub_tl(dst
, a
, b
);
762 /* Extended arithmetics. */
763 t_gen_subx_carry(dc
, dst
);
766 tcg_gen_mov_tl(dst
, b
);
769 tcg_gen_or_tl(dst
, a
, b
);
772 tcg_gen_and_tl(dst
, a
, b
);
775 tcg_gen_xor_tl(dst
, a
, b
);
778 t_gen_lsl(dst
, a
, b
);
781 t_gen_lsr(dst
, a
, b
);
784 t_gen_asr(dst
, a
, b
);
787 tcg_gen_neg_tl(dst
, b
);
788 /* Extended arithmetics. */
789 t_gen_subx_carry(dc
, dst
);
792 gen_helper_lz(dst
, b
);
795 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
798 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
801 t_gen_cris_dstep(dst
, a
, b
);
804 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
809 l1
= gen_new_label();
810 tcg_gen_mov_tl(dst
, a
);
811 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
812 tcg_gen_mov_tl(dst
, b
);
817 tcg_gen_sub_tl(dst
, a
, b
);
818 /* Extended arithmetics. */
819 t_gen_subx_carry(dc
, dst
);
822 qemu_log("illegal ALU op.\n");
828 tcg_gen_andi_tl(dst
, dst
, 0xff);
829 } else if (size
== 2) {
830 tcg_gen_andi_tl(dst
, dst
, 0xffff);
834 static void cris_alu(DisasContext
*dc
, int op
,
835 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
842 if (op
== CC_OP_CMP
) {
843 tmp
= tcg_temp_new();
845 } else if (size
== 4) {
849 tmp
= tcg_temp_new();
853 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
854 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
855 cris_update_result(dc
, tmp
);
860 tcg_gen_andi_tl(d
, d
, ~0xff);
862 tcg_gen_andi_tl(d
, d
, ~0xffff);
864 tcg_gen_or_tl(d
, d
, tmp
);
866 if (!TCGV_EQUAL(tmp
, d
)) {
871 static int arith_cc(DisasContext
*dc
)
875 case CC_OP_ADDC
: return 1;
876 case CC_OP_ADD
: return 1;
877 case CC_OP_SUB
: return 1;
878 case CC_OP_DSTEP
: return 1;
879 case CC_OP_LSL
: return 1;
880 case CC_OP_LSR
: return 1;
881 case CC_OP_ASR
: return 1;
882 case CC_OP_CMP
: return 1;
883 case CC_OP_NEG
: return 1;
884 case CC_OP_OR
: return 1;
885 case CC_OP_AND
: return 1;
886 case CC_OP_XOR
: return 1;
887 case CC_OP_MULU
: return 1;
888 case CC_OP_MULS
: return 1;
896 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
898 int arith_opt
, move_opt
;
900 /* TODO: optimize more condition codes. */
903 * If the flags are live, we've gotta look into the bits of CCS.
904 * Otherwise, if we just did an arithmetic operation we try to
905 * evaluate the condition code faster.
907 * When this function is done, T0 should be non-zero if the condition
910 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
911 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
914 if ((arith_opt
|| move_opt
)
915 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
916 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
917 cc_result
, tcg_const_tl(0));
919 cris_evaluate_flags(dc
);
921 cpu_PR
[PR_CCS
], Z_FLAG
);
925 if ((arith_opt
|| move_opt
)
926 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
927 tcg_gen_mov_tl(cc
, cc_result
);
929 cris_evaluate_flags(dc
);
930 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
932 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
936 cris_evaluate_flags(dc
);
937 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
940 cris_evaluate_flags(dc
);
941 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
942 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
945 cris_evaluate_flags(dc
);
946 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
949 cris_evaluate_flags(dc
);
950 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
952 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
955 if (arith_opt
|| move_opt
) {
958 if (dc
->cc_size
== 1) {
960 } else if (dc
->cc_size
== 2) {
964 tcg_gen_shri_tl(cc
, cc_result
, bits
);
965 tcg_gen_xori_tl(cc
, cc
, 1);
967 cris_evaluate_flags(dc
);
968 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
970 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
974 if (arith_opt
|| move_opt
) {
977 if (dc
->cc_size
== 1) {
979 } else if (dc
->cc_size
== 2) {
983 tcg_gen_shri_tl(cc
, cc_result
, bits
);
984 tcg_gen_andi_tl(cc
, cc
, 1);
986 cris_evaluate_flags(dc
);
987 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
992 cris_evaluate_flags(dc
);
993 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
997 cris_evaluate_flags(dc
);
1001 tmp
= tcg_temp_new();
1002 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
1004 /* Overlay the C flag on top of the Z. */
1005 tcg_gen_shli_tl(cc
, tmp
, 2);
1006 tcg_gen_and_tl(cc
, tmp
, cc
);
1007 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
1013 cris_evaluate_flags(dc
);
1014 /* Overlay the V flag on top of the N. */
1015 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1017 cpu_PR
[PR_CCS
], cc
);
1018 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1019 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
1022 cris_evaluate_flags(dc
);
1023 /* Overlay the V flag on top of the N. */
1024 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1026 cpu_PR
[PR_CCS
], cc
);
1027 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1030 cris_evaluate_flags(dc
);
1037 /* To avoid a shift we overlay everything on
1039 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1040 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1042 tcg_gen_xori_tl(z
, z
, 2);
1044 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1045 tcg_gen_xori_tl(n
, n
, 2);
1046 tcg_gen_and_tl(cc
, z
, n
);
1047 tcg_gen_andi_tl(cc
, cc
, 2);
1054 cris_evaluate_flags(dc
);
1061 /* To avoid a shift we overlay everything on
1063 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1064 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1066 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1067 tcg_gen_or_tl(cc
, z
, n
);
1068 tcg_gen_andi_tl(cc
, cc
, 2);
1075 cris_evaluate_flags(dc
);
1076 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1079 tcg_gen_movi_tl(cc
, 1);
1087 static void cris_store_direct_jmp(DisasContext
*dc
)
1089 /* Store the direct jmp state into the cpu-state. */
1090 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1091 if (dc
->jmp
== JMP_DIRECT
) {
1092 tcg_gen_movi_tl(env_btaken
, 1);
1094 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1095 dc
->jmp
= JMP_INDIRECT
;
1099 static void cris_prepare_cc_branch (DisasContext
*dc
,
1100 int offset
, int cond
)
1102 /* This helps us re-schedule the micro-code to insns in delay-slots
1103 before the actual jump. */
1104 dc
->delayed_branch
= 2;
1105 dc
->jmp
= JMP_DIRECT_CC
;
1106 dc
->jmp_pc
= dc
->pc
+ offset
;
1108 gen_tst_cc(dc
, env_btaken
, cond
);
1109 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1113 /* jumps, when the dest is in a live reg for example. Direct should be set
1114 when the dest addr is constant to allow tb chaining. */
1115 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1117 /* This helps us re-schedule the micro-code to insns in delay-slots
1118 before the actual jump. */
1119 dc
->delayed_branch
= 2;
1121 if (type
== JMP_INDIRECT
) {
1122 tcg_gen_movi_tl(env_btaken
, 1);
1126 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1128 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1130 /* If we get a fault on a delayslot we must keep the jmp state in
1131 the cpu-state to be able to re-execute the jmp. */
1132 if (dc
->delayed_branch
== 1) {
1133 cris_store_direct_jmp(dc
);
1136 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1139 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1140 unsigned int size
, int sign
)
1142 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1144 /* If we get a fault on a delayslot we must keep the jmp state in
1145 the cpu-state to be able to re-execute the jmp. */
1146 if (dc
->delayed_branch
== 1) {
1147 cris_store_direct_jmp(dc
);
1150 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1151 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1154 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1157 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1159 /* If we get a fault on a delayslot we must keep the jmp state in
1160 the cpu-state to be able to re-execute the jmp. */
1161 if (dc
->delayed_branch
== 1) {
1162 cris_store_direct_jmp(dc
);
1166 /* Conditional writes. We only support the kind were X and P are known
1167 at translation time. */
1168 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1170 cris_evaluate_flags(dc
);
1171 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1175 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1177 if (dc
->flagx_known
&& dc
->flags_x
) {
1178 cris_evaluate_flags(dc
);
1179 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1183 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1186 tcg_gen_ext8s_i32(d
, s
);
1187 } else if (size
== 2) {
1188 tcg_gen_ext16s_i32(d
, s
);
1189 } else if (!TCGV_EQUAL(d
, s
)) {
1190 tcg_gen_mov_tl(d
, s
);
1194 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1197 tcg_gen_ext8u_i32(d
, s
);
1198 } else if (size
== 2) {
1199 tcg_gen_ext16u_i32(d
, s
);
1200 } else if (!TCGV_EQUAL(d
, s
)) {
1201 tcg_gen_mov_tl(d
, s
);
1206 static char memsize_char(int size
)
1209 case 1: return 'b'; break;
1210 case 2: return 'w'; break;
1211 case 4: return 'd'; break;
1219 static inline unsigned int memsize_z(DisasContext
*dc
)
1221 return dc
->zsize
+ 1;
1224 static inline unsigned int memsize_zz(DisasContext
*dc
)
1226 switch (dc
->zzsize
) {
1234 static inline void do_postinc (DisasContext
*dc
, int size
)
1237 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1241 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1242 int size
, int s_ext
, TCGv dst
)
1245 t_gen_sext(dst
, cpu_R
[rs
], size
);
1247 t_gen_zext(dst
, cpu_R
[rs
], size
);
1251 /* Prepare T0 and T1 for a register alu operation.
1252 s_ext decides if the operand1 should be sign-extended or zero-extended when
1254 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1255 int size
, int s_ext
, TCGv dst
, TCGv src
)
1257 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1260 t_gen_sext(dst
, cpu_R
[rd
], size
);
1262 t_gen_zext(dst
, cpu_R
[rd
], size
);
1266 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1267 int s_ext
, int memsize
, TCGv dst
)
1275 is_imm
= rs
== 15 && dc
->postinc
;
1277 /* Load [$rs] onto T1. */
1279 insn_len
= 2 + memsize
;
1284 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1285 tcg_gen_movi_tl(dst
, imm
);
1288 cris_flush_cc_state(dc
);
1289 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1291 t_gen_sext(dst
, dst
, memsize
);
1293 t_gen_zext(dst
, dst
, memsize
);
1299 /* Prepare T0 and T1 for a memory + alu operation.
1300 s_ext decides if the operand1 should be sign-extended or zero-extended when
1302 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1303 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1307 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1308 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1313 static const char *cc_name(int cc
)
1315 static const char *cc_names
[16] = {
1316 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1317 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1320 return cc_names
[cc
];
1324 /* Start of insn decoders. */
1326 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1330 uint32_t cond
= dc
->op2
;
1332 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1333 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1336 offset
|= sign
<< 8;
1337 offset
= sign_extend(offset
, 8);
1339 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1341 /* op2 holds the condition-code. */
1342 cris_cc_mask(dc
, 0);
1343 cris_prepare_cc_branch(dc
, offset
, cond
);
1346 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1350 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1351 imm
= sign_extend(dc
->op1
, 7);
1353 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1354 cris_cc_mask(dc
, 0);
1355 /* Fetch register operand, */
1356 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1360 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1362 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1364 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1366 cris_cc_mask(dc
, CC_MASK_NZVC
);
1368 cris_alu(dc
, CC_OP_ADD
,
1369 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1372 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1376 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1377 imm
= sign_extend(dc
->op1
, 5);
1378 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1380 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1383 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1385 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1387 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1389 cris_cc_mask(dc
, CC_MASK_NZVC
);
1390 cris_alu(dc
, CC_OP_SUB
,
1391 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1394 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1397 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1398 imm
= sign_extend(dc
->op1
, 5);
1400 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1401 cris_cc_mask(dc
, CC_MASK_NZVC
);
1403 cris_alu(dc
, CC_OP_CMP
,
1404 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1407 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1410 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1411 imm
= sign_extend(dc
->op1
, 5);
1413 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1414 cris_cc_mask(dc
, CC_MASK_NZ
);
1416 cris_alu(dc
, CC_OP_AND
,
1417 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1420 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1423 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1424 imm
= sign_extend(dc
->op1
, 5);
1425 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1426 cris_cc_mask(dc
, CC_MASK_NZ
);
1428 cris_alu(dc
, CC_OP_OR
,
1429 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1432 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1434 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1435 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1437 cris_cc_mask(dc
, CC_MASK_NZ
);
1438 cris_evaluate_flags(dc
);
1439 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1440 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1441 cris_alu(dc
, CC_OP_MOVE
,
1442 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1443 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1444 dc
->flags_uptodate
= 1;
1447 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1449 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1450 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1451 cris_cc_mask(dc
, CC_MASK_NZ
);
1453 tcg_gen_sari_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);
1459 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1461 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1462 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1464 cris_cc_mask(dc
, CC_MASK_NZ
);
1466 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1468 cris_alu(dc
, CC_OP_MOVE
,
1470 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1473 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1475 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1476 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1478 cris_cc_mask(dc
, CC_MASK_NZ
);
1480 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1481 cris_alu(dc
, CC_OP_MOVE
,
1483 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1487 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1489 int size
= memsize_zz(dc
);
1491 LOG_DIS("move.%c $r%u, $r%u\n",
1492 memsize_char(size
), dc
->op1
, dc
->op2
);
1494 cris_cc_mask(dc
, CC_MASK_NZ
);
1496 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1497 cris_cc_mask(dc
, CC_MASK_NZ
);
1498 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1499 cris_update_cc_x(dc
);
1500 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1504 t0
= tcg_temp_new();
1505 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1506 cris_alu(dc
, CC_OP_MOVE
,
1508 cpu_R
[dc
->op2
], t0
, size
);
1514 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1518 LOG_DIS("s%s $r%u\n",
1519 cc_name(cond
), dc
->op1
);
1524 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1525 l1
= gen_new_label();
1526 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1527 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1530 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1533 cris_cc_mask(dc
, 0);
1537 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1540 t
[0] = cpu_R
[dc
->op2
];
1541 t
[1] = cpu_R
[dc
->op1
];
1543 t
[0] = tcg_temp_new();
1544 t
[1] = tcg_temp_new();
1548 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1551 tcg_temp_free(t
[0]);
1552 tcg_temp_free(t
[1]);
1556 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1559 int size
= memsize_zz(dc
);
1561 LOG_DIS("and.%c $r%u, $r%u\n",
1562 memsize_char(size
), dc
->op1
, dc
->op2
);
1564 cris_cc_mask(dc
, CC_MASK_NZ
);
1566 cris_alu_alloc_temps(dc
, size
, t
);
1567 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1568 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1569 cris_alu_free_temps(dc
, size
, t
);
1573 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1576 LOG_DIS("lz $r%u, $r%u\n",
1578 cris_cc_mask(dc
, CC_MASK_NZ
);
1579 t0
= tcg_temp_new();
1580 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1581 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1586 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1589 int size
= memsize_zz(dc
);
1591 LOG_DIS("lsl.%c $r%u, $r%u\n",
1592 memsize_char(size
), dc
->op1
, dc
->op2
);
1594 cris_cc_mask(dc
, CC_MASK_NZ
);
1595 cris_alu_alloc_temps(dc
, size
, t
);
1596 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1597 tcg_gen_andi_tl(t
[1], t
[1], 63);
1598 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1599 cris_alu_alloc_temps(dc
, size
, t
);
1603 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1606 int size
= memsize_zz(dc
);
1608 LOG_DIS("lsr.%c $r%u, $r%u\n",
1609 memsize_char(size
), dc
->op1
, dc
->op2
);
1611 cris_cc_mask(dc
, CC_MASK_NZ
);
1612 cris_alu_alloc_temps(dc
, size
, t
);
1613 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1614 tcg_gen_andi_tl(t
[1], t
[1], 63);
1615 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1616 cris_alu_free_temps(dc
, size
, t
);
1620 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1623 int size
= memsize_zz(dc
);
1625 LOG_DIS("asr.%c $r%u, $r%u\n",
1626 memsize_char(size
), dc
->op1
, dc
->op2
);
1628 cris_cc_mask(dc
, CC_MASK_NZ
);
1629 cris_alu_alloc_temps(dc
, size
, t
);
1630 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1631 tcg_gen_andi_tl(t
[1], t
[1], 63);
1632 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1633 cris_alu_free_temps(dc
, size
, t
);
1637 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1640 int size
= memsize_zz(dc
);
1642 LOG_DIS("muls.%c $r%u, $r%u\n",
1643 memsize_char(size
), dc
->op1
, dc
->op2
);
1644 cris_cc_mask(dc
, CC_MASK_NZV
);
1645 cris_alu_alloc_temps(dc
, size
, t
);
1646 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1648 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1649 cris_alu_free_temps(dc
, size
, t
);
1653 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1656 int size
= memsize_zz(dc
);
1658 LOG_DIS("mulu.%c $r%u, $r%u\n",
1659 memsize_char(size
), dc
->op1
, dc
->op2
);
1660 cris_cc_mask(dc
, CC_MASK_NZV
);
1661 cris_alu_alloc_temps(dc
, size
, t
);
1662 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1664 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1665 cris_alu_alloc_temps(dc
, size
, t
);
1670 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1672 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1673 cris_cc_mask(dc
, CC_MASK_NZ
);
1674 cris_alu(dc
, CC_OP_DSTEP
,
1675 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1679 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1682 int size
= memsize_zz(dc
);
1683 LOG_DIS("xor.%c $r%u, $r%u\n",
1684 memsize_char(size
), dc
->op1
, dc
->op2
);
1685 BUG_ON(size
!= 4); /* xor is dword. */
1686 cris_cc_mask(dc
, CC_MASK_NZ
);
1687 cris_alu_alloc_temps(dc
, size
, t
);
1688 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1690 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1691 cris_alu_free_temps(dc
, size
, t
);
1695 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1698 int size
= memsize_zz(dc
);
1699 LOG_DIS("bound.%c $r%u, $r%u\n",
1700 memsize_char(size
), dc
->op1
, dc
->op2
);
1701 cris_cc_mask(dc
, CC_MASK_NZ
);
1702 l0
= tcg_temp_local_new();
1703 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1704 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1709 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1712 int size
= memsize_zz(dc
);
1713 LOG_DIS("cmp.%c $r%u, $r%u\n",
1714 memsize_char(size
), dc
->op1
, dc
->op2
);
1715 cris_cc_mask(dc
, CC_MASK_NZVC
);
1716 cris_alu_alloc_temps(dc
, size
, t
);
1717 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1719 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1720 cris_alu_free_temps(dc
, size
, t
);
1724 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1728 LOG_DIS("abs $r%u, $r%u\n",
1730 cris_cc_mask(dc
, CC_MASK_NZ
);
1732 t0
= tcg_temp_new();
1733 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1734 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1735 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1738 cris_alu(dc
, CC_OP_MOVE
,
1739 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1743 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1746 int size
= memsize_zz(dc
);
1747 LOG_DIS("add.%c $r%u, $r%u\n",
1748 memsize_char(size
), dc
->op1
, dc
->op2
);
1749 cris_cc_mask(dc
, CC_MASK_NZVC
);
1750 cris_alu_alloc_temps(dc
, size
, t
);
1751 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1753 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1754 cris_alu_free_temps(dc
, size
, t
);
1758 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1760 LOG_DIS("addc $r%u, $r%u\n",
1762 cris_evaluate_flags(dc
);
1763 /* Set for this insn. */
1764 dc
->flagx_known
= 1;
1765 dc
->flags_x
= X_FLAG
;
1767 cris_cc_mask(dc
, CC_MASK_NZVC
);
1768 cris_alu(dc
, CC_OP_ADDC
,
1769 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1773 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1775 LOG_DIS("mcp $p%u, $r%u\n",
1777 cris_evaluate_flags(dc
);
1778 cris_cc_mask(dc
, CC_MASK_RNZV
);
1779 cris_alu(dc
, CC_OP_MCP
,
1780 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1785 static char * swapmode_name(int mode
, char *modename
) {
1788 modename
[i
++] = 'n';
1791 modename
[i
++] = 'w';
1794 modename
[i
++] = 'b';
1797 modename
[i
++] = 'r';
1804 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1810 LOG_DIS("swap%s $r%u\n",
1811 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1813 cris_cc_mask(dc
, CC_MASK_NZ
);
1814 t0
= tcg_temp_new();
1815 t_gen_mov_TN_reg(t0
, dc
->op1
);
1817 tcg_gen_not_tl(t0
, t0
);
1820 t_gen_swapw(t0
, t0
);
1823 t_gen_swapb(t0
, t0
);
1826 t_gen_swapr(t0
, t0
);
1828 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1833 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1836 int size
= memsize_zz(dc
);
1837 LOG_DIS("or.%c $r%u, $r%u\n",
1838 memsize_char(size
), dc
->op1
, dc
->op2
);
1839 cris_cc_mask(dc
, CC_MASK_NZ
);
1840 cris_alu_alloc_temps(dc
, size
, t
);
1841 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1842 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1843 cris_alu_free_temps(dc
, size
, t
);
1847 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1850 LOG_DIS("addi.%c $r%u, $r%u\n",
1851 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1852 cris_cc_mask(dc
, 0);
1853 t0
= tcg_temp_new();
1854 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1855 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1860 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1863 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1864 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1865 cris_cc_mask(dc
, 0);
1866 t0
= tcg_temp_new();
1867 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1868 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1873 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1876 int size
= memsize_zz(dc
);
1877 LOG_DIS("neg.%c $r%u, $r%u\n",
1878 memsize_char(size
), dc
->op1
, dc
->op2
);
1879 cris_cc_mask(dc
, CC_MASK_NZVC
);
1880 cris_alu_alloc_temps(dc
, size
, t
);
1881 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1883 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1884 cris_alu_free_temps(dc
, size
, t
);
1888 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1890 LOG_DIS("btst $r%u, $r%u\n",
1892 cris_cc_mask(dc
, CC_MASK_NZ
);
1893 cris_evaluate_flags(dc
);
1894 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1895 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1896 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1897 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1898 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1899 dc
->flags_uptodate
= 1;
1903 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1906 int size
= memsize_zz(dc
);
1907 LOG_DIS("sub.%c $r%u, $r%u\n",
1908 memsize_char(size
), dc
->op1
, dc
->op2
);
1909 cris_cc_mask(dc
, CC_MASK_NZVC
);
1910 cris_alu_alloc_temps(dc
, size
, t
);
1911 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1912 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1913 cris_alu_free_temps(dc
, size
, t
);
1917 /* Zero extension. From size to dword. */
1918 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1921 int size
= memsize_z(dc
);
1922 LOG_DIS("movu.%c $r%u, $r%u\n",
1926 cris_cc_mask(dc
, CC_MASK_NZ
);
1927 t0
= tcg_temp_new();
1928 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1929 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1934 /* Sign extension. From size to dword. */
1935 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1938 int size
= memsize_z(dc
);
1939 LOG_DIS("movs.%c $r%u, $r%u\n",
1943 cris_cc_mask(dc
, CC_MASK_NZ
);
1944 t0
= tcg_temp_new();
1945 /* Size can only be qi or hi. */
1946 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1947 cris_alu(dc
, CC_OP_MOVE
,
1948 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1953 /* zero extension. From size to dword. */
1954 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1957 int size
= memsize_z(dc
);
1958 LOG_DIS("addu.%c $r%u, $r%u\n",
1962 cris_cc_mask(dc
, CC_MASK_NZVC
);
1963 t0
= tcg_temp_new();
1964 /* Size can only be qi or hi. */
1965 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1966 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1971 /* Sign extension. From size to dword. */
1972 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1975 int size
= memsize_z(dc
);
1976 LOG_DIS("adds.%c $r%u, $r%u\n",
1980 cris_cc_mask(dc
, CC_MASK_NZVC
);
1981 t0
= tcg_temp_new();
1982 /* Size can only be qi or hi. */
1983 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1984 cris_alu(dc
, CC_OP_ADD
,
1985 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1990 /* Zero extension. From size to dword. */
1991 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1994 int size
= memsize_z(dc
);
1995 LOG_DIS("subu.%c $r%u, $r%u\n",
1999 cris_cc_mask(dc
, CC_MASK_NZVC
);
2000 t0
= tcg_temp_new();
2001 /* Size can only be qi or hi. */
2002 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
2003 cris_alu(dc
, CC_OP_SUB
,
2004 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2009 /* Sign extension. From size to dword. */
2010 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
2013 int size
= memsize_z(dc
);
2014 LOG_DIS("subs.%c $r%u, $r%u\n",
2018 cris_cc_mask(dc
, CC_MASK_NZVC
);
2019 t0
= tcg_temp_new();
2020 /* Size can only be qi or hi. */
2021 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2022 cris_alu(dc
, CC_OP_SUB
,
2023 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2028 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
2031 int set
= (~dc
->opcode
>> 2) & 1;
2034 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2035 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2036 if (set
&& flags
== 0) {
2039 } else if (!set
&& (flags
& 0x20)) {
2042 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2045 /* User space is not allowed to touch these. Silently ignore. */
2046 if (dc
->tb_flags
& U_FLAG
) {
2047 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2050 if (flags
& X_FLAG
) {
2051 dc
->flagx_known
= 1;
2053 dc
->flags_x
= X_FLAG
;
2059 /* Break the TB if any of the SPI flag changes. */
2060 if (flags
& (P_FLAG
| S_FLAG
)) {
2061 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2062 dc
->is_jmp
= DISAS_UPDATE
;
2063 dc
->cpustate_changed
= 1;
2066 /* For the I flag, only act on posedge. */
2067 if ((flags
& I_FLAG
)) {
2068 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2069 dc
->is_jmp
= DISAS_UPDATE
;
2070 dc
->cpustate_changed
= 1;
2074 /* Simply decode the flags. */
2075 cris_evaluate_flags(dc
);
2076 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2077 cris_update_cc_x(dc
);
2078 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2081 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2082 /* Enter user mode. */
2083 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2084 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2085 dc
->cpustate_changed
= 1;
2087 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2089 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2092 dc
->flags_uptodate
= 1;
2097 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2099 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2100 cris_cc_mask(dc
, 0);
2101 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2102 tcg_const_tl(dc
->op1
));
2105 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2107 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2108 cris_cc_mask(dc
, 0);
2109 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2110 tcg_const_tl(dc
->op2
));
2114 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2117 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2118 cris_cc_mask(dc
, 0);
2120 t
[0] = tcg_temp_new();
2121 if (dc
->op2
== PR_CCS
) {
2122 cris_evaluate_flags(dc
);
2123 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2124 if (dc
->tb_flags
& U_FLAG
) {
2125 t
[1] = tcg_temp_new();
2126 /* User space is not allowed to touch all flags. */
2127 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2128 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2129 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2130 tcg_temp_free(t
[1]);
2133 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2136 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2137 if (dc
->op2
== PR_CCS
) {
2138 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2139 dc
->flags_uptodate
= 1;
2141 tcg_temp_free(t
[0]);
2144 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2147 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2148 cris_cc_mask(dc
, 0);
2150 if (dc
->op2
== PR_CCS
) {
2151 cris_evaluate_flags(dc
);
2154 if (dc
->op2
== PR_DZ
) {
2155 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2157 t0
= tcg_temp_new();
2158 t_gen_mov_TN_preg(t0
, dc
->op2
);
2159 cris_alu(dc
, CC_OP_MOVE
,
2160 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2161 preg_sizes
[dc
->op2
]);
2167 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2169 int memsize
= memsize_zz(dc
);
2171 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2172 memsize_char(memsize
),
2173 dc
->op1
, dc
->postinc
? "+]" : "]",
2177 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2178 cris_cc_mask(dc
, CC_MASK_NZ
);
2179 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2180 cris_update_cc_x(dc
);
2181 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2185 t0
= tcg_temp_new();
2186 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2187 cris_cc_mask(dc
, CC_MASK_NZ
);
2188 cris_alu(dc
, CC_OP_MOVE
,
2189 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2192 do_postinc(dc
, memsize
);
2196 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2198 t
[0] = tcg_temp_new();
2199 t
[1] = tcg_temp_new();
2202 static inline void cris_alu_m_free_temps(TCGv
*t
)
2204 tcg_temp_free(t
[0]);
2205 tcg_temp_free(t
[1]);
2208 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2211 int memsize
= memsize_z(dc
);
2213 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2214 memsize_char(memsize
),
2215 dc
->op1
, dc
->postinc
? "+]" : "]",
2218 cris_alu_m_alloc_temps(t
);
2220 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2221 cris_cc_mask(dc
, CC_MASK_NZ
);
2222 cris_alu(dc
, CC_OP_MOVE
,
2223 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2224 do_postinc(dc
, memsize
);
2225 cris_alu_m_free_temps(t
);
2229 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2232 int memsize
= memsize_z(dc
);
2234 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2235 memsize_char(memsize
),
2236 dc
->op1
, dc
->postinc
? "+]" : "]",
2239 cris_alu_m_alloc_temps(t
);
2241 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2242 cris_cc_mask(dc
, CC_MASK_NZVC
);
2243 cris_alu(dc
, CC_OP_ADD
,
2244 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2245 do_postinc(dc
, memsize
);
2246 cris_alu_m_free_temps(t
);
2250 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2253 int memsize
= memsize_z(dc
);
2255 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2256 memsize_char(memsize
),
2257 dc
->op1
, dc
->postinc
? "+]" : "]",
2260 cris_alu_m_alloc_temps(t
);
2262 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2263 cris_cc_mask(dc
, CC_MASK_NZVC
);
2264 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2265 do_postinc(dc
, memsize
);
2266 cris_alu_m_free_temps(t
);
2270 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2273 int memsize
= memsize_z(dc
);
2275 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2276 memsize_char(memsize
),
2277 dc
->op1
, dc
->postinc
? "+]" : "]",
2280 cris_alu_m_alloc_temps(t
);
2282 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2283 cris_cc_mask(dc
, CC_MASK_NZVC
);
2284 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2285 do_postinc(dc
, memsize
);
2286 cris_alu_m_free_temps(t
);
2290 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2293 int memsize
= memsize_z(dc
);
2295 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2296 memsize_char(memsize
),
2297 dc
->op1
, dc
->postinc
? "+]" : "]",
2300 cris_alu_m_alloc_temps(t
);
2302 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2303 cris_cc_mask(dc
, CC_MASK_NZVC
);
2304 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2305 do_postinc(dc
, memsize
);
2306 cris_alu_m_free_temps(t
);
2310 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2313 int memsize
= memsize_z(dc
);
2316 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2317 memsize_char(memsize
),
2318 dc
->op1
, dc
->postinc
? "+]" : "]",
2321 cris_alu_m_alloc_temps(t
);
2322 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2323 cris_cc_mask(dc
, CC_MASK_NZ
);
2324 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2325 do_postinc(dc
, memsize
);
2326 cris_alu_m_free_temps(t
);
2330 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2333 int memsize
= memsize_z(dc
);
2335 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2336 memsize_char(memsize
),
2337 dc
->op1
, dc
->postinc
? "+]" : "]",
2340 cris_alu_m_alloc_temps(t
);
2341 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2342 cris_cc_mask(dc
, CC_MASK_NZVC
);
2343 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2344 do_postinc(dc
, memsize
);
2345 cris_alu_m_free_temps(t
);
2349 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2352 int memsize
= memsize_z(dc
);
2354 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2355 memsize_char(memsize
),
2356 dc
->op1
, dc
->postinc
? "+]" : "]",
2359 cris_alu_m_alloc_temps(t
);
2360 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2361 cris_cc_mask(dc
, CC_MASK_NZVC
);
2362 cris_alu(dc
, CC_OP_CMP
,
2363 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2365 do_postinc(dc
, memsize
);
2366 cris_alu_m_free_temps(t
);
2370 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2373 int memsize
= memsize_zz(dc
);
2375 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2376 memsize_char(memsize
),
2377 dc
->op1
, dc
->postinc
? "+]" : "]",
2380 cris_alu_m_alloc_temps(t
);
2381 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2382 cris_cc_mask(dc
, CC_MASK_NZVC
);
2383 cris_alu(dc
, CC_OP_CMP
,
2384 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2386 do_postinc(dc
, memsize
);
2387 cris_alu_m_free_temps(t
);
2391 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2394 int memsize
= memsize_zz(dc
);
2396 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2397 memsize_char(memsize
),
2398 dc
->op1
, dc
->postinc
? "+]" : "]",
2401 cris_evaluate_flags(dc
);
2403 cris_alu_m_alloc_temps(t
);
2404 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2405 cris_cc_mask(dc
, CC_MASK_NZ
);
2406 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2408 cris_alu(dc
, CC_OP_CMP
,
2409 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2410 do_postinc(dc
, memsize
);
2411 cris_alu_m_free_temps(t
);
2415 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2418 int memsize
= memsize_zz(dc
);
2420 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2421 memsize_char(memsize
),
2422 dc
->op1
, dc
->postinc
? "+]" : "]",
2425 cris_alu_m_alloc_temps(t
);
2426 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2427 cris_cc_mask(dc
, CC_MASK_NZ
);
2428 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2429 do_postinc(dc
, memsize
);
2430 cris_alu_m_free_temps(t
);
2434 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2437 int memsize
= memsize_zz(dc
);
2439 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2440 memsize_char(memsize
),
2441 dc
->op1
, dc
->postinc
? "+]" : "]",
2444 cris_alu_m_alloc_temps(t
);
2445 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2446 cris_cc_mask(dc
, CC_MASK_NZVC
);
2447 cris_alu(dc
, CC_OP_ADD
,
2448 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2449 do_postinc(dc
, memsize
);
2450 cris_alu_m_free_temps(t
);
2454 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2457 int memsize
= memsize_zz(dc
);
2459 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2460 memsize_char(memsize
),
2461 dc
->op1
, dc
->postinc
? "+]" : "]",
2464 cris_alu_m_alloc_temps(t
);
2465 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2466 cris_cc_mask(dc
, 0);
2467 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2468 do_postinc(dc
, memsize
);
2469 cris_alu_m_free_temps(t
);
2473 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2476 int memsize
= memsize_zz(dc
);
2478 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2479 memsize_char(memsize
),
2480 dc
->op1
, dc
->postinc
? "+]" : "]",
2483 l
[0] = tcg_temp_local_new();
2484 l
[1] = tcg_temp_local_new();
2485 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2486 cris_cc_mask(dc
, CC_MASK_NZ
);
2487 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2488 do_postinc(dc
, memsize
);
2489 tcg_temp_free(l
[0]);
2490 tcg_temp_free(l
[1]);
2494 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2498 LOG_DIS("addc [$r%u%s, $r%u\n",
2499 dc
->op1
, dc
->postinc
? "+]" : "]",
2502 cris_evaluate_flags(dc
);
2504 /* Set for this insn. */
2505 dc
->flagx_known
= 1;
2506 dc
->flags_x
= X_FLAG
;
2508 cris_alu_m_alloc_temps(t
);
2509 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2510 cris_cc_mask(dc
, CC_MASK_NZVC
);
2511 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2513 cris_alu_m_free_temps(t
);
2517 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2520 int memsize
= memsize_zz(dc
);
2522 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2523 memsize_char(memsize
),
2524 dc
->op1
, dc
->postinc
? "+]" : "]",
2525 dc
->op2
, dc
->ir
, dc
->zzsize
);
2527 cris_alu_m_alloc_temps(t
);
2528 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2529 cris_cc_mask(dc
, CC_MASK_NZVC
);
2530 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2531 do_postinc(dc
, memsize
);
2532 cris_alu_m_free_temps(t
);
2536 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2539 int memsize
= memsize_zz(dc
);
2541 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2542 memsize_char(memsize
),
2543 dc
->op1
, dc
->postinc
? "+]" : "]",
2546 cris_alu_m_alloc_temps(t
);
2547 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2548 cris_cc_mask(dc
, CC_MASK_NZ
);
2549 cris_alu(dc
, CC_OP_OR
,
2550 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2551 do_postinc(dc
, memsize
);
2552 cris_alu_m_free_temps(t
);
2556 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2559 int memsize
= memsize_zz(dc
);
2562 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2563 memsize_char(memsize
),
2565 dc
->postinc
? "+]" : "]",
2568 cris_alu_m_alloc_temps(t
);
2569 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2570 cris_cc_mask(dc
, 0);
2571 if (dc
->op2
== PR_CCS
) {
2572 cris_evaluate_flags(dc
);
2573 if (dc
->tb_flags
& U_FLAG
) {
2574 /* User space is not allowed to touch all flags. */
2575 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2576 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2577 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2581 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2583 do_postinc(dc
, memsize
);
2584 cris_alu_m_free_temps(t
);
2588 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2593 memsize
= preg_sizes
[dc
->op2
];
2595 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2596 memsize_char(memsize
),
2597 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2599 /* prepare store. Address in T0, value in T1. */
2600 if (dc
->op2
== PR_CCS
) {
2601 cris_evaluate_flags(dc
);
2603 t0
= tcg_temp_new();
2604 t_gen_mov_TN_preg(t0
, dc
->op2
);
2605 cris_flush_cc_state(dc
);
2606 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2609 cris_cc_mask(dc
, 0);
2611 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2616 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2622 int nr
= dc
->op2
+ 1;
2624 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2625 dc
->postinc
? "+]" : "]", dc
->op2
);
2627 addr
= tcg_temp_new();
2628 /* There are probably better ways of doing this. */
2629 cris_flush_cc_state(dc
);
2630 for (i
= 0; i
< (nr
>> 1); i
++) {
2631 tmp
[i
] = tcg_temp_new_i64();
2632 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2633 gen_load64(dc
, tmp
[i
], addr
);
2636 tmp32
= tcg_temp_new_i32();
2637 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2638 gen_load(dc
, tmp32
, addr
, 4, 0);
2642 tcg_temp_free(addr
);
2644 for (i
= 0; i
< (nr
>> 1); i
++) {
2645 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2646 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2647 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2648 tcg_temp_free_i64(tmp
[i
]);
2651 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2652 tcg_temp_free(tmp32
);
2655 /* writeback the updated pointer value. */
2657 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2660 /* gen_load might want to evaluate the previous insns flags. */
2661 cris_cc_mask(dc
, 0);
2665 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2671 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2672 dc
->postinc
? "+]" : "]");
2674 cris_flush_cc_state(dc
);
2676 tmp
= tcg_temp_new();
2677 addr
= tcg_temp_new();
2678 tcg_gen_movi_tl(tmp
, 4);
2679 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2680 for (i
= 0; i
<= dc
->op2
; i
++) {
2681 /* Displace addr. */
2682 /* Perform the store. */
2683 gen_store(dc
, addr
, cpu_R
[i
], 4);
2684 tcg_gen_add_tl(addr
, addr
, tmp
);
2687 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2689 cris_cc_mask(dc
, 0);
2691 tcg_temp_free(addr
);
2695 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2699 memsize
= memsize_zz(dc
);
2701 LOG_DIS("move.%c $r%u, [$r%u]\n",
2702 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2704 /* prepare store. */
2705 cris_flush_cc_state(dc
);
2706 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2709 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2711 cris_cc_mask(dc
, 0);
2715 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2717 LOG_DIS("lapcq %x, $r%u\n",
2718 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2719 cris_cc_mask(dc
, 0);
2720 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2724 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2732 cris_cc_mask(dc
, 0);
2733 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2734 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2738 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2742 /* Jump to special reg. */
2743 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2745 LOG_DIS("jump $p%u\n", dc
->op2
);
2747 if (dc
->op2
== PR_CCS
) {
2748 cris_evaluate_flags(dc
);
2750 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2751 /* rete will often have low bit set to indicate delayslot. */
2752 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2753 cris_cc_mask(dc
, 0);
2754 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2758 /* Jump and save. */
2759 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2761 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2762 cris_cc_mask(dc
, 0);
2763 /* Store the return address in Pd. */
2764 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2768 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2770 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2774 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2778 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2780 LOG_DIS("jas 0x%x\n", imm
);
2781 cris_cc_mask(dc
, 0);
2782 /* Store the return address in Pd. */
2783 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2786 cris_prepare_jmp(dc
, JMP_DIRECT
);
2790 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2794 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2796 LOG_DIS("jasc 0x%x\n", imm
);
2797 cris_cc_mask(dc
, 0);
2798 /* Store the return address in Pd. */
2799 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2802 cris_prepare_jmp(dc
, JMP_DIRECT
);
2806 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2808 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2809 cris_cc_mask(dc
, 0);
2810 /* Store the return address in Pd. */
2811 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2812 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2813 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2817 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2820 uint32_t cond
= dc
->op2
;
2822 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2824 LOG_DIS("b%s %d pc=%x dst=%x\n",
2825 cc_name(cond
), offset
,
2826 dc
->pc
, dc
->pc
+ offset
);
2828 cris_cc_mask(dc
, 0);
2829 /* op2 holds the condition-code. */
2830 cris_prepare_cc_branch(dc
, offset
, cond
);
2834 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2838 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2840 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2841 cris_cc_mask(dc
, 0);
2842 /* Store the return address in Pd. */
2843 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2845 dc
->jmp_pc
= dc
->pc
+ simm
;
2846 cris_prepare_jmp(dc
, JMP_DIRECT
);
2850 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2853 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2855 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2856 cris_cc_mask(dc
, 0);
2857 /* Store the return address in Pd. */
2858 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2860 dc
->jmp_pc
= dc
->pc
+ simm
;
2861 cris_prepare_jmp(dc
, JMP_DIRECT
);
2865 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2867 cris_cc_mask(dc
, 0);
2869 if (dc
->op2
== 15) {
2870 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2871 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2872 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2873 t_gen_raise_exception(EXCP_HLT
);
2877 switch (dc
->op2
& 7) {
2881 cris_evaluate_flags(dc
);
2882 gen_helper_rfe(cpu_env
);
2883 dc
->is_jmp
= DISAS_UPDATE
;
2888 cris_evaluate_flags(dc
);
2889 gen_helper_rfn(cpu_env
);
2890 dc
->is_jmp
= DISAS_UPDATE
;
2893 LOG_DIS("break %d\n", dc
->op1
);
2894 cris_evaluate_flags(dc
);
2896 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2898 /* Breaks start at 16 in the exception vector. */
2899 t_gen_mov_env_TN(trap_vector
,
2900 tcg_const_tl(dc
->op1
+ 16));
2901 t_gen_raise_exception(EXCP_BREAK
);
2902 dc
->is_jmp
= DISAS_UPDATE
;
2905 printf("op2=%x\n", dc
->op2
);
2913 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2918 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2923 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2925 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2926 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2932 static struct decoder_info
{
2937 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2939 /* Order matters here. */
2940 {DEC_MOVEQ
, dec_moveq
},
2941 {DEC_BTSTQ
, dec_btstq
},
2942 {DEC_CMPQ
, dec_cmpq
},
2943 {DEC_ADDOQ
, dec_addoq
},
2944 {DEC_ADDQ
, dec_addq
},
2945 {DEC_SUBQ
, dec_subq
},
2946 {DEC_ANDQ
, dec_andq
},
2948 {DEC_ASRQ
, dec_asrq
},
2949 {DEC_LSLQ
, dec_lslq
},
2950 {DEC_LSRQ
, dec_lsrq
},
2951 {DEC_BCCQ
, dec_bccq
},
2953 {DEC_BCC_IM
, dec_bcc_im
},
2954 {DEC_JAS_IM
, dec_jas_im
},
2955 {DEC_JAS_R
, dec_jas_r
},
2956 {DEC_JASC_IM
, dec_jasc_im
},
2957 {DEC_JASC_R
, dec_jasc_r
},
2958 {DEC_BAS_IM
, dec_bas_im
},
2959 {DEC_BASC_IM
, dec_basc_im
},
2960 {DEC_JUMP_P
, dec_jump_p
},
2961 {DEC_LAPC_IM
, dec_lapc_im
},
2962 {DEC_LAPCQ
, dec_lapcq
},
2964 {DEC_RFE_ETC
, dec_rfe_etc
},
2965 {DEC_ADDC_MR
, dec_addc_mr
},
2967 {DEC_MOVE_MP
, dec_move_mp
},
2968 {DEC_MOVE_PM
, dec_move_pm
},
2969 {DEC_MOVEM_MR
, dec_movem_mr
},
2970 {DEC_MOVEM_RM
, dec_movem_rm
},
2971 {DEC_MOVE_PR
, dec_move_pr
},
2972 {DEC_SCC_R
, dec_scc_r
},
2973 {DEC_SETF
, dec_setclrf
},
2974 {DEC_CLEARF
, dec_setclrf
},
2976 {DEC_MOVE_SR
, dec_move_sr
},
2977 {DEC_MOVE_RP
, dec_move_rp
},
2978 {DEC_SWAP_R
, dec_swap_r
},
2979 {DEC_ABS_R
, dec_abs_r
},
2980 {DEC_LZ_R
, dec_lz_r
},
2981 {DEC_MOVE_RS
, dec_move_rs
},
2982 {DEC_BTST_R
, dec_btst_r
},
2983 {DEC_ADDC_R
, dec_addc_r
},
2985 {DEC_DSTEP_R
, dec_dstep_r
},
2986 {DEC_XOR_R
, dec_xor_r
},
2987 {DEC_MCP_R
, dec_mcp_r
},
2988 {DEC_CMP_R
, dec_cmp_r
},
2990 {DEC_ADDI_R
, dec_addi_r
},
2991 {DEC_ADDI_ACR
, dec_addi_acr
},
2993 {DEC_ADD_R
, dec_add_r
},
2994 {DEC_SUB_R
, dec_sub_r
},
2996 {DEC_ADDU_R
, dec_addu_r
},
2997 {DEC_ADDS_R
, dec_adds_r
},
2998 {DEC_SUBU_R
, dec_subu_r
},
2999 {DEC_SUBS_R
, dec_subs_r
},
3000 {DEC_LSL_R
, dec_lsl_r
},
3002 {DEC_AND_R
, dec_and_r
},
3003 {DEC_OR_R
, dec_or_r
},
3004 {DEC_BOUND_R
, dec_bound_r
},
3005 {DEC_ASR_R
, dec_asr_r
},
3006 {DEC_LSR_R
, dec_lsr_r
},
3008 {DEC_MOVU_R
, dec_movu_r
},
3009 {DEC_MOVS_R
, dec_movs_r
},
3010 {DEC_NEG_R
, dec_neg_r
},
3011 {DEC_MOVE_R
, dec_move_r
},
3013 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
3014 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
3016 {DEC_MULS_R
, dec_muls_r
},
3017 {DEC_MULU_R
, dec_mulu_r
},
3019 {DEC_ADDU_M
, dec_addu_m
},
3020 {DEC_ADDS_M
, dec_adds_m
},
3021 {DEC_SUBU_M
, dec_subu_m
},
3022 {DEC_SUBS_M
, dec_subs_m
},
3024 {DEC_CMPU_M
, dec_cmpu_m
},
3025 {DEC_CMPS_M
, dec_cmps_m
},
3026 {DEC_MOVU_M
, dec_movu_m
},
3027 {DEC_MOVS_M
, dec_movs_m
},
3029 {DEC_CMP_M
, dec_cmp_m
},
3030 {DEC_ADDO_M
, dec_addo_m
},
3031 {DEC_BOUND_M
, dec_bound_m
},
3032 {DEC_ADD_M
, dec_add_m
},
3033 {DEC_SUB_M
, dec_sub_m
},
3034 {DEC_AND_M
, dec_and_m
},
3035 {DEC_OR_M
, dec_or_m
},
3036 {DEC_MOVE_RM
, dec_move_rm
},
3037 {DEC_TEST_M
, dec_test_m
},
3038 {DEC_MOVE_MR
, dec_move_mr
},
3043 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3048 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3049 tcg_gen_debug_insn_start(dc
->pc
);
3052 /* Load a halfword onto the instruction register. */
3053 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3055 /* Now decode it. */
3056 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3057 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3058 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3059 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3060 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3061 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3063 /* Large switch for all insns. */
3064 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3065 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3066 insn_len
= decinfo
[i
].dec(env
, dc
);
3071 #if !defined(CONFIG_USER_ONLY)
3072 /* Single-stepping ? */
3073 if (dc
->tb_flags
& S_FLAG
) {
3076 l1
= gen_new_label();
3077 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3078 /* We treat SPC as a break with an odd trap vector. */
3079 cris_evaluate_flags(dc
);
3080 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3081 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3082 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3083 t_gen_raise_exception(EXCP_BREAK
);
3090 static void check_breakpoint(CPUCRISState
*env
, DisasContext
*dc
)
3092 CPUState
*cs
= CPU(cris_env_get_cpu(env
));
3095 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
3096 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
3097 if (bp
->pc
== dc
->pc
) {
3098 cris_evaluate_flags(dc
);
3099 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3100 t_gen_raise_exception(EXCP_DEBUG
);
3101 dc
->is_jmp
= DISAS_UPDATE
;
3107 #include "translate_v10.c"
3110 * Delay slots on QEMU/CRIS.
3112 * If an exception hits on a delayslot, the core will let ERP (the Exception
3113 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3114 * to give SW a hint that the exception actually hit on the dslot.
3116 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3117 * the core and any jmp to an odd addresses will mask off that lsb. It is
3118 * simply there to let sw know there was an exception on a dslot.
3120 * When the software returns from an exception, the branch will re-execute.
3121 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3122 * and the branch and delayslot dont share pages.
3124 * The TB contaning the branch insn will set up env->btarget and evaluate
3125 * env->btaken. When the translation loop exits we will note that the branch
3126 * sequence is broken and let env->dslot be the size of the branch insn (those
3129 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3130 * set). It will also expect to have env->dslot setup with the size of the
3131 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3132 * will execute the dslot and take the branch, either to btarget or just one
3135 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3136 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3137 * branch and set lsb). Then env->dslot gets cleared so that the exception
3138 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3139 * masked off and we will reexecute the branch insn.
3143 /* generate intermediate code for basic block 'tb'. */
3145 gen_intermediate_code_internal(CRISCPU
*cpu
, TranslationBlock
*tb
,
3148 CPUState
*cs
= CPU(cpu
);
3149 CPUCRISState
*env
= &cpu
->env
;
3150 uint16_t *gen_opc_end
;
3152 unsigned int insn_len
;
3154 struct DisasContext ctx
;
3155 struct DisasContext
*dc
= &ctx
;
3156 uint32_t next_page_start
;
3161 if (env
->pregs
[PR_VR
] == 32) {
3162 dc
->decoder
= crisv32_decoder
;
3163 dc
->clear_locked_irq
= 0;
3165 dc
->decoder
= crisv10_decoder
;
3166 dc
->clear_locked_irq
= 1;
3169 /* Odd PC indicates that branch is rexecuting due to exception in the
3170 * delayslot, like in real hw.
3172 pc_start
= tb
->pc
& ~1;
3176 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
3178 dc
->is_jmp
= DISAS_NEXT
;
3181 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3182 dc
->flags_uptodate
= 1;
3183 dc
->flagx_known
= 1;
3184 dc
->flags_x
= tb
->flags
& X_FLAG
;
3185 dc
->cc_x_uptodate
= 0;
3188 dc
->clear_prefix
= 0;
3190 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3191 dc
->cc_size_uptodate
= -1;
3193 /* Decode TB flags. */
3194 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3195 | X_FLAG
| PFIX_FLAG
);
3196 dc
->delayed_branch
= !!(tb
->flags
& 7);
3197 if (dc
->delayed_branch
) {
3198 dc
->jmp
= JMP_INDIRECT
;
3200 dc
->jmp
= JMP_NOJMP
;
3203 dc
->cpustate_changed
= 0;
3205 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3207 "srch=%d pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3213 search_pc
, dc
->pc
, dc
->ppc
,
3214 (uint64_t)tb
->flags
,
3215 env
->btarget
, (unsigned)tb
->flags
& 7,
3217 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3218 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3219 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3220 env
->regs
[8], env
->regs
[9],
3221 env
->regs
[10], env
->regs
[11],
3222 env
->regs
[12], env
->regs
[13],
3223 env
->regs
[14], env
->regs
[15]);
3224 qemu_log("--------------\n");
3225 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3228 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3231 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3232 if (max_insns
== 0) {
3233 max_insns
= CF_COUNT_MASK
;
3238 check_breakpoint(env
, dc
);
3241 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3245 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3248 if (dc
->delayed_branch
== 1) {
3249 tcg_ctx
.gen_opc_pc
[lj
] = dc
->ppc
| 1;
3251 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
3253 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3254 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
3258 LOG_DIS("%8.8x:\t", dc
->pc
);
3260 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3265 insn_len
= dc
->decoder(env
, dc
);
3269 cris_clear_x_flag(dc
);
3273 /* Check for delayed branches here. If we do it before
3274 actually generating any host code, the simulator will just
3275 loop doing nothing for on this program location. */
3276 if (dc
->delayed_branch
) {
3277 dc
->delayed_branch
--;
3278 if (dc
->delayed_branch
== 0) {
3279 if (tb
->flags
& 7) {
3280 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3282 if (dc
->cpustate_changed
|| !dc
->flagx_known
3283 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3284 cris_store_direct_jmp(dc
);
3287 if (dc
->clear_locked_irq
) {
3288 dc
->clear_locked_irq
= 0;
3289 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3292 if (dc
->jmp
== JMP_DIRECT_CC
) {
3295 l1
= gen_new_label();
3296 cris_evaluate_flags(dc
);
3298 /* Conditional jmp. */
3299 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3301 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3303 gen_goto_tb(dc
, 0, dc
->pc
);
3304 dc
->is_jmp
= DISAS_TB_JUMP
;
3305 dc
->jmp
= JMP_NOJMP
;
3306 } else if (dc
->jmp
== JMP_DIRECT
) {
3307 cris_evaluate_flags(dc
);
3308 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3309 dc
->is_jmp
= DISAS_TB_JUMP
;
3310 dc
->jmp
= JMP_NOJMP
;
3312 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3313 dc
->is_jmp
= DISAS_JUMP
;
3319 /* If we are rexecuting a branch due to exceptions on
3320 delay slots dont break. */
3321 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3324 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3325 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
3327 && (dc
->pc
< next_page_start
)
3328 && num_insns
< max_insns
);
3330 if (dc
->clear_locked_irq
) {
3331 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3336 if (tb
->cflags
& CF_LAST_IO
)
3338 /* Force an update if the per-tb cpu state has changed. */
3339 if (dc
->is_jmp
== DISAS_NEXT
3340 && (dc
->cpustate_changed
|| !dc
->flagx_known
3341 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3342 dc
->is_jmp
= DISAS_UPDATE
;
3343 tcg_gen_movi_tl(env_pc
, npc
);
3345 /* Broken branch+delayslot sequence. */
3346 if (dc
->delayed_branch
== 1) {
3347 /* Set env->dslot to the size of the branch insn. */
3348 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3349 cris_store_direct_jmp(dc
);
3352 cris_evaluate_flags(dc
);
3354 if (unlikely(cs
->singlestep_enabled
)) {
3355 if (dc
->is_jmp
== DISAS_NEXT
) {
3356 tcg_gen_movi_tl(env_pc
, npc
);
3358 t_gen_raise_exception(EXCP_DEBUG
);
3360 switch (dc
->is_jmp
) {
3362 gen_goto_tb(dc
, 1, npc
);
3367 /* indicate that the hash table must be used
3368 to find the next TB */
3373 /* nothing more to generate */
3377 gen_tb_end(tb
, num_insns
);
3378 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3380 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3383 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3386 tb
->size
= dc
->pc
- pc_start
;
3387 tb
->icount
= num_insns
;
3392 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3393 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
3395 qemu_log("\nisize=%d osize=%td\n",
3396 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
);
3402 void gen_intermediate_code (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3404 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, false);
3407 void gen_intermediate_code_pc (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3409 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, true);
3412 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
3415 CRISCPU
*cpu
= CRIS_CPU(cs
);
3416 CPUCRISState
*env
= &cpu
->env
;
3424 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3425 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3426 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3428 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3431 for (i
= 0; i
< 16; i
++) {
3432 cpu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3433 if ((i
+ 1) % 4 == 0) {
3434 cpu_fprintf(f
, "\n");
3437 cpu_fprintf(f
, "\nspecial regs:\n");
3438 for (i
= 0; i
< 16; i
++) {
3439 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3440 if ((i
+ 1) % 4 == 0) {
3441 cpu_fprintf(f
, "\n");
3444 srs
= env
->pregs
[PR_SRS
];
3445 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3446 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3447 for (i
= 0; i
< 16; i
++) {
3448 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3449 i
, env
->sregs
[srs
][i
]);
3450 if ((i
+ 1) % 4 == 0) {
3451 cpu_fprintf(f
, "\n");
3455 cpu_fprintf(f
, "\n\n");
3459 void cris_initialize_tcg(void)
3463 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3464 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3465 offsetof(CPUCRISState
, cc_x
), "cc_x");
3466 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3467 offsetof(CPUCRISState
, cc_src
), "cc_src");
3468 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3469 offsetof(CPUCRISState
, cc_dest
),
3471 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3472 offsetof(CPUCRISState
, cc_result
),
3474 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3475 offsetof(CPUCRISState
, cc_op
), "cc_op");
3476 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3477 offsetof(CPUCRISState
, cc_size
),
3479 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3480 offsetof(CPUCRISState
, cc_mask
),
3483 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3484 offsetof(CPUCRISState
, pc
),
3486 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3487 offsetof(CPUCRISState
, btarget
),
3489 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3490 offsetof(CPUCRISState
, btaken
),
3492 for (i
= 0; i
< 16; i
++) {
3493 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3494 offsetof(CPUCRISState
, regs
[i
]),
3497 for (i
= 0; i
< 16; i
++) {
3498 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3499 offsetof(CPUCRISState
, pregs
[i
]),
3504 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
, int pc_pos
)
3506 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];