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"
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 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
164 #define t_gen_mov_env_TN(member, tn) \
165 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
167 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
169 if (r
< 0 || r
> 15) {
170 fprintf(stderr
, "wrong register read $p%d\n", r
);
172 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
173 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
174 } else if (r
== PR_VR
) {
175 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
177 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
180 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
182 if (r
< 0 || r
> 15) {
183 fprintf(stderr
, "wrong register write $p%d\n", r
);
185 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
187 } else if (r
== PR_SRS
) {
188 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
191 gen_helper_tlb_flush_pid(cpu_env
, tn
);
193 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
194 gen_helper_spc_write(cpu_env
, tn
);
195 } else if (r
== PR_CCS
) {
196 dc
->cpustate_changed
= 1;
198 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
202 /* Sign extend at translation time. */
203 static int sign_extend(unsigned int val
, unsigned int width
)
215 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
216 unsigned int size
, unsigned int sign
)
223 r
= cpu_ldl_code(env
, addr
);
229 r
= cpu_ldsw_code(env
, addr
);
231 r
= cpu_lduw_code(env
, addr
);
238 r
= cpu_ldsb_code(env
, addr
);
240 r
= cpu_ldub_code(env
, addr
);
245 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
251 static void cris_lock_irq(DisasContext
*dc
)
253 dc
->clear_locked_irq
= 0;
254 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
257 static inline void t_gen_raise_exception(uint32_t index
)
259 TCGv_i32 tmp
= tcg_const_i32(index
);
260 gen_helper_raise_exception(cpu_env
, tmp
);
261 tcg_temp_free_i32(tmp
);
264 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
269 t_31
= tcg_const_tl(31);
270 tcg_gen_shl_tl(d
, a
, b
);
272 tcg_gen_sub_tl(t0
, t_31
, b
);
273 tcg_gen_sar_tl(t0
, t0
, t_31
);
274 tcg_gen_and_tl(t0
, t0
, d
);
275 tcg_gen_xor_tl(d
, d
, t0
);
280 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
285 t_31
= tcg_temp_new();
286 tcg_gen_shr_tl(d
, a
, b
);
288 tcg_gen_movi_tl(t_31
, 31);
289 tcg_gen_sub_tl(t0
, t_31
, b
);
290 tcg_gen_sar_tl(t0
, t0
, t_31
);
291 tcg_gen_and_tl(t0
, t0
, d
);
292 tcg_gen_xor_tl(d
, d
, t0
);
297 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
302 t_31
= tcg_temp_new();
303 tcg_gen_sar_tl(d
, a
, b
);
305 tcg_gen_movi_tl(t_31
, 31);
306 tcg_gen_sub_tl(t0
, t_31
, b
);
307 tcg_gen_sar_tl(t0
, t0
, t_31
);
308 tcg_gen_or_tl(d
, d
, t0
);
313 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
317 l1
= gen_new_label();
324 tcg_gen_shli_tl(d
, a
, 1);
325 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
326 tcg_gen_sub_tl(d
, d
, b
);
330 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
340 tcg_gen_shli_tl(d
, a
, 1);
341 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
342 tcg_gen_sari_tl(t
, t
, 31);
343 tcg_gen_and_tl(t
, t
, b
);
344 tcg_gen_add_tl(d
, d
, t
);
348 /* Extended arithmetics on CRIS. */
349 static inline void t_gen_add_flag(TCGv d
, int flag
)
354 t_gen_mov_TN_preg(c
, PR_CCS
);
355 /* Propagate carry into d. */
356 tcg_gen_andi_tl(c
, c
, 1 << flag
);
358 tcg_gen_shri_tl(c
, c
, flag
);
360 tcg_gen_add_tl(d
, d
, c
);
364 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
366 if (dc
->flagx_known
) {
371 t_gen_mov_TN_preg(c
, PR_CCS
);
372 /* C flag is already at bit 0. */
373 tcg_gen_andi_tl(c
, c
, C_FLAG
);
374 tcg_gen_add_tl(d
, d
, c
);
382 t_gen_mov_TN_preg(x
, PR_CCS
);
383 tcg_gen_mov_tl(c
, x
);
385 /* Propagate carry into d if X is set. Branch free. */
386 tcg_gen_andi_tl(c
, c
, C_FLAG
);
387 tcg_gen_andi_tl(x
, x
, X_FLAG
);
388 tcg_gen_shri_tl(x
, x
, 4);
390 tcg_gen_and_tl(x
, x
, c
);
391 tcg_gen_add_tl(d
, d
, x
);
397 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
399 if (dc
->flagx_known
) {
404 t_gen_mov_TN_preg(c
, PR_CCS
);
405 /* C flag is already at bit 0. */
406 tcg_gen_andi_tl(c
, c
, C_FLAG
);
407 tcg_gen_sub_tl(d
, d
, c
);
415 t_gen_mov_TN_preg(x
, PR_CCS
);
416 tcg_gen_mov_tl(c
, x
);
418 /* Propagate carry into d if X is set. Branch free. */
419 tcg_gen_andi_tl(c
, c
, C_FLAG
);
420 tcg_gen_andi_tl(x
, x
, X_FLAG
);
421 tcg_gen_shri_tl(x
, x
, 4);
423 tcg_gen_and_tl(x
, x
, c
);
424 tcg_gen_sub_tl(d
, d
, x
);
430 /* Swap the two bytes within each half word of the s operand.
431 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
432 static inline void t_gen_swapb(TCGv d
, TCGv s
)
437 org_s
= tcg_temp_new();
439 /* d and s may refer to the same object. */
440 tcg_gen_mov_tl(org_s
, s
);
441 tcg_gen_shli_tl(t
, org_s
, 8);
442 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
443 tcg_gen_shri_tl(t
, org_s
, 8);
444 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
445 tcg_gen_or_tl(d
, d
, t
);
447 tcg_temp_free(org_s
);
450 /* Swap the halfwords of the s operand. */
451 static inline void t_gen_swapw(TCGv d
, TCGv s
)
454 /* d and s refer the same object. */
456 tcg_gen_mov_tl(t
, s
);
457 tcg_gen_shli_tl(d
, t
, 16);
458 tcg_gen_shri_tl(t
, t
, 16);
459 tcg_gen_or_tl(d
, d
, t
);
463 /* Reverse the within each byte.
464 T0 = (((T0 << 7) & 0x80808080) |
465 ((T0 << 5) & 0x40404040) |
466 ((T0 << 3) & 0x20202020) |
467 ((T0 << 1) & 0x10101010) |
468 ((T0 >> 1) & 0x08080808) |
469 ((T0 >> 3) & 0x04040404) |
470 ((T0 >> 5) & 0x02020202) |
471 ((T0 >> 7) & 0x01010101));
473 static inline void t_gen_swapr(TCGv d
, TCGv s
)
476 int shift
; /* LSL when positive, LSR when negative. */
491 /* d and s refer the same object. */
493 org_s
= tcg_temp_new();
494 tcg_gen_mov_tl(org_s
, s
);
496 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
497 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
498 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
499 if (bitrev
[i
].shift
>= 0) {
500 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
502 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
504 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
505 tcg_gen_or_tl(d
, d
, t
);
508 tcg_temp_free(org_s
);
511 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
515 l1
= gen_new_label();
517 /* Conditional jmp. */
518 tcg_gen_mov_tl(env_pc
, pc_false
);
519 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
520 tcg_gen_mov_tl(env_pc
, pc_true
);
524 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
526 TranslationBlock
*tb
;
528 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
530 tcg_gen_movi_tl(env_pc
, dest
);
531 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
533 tcg_gen_movi_tl(env_pc
, dest
);
538 static inline void cris_clear_x_flag(DisasContext
*dc
)
540 if (dc
->flagx_known
&& dc
->flags_x
) {
541 dc
->flags_uptodate
= 0;
548 static void cris_flush_cc_state(DisasContext
*dc
)
550 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
551 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
552 dc
->cc_size_uptodate
= dc
->cc_size
;
554 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
555 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
558 static void cris_evaluate_flags(DisasContext
*dc
)
560 if (dc
->flags_uptodate
) {
564 cris_flush_cc_state(dc
);
568 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
569 cpu_PR
[PR_CCS
], cc_src
,
573 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
574 cpu_PR
[PR_CCS
], cc_result
,
578 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
579 cpu_PR
[PR_CCS
], cc_result
,
589 switch (dc
->cc_size
) {
591 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
592 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
595 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
596 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
599 gen_helper_evaluate_flags(cpu_env
);
608 if (dc
->cc_size
== 4) {
609 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
610 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
612 gen_helper_evaluate_flags(cpu_env
);
617 switch (dc
->cc_size
) {
619 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
620 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
623 gen_helper_evaluate_flags(cpu_env
);
629 if (dc
->flagx_known
) {
631 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
632 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
633 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
636 dc
->flags_uptodate
= 1;
639 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
648 /* Check if we need to evaluate the condition codes due to
650 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
652 /* TODO: optimize this case. It trigs all the time. */
653 cris_evaluate_flags(dc
);
659 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
663 dc
->flags_uptodate
= 0;
666 static inline void cris_update_cc_x(DisasContext
*dc
)
668 /* Save the x flag state at the time of the cc snapshot. */
669 if (dc
->flagx_known
) {
670 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
673 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
674 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
676 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
677 dc
->cc_x_uptodate
= 1;
681 /* Update cc prior to executing ALU op. Needs source operands untouched. */
682 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
683 TCGv dst
, TCGv src
, int size
)
686 cris_update_cc_op(dc
, op
, size
);
687 tcg_gen_mov_tl(cc_src
, src
);
695 && op
!= CC_OP_LSL
) {
696 tcg_gen_mov_tl(cc_dest
, dst
);
699 cris_update_cc_x(dc
);
703 /* Update cc after executing ALU op. needs the result. */
704 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
707 tcg_gen_mov_tl(cc_result
, res
);
711 /* Returns one if the write back stage should execute. */
712 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
713 TCGv dst
, TCGv a
, TCGv b
, int size
)
715 /* Emit the ALU insns. */
718 tcg_gen_add_tl(dst
, a
, b
);
719 /* Extended arithmetics. */
720 t_gen_addx_carry(dc
, dst
);
723 tcg_gen_add_tl(dst
, a
, b
);
724 t_gen_add_flag(dst
, 0); /* C_FLAG. */
727 tcg_gen_add_tl(dst
, a
, b
);
728 t_gen_add_flag(dst
, 8); /* R_FLAG. */
731 tcg_gen_sub_tl(dst
, a
, b
);
732 /* Extended arithmetics. */
733 t_gen_subx_carry(dc
, dst
);
736 tcg_gen_mov_tl(dst
, b
);
739 tcg_gen_or_tl(dst
, a
, b
);
742 tcg_gen_and_tl(dst
, a
, b
);
745 tcg_gen_xor_tl(dst
, a
, b
);
748 t_gen_lsl(dst
, a
, b
);
751 t_gen_lsr(dst
, a
, b
);
754 t_gen_asr(dst
, a
, b
);
757 tcg_gen_neg_tl(dst
, b
);
758 /* Extended arithmetics. */
759 t_gen_subx_carry(dc
, dst
);
762 gen_helper_lz(dst
, b
);
765 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
768 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
771 t_gen_cris_dstep(dst
, a
, b
);
774 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
779 l1
= gen_new_label();
780 tcg_gen_mov_tl(dst
, a
);
781 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
782 tcg_gen_mov_tl(dst
, b
);
787 tcg_gen_sub_tl(dst
, a
, b
);
788 /* Extended arithmetics. */
789 t_gen_subx_carry(dc
, dst
);
792 qemu_log("illegal ALU op.\n");
798 tcg_gen_andi_tl(dst
, dst
, 0xff);
799 } else if (size
== 2) {
800 tcg_gen_andi_tl(dst
, dst
, 0xffff);
804 static void cris_alu(DisasContext
*dc
, int op
,
805 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
812 if (op
== CC_OP_CMP
) {
813 tmp
= tcg_temp_new();
815 } else if (size
== 4) {
819 tmp
= tcg_temp_new();
823 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
824 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
825 cris_update_result(dc
, tmp
);
830 tcg_gen_andi_tl(d
, d
, ~0xff);
832 tcg_gen_andi_tl(d
, d
, ~0xffff);
834 tcg_gen_or_tl(d
, d
, tmp
);
836 if (!TCGV_EQUAL(tmp
, d
)) {
841 static int arith_cc(DisasContext
*dc
)
845 case CC_OP_ADDC
: return 1;
846 case CC_OP_ADD
: return 1;
847 case CC_OP_SUB
: return 1;
848 case CC_OP_DSTEP
: return 1;
849 case CC_OP_LSL
: return 1;
850 case CC_OP_LSR
: return 1;
851 case CC_OP_ASR
: return 1;
852 case CC_OP_CMP
: return 1;
853 case CC_OP_NEG
: return 1;
854 case CC_OP_OR
: return 1;
855 case CC_OP_AND
: return 1;
856 case CC_OP_XOR
: return 1;
857 case CC_OP_MULU
: return 1;
858 case CC_OP_MULS
: return 1;
866 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
868 int arith_opt
, move_opt
;
870 /* TODO: optimize more condition codes. */
873 * If the flags are live, we've gotta look into the bits of CCS.
874 * Otherwise, if we just did an arithmetic operation we try to
875 * evaluate the condition code faster.
877 * When this function is done, T0 should be non-zero if the condition
880 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
881 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
884 if ((arith_opt
|| move_opt
)
885 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
886 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
887 cc_result
, tcg_const_tl(0));
889 cris_evaluate_flags(dc
);
891 cpu_PR
[PR_CCS
], Z_FLAG
);
895 if ((arith_opt
|| move_opt
)
896 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
897 tcg_gen_mov_tl(cc
, cc_result
);
899 cris_evaluate_flags(dc
);
900 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
902 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
906 cris_evaluate_flags(dc
);
907 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
910 cris_evaluate_flags(dc
);
911 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
912 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
915 cris_evaluate_flags(dc
);
916 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
919 cris_evaluate_flags(dc
);
920 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
922 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
925 if (arith_opt
|| move_opt
) {
928 if (dc
->cc_size
== 1) {
930 } else if (dc
->cc_size
== 2) {
934 tcg_gen_shri_tl(cc
, cc_result
, bits
);
935 tcg_gen_xori_tl(cc
, cc
, 1);
937 cris_evaluate_flags(dc
);
938 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
940 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
944 if (arith_opt
|| move_opt
) {
947 if (dc
->cc_size
== 1) {
949 } else if (dc
->cc_size
== 2) {
953 tcg_gen_shri_tl(cc
, cc_result
, bits
);
954 tcg_gen_andi_tl(cc
, cc
, 1);
956 cris_evaluate_flags(dc
);
957 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
962 cris_evaluate_flags(dc
);
963 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
967 cris_evaluate_flags(dc
);
971 tmp
= tcg_temp_new();
972 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
974 /* Overlay the C flag on top of the Z. */
975 tcg_gen_shli_tl(cc
, tmp
, 2);
976 tcg_gen_and_tl(cc
, tmp
, cc
);
977 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
983 cris_evaluate_flags(dc
);
984 /* Overlay the V flag on top of the N. */
985 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
988 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
989 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
992 cris_evaluate_flags(dc
);
993 /* Overlay the V flag on top of the N. */
994 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
997 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1000 cris_evaluate_flags(dc
);
1007 /* To avoid a shift we overlay everything on
1009 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1010 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1012 tcg_gen_xori_tl(z
, z
, 2);
1014 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1015 tcg_gen_xori_tl(n
, n
, 2);
1016 tcg_gen_and_tl(cc
, z
, n
);
1017 tcg_gen_andi_tl(cc
, cc
, 2);
1024 cris_evaluate_flags(dc
);
1031 /* To avoid a shift we overlay everything on
1033 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1034 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1036 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1037 tcg_gen_or_tl(cc
, z
, n
);
1038 tcg_gen_andi_tl(cc
, cc
, 2);
1045 cris_evaluate_flags(dc
);
1046 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1049 tcg_gen_movi_tl(cc
, 1);
1057 static void cris_store_direct_jmp(DisasContext
*dc
)
1059 /* Store the direct jmp state into the cpu-state. */
1060 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1061 if (dc
->jmp
== JMP_DIRECT
) {
1062 tcg_gen_movi_tl(env_btaken
, 1);
1064 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1065 dc
->jmp
= JMP_INDIRECT
;
1069 static void cris_prepare_cc_branch (DisasContext
*dc
,
1070 int offset
, int cond
)
1072 /* This helps us re-schedule the micro-code to insns in delay-slots
1073 before the actual jump. */
1074 dc
->delayed_branch
= 2;
1075 dc
->jmp
= JMP_DIRECT_CC
;
1076 dc
->jmp_pc
= dc
->pc
+ offset
;
1078 gen_tst_cc(dc
, env_btaken
, cond
);
1079 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1083 /* jumps, when the dest is in a live reg for example. Direct should be set
1084 when the dest addr is constant to allow tb chaining. */
1085 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1087 /* This helps us re-schedule the micro-code to insns in delay-slots
1088 before the actual jump. */
1089 dc
->delayed_branch
= 2;
1091 if (type
== JMP_INDIRECT
) {
1092 tcg_gen_movi_tl(env_btaken
, 1);
1096 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1098 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1100 /* If we get a fault on a delayslot we must keep the jmp state in
1101 the cpu-state to be able to re-execute the jmp. */
1102 if (dc
->delayed_branch
== 1) {
1103 cris_store_direct_jmp(dc
);
1106 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1109 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1110 unsigned int size
, int sign
)
1112 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1114 /* If we get a fault on a delayslot we must keep the jmp state in
1115 the cpu-state to be able to re-execute the jmp. */
1116 if (dc
->delayed_branch
== 1) {
1117 cris_store_direct_jmp(dc
);
1120 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1121 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1124 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1127 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
);
1129 /* If we get a fault on a delayslot we must keep the jmp state in
1130 the cpu-state to be able to re-execute the jmp. */
1131 if (dc
->delayed_branch
== 1) {
1132 cris_store_direct_jmp(dc
);
1136 /* Conditional writes. We only support the kind were X and P are known
1137 at translation time. */
1138 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1140 cris_evaluate_flags(dc
);
1141 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1145 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1147 if (dc
->flagx_known
&& dc
->flags_x
) {
1148 cris_evaluate_flags(dc
);
1149 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1153 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1156 tcg_gen_ext8s_i32(d
, s
);
1157 } else if (size
== 2) {
1158 tcg_gen_ext16s_i32(d
, s
);
1159 } else if (!TCGV_EQUAL(d
, s
)) {
1160 tcg_gen_mov_tl(d
, s
);
1164 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1167 tcg_gen_ext8u_i32(d
, s
);
1168 } else if (size
== 2) {
1169 tcg_gen_ext16u_i32(d
, s
);
1170 } else if (!TCGV_EQUAL(d
, s
)) {
1171 tcg_gen_mov_tl(d
, s
);
1176 static char memsize_char(int size
)
1179 case 1: return 'b'; break;
1180 case 2: return 'w'; break;
1181 case 4: return 'd'; break;
1189 static inline unsigned int memsize_z(DisasContext
*dc
)
1191 return dc
->zsize
+ 1;
1194 static inline unsigned int memsize_zz(DisasContext
*dc
)
1196 switch (dc
->zzsize
) {
1204 static inline void do_postinc (DisasContext
*dc
, int size
)
1207 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1211 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1212 int size
, int s_ext
, TCGv dst
)
1215 t_gen_sext(dst
, cpu_R
[rs
], size
);
1217 t_gen_zext(dst
, cpu_R
[rs
], size
);
1221 /* Prepare T0 and T1 for a register alu operation.
1222 s_ext decides if the operand1 should be sign-extended or zero-extended when
1224 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1225 int size
, int s_ext
, TCGv dst
, TCGv src
)
1227 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1230 t_gen_sext(dst
, cpu_R
[rd
], size
);
1232 t_gen_zext(dst
, cpu_R
[rd
], size
);
1236 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1237 int s_ext
, int memsize
, TCGv dst
)
1245 is_imm
= rs
== 15 && dc
->postinc
;
1247 /* Load [$rs] onto T1. */
1249 insn_len
= 2 + memsize
;
1254 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1255 tcg_gen_movi_tl(dst
, imm
);
1258 cris_flush_cc_state(dc
);
1259 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1261 t_gen_sext(dst
, dst
, memsize
);
1263 t_gen_zext(dst
, dst
, memsize
);
1269 /* Prepare T0 and T1 for a memory + alu operation.
1270 s_ext decides if the operand1 should be sign-extended or zero-extended when
1272 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1273 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1277 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1278 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1283 static const char *cc_name(int cc
)
1285 static const char *cc_names
[16] = {
1286 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1287 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1290 return cc_names
[cc
];
1294 /* Start of insn decoders. */
1296 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1300 uint32_t cond
= dc
->op2
;
1302 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1303 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1306 offset
|= sign
<< 8;
1307 offset
= sign_extend(offset
, 8);
1309 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1311 /* op2 holds the condition-code. */
1312 cris_cc_mask(dc
, 0);
1313 cris_prepare_cc_branch(dc
, offset
, cond
);
1316 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1320 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1321 imm
= sign_extend(dc
->op1
, 7);
1323 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1324 cris_cc_mask(dc
, 0);
1325 /* Fetch register operand, */
1326 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1330 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1332 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1334 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1336 cris_cc_mask(dc
, CC_MASK_NZVC
);
1338 cris_alu(dc
, CC_OP_ADD
,
1339 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1342 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1346 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1347 imm
= sign_extend(dc
->op1
, 5);
1348 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1350 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1353 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1355 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1357 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1359 cris_cc_mask(dc
, CC_MASK_NZVC
);
1360 cris_alu(dc
, CC_OP_SUB
,
1361 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1364 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1367 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1368 imm
= sign_extend(dc
->op1
, 5);
1370 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1371 cris_cc_mask(dc
, CC_MASK_NZVC
);
1373 cris_alu(dc
, CC_OP_CMP
,
1374 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1377 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1380 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1381 imm
= sign_extend(dc
->op1
, 5);
1383 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1384 cris_cc_mask(dc
, CC_MASK_NZ
);
1386 cris_alu(dc
, CC_OP_AND
,
1387 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1390 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1393 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1394 imm
= sign_extend(dc
->op1
, 5);
1395 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1396 cris_cc_mask(dc
, CC_MASK_NZ
);
1398 cris_alu(dc
, CC_OP_OR
,
1399 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1402 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1404 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1405 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1407 cris_cc_mask(dc
, CC_MASK_NZ
);
1408 cris_evaluate_flags(dc
);
1409 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1410 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1411 cris_alu(dc
, CC_OP_MOVE
,
1412 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1413 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1414 dc
->flags_uptodate
= 1;
1417 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1419 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1420 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1421 cris_cc_mask(dc
, CC_MASK_NZ
);
1423 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1424 cris_alu(dc
, CC_OP_MOVE
,
1426 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1429 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1431 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1432 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1434 cris_cc_mask(dc
, CC_MASK_NZ
);
1436 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1438 cris_alu(dc
, CC_OP_MOVE
,
1440 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1443 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1445 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1446 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1448 cris_cc_mask(dc
, CC_MASK_NZ
);
1450 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1451 cris_alu(dc
, CC_OP_MOVE
,
1453 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1457 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1459 int size
= memsize_zz(dc
);
1461 LOG_DIS("move.%c $r%u, $r%u\n",
1462 memsize_char(size
), dc
->op1
, dc
->op2
);
1464 cris_cc_mask(dc
, CC_MASK_NZ
);
1466 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1467 cris_cc_mask(dc
, CC_MASK_NZ
);
1468 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1469 cris_update_cc_x(dc
);
1470 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1474 t0
= tcg_temp_new();
1475 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1476 cris_alu(dc
, CC_OP_MOVE
,
1478 cpu_R
[dc
->op2
], t0
, size
);
1484 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1488 LOG_DIS("s%s $r%u\n",
1489 cc_name(cond
), dc
->op1
);
1494 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1495 l1
= gen_new_label();
1496 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1497 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1500 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1503 cris_cc_mask(dc
, 0);
1507 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1510 t
[0] = cpu_R
[dc
->op2
];
1511 t
[1] = cpu_R
[dc
->op1
];
1513 t
[0] = tcg_temp_new();
1514 t
[1] = tcg_temp_new();
1518 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1521 tcg_temp_free(t
[0]);
1522 tcg_temp_free(t
[1]);
1526 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1529 int size
= memsize_zz(dc
);
1531 LOG_DIS("and.%c $r%u, $r%u\n",
1532 memsize_char(size
), dc
->op1
, dc
->op2
);
1534 cris_cc_mask(dc
, CC_MASK_NZ
);
1536 cris_alu_alloc_temps(dc
, size
, t
);
1537 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1538 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1539 cris_alu_free_temps(dc
, size
, t
);
1543 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1546 LOG_DIS("lz $r%u, $r%u\n",
1548 cris_cc_mask(dc
, CC_MASK_NZ
);
1549 t0
= tcg_temp_new();
1550 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1551 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1556 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1559 int size
= memsize_zz(dc
);
1561 LOG_DIS("lsl.%c $r%u, $r%u\n",
1562 memsize_char(size
), dc
->op1
, dc
->op2
);
1564 cris_cc_mask(dc
, CC_MASK_NZ
);
1565 cris_alu_alloc_temps(dc
, size
, t
);
1566 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1567 tcg_gen_andi_tl(t
[1], t
[1], 63);
1568 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1569 cris_alu_alloc_temps(dc
, size
, t
);
1573 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1576 int size
= memsize_zz(dc
);
1578 LOG_DIS("lsr.%c $r%u, $r%u\n",
1579 memsize_char(size
), dc
->op1
, dc
->op2
);
1581 cris_cc_mask(dc
, CC_MASK_NZ
);
1582 cris_alu_alloc_temps(dc
, size
, t
);
1583 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1584 tcg_gen_andi_tl(t
[1], t
[1], 63);
1585 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1586 cris_alu_free_temps(dc
, size
, t
);
1590 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1593 int size
= memsize_zz(dc
);
1595 LOG_DIS("asr.%c $r%u, $r%u\n",
1596 memsize_char(size
), dc
->op1
, dc
->op2
);
1598 cris_cc_mask(dc
, CC_MASK_NZ
);
1599 cris_alu_alloc_temps(dc
, size
, t
);
1600 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1601 tcg_gen_andi_tl(t
[1], t
[1], 63);
1602 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1603 cris_alu_free_temps(dc
, size
, t
);
1607 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1610 int size
= memsize_zz(dc
);
1612 LOG_DIS("muls.%c $r%u, $r%u\n",
1613 memsize_char(size
), dc
->op1
, dc
->op2
);
1614 cris_cc_mask(dc
, CC_MASK_NZV
);
1615 cris_alu_alloc_temps(dc
, size
, t
);
1616 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1618 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1619 cris_alu_free_temps(dc
, size
, t
);
1623 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1626 int size
= memsize_zz(dc
);
1628 LOG_DIS("mulu.%c $r%u, $r%u\n",
1629 memsize_char(size
), dc
->op1
, dc
->op2
);
1630 cris_cc_mask(dc
, CC_MASK_NZV
);
1631 cris_alu_alloc_temps(dc
, size
, t
);
1632 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1634 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1635 cris_alu_alloc_temps(dc
, size
, t
);
1640 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1642 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1643 cris_cc_mask(dc
, CC_MASK_NZ
);
1644 cris_alu(dc
, CC_OP_DSTEP
,
1645 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1649 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1652 int size
= memsize_zz(dc
);
1653 LOG_DIS("xor.%c $r%u, $r%u\n",
1654 memsize_char(size
), dc
->op1
, dc
->op2
);
1655 BUG_ON(size
!= 4); /* xor is dword. */
1656 cris_cc_mask(dc
, CC_MASK_NZ
);
1657 cris_alu_alloc_temps(dc
, size
, t
);
1658 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1660 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1661 cris_alu_free_temps(dc
, size
, t
);
1665 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1668 int size
= memsize_zz(dc
);
1669 LOG_DIS("bound.%c $r%u, $r%u\n",
1670 memsize_char(size
), dc
->op1
, dc
->op2
);
1671 cris_cc_mask(dc
, CC_MASK_NZ
);
1672 l0
= tcg_temp_local_new();
1673 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1674 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1679 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1682 int size
= memsize_zz(dc
);
1683 LOG_DIS("cmp.%c $r%u, $r%u\n",
1684 memsize_char(size
), dc
->op1
, dc
->op2
);
1685 cris_cc_mask(dc
, CC_MASK_NZVC
);
1686 cris_alu_alloc_temps(dc
, size
, t
);
1687 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1689 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1690 cris_alu_free_temps(dc
, size
, t
);
1694 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1698 LOG_DIS("abs $r%u, $r%u\n",
1700 cris_cc_mask(dc
, CC_MASK_NZ
);
1702 t0
= tcg_temp_new();
1703 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1704 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1705 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1708 cris_alu(dc
, CC_OP_MOVE
,
1709 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1713 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1716 int size
= memsize_zz(dc
);
1717 LOG_DIS("add.%c $r%u, $r%u\n",
1718 memsize_char(size
), dc
->op1
, dc
->op2
);
1719 cris_cc_mask(dc
, CC_MASK_NZVC
);
1720 cris_alu_alloc_temps(dc
, size
, t
);
1721 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1723 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1724 cris_alu_free_temps(dc
, size
, t
);
1728 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1730 LOG_DIS("addc $r%u, $r%u\n",
1732 cris_evaluate_flags(dc
);
1733 /* Set for this insn. */
1734 dc
->flagx_known
= 1;
1735 dc
->flags_x
= X_FLAG
;
1737 cris_cc_mask(dc
, CC_MASK_NZVC
);
1738 cris_alu(dc
, CC_OP_ADDC
,
1739 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1743 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1745 LOG_DIS("mcp $p%u, $r%u\n",
1747 cris_evaluate_flags(dc
);
1748 cris_cc_mask(dc
, CC_MASK_RNZV
);
1749 cris_alu(dc
, CC_OP_MCP
,
1750 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1755 static char * swapmode_name(int mode
, char *modename
) {
1758 modename
[i
++] = 'n';
1761 modename
[i
++] = 'w';
1764 modename
[i
++] = 'b';
1767 modename
[i
++] = 'r';
1774 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1780 LOG_DIS("swap%s $r%u\n",
1781 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1783 cris_cc_mask(dc
, CC_MASK_NZ
);
1784 t0
= tcg_temp_new();
1785 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1787 tcg_gen_not_tl(t0
, t0
);
1790 t_gen_swapw(t0
, t0
);
1793 t_gen_swapb(t0
, t0
);
1796 t_gen_swapr(t0
, t0
);
1798 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1803 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1806 int size
= memsize_zz(dc
);
1807 LOG_DIS("or.%c $r%u, $r%u\n",
1808 memsize_char(size
), dc
->op1
, dc
->op2
);
1809 cris_cc_mask(dc
, CC_MASK_NZ
);
1810 cris_alu_alloc_temps(dc
, size
, t
);
1811 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1812 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1813 cris_alu_free_temps(dc
, size
, t
);
1817 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1820 LOG_DIS("addi.%c $r%u, $r%u\n",
1821 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1822 cris_cc_mask(dc
, 0);
1823 t0
= tcg_temp_new();
1824 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1825 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1830 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1833 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1834 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1835 cris_cc_mask(dc
, 0);
1836 t0
= tcg_temp_new();
1837 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1838 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1843 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1846 int size
= memsize_zz(dc
);
1847 LOG_DIS("neg.%c $r%u, $r%u\n",
1848 memsize_char(size
), dc
->op1
, dc
->op2
);
1849 cris_cc_mask(dc
, CC_MASK_NZVC
);
1850 cris_alu_alloc_temps(dc
, size
, t
);
1851 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1853 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1854 cris_alu_free_temps(dc
, size
, t
);
1858 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1860 LOG_DIS("btst $r%u, $r%u\n",
1862 cris_cc_mask(dc
, CC_MASK_NZ
);
1863 cris_evaluate_flags(dc
);
1864 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1865 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1866 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1867 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1868 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1869 dc
->flags_uptodate
= 1;
1873 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1876 int size
= memsize_zz(dc
);
1877 LOG_DIS("sub.%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]);
1882 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1883 cris_alu_free_temps(dc
, size
, t
);
1887 /* Zero extension. From size to dword. */
1888 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1891 int size
= memsize_z(dc
);
1892 LOG_DIS("movu.%c $r%u, $r%u\n",
1896 cris_cc_mask(dc
, CC_MASK_NZ
);
1897 t0
= tcg_temp_new();
1898 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1899 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1904 /* Sign extension. From size to dword. */
1905 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1908 int size
= memsize_z(dc
);
1909 LOG_DIS("movs.%c $r%u, $r%u\n",
1913 cris_cc_mask(dc
, CC_MASK_NZ
);
1914 t0
= tcg_temp_new();
1915 /* Size can only be qi or hi. */
1916 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1917 cris_alu(dc
, CC_OP_MOVE
,
1918 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1923 /* zero extension. From size to dword. */
1924 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1927 int size
= memsize_z(dc
);
1928 LOG_DIS("addu.%c $r%u, $r%u\n",
1932 cris_cc_mask(dc
, CC_MASK_NZVC
);
1933 t0
= tcg_temp_new();
1934 /* Size can only be qi or hi. */
1935 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1936 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1941 /* Sign extension. From size to dword. */
1942 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1945 int size
= memsize_z(dc
);
1946 LOG_DIS("adds.%c $r%u, $r%u\n",
1950 cris_cc_mask(dc
, CC_MASK_NZVC
);
1951 t0
= tcg_temp_new();
1952 /* Size can only be qi or hi. */
1953 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1954 cris_alu(dc
, CC_OP_ADD
,
1955 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1960 /* Zero extension. From size to dword. */
1961 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1964 int size
= memsize_z(dc
);
1965 LOG_DIS("subu.%c $r%u, $r%u\n",
1969 cris_cc_mask(dc
, CC_MASK_NZVC
);
1970 t0
= tcg_temp_new();
1971 /* Size can only be qi or hi. */
1972 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1973 cris_alu(dc
, CC_OP_SUB
,
1974 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1979 /* Sign extension. From size to dword. */
1980 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1983 int size
= memsize_z(dc
);
1984 LOG_DIS("subs.%c $r%u, $r%u\n",
1988 cris_cc_mask(dc
, CC_MASK_NZVC
);
1989 t0
= tcg_temp_new();
1990 /* Size can only be qi or hi. */
1991 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1992 cris_alu(dc
, CC_OP_SUB
,
1993 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1998 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
2001 int set
= (~dc
->opcode
>> 2) & 1;
2004 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2005 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2006 if (set
&& flags
== 0) {
2009 } else if (!set
&& (flags
& 0x20)) {
2012 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2015 /* User space is not allowed to touch these. Silently ignore. */
2016 if (dc
->tb_flags
& U_FLAG
) {
2017 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2020 if (flags
& X_FLAG
) {
2021 dc
->flagx_known
= 1;
2023 dc
->flags_x
= X_FLAG
;
2029 /* Break the TB if any of the SPI flag changes. */
2030 if (flags
& (P_FLAG
| S_FLAG
)) {
2031 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2032 dc
->is_jmp
= DISAS_UPDATE
;
2033 dc
->cpustate_changed
= 1;
2036 /* For the I flag, only act on posedge. */
2037 if ((flags
& I_FLAG
)) {
2038 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2039 dc
->is_jmp
= DISAS_UPDATE
;
2040 dc
->cpustate_changed
= 1;
2044 /* Simply decode the flags. */
2045 cris_evaluate_flags(dc
);
2046 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2047 cris_update_cc_x(dc
);
2048 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2051 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2052 /* Enter user mode. */
2053 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2054 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2055 dc
->cpustate_changed
= 1;
2057 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2059 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2062 dc
->flags_uptodate
= 1;
2067 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2069 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2070 cris_cc_mask(dc
, 0);
2071 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2072 tcg_const_tl(dc
->op1
));
2075 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2077 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2078 cris_cc_mask(dc
, 0);
2079 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2080 tcg_const_tl(dc
->op2
));
2084 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2087 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2088 cris_cc_mask(dc
, 0);
2090 t
[0] = tcg_temp_new();
2091 if (dc
->op2
== PR_CCS
) {
2092 cris_evaluate_flags(dc
);
2093 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2094 if (dc
->tb_flags
& U_FLAG
) {
2095 t
[1] = tcg_temp_new();
2096 /* User space is not allowed to touch all flags. */
2097 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2098 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2099 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2100 tcg_temp_free(t
[1]);
2103 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2106 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2107 if (dc
->op2
== PR_CCS
) {
2108 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2109 dc
->flags_uptodate
= 1;
2111 tcg_temp_free(t
[0]);
2114 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2117 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2118 cris_cc_mask(dc
, 0);
2120 if (dc
->op2
== PR_CCS
) {
2121 cris_evaluate_flags(dc
);
2124 if (dc
->op2
== PR_DZ
) {
2125 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2127 t0
= tcg_temp_new();
2128 t_gen_mov_TN_preg(t0
, dc
->op2
);
2129 cris_alu(dc
, CC_OP_MOVE
,
2130 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2131 preg_sizes
[dc
->op2
]);
2137 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2139 int memsize
= memsize_zz(dc
);
2141 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2142 memsize_char(memsize
),
2143 dc
->op1
, dc
->postinc
? "+]" : "]",
2147 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2148 cris_cc_mask(dc
, CC_MASK_NZ
);
2149 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2150 cris_update_cc_x(dc
);
2151 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2155 t0
= tcg_temp_new();
2156 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2157 cris_cc_mask(dc
, CC_MASK_NZ
);
2158 cris_alu(dc
, CC_OP_MOVE
,
2159 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2162 do_postinc(dc
, memsize
);
2166 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2168 t
[0] = tcg_temp_new();
2169 t
[1] = tcg_temp_new();
2172 static inline void cris_alu_m_free_temps(TCGv
*t
)
2174 tcg_temp_free(t
[0]);
2175 tcg_temp_free(t
[1]);
2178 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2181 int memsize
= memsize_z(dc
);
2183 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2184 memsize_char(memsize
),
2185 dc
->op1
, dc
->postinc
? "+]" : "]",
2188 cris_alu_m_alloc_temps(t
);
2190 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2191 cris_cc_mask(dc
, CC_MASK_NZ
);
2192 cris_alu(dc
, CC_OP_MOVE
,
2193 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2194 do_postinc(dc
, memsize
);
2195 cris_alu_m_free_temps(t
);
2199 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2202 int memsize
= memsize_z(dc
);
2204 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2205 memsize_char(memsize
),
2206 dc
->op1
, dc
->postinc
? "+]" : "]",
2209 cris_alu_m_alloc_temps(t
);
2211 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2212 cris_cc_mask(dc
, CC_MASK_NZVC
);
2213 cris_alu(dc
, CC_OP_ADD
,
2214 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2215 do_postinc(dc
, memsize
);
2216 cris_alu_m_free_temps(t
);
2220 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2223 int memsize
= memsize_z(dc
);
2225 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2226 memsize_char(memsize
),
2227 dc
->op1
, dc
->postinc
? "+]" : "]",
2230 cris_alu_m_alloc_temps(t
);
2232 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2233 cris_cc_mask(dc
, CC_MASK_NZVC
);
2234 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2235 do_postinc(dc
, memsize
);
2236 cris_alu_m_free_temps(t
);
2240 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2243 int memsize
= memsize_z(dc
);
2245 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2246 memsize_char(memsize
),
2247 dc
->op1
, dc
->postinc
? "+]" : "]",
2250 cris_alu_m_alloc_temps(t
);
2252 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2253 cris_cc_mask(dc
, CC_MASK_NZVC
);
2254 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2255 do_postinc(dc
, memsize
);
2256 cris_alu_m_free_temps(t
);
2260 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2263 int memsize
= memsize_z(dc
);
2265 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2266 memsize_char(memsize
),
2267 dc
->op1
, dc
->postinc
? "+]" : "]",
2270 cris_alu_m_alloc_temps(t
);
2272 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2273 cris_cc_mask(dc
, CC_MASK_NZVC
);
2274 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2275 do_postinc(dc
, memsize
);
2276 cris_alu_m_free_temps(t
);
2280 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2283 int memsize
= memsize_z(dc
);
2286 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2287 memsize_char(memsize
),
2288 dc
->op1
, dc
->postinc
? "+]" : "]",
2291 cris_alu_m_alloc_temps(t
);
2292 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2293 cris_cc_mask(dc
, CC_MASK_NZ
);
2294 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2295 do_postinc(dc
, memsize
);
2296 cris_alu_m_free_temps(t
);
2300 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2303 int memsize
= memsize_z(dc
);
2305 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2306 memsize_char(memsize
),
2307 dc
->op1
, dc
->postinc
? "+]" : "]",
2310 cris_alu_m_alloc_temps(t
);
2311 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2312 cris_cc_mask(dc
, CC_MASK_NZVC
);
2313 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2314 do_postinc(dc
, memsize
);
2315 cris_alu_m_free_temps(t
);
2319 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2322 int memsize
= memsize_z(dc
);
2324 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2325 memsize_char(memsize
),
2326 dc
->op1
, dc
->postinc
? "+]" : "]",
2329 cris_alu_m_alloc_temps(t
);
2330 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2331 cris_cc_mask(dc
, CC_MASK_NZVC
);
2332 cris_alu(dc
, CC_OP_CMP
,
2333 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2335 do_postinc(dc
, memsize
);
2336 cris_alu_m_free_temps(t
);
2340 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2343 int memsize
= memsize_zz(dc
);
2345 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2346 memsize_char(memsize
),
2347 dc
->op1
, dc
->postinc
? "+]" : "]",
2350 cris_alu_m_alloc_temps(t
);
2351 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2352 cris_cc_mask(dc
, CC_MASK_NZVC
);
2353 cris_alu(dc
, CC_OP_CMP
,
2354 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2356 do_postinc(dc
, memsize
);
2357 cris_alu_m_free_temps(t
);
2361 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2364 int memsize
= memsize_zz(dc
);
2366 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2367 memsize_char(memsize
),
2368 dc
->op1
, dc
->postinc
? "+]" : "]",
2371 cris_evaluate_flags(dc
);
2373 cris_alu_m_alloc_temps(t
);
2374 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2375 cris_cc_mask(dc
, CC_MASK_NZ
);
2376 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2378 cris_alu(dc
, CC_OP_CMP
,
2379 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2380 do_postinc(dc
, memsize
);
2381 cris_alu_m_free_temps(t
);
2385 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2388 int memsize
= memsize_zz(dc
);
2390 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2391 memsize_char(memsize
),
2392 dc
->op1
, dc
->postinc
? "+]" : "]",
2395 cris_alu_m_alloc_temps(t
);
2396 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2397 cris_cc_mask(dc
, CC_MASK_NZ
);
2398 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2399 do_postinc(dc
, memsize
);
2400 cris_alu_m_free_temps(t
);
2404 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2407 int memsize
= memsize_zz(dc
);
2409 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2410 memsize_char(memsize
),
2411 dc
->op1
, dc
->postinc
? "+]" : "]",
2414 cris_alu_m_alloc_temps(t
);
2415 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2416 cris_cc_mask(dc
, CC_MASK_NZVC
);
2417 cris_alu(dc
, CC_OP_ADD
,
2418 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2419 do_postinc(dc
, memsize
);
2420 cris_alu_m_free_temps(t
);
2424 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2427 int memsize
= memsize_zz(dc
);
2429 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2430 memsize_char(memsize
),
2431 dc
->op1
, dc
->postinc
? "+]" : "]",
2434 cris_alu_m_alloc_temps(t
);
2435 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2436 cris_cc_mask(dc
, 0);
2437 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2438 do_postinc(dc
, memsize
);
2439 cris_alu_m_free_temps(t
);
2443 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2446 int memsize
= memsize_zz(dc
);
2448 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2449 memsize_char(memsize
),
2450 dc
->op1
, dc
->postinc
? "+]" : "]",
2453 l
[0] = tcg_temp_local_new();
2454 l
[1] = tcg_temp_local_new();
2455 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2456 cris_cc_mask(dc
, CC_MASK_NZ
);
2457 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2458 do_postinc(dc
, memsize
);
2459 tcg_temp_free(l
[0]);
2460 tcg_temp_free(l
[1]);
2464 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2468 LOG_DIS("addc [$r%u%s, $r%u\n",
2469 dc
->op1
, dc
->postinc
? "+]" : "]",
2472 cris_evaluate_flags(dc
);
2474 /* Set for this insn. */
2475 dc
->flagx_known
= 1;
2476 dc
->flags_x
= X_FLAG
;
2478 cris_alu_m_alloc_temps(t
);
2479 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2480 cris_cc_mask(dc
, CC_MASK_NZVC
);
2481 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2483 cris_alu_m_free_temps(t
);
2487 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2490 int memsize
= memsize_zz(dc
);
2492 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2493 memsize_char(memsize
),
2494 dc
->op1
, dc
->postinc
? "+]" : "]",
2495 dc
->op2
, dc
->ir
, dc
->zzsize
);
2497 cris_alu_m_alloc_temps(t
);
2498 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2499 cris_cc_mask(dc
, CC_MASK_NZVC
);
2500 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2501 do_postinc(dc
, memsize
);
2502 cris_alu_m_free_temps(t
);
2506 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2509 int memsize
= memsize_zz(dc
);
2511 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2512 memsize_char(memsize
),
2513 dc
->op1
, dc
->postinc
? "+]" : "]",
2516 cris_alu_m_alloc_temps(t
);
2517 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2518 cris_cc_mask(dc
, CC_MASK_NZ
);
2519 cris_alu(dc
, CC_OP_OR
,
2520 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2521 do_postinc(dc
, memsize
);
2522 cris_alu_m_free_temps(t
);
2526 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2529 int memsize
= memsize_zz(dc
);
2532 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2533 memsize_char(memsize
),
2535 dc
->postinc
? "+]" : "]",
2538 cris_alu_m_alloc_temps(t
);
2539 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2540 cris_cc_mask(dc
, 0);
2541 if (dc
->op2
== PR_CCS
) {
2542 cris_evaluate_flags(dc
);
2543 if (dc
->tb_flags
& U_FLAG
) {
2544 /* User space is not allowed to touch all flags. */
2545 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2546 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2547 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2551 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2553 do_postinc(dc
, memsize
);
2554 cris_alu_m_free_temps(t
);
2558 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2563 memsize
= preg_sizes
[dc
->op2
];
2565 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2566 memsize_char(memsize
),
2567 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2569 /* prepare store. Address in T0, value in T1. */
2570 if (dc
->op2
== PR_CCS
) {
2571 cris_evaluate_flags(dc
);
2573 t0
= tcg_temp_new();
2574 t_gen_mov_TN_preg(t0
, dc
->op2
);
2575 cris_flush_cc_state(dc
);
2576 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2579 cris_cc_mask(dc
, 0);
2581 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2586 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2592 int nr
= dc
->op2
+ 1;
2594 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2595 dc
->postinc
? "+]" : "]", dc
->op2
);
2597 addr
= tcg_temp_new();
2598 /* There are probably better ways of doing this. */
2599 cris_flush_cc_state(dc
);
2600 for (i
= 0; i
< (nr
>> 1); i
++) {
2601 tmp
[i
] = tcg_temp_new_i64();
2602 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2603 gen_load64(dc
, tmp
[i
], addr
);
2606 tmp32
= tcg_temp_new_i32();
2607 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2608 gen_load(dc
, tmp32
, addr
, 4, 0);
2612 tcg_temp_free(addr
);
2614 for (i
= 0; i
< (nr
>> 1); i
++) {
2615 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2616 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2617 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2618 tcg_temp_free_i64(tmp
[i
]);
2621 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2622 tcg_temp_free(tmp32
);
2625 /* writeback the updated pointer value. */
2627 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2630 /* gen_load might want to evaluate the previous insns flags. */
2631 cris_cc_mask(dc
, 0);
2635 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2641 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2642 dc
->postinc
? "+]" : "]");
2644 cris_flush_cc_state(dc
);
2646 tmp
= tcg_temp_new();
2647 addr
= tcg_temp_new();
2648 tcg_gen_movi_tl(tmp
, 4);
2649 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2650 for (i
= 0; i
<= dc
->op2
; i
++) {
2651 /* Displace addr. */
2652 /* Perform the store. */
2653 gen_store(dc
, addr
, cpu_R
[i
], 4);
2654 tcg_gen_add_tl(addr
, addr
, tmp
);
2657 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2659 cris_cc_mask(dc
, 0);
2661 tcg_temp_free(addr
);
2665 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2669 memsize
= memsize_zz(dc
);
2671 LOG_DIS("move.%c $r%u, [$r%u]\n",
2672 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2674 /* prepare store. */
2675 cris_flush_cc_state(dc
);
2676 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2679 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2681 cris_cc_mask(dc
, 0);
2685 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2687 LOG_DIS("lapcq %x, $r%u\n",
2688 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2689 cris_cc_mask(dc
, 0);
2690 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2694 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2702 cris_cc_mask(dc
, 0);
2703 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2704 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2708 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2712 /* Jump to special reg. */
2713 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2715 LOG_DIS("jump $p%u\n", dc
->op2
);
2717 if (dc
->op2
== PR_CCS
) {
2718 cris_evaluate_flags(dc
);
2720 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2721 /* rete will often have low bit set to indicate delayslot. */
2722 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2723 cris_cc_mask(dc
, 0);
2724 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2728 /* Jump and save. */
2729 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2731 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2732 cris_cc_mask(dc
, 0);
2733 /* Store the return address in Pd. */
2734 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2738 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2740 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2744 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2748 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2750 LOG_DIS("jas 0x%x\n", imm
);
2751 cris_cc_mask(dc
, 0);
2752 /* Store the return address in Pd. */
2753 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2756 cris_prepare_jmp(dc
, JMP_DIRECT
);
2760 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2764 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2766 LOG_DIS("jasc 0x%x\n", imm
);
2767 cris_cc_mask(dc
, 0);
2768 /* Store the return address in Pd. */
2769 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2772 cris_prepare_jmp(dc
, JMP_DIRECT
);
2776 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2778 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2779 cris_cc_mask(dc
, 0);
2780 /* Store the return address in Pd. */
2781 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2782 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2783 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2787 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2790 uint32_t cond
= dc
->op2
;
2792 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2794 LOG_DIS("b%s %d pc=%x dst=%x\n",
2795 cc_name(cond
), offset
,
2796 dc
->pc
, dc
->pc
+ offset
);
2798 cris_cc_mask(dc
, 0);
2799 /* op2 holds the condition-code. */
2800 cris_prepare_cc_branch(dc
, offset
, cond
);
2804 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2808 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2810 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2811 cris_cc_mask(dc
, 0);
2812 /* Store the return address in Pd. */
2813 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2815 dc
->jmp_pc
= dc
->pc
+ simm
;
2816 cris_prepare_jmp(dc
, JMP_DIRECT
);
2820 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2823 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2825 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2826 cris_cc_mask(dc
, 0);
2827 /* Store the return address in Pd. */
2828 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2830 dc
->jmp_pc
= dc
->pc
+ simm
;
2831 cris_prepare_jmp(dc
, JMP_DIRECT
);
2835 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2837 cris_cc_mask(dc
, 0);
2839 if (dc
->op2
== 15) {
2840 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2841 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2842 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2843 t_gen_raise_exception(EXCP_HLT
);
2847 switch (dc
->op2
& 7) {
2851 cris_evaluate_flags(dc
);
2852 gen_helper_rfe(cpu_env
);
2853 dc
->is_jmp
= DISAS_UPDATE
;
2858 cris_evaluate_flags(dc
);
2859 gen_helper_rfn(cpu_env
);
2860 dc
->is_jmp
= DISAS_UPDATE
;
2863 LOG_DIS("break %d\n", dc
->op1
);
2864 cris_evaluate_flags(dc
);
2866 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2868 /* Breaks start at 16 in the exception vector. */
2869 t_gen_mov_env_TN(trap_vector
,
2870 tcg_const_tl(dc
->op1
+ 16));
2871 t_gen_raise_exception(EXCP_BREAK
);
2872 dc
->is_jmp
= DISAS_UPDATE
;
2875 printf("op2=%x\n", dc
->op2
);
2883 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2888 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2893 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2895 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2896 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2902 static struct decoder_info
{
2907 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2909 /* Order matters here. */
2910 {DEC_MOVEQ
, dec_moveq
},
2911 {DEC_BTSTQ
, dec_btstq
},
2912 {DEC_CMPQ
, dec_cmpq
},
2913 {DEC_ADDOQ
, dec_addoq
},
2914 {DEC_ADDQ
, dec_addq
},
2915 {DEC_SUBQ
, dec_subq
},
2916 {DEC_ANDQ
, dec_andq
},
2918 {DEC_ASRQ
, dec_asrq
},
2919 {DEC_LSLQ
, dec_lslq
},
2920 {DEC_LSRQ
, dec_lsrq
},
2921 {DEC_BCCQ
, dec_bccq
},
2923 {DEC_BCC_IM
, dec_bcc_im
},
2924 {DEC_JAS_IM
, dec_jas_im
},
2925 {DEC_JAS_R
, dec_jas_r
},
2926 {DEC_JASC_IM
, dec_jasc_im
},
2927 {DEC_JASC_R
, dec_jasc_r
},
2928 {DEC_BAS_IM
, dec_bas_im
},
2929 {DEC_BASC_IM
, dec_basc_im
},
2930 {DEC_JUMP_P
, dec_jump_p
},
2931 {DEC_LAPC_IM
, dec_lapc_im
},
2932 {DEC_LAPCQ
, dec_lapcq
},
2934 {DEC_RFE_ETC
, dec_rfe_etc
},
2935 {DEC_ADDC_MR
, dec_addc_mr
},
2937 {DEC_MOVE_MP
, dec_move_mp
},
2938 {DEC_MOVE_PM
, dec_move_pm
},
2939 {DEC_MOVEM_MR
, dec_movem_mr
},
2940 {DEC_MOVEM_RM
, dec_movem_rm
},
2941 {DEC_MOVE_PR
, dec_move_pr
},
2942 {DEC_SCC_R
, dec_scc_r
},
2943 {DEC_SETF
, dec_setclrf
},
2944 {DEC_CLEARF
, dec_setclrf
},
2946 {DEC_MOVE_SR
, dec_move_sr
},
2947 {DEC_MOVE_RP
, dec_move_rp
},
2948 {DEC_SWAP_R
, dec_swap_r
},
2949 {DEC_ABS_R
, dec_abs_r
},
2950 {DEC_LZ_R
, dec_lz_r
},
2951 {DEC_MOVE_RS
, dec_move_rs
},
2952 {DEC_BTST_R
, dec_btst_r
},
2953 {DEC_ADDC_R
, dec_addc_r
},
2955 {DEC_DSTEP_R
, dec_dstep_r
},
2956 {DEC_XOR_R
, dec_xor_r
},
2957 {DEC_MCP_R
, dec_mcp_r
},
2958 {DEC_CMP_R
, dec_cmp_r
},
2960 {DEC_ADDI_R
, dec_addi_r
},
2961 {DEC_ADDI_ACR
, dec_addi_acr
},
2963 {DEC_ADD_R
, dec_add_r
},
2964 {DEC_SUB_R
, dec_sub_r
},
2966 {DEC_ADDU_R
, dec_addu_r
},
2967 {DEC_ADDS_R
, dec_adds_r
},
2968 {DEC_SUBU_R
, dec_subu_r
},
2969 {DEC_SUBS_R
, dec_subs_r
},
2970 {DEC_LSL_R
, dec_lsl_r
},
2972 {DEC_AND_R
, dec_and_r
},
2973 {DEC_OR_R
, dec_or_r
},
2974 {DEC_BOUND_R
, dec_bound_r
},
2975 {DEC_ASR_R
, dec_asr_r
},
2976 {DEC_LSR_R
, dec_lsr_r
},
2978 {DEC_MOVU_R
, dec_movu_r
},
2979 {DEC_MOVS_R
, dec_movs_r
},
2980 {DEC_NEG_R
, dec_neg_r
},
2981 {DEC_MOVE_R
, dec_move_r
},
2983 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2984 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2986 {DEC_MULS_R
, dec_muls_r
},
2987 {DEC_MULU_R
, dec_mulu_r
},
2989 {DEC_ADDU_M
, dec_addu_m
},
2990 {DEC_ADDS_M
, dec_adds_m
},
2991 {DEC_SUBU_M
, dec_subu_m
},
2992 {DEC_SUBS_M
, dec_subs_m
},
2994 {DEC_CMPU_M
, dec_cmpu_m
},
2995 {DEC_CMPS_M
, dec_cmps_m
},
2996 {DEC_MOVU_M
, dec_movu_m
},
2997 {DEC_MOVS_M
, dec_movs_m
},
2999 {DEC_CMP_M
, dec_cmp_m
},
3000 {DEC_ADDO_M
, dec_addo_m
},
3001 {DEC_BOUND_M
, dec_bound_m
},
3002 {DEC_ADD_M
, dec_add_m
},
3003 {DEC_SUB_M
, dec_sub_m
},
3004 {DEC_AND_M
, dec_and_m
},
3005 {DEC_OR_M
, dec_or_m
},
3006 {DEC_MOVE_RM
, dec_move_rm
},
3007 {DEC_TEST_M
, dec_test_m
},
3008 {DEC_MOVE_MR
, dec_move_mr
},
3013 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3018 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3019 tcg_gen_debug_insn_start(dc
->pc
);
3022 /* Load a halfword onto the instruction register. */
3023 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3025 /* Now decode it. */
3026 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3027 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3028 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3029 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3030 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3031 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3033 /* Large switch for all insns. */
3034 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3035 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3036 insn_len
= decinfo
[i
].dec(env
, dc
);
3041 #if !defined(CONFIG_USER_ONLY)
3042 /* Single-stepping ? */
3043 if (dc
->tb_flags
& S_FLAG
) {
3046 l1
= gen_new_label();
3047 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3048 /* We treat SPC as a break with an odd trap vector. */
3049 cris_evaluate_flags(dc
);
3050 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3051 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3052 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3053 t_gen_raise_exception(EXCP_BREAK
);
3060 static void check_breakpoint(CPUCRISState
*env
, DisasContext
*dc
)
3062 CPUState
*cs
= CPU(cris_env_get_cpu(env
));
3065 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
3066 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
3067 if (bp
->pc
== dc
->pc
) {
3068 cris_evaluate_flags(dc
);
3069 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3070 t_gen_raise_exception(EXCP_DEBUG
);
3071 dc
->is_jmp
= DISAS_UPDATE
;
3077 #include "translate_v10.c"
3080 * Delay slots on QEMU/CRIS.
3082 * If an exception hits on a delayslot, the core will let ERP (the Exception
3083 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3084 * to give SW a hint that the exception actually hit on the dslot.
3086 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3087 * the core and any jmp to an odd addresses will mask off that lsb. It is
3088 * simply there to let sw know there was an exception on a dslot.
3090 * When the software returns from an exception, the branch will re-execute.
3091 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3092 * and the branch and delayslot dont share pages.
3094 * The TB contaning the branch insn will set up env->btarget and evaluate
3095 * env->btaken. When the translation loop exits we will note that the branch
3096 * sequence is broken and let env->dslot be the size of the branch insn (those
3099 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3100 * set). It will also expect to have env->dslot setup with the size of the
3101 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3102 * will execute the dslot and take the branch, either to btarget or just one
3105 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3106 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3107 * branch and set lsb). Then env->dslot gets cleared so that the exception
3108 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3109 * masked off and we will reexecute the branch insn.
3113 /* generate intermediate code for basic block 'tb'. */
3115 gen_intermediate_code_internal(CRISCPU
*cpu
, TranslationBlock
*tb
,
3118 CPUState
*cs
= CPU(cpu
);
3119 CPUCRISState
*env
= &cpu
->env
;
3120 uint16_t *gen_opc_end
;
3122 unsigned int insn_len
;
3124 struct DisasContext ctx
;
3125 struct DisasContext
*dc
= &ctx
;
3126 uint32_t next_page_start
;
3131 if (env
->pregs
[PR_VR
] == 32) {
3132 dc
->decoder
= crisv32_decoder
;
3133 dc
->clear_locked_irq
= 0;
3135 dc
->decoder
= crisv10_decoder
;
3136 dc
->clear_locked_irq
= 1;
3139 /* Odd PC indicates that branch is rexecuting due to exception in the
3140 * delayslot, like in real hw.
3142 pc_start
= tb
->pc
& ~1;
3146 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
3148 dc
->is_jmp
= DISAS_NEXT
;
3151 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3152 dc
->flags_uptodate
= 1;
3153 dc
->flagx_known
= 1;
3154 dc
->flags_x
= tb
->flags
& X_FLAG
;
3155 dc
->cc_x_uptodate
= 0;
3158 dc
->clear_prefix
= 0;
3160 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3161 dc
->cc_size_uptodate
= -1;
3163 /* Decode TB flags. */
3164 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3165 | X_FLAG
| PFIX_FLAG
);
3166 dc
->delayed_branch
= !!(tb
->flags
& 7);
3167 if (dc
->delayed_branch
) {
3168 dc
->jmp
= JMP_INDIRECT
;
3170 dc
->jmp
= JMP_NOJMP
;
3173 dc
->cpustate_changed
= 0;
3175 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3177 "srch=%d pc=%x %x flg=%" PRIx64
" bt=%x ds=%u ccs=%x\n"
3183 search_pc
, dc
->pc
, dc
->ppc
,
3184 (uint64_t)tb
->flags
,
3185 env
->btarget
, (unsigned)tb
->flags
& 7,
3187 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3188 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3189 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3190 env
->regs
[8], env
->regs
[9],
3191 env
->regs
[10], env
->regs
[11],
3192 env
->regs
[12], env
->regs
[13],
3193 env
->regs
[14], env
->regs
[15]);
3194 qemu_log("--------------\n");
3195 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3198 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3201 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3202 if (max_insns
== 0) {
3203 max_insns
= CF_COUNT_MASK
;
3208 check_breakpoint(env
, dc
);
3211 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3215 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3218 if (dc
->delayed_branch
== 1) {
3219 tcg_ctx
.gen_opc_pc
[lj
] = dc
->ppc
| 1;
3221 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
3223 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3224 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
3228 LOG_DIS("%8.8x:\t", dc
->pc
);
3230 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3235 insn_len
= dc
->decoder(env
, dc
);
3239 cris_clear_x_flag(dc
);
3243 /* Check for delayed branches here. If we do it before
3244 actually generating any host code, the simulator will just
3245 loop doing nothing for on this program location. */
3246 if (dc
->delayed_branch
) {
3247 dc
->delayed_branch
--;
3248 if (dc
->delayed_branch
== 0) {
3249 if (tb
->flags
& 7) {
3250 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3252 if (dc
->cpustate_changed
|| !dc
->flagx_known
3253 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3254 cris_store_direct_jmp(dc
);
3257 if (dc
->clear_locked_irq
) {
3258 dc
->clear_locked_irq
= 0;
3259 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3262 if (dc
->jmp
== JMP_DIRECT_CC
) {
3265 l1
= gen_new_label();
3266 cris_evaluate_flags(dc
);
3268 /* Conditional jmp. */
3269 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3271 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3273 gen_goto_tb(dc
, 0, dc
->pc
);
3274 dc
->is_jmp
= DISAS_TB_JUMP
;
3275 dc
->jmp
= JMP_NOJMP
;
3276 } else if (dc
->jmp
== JMP_DIRECT
) {
3277 cris_evaluate_flags(dc
);
3278 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3279 dc
->is_jmp
= DISAS_TB_JUMP
;
3280 dc
->jmp
= JMP_NOJMP
;
3282 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3283 dc
->is_jmp
= DISAS_JUMP
;
3289 /* If we are rexecuting a branch due to exceptions on
3290 delay slots dont break. */
3291 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3294 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3295 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
3297 && (dc
->pc
< next_page_start
)
3298 && num_insns
< max_insns
);
3300 if (dc
->clear_locked_irq
) {
3301 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3306 if (tb
->cflags
& CF_LAST_IO
)
3308 /* Force an update if the per-tb cpu state has changed. */
3309 if (dc
->is_jmp
== DISAS_NEXT
3310 && (dc
->cpustate_changed
|| !dc
->flagx_known
3311 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3312 dc
->is_jmp
= DISAS_UPDATE
;
3313 tcg_gen_movi_tl(env_pc
, npc
);
3315 /* Broken branch+delayslot sequence. */
3316 if (dc
->delayed_branch
== 1) {
3317 /* Set env->dslot to the size of the branch insn. */
3318 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3319 cris_store_direct_jmp(dc
);
3322 cris_evaluate_flags(dc
);
3324 if (unlikely(cs
->singlestep_enabled
)) {
3325 if (dc
->is_jmp
== DISAS_NEXT
) {
3326 tcg_gen_movi_tl(env_pc
, npc
);
3328 t_gen_raise_exception(EXCP_DEBUG
);
3330 switch (dc
->is_jmp
) {
3332 gen_goto_tb(dc
, 1, npc
);
3337 /* indicate that the hash table must be used
3338 to find the next TB */
3343 /* nothing more to generate */
3347 gen_tb_end(tb
, num_insns
);
3348 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3350 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3353 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3356 tb
->size
= dc
->pc
- pc_start
;
3357 tb
->icount
= num_insns
;
3362 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3363 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
3365 qemu_log("\nisize=%d osize=%td\n",
3366 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
);
3372 void gen_intermediate_code (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3374 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, false);
3377 void gen_intermediate_code_pc (CPUCRISState
*env
, struct TranslationBlock
*tb
)
3379 gen_intermediate_code_internal(cris_env_get_cpu(env
), tb
, true);
3382 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
3385 CRISCPU
*cpu
= CRIS_CPU(cs
);
3386 CPUCRISState
*env
= &cpu
->env
;
3394 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3395 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3396 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3398 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3401 for (i
= 0; i
< 16; i
++) {
3402 cpu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3403 if ((i
+ 1) % 4 == 0) {
3404 cpu_fprintf(f
, "\n");
3407 cpu_fprintf(f
, "\nspecial regs:\n");
3408 for (i
= 0; i
< 16; i
++) {
3409 cpu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3410 if ((i
+ 1) % 4 == 0) {
3411 cpu_fprintf(f
, "\n");
3414 srs
= env
->pregs
[PR_SRS
];
3415 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3416 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3417 for (i
= 0; i
< 16; i
++) {
3418 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3419 i
, env
->sregs
[srs
][i
]);
3420 if ((i
+ 1) % 4 == 0) {
3421 cpu_fprintf(f
, "\n");
3425 cpu_fprintf(f
, "\n\n");
3429 void cris_initialize_tcg(void)
3433 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3434 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3435 offsetof(CPUCRISState
, cc_x
), "cc_x");
3436 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3437 offsetof(CPUCRISState
, cc_src
), "cc_src");
3438 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3439 offsetof(CPUCRISState
, cc_dest
),
3441 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3442 offsetof(CPUCRISState
, cc_result
),
3444 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3445 offsetof(CPUCRISState
, cc_op
), "cc_op");
3446 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3447 offsetof(CPUCRISState
, cc_size
),
3449 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3450 offsetof(CPUCRISState
, cc_mask
),
3453 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3454 offsetof(CPUCRISState
, pc
),
3456 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3457 offsetof(CPUCRISState
, btarget
),
3459 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3460 offsetof(CPUCRISState
, btaken
),
3462 for (i
= 0; i
< 16; i
++) {
3463 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3464 offsetof(CPUCRISState
, regs
[i
]),
3467 for (i
= 0; i
< 16; i
++) {
3468 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3469 offsetof(CPUCRISState
, pregs
[i
]),
3474 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
, int pc_pos
)
3476 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];