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
)
1190 static inline unsigned int memsize_z(DisasContext
*dc
)
1192 return dc
->zsize
+ 1;
1195 static inline unsigned int memsize_zz(DisasContext
*dc
)
1197 switch (dc
->zzsize
) {
1205 static inline void do_postinc (DisasContext
*dc
, int size
)
1208 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1212 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1213 int size
, int s_ext
, TCGv dst
)
1216 t_gen_sext(dst
, cpu_R
[rs
], size
);
1218 t_gen_zext(dst
, cpu_R
[rs
], size
);
1222 /* Prepare T0 and T1 for a register alu operation.
1223 s_ext decides if the operand1 should be sign-extended or zero-extended when
1225 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1226 int size
, int s_ext
, TCGv dst
, TCGv src
)
1228 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1231 t_gen_sext(dst
, cpu_R
[rd
], size
);
1233 t_gen_zext(dst
, cpu_R
[rd
], size
);
1237 static int dec_prep_move_m(CPUCRISState
*env
, DisasContext
*dc
,
1238 int s_ext
, int memsize
, TCGv dst
)
1246 is_imm
= rs
== 15 && dc
->postinc
;
1248 /* Load [$rs] onto T1. */
1250 insn_len
= 2 + memsize
;
1255 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, memsize
, s_ext
);
1256 tcg_gen_movi_tl(dst
, imm
);
1259 cris_flush_cc_state(dc
);
1260 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1262 t_gen_sext(dst
, dst
, memsize
);
1264 t_gen_zext(dst
, dst
, memsize
);
1270 /* Prepare T0 and T1 for a memory + alu operation.
1271 s_ext decides if the operand1 should be sign-extended or zero-extended when
1273 static int dec_prep_alu_m(CPUCRISState
*env
, DisasContext
*dc
,
1274 int s_ext
, int memsize
, TCGv dst
, TCGv src
)
1278 insn_len
= dec_prep_move_m(env
, dc
, s_ext
, memsize
, src
);
1279 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1284 static const char *cc_name(int cc
)
1286 static const char *cc_names
[16] = {
1287 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1288 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1291 return cc_names
[cc
];
1295 /* Start of insn decoders. */
1297 static int dec_bccq(CPUCRISState
*env
, DisasContext
*dc
)
1301 uint32_t cond
= dc
->op2
;
1303 offset
= EXTRACT_FIELD(dc
->ir
, 1, 7);
1304 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1307 offset
|= sign
<< 8;
1308 offset
= sign_extend(offset
, 8);
1310 LOG_DIS("b%s %x\n", cc_name(cond
), dc
->pc
+ offset
);
1312 /* op2 holds the condition-code. */
1313 cris_cc_mask(dc
, 0);
1314 cris_prepare_cc_branch(dc
, offset
, cond
);
1317 static int dec_addoq(CPUCRISState
*env
, DisasContext
*dc
)
1321 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1322 imm
= sign_extend(dc
->op1
, 7);
1324 LOG_DIS("addoq %d, $r%u\n", imm
, dc
->op2
);
1325 cris_cc_mask(dc
, 0);
1326 /* Fetch register operand, */
1327 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1331 static int dec_addq(CPUCRISState
*env
, DisasContext
*dc
)
1333 LOG_DIS("addq %u, $r%u\n", dc
->op1
, dc
->op2
);
1335 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1337 cris_cc_mask(dc
, CC_MASK_NZVC
);
1339 cris_alu(dc
, CC_OP_ADD
,
1340 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1343 static int dec_moveq(CPUCRISState
*env
, DisasContext
*dc
)
1347 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1348 imm
= sign_extend(dc
->op1
, 5);
1349 LOG_DIS("moveq %d, $r%u\n", imm
, dc
->op2
);
1351 tcg_gen_movi_tl(cpu_R
[dc
->op2
], imm
);
1354 static int dec_subq(CPUCRISState
*env
, DisasContext
*dc
)
1356 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1358 LOG_DIS("subq %u, $r%u\n", dc
->op1
, dc
->op2
);
1360 cris_cc_mask(dc
, CC_MASK_NZVC
);
1361 cris_alu(dc
, CC_OP_SUB
,
1362 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1365 static int dec_cmpq(CPUCRISState
*env
, DisasContext
*dc
)
1368 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1369 imm
= sign_extend(dc
->op1
, 5);
1371 LOG_DIS("cmpq %d, $r%d\n", imm
, dc
->op2
);
1372 cris_cc_mask(dc
, CC_MASK_NZVC
);
1374 cris_alu(dc
, CC_OP_CMP
,
1375 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1378 static int dec_andq(CPUCRISState
*env
, DisasContext
*dc
)
1381 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1382 imm
= sign_extend(dc
->op1
, 5);
1384 LOG_DIS("andq %d, $r%d\n", imm
, dc
->op2
);
1385 cris_cc_mask(dc
, CC_MASK_NZ
);
1387 cris_alu(dc
, CC_OP_AND
,
1388 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1391 static int dec_orq(CPUCRISState
*env
, DisasContext
*dc
)
1394 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1395 imm
= sign_extend(dc
->op1
, 5);
1396 LOG_DIS("orq %d, $r%d\n", imm
, dc
->op2
);
1397 cris_cc_mask(dc
, CC_MASK_NZ
);
1399 cris_alu(dc
, CC_OP_OR
,
1400 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1403 static int dec_btstq(CPUCRISState
*env
, DisasContext
*dc
)
1405 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1406 LOG_DIS("btstq %u, $r%d\n", dc
->op1
, dc
->op2
);
1408 cris_cc_mask(dc
, CC_MASK_NZ
);
1409 cris_evaluate_flags(dc
);
1410 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1411 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1412 cris_alu(dc
, CC_OP_MOVE
,
1413 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1414 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1415 dc
->flags_uptodate
= 1;
1418 static int dec_asrq(CPUCRISState
*env
, DisasContext
*dc
)
1420 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1421 LOG_DIS("asrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1422 cris_cc_mask(dc
, CC_MASK_NZ
);
1424 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1425 cris_alu(dc
, CC_OP_MOVE
,
1427 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1430 static int dec_lslq(CPUCRISState
*env
, DisasContext
*dc
)
1432 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1433 LOG_DIS("lslq %u, $r%d\n", dc
->op1
, dc
->op2
);
1435 cris_cc_mask(dc
, CC_MASK_NZ
);
1437 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1439 cris_alu(dc
, CC_OP_MOVE
,
1441 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1444 static int dec_lsrq(CPUCRISState
*env
, DisasContext
*dc
)
1446 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1447 LOG_DIS("lsrq %u, $r%d\n", dc
->op1
, dc
->op2
);
1449 cris_cc_mask(dc
, CC_MASK_NZ
);
1451 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1452 cris_alu(dc
, CC_OP_MOVE
,
1454 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1458 static int dec_move_r(CPUCRISState
*env
, DisasContext
*dc
)
1460 int size
= memsize_zz(dc
);
1462 LOG_DIS("move.%c $r%u, $r%u\n",
1463 memsize_char(size
), dc
->op1
, dc
->op2
);
1465 cris_cc_mask(dc
, CC_MASK_NZ
);
1467 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1468 cris_cc_mask(dc
, CC_MASK_NZ
);
1469 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1470 cris_update_cc_x(dc
);
1471 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1475 t0
= tcg_temp_new();
1476 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1477 cris_alu(dc
, CC_OP_MOVE
,
1479 cpu_R
[dc
->op2
], t0
, size
);
1485 static int dec_scc_r(CPUCRISState
*env
, DisasContext
*dc
)
1489 LOG_DIS("s%s $r%u\n",
1490 cc_name(cond
), dc
->op1
);
1492 gen_tst_cc(dc
, cpu_R
[dc
->op1
], cond
);
1493 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], 0);
1495 cris_cc_mask(dc
, 0);
1499 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1502 t
[0] = cpu_R
[dc
->op2
];
1503 t
[1] = cpu_R
[dc
->op1
];
1505 t
[0] = tcg_temp_new();
1506 t
[1] = tcg_temp_new();
1510 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1513 tcg_temp_free(t
[0]);
1514 tcg_temp_free(t
[1]);
1518 static int dec_and_r(CPUCRISState
*env
, DisasContext
*dc
)
1521 int size
= memsize_zz(dc
);
1523 LOG_DIS("and.%c $r%u, $r%u\n",
1524 memsize_char(size
), dc
->op1
, dc
->op2
);
1526 cris_cc_mask(dc
, CC_MASK_NZ
);
1528 cris_alu_alloc_temps(dc
, size
, t
);
1529 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1530 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1531 cris_alu_free_temps(dc
, size
, t
);
1535 static int dec_lz_r(CPUCRISState
*env
, DisasContext
*dc
)
1538 LOG_DIS("lz $r%u, $r%u\n",
1540 cris_cc_mask(dc
, CC_MASK_NZ
);
1541 t0
= tcg_temp_new();
1542 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1543 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1548 static int dec_lsl_r(CPUCRISState
*env
, DisasContext
*dc
)
1551 int size
= memsize_zz(dc
);
1553 LOG_DIS("lsl.%c $r%u, $r%u\n",
1554 memsize_char(size
), dc
->op1
, dc
->op2
);
1556 cris_cc_mask(dc
, CC_MASK_NZ
);
1557 cris_alu_alloc_temps(dc
, size
, t
);
1558 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1559 tcg_gen_andi_tl(t
[1], t
[1], 63);
1560 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1561 cris_alu_alloc_temps(dc
, size
, t
);
1565 static int dec_lsr_r(CPUCRISState
*env
, DisasContext
*dc
)
1568 int size
= memsize_zz(dc
);
1570 LOG_DIS("lsr.%c $r%u, $r%u\n",
1571 memsize_char(size
), dc
->op1
, dc
->op2
);
1573 cris_cc_mask(dc
, CC_MASK_NZ
);
1574 cris_alu_alloc_temps(dc
, size
, t
);
1575 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1576 tcg_gen_andi_tl(t
[1], t
[1], 63);
1577 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1578 cris_alu_free_temps(dc
, size
, t
);
1582 static int dec_asr_r(CPUCRISState
*env
, DisasContext
*dc
)
1585 int size
= memsize_zz(dc
);
1587 LOG_DIS("asr.%c $r%u, $r%u\n",
1588 memsize_char(size
), dc
->op1
, dc
->op2
);
1590 cris_cc_mask(dc
, CC_MASK_NZ
);
1591 cris_alu_alloc_temps(dc
, size
, t
);
1592 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1593 tcg_gen_andi_tl(t
[1], t
[1], 63);
1594 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1595 cris_alu_free_temps(dc
, size
, t
);
1599 static int dec_muls_r(CPUCRISState
*env
, DisasContext
*dc
)
1602 int size
= memsize_zz(dc
);
1604 LOG_DIS("muls.%c $r%u, $r%u\n",
1605 memsize_char(size
), dc
->op1
, dc
->op2
);
1606 cris_cc_mask(dc
, CC_MASK_NZV
);
1607 cris_alu_alloc_temps(dc
, size
, t
);
1608 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1610 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1611 cris_alu_free_temps(dc
, size
, t
);
1615 static int dec_mulu_r(CPUCRISState
*env
, DisasContext
*dc
)
1618 int size
= memsize_zz(dc
);
1620 LOG_DIS("mulu.%c $r%u, $r%u\n",
1621 memsize_char(size
), dc
->op1
, dc
->op2
);
1622 cris_cc_mask(dc
, CC_MASK_NZV
);
1623 cris_alu_alloc_temps(dc
, size
, t
);
1624 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1626 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1627 cris_alu_alloc_temps(dc
, size
, t
);
1632 static int dec_dstep_r(CPUCRISState
*env
, DisasContext
*dc
)
1634 LOG_DIS("dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
);
1635 cris_cc_mask(dc
, CC_MASK_NZ
);
1636 cris_alu(dc
, CC_OP_DSTEP
,
1637 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1641 static int dec_xor_r(CPUCRISState
*env
, DisasContext
*dc
)
1644 int size
= memsize_zz(dc
);
1645 LOG_DIS("xor.%c $r%u, $r%u\n",
1646 memsize_char(size
), dc
->op1
, dc
->op2
);
1647 BUG_ON(size
!= 4); /* xor is dword. */
1648 cris_cc_mask(dc
, CC_MASK_NZ
);
1649 cris_alu_alloc_temps(dc
, size
, t
);
1650 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1652 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1653 cris_alu_free_temps(dc
, size
, t
);
1657 static int dec_bound_r(CPUCRISState
*env
, DisasContext
*dc
)
1660 int size
= memsize_zz(dc
);
1661 LOG_DIS("bound.%c $r%u, $r%u\n",
1662 memsize_char(size
), dc
->op1
, dc
->op2
);
1663 cris_cc_mask(dc
, CC_MASK_NZ
);
1664 l0
= tcg_temp_local_new();
1665 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1666 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1671 static int dec_cmp_r(CPUCRISState
*env
, DisasContext
*dc
)
1674 int size
= memsize_zz(dc
);
1675 LOG_DIS("cmp.%c $r%u, $r%u\n",
1676 memsize_char(size
), dc
->op1
, dc
->op2
);
1677 cris_cc_mask(dc
, CC_MASK_NZVC
);
1678 cris_alu_alloc_temps(dc
, size
, t
);
1679 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1681 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1682 cris_alu_free_temps(dc
, size
, t
);
1686 static int dec_abs_r(CPUCRISState
*env
, DisasContext
*dc
)
1688 LOG_DIS("abs $r%u, $r%u\n",
1690 cris_cc_mask(dc
, CC_MASK_NZ
);
1692 tcg_gen_abs_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
]);
1693 cris_alu(dc
, CC_OP_MOVE
,
1694 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1698 static int dec_add_r(CPUCRISState
*env
, DisasContext
*dc
)
1701 int size
= memsize_zz(dc
);
1702 LOG_DIS("add.%c $r%u, $r%u\n",
1703 memsize_char(size
), dc
->op1
, dc
->op2
);
1704 cris_cc_mask(dc
, CC_MASK_NZVC
);
1705 cris_alu_alloc_temps(dc
, size
, t
);
1706 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1708 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1709 cris_alu_free_temps(dc
, size
, t
);
1713 static int dec_addc_r(CPUCRISState
*env
, DisasContext
*dc
)
1715 LOG_DIS("addc $r%u, $r%u\n",
1717 cris_evaluate_flags(dc
);
1718 /* Set for this insn. */
1719 dc
->flagx_known
= 1;
1720 dc
->flags_x
= X_FLAG
;
1722 cris_cc_mask(dc
, CC_MASK_NZVC
);
1723 cris_alu(dc
, CC_OP_ADDC
,
1724 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1728 static int dec_mcp_r(CPUCRISState
*env
, DisasContext
*dc
)
1730 LOG_DIS("mcp $p%u, $r%u\n",
1732 cris_evaluate_flags(dc
);
1733 cris_cc_mask(dc
, CC_MASK_RNZV
);
1734 cris_alu(dc
, CC_OP_MCP
,
1735 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1740 static char * swapmode_name(int mode
, char *modename
) {
1743 modename
[i
++] = 'n';
1746 modename
[i
++] = 'w';
1749 modename
[i
++] = 'b';
1752 modename
[i
++] = 'r';
1759 static int dec_swap_r(CPUCRISState
*env
, DisasContext
*dc
)
1765 LOG_DIS("swap%s $r%u\n",
1766 swapmode_name(dc
->op2
, modename
), dc
->op1
);
1768 cris_cc_mask(dc
, CC_MASK_NZ
);
1769 t0
= tcg_temp_new();
1770 tcg_gen_mov_tl(t0
, cpu_R
[dc
->op1
]);
1772 tcg_gen_not_tl(t0
, t0
);
1775 t_gen_swapw(t0
, t0
);
1778 t_gen_swapb(t0
, t0
);
1781 t_gen_swapr(t0
, t0
);
1783 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1788 static int dec_or_r(CPUCRISState
*env
, DisasContext
*dc
)
1791 int size
= memsize_zz(dc
);
1792 LOG_DIS("or.%c $r%u, $r%u\n",
1793 memsize_char(size
), dc
->op1
, dc
->op2
);
1794 cris_cc_mask(dc
, CC_MASK_NZ
);
1795 cris_alu_alloc_temps(dc
, size
, t
);
1796 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1797 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1798 cris_alu_free_temps(dc
, size
, t
);
1802 static int dec_addi_r(CPUCRISState
*env
, DisasContext
*dc
)
1805 LOG_DIS("addi.%c $r%u, $r%u\n",
1806 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1807 cris_cc_mask(dc
, 0);
1808 t0
= tcg_temp_new();
1809 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1810 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1815 static int dec_addi_acr(CPUCRISState
*env
, DisasContext
*dc
)
1818 LOG_DIS("addi.%c $r%u, $r%u, $acr\n",
1819 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
);
1820 cris_cc_mask(dc
, 0);
1821 t0
= tcg_temp_new();
1822 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1823 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1828 static int dec_neg_r(CPUCRISState
*env
, DisasContext
*dc
)
1831 int size
= memsize_zz(dc
);
1832 LOG_DIS("neg.%c $r%u, $r%u\n",
1833 memsize_char(size
), dc
->op1
, dc
->op2
);
1834 cris_cc_mask(dc
, CC_MASK_NZVC
);
1835 cris_alu_alloc_temps(dc
, size
, t
);
1836 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1838 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1839 cris_alu_free_temps(dc
, size
, t
);
1843 static int dec_btst_r(CPUCRISState
*env
, DisasContext
*dc
)
1845 LOG_DIS("btst $r%u, $r%u\n",
1847 cris_cc_mask(dc
, CC_MASK_NZ
);
1848 cris_evaluate_flags(dc
);
1849 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_env
, cpu_R
[dc
->op2
],
1850 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1851 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1852 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1853 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1854 dc
->flags_uptodate
= 1;
1858 static int dec_sub_r(CPUCRISState
*env
, DisasContext
*dc
)
1861 int size
= memsize_zz(dc
);
1862 LOG_DIS("sub.%c $r%u, $r%u\n",
1863 memsize_char(size
), dc
->op1
, dc
->op2
);
1864 cris_cc_mask(dc
, CC_MASK_NZVC
);
1865 cris_alu_alloc_temps(dc
, size
, t
);
1866 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1867 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1868 cris_alu_free_temps(dc
, size
, t
);
1872 /* Zero extension. From size to dword. */
1873 static int dec_movu_r(CPUCRISState
*env
, DisasContext
*dc
)
1876 int size
= memsize_z(dc
);
1877 LOG_DIS("movu.%c $r%u, $r%u\n",
1881 cris_cc_mask(dc
, CC_MASK_NZ
);
1882 t0
= tcg_temp_new();
1883 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1884 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1889 /* Sign extension. From size to dword. */
1890 static int dec_movs_r(CPUCRISState
*env
, DisasContext
*dc
)
1893 int size
= memsize_z(dc
);
1894 LOG_DIS("movs.%c $r%u, $r%u\n",
1898 cris_cc_mask(dc
, CC_MASK_NZ
);
1899 t0
= tcg_temp_new();
1900 /* Size can only be qi or hi. */
1901 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1902 cris_alu(dc
, CC_OP_MOVE
,
1903 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
1908 /* zero extension. From size to dword. */
1909 static int dec_addu_r(CPUCRISState
*env
, DisasContext
*dc
)
1912 int size
= memsize_z(dc
);
1913 LOG_DIS("addu.%c $r%u, $r%u\n",
1917 cris_cc_mask(dc
, CC_MASK_NZVC
);
1918 t0
= tcg_temp_new();
1919 /* Size can only be qi or hi. */
1920 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1921 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1926 /* Sign extension. From size to dword. */
1927 static int dec_adds_r(CPUCRISState
*env
, DisasContext
*dc
)
1930 int size
= memsize_z(dc
);
1931 LOG_DIS("adds.%c $r%u, $r%u\n",
1935 cris_cc_mask(dc
, CC_MASK_NZVC
);
1936 t0
= tcg_temp_new();
1937 /* Size can only be qi or hi. */
1938 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1939 cris_alu(dc
, CC_OP_ADD
,
1940 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1945 /* Zero extension. From size to dword. */
1946 static int dec_subu_r(CPUCRISState
*env
, DisasContext
*dc
)
1949 int size
= memsize_z(dc
);
1950 LOG_DIS("subu.%c $r%u, $r%u\n",
1954 cris_cc_mask(dc
, CC_MASK_NZVC
);
1955 t0
= tcg_temp_new();
1956 /* Size can only be qi or hi. */
1957 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
1958 cris_alu(dc
, CC_OP_SUB
,
1959 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1964 /* Sign extension. From size to dword. */
1965 static int dec_subs_r(CPUCRISState
*env
, DisasContext
*dc
)
1968 int size
= memsize_z(dc
);
1969 LOG_DIS("subs.%c $r%u, $r%u\n",
1973 cris_cc_mask(dc
, CC_MASK_NZVC
);
1974 t0
= tcg_temp_new();
1975 /* Size can only be qi or hi. */
1976 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
1977 cris_alu(dc
, CC_OP_SUB
,
1978 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1983 static int dec_setclrf(CPUCRISState
*env
, DisasContext
*dc
)
1986 int set
= (~dc
->opcode
>> 2) & 1;
1989 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1990 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1991 if (set
&& flags
== 0) {
1994 } else if (!set
&& (flags
& 0x20)) {
1997 LOG_DIS("%sf %x\n", set
? "set" : "clr", flags
);
2000 /* User space is not allowed to touch these. Silently ignore. */
2001 if (dc
->tb_flags
& U_FLAG
) {
2002 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2005 if (flags
& X_FLAG
) {
2006 dc
->flagx_known
= 1;
2008 dc
->flags_x
= X_FLAG
;
2014 /* Break the TB if any of the SPI flag changes. */
2015 if (flags
& (P_FLAG
| S_FLAG
)) {
2016 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2017 dc
->is_jmp
= DISAS_UPDATE
;
2018 dc
->cpustate_changed
= 1;
2021 /* For the I flag, only act on posedge. */
2022 if ((flags
& I_FLAG
)) {
2023 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2024 dc
->is_jmp
= DISAS_UPDATE
;
2025 dc
->cpustate_changed
= 1;
2029 /* Simply decode the flags. */
2030 cris_evaluate_flags(dc
);
2031 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2032 cris_update_cc_x(dc
);
2033 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2036 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2037 /* Enter user mode. */
2038 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2039 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2040 dc
->cpustate_changed
= 1;
2042 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2044 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2047 dc
->flags_uptodate
= 1;
2052 static int dec_move_rs(CPUCRISState
*env
, DisasContext
*dc
)
2054 LOG_DIS("move $r%u, $s%u\n", dc
->op1
, dc
->op2
);
2055 cris_cc_mask(dc
, 0);
2056 gen_helper_movl_sreg_reg(cpu_env
, tcg_const_tl(dc
->op2
),
2057 tcg_const_tl(dc
->op1
));
2060 static int dec_move_sr(CPUCRISState
*env
, DisasContext
*dc
)
2062 LOG_DIS("move $s%u, $r%u\n", dc
->op2
, dc
->op1
);
2063 cris_cc_mask(dc
, 0);
2064 gen_helper_movl_reg_sreg(cpu_env
, tcg_const_tl(dc
->op1
),
2065 tcg_const_tl(dc
->op2
));
2069 static int dec_move_rp(CPUCRISState
*env
, DisasContext
*dc
)
2072 LOG_DIS("move $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2073 cris_cc_mask(dc
, 0);
2075 t
[0] = tcg_temp_new();
2076 if (dc
->op2
== PR_CCS
) {
2077 cris_evaluate_flags(dc
);
2078 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2079 if (dc
->tb_flags
& U_FLAG
) {
2080 t
[1] = tcg_temp_new();
2081 /* User space is not allowed to touch all flags. */
2082 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2083 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2084 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2085 tcg_temp_free(t
[1]);
2088 tcg_gen_mov_tl(t
[0], cpu_R
[dc
->op1
]);
2091 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2092 if (dc
->op2
== PR_CCS
) {
2093 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2094 dc
->flags_uptodate
= 1;
2096 tcg_temp_free(t
[0]);
2099 static int dec_move_pr(CPUCRISState
*env
, DisasContext
*dc
)
2102 LOG_DIS("move $p%u, $r%u\n", dc
->op2
, dc
->op1
);
2103 cris_cc_mask(dc
, 0);
2105 if (dc
->op2
== PR_CCS
) {
2106 cris_evaluate_flags(dc
);
2109 if (dc
->op2
== PR_DZ
) {
2110 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
2112 t0
= tcg_temp_new();
2113 t_gen_mov_TN_preg(t0
, dc
->op2
);
2114 cris_alu(dc
, CC_OP_MOVE
,
2115 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
,
2116 preg_sizes
[dc
->op2
]);
2122 static int dec_move_mr(CPUCRISState
*env
, DisasContext
*dc
)
2124 int memsize
= memsize_zz(dc
);
2126 LOG_DIS("move.%c [$r%u%s, $r%u\n",
2127 memsize_char(memsize
),
2128 dc
->op1
, dc
->postinc
? "+]" : "]",
2132 insn_len
= dec_prep_move_m(env
, dc
, 0, 4, cpu_R
[dc
->op2
]);
2133 cris_cc_mask(dc
, CC_MASK_NZ
);
2134 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2135 cris_update_cc_x(dc
);
2136 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2140 t0
= tcg_temp_new();
2141 insn_len
= dec_prep_move_m(env
, dc
, 0, memsize
, t0
);
2142 cris_cc_mask(dc
, CC_MASK_NZ
);
2143 cris_alu(dc
, CC_OP_MOVE
,
2144 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2147 do_postinc(dc
, memsize
);
2151 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2153 t
[0] = tcg_temp_new();
2154 t
[1] = tcg_temp_new();
2157 static inline void cris_alu_m_free_temps(TCGv
*t
)
2159 tcg_temp_free(t
[0]);
2160 tcg_temp_free(t
[1]);
2163 static int dec_movs_m(CPUCRISState
*env
, DisasContext
*dc
)
2166 int memsize
= memsize_z(dc
);
2168 LOG_DIS("movs.%c [$r%u%s, $r%u\n",
2169 memsize_char(memsize
),
2170 dc
->op1
, dc
->postinc
? "+]" : "]",
2173 cris_alu_m_alloc_temps(t
);
2175 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2176 cris_cc_mask(dc
, CC_MASK_NZ
);
2177 cris_alu(dc
, CC_OP_MOVE
,
2178 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2179 do_postinc(dc
, memsize
);
2180 cris_alu_m_free_temps(t
);
2184 static int dec_addu_m(CPUCRISState
*env
, DisasContext
*dc
)
2187 int memsize
= memsize_z(dc
);
2189 LOG_DIS("addu.%c [$r%u%s, $r%u\n",
2190 memsize_char(memsize
),
2191 dc
->op1
, dc
->postinc
? "+]" : "]",
2194 cris_alu_m_alloc_temps(t
);
2196 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2197 cris_cc_mask(dc
, CC_MASK_NZVC
);
2198 cris_alu(dc
, CC_OP_ADD
,
2199 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2200 do_postinc(dc
, memsize
);
2201 cris_alu_m_free_temps(t
);
2205 static int dec_adds_m(CPUCRISState
*env
, DisasContext
*dc
)
2208 int memsize
= memsize_z(dc
);
2210 LOG_DIS("adds.%c [$r%u%s, $r%u\n",
2211 memsize_char(memsize
),
2212 dc
->op1
, dc
->postinc
? "+]" : "]",
2215 cris_alu_m_alloc_temps(t
);
2217 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2218 cris_cc_mask(dc
, CC_MASK_NZVC
);
2219 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2220 do_postinc(dc
, memsize
);
2221 cris_alu_m_free_temps(t
);
2225 static int dec_subu_m(CPUCRISState
*env
, DisasContext
*dc
)
2228 int memsize
= memsize_z(dc
);
2230 LOG_DIS("subu.%c [$r%u%s, $r%u\n",
2231 memsize_char(memsize
),
2232 dc
->op1
, dc
->postinc
? "+]" : "]",
2235 cris_alu_m_alloc_temps(t
);
2237 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2238 cris_cc_mask(dc
, CC_MASK_NZVC
);
2239 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2240 do_postinc(dc
, memsize
);
2241 cris_alu_m_free_temps(t
);
2245 static int dec_subs_m(CPUCRISState
*env
, DisasContext
*dc
)
2248 int memsize
= memsize_z(dc
);
2250 LOG_DIS("subs.%c [$r%u%s, $r%u\n",
2251 memsize_char(memsize
),
2252 dc
->op1
, dc
->postinc
? "+]" : "]",
2255 cris_alu_m_alloc_temps(t
);
2257 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2258 cris_cc_mask(dc
, CC_MASK_NZVC
);
2259 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2260 do_postinc(dc
, memsize
);
2261 cris_alu_m_free_temps(t
);
2265 static int dec_movu_m(CPUCRISState
*env
, DisasContext
*dc
)
2268 int memsize
= memsize_z(dc
);
2271 LOG_DIS("movu.%c [$r%u%s, $r%u\n",
2272 memsize_char(memsize
),
2273 dc
->op1
, dc
->postinc
? "+]" : "]",
2276 cris_alu_m_alloc_temps(t
);
2277 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2278 cris_cc_mask(dc
, CC_MASK_NZ
);
2279 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2280 do_postinc(dc
, memsize
);
2281 cris_alu_m_free_temps(t
);
2285 static int dec_cmpu_m(CPUCRISState
*env
, DisasContext
*dc
)
2288 int memsize
= memsize_z(dc
);
2290 LOG_DIS("cmpu.%c [$r%u%s, $r%u\n",
2291 memsize_char(memsize
),
2292 dc
->op1
, dc
->postinc
? "+]" : "]",
2295 cris_alu_m_alloc_temps(t
);
2296 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2297 cris_cc_mask(dc
, CC_MASK_NZVC
);
2298 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2299 do_postinc(dc
, memsize
);
2300 cris_alu_m_free_temps(t
);
2304 static int dec_cmps_m(CPUCRISState
*env
, DisasContext
*dc
)
2307 int memsize
= memsize_z(dc
);
2309 LOG_DIS("cmps.%c [$r%u%s, $r%u\n",
2310 memsize_char(memsize
),
2311 dc
->op1
, dc
->postinc
? "+]" : "]",
2314 cris_alu_m_alloc_temps(t
);
2315 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2316 cris_cc_mask(dc
, CC_MASK_NZVC
);
2317 cris_alu(dc
, CC_OP_CMP
,
2318 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2320 do_postinc(dc
, memsize
);
2321 cris_alu_m_free_temps(t
);
2325 static int dec_cmp_m(CPUCRISState
*env
, DisasContext
*dc
)
2328 int memsize
= memsize_zz(dc
);
2330 LOG_DIS("cmp.%c [$r%u%s, $r%u\n",
2331 memsize_char(memsize
),
2332 dc
->op1
, dc
->postinc
? "+]" : "]",
2335 cris_alu_m_alloc_temps(t
);
2336 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2337 cris_cc_mask(dc
, CC_MASK_NZVC
);
2338 cris_alu(dc
, CC_OP_CMP
,
2339 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2341 do_postinc(dc
, memsize
);
2342 cris_alu_m_free_temps(t
);
2346 static int dec_test_m(CPUCRISState
*env
, DisasContext
*dc
)
2349 int memsize
= memsize_zz(dc
);
2351 LOG_DIS("test.%c [$r%u%s] op2=%x\n",
2352 memsize_char(memsize
),
2353 dc
->op1
, dc
->postinc
? "+]" : "]",
2356 cris_evaluate_flags(dc
);
2358 cris_alu_m_alloc_temps(t
);
2359 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2360 cris_cc_mask(dc
, CC_MASK_NZ
);
2361 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2363 cris_alu(dc
, CC_OP_CMP
,
2364 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2365 do_postinc(dc
, memsize
);
2366 cris_alu_m_free_temps(t
);
2370 static int dec_and_m(CPUCRISState
*env
, DisasContext
*dc
)
2373 int memsize
= memsize_zz(dc
);
2375 LOG_DIS("and.%c [$r%u%s, $r%u\n",
2376 memsize_char(memsize
),
2377 dc
->op1
, dc
->postinc
? "+]" : "]",
2380 cris_alu_m_alloc_temps(t
);
2381 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2382 cris_cc_mask(dc
, CC_MASK_NZ
);
2383 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2384 do_postinc(dc
, memsize
);
2385 cris_alu_m_free_temps(t
);
2389 static int dec_add_m(CPUCRISState
*env
, DisasContext
*dc
)
2392 int memsize
= memsize_zz(dc
);
2394 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2395 memsize_char(memsize
),
2396 dc
->op1
, dc
->postinc
? "+]" : "]",
2399 cris_alu_m_alloc_temps(t
);
2400 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2401 cris_cc_mask(dc
, CC_MASK_NZVC
);
2402 cris_alu(dc
, CC_OP_ADD
,
2403 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2404 do_postinc(dc
, memsize
);
2405 cris_alu_m_free_temps(t
);
2409 static int dec_addo_m(CPUCRISState
*env
, DisasContext
*dc
)
2412 int memsize
= memsize_zz(dc
);
2414 LOG_DIS("add.%c [$r%u%s, $r%u\n",
2415 memsize_char(memsize
),
2416 dc
->op1
, dc
->postinc
? "+]" : "]",
2419 cris_alu_m_alloc_temps(t
);
2420 insn_len
= dec_prep_alu_m(env
, dc
, 1, memsize
, t
[0], t
[1]);
2421 cris_cc_mask(dc
, 0);
2422 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2423 do_postinc(dc
, memsize
);
2424 cris_alu_m_free_temps(t
);
2428 static int dec_bound_m(CPUCRISState
*env
, DisasContext
*dc
)
2431 int memsize
= memsize_zz(dc
);
2433 LOG_DIS("bound.%c [$r%u%s, $r%u\n",
2434 memsize_char(memsize
),
2435 dc
->op1
, dc
->postinc
? "+]" : "]",
2438 l
[0] = tcg_temp_local_new();
2439 l
[1] = tcg_temp_local_new();
2440 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, l
[0], l
[1]);
2441 cris_cc_mask(dc
, CC_MASK_NZ
);
2442 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2443 do_postinc(dc
, memsize
);
2444 tcg_temp_free(l
[0]);
2445 tcg_temp_free(l
[1]);
2449 static int dec_addc_mr(CPUCRISState
*env
, DisasContext
*dc
)
2453 LOG_DIS("addc [$r%u%s, $r%u\n",
2454 dc
->op1
, dc
->postinc
? "+]" : "]",
2457 cris_evaluate_flags(dc
);
2459 /* Set for this insn. */
2460 dc
->flagx_known
= 1;
2461 dc
->flags_x
= X_FLAG
;
2463 cris_alu_m_alloc_temps(t
);
2464 insn_len
= dec_prep_alu_m(env
, dc
, 0, 4, t
[0], t
[1]);
2465 cris_cc_mask(dc
, CC_MASK_NZVC
);
2466 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2468 cris_alu_m_free_temps(t
);
2472 static int dec_sub_m(CPUCRISState
*env
, DisasContext
*dc
)
2475 int memsize
= memsize_zz(dc
);
2477 LOG_DIS("sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2478 memsize_char(memsize
),
2479 dc
->op1
, dc
->postinc
? "+]" : "]",
2480 dc
->op2
, dc
->ir
, dc
->zzsize
);
2482 cris_alu_m_alloc_temps(t
);
2483 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2484 cris_cc_mask(dc
, CC_MASK_NZVC
);
2485 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2486 do_postinc(dc
, memsize
);
2487 cris_alu_m_free_temps(t
);
2491 static int dec_or_m(CPUCRISState
*env
, DisasContext
*dc
)
2494 int memsize
= memsize_zz(dc
);
2496 LOG_DIS("or.%c [$r%u%s, $r%u pc=%x\n",
2497 memsize_char(memsize
),
2498 dc
->op1
, dc
->postinc
? "+]" : "]",
2501 cris_alu_m_alloc_temps(t
);
2502 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2503 cris_cc_mask(dc
, CC_MASK_NZ
);
2504 cris_alu(dc
, CC_OP_OR
,
2505 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2506 do_postinc(dc
, memsize
);
2507 cris_alu_m_free_temps(t
);
2511 static int dec_move_mp(CPUCRISState
*env
, DisasContext
*dc
)
2514 int memsize
= memsize_zz(dc
);
2517 LOG_DIS("move.%c [$r%u%s, $p%u\n",
2518 memsize_char(memsize
),
2520 dc
->postinc
? "+]" : "]",
2523 cris_alu_m_alloc_temps(t
);
2524 insn_len
= dec_prep_alu_m(env
, dc
, 0, memsize
, t
[0], t
[1]);
2525 cris_cc_mask(dc
, 0);
2526 if (dc
->op2
== PR_CCS
) {
2527 cris_evaluate_flags(dc
);
2528 if (dc
->tb_flags
& U_FLAG
) {
2529 /* User space is not allowed to touch all flags. */
2530 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2531 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2532 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2536 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2538 do_postinc(dc
, memsize
);
2539 cris_alu_m_free_temps(t
);
2543 static int dec_move_pm(CPUCRISState
*env
, DisasContext
*dc
)
2548 memsize
= preg_sizes
[dc
->op2
];
2550 LOG_DIS("move.%c $p%u, [$r%u%s\n",
2551 memsize_char(memsize
),
2552 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]");
2554 /* prepare store. Address in T0, value in T1. */
2555 if (dc
->op2
== PR_CCS
) {
2556 cris_evaluate_flags(dc
);
2558 t0
= tcg_temp_new();
2559 t_gen_mov_TN_preg(t0
, dc
->op2
);
2560 cris_flush_cc_state(dc
);
2561 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2564 cris_cc_mask(dc
, 0);
2566 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2571 static int dec_movem_mr(CPUCRISState
*env
, DisasContext
*dc
)
2577 int nr
= dc
->op2
+ 1;
2579 LOG_DIS("movem [$r%u%s, $r%u\n", dc
->op1
,
2580 dc
->postinc
? "+]" : "]", dc
->op2
);
2582 addr
= tcg_temp_new();
2583 /* There are probably better ways of doing this. */
2584 cris_flush_cc_state(dc
);
2585 for (i
= 0; i
< (nr
>> 1); i
++) {
2586 tmp
[i
] = tcg_temp_new_i64();
2587 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2588 gen_load64(dc
, tmp
[i
], addr
);
2591 tmp32
= tcg_temp_new_i32();
2592 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2593 gen_load(dc
, tmp32
, addr
, 4, 0);
2597 tcg_temp_free(addr
);
2599 for (i
= 0; i
< (nr
>> 1); i
++) {
2600 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2601 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2602 tcg_gen_extrl_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2603 tcg_temp_free_i64(tmp
[i
]);
2606 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2607 tcg_temp_free(tmp32
);
2610 /* writeback the updated pointer value. */
2612 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2615 /* gen_load might want to evaluate the previous insns flags. */
2616 cris_cc_mask(dc
, 0);
2620 static int dec_movem_rm(CPUCRISState
*env
, DisasContext
*dc
)
2626 LOG_DIS("movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2627 dc
->postinc
? "+]" : "]");
2629 cris_flush_cc_state(dc
);
2631 tmp
= tcg_temp_new();
2632 addr
= tcg_temp_new();
2633 tcg_gen_movi_tl(tmp
, 4);
2634 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2635 for (i
= 0; i
<= dc
->op2
; i
++) {
2636 /* Displace addr. */
2637 /* Perform the store. */
2638 gen_store(dc
, addr
, cpu_R
[i
], 4);
2639 tcg_gen_add_tl(addr
, addr
, tmp
);
2642 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2644 cris_cc_mask(dc
, 0);
2646 tcg_temp_free(addr
);
2650 static int dec_move_rm(CPUCRISState
*env
, DisasContext
*dc
)
2654 memsize
= memsize_zz(dc
);
2656 LOG_DIS("move.%c $r%u, [$r%u]\n",
2657 memsize_char(memsize
), dc
->op2
, dc
->op1
);
2659 /* prepare store. */
2660 cris_flush_cc_state(dc
);
2661 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2664 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2666 cris_cc_mask(dc
, 0);
2670 static int dec_lapcq(CPUCRISState
*env
, DisasContext
*dc
)
2672 LOG_DIS("lapcq %x, $r%u\n",
2673 dc
->pc
+ dc
->op1
*2, dc
->op2
);
2674 cris_cc_mask(dc
, 0);
2675 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2679 static int dec_lapc_im(CPUCRISState
*env
, DisasContext
*dc
)
2687 cris_cc_mask(dc
, 0);
2688 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2689 LOG_DIS("lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
);
2693 tcg_gen_movi_tl(cpu_R
[rd
], pc
);
2697 /* Jump to special reg. */
2698 static int dec_jump_p(CPUCRISState
*env
, DisasContext
*dc
)
2700 LOG_DIS("jump $p%u\n", dc
->op2
);
2702 if (dc
->op2
== PR_CCS
) {
2703 cris_evaluate_flags(dc
);
2705 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2706 /* rete will often have low bit set to indicate delayslot. */
2707 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2708 cris_cc_mask(dc
, 0);
2709 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2713 /* Jump and save. */
2714 static int dec_jas_r(CPUCRISState
*env
, DisasContext
*dc
)
2716 LOG_DIS("jas $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2717 cris_cc_mask(dc
, 0);
2718 /* Store the return address in Pd. */
2719 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2723 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2725 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2729 static int dec_jas_im(CPUCRISState
*env
, DisasContext
*dc
)
2733 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2735 LOG_DIS("jas 0x%x\n", imm
);
2736 cris_cc_mask(dc
, 0);
2737 /* Store the return address in Pd. */
2738 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2741 cris_prepare_jmp(dc
, JMP_DIRECT
);
2745 static int dec_jasc_im(CPUCRISState
*env
, DisasContext
*dc
)
2749 imm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2751 LOG_DIS("jasc 0x%x\n", imm
);
2752 cris_cc_mask(dc
, 0);
2753 /* Store the return address in Pd. */
2754 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2757 cris_prepare_jmp(dc
, JMP_DIRECT
);
2761 static int dec_jasc_r(CPUCRISState
*env
, DisasContext
*dc
)
2763 LOG_DIS("jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
);
2764 cris_cc_mask(dc
, 0);
2765 /* Store the return address in Pd. */
2766 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2767 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2768 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2772 static int dec_bcc_im(CPUCRISState
*env
, DisasContext
*dc
)
2775 uint32_t cond
= dc
->op2
;
2777 offset
= cris_fetch(env
, dc
, dc
->pc
+ 2, 2, 1);
2779 LOG_DIS("b%s %d pc=%x dst=%x\n",
2780 cc_name(cond
), offset
,
2781 dc
->pc
, dc
->pc
+ offset
);
2783 cris_cc_mask(dc
, 0);
2784 /* op2 holds the condition-code. */
2785 cris_prepare_cc_branch(dc
, offset
, cond
);
2789 static int dec_bas_im(CPUCRISState
*env
, DisasContext
*dc
)
2793 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2795 LOG_DIS("bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
);
2796 cris_cc_mask(dc
, 0);
2797 /* Store the return address in Pd. */
2798 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2800 dc
->jmp_pc
= dc
->pc
+ simm
;
2801 cris_prepare_jmp(dc
, JMP_DIRECT
);
2805 static int dec_basc_im(CPUCRISState
*env
, DisasContext
*dc
)
2808 simm
= cris_fetch(env
, dc
, dc
->pc
+ 2, 4, 0);
2810 LOG_DIS("basc 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
+ 12));
2815 dc
->jmp_pc
= dc
->pc
+ simm
;
2816 cris_prepare_jmp(dc
, JMP_DIRECT
);
2820 static int dec_rfe_etc(CPUCRISState
*env
, DisasContext
*dc
)
2822 cris_cc_mask(dc
, 0);
2824 if (dc
->op2
== 15) {
2825 tcg_gen_st_i32(tcg_const_i32(1), cpu_env
,
2826 -offsetof(CRISCPU
, env
) + offsetof(CPUState
, halted
));
2827 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2828 t_gen_raise_exception(EXCP_HLT
);
2832 switch (dc
->op2
& 7) {
2836 cris_evaluate_flags(dc
);
2837 gen_helper_rfe(cpu_env
);
2838 dc
->is_jmp
= DISAS_UPDATE
;
2843 cris_evaluate_flags(dc
);
2844 gen_helper_rfn(cpu_env
);
2845 dc
->is_jmp
= DISAS_UPDATE
;
2848 LOG_DIS("break %d\n", dc
->op1
);
2849 cris_evaluate_flags(dc
);
2851 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2853 /* Breaks start at 16 in the exception vector. */
2854 t_gen_mov_env_TN(trap_vector
,
2855 tcg_const_tl(dc
->op1
+ 16));
2856 t_gen_raise_exception(EXCP_BREAK
);
2857 dc
->is_jmp
= DISAS_UPDATE
;
2860 printf("op2=%x\n", dc
->op2
);
2868 static int dec_ftag_fidx_d_m(CPUCRISState
*env
, DisasContext
*dc
)
2873 static int dec_ftag_fidx_i_m(CPUCRISState
*env
, DisasContext
*dc
)
2878 static int dec_null(CPUCRISState
*env
, DisasContext
*dc
)
2880 printf("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2881 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2887 static struct decoder_info
{
2892 int (*dec
)(CPUCRISState
*env
, DisasContext
*dc
);
2894 /* Order matters here. */
2895 {DEC_MOVEQ
, dec_moveq
},
2896 {DEC_BTSTQ
, dec_btstq
},
2897 {DEC_CMPQ
, dec_cmpq
},
2898 {DEC_ADDOQ
, dec_addoq
},
2899 {DEC_ADDQ
, dec_addq
},
2900 {DEC_SUBQ
, dec_subq
},
2901 {DEC_ANDQ
, dec_andq
},
2903 {DEC_ASRQ
, dec_asrq
},
2904 {DEC_LSLQ
, dec_lslq
},
2905 {DEC_LSRQ
, dec_lsrq
},
2906 {DEC_BCCQ
, dec_bccq
},
2908 {DEC_BCC_IM
, dec_bcc_im
},
2909 {DEC_JAS_IM
, dec_jas_im
},
2910 {DEC_JAS_R
, dec_jas_r
},
2911 {DEC_JASC_IM
, dec_jasc_im
},
2912 {DEC_JASC_R
, dec_jasc_r
},
2913 {DEC_BAS_IM
, dec_bas_im
},
2914 {DEC_BASC_IM
, dec_basc_im
},
2915 {DEC_JUMP_P
, dec_jump_p
},
2916 {DEC_LAPC_IM
, dec_lapc_im
},
2917 {DEC_LAPCQ
, dec_lapcq
},
2919 {DEC_RFE_ETC
, dec_rfe_etc
},
2920 {DEC_ADDC_MR
, dec_addc_mr
},
2922 {DEC_MOVE_MP
, dec_move_mp
},
2923 {DEC_MOVE_PM
, dec_move_pm
},
2924 {DEC_MOVEM_MR
, dec_movem_mr
},
2925 {DEC_MOVEM_RM
, dec_movem_rm
},
2926 {DEC_MOVE_PR
, dec_move_pr
},
2927 {DEC_SCC_R
, dec_scc_r
},
2928 {DEC_SETF
, dec_setclrf
},
2929 {DEC_CLEARF
, dec_setclrf
},
2931 {DEC_MOVE_SR
, dec_move_sr
},
2932 {DEC_MOVE_RP
, dec_move_rp
},
2933 {DEC_SWAP_R
, dec_swap_r
},
2934 {DEC_ABS_R
, dec_abs_r
},
2935 {DEC_LZ_R
, dec_lz_r
},
2936 {DEC_MOVE_RS
, dec_move_rs
},
2937 {DEC_BTST_R
, dec_btst_r
},
2938 {DEC_ADDC_R
, dec_addc_r
},
2940 {DEC_DSTEP_R
, dec_dstep_r
},
2941 {DEC_XOR_R
, dec_xor_r
},
2942 {DEC_MCP_R
, dec_mcp_r
},
2943 {DEC_CMP_R
, dec_cmp_r
},
2945 {DEC_ADDI_R
, dec_addi_r
},
2946 {DEC_ADDI_ACR
, dec_addi_acr
},
2948 {DEC_ADD_R
, dec_add_r
},
2949 {DEC_SUB_R
, dec_sub_r
},
2951 {DEC_ADDU_R
, dec_addu_r
},
2952 {DEC_ADDS_R
, dec_adds_r
},
2953 {DEC_SUBU_R
, dec_subu_r
},
2954 {DEC_SUBS_R
, dec_subs_r
},
2955 {DEC_LSL_R
, dec_lsl_r
},
2957 {DEC_AND_R
, dec_and_r
},
2958 {DEC_OR_R
, dec_or_r
},
2959 {DEC_BOUND_R
, dec_bound_r
},
2960 {DEC_ASR_R
, dec_asr_r
},
2961 {DEC_LSR_R
, dec_lsr_r
},
2963 {DEC_MOVU_R
, dec_movu_r
},
2964 {DEC_MOVS_R
, dec_movs_r
},
2965 {DEC_NEG_R
, dec_neg_r
},
2966 {DEC_MOVE_R
, dec_move_r
},
2968 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2969 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2971 {DEC_MULS_R
, dec_muls_r
},
2972 {DEC_MULU_R
, dec_mulu_r
},
2974 {DEC_ADDU_M
, dec_addu_m
},
2975 {DEC_ADDS_M
, dec_adds_m
},
2976 {DEC_SUBU_M
, dec_subu_m
},
2977 {DEC_SUBS_M
, dec_subs_m
},
2979 {DEC_CMPU_M
, dec_cmpu_m
},
2980 {DEC_CMPS_M
, dec_cmps_m
},
2981 {DEC_MOVU_M
, dec_movu_m
},
2982 {DEC_MOVS_M
, dec_movs_m
},
2984 {DEC_CMP_M
, dec_cmp_m
},
2985 {DEC_ADDO_M
, dec_addo_m
},
2986 {DEC_BOUND_M
, dec_bound_m
},
2987 {DEC_ADD_M
, dec_add_m
},
2988 {DEC_SUB_M
, dec_sub_m
},
2989 {DEC_AND_M
, dec_and_m
},
2990 {DEC_OR_M
, dec_or_m
},
2991 {DEC_MOVE_RM
, dec_move_rm
},
2992 {DEC_TEST_M
, dec_test_m
},
2993 {DEC_MOVE_MR
, dec_move_mr
},
2998 static unsigned int crisv32_decoder(CPUCRISState
*env
, DisasContext
*dc
)
3003 /* Load a halfword onto the instruction register. */
3004 dc
->ir
= cris_fetch(env
, dc
, dc
->pc
, 2, 0);
3006 /* Now decode it. */
3007 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3008 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3009 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3010 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3011 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3012 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3014 /* Large switch for all insns. */
3015 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3016 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
3017 insn_len
= decinfo
[i
].dec(env
, dc
);
3022 #if !defined(CONFIG_USER_ONLY)
3023 /* Single-stepping ? */
3024 if (dc
->tb_flags
& S_FLAG
) {
3025 TCGLabel
*l1
= gen_new_label();
3026 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3027 /* We treat SPC as a break with an odd trap vector. */
3028 cris_evaluate_flags(dc
);
3029 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3030 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3031 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3032 t_gen_raise_exception(EXCP_BREAK
);
3039 #include "translate_v10.c.inc"
3042 * Delay slots on QEMU/CRIS.
3044 * If an exception hits on a delayslot, the core will let ERP (the Exception
3045 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3046 * to give SW a hint that the exception actually hit on the dslot.
3048 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3049 * the core and any jmp to an odd addresses will mask off that lsb. It is
3050 * simply there to let sw know there was an exception on a dslot.
3052 * When the software returns from an exception, the branch will re-execute.
3053 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3054 * and the branch and delayslot don't share pages.
3056 * The TB contaning the branch insn will set up env->btarget and evaluate
3057 * env->btaken. When the translation loop exits we will note that the branch
3058 * sequence is broken and let env->dslot be the size of the branch insn (those
3061 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3062 * set). It will also expect to have env->dslot setup with the size of the
3063 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3064 * will execute the dslot and take the branch, either to btarget or just one
3067 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3068 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3069 * branch and set lsb). Then env->dslot gets cleared so that the exception
3070 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3071 * masked off and we will reexecute the branch insn.
3075 /* generate intermediate code for basic block 'tb'. */
3076 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
3078 CPUCRISState
*env
= cs
->env_ptr
;
3080 unsigned int insn_len
;
3081 struct DisasContext ctx
;
3082 struct DisasContext
*dc
= &ctx
;
3083 uint32_t page_start
;
3087 if (env
->pregs
[PR_VR
] == 32) {
3088 dc
->decoder
= crisv32_decoder
;
3089 dc
->clear_locked_irq
= 0;
3091 dc
->decoder
= crisv10_decoder
;
3092 dc
->clear_locked_irq
= 1;
3095 /* Odd PC indicates that branch is rexecuting due to exception in the
3096 * delayslot, like in real hw.
3098 pc_start
= tb
->pc
& ~1;
3099 dc
->cpu
= env_archcpu(env
);
3102 dc
->is_jmp
= DISAS_NEXT
;
3105 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
3106 dc
->flags_uptodate
= 1;
3107 dc
->flagx_known
= 1;
3108 dc
->flags_x
= tb
->flags
& X_FLAG
;
3109 dc
->cc_x_uptodate
= 0;
3112 dc
->clear_prefix
= 0;
3114 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3115 dc
->cc_size_uptodate
= -1;
3117 /* Decode TB flags. */
3118 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG \
3119 | X_FLAG
| PFIX_FLAG
);
3120 dc
->delayed_branch
= !!(tb
->flags
& 7);
3121 if (dc
->delayed_branch
) {
3122 dc
->jmp
= JMP_INDIRECT
;
3124 dc
->jmp
= JMP_NOJMP
;
3127 dc
->cpustate_changed
= 0;
3129 page_start
= pc_start
& TARGET_PAGE_MASK
;
3134 tcg_gen_insn_start(dc
->delayed_branch
== 1
3135 ? dc
->ppc
| 1 : dc
->pc
);
3138 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
3139 cris_evaluate_flags(dc
);
3140 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3141 t_gen_raise_exception(EXCP_DEBUG
);
3142 dc
->is_jmp
= DISAS_UPDATE
;
3143 /* The address covered by the breakpoint must be included in
3144 [tb->pc, tb->pc + tb->size) in order to for it to be
3145 properly cleared -- thus we increment the PC here so that
3146 the logic setting tb->size below does the right thing. */
3152 LOG_DIS("%8.8x:\t", dc
->pc
);
3154 if (num_insns
== max_insns
&& (tb_cflags(tb
) & CF_LAST_IO
)) {
3159 insn_len
= dc
->decoder(env
, dc
);
3163 cris_clear_x_flag(dc
);
3166 /* Check for delayed branches here. If we do it before
3167 actually generating any host code, the simulator will just
3168 loop doing nothing for on this program location. */
3169 if (dc
->delayed_branch
) {
3170 dc
->delayed_branch
--;
3171 if (dc
->delayed_branch
== 0) {
3172 if (tb
->flags
& 7) {
3173 t_gen_mov_env_TN(dslot
, tcg_const_tl(0));
3175 if (dc
->cpustate_changed
|| !dc
->flagx_known
3176 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
))) {
3177 cris_store_direct_jmp(dc
);
3180 if (dc
->clear_locked_irq
) {
3181 dc
->clear_locked_irq
= 0;
3182 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3185 if (dc
->jmp
== JMP_DIRECT_CC
) {
3186 TCGLabel
*l1
= gen_new_label();
3187 cris_evaluate_flags(dc
);
3189 /* Conditional jmp. */
3190 tcg_gen_brcondi_tl(TCG_COND_EQ
,
3192 gen_goto_tb(dc
, 1, dc
->jmp_pc
);
3194 gen_goto_tb(dc
, 0, dc
->pc
);
3195 dc
->is_jmp
= DISAS_TB_JUMP
;
3196 dc
->jmp
= JMP_NOJMP
;
3197 } else if (dc
->jmp
== JMP_DIRECT
) {
3198 cris_evaluate_flags(dc
);
3199 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
3200 dc
->is_jmp
= DISAS_TB_JUMP
;
3201 dc
->jmp
= JMP_NOJMP
;
3203 t_gen_cc_jmp(env_btarget
, tcg_const_tl(dc
->pc
));
3204 dc
->is_jmp
= DISAS_JUMP
;
3210 /* If we are rexecuting a branch due to exceptions on
3211 delay slots don't break. */
3212 if (!(tb
->pc
& 1) && cs
->singlestep_enabled
) {
3215 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3216 && !tcg_op_buf_full()
3218 && (dc
->pc
- page_start
< TARGET_PAGE_SIZE
)
3219 && num_insns
< max_insns
);
3221 if (dc
->clear_locked_irq
) {
3222 t_gen_mov_env_TN(locked_irq
, tcg_const_tl(0));
3227 /* Force an update if the per-tb cpu state has changed. */
3228 if (dc
->is_jmp
== DISAS_NEXT
3229 && (dc
->cpustate_changed
|| !dc
->flagx_known
3230 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3231 dc
->is_jmp
= DISAS_UPDATE
;
3232 tcg_gen_movi_tl(env_pc
, npc
);
3234 /* Broken branch+delayslot sequence. */
3235 if (dc
->delayed_branch
== 1) {
3236 /* Set env->dslot to the size of the branch insn. */
3237 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3238 cris_store_direct_jmp(dc
);
3241 cris_evaluate_flags(dc
);
3243 if (unlikely(cs
->singlestep_enabled
)) {
3244 if (dc
->is_jmp
== DISAS_NEXT
) {
3245 tcg_gen_movi_tl(env_pc
, npc
);
3247 t_gen_raise_exception(EXCP_DEBUG
);
3249 switch (dc
->is_jmp
) {
3251 gen_goto_tb(dc
, 1, npc
);
3256 /* indicate that the hash table must be used
3257 to find the next TB */
3258 tcg_gen_exit_tb(NULL
, 0);
3262 /* nothing more to generate */
3266 gen_tb_end(tb
, num_insns
);
3268 tb
->size
= dc
->pc
- pc_start
;
3269 tb
->icount
= num_insns
;
3273 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
3274 && qemu_log_in_addr_range(pc_start
)) {
3275 FILE *logfile
= qemu_log_lock();
3276 qemu_log("--------------\n");
3277 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3278 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
);
3279 qemu_log_unlock(logfile
);
3285 void cris_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
3287 CRISCPU
*cpu
= CRIS_CPU(cs
);
3288 CPUCRISState
*env
= &cpu
->env
;
3289 const char **regnames
;
3290 const char **pregnames
;
3296 if (env
->pregs
[PR_VR
] < 32) {
3297 pregnames
= pregnames_v10
;
3298 regnames
= regnames_v10
;
3300 pregnames
= pregnames_v32
;
3301 regnames
= regnames_v32
;
3304 qemu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3305 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3306 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3308 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3311 for (i
= 0; i
< 16; i
++) {
3312 qemu_fprintf(f
, "%s=%8.8x ", regnames
[i
], env
->regs
[i
]);
3313 if ((i
+ 1) % 4 == 0) {
3314 qemu_fprintf(f
, "\n");
3317 qemu_fprintf(f
, "\nspecial regs:\n");
3318 for (i
= 0; i
< 16; i
++) {
3319 qemu_fprintf(f
, "%s=%8.8x ", pregnames
[i
], env
->pregs
[i
]);
3320 if ((i
+ 1) % 4 == 0) {
3321 qemu_fprintf(f
, "\n");
3324 if (env
->pregs
[PR_VR
] >= 32) {
3325 uint32_t srs
= env
->pregs
[PR_SRS
];
3326 qemu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3327 if (srs
< ARRAY_SIZE(env
->sregs
)) {
3328 for (i
= 0; i
< 16; i
++) {
3329 qemu_fprintf(f
, "s%2.2d=%8.8x ",
3330 i
, env
->sregs
[srs
][i
]);
3331 if ((i
+ 1) % 4 == 0) {
3332 qemu_fprintf(f
, "\n");
3337 qemu_fprintf(f
, "\n\n");
3341 void cris_initialize_tcg(void)
3345 cc_x
= tcg_global_mem_new(cpu_env
,
3346 offsetof(CPUCRISState
, cc_x
), "cc_x");
3347 cc_src
= tcg_global_mem_new(cpu_env
,
3348 offsetof(CPUCRISState
, cc_src
), "cc_src");
3349 cc_dest
= tcg_global_mem_new(cpu_env
,
3350 offsetof(CPUCRISState
, cc_dest
),
3352 cc_result
= tcg_global_mem_new(cpu_env
,
3353 offsetof(CPUCRISState
, cc_result
),
3355 cc_op
= tcg_global_mem_new(cpu_env
,
3356 offsetof(CPUCRISState
, cc_op
), "cc_op");
3357 cc_size
= tcg_global_mem_new(cpu_env
,
3358 offsetof(CPUCRISState
, cc_size
),
3360 cc_mask
= tcg_global_mem_new(cpu_env
,
3361 offsetof(CPUCRISState
, cc_mask
),
3364 env_pc
= tcg_global_mem_new(cpu_env
,
3365 offsetof(CPUCRISState
, pc
),
3367 env_btarget
= tcg_global_mem_new(cpu_env
,
3368 offsetof(CPUCRISState
, btarget
),
3370 env_btaken
= tcg_global_mem_new(cpu_env
,
3371 offsetof(CPUCRISState
, btaken
),
3373 for (i
= 0; i
< 16; i
++) {
3374 cpu_R
[i
] = tcg_global_mem_new(cpu_env
,
3375 offsetof(CPUCRISState
, regs
[i
]),
3378 for (i
= 0; i
< 16; i
++) {
3379 cpu_PR
[i
] = tcg_global_mem_new(cpu_env
,
3380 offsetof(CPUCRISState
, pregs
[i
]),
3385 void restore_state_to_opc(CPUCRISState
*env
, TranslationBlock
*tb
,