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.
26 #include "qemu/osdep.h"
28 #include "disas/disas.h"
29 #include "exec/exec-all.h"
30 #include "tcg/tcg-op.h"
31 #include "exec/helper-proto.h"
33 #include "exec/cpu_ldst.h"
34 #include "exec/translator.h"
35 #include "crisv32-decode.h"
36 #include "qemu/qemu-print.h"
38 #include "exec/helper-gen.h"
40 #include "trace-tcg.h"
46 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
48 # define LOG_DIS(...) do { } while (0)
52 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
53 #define BUG_ON(x) ({if (x) BUG();})
55 /* is_jmp field values */
56 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
57 #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */
58 #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
59 #define DISAS_SWI DISAS_TARGET_3
61 /* Used by the decoder. */
62 #define EXTRACT_FIELD(src, start, end) \
63 (((src) >> start) & ((1 << (end - start + 1)) - 1))
65 #define CC_MASK_NZ 0xc
66 #define CC_MASK_NZV 0xe
67 #define CC_MASK_NZVC 0xf
68 #define CC_MASK_RNZV 0x10e
70 static TCGv cpu_R
[16];
71 static TCGv cpu_PR
[16];
75 static TCGv cc_result
;
80 static TCGv env_btaken
;
81 static TCGv env_btarget
;
84 #include "exec/gen-icount.h"
86 /* This is the state at translation time. */
87 typedef struct DisasContext
{
92 unsigned int (*decoder
)(CPUCRISState
*env
, struct DisasContext
*dc
);
97 unsigned int zsize
, zzsize
;
111 int cc_size_uptodate
; /* -1 invalid or last written value. */
113 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not up-to-date. */
114 int flags_uptodate
; /* Whether or not $ccs is up-to-date. */
115 int flagx_known
; /* Whether or not flags_x has the x flag known at
119 int clear_x
; /* Clear x after this insn? */
120 int clear_prefix
; /* Clear prefix after this insn? */
121 int clear_locked_irq
; /* Clear the irq lockout. */
122 int cpustate_changed
;
123 unsigned int tb_flags
; /* tb dependent flags. */
128 #define JMP_DIRECT_CC 2
129 #define JMP_INDIRECT 3
130 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
135 struct TranslationBlock
*tb
;
136 int singlestep_enabled
;
139 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
141 cpu_abort(CPU(dc
->cpu
), "%s:%d pc=%x\n", file
, line
, dc
->pc
);
144 static const char *regnames_v32
[] =
146 "$r0", "$r1", "$r2", "$r3",
147 "$r4", "$r5", "$r6", "$r7",
148 "$r8", "$r9", "$r10", "$r11",
149 "$r12", "$r13", "$sp", "$acr",
151 static const char *pregnames_v32
[] =
153 "$bz", "$vr", "$pid", "$srs",
154 "$wz", "$exs", "$eda", "$mof",
155 "$dz", "$ebp", "$erp", "$srp",
156 "$nrp", "$ccs", "$usp", "$spc",
159 /* We need this table to handle preg-moves with implicit width. */
160 static int preg_sizes
[] = {
171 #define t_gen_mov_TN_env(tn, member) \
172 tcg_gen_ld_tl(tn, cpu_env, offsetof(CPUCRISState, member))
173 #define t_gen_mov_env_TN(member, tn) \
174 tcg_gen_st_tl(tn, cpu_env, offsetof(CPUCRISState, member))
176 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
178 assert(r
>= 0 && r
<= 15);
179 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
180 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
181 } else if (r
== PR_VR
) {
182 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
184 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
187 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
189 assert(r
>= 0 && r
<= 15);
190 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
) {
192 } else if (r
== PR_SRS
) {
193 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
196 gen_helper_tlb_flush_pid(cpu_env
, tn
);
198 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
) {
199 gen_helper_spc_write(cpu_env
, tn
);
200 } else if (r
== PR_CCS
) {
201 dc
->cpustate_changed
= 1;
203 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
207 /* Sign extend at translation time. */
208 static int sign_extend(unsigned int val
, unsigned int width
)
220 static int cris_fetch(CPUCRISState
*env
, DisasContext
*dc
, uint32_t addr
,
221 unsigned int size
, unsigned int sign
)
228 r
= cpu_ldl_code(env
, addr
);
234 r
= cpu_ldsw_code(env
, addr
);
236 r
= cpu_lduw_code(env
, addr
);
243 r
= cpu_ldsb_code(env
, addr
);
245 r
= cpu_ldub_code(env
, addr
);
250 cpu_abort(CPU(dc
->cpu
), "Invalid fetch size %d\n", size
);
256 static void cris_lock_irq(DisasContext
*dc
)
258 dc
->clear_locked_irq
= 0;
259 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(1));
262 static inline void t_gen_raise_exception(uint32_t index
)
264 TCGv_i32 tmp
= tcg_const_i32(index
);
265 gen_helper_raise_exception(cpu_env
, tmp
);
266 tcg_temp_free_i32(tmp
);
269 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
274 t_31
= tcg_const_tl(31);
275 tcg_gen_shl_tl(d
, a
, b
);
277 tcg_gen_sub_tl(t0
, t_31
, b
);
278 tcg_gen_sar_tl(t0
, t0
, t_31
);
279 tcg_gen_and_tl(t0
, t0
, d
);
280 tcg_gen_xor_tl(d
, d
, t0
);
285 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
290 t_31
= tcg_temp_new();
291 tcg_gen_shr_tl(d
, a
, b
);
293 tcg_gen_movi_tl(t_31
, 31);
294 tcg_gen_sub_tl(t0
, t_31
, b
);
295 tcg_gen_sar_tl(t0
, t0
, t_31
);
296 tcg_gen_and_tl(t0
, t0
, d
);
297 tcg_gen_xor_tl(d
, d
, t0
);
302 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
307 t_31
= tcg_temp_new();
308 tcg_gen_sar_tl(d
, a
, b
);
310 tcg_gen_movi_tl(t_31
, 31);
311 tcg_gen_sub_tl(t0
, t_31
, b
);
312 tcg_gen_sar_tl(t0
, t0
, t_31
);
313 tcg_gen_or_tl(d
, d
, t0
);
318 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
320 TCGv t
= tcg_temp_new();
327 tcg_gen_shli_tl(d
, a
, 1);
328 tcg_gen_sub_tl(t
, d
, b
);
329 tcg_gen_movcond_tl(TCG_COND_GEU
, d
, d
, b
, t
, d
);
333 static void t_gen_cris_mstep(TCGv d
, TCGv a
, TCGv b
, TCGv ccs
)
343 tcg_gen_shli_tl(d
, a
, 1);
344 tcg_gen_shli_tl(t
, ccs
, 31 - 3);
345 tcg_gen_sari_tl(t
, t
, 31);
346 tcg_gen_and_tl(t
, t
, b
);
347 tcg_gen_add_tl(d
, d
, t
);
351 /* Extended arithmetics on CRIS. */
352 static inline void t_gen_add_flag(TCGv d
, int flag
)
357 t_gen_mov_TN_preg(c
, PR_CCS
);
358 /* Propagate carry into d. */
359 tcg_gen_andi_tl(c
, c
, 1 << flag
);
361 tcg_gen_shri_tl(c
, c
, flag
);
363 tcg_gen_add_tl(d
, d
, c
);
367 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
369 if (dc
->flagx_known
) {
374 t_gen_mov_TN_preg(c
, PR_CCS
);
375 /* C flag is already at bit 0. */
376 tcg_gen_andi_tl(c
, c
, C_FLAG
);
377 tcg_gen_add_tl(d
, d
, c
);
385 t_gen_mov_TN_preg(x
, PR_CCS
);
386 tcg_gen_mov_tl(c
, x
);
388 /* Propagate carry into d if X is set. Branch free. */
389 tcg_gen_andi_tl(c
, c
, C_FLAG
);
390 tcg_gen_andi_tl(x
, x
, X_FLAG
);
391 tcg_gen_shri_tl(x
, x
, 4);
393 tcg_gen_and_tl(x
, x
, c
);
394 tcg_gen_add_tl(d
, d
, x
);
400 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
402 if (dc
->flagx_known
) {
407 t_gen_mov_TN_preg(c
, PR_CCS
);
408 /* C flag is already at bit 0. */
409 tcg_gen_andi_tl(c
, c
, C_FLAG
);
410 tcg_gen_sub_tl(d
, d
, c
);
418 t_gen_mov_TN_preg(x
, PR_CCS
);
419 tcg_gen_mov_tl(c
, x
);
421 /* Propagate carry into d if X is set. Branch free. */
422 tcg_gen_andi_tl(c
, c
, C_FLAG
);
423 tcg_gen_andi_tl(x
, x
, X_FLAG
);
424 tcg_gen_shri_tl(x
, x
, 4);
426 tcg_gen_and_tl(x
, x
, c
);
427 tcg_gen_sub_tl(d
, d
, x
);
433 /* Swap the two bytes within each half word of the s operand.
434 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
435 static inline void t_gen_swapb(TCGv d
, TCGv s
)
440 org_s
= tcg_temp_new();
442 /* d and s may refer to the same object. */
443 tcg_gen_mov_tl(org_s
, s
);
444 tcg_gen_shli_tl(t
, org_s
, 8);
445 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
446 tcg_gen_shri_tl(t
, org_s
, 8);
447 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
448 tcg_gen_or_tl(d
, d
, t
);
450 tcg_temp_free(org_s
);
453 /* Swap the halfwords of the s operand. */
454 static inline void t_gen_swapw(TCGv d
, TCGv s
)
457 /* d and s refer the same object. */
459 tcg_gen_mov_tl(t
, s
);
460 tcg_gen_shli_tl(d
, t
, 16);
461 tcg_gen_shri_tl(t
, t
, 16);
462 tcg_gen_or_tl(d
, d
, t
);
466 /* Reverse the within each byte.
467 T0 = (((T0 << 7) & 0x80808080) |
468 ((T0 << 5) & 0x40404040) |
469 ((T0 << 3) & 0x20202020) |
470 ((T0 << 1) & 0x10101010) |
471 ((T0 >> 1) & 0x08080808) |
472 ((T0 >> 3) & 0x04040404) |
473 ((T0 >> 5) & 0x02020202) |
474 ((T0 >> 7) & 0x01010101));
476 static inline void t_gen_swapr(TCGv d
, TCGv s
)
479 int shift
; /* LSL when positive, LSR when negative. */
494 /* d and s refer the same object. */
496 org_s
= tcg_temp_new();
497 tcg_gen_mov_tl(org_s
, s
);
499 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
500 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
501 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
502 if (bitrev
[i
].shift
>= 0) {
503 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
505 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
507 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
508 tcg_gen_or_tl(d
, d
, t
);
511 tcg_temp_free(org_s
);
514 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
516 TCGLabel
*l1
= gen_new_label();
518 /* Conditional jmp. */
519 tcg_gen_mov_tl(env_pc
, pc_false
);
520 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
521 tcg_gen_mov_tl(env_pc
, pc_true
);
525 static inline bool use_goto_tb(DisasContext
*dc
, target_ulong dest
)
527 #ifndef CONFIG_USER_ONLY
528 return (dc
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) ||
529 (dc
->ppc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
535 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
537 if (use_goto_tb(dc
, dest
)) {
539 tcg_gen_movi_tl(env_pc
, dest
);
540 tcg_gen_exit_tb(dc
->tb
, n
);
542 tcg_gen_movi_tl(env_pc
, dest
);
543 tcg_gen_exit_tb(NULL
, 0);
547 static inline void cris_clear_x_flag(DisasContext
*dc
)
549 if (dc
->flagx_known
&& dc
->flags_x
) {
550 dc
->flags_uptodate
= 0;
557 static void cris_flush_cc_state(DisasContext
*dc
)
559 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
560 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
561 dc
->cc_size_uptodate
= dc
->cc_size
;
563 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
564 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
567 static void cris_evaluate_flags(DisasContext
*dc
)
569 if (dc
->flags_uptodate
) {
573 cris_flush_cc_state(dc
);
577 gen_helper_evaluate_flags_mcp(cpu_PR
[PR_CCS
], cpu_env
,
578 cpu_PR
[PR_CCS
], cc_src
,
582 gen_helper_evaluate_flags_muls(cpu_PR
[PR_CCS
], cpu_env
,
583 cpu_PR
[PR_CCS
], cc_result
,
587 gen_helper_evaluate_flags_mulu(cpu_PR
[PR_CCS
], cpu_env
,
588 cpu_PR
[PR_CCS
], cc_result
,
598 switch (dc
->cc_size
) {
600 gen_helper_evaluate_flags_move_4(cpu_PR
[PR_CCS
],
601 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
604 gen_helper_evaluate_flags_move_2(cpu_PR
[PR_CCS
],
605 cpu_env
, cpu_PR
[PR_CCS
], cc_result
);
608 gen_helper_evaluate_flags(cpu_env
);
617 if (dc
->cc_size
== 4) {
618 gen_helper_evaluate_flags_sub_4(cpu_PR
[PR_CCS
], cpu_env
,
619 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
621 gen_helper_evaluate_flags(cpu_env
);
626 switch (dc
->cc_size
) {
628 gen_helper_evaluate_flags_alu_4(cpu_PR
[PR_CCS
], cpu_env
,
629 cpu_PR
[PR_CCS
], cc_src
, cc_dest
, cc_result
);
632 gen_helper_evaluate_flags(cpu_env
);
638 if (dc
->flagx_known
) {
640 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], X_FLAG
);
641 } else if (dc
->cc_op
== CC_OP_FLAGS
) {
642 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
645 dc
->flags_uptodate
= 1;
648 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
657 /* Check if we need to evaluate the condition codes due to
659 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
661 /* TODO: optimize this case. It trigs all the time. */
662 cris_evaluate_flags(dc
);
668 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
672 dc
->flags_uptodate
= 0;
675 static inline void cris_update_cc_x(DisasContext
*dc
)
677 /* Save the x flag state at the time of the cc snapshot. */
678 if (dc
->flagx_known
) {
679 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
)) {
682 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
683 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
685 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
686 dc
->cc_x_uptodate
= 1;
690 /* Update cc prior to executing ALU op. Needs source operands untouched. */
691 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
692 TCGv dst
, TCGv src
, int size
)
695 cris_update_cc_op(dc
, op
, size
);
696 tcg_gen_mov_tl(cc_src
, src
);
704 && op
!= CC_OP_LSL
) {
705 tcg_gen_mov_tl(cc_dest
, dst
);
708 cris_update_cc_x(dc
);
712 /* Update cc after executing ALU op. needs the result. */
713 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
716 tcg_gen_mov_tl(cc_result
, res
);
720 /* Returns one if the write back stage should execute. */
721 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
722 TCGv dst
, TCGv a
, TCGv b
, int size
)
724 /* Emit the ALU insns. */
727 tcg_gen_add_tl(dst
, a
, b
);
728 /* Extended arithmetics. */
729 t_gen_addx_carry(dc
, dst
);
732 tcg_gen_add_tl(dst
, a
, b
);
733 t_gen_add_flag(dst
, 0); /* C_FLAG. */
736 tcg_gen_add_tl(dst
, a
, b
);
737 t_gen_add_flag(dst
, 8); /* R_FLAG. */
740 tcg_gen_sub_tl(dst
, a
, b
);
741 /* Extended arithmetics. */
742 t_gen_subx_carry(dc
, dst
);
745 tcg_gen_mov_tl(dst
, b
);
748 tcg_gen_or_tl(dst
, a
, b
);
751 tcg_gen_and_tl(dst
, a
, b
);
754 tcg_gen_xor_tl(dst
, a
, b
);
757 t_gen_lsl(dst
, a
, b
);
760 t_gen_lsr(dst
, a
, b
);
763 t_gen_asr(dst
, a
, b
);
766 tcg_gen_neg_tl(dst
, b
);
767 /* Extended arithmetics. */
768 t_gen_subx_carry(dc
, dst
);
771 tcg_gen_clzi_tl(dst
, b
, TARGET_LONG_BITS
);
774 tcg_gen_muls2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
777 tcg_gen_mulu2_tl(dst
, cpu_PR
[PR_MOF
], a
, b
);
780 t_gen_cris_dstep(dst
, a
, b
);
783 t_gen_cris_mstep(dst
, a
, b
, cpu_PR
[PR_CCS
]);
786 tcg_gen_movcond_tl(TCG_COND_LEU
, dst
, a
, b
, a
, b
);
789 tcg_gen_sub_tl(dst
, a
, b
);
790 /* Extended arithmetics. */
791 t_gen_subx_carry(dc
, dst
);
794 qemu_log_mask(LOG_GUEST_ERROR
, "illegal ALU op.\n");
800 tcg_gen_andi_tl(dst
, dst
, 0xff);
801 } else if (size
== 2) {
802 tcg_gen_andi_tl(dst
, dst
, 0xffff);
806 static void cris_alu(DisasContext
*dc
, int op
,
807 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
814 if (op
== CC_OP_CMP
) {
815 tmp
= tcg_temp_new();
817 } else if (size
== 4) {
821 tmp
= tcg_temp_new();
825 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
826 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
827 cris_update_result(dc
, tmp
);
832 tcg_gen_andi_tl(d
, d
, ~0xff);
834 tcg_gen_andi_tl(d
, d
, ~0xffff);
836 tcg_gen_or_tl(d
, d
, tmp
);
843 static int arith_cc(DisasContext
*dc
)
847 case CC_OP_ADDC
: return 1;
848 case CC_OP_ADD
: return 1;
849 case CC_OP_SUB
: return 1;
850 case CC_OP_DSTEP
: return 1;
851 case CC_OP_LSL
: return 1;
852 case CC_OP_LSR
: return 1;
853 case CC_OP_ASR
: return 1;
854 case CC_OP_CMP
: return 1;
855 case CC_OP_NEG
: return 1;
856 case CC_OP_OR
: return 1;
857 case CC_OP_AND
: return 1;
858 case CC_OP_XOR
: return 1;
859 case CC_OP_MULU
: return 1;
860 case CC_OP_MULS
: return 1;
868 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
870 int arith_opt
, move_opt
;
872 /* TODO: optimize more condition codes. */
875 * If the flags are live, we've gotta look into the bits of CCS.
876 * Otherwise, if we just did an arithmetic operation we try to
877 * evaluate the condition code faster.
879 * When this function is done, T0 should be non-zero if the condition
882 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
883 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
886 if ((arith_opt
|| move_opt
)
887 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
888 tcg_gen_setcond_tl(TCG_COND_EQ
, cc
,
889 cc_result
, tcg_const_tl(0));
891 cris_evaluate_flags(dc
);
893 cpu_PR
[PR_CCS
], Z_FLAG
);
897 if ((arith_opt
|| move_opt
)
898 && dc
->cc_x_uptodate
!= (2 | X_FLAG
)) {
899 tcg_gen_mov_tl(cc
, cc_result
);
901 cris_evaluate_flags(dc
);
902 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
904 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
908 cris_evaluate_flags(dc
);
909 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
912 cris_evaluate_flags(dc
);
913 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
914 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
917 cris_evaluate_flags(dc
);
918 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
921 cris_evaluate_flags(dc
);
922 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
924 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
927 if (arith_opt
|| move_opt
) {
930 if (dc
->cc_size
== 1) {
932 } else if (dc
->cc_size
== 2) {
936 tcg_gen_shri_tl(cc
, cc_result
, bits
);
937 tcg_gen_xori_tl(cc
, cc
, 1);
939 cris_evaluate_flags(dc
);
940 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
942 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
946 if (arith_opt
|| move_opt
) {
949 if (dc
->cc_size
== 1) {
951 } else if (dc
->cc_size
== 2) {
955 tcg_gen_shri_tl(cc
, cc_result
, bits
);
956 tcg_gen_andi_tl(cc
, cc
, 1);
958 cris_evaluate_flags(dc
);
959 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
964 cris_evaluate_flags(dc
);
965 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
969 cris_evaluate_flags(dc
);
973 tmp
= tcg_temp_new();
974 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
976 /* Overlay the C flag on top of the Z. */
977 tcg_gen_shli_tl(cc
, tmp
, 2);
978 tcg_gen_and_tl(cc
, tmp
, cc
);
979 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
985 cris_evaluate_flags(dc
);
986 /* Overlay the V flag on top of the N. */
987 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
990 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
991 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
994 cris_evaluate_flags(dc
);
995 /* Overlay the V flag on top of the N. */
996 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
999 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1002 cris_evaluate_flags(dc
);
1009 /* To avoid a shift we overlay everything on
1011 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1012 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1014 tcg_gen_xori_tl(z
, z
, 2);
1016 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1017 tcg_gen_xori_tl(n
, n
, 2);
1018 tcg_gen_and_tl(cc
, z
, n
);
1019 tcg_gen_andi_tl(cc
, cc
, 2);
1026 cris_evaluate_flags(dc
);
1033 /* To avoid a shift we overlay everything on
1035 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1036 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1038 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1039 tcg_gen_or_tl(cc
, z
, n
);
1040 tcg_gen_andi_tl(cc
, cc
, 2);
1047 cris_evaluate_flags(dc
);
1048 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1051 tcg_gen_movi_tl(cc
, 1);
1059 static void cris_store_direct_jmp(DisasContext
*dc
)
1061 /* Store the direct jmp state into the cpu-state. */
1062 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1063 if (dc
->jmp
== JMP_DIRECT
) {
1064 tcg_gen_movi_tl(env_btaken
, 1);
1066 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1067 dc
->jmp
= JMP_INDIRECT
;
1071 static void cris_prepare_cc_branch (DisasContext
*dc
,
1072 int offset
, int cond
)
1074 /* This helps us re-schedule the micro-code to insns in delay-slots
1075 before the actual jump. */
1076 dc
->delayed_branch
= 2;
1077 dc
->jmp
= JMP_DIRECT_CC
;
1078 dc
->jmp_pc
= dc
->pc
+ offset
;
1080 gen_tst_cc(dc
, env_btaken
, cond
);
1081 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1085 /* jumps, when the dest is in a live reg for example. Direct should be set
1086 when the dest addr is constant to allow tb chaining. */
1087 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1089 /* This helps us re-schedule the micro-code to insns in delay-slots
1090 before the actual jump. */
1091 dc
->delayed_branch
= 2;
1093 if (type
== JMP_INDIRECT
) {
1094 tcg_gen_movi_tl(env_btaken
, 1);
1098 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1100 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1102 /* If we get a fault on a delayslot we must keep the jmp state in
1103 the cpu-state to be able to re-execute the jmp. */
1104 if (dc
->delayed_branch
== 1) {
1105 cris_store_direct_jmp(dc
);
1108 tcg_gen_qemu_ld_i64(dst
, addr
, mem_index
, MO_TEQ
);
1111 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1112 unsigned int size
, int sign
)
1114 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1116 /* If we get a fault on a delayslot we must keep the jmp state in
1117 the cpu-state to be able to re-execute the jmp. */
1118 if (dc
->delayed_branch
== 1) {
1119 cris_store_direct_jmp(dc
);
1122 tcg_gen_qemu_ld_tl(dst
, addr
, mem_index
,
1123 MO_TE
+ ctz32(size
) + (sign
? MO_SIGN
: 0));
1126 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1129 int mem_index
= cpu_mmu_index(&dc
->cpu
->env
, false);
1131 /* If we get a fault on a delayslot we must keep the jmp state in
1132 the cpu-state to be able to re-execute the jmp. */
1133 if (dc
->delayed_branch
== 1) {
1134 cris_store_direct_jmp(dc
);
1138 /* Conditional writes. We only support the kind were X and P are known
1139 at translation time. */
1140 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1142 cris_evaluate_flags(dc
);
1143 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1147 tcg_gen_qemu_st_tl(val
, addr
, mem_index
, MO_TE
+ ctz32(size
));
1149 if (dc
->flagx_known
&& dc
->flags_x
) {
1150 cris_evaluate_flags(dc
);
1151 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1155 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1158 tcg_gen_ext8s_i32(d
, s
);
1159 } else if (size
== 2) {
1160 tcg_gen_ext16s_i32(d
, s
);
1162 tcg_gen_mov_tl(d
, s
);
1166 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1169 tcg_gen_ext8u_i32(d
, s
);
1170 } else if (size
== 2) {
1171 tcg_gen_ext16u_i32(d
, s
);
1173 tcg_gen_mov_tl(d
, s
);
1178 static char memsize_char(int size
)
1181 case 1: return 'b'; break;
1182 case 2: return 'w'; break;
1183 case 4: return 'd'; break;
1191 static inline unsigned int memsize_z(DisasContext
*dc
)
1193 return dc
->zsize
+ 1;
1196 static inline unsigned int memsize_zz(DisasContext
*dc
)
1198 switch (dc
->zzsize
) {
1206 static inline void do_postinc (DisasContext
*dc
, int size
)
1209 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1213 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1214 int size
, int s_ext
, TCGv dst
)
1217 t_gen_sext(dst
, cpu_R
[rs
], size
);
1219 t_gen_zext(dst
, cpu_R
[rs
], size
);
1223 /* Prepare T0 and T1 for a register alu operation.
1224 s_ext decides if the operand1 should be sign-extended or zero-extended when
1226 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1227 int size
, int s_ext
, TCGv dst
, TCGv src
)
1229 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1232 t_gen_sext(dst
, cpu_R
[rd
], size
);
1234 t_gen_zext(dst
, cpu_R
[rd
], size
);
1238 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1239 int s_ext
, int memsize
, TCGv dst
)
1247 is_imm
= rs
== 15 && dc
->postinc
;
1249 /* Load [$rs] onto T1. */
1251 insn_len
= 2 + memsize
;
1256 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1257 tcg_gen_movi_tl(dst
, imm
);
1260 cris_flush_cc_state(dc
);
1261 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1263 t_gen_sext(dst
, dst
, memsize
);
1265 t_gen_zext(dst
, dst
, memsize
);
1271 /* Prepare T0 and T1 for a memory + alu operation.
1272 s_ext decides if the operand1 should be sign-extended or zero-extended when
1274 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1275 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1279 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1280 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1285 static const char *cc_name(int cc
)
1287 static const char *cc_names
[16] = {
1288 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1289 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1292 return cc_names
[cc
];
1296 /* Start of insn decoders. */
1298 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1302 uint32_t cond
= dc
->op2
;
1304 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1305 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1308 offset
|= sign
<< 8;
1309 offset
= sign_extend(offset
, 8);
1311 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1313 /* op2 holds the condition-code. */
1314 cris_cc_mask(dc
, 0);
1315 cris_prepare_cc_branch(dc
, offset
, cond
);
1318 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1322 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1323 imm
= sign_extend(dc
->op1
, 7);
1325 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1326 cris_cc_mask(dc
, 0);
1327 /* Fetch register operand, */
1328 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1332 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1334 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1336 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1338 cris_cc_mask(dc
, CC_MASK_NZVC
);
1340 cris_alu(dc
, CC_OP_ADD
,
1341 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1344 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1348 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1349 imm
= sign_extend(dc
->op1
, 5);
1350 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1352 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1355 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1357 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1359 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1361 cris_cc_mask(dc
, CC_MASK_NZVC
);
1362 cris_alu(dc
, CC_OP_SUB
,
1363 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1366 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1369 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1370 imm
= sign_extend(dc
->op1
, 5);
1372 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1373 cris_cc_mask(dc
, CC_MASK_NZVC
);
1375 cris_alu(dc
, CC_OP_CMP
,
1376 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1379 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1382 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1383 imm
= sign_extend(dc
->op1
, 5);
1385 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1386 cris_cc_mask(dc
, CC_MASK_NZ
);
1388 cris_alu(dc
, CC_OP_AND
,
1389 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1392 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1395 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1396 imm
= sign_extend(dc
->op1
, 5);
1397 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1398 cris_cc_mask(dc
, CC_MASK_NZ
);
1400 cris_alu(dc
, CC_OP_OR
,
1401 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1404 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1406 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1407 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1409 cris_cc_mask(dc
, CC_MASK_NZ
);
1410 cris_evaluate_flags(dc
);
1411 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1412 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1413 cris_alu(dc
, CC_OP_MOVE
,
1414 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1415 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1416 dc
->flags_uptodate
= 1;
1419 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1421 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1422 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1423 cris_cc_mask(dc
, CC_MASK_NZ
);
1425 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1426 cris_alu(dc
, CC_OP_MOVE
,
1428 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1431 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1433 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1434 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1436 cris_cc_mask(dc
, CC_MASK_NZ
);
1438 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1440 cris_alu(dc
, CC_OP_MOVE
,
1442 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1445 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1447 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1448 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1450 cris_cc_mask(dc
, CC_MASK_NZ
);
1452 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1453 cris_alu(dc
, CC_OP_MOVE
,
1455 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1459 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1461 int size
= memsize_zz(dc
);
1463 LOG_DIS("move.%c $r%u, $r%u\n",
1464 memsize_char(size
), dc
->op1
, dc
->op2
);
1466 cris_cc_mask(dc
, CC_MASK_NZ
);
1468 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1469 cris_cc_mask(dc
, CC_MASK_NZ
);
1470 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1471 cris_update_cc_x(dc
);
1472 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1476 t0
= tcg_temp_new();
1477 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1478 cris_alu(dc
, CC_OP_MOVE
,
1480 cpu_R
[dc
->op2
], t0
, size
);
1486 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1490 LOG_DIS("s%s $r%u\n",
1491 cc_name(cond
), dc
->op1
);
1493 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1494 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], 0);
1496 cris_cc_mask(dc
, 0);
1500 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1503 t
[0] = cpu_R
[dc
->op2
];
1504 t
[1] = cpu_R
[dc
->op1
];
1506 t
[0] = tcg_temp_new();
1507 t
[1] = tcg_temp_new();
1511 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1514 tcg_temp_free(t
[0]);
1515 tcg_temp_free(t
[1]);
1519 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1522 int size
= memsize_zz(dc
);
1524 LOG_DIS("and.%c $r%u, $r%u\n",
1525 memsize_char(size
), dc
->op1
, dc
->op2
);
1527 cris_cc_mask(dc
, CC_MASK_NZ
);
1529 cris_alu_alloc_temps(dc
, size
, t
);
1530 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1531 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1532 cris_alu_free_temps(dc
, size
, t
);
1536 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1539 LOG_DIS("lz $r%u, $r%u\n",
1541 cris_cc_mask(dc
, CC_MASK_NZ
);
1542 t0
= tcg_temp_new();
1543 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1544 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1549 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1552 int size
= memsize_zz(dc
);
1554 LOG_DIS("lsl.%c $r%u, $r%u\n",
1555 memsize_char(size
), dc
->op1
, dc
->op2
);
1557 cris_cc_mask(dc
, CC_MASK_NZ
);
1558 cris_alu_alloc_temps(dc
, size
, t
);
1559 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1560 tcg_gen_andi_tl(t
[1], t
[1], 63);
1561 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1562 cris_alu_alloc_temps(dc
, size
, t
);
1566 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1569 int size
= memsize_zz(dc
);
1571 LOG_DIS("lsr.%c $r%u, $r%u\n",
1572 memsize_char(size
), dc
->op1
, dc
->op2
);
1574 cris_cc_mask(dc
, CC_MASK_NZ
);
1575 cris_alu_alloc_temps(dc
, size
, t
);
1576 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1577 tcg_gen_andi_tl(t
[1], t
[1], 63);
1578 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1579 cris_alu_free_temps(dc
, size
, t
);
1583 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1586 int size
= memsize_zz(dc
);
1588 LOG_DIS("asr.%c $r%u, $r%u\n",
1589 memsize_char(size
), dc
->op1
, dc
->op2
);
1591 cris_cc_mask(dc
, CC_MASK_NZ
);
1592 cris_alu_alloc_temps(dc
, size
, t
);
1593 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1594 tcg_gen_andi_tl(t
[1], t
[1], 63);
1595 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1596 cris_alu_free_temps(dc
, size
, t
);
1600 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1603 int size
= memsize_zz(dc
);
1605 LOG_DIS("muls.%c $r%u, $r%u\n",
1606 memsize_char(size
), dc
->op1
, dc
->op2
);
1607 cris_cc_mask(dc
, CC_MASK_NZV
);
1608 cris_alu_alloc_temps(dc
, size
, t
);
1609 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1611 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1612 cris_alu_free_temps(dc
, size
, t
);
1616 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1619 int size
= memsize_zz(dc
);
1621 LOG_DIS("mulu.%c $r%u, $r%u\n",
1622 memsize_char(size
), dc
->op1
, dc
->op2
);
1623 cris_cc_mask(dc
, CC_MASK_NZV
);
1624 cris_alu_alloc_temps(dc
, size
, t
);
1625 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1627 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1628 cris_alu_alloc_temps(dc
, size
, t
);
1633 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1635 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1636 cris_cc_mask(dc
, CC_MASK_NZ
);
1637 cris_alu(dc
, CC_OP_DSTEP
,
1638 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1642 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1645 int size
= memsize_zz(dc
);
1646 LOG_DIS("xor.%c $r%u, $r%u\n",
1647 memsize_char(size
), dc
->op1
, dc
->op2
);
1648 BUG_ON(size
!= 4); /* xor is dword. */
1649 cris_cc_mask(dc
, CC_MASK_NZ
);
1650 cris_alu_alloc_temps(dc
, size
, t
);
1651 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1653 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1654 cris_alu_free_temps(dc
, size
, t
);
1658 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1661 int size
= memsize_zz(dc
);
1662 LOG_DIS("bound.%c $r%u, $r%u\n",
1663 memsize_char(size
), dc
->op1
, dc
->op2
);
1664 cris_cc_mask(dc
, CC_MASK_NZ
);
1665 l0
= tcg_temp_local_new();
1666 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1667 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1672 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1675 int size
= memsize_zz(dc
);
1676 LOG_DIS("cmp.%c $r%u, $r%u\n",
1677 memsize_char(size
), dc
->op1
, dc
->op2
);
1678 cris_cc_mask(dc
, CC_MASK_NZVC
);
1679 cris_alu_alloc_temps(dc
, size
, t
);
1680 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1682 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1683 cris_alu_free_temps(dc
, size
, t
);
1687 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1689 LOG_DIS("abs $r%u, $r%u\n",
1691 cris_cc_mask(dc
, CC_MASK_NZ
);
1693 tcg_gen_abs_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
]);
1694 cris_alu(dc
, CC_OP_MOVE
,
1695 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1699 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1702 int size
= memsize_zz(dc
);
1703 LOG_DIS("add.%c $r%u, $r%u\n",
1704 memsize_char(size
), dc
->op1
, dc
->op2
);
1705 cris_cc_mask(dc
, CC_MASK_NZVC
);
1706 cris_alu_alloc_temps(dc
, size
, t
);
1707 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1709 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1710 cris_alu_free_temps(dc
, size
, t
);
1714 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1716 LOG_DIS("addc $r%u, $r%u\n",
1718 cris_evaluate_flags(dc
);
1719 /* Set for this insn. */
1720 dc
->flagx_known
= 1;
1721 dc
->flags_x
= X_FLAG
;
1723 cris_cc_mask(dc
, CC_MASK_NZVC
);
1724 cris_alu(dc
, CC_OP_ADDC
,
1725 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1729 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1731 LOG_DIS("mcp $p%u, $r%u\n",
1733 cris_evaluate_flags(dc
);
1734 cris_cc_mask(dc
, CC_MASK_RNZV
);
1735 cris_alu(dc
, CC_OP_MCP
,
1736 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1741 static char * swapmode_name(int mode
, char *modename
) {
1744 modename
[i
++] = 'n';
1747 modename
[i
++] = 'w';
1750 modename
[i
++] = 'b';
1753 modename
[i
++] = 'r';
1760 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1766 LOG_DIS("swap%s $r%u\n",
1767 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1769 cris_cc_mask(dc
, CC_MASK_NZ
);
1770 t0
= tcg_temp_new();
1771 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1773 tcg_gen_not_tl(t0
, t0
);
1776 t_gen_swapw(t0
, t0
);
1779 t_gen_swapb(t0
, t0
);
1782 t_gen_swapr(t0
, t0
);
1784 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1789 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1792 int size
= memsize_zz(dc
);
1793 LOG_DIS("or.%c $r%u, $r%u\n",
1794 memsize_char(size
), dc
->op1
, dc
->op2
);
1795 cris_cc_mask(dc
, CC_MASK_NZ
);
1796 cris_alu_alloc_temps(dc
, size
, t
);
1797 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1798 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1799 cris_alu_free_temps(dc
, size
, t
);
1803 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1806 LOG_DIS("addi.%c $r%u, $r%u\n",
1807 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1808 cris_cc_mask(dc
, 0);
1809 t0
= tcg_temp_new();
1810 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1811 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1816 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1819 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1820 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1821 cris_cc_mask(dc
, 0);
1822 t0
= tcg_temp_new();
1823 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1824 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1829 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1832 int size
= memsize_zz(dc
);
1833 LOG_DIS("neg.%c $r%u, $r%u\n",
1834 memsize_char(size
), dc
->op1
, dc
->op2
);
1835 cris_cc_mask(dc
, CC_MASK_NZVC
);
1836 cris_alu_alloc_temps(dc
, size
, t
);
1837 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1839 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1840 cris_alu_free_temps(dc
, size
, t
);
1844 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1846 LOG_DIS("btst $r%u, $r%u\n",
1848 cris_cc_mask(dc
, CC_MASK_NZ
);
1849 cris_evaluate_flags(dc
);
1850 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1851 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1852 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1853 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1854 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1855 dc
->flags_uptodate
= 1;
1859 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1862 int size
= memsize_zz(dc
);
1863 LOG_DIS("sub.%c $r%u, $r%u\n",
1864 memsize_char(size
), dc
->op1
, dc
->op2
);
1865 cris_cc_mask(dc
, CC_MASK_NZVC
);
1866 cris_alu_alloc_temps(dc
, size
, t
);
1867 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1868 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1869 cris_alu_free_temps(dc
, size
, t
);
1873 /* Zero extension. From size to dword. */
1874 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1877 int size
= memsize_z(dc
);
1878 LOG_DIS("movu.%c $r%u, $r%u\n",
1882 cris_cc_mask(dc
, CC_MASK_NZ
);
1883 t0
= tcg_temp_new();
1884 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1885 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1890 /* Sign extension. From size to dword. */
1891 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1894 int size
= memsize_z(dc
);
1895 LOG_DIS("movs.%c $r%u, $r%u\n",
1899 cris_cc_mask(dc
, CC_MASK_NZ
);
1900 t0
= tcg_temp_new();
1901 /* Size can only be qi or hi. */
1902 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1903 cris_alu(dc
, CC_OP_MOVE
,
1904 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1909 /* zero extension. From size to dword. */
1910 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1913 int size
= memsize_z(dc
);
1914 LOG_DIS("addu.%c $r%u, $r%u\n",
1918 cris_cc_mask(dc
, CC_MASK_NZVC
);
1919 t0
= tcg_temp_new();
1920 /* Size can only be qi or hi. */
1921 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1922 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1927 /* Sign extension. From size to dword. */
1928 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1931 int size
= memsize_z(dc
);
1932 LOG_DIS("adds.%c $r%u, $r%u\n",
1936 cris_cc_mask(dc
, CC_MASK_NZVC
);
1937 t0
= tcg_temp_new();
1938 /* Size can only be qi or hi. */
1939 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1940 cris_alu(dc
, CC_OP_ADD
,
1941 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1946 /* Zero extension. From size to dword. */
1947 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1950 int size
= memsize_z(dc
);
1951 LOG_DIS("subu.%c $r%u, $r%u\n",
1955 cris_cc_mask(dc
, CC_MASK_NZVC
);
1956 t0
= tcg_temp_new();
1957 /* Size can only be qi or hi. */
1958 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1959 cris_alu(dc
, CC_OP_SUB
,
1960 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1965 /* Sign extension. From size to dword. */
1966 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1969 int size
= memsize_z(dc
);
1970 LOG_DIS("subs.%c $r%u, $r%u\n",
1974 cris_cc_mask(dc
, CC_MASK_NZVC
);
1975 t0
= tcg_temp_new();
1976 /* Size can only be qi or hi. */
1977 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1978 cris_alu(dc
, CC_OP_SUB
,
1979 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1984 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
1987 int set
= (~dc
->opcode
>> 2) & 1;
1990 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1991 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1992 if (set
&& flags
== 0) {
1995 } else if (!set
&& (flags
& 0x20)) {
1998 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2001 /* User space is not allowed to touch these. Silently ignore. */
2002 if (dc
->tb_flags
& U_FLAG
) {
2003 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2006 if (flags
& X_FLAG
) {
2007 dc
->flagx_known
= 1;
2009 dc
->flags_x
= X_FLAG
;
2015 /* Break the TB if any of the SPI flag changes. */
2016 if (flags
& (P_FLAG
| S_FLAG
)) {
2017 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2018 dc
->is_jmp
= DISAS_UPDATE
;
2019 dc
->cpustate_changed
= 1;
2022 /* For the I flag, only act on posedge. */
2023 if ((flags
& I_FLAG
)) {
2024 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2025 dc
->is_jmp
= DISAS_UPDATE
;
2026 dc
->cpustate_changed
= 1;
2030 /* Simply decode the flags. */
2031 cris_evaluate_flags(dc
);
2032 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2033 cris_update_cc_x(dc
);
2034 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2037 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2038 /* Enter user mode. */
2039 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2040 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2041 dc
->cpustate_changed
= 1;
2043 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2045 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2048 dc
->flags_uptodate
= 1;
2053 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2055 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2056 cris_cc_mask(dc
, 0);
2057 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2058 tcg_const_tl(dc
->op1
));
2061 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2063 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2064 cris_cc_mask(dc
, 0);
2065 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2066 tcg_const_tl(dc
->op2
));
2070 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2073 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2074 cris_cc_mask(dc
, 0);
2076 t
[0] = tcg_temp_new();
2077 if (dc
->op2
== PR_CCS
) {
2078 cris_evaluate_flags(dc
);
2079 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2080 if (dc
->tb_flags
& U_FLAG
) {
2081 t
[1] = tcg_temp_new();
2082 /* User space is not allowed to touch all flags. */
2083 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2084 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2085 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2086 tcg_temp_free(t
[1]);
2089 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2092 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2093 if (dc
->op2
== PR_CCS
) {
2094 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2095 dc
->flags_uptodate
= 1;
2097 tcg_temp_free(t
[0]);
2100 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2103 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2104 cris_cc_mask(dc
, 0);
2106 if (dc
->op2
== PR_CCS
) {
2107 cris_evaluate_flags(dc
);
2110 if (dc
->op2
== PR_DZ
) {
2111 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2113 t0
= tcg_temp_new();
2114 t_gen_mov_TN_preg(t0
, dc
->op2
);
2115 cris_alu(dc
, CC_OP_MOVE
,
2116 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2117 preg_sizes
[dc
->op2
]);
2123 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2125 int memsize
= memsize_zz(dc
);
2127 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2128 memsize_char(memsize
),
2129 dc
->op1
, dc
->postinc
? "+]" : "]",
2133 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2134 cris_cc_mask(dc
, CC_MASK_NZ
);
2135 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2136 cris_update_cc_x(dc
);
2137 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2141 t0
= tcg_temp_new();
2142 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2143 cris_cc_mask(dc
, CC_MASK_NZ
);
2144 cris_alu(dc
, CC_OP_MOVE
,
2145 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2148 do_postinc(dc
, memsize
);
2152 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2154 t
[0] = tcg_temp_new();
2155 t
[1] = tcg_temp_new();
2158 static inline void cris_alu_m_free_temps(TCGv
*t
)
2160 tcg_temp_free(t
[0]);
2161 tcg_temp_free(t
[1]);
2164 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2167 int memsize
= memsize_z(dc
);
2169 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2170 memsize_char(memsize
),
2171 dc
->op1
, dc
->postinc
? "+]" : "]",
2174 cris_alu_m_alloc_temps(t
);
2176 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2177 cris_cc_mask(dc
, CC_MASK_NZ
);
2178 cris_alu(dc
, CC_OP_MOVE
,
2179 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2180 do_postinc(dc
, memsize
);
2181 cris_alu_m_free_temps(t
);
2185 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2188 int memsize
= memsize_z(dc
);
2190 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2191 memsize_char(memsize
),
2192 dc
->op1
, dc
->postinc
? "+]" : "]",
2195 cris_alu_m_alloc_temps(t
);
2197 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2198 cris_cc_mask(dc
, CC_MASK_NZVC
);
2199 cris_alu(dc
, CC_OP_ADD
,
2200 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2201 do_postinc(dc
, memsize
);
2202 cris_alu_m_free_temps(t
);
2206 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2209 int memsize
= memsize_z(dc
);
2211 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2212 memsize_char(memsize
),
2213 dc
->op1
, dc
->postinc
? "+]" : "]",
2216 cris_alu_m_alloc_temps(t
);
2218 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2219 cris_cc_mask(dc
, CC_MASK_NZVC
);
2220 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2221 do_postinc(dc
, memsize
);
2222 cris_alu_m_free_temps(t
);
2226 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2229 int memsize
= memsize_z(dc
);
2231 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2232 memsize_char(memsize
),
2233 dc
->op1
, dc
->postinc
? "+]" : "]",
2236 cris_alu_m_alloc_temps(t
);
2238 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2239 cris_cc_mask(dc
, CC_MASK_NZVC
);
2240 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2241 do_postinc(dc
, memsize
);
2242 cris_alu_m_free_temps(t
);
2246 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2249 int memsize
= memsize_z(dc
);
2251 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2252 memsize_char(memsize
),
2253 dc
->op1
, dc
->postinc
? "+]" : "]",
2256 cris_alu_m_alloc_temps(t
);
2258 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2259 cris_cc_mask(dc
, CC_MASK_NZVC
);
2260 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2261 do_postinc(dc
, memsize
);
2262 cris_alu_m_free_temps(t
);
2266 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2269 int memsize
= memsize_z(dc
);
2272 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2273 memsize_char(memsize
),
2274 dc
->op1
, dc
->postinc
? "+]" : "]",
2277 cris_alu_m_alloc_temps(t
);
2278 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2279 cris_cc_mask(dc
, CC_MASK_NZ
);
2280 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2281 do_postinc(dc
, memsize
);
2282 cris_alu_m_free_temps(t
);
2286 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2289 int memsize
= memsize_z(dc
);
2291 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2292 memsize_char(memsize
),
2293 dc
->op1
, dc
->postinc
? "+]" : "]",
2296 cris_alu_m_alloc_temps(t
);
2297 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2298 cris_cc_mask(dc
, CC_MASK_NZVC
);
2299 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2300 do_postinc(dc
, memsize
);
2301 cris_alu_m_free_temps(t
);
2305 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2308 int memsize
= memsize_z(dc
);
2310 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2311 memsize_char(memsize
),
2312 dc
->op1
, dc
->postinc
? "+]" : "]",
2315 cris_alu_m_alloc_temps(t
);
2316 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2317 cris_cc_mask(dc
, CC_MASK_NZVC
);
2318 cris_alu(dc
, CC_OP_CMP
,
2319 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2321 do_postinc(dc
, memsize
);
2322 cris_alu_m_free_temps(t
);
2326 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2329 int memsize
= memsize_zz(dc
);
2331 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2332 memsize_char(memsize
),
2333 dc
->op1
, dc
->postinc
? "+]" : "]",
2336 cris_alu_m_alloc_temps(t
);
2337 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2338 cris_cc_mask(dc
, CC_MASK_NZVC
);
2339 cris_alu(dc
, CC_OP_CMP
,
2340 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2342 do_postinc(dc
, memsize
);
2343 cris_alu_m_free_temps(t
);
2347 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2350 int memsize
= memsize_zz(dc
);
2352 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2353 memsize_char(memsize
),
2354 dc
->op1
, dc
->postinc
? "+]" : "]",
2357 cris_evaluate_flags(dc
);
2359 cris_alu_m_alloc_temps(t
);
2360 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2361 cris_cc_mask(dc
, CC_MASK_NZ
);
2362 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2364 cris_alu(dc
, CC_OP_CMP
,
2365 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2366 do_postinc(dc
, memsize
);
2367 cris_alu_m_free_temps(t
);
2371 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2374 int memsize
= memsize_zz(dc
);
2376 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2377 memsize_char(memsize
),
2378 dc
->op1
, dc
->postinc
? "+]" : "]",
2381 cris_alu_m_alloc_temps(t
);
2382 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2383 cris_cc_mask(dc
, CC_MASK_NZ
);
2384 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2385 do_postinc(dc
, memsize
);
2386 cris_alu_m_free_temps(t
);
2390 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2393 int memsize
= memsize_zz(dc
);
2395 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2396 memsize_char(memsize
),
2397 dc
->op1
, dc
->postinc
? "+]" : "]",
2400 cris_alu_m_alloc_temps(t
);
2401 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2402 cris_cc_mask(dc
, CC_MASK_NZVC
);
2403 cris_alu(dc
, CC_OP_ADD
,
2404 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2405 do_postinc(dc
, memsize
);
2406 cris_alu_m_free_temps(t
);
2410 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2413 int memsize
= memsize_zz(dc
);
2415 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2416 memsize_char(memsize
),
2417 dc
->op1
, dc
->postinc
? "+]" : "]",
2420 cris_alu_m_alloc_temps(t
);
2421 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2422 cris_cc_mask(dc
, 0);
2423 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2424 do_postinc(dc
, memsize
);
2425 cris_alu_m_free_temps(t
);
2429 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2432 int memsize
= memsize_zz(dc
);
2434 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2435 memsize_char(memsize
),
2436 dc
->op1
, dc
->postinc
? "+]" : "]",
2439 l
[0] = tcg_temp_local_new();
2440 l
[1] = tcg_temp_local_new();
2441 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2442 cris_cc_mask(dc
, CC_MASK_NZ
);
2443 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2444 do_postinc(dc
, memsize
);
2445 tcg_temp_free(l
[0]);
2446 tcg_temp_free(l
[1]);
2450 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2454 LOG_DIS("addc [$r%u%s, $r%u\n",
2455 dc
->op1
, dc
->postinc
? "+]" : "]",
2458 cris_evaluate_flags(dc
);
2460 /* Set for this insn. */
2461 dc
->flagx_known
= 1;
2462 dc
->flags_x
= X_FLAG
;
2464 cris_alu_m_alloc_temps(t
);
2465 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2466 cris_cc_mask(dc
, CC_MASK_NZVC
);
2467 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2469 cris_alu_m_free_temps(t
);
2473 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2476 int memsize
= memsize_zz(dc
);
2478 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2479 memsize_char(memsize
),
2480 dc
->op1
, dc
->postinc
? "+]" : "]",
2481 dc
->op2
, dc
->ir
, dc
->zzsize
);
2483 cris_alu_m_alloc_temps(t
);
2484 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2485 cris_cc_mask(dc
, CC_MASK_NZVC
);
2486 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2487 do_postinc(dc
, memsize
);
2488 cris_alu_m_free_temps(t
);
2492 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2495 int memsize
= memsize_zz(dc
);
2497 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2498 memsize_char(memsize
),
2499 dc
->op1
, dc
->postinc
? "+]" : "]",
2502 cris_alu_m_alloc_temps(t
);
2503 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2504 cris_cc_mask(dc
, CC_MASK_NZ
);
2505 cris_alu(dc
, CC_OP_OR
,
2506 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2507 do_postinc(dc
, memsize
);
2508 cris_alu_m_free_temps(t
);
2512 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2515 int memsize
= memsize_zz(dc
);
2518 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2519 memsize_char(memsize
),
2521 dc
->postinc
? "+]" : "]",
2524 cris_alu_m_alloc_temps(t
);
2525 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2526 cris_cc_mask(dc
, 0);
2527 if (dc
->op2
== PR_CCS
) {
2528 cris_evaluate_flags(dc
);
2529 if (dc
->tb_flags
& U_FLAG
) {
2530 /* User space is not allowed to touch all flags. */
2531 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2532 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2533 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2537 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2539 do_postinc(dc
, memsize
);
2540 cris_alu_m_free_temps(t
);
2544 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2549 memsize
= preg_sizes
[dc
->op2
];
2551 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2552 memsize_char(memsize
),
2553 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2555 /* prepare store. Address in T0, value in T1. */
2556 if (dc
->op2
== PR_CCS
) {
2557 cris_evaluate_flags(dc
);
2559 t0
= tcg_temp_new();
2560 t_gen_mov_TN_preg(t0
, dc
->op2
);
2561 cris_flush_cc_state(dc
);
2562 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2565 cris_cc_mask(dc
, 0);
2567 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2572 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2578 int nr
= dc
->op2
+ 1;
2580 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2581 dc
->postinc
? "+]" : "]", dc
->op2
);
2583 addr
= tcg_temp_new();
2584 /* There are probably better ways of doing this. */
2585 cris_flush_cc_state(dc
);
2586 for (i
= 0; i
< (nr
>> 1); i
++) {
2587 tmp
[i
] = tcg_temp_new_i64();
2588 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2589 gen_load64(dc
, tmp
[i
], addr
);
2592 tmp32
= tcg_temp_new_i32();
2593 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2594 gen_load(dc
, tmp32
, addr
, 4, 0);
2598 tcg_temp_free(addr
);
2600 for (i
= 0; i
< (nr
>> 1); i
++) {
2601 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2602 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2603 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2604 tcg_temp_free_i64(tmp
[i
]);
2607 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2608 tcg_temp_free(tmp32
);
2611 /* writeback the updated pointer value. */
2613 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2616 /* gen_load might want to evaluate the previous insns flags. */
2617 cris_cc_mask(dc
, 0);
2621 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2627 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2628 dc
->postinc
? "+]" : "]");
2630 cris_flush_cc_state(dc
);
2632 tmp
= tcg_temp_new();
2633 addr
= tcg_temp_new();
2634 tcg_gen_movi_tl(tmp
, 4);
2635 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2636 for (i
= 0; i
<= dc
->op2
; i
++) {
2637 /* Displace addr. */
2638 /* Perform the store. */
2639 gen_store(dc
, addr
, cpu_R
[i
], 4);
2640 tcg_gen_add_tl(addr
, addr
, tmp
);
2643 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2645 cris_cc_mask(dc
, 0);
2647 tcg_temp_free(addr
);
2651 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2655 memsize
= memsize_zz(dc
);
2657 LOG_DIS("move.%c $r%u, [$r%u]\n",
2658 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2660 /* prepare store. */
2661 cris_flush_cc_state(dc
);
2662 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2665 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2667 cris_cc_mask(dc
, 0);
2671 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2673 LOG_DIS("lapcq %x, $r%u\n",
2674 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2675 cris_cc_mask(dc
, 0);
2676 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2680 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2688 cris_cc_mask(dc
, 0);
2689 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2690 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2694 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2698 /* Jump to special reg. */
2699 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2701 LOG_DIS("jump $p%u\n", dc
->op2
);
2703 if (dc
->op2
== PR_CCS
) {
2704 cris_evaluate_flags(dc
);
2706 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2707 /* rete will often have low bit set to indicate delayslot. */
2708 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2709 cris_cc_mask(dc
, 0);
2710 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2714 /* Jump and save. */
2715 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2717 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2718 cris_cc_mask(dc
, 0);
2719 /* Store the return address in Pd. */
2720 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2724 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2726 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2730 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2734 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2736 LOG_DIS("jas 0x%x\n", imm
);
2737 cris_cc_mask(dc
, 0);
2738 /* Store the return address in Pd. */
2739 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2742 cris_prepare_jmp(dc
, JMP_DIRECT
);
2746 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2750 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2752 LOG_DIS("jasc 0x%x\n", imm
);
2753 cris_cc_mask(dc
, 0);
2754 /* Store the return address in Pd. */
2755 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2758 cris_prepare_jmp(dc
, JMP_DIRECT
);
2762 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2764 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2765 cris_cc_mask(dc
, 0);
2766 /* Store the return address in Pd. */
2767 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 + 4));
2769 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2773 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2776 uint32_t cond
= dc
->op2
;
2778 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2780 LOG_DIS("b%s %d pc=%x dst=%x\n",
2781 cc_name(cond
), offset
,
2782 dc
->pc
, dc
->pc
+ offset
);
2784 cris_cc_mask(dc
, 0);
2785 /* op2 holds the condition-code. */
2786 cris_prepare_cc_branch(dc
, offset
, cond
);
2790 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2794 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2796 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
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));
2801 dc
->jmp_pc
= dc
->pc
+ simm
;
2802 cris_prepare_jmp(dc
, JMP_DIRECT
);
2806 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2809 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2811 LOG_DIS("basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2812 cris_cc_mask(dc
, 0);
2813 /* Store the return address in Pd. */
2814 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2816 dc
->jmp_pc
= dc
->pc
+ simm
;
2817 cris_prepare_jmp(dc
, JMP_DIRECT
);
2821 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2823 cris_cc_mask(dc
, 0);
2825 if (dc
->op2
== 15) {
2826 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2827 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2828 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2829 t_gen_raise_exception(EXCP_HLT
);
2833 switch (dc
->op2
& 7) {
2837 cris_evaluate_flags(dc
);
2838 gen_helper_rfe(cpu_env
);
2839 dc
->is_jmp
= DISAS_UPDATE
;
2844 cris_evaluate_flags(dc
);
2845 gen_helper_rfn(cpu_env
);
2846 dc
->is_jmp
= DISAS_UPDATE
;
2849 LOG_DIS("break %d\n", dc
->op1
);
2850 cris_evaluate_flags(dc
);
2852 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2854 /* Breaks start at 16 in the exception vector. */
2855 t_gen_mov_env_TN(trap_vector
,
2856 tcg_const_tl(dc
->op1
+ 16));
2857 t_gen_raise_exception(EXCP_BREAK
);
2858 dc
->is_jmp
= DISAS_UPDATE
;
2861 printf("op2=%x\n", dc
->op2
);
2869 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2874 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2879 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2881 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2882 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2888 static struct decoder_info
{
2893 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2895 /* Order matters here. */
2896 {DEC_MOVEQ
, dec_moveq
},
2897 {DEC_BTSTQ
, dec_btstq
},
2898 {DEC_CMPQ
, dec_cmpq
},
2899 {DEC_ADDOQ
, dec_addoq
},
2900 {DEC_ADDQ
, dec_addq
},
2901 {DEC_SUBQ
, dec_subq
},
2902 {DEC_ANDQ
, dec_andq
},
2904 {DEC_ASRQ
, dec_asrq
},
2905 {DEC_LSLQ
, dec_lslq
},
2906 {DEC_LSRQ
, dec_lsrq
},
2907 {DEC_BCCQ
, dec_bccq
},
2909 {DEC_BCC_IM
, dec_bcc_im
},
2910 {DEC_JAS_IM
, dec_jas_im
},
2911 {DEC_JAS_R
, dec_jas_r
},
2912 {DEC_JASC_IM
, dec_jasc_im
},
2913 {DEC_JASC_R
, dec_jasc_r
},
2914 {DEC_BAS_IM
, dec_bas_im
},
2915 {DEC_BASC_IM
, dec_basc_im
},
2916 {DEC_JUMP_P
, dec_jump_p
},
2917 {DEC_LAPC_IM
, dec_lapc_im
},
2918 {DEC_LAPCQ
, dec_lapcq
},
2920 {DEC_RFE_ETC
, dec_rfe_etc
},
2921 {DEC_ADDC_MR
, dec_addc_mr
},
2923 {DEC_MOVE_MP
, dec_move_mp
},
2924 {DEC_MOVE_PM
, dec_move_pm
},
2925 {DEC_MOVEM_MR
, dec_movem_mr
},
2926 {DEC_MOVEM_RM
, dec_movem_rm
},
2927 {DEC_MOVE_PR
, dec_move_pr
},
2928 {DEC_SCC_R
, dec_scc_r
},
2929 {DEC_SETF
, dec_setclrf
},
2930 {DEC_CLEARF
, dec_setclrf
},
2932 {DEC_MOVE_SR
, dec_move_sr
},
2933 {DEC_MOVE_RP
, dec_move_rp
},
2934 {DEC_SWAP_R
, dec_swap_r
},
2935 {DEC_ABS_R
, dec_abs_r
},
2936 {DEC_LZ_R
, dec_lz_r
},
2937 {DEC_MOVE_RS
, dec_move_rs
},
2938 {DEC_BTST_R
, dec_btst_r
},
2939 {DEC_ADDC_R
, dec_addc_r
},
2941 {DEC_DSTEP_R
, dec_dstep_r
},
2942 {DEC_XOR_R
, dec_xor_r
},
2943 {DEC_MCP_R
, dec_mcp_r
},
2944 {DEC_CMP_R
, dec_cmp_r
},
2946 {DEC_ADDI_R
, dec_addi_r
},
2947 {DEC_ADDI_ACR
, dec_addi_acr
},
2949 {DEC_ADD_R
, dec_add_r
},
2950 {DEC_SUB_R
, dec_sub_r
},
2952 {DEC_ADDU_R
, dec_addu_r
},
2953 {DEC_ADDS_R
, dec_adds_r
},
2954 {DEC_SUBU_R
, dec_subu_r
},
2955 {DEC_SUBS_R
, dec_subs_r
},
2956 {DEC_LSL_R
, dec_lsl_r
},
2958 {DEC_AND_R
, dec_and_r
},
2959 {DEC_OR_R
, dec_or_r
},
2960 {DEC_BOUND_R
, dec_bound_r
},
2961 {DEC_ASR_R
, dec_asr_r
},
2962 {DEC_LSR_R
, dec_lsr_r
},
2964 {DEC_MOVU_R
, dec_movu_r
},
2965 {DEC_MOVS_R
, dec_movs_r
},
2966 {DEC_NEG_R
, dec_neg_r
},
2967 {DEC_MOVE_R
, dec_move_r
},
2969 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2970 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2972 {DEC_MULS_R
, dec_muls_r
},
2973 {DEC_MULU_R
, dec_mulu_r
},
2975 {DEC_ADDU_M
, dec_addu_m
},
2976 {DEC_ADDS_M
, dec_adds_m
},
2977 {DEC_SUBU_M
, dec_subu_m
},
2978 {DEC_SUBS_M
, dec_subs_m
},
2980 {DEC_CMPU_M
, dec_cmpu_m
},
2981 {DEC_CMPS_M
, dec_cmps_m
},
2982 {DEC_MOVU_M
, dec_movu_m
},
2983 {DEC_MOVS_M
, dec_movs_m
},
2985 {DEC_CMP_M
, dec_cmp_m
},
2986 {DEC_ADDO_M
, dec_addo_m
},
2987 {DEC_BOUND_M
, dec_bound_m
},
2988 {DEC_ADD_M
, dec_add_m
},
2989 {DEC_SUB_M
, dec_sub_m
},
2990 {DEC_AND_M
, dec_and_m
},
2991 {DEC_OR_M
, dec_or_m
},
2992 {DEC_MOVE_RM
, dec_move_rm
},
2993 {DEC_TEST_M
, dec_test_m
},
2994 {DEC_MOVE_MR
, dec_move_mr
},
2999 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3004 /* Load a halfword onto the instruction register. */
3005 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3007 /* Now decode it. */
3008 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3009 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3010 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3011 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3012 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3013 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3015 /* Large switch for all insns. */
3016 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3017 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3018 insn_len
= decinfo
[i
].dec(env
, dc
);
3023 #if !defined(CONFIG_USER_ONLY)
3024 /* Single-stepping ? */
3025 if (dc
->tb_flags
& S_FLAG
) {
3026 TCGLabel
*l1
= gen_new_label();
3027 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3028 /* We treat SPC as a break with an odd trap vector. */
3029 cris_evaluate_flags(dc
);
3030 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3031 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3032 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3033 t_gen_raise_exception(EXCP_BREAK
);
3040 #include "translate_v10.inc.c"
3043 * Delay slots on QEMU/CRIS.
3045 * If an exception hits on a delayslot, the core will let ERP (the Exception
3046 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3047 * to give SW a hint that the exception actually hit on the dslot.
3049 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3050 * the core and any jmp to an odd addresses will mask off that lsb. It is
3051 * simply there to let sw know there was an exception on a dslot.
3053 * When the software returns from an exception, the branch will re-execute.
3054 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3055 * and the branch and delayslot don't share pages.
3057 * The TB contaning the branch insn will set up env->btarget and evaluate
3058 * env->btaken. When the translation loop exits we will note that the branch
3059 * sequence is broken and let env->dslot be the size of the branch insn (those
3062 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3063 * set). It will also expect to have env->dslot setup with the size of the
3064 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3065 * will execute the dslot and take the branch, either to btarget or just one
3068 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3069 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3070 * branch and set lsb). Then env->dslot gets cleared so that the exception
3071 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3072 * masked off and we will reexecute the branch insn.
3076 /* generate intermediate code for basic block 'tb'. */
3077 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
3079 CPUCRISState
*env
= cs
->env_ptr
;
3081 unsigned int insn_len
;
3082 struct DisasContext ctx
;
3083 struct DisasContext
*dc
= &ctx
;
3084 uint32_t page_start
;
3088 if (env
->pregs
[PR_VR
] == 32) {
3089 dc
->decoder
= crisv32_decoder
;
3090 dc
->clear_locked_irq
= 0;
3092 dc
->decoder
= crisv10_decoder
;
3093 dc
->clear_locked_irq
= 1;
3096 /* Odd PC indicates that branch is rexecuting due to exception in the
3097 * delayslot, like in real hw.
3099 pc_start
= tb
->pc
& ~1;
3100 dc
->cpu
= env_archcpu(env
);
3103 dc
->is_jmp
= DISAS_NEXT
;
3106 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3107 dc
->flags_uptodate
= 1;
3108 dc
->flagx_known
= 1;
3109 dc
->flags_x
= tb
->flags
& X_FLAG
;
3110 dc
->cc_x_uptodate
= 0;
3113 dc
->clear_prefix
= 0;
3115 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3116 dc
->cc_size_uptodate
= -1;
3118 /* Decode TB flags. */
3119 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3120 | X_FLAG
| PFIX_FLAG
);
3121 dc
->delayed_branch
= !!(tb
->flags
& 7);
3122 if (dc
->delayed_branch
) {
3123 dc
->jmp
= JMP_INDIRECT
;
3125 dc
->jmp
= JMP_NOJMP
;
3128 dc
->cpustate_changed
= 0;
3130 page_start
= pc_start
& TARGET_PAGE_MASK
;
3135 tcg_gen_insn_start(dc
->delayed_branch
== 1
3136 ? dc
->ppc
| 1 : dc
->pc
);
3139 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
3140 cris_evaluate_flags(dc
);
3141 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3142 t_gen_raise_exception(EXCP_DEBUG
);
3143 dc
->is_jmp
= DISAS_UPDATE
;
3144 /* The address covered by the breakpoint must be included in
3145 [tb->pc, tb->pc + tb->size) in order to for it to be
3146 properly cleared -- thus we increment the PC here so that
3147 the logic setting tb->size below does the right thing. */
3153 LOG_DIS("%8.8x:\t", dc
->pc
);
3155 if (num_insns
== max_insns
&& (tb_cflags(tb
) & CF_LAST_IO
)) {
3160 insn_len
= dc
->decoder(env
, dc
);
3164 cris_clear_x_flag(dc
);
3167 /* Check for delayed branches here. If we do it before
3168 actually generating any host code, the simulator will just
3169 loop doing nothing for on this program location. */
3170 if (dc
->delayed_branch
) {
3171 dc
->delayed_branch
--;
3172 if (dc
->delayed_branch
== 0) {
3173 if (tb
->flags
& 7) {
3174 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3176 if (dc
->cpustate_changed
|| !dc
->flagx_known
3177 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3178 cris_store_direct_jmp(dc
);
3181 if (dc
->clear_locked_irq
) {
3182 dc
->clear_locked_irq
= 0;
3183 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3186 if (dc
->jmp
== JMP_DIRECT_CC
) {
3187 TCGLabel
*l1
= gen_new_label();
3188 cris_evaluate_flags(dc
);
3190 /* Conditional jmp. */
3191 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3193 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3195 gen_goto_tb(dc
, 0, dc
->pc
);
3196 dc
->is_jmp
= DISAS_TB_JUMP
;
3197 dc
->jmp
= JMP_NOJMP
;
3198 } else if (dc
->jmp
== JMP_DIRECT
) {
3199 cris_evaluate_flags(dc
);
3200 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3201 dc
->is_jmp
= DISAS_TB_JUMP
;
3202 dc
->jmp
= JMP_NOJMP
;
3204 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3205 dc
->is_jmp
= DISAS_JUMP
;
3211 /* If we are rexecuting a branch due to exceptions on
3212 delay slots don't break. */
3213 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3216 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3217 && !tcg_op_buf_full()
3219 && (dc
->pc
- page_start
< TARGET_PAGE_SIZE
)
3220 && num_insns
< max_insns
);
3222 if (dc
->clear_locked_irq
) {
3223 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3228 /* Force an update if the per-tb cpu state has changed. */
3229 if (dc
->is_jmp
== DISAS_NEXT
3230 && (dc
->cpustate_changed
|| !dc
->flagx_known
3231 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3232 dc
->is_jmp
= DISAS_UPDATE
;
3233 tcg_gen_movi_tl(env_pc
, npc
);
3235 /* Broken branch+delayslot sequence. */
3236 if (dc
->delayed_branch
== 1) {
3237 /* Set env->dslot to the size of the branch insn. */
3238 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3239 cris_store_direct_jmp(dc
);
3242 cris_evaluate_flags(dc
);
3244 if (unlikely(cs
->singlestep_enabled
)) {
3245 if (dc
->is_jmp
== DISAS_NEXT
) {
3246 tcg_gen_movi_tl(env_pc
, npc
);
3248 t_gen_raise_exception(EXCP_DEBUG
);
3250 switch (dc
->is_jmp
) {
3252 gen_goto_tb(dc
, 1, npc
);
3257 /* indicate that the hash table must be used
3258 to find the next TB */
3259 tcg_gen_exit_tb(NULL
, 0);
3263 /* nothing more to generate */
3267 gen_tb_end(tb
, num_insns
);
3269 tb
->size
= dc
->pc
- pc_start
;
3270 tb
->icount
= num_insns
;
3274 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
3275 && qemu_log_in_addr_range(pc_start
)) {
3276 FILE *logfile
= qemu_log_lock();
3277 qemu_log("--------------\n");
3278 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3279 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
);
3280 qemu_log_unlock(logfile
);
3286 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
3288 CRISCPU
*cpu
= CRIS_CPU(cs
);
3289 CPUCRISState
*env
= &cpu
->env
;
3290 const char **regnames
;
3291 const char **pregnames
;
3297 if (env
->pregs
[PR_VR
] < 32) {
3298 pregnames
= pregnames_v10
;
3299 regnames
= regnames_v10
;
3301 pregnames
= pregnames_v32
;
3302 regnames
= regnames_v32
;
3305 qemu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3306 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3307 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3309 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3312 for (i
= 0; i
< 16; i
++) {
3313 qemu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3314 if ((i
+ 1) % 4 == 0) {
3315 qemu_fprintf(f
, "\n");
3318 qemu_fprintf(f
, "\nspecial regs:\n");
3319 for (i
= 0; i
< 16; i
++) {
3320 qemu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3321 if ((i
+ 1) % 4 == 0) {
3322 qemu_fprintf(f
, "\n");
3325 if (env
->pregs
[PR_VR
] >= 32) {
3326 uint32_t srs
= env
->pregs
[PR_SRS
];
3327 qemu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3328 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3329 for (i
= 0; i
< 16; i
++) {
3330 qemu_fprintf(f
, "s%2.2d=%8.8x ",
3331 i
, env
->sregs
[srs
][i
]);
3332 if ((i
+ 1) % 4 == 0) {
3333 qemu_fprintf(f
, "\n");
3338 qemu_fprintf(f
, "\n\n");
3342 void cris_initialize_tcg(void)
3346 cc_x
= tcg_global_mem_new(cpu_env
,
3347 offsetof(CPUCRISState
, cc_x
), "cc_x");
3348 cc_src
= tcg_global_mem_new(cpu_env
,
3349 offsetof(CPUCRISState
, cc_src
), "cc_src");
3350 cc_dest
= tcg_global_mem_new(cpu_env
,
3351 offsetof(CPUCRISState
, cc_dest
),
3353 cc_result
= tcg_global_mem_new(cpu_env
,
3354 offsetof(CPUCRISState
, cc_result
),
3356 cc_op
= tcg_global_mem_new(cpu_env
,
3357 offsetof(CPUCRISState
, cc_op
), "cc_op");
3358 cc_size
= tcg_global_mem_new(cpu_env
,
3359 offsetof(CPUCRISState
, cc_size
),
3361 cc_mask
= tcg_global_mem_new(cpu_env
,
3362 offsetof(CPUCRISState
, cc_mask
),
3365 env_pc
= tcg_global_mem_new(cpu_env
,
3366 offsetof(CPUCRISState
, pc
),
3368 env_btarget
= tcg_global_mem_new(cpu_env
,
3369 offsetof(CPUCRISState
, btarget
),
3371 env_btaken
= tcg_global_mem_new(cpu_env
,
3372 offsetof(CPUCRISState
, btaken
),
3374 for (i
= 0; i
< 16; i
++) {
3375 cpu_R
[i
] = tcg_global_mem_new(cpu_env
,
3376 offsetof(CPUCRISState
, regs
[i
]),
3379 for (i
= 0; i
< 16; i
++) {
3380 cpu_PR
[i
] = tcg_global_mem_new(cpu_env
,
3381 offsetof(CPUCRISState
, pregs
[i
]),
3386 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
,