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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
24 * The condition code translation is in need of attention.
39 #include "crisv32-decode.h"
40 #include "qemu-common.h"
47 #define DIS(x) if (loglevel & CPU_LOG_TB_IN_ASM) x
53 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
54 #define BUG_ON(x) ({if (x) BUG();})
58 /* Used by the decoder. */
59 #define EXTRACT_FIELD(src, start, end) \
60 (((src) >> start) & ((1 << (end - start + 1)) - 1))
62 #define CC_MASK_NZ 0xc
63 #define CC_MASK_NZV 0xe
64 #define CC_MASK_NZVC 0xf
65 #define CC_MASK_RNZV 0x10e
67 static TCGv_ptr cpu_env
;
68 static TCGv cpu_R
[16];
69 static TCGv cpu_PR
[16];
73 static TCGv cc_result
;
78 static TCGv env_btaken
;
79 static TCGv env_btarget
;
82 #include "gen-icount.h"
84 /* This is the state at translation time. */
85 typedef struct DisasContext
{
94 unsigned int zsize
, zzsize
;
103 int cc_size_uptodate
; /* -1 invalid or last written value. */
105 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
106 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
107 int flagx_known
; /* Wether or not flags_x has the x flag known at
111 int clear_x
; /* Clear x after this insn? */
112 int cpustate_changed
;
113 unsigned int tb_flags
; /* tb dependent flags. */
118 #define JMP_INDIRECT 2
119 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
124 struct TranslationBlock
*tb
;
125 int singlestep_enabled
;
128 static void gen_BUG(DisasContext
*dc
, const char *file
, int line
)
130 printf ("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
131 fprintf (logfile
, "BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
132 cpu_abort(dc
->env
, "%s:%d\n", file
, line
);
135 static const char *regnames
[] =
137 "$r0", "$r1", "$r2", "$r3",
138 "$r4", "$r5", "$r6", "$r7",
139 "$r8", "$r9", "$r10", "$r11",
140 "$r12", "$r13", "$sp", "$acr",
142 static const char *pregnames
[] =
144 "$bz", "$vr", "$pid", "$srs",
145 "$wz", "$exs", "$eda", "$mof",
146 "$dz", "$ebp", "$erp", "$srp",
147 "$nrp", "$ccs", "$usp", "$spc",
150 /* We need this table to handle preg-moves with implicit width. */
151 static int preg_sizes
[] = {
162 #define t_gen_mov_TN_env(tn, member) \
163 _t_gen_mov_TN_env((tn), offsetof(CPUState, member))
164 #define t_gen_mov_env_TN(member, tn) \
165 _t_gen_mov_env_TN(offsetof(CPUState, member), (tn))
167 static inline void t_gen_mov_TN_reg(TCGv tn
, int r
)
170 fprintf(stderr
, "wrong register read $r%d\n", r
);
171 tcg_gen_mov_tl(tn
, cpu_R
[r
]);
173 static inline void t_gen_mov_reg_TN(int r
, TCGv tn
)
176 fprintf(stderr
, "wrong register write $r%d\n", r
);
177 tcg_gen_mov_tl(cpu_R
[r
], tn
);
180 static inline void _t_gen_mov_TN_env(TCGv tn
, int offset
)
182 if (offset
> sizeof (CPUState
))
183 fprintf(stderr
, "wrong load from env from off=%d\n", offset
);
184 tcg_gen_ld_tl(tn
, cpu_env
, offset
);
186 static inline void _t_gen_mov_env_TN(int offset
, TCGv tn
)
188 if (offset
> sizeof (CPUState
))
189 fprintf(stderr
, "wrong store to env at off=%d\n", offset
);
190 tcg_gen_st_tl(tn
, cpu_env
, offset
);
193 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
196 fprintf(stderr
, "wrong register read $p%d\n", r
);
197 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
198 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
200 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
201 else if (r
== PR_EDA
) {
202 printf("read from EDA!\n");
203 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
206 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
208 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
211 fprintf(stderr
, "wrong register write $p%d\n", r
);
212 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
214 else if (r
== PR_SRS
)
215 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
218 gen_helper_tlb_flush_pid(tn
);
219 if (dc
->tb_flags
& S_FLAG
&& r
== PR_SPC
)
220 gen_helper_spc_write(tn
);
221 else if (r
== PR_CCS
)
222 dc
->cpustate_changed
= 1;
223 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
227 static inline void t_gen_raise_exception(uint32_t index
)
229 TCGv_i32 tmp
= tcg_const_i32(index
);
230 gen_helper_raise_exception(tmp
);
231 tcg_temp_free_i32(tmp
);
234 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
239 t_31
= tcg_const_tl(31);
240 tcg_gen_shl_tl(d
, a
, b
);
242 tcg_gen_sub_tl(t0
, t_31
, b
);
243 tcg_gen_sar_tl(t0
, t0
, t_31
);
244 tcg_gen_and_tl(t0
, t0
, d
);
245 tcg_gen_xor_tl(d
, d
, t0
);
250 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
255 t_31
= tcg_temp_new();
256 tcg_gen_shr_tl(d
, a
, b
);
258 tcg_gen_movi_tl(t_31
, 31);
259 tcg_gen_sub_tl(t0
, t_31
, b
);
260 tcg_gen_sar_tl(t0
, t0
, t_31
);
261 tcg_gen_and_tl(t0
, t0
, d
);
262 tcg_gen_xor_tl(d
, d
, t0
);
267 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
272 t_31
= tcg_temp_new();
273 tcg_gen_sar_tl(d
, a
, b
);
275 tcg_gen_movi_tl(t_31
, 31);
276 tcg_gen_sub_tl(t0
, t_31
, b
);
277 tcg_gen_sar_tl(t0
, t0
, t_31
);
278 tcg_gen_or_tl(d
, d
, t0
);
283 /* 64-bit signed mul, lower result in d and upper in d2. */
284 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
288 t0
= tcg_temp_new_i64();
289 t1
= tcg_temp_new_i64();
291 tcg_gen_ext_i32_i64(t0
, a
);
292 tcg_gen_ext_i32_i64(t1
, b
);
293 tcg_gen_mul_i64(t0
, t0
, t1
);
295 tcg_gen_trunc_i64_i32(d
, t0
);
296 tcg_gen_shri_i64(t0
, t0
, 32);
297 tcg_gen_trunc_i64_i32(d2
, t0
);
299 tcg_temp_free_i64(t0
);
300 tcg_temp_free_i64(t1
);
303 /* 64-bit unsigned muls, lower result in d and upper in d2. */
304 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
308 t0
= tcg_temp_new_i64();
309 t1
= tcg_temp_new_i64();
311 tcg_gen_extu_i32_i64(t0
, a
);
312 tcg_gen_extu_i32_i64(t1
, b
);
313 tcg_gen_mul_i64(t0
, t0
, t1
);
315 tcg_gen_trunc_i64_i32(d
, t0
);
316 tcg_gen_shri_i64(t0
, t0
, 32);
317 tcg_gen_trunc_i64_i32(d2
, t0
);
319 tcg_temp_free_i64(t0
);
320 tcg_temp_free_i64(t1
);
323 /* 32bit branch-free binary search for counting leading zeros. */
324 static void t_gen_lz_i32(TCGv d
, TCGv x
)
328 y
= tcg_temp_new_i32();
329 m
= tcg_temp_new_i32();
330 n
= tcg_temp_new_i32();
333 tcg_gen_shri_i32(y
, x
, 16);
334 tcg_gen_neg_i32(y
, y
);
336 /* m = (y >> 16) & 16 */
337 tcg_gen_sari_i32(m
, y
, 16);
338 tcg_gen_andi_i32(m
, m
, 16);
341 tcg_gen_sub_i32(n
, tcg_const_i32(16), m
);
343 tcg_gen_shr_i32(x
, x
, m
);
346 tcg_gen_subi_i32(y
, x
, 0x100);
347 /* m = (y >> 16) & 8 */
348 tcg_gen_sari_i32(m
, y
, 16);
349 tcg_gen_andi_i32(m
, m
, 8);
351 tcg_gen_add_i32(n
, n
, m
);
353 tcg_gen_shl_i32(x
, x
, m
);
356 tcg_gen_subi_i32(y
, x
, 0x1000);
357 /* m = (y >> 16) & 4 */
358 tcg_gen_sari_i32(m
, y
, 16);
359 tcg_gen_andi_i32(m
, m
, 4);
361 tcg_gen_add_i32(n
, n
, m
);
363 tcg_gen_shl_i32(x
, x
, m
);
366 tcg_gen_subi_i32(y
, x
, 0x4000);
367 /* m = (y >> 16) & 2 */
368 tcg_gen_sari_i32(m
, y
, 16);
369 tcg_gen_andi_i32(m
, m
, 2);
371 tcg_gen_add_i32(n
, n
, m
);
373 tcg_gen_shl_i32(x
, x
, m
);
376 tcg_gen_shri_i32(y
, x
, 14);
377 /* m = y & ~(y >> 1) */
378 tcg_gen_sari_i32(m
, y
, 1);
379 tcg_gen_not_i32(m
, m
);
380 tcg_gen_and_i32(m
, m
, y
);
383 tcg_gen_addi_i32(d
, n
, 2);
384 tcg_gen_sub_i32(d
, d
, m
);
391 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
395 l1
= gen_new_label();
402 tcg_gen_shli_tl(d
, a
, 1);
403 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
404 tcg_gen_sub_tl(d
, d
, b
);
408 /* Extended arithmetics on CRIS. */
409 static inline void t_gen_add_flag(TCGv d
, int flag
)
414 t_gen_mov_TN_preg(c
, PR_CCS
);
415 /* Propagate carry into d. */
416 tcg_gen_andi_tl(c
, c
, 1 << flag
);
418 tcg_gen_shri_tl(c
, c
, flag
);
419 tcg_gen_add_tl(d
, d
, c
);
423 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
425 if (dc
->flagx_known
) {
430 t_gen_mov_TN_preg(c
, PR_CCS
);
431 /* C flag is already at bit 0. */
432 tcg_gen_andi_tl(c
, c
, C_FLAG
);
433 tcg_gen_add_tl(d
, d
, c
);
441 t_gen_mov_TN_preg(x
, PR_CCS
);
442 tcg_gen_mov_tl(c
, x
);
444 /* Propagate carry into d if X is set. Branch free. */
445 tcg_gen_andi_tl(c
, c
, C_FLAG
);
446 tcg_gen_andi_tl(x
, x
, X_FLAG
);
447 tcg_gen_shri_tl(x
, x
, 4);
449 tcg_gen_and_tl(x
, x
, c
);
450 tcg_gen_add_tl(d
, d
, x
);
456 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
458 if (dc
->flagx_known
) {
463 t_gen_mov_TN_preg(c
, PR_CCS
);
464 /* C flag is already at bit 0. */
465 tcg_gen_andi_tl(c
, c
, C_FLAG
);
466 tcg_gen_sub_tl(d
, d
, c
);
474 t_gen_mov_TN_preg(x
, PR_CCS
);
475 tcg_gen_mov_tl(c
, x
);
477 /* Propagate carry into d if X is set. Branch free. */
478 tcg_gen_andi_tl(c
, c
, C_FLAG
);
479 tcg_gen_andi_tl(x
, x
, X_FLAG
);
480 tcg_gen_shri_tl(x
, x
, 4);
482 tcg_gen_and_tl(x
, x
, c
);
483 tcg_gen_sub_tl(d
, d
, x
);
489 /* Swap the two bytes within each half word of the s operand.
490 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
491 static inline void t_gen_swapb(TCGv d
, TCGv s
)
496 org_s
= tcg_temp_new();
498 /* d and s may refer to the same object. */
499 tcg_gen_mov_tl(org_s
, s
);
500 tcg_gen_shli_tl(t
, org_s
, 8);
501 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
502 tcg_gen_shri_tl(t
, org_s
, 8);
503 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
504 tcg_gen_or_tl(d
, d
, t
);
506 tcg_temp_free(org_s
);
509 /* Swap the halfwords of the s operand. */
510 static inline void t_gen_swapw(TCGv d
, TCGv s
)
513 /* d and s refer the same object. */
515 tcg_gen_mov_tl(t
, s
);
516 tcg_gen_shli_tl(d
, t
, 16);
517 tcg_gen_shri_tl(t
, t
, 16);
518 tcg_gen_or_tl(d
, d
, t
);
522 /* Reverse the within each byte.
523 T0 = (((T0 << 7) & 0x80808080) |
524 ((T0 << 5) & 0x40404040) |
525 ((T0 << 3) & 0x20202020) |
526 ((T0 << 1) & 0x10101010) |
527 ((T0 >> 1) & 0x08080808) |
528 ((T0 >> 3) & 0x04040404) |
529 ((T0 >> 5) & 0x02020202) |
530 ((T0 >> 7) & 0x01010101));
532 static inline void t_gen_swapr(TCGv d
, TCGv s
)
535 int shift
; /* LSL when positive, LSR when negative. */
550 /* d and s refer the same object. */
552 org_s
= tcg_temp_new();
553 tcg_gen_mov_tl(org_s
, s
);
555 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
556 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
557 for (i
= 1; i
< ARRAY_SIZE(bitrev
); i
++) {
558 if (bitrev
[i
].shift
>= 0) {
559 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
561 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
563 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
564 tcg_gen_or_tl(d
, d
, t
);
567 tcg_temp_free(org_s
);
570 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
575 l1
= gen_new_label();
576 btaken
= tcg_temp_new();
578 /* Conditional jmp. */
579 tcg_gen_mov_tl(btaken
, env_btaken
);
580 tcg_gen_mov_tl(env_pc
, pc_false
);
581 tcg_gen_brcondi_tl(TCG_COND_EQ
, btaken
, 0, l1
);
582 tcg_gen_mov_tl(env_pc
, pc_true
);
585 tcg_temp_free(btaken
);
588 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
590 TranslationBlock
*tb
;
592 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
594 tcg_gen_movi_tl(env_pc
, dest
);
595 tcg_gen_exit_tb((long)tb
+ n
);
597 tcg_gen_movi_tl(env_pc
, dest
);
602 /* Sign extend at translation time. */
603 static int sign_extend(unsigned int val
, unsigned int width
)
615 static inline void cris_clear_x_flag(DisasContext
*dc
)
617 if (dc
->flagx_known
&& dc
->flags_x
)
618 dc
->flags_uptodate
= 0;
624 static void cris_flush_cc_state(DisasContext
*dc
)
626 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
627 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
628 dc
->cc_size_uptodate
= dc
->cc_size
;
630 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
631 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
634 static void cris_evaluate_flags(DisasContext
*dc
)
636 if (!dc
->flags_uptodate
) {
637 cris_flush_cc_state(dc
);
642 gen_helper_evaluate_flags_mcp();
645 gen_helper_evaluate_flags_muls();
648 gen_helper_evaluate_flags_mulu();
660 gen_helper_evaluate_flags_move_4();
663 gen_helper_evaluate_flags_move_2();
666 gen_helper_evaluate_flags();
675 if (dc
->cc_size
== 4)
676 gen_helper_evaluate_flags_sub_4();
678 gen_helper_evaluate_flags();
685 gen_helper_evaluate_flags_alu_4();
688 gen_helper_evaluate_flags();
693 if (dc
->flagx_known
) {
695 tcg_gen_ori_tl(cpu_PR
[PR_CCS
],
696 cpu_PR
[PR_CCS
], X_FLAG
);
698 tcg_gen_andi_tl(cpu_PR
[PR_CCS
],
699 cpu_PR
[PR_CCS
], ~X_FLAG
);
702 dc
->flags_uptodate
= 1;
706 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
715 /* Check if we need to evaluate the condition codes due to
717 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
719 /* TODO: optimize this case. It trigs all the time. */
720 cris_evaluate_flags (dc
);
726 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
730 dc
->flags_uptodate
= 0;
733 static inline void cris_update_cc_x(DisasContext
*dc
)
735 /* Save the x flag state at the time of the cc snapshot. */
736 if (dc
->flagx_known
) {
737 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
))
739 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
740 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
743 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
744 dc
->cc_x_uptodate
= 1;
748 /* Update cc prior to executing ALU op. Needs source operands untouched. */
749 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
750 TCGv dst
, TCGv src
, int size
)
753 cris_update_cc_op(dc
, op
, size
);
754 tcg_gen_mov_tl(cc_src
, src
);
763 tcg_gen_mov_tl(cc_dest
, dst
);
765 cris_update_cc_x(dc
);
769 /* Update cc after executing ALU op. needs the result. */
770 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
773 tcg_gen_mov_tl(cc_result
, res
);
776 /* Returns one if the write back stage should execute. */
777 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
778 TCGv dst
, TCGv a
, TCGv b
, int size
)
780 /* Emit the ALU insns. */
784 tcg_gen_add_tl(dst
, a
, b
);
785 /* Extended arithmetics. */
786 t_gen_addx_carry(dc
, dst
);
789 tcg_gen_add_tl(dst
, a
, b
);
790 t_gen_add_flag(dst
, 0); /* C_FLAG. */
793 tcg_gen_add_tl(dst
, a
, b
);
794 t_gen_add_flag(dst
, 8); /* R_FLAG. */
797 tcg_gen_sub_tl(dst
, a
, b
);
798 /* Extended arithmetics. */
799 t_gen_subx_carry(dc
, dst
);
802 tcg_gen_mov_tl(dst
, b
);
805 tcg_gen_or_tl(dst
, a
, b
);
808 tcg_gen_and_tl(dst
, a
, b
);
811 tcg_gen_xor_tl(dst
, a
, b
);
814 t_gen_lsl(dst
, a
, b
);
817 t_gen_lsr(dst
, a
, b
);
820 t_gen_asr(dst
, a
, b
);
823 tcg_gen_neg_tl(dst
, b
);
824 /* Extended arithmetics. */
825 t_gen_subx_carry(dc
, dst
);
828 t_gen_lz_i32(dst
, b
);
831 t_gen_muls(dst
, cpu_PR
[PR_MOF
], a
, b
);
834 t_gen_mulu(dst
, cpu_PR
[PR_MOF
], a
, b
);
837 t_gen_cris_dstep(dst
, a
, b
);
842 l1
= gen_new_label();
843 tcg_gen_mov_tl(dst
, a
);
844 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
845 tcg_gen_mov_tl(dst
, b
);
850 tcg_gen_sub_tl(dst
, a
, b
);
851 /* Extended arithmetics. */
852 t_gen_subx_carry(dc
, dst
);
855 fprintf (logfile
, "illegal ALU op.\n");
861 tcg_gen_andi_tl(dst
, dst
, 0xff);
863 tcg_gen_andi_tl(dst
, dst
, 0xffff);
866 static void cris_alu(DisasContext
*dc
, int op
,
867 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
874 if (op
== CC_OP_BOUND
)
875 tmp
= tcg_temp_local_new();
877 if (op
== CC_OP_CMP
) {
878 tmp
= tcg_temp_new();
880 } else if (size
== 4) {
884 tmp
= tcg_temp_new();
887 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
888 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
889 cris_update_result(dc
, tmp
);
894 tcg_gen_andi_tl(d
, d
, ~0xff);
896 tcg_gen_andi_tl(d
, d
, ~0xffff);
897 tcg_gen_or_tl(d
, d
, tmp
);
899 if (!TCGV_EQUAL(tmp
, d
))
903 static int arith_cc(DisasContext
*dc
)
907 case CC_OP_ADDC
: return 1;
908 case CC_OP_ADD
: return 1;
909 case CC_OP_SUB
: return 1;
910 case CC_OP_DSTEP
: return 1;
911 case CC_OP_LSL
: return 1;
912 case CC_OP_LSR
: return 1;
913 case CC_OP_ASR
: return 1;
914 case CC_OP_CMP
: return 1;
915 case CC_OP_NEG
: return 1;
916 case CC_OP_OR
: return 1;
917 case CC_OP_AND
: return 1;
918 case CC_OP_XOR
: return 1;
919 case CC_OP_MULU
: return 1;
920 case CC_OP_MULS
: return 1;
928 static void gen_tst_cc (DisasContext
*dc
, TCGv cc
, int cond
)
930 int arith_opt
, move_opt
;
932 /* TODO: optimize more condition codes. */
935 * If the flags are live, we've gotta look into the bits of CCS.
936 * Otherwise, if we just did an arithmetic operation we try to
937 * evaluate the condition code faster.
939 * When this function is done, T0 should be non-zero if the condition
942 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
943 move_opt
= (dc
->cc_op
== CC_OP_MOVE
);
946 if (arith_opt
|| move_opt
) {
947 /* If cc_result is zero, T0 should be
948 non-zero otherwise T0 should be zero. */
950 l1
= gen_new_label();
951 tcg_gen_movi_tl(cc
, 0);
952 tcg_gen_brcondi_tl(TCG_COND_NE
, cc_result
,
954 tcg_gen_movi_tl(cc
, 1);
958 cris_evaluate_flags(dc
);
960 cpu_PR
[PR_CCS
], Z_FLAG
);
964 if (arith_opt
|| move_opt
)
965 tcg_gen_mov_tl(cc
, cc_result
);
967 cris_evaluate_flags(dc
);
968 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
970 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
974 cris_evaluate_flags(dc
);
975 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
978 cris_evaluate_flags(dc
);
979 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
], C_FLAG
);
980 tcg_gen_andi_tl(cc
, cc
, C_FLAG
);
983 cris_evaluate_flags(dc
);
984 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], V_FLAG
);
987 cris_evaluate_flags(dc
);
988 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
990 tcg_gen_andi_tl(cc
, cc
, V_FLAG
);
993 if (arith_opt
|| move_opt
) {
996 if (dc
->cc_size
== 1)
998 else if (dc
->cc_size
== 2)
1001 tcg_gen_shri_tl(cc
, cc_result
, bits
);
1002 tcg_gen_xori_tl(cc
, cc
, 1);
1004 cris_evaluate_flags(dc
);
1005 tcg_gen_xori_tl(cc
, cpu_PR
[PR_CCS
],
1007 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1011 if (arith_opt
|| move_opt
) {
1014 if (dc
->cc_size
== 1)
1016 else if (dc
->cc_size
== 2)
1019 tcg_gen_shri_tl(cc
, cc_result
, 31);
1022 cris_evaluate_flags(dc
);
1023 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
1028 cris_evaluate_flags(dc
);
1029 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
],
1033 cris_evaluate_flags(dc
);
1037 tmp
= tcg_temp_new();
1038 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
1040 /* Overlay the C flag on top of the Z. */
1041 tcg_gen_shli_tl(cc
, tmp
, 2);
1042 tcg_gen_and_tl(cc
, tmp
, cc
);
1043 tcg_gen_andi_tl(cc
, cc
, Z_FLAG
);
1049 cris_evaluate_flags(dc
);
1050 /* Overlay the V flag on top of the N. */
1051 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1053 cpu_PR
[PR_CCS
], cc
);
1054 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1055 tcg_gen_xori_tl(cc
, cc
, N_FLAG
);
1058 cris_evaluate_flags(dc
);
1059 /* Overlay the V flag on top of the N. */
1060 tcg_gen_shli_tl(cc
, cpu_PR
[PR_CCS
], 2);
1062 cpu_PR
[PR_CCS
], cc
);
1063 tcg_gen_andi_tl(cc
, cc
, N_FLAG
);
1066 cris_evaluate_flags(dc
);
1073 /* To avoid a shift we overlay everything on
1075 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1076 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1078 tcg_gen_xori_tl(z
, z
, 2);
1080 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1081 tcg_gen_xori_tl(n
, n
, 2);
1082 tcg_gen_and_tl(cc
, z
, n
);
1083 tcg_gen_andi_tl(cc
, cc
, 2);
1090 cris_evaluate_flags(dc
);
1097 /* To avoid a shift we overlay everything on
1099 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1100 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1102 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1103 tcg_gen_or_tl(cc
, z
, n
);
1104 tcg_gen_andi_tl(cc
, cc
, 2);
1111 cris_evaluate_flags(dc
);
1112 tcg_gen_andi_tl(cc
, cpu_PR
[PR_CCS
], P_FLAG
);
1115 tcg_gen_movi_tl(cc
, 1);
1123 static void cris_store_direct_jmp(DisasContext
*dc
)
1125 /* Store the direct jmp state into the cpu-state. */
1126 if (dc
->jmp
== JMP_DIRECT
) {
1127 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1128 tcg_gen_movi_tl(env_btaken
, 1);
1132 static void cris_prepare_cc_branch (DisasContext
*dc
,
1133 int offset
, int cond
)
1135 /* This helps us re-schedule the micro-code to insns in delay-slots
1136 before the actual jump. */
1137 dc
->delayed_branch
= 2;
1138 dc
->jmp_pc
= dc
->pc
+ offset
;
1142 dc
->jmp
= JMP_INDIRECT
;
1143 gen_tst_cc (dc
, env_btaken
, cond
);
1144 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1146 /* Allow chaining. */
1147 dc
->jmp
= JMP_DIRECT
;
1152 /* jumps, when the dest is in a live reg for example. Direct should be set
1153 when the dest addr is constant to allow tb chaining. */
1154 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1156 /* This helps us re-schedule the micro-code to insns in delay-slots
1157 before the actual jump. */
1158 dc
->delayed_branch
= 2;
1160 if (type
== JMP_INDIRECT
)
1161 tcg_gen_movi_tl(env_btaken
, 1);
1164 static void gen_load64(DisasContext
*dc
, TCGv_i64 dst
, TCGv addr
)
1166 int mem_index
= cpu_mmu_index(dc
->env
);
1168 /* If we get a fault on a delayslot we must keep the jmp state in
1169 the cpu-state to be able to re-execute the jmp. */
1170 if (dc
->delayed_branch
== 1)
1171 cris_store_direct_jmp(dc
);
1173 tcg_gen_qemu_ld64(dst
, addr
, mem_index
);
1176 static void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1177 unsigned int size
, int sign
)
1179 int mem_index
= cpu_mmu_index(dc
->env
);
1181 /* If we get a fault on a delayslot we must keep the jmp state in
1182 the cpu-state to be able to re-execute the jmp. */
1183 if (dc
->delayed_branch
== 1)
1184 cris_store_direct_jmp(dc
);
1188 tcg_gen_qemu_ld8s(dst
, addr
, mem_index
);
1190 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
1192 else if (size
== 2) {
1194 tcg_gen_qemu_ld16s(dst
, addr
, mem_index
);
1196 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
1198 else if (size
== 4) {
1199 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
1206 static void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1209 int mem_index
= cpu_mmu_index(dc
->env
);
1211 /* If we get a fault on a delayslot we must keep the jmp state in
1212 the cpu-state to be able to re-execute the jmp. */
1213 if (dc
->delayed_branch
== 1)
1214 cris_store_direct_jmp(dc
);
1217 /* Conditional writes. We only support the kind were X and P are known
1218 at translation time. */
1219 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1221 cris_evaluate_flags(dc
);
1222 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1227 tcg_gen_qemu_st8(val
, addr
, mem_index
);
1229 tcg_gen_qemu_st16(val
, addr
, mem_index
);
1231 tcg_gen_qemu_st32(val
, addr
, mem_index
);
1233 if (dc
->flagx_known
&& dc
->flags_x
) {
1234 cris_evaluate_flags(dc
);
1235 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1239 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1242 tcg_gen_ext8s_i32(d
, s
);
1244 tcg_gen_ext16s_i32(d
, s
);
1245 else if(!TCGV_EQUAL(d
, s
))
1246 tcg_gen_mov_tl(d
, s
);
1249 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1252 tcg_gen_ext8u_i32(d
, s
);
1254 tcg_gen_ext16u_i32(d
, s
);
1255 else if (!TCGV_EQUAL(d
, s
))
1256 tcg_gen_mov_tl(d
, s
);
1260 static char memsize_char(int size
)
1264 case 1: return 'b'; break;
1265 case 2: return 'w'; break;
1266 case 4: return 'd'; break;
1274 static inline unsigned int memsize_z(DisasContext
*dc
)
1276 return dc
->zsize
+ 1;
1279 static inline unsigned int memsize_zz(DisasContext
*dc
)
1290 static inline void do_postinc (DisasContext
*dc
, int size
)
1293 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1296 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1297 int size
, int s_ext
, TCGv dst
)
1300 t_gen_sext(dst
, cpu_R
[rs
], size
);
1302 t_gen_zext(dst
, cpu_R
[rs
], size
);
1305 /* Prepare T0 and T1 for a register alu operation.
1306 s_ext decides if the operand1 should be sign-extended or zero-extended when
1308 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1309 int size
, int s_ext
, TCGv dst
, TCGv src
)
1311 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, src
);
1314 t_gen_sext(dst
, cpu_R
[rd
], size
);
1316 t_gen_zext(dst
, cpu_R
[rd
], size
);
1319 static int dec_prep_move_m(DisasContext
*dc
, int s_ext
, int memsize
,
1322 unsigned int rs
, rd
;
1329 is_imm
= rs
== 15 && dc
->postinc
;
1331 /* Load [$rs] onto T1. */
1333 insn_len
= 2 + memsize
;
1340 imm
= ldsb_code(dc
->pc
+ 2);
1342 imm
= ldsw_code(dc
->pc
+ 2);
1345 imm
= ldub_code(dc
->pc
+ 2);
1347 imm
= lduw_code(dc
->pc
+ 2);
1350 imm
= ldl_code(dc
->pc
+ 2);
1352 tcg_gen_movi_tl(dst
, imm
);
1355 cris_flush_cc_state(dc
);
1356 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1358 t_gen_sext(dst
, dst
, memsize
);
1360 t_gen_zext(dst
, dst
, memsize
);
1365 /* Prepare T0 and T1 for a memory + alu operation.
1366 s_ext decides if the operand1 should be sign-extended or zero-extended when
1368 static int dec_prep_alu_m(DisasContext
*dc
, int s_ext
, int memsize
,
1373 insn_len
= dec_prep_move_m(dc
, s_ext
, memsize
, src
);
1374 tcg_gen_mov_tl(dst
, cpu_R
[dc
->op2
]);
1379 static const char *cc_name(int cc
)
1381 static const char *cc_names
[16] = {
1382 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1383 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1386 return cc_names
[cc
];
1390 /* Start of insn decoders. */
1392 static unsigned int dec_bccq(DisasContext
*dc
)
1396 uint32_t cond
= dc
->op2
;
1399 offset
= EXTRACT_FIELD (dc
->ir
, 1, 7);
1400 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1403 offset
|= sign
<< 8;
1405 offset
= sign_extend(offset
, 8);
1407 DIS(fprintf (logfile
, "b%s %x\n", cc_name(cond
), dc
->pc
+ offset
));
1409 /* op2 holds the condition-code. */
1410 cris_cc_mask(dc
, 0);
1411 cris_prepare_cc_branch (dc
, offset
, cond
);
1414 static unsigned int dec_addoq(DisasContext
*dc
)
1418 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1419 imm
= sign_extend(dc
->op1
, 7);
1421 DIS(fprintf (logfile
, "addoq %d, $r%u\n", imm
, dc
->op2
));
1422 cris_cc_mask(dc
, 0);
1423 /* Fetch register operand, */
1424 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1428 static unsigned int dec_addq(DisasContext
*dc
)
1430 DIS(fprintf (logfile
, "addq %u, $r%u\n", dc
->op1
, dc
->op2
));
1432 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1434 cris_cc_mask(dc
, CC_MASK_NZVC
);
1436 cris_alu(dc
, CC_OP_ADD
,
1437 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1440 static unsigned int dec_moveq(DisasContext
*dc
)
1444 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1445 imm
= sign_extend(dc
->op1
, 5);
1446 DIS(fprintf (logfile
, "moveq %d, $r%u\n", imm
, dc
->op2
));
1448 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tcg_const_tl(imm
));
1451 static unsigned int dec_subq(DisasContext
*dc
)
1453 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1455 DIS(fprintf (logfile
, "subq %u, $r%u\n", dc
->op1
, dc
->op2
));
1457 cris_cc_mask(dc
, CC_MASK_NZVC
);
1458 cris_alu(dc
, CC_OP_SUB
,
1459 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1462 static unsigned int dec_cmpq(DisasContext
*dc
)
1465 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1466 imm
= sign_extend(dc
->op1
, 5);
1468 DIS(fprintf (logfile
, "cmpq %d, $r%d\n", imm
, dc
->op2
));
1469 cris_cc_mask(dc
, CC_MASK_NZVC
);
1471 cris_alu(dc
, CC_OP_CMP
,
1472 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1475 static unsigned int dec_andq(DisasContext
*dc
)
1478 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1479 imm
= sign_extend(dc
->op1
, 5);
1481 DIS(fprintf (logfile
, "andq %d, $r%d\n", imm
, dc
->op2
));
1482 cris_cc_mask(dc
, CC_MASK_NZ
);
1484 cris_alu(dc
, CC_OP_AND
,
1485 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1488 static unsigned int dec_orq(DisasContext
*dc
)
1491 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1492 imm
= sign_extend(dc
->op1
, 5);
1493 DIS(fprintf (logfile
, "orq %d, $r%d\n", imm
, dc
->op2
));
1494 cris_cc_mask(dc
, CC_MASK_NZ
);
1496 cris_alu(dc
, CC_OP_OR
,
1497 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1500 static unsigned int dec_btstq(DisasContext
*dc
)
1502 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1503 DIS(fprintf (logfile
, "btstq %u, $r%d\n", dc
->op1
, dc
->op2
));
1505 cris_cc_mask(dc
, CC_MASK_NZ
);
1506 cris_evaluate_flags(dc
);
1507 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->op2
],
1508 tcg_const_tl(dc
->op1
), cpu_PR
[PR_CCS
]);
1509 cris_alu(dc
, CC_OP_MOVE
,
1510 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1511 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1512 dc
->flags_uptodate
= 1;
1515 static unsigned int dec_asrq(DisasContext
*dc
)
1517 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1518 DIS(fprintf (logfile
, "asrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1519 cris_cc_mask(dc
, CC_MASK_NZ
);
1521 tcg_gen_sari_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1522 cris_alu(dc
, CC_OP_MOVE
,
1524 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1527 static unsigned int dec_lslq(DisasContext
*dc
)
1529 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1530 DIS(fprintf (logfile
, "lslq %u, $r%d\n", dc
->op1
, dc
->op2
));
1532 cris_cc_mask(dc
, CC_MASK_NZ
);
1534 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1536 cris_alu(dc
, CC_OP_MOVE
,
1538 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1541 static unsigned int dec_lsrq(DisasContext
*dc
)
1543 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1544 DIS(fprintf (logfile
, "lsrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1546 cris_cc_mask(dc
, CC_MASK_NZ
);
1548 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1549 cris_alu(dc
, CC_OP_MOVE
,
1551 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1555 static unsigned int dec_move_r(DisasContext
*dc
)
1557 int size
= memsize_zz(dc
);
1559 DIS(fprintf (logfile
, "move.%c $r%u, $r%u\n",
1560 memsize_char(size
), dc
->op1
, dc
->op2
));
1562 cris_cc_mask(dc
, CC_MASK_NZ
);
1564 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1565 cris_cc_mask(dc
, CC_MASK_NZ
);
1566 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1567 cris_update_cc_x(dc
);
1568 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1573 t0
= tcg_temp_new();
1574 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1575 cris_alu(dc
, CC_OP_MOVE
,
1577 cpu_R
[dc
->op2
], t0
, size
);
1583 static unsigned int dec_scc_r(DisasContext
*dc
)
1587 DIS(fprintf (logfile
, "s%s $r%u\n",
1588 cc_name(cond
), dc
->op1
));
1594 gen_tst_cc (dc
, cpu_R
[dc
->op1
], cond
);
1595 l1
= gen_new_label();
1596 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->op1
], 0, l1
);
1597 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1601 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1603 cris_cc_mask(dc
, 0);
1607 static inline void cris_alu_alloc_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1610 t
[0] = cpu_R
[dc
->op2
];
1611 t
[1] = cpu_R
[dc
->op1
];
1613 t
[0] = tcg_temp_new();
1614 t
[1] = tcg_temp_new();
1618 static inline void cris_alu_free_temps(DisasContext
*dc
, int size
, TCGv
*t
)
1621 tcg_temp_free(t
[0]);
1622 tcg_temp_free(t
[1]);
1626 static unsigned int dec_and_r(DisasContext
*dc
)
1629 int size
= memsize_zz(dc
);
1631 DIS(fprintf (logfile
, "and.%c $r%u, $r%u\n",
1632 memsize_char(size
), dc
->op1
, dc
->op2
));
1634 cris_cc_mask(dc
, CC_MASK_NZ
);
1636 cris_alu_alloc_temps(dc
, size
, t
);
1637 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1638 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1639 cris_alu_free_temps(dc
, size
, t
);
1643 static unsigned int dec_lz_r(DisasContext
*dc
)
1646 DIS(fprintf (logfile
, "lz $r%u, $r%u\n",
1648 cris_cc_mask(dc
, CC_MASK_NZ
);
1649 t0
= tcg_temp_new();
1650 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_R
[dc
->op2
], t0
);
1651 cris_alu(dc
, CC_OP_LZ
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1656 static unsigned int dec_lsl_r(DisasContext
*dc
)
1659 int size
= memsize_zz(dc
);
1661 DIS(fprintf (logfile
, "lsl.%c $r%u, $r%u\n",
1662 memsize_char(size
), dc
->op1
, dc
->op2
));
1664 cris_cc_mask(dc
, CC_MASK_NZ
);
1665 cris_alu_alloc_temps(dc
, size
, t
);
1666 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1667 tcg_gen_andi_tl(t
[1], t
[1], 63);
1668 cris_alu(dc
, CC_OP_LSL
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1669 cris_alu_alloc_temps(dc
, size
, t
);
1673 static unsigned int dec_lsr_r(DisasContext
*dc
)
1676 int size
= memsize_zz(dc
);
1678 DIS(fprintf (logfile
, "lsr.%c $r%u, $r%u\n",
1679 memsize_char(size
), dc
->op1
, dc
->op2
));
1681 cris_cc_mask(dc
, CC_MASK_NZ
);
1682 cris_alu_alloc_temps(dc
, size
, t
);
1683 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1684 tcg_gen_andi_tl(t
[1], t
[1], 63);
1685 cris_alu(dc
, CC_OP_LSR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1686 cris_alu_free_temps(dc
, size
, t
);
1690 static unsigned int dec_asr_r(DisasContext
*dc
)
1693 int size
= memsize_zz(dc
);
1695 DIS(fprintf (logfile
, "asr.%c $r%u, $r%u\n",
1696 memsize_char(size
), dc
->op1
, dc
->op2
));
1698 cris_cc_mask(dc
, CC_MASK_NZ
);
1699 cris_alu_alloc_temps(dc
, size
, t
);
1700 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1701 tcg_gen_andi_tl(t
[1], t
[1], 63);
1702 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1703 cris_alu_free_temps(dc
, size
, t
);
1707 static unsigned int dec_muls_r(DisasContext
*dc
)
1710 int size
= memsize_zz(dc
);
1712 DIS(fprintf (logfile
, "muls.%c $r%u, $r%u\n",
1713 memsize_char(size
), dc
->op1
, dc
->op2
));
1714 cris_cc_mask(dc
, CC_MASK_NZV
);
1715 cris_alu_alloc_temps(dc
, size
, t
);
1716 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1, t
[0], t
[1]);
1718 cris_alu(dc
, CC_OP_MULS
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1719 cris_alu_free_temps(dc
, size
, t
);
1723 static unsigned int dec_mulu_r(DisasContext
*dc
)
1726 int size
= memsize_zz(dc
);
1728 DIS(fprintf (logfile
, "mulu.%c $r%u, $r%u\n",
1729 memsize_char(size
), dc
->op1
, dc
->op2
));
1730 cris_cc_mask(dc
, CC_MASK_NZV
);
1731 cris_alu_alloc_temps(dc
, size
, t
);
1732 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1734 cris_alu(dc
, CC_OP_MULU
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1735 cris_alu_alloc_temps(dc
, size
, t
);
1740 static unsigned int dec_dstep_r(DisasContext
*dc
)
1742 DIS(fprintf (logfile
, "dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
));
1743 cris_cc_mask(dc
, CC_MASK_NZ
);
1744 cris_alu(dc
, CC_OP_DSTEP
,
1745 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1749 static unsigned int dec_xor_r(DisasContext
*dc
)
1752 int size
= memsize_zz(dc
);
1753 DIS(fprintf (logfile
, "xor.%c $r%u, $r%u\n",
1754 memsize_char(size
), dc
->op1
, dc
->op2
));
1755 BUG_ON(size
!= 4); /* xor is dword. */
1756 cris_cc_mask(dc
, CC_MASK_NZ
);
1757 cris_alu_alloc_temps(dc
, size
, t
);
1758 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1760 cris_alu(dc
, CC_OP_XOR
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
1761 cris_alu_free_temps(dc
, size
, t
);
1765 static unsigned int dec_bound_r(DisasContext
*dc
)
1768 int size
= memsize_zz(dc
);
1769 DIS(fprintf (logfile
, "bound.%c $r%u, $r%u\n",
1770 memsize_char(size
), dc
->op1
, dc
->op2
));
1771 cris_cc_mask(dc
, CC_MASK_NZ
);
1772 l0
= tcg_temp_local_new();
1773 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, l0
);
1774 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], l0
, 4);
1779 static unsigned int dec_cmp_r(DisasContext
*dc
)
1782 int size
= memsize_zz(dc
);
1783 DIS(fprintf (logfile
, "cmp.%c $r%u, $r%u\n",
1784 memsize_char(size
), dc
->op1
, dc
->op2
));
1785 cris_cc_mask(dc
, CC_MASK_NZVC
);
1786 cris_alu_alloc_temps(dc
, size
, t
);
1787 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1789 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1790 cris_alu_free_temps(dc
, size
, t
);
1794 static unsigned int dec_abs_r(DisasContext
*dc
)
1798 DIS(fprintf (logfile
, "abs $r%u, $r%u\n",
1800 cris_cc_mask(dc
, CC_MASK_NZ
);
1802 t0
= tcg_temp_new();
1803 tcg_gen_sari_tl(t0
, cpu_R
[dc
->op1
], 31);
1804 tcg_gen_xor_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
);
1805 tcg_gen_sub_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
);
1808 cris_alu(dc
, CC_OP_MOVE
,
1809 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1813 static unsigned int dec_add_r(DisasContext
*dc
)
1816 int size
= memsize_zz(dc
);
1817 DIS(fprintf (logfile
, "add.%c $r%u, $r%u\n",
1818 memsize_char(size
), dc
->op1
, dc
->op2
));
1819 cris_cc_mask(dc
, CC_MASK_NZVC
);
1820 cris_alu_alloc_temps(dc
, size
, t
);
1821 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1823 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1824 cris_alu_free_temps(dc
, size
, t
);
1828 static unsigned int dec_addc_r(DisasContext
*dc
)
1830 DIS(fprintf (logfile
, "addc $r%u, $r%u\n",
1832 cris_evaluate_flags(dc
);
1833 /* Set for this insn. */
1834 dc
->flagx_known
= 1;
1835 dc
->flags_x
= X_FLAG
;
1837 cris_cc_mask(dc
, CC_MASK_NZVC
);
1838 cris_alu(dc
, CC_OP_ADDC
,
1839 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1843 static unsigned int dec_mcp_r(DisasContext
*dc
)
1845 DIS(fprintf (logfile
, "mcp $p%u, $r%u\n",
1847 cris_evaluate_flags(dc
);
1848 cris_cc_mask(dc
, CC_MASK_RNZV
);
1849 cris_alu(dc
, CC_OP_MCP
,
1850 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1855 static char * swapmode_name(int mode
, char *modename
) {
1858 modename
[i
++] = 'n';
1860 modename
[i
++] = 'w';
1862 modename
[i
++] = 'b';
1864 modename
[i
++] = 'r';
1870 static unsigned int dec_swap_r(DisasContext
*dc
)
1876 DIS(fprintf (logfile
, "swap%s $r%u\n",
1877 swapmode_name(dc
->op2
, modename
), dc
->op1
));
1879 cris_cc_mask(dc
, CC_MASK_NZ
);
1880 t0
= tcg_temp_new();
1881 t_gen_mov_TN_reg(t0
, dc
->op1
);
1883 tcg_gen_not_tl(t0
, t0
);
1885 t_gen_swapw(t0
, t0
);
1887 t_gen_swapb(t0
, t0
);
1889 t_gen_swapr(t0
, t0
);
1890 cris_alu(dc
, CC_OP_MOVE
,
1891 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, 4);
1896 static unsigned int dec_or_r(DisasContext
*dc
)
1899 int size
= memsize_zz(dc
);
1900 DIS(fprintf (logfile
, "or.%c $r%u, $r%u\n",
1901 memsize_char(size
), dc
->op1
, dc
->op2
));
1902 cris_cc_mask(dc
, CC_MASK_NZ
);
1903 cris_alu_alloc_temps(dc
, size
, t
);
1904 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1905 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1906 cris_alu_free_temps(dc
, size
, t
);
1910 static unsigned int dec_addi_r(DisasContext
*dc
)
1913 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u\n",
1914 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1915 cris_cc_mask(dc
, 0);
1916 t0
= tcg_temp_new();
1917 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1918 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
);
1923 static unsigned int dec_addi_acr(DisasContext
*dc
)
1926 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u, $acr\n",
1927 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1928 cris_cc_mask(dc
, 0);
1929 t0
= tcg_temp_new();
1930 tcg_gen_shl_tl(t0
, cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1931 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], t0
);
1936 static unsigned int dec_neg_r(DisasContext
*dc
)
1939 int size
= memsize_zz(dc
);
1940 DIS(fprintf (logfile
, "neg.%c $r%u, $r%u\n",
1941 memsize_char(size
), dc
->op1
, dc
->op2
));
1942 cris_cc_mask(dc
, CC_MASK_NZVC
);
1943 cris_alu_alloc_temps(dc
, size
, t
);
1944 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1946 cris_alu(dc
, CC_OP_NEG
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1947 cris_alu_free_temps(dc
, size
, t
);
1951 static unsigned int dec_btst_r(DisasContext
*dc
)
1953 DIS(fprintf (logfile
, "btst $r%u, $r%u\n",
1955 cris_cc_mask(dc
, CC_MASK_NZ
);
1956 cris_evaluate_flags(dc
);
1957 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->op2
],
1958 cpu_R
[dc
->op1
], cpu_PR
[PR_CCS
]);
1959 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
],
1960 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1961 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1962 dc
->flags_uptodate
= 1;
1966 static unsigned int dec_sub_r(DisasContext
*dc
)
1969 int size
= memsize_zz(dc
);
1970 DIS(fprintf (logfile
, "sub.%c $r%u, $r%u\n",
1971 memsize_char(size
), dc
->op1
, dc
->op2
));
1972 cris_cc_mask(dc
, CC_MASK_NZVC
);
1973 cris_alu_alloc_temps(dc
, size
, t
);
1974 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t
[0], t
[1]);
1975 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], size
);
1976 cris_alu_free_temps(dc
, size
, t
);
1980 /* Zero extension. From size to dword. */
1981 static unsigned int dec_movu_r(DisasContext
*dc
)
1984 int size
= memsize_z(dc
);
1985 DIS(fprintf (logfile
, "movu.%c $r%u, $r%u\n",
1989 cris_cc_mask(dc
, CC_MASK_NZ
);
1990 t0
= tcg_temp_new();
1991 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, t0
);
1992 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
1997 /* Sign extension. From size to dword. */
1998 static unsigned int dec_movs_r(DisasContext
*dc
)
2001 int size
= memsize_z(dc
);
2002 DIS(fprintf (logfile
, "movs.%c $r%u, $r%u\n",
2006 cris_cc_mask(dc
, CC_MASK_NZ
);
2007 t0
= tcg_temp_new();
2008 /* Size can only be qi or hi. */
2009 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2010 cris_alu(dc
, CC_OP_MOVE
,
2011 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], t0
, 4);
2016 /* zero extension. From size to dword. */
2017 static unsigned int dec_addu_r(DisasContext
*dc
)
2020 int size
= memsize_z(dc
);
2021 DIS(fprintf (logfile
, "addu.%c $r%u, $r%u\n",
2025 cris_cc_mask(dc
, CC_MASK_NZVC
);
2026 t0
= tcg_temp_new();
2027 /* Size can only be qi or hi. */
2028 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
2029 cris_alu(dc
, CC_OP_ADD
,
2030 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2035 /* Sign extension. From size to dword. */
2036 static unsigned int dec_adds_r(DisasContext
*dc
)
2039 int size
= memsize_z(dc
);
2040 DIS(fprintf (logfile
, "adds.%c $r%u, $r%u\n",
2044 cris_cc_mask(dc
, CC_MASK_NZVC
);
2045 t0
= tcg_temp_new();
2046 /* Size can only be qi or hi. */
2047 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2048 cris_alu(dc
, CC_OP_ADD
,
2049 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2054 /* Zero extension. From size to dword. */
2055 static unsigned int dec_subu_r(DisasContext
*dc
)
2058 int size
= memsize_z(dc
);
2059 DIS(fprintf (logfile
, "subu.%c $r%u, $r%u\n",
2063 cris_cc_mask(dc
, CC_MASK_NZVC
);
2064 t0
= tcg_temp_new();
2065 /* Size can only be qi or hi. */
2066 t_gen_zext(t0
, cpu_R
[dc
->op1
], size
);
2067 cris_alu(dc
, CC_OP_SUB
,
2068 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2073 /* Sign extension. From size to dword. */
2074 static unsigned int dec_subs_r(DisasContext
*dc
)
2077 int size
= memsize_z(dc
);
2078 DIS(fprintf (logfile
, "subs.%c $r%u, $r%u\n",
2082 cris_cc_mask(dc
, CC_MASK_NZVC
);
2083 t0
= tcg_temp_new();
2084 /* Size can only be qi or hi. */
2085 t_gen_sext(t0
, cpu_R
[dc
->op1
], size
);
2086 cris_alu(dc
, CC_OP_SUB
,
2087 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, 4);
2092 static unsigned int dec_setclrf(DisasContext
*dc
)
2095 int set
= (~dc
->opcode
>> 2) & 1;
2098 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2099 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2100 if (set
&& flags
== 0) {
2101 DIS(fprintf (logfile
, "nop\n"));
2103 } else if (!set
&& (flags
& 0x20)) {
2104 DIS(fprintf (logfile
, "di\n"));
2107 DIS(fprintf (logfile
, "%sf %x\n",
2108 set
? "set" : "clr",
2112 /* User space is not allowed to touch these. Silently ignore. */
2113 if (dc
->tb_flags
& U_FLAG
) {
2114 flags
&= ~(S_FLAG
| I_FLAG
| U_FLAG
);
2117 if (flags
& X_FLAG
) {
2118 dc
->flagx_known
= 1;
2120 dc
->flags_x
= X_FLAG
;
2125 /* Break the TB if the P flag changes. */
2126 if (flags
& P_FLAG
) {
2127 if ((set
&& !(dc
->tb_flags
& P_FLAG
))
2128 || (!set
&& (dc
->tb_flags
& P_FLAG
))) {
2129 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2130 dc
->is_jmp
= DISAS_UPDATE
;
2131 dc
->cpustate_changed
= 1;
2134 if (flags
& S_FLAG
) {
2135 dc
->cpustate_changed
= 1;
2139 /* Simply decode the flags. */
2140 cris_evaluate_flags (dc
);
2141 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2142 cris_update_cc_x(dc
);
2143 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2146 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2147 /* Enter user mode. */
2148 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2149 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2150 dc
->cpustate_changed
= 1;
2152 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2155 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2157 dc
->flags_uptodate
= 1;
2162 static unsigned int dec_move_rs(DisasContext
*dc
)
2164 DIS(fprintf (logfile
, "move $r%u, $s%u\n", dc
->op1
, dc
->op2
));
2165 cris_cc_mask(dc
, 0);
2166 gen_helper_movl_sreg_reg(tcg_const_tl(dc
->op2
), tcg_const_tl(dc
->op1
));
2169 static unsigned int dec_move_sr(DisasContext
*dc
)
2171 DIS(fprintf (logfile
, "move $s%u, $r%u\n", dc
->op2
, dc
->op1
));
2172 cris_cc_mask(dc
, 0);
2173 gen_helper_movl_reg_sreg(tcg_const_tl(dc
->op1
), tcg_const_tl(dc
->op2
));
2177 static unsigned int dec_move_rp(DisasContext
*dc
)
2180 DIS(fprintf (logfile
, "move $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2181 cris_cc_mask(dc
, 0);
2183 t
[0] = tcg_temp_new();
2184 if (dc
->op2
== PR_CCS
) {
2185 cris_evaluate_flags(dc
);
2186 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2187 if (dc
->tb_flags
& U_FLAG
) {
2188 t
[1] = tcg_temp_new();
2189 /* User space is not allowed to touch all flags. */
2190 tcg_gen_andi_tl(t
[0], t
[0], 0x39f);
2191 tcg_gen_andi_tl(t
[1], cpu_PR
[PR_CCS
], ~0x39f);
2192 tcg_gen_or_tl(t
[0], t
[1], t
[0]);
2193 tcg_temp_free(t
[1]);
2197 t_gen_mov_TN_reg(t
[0], dc
->op1
);
2199 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[0]);
2200 if (dc
->op2
== PR_CCS
) {
2201 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2202 dc
->flags_uptodate
= 1;
2204 tcg_temp_free(t
[0]);
2207 static unsigned int dec_move_pr(DisasContext
*dc
)
2210 DIS(fprintf (logfile
, "move $p%u, $r%u\n", dc
->op1
, dc
->op2
));
2211 cris_cc_mask(dc
, 0);
2213 if (dc
->op2
== PR_CCS
)
2214 cris_evaluate_flags(dc
);
2216 t0
= tcg_temp_new();
2217 t_gen_mov_TN_preg(t0
, dc
->op2
);
2218 cris_alu(dc
, CC_OP_MOVE
,
2219 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], t0
, preg_sizes
[dc
->op2
]);
2224 static unsigned int dec_move_mr(DisasContext
*dc
)
2226 int memsize
= memsize_zz(dc
);
2228 DIS(fprintf (logfile
, "move.%c [$r%u%s, $r%u\n",
2229 memsize_char(memsize
),
2230 dc
->op1
, dc
->postinc
? "+]" : "]",
2234 insn_len
= dec_prep_move_m(dc
, 0, 4, cpu_R
[dc
->op2
]);
2235 cris_cc_mask(dc
, CC_MASK_NZ
);
2236 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2237 cris_update_cc_x(dc
);
2238 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2243 t0
= tcg_temp_new();
2244 insn_len
= dec_prep_move_m(dc
, 0, memsize
, t0
);
2245 cris_cc_mask(dc
, CC_MASK_NZ
);
2246 cris_alu(dc
, CC_OP_MOVE
,
2247 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t0
, memsize
);
2250 do_postinc(dc
, memsize
);
2254 static inline void cris_alu_m_alloc_temps(TCGv
*t
)
2256 t
[0] = tcg_temp_new();
2257 t
[1] = tcg_temp_new();
2260 static inline void cris_alu_m_free_temps(TCGv
*t
)
2262 tcg_temp_free(t
[0]);
2263 tcg_temp_free(t
[1]);
2266 static unsigned int dec_movs_m(DisasContext
*dc
)
2269 int memsize
= memsize_z(dc
);
2271 DIS(fprintf (logfile
, "movs.%c [$r%u%s, $r%u\n",
2272 memsize_char(memsize
),
2273 dc
->op1
, dc
->postinc
? "+]" : "]",
2276 cris_alu_m_alloc_temps(t
);
2278 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2279 cris_cc_mask(dc
, CC_MASK_NZ
);
2280 cris_alu(dc
, CC_OP_MOVE
,
2281 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2282 do_postinc(dc
, memsize
);
2283 cris_alu_m_free_temps(t
);
2287 static unsigned int dec_addu_m(DisasContext
*dc
)
2290 int memsize
= memsize_z(dc
);
2292 DIS(fprintf (logfile
, "addu.%c [$r%u%s, $r%u\n",
2293 memsize_char(memsize
),
2294 dc
->op1
, dc
->postinc
? "+]" : "]",
2297 cris_alu_m_alloc_temps(t
);
2299 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2300 cris_cc_mask(dc
, CC_MASK_NZVC
);
2301 cris_alu(dc
, CC_OP_ADD
,
2302 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2303 do_postinc(dc
, memsize
);
2304 cris_alu_m_free_temps(t
);
2308 static unsigned int dec_adds_m(DisasContext
*dc
)
2311 int memsize
= memsize_z(dc
);
2313 DIS(fprintf (logfile
, "adds.%c [$r%u%s, $r%u\n",
2314 memsize_char(memsize
),
2315 dc
->op1
, dc
->postinc
? "+]" : "]",
2318 cris_alu_m_alloc_temps(t
);
2320 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2321 cris_cc_mask(dc
, CC_MASK_NZVC
);
2322 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2323 do_postinc(dc
, memsize
);
2324 cris_alu_m_free_temps(t
);
2328 static unsigned int dec_subu_m(DisasContext
*dc
)
2331 int memsize
= memsize_z(dc
);
2333 DIS(fprintf (logfile
, "subu.%c [$r%u%s, $r%u\n",
2334 memsize_char(memsize
),
2335 dc
->op1
, dc
->postinc
? "+]" : "]",
2338 cris_alu_m_alloc_temps(t
);
2340 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2341 cris_cc_mask(dc
, CC_MASK_NZVC
);
2342 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2343 do_postinc(dc
, memsize
);
2344 cris_alu_m_free_temps(t
);
2348 static unsigned int dec_subs_m(DisasContext
*dc
)
2351 int memsize
= memsize_z(dc
);
2353 DIS(fprintf (logfile
, "subs.%c [$r%u%s, $r%u\n",
2354 memsize_char(memsize
),
2355 dc
->op1
, dc
->postinc
? "+]" : "]",
2358 cris_alu_m_alloc_temps(t
);
2360 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2361 cris_cc_mask(dc
, CC_MASK_NZVC
);
2362 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2363 do_postinc(dc
, memsize
);
2364 cris_alu_m_free_temps(t
);
2368 static unsigned int dec_movu_m(DisasContext
*dc
)
2371 int memsize
= memsize_z(dc
);
2374 DIS(fprintf (logfile
, "movu.%c [$r%u%s, $r%u\n",
2375 memsize_char(memsize
),
2376 dc
->op1
, dc
->postinc
? "+]" : "]",
2379 cris_alu_m_alloc_temps(t
);
2380 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2381 cris_cc_mask(dc
, CC_MASK_NZ
);
2382 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2383 do_postinc(dc
, memsize
);
2384 cris_alu_m_free_temps(t
);
2388 static unsigned int dec_cmpu_m(DisasContext
*dc
)
2391 int memsize
= memsize_z(dc
);
2393 DIS(fprintf (logfile
, "cmpu.%c [$r%u%s, $r%u\n",
2394 memsize_char(memsize
),
2395 dc
->op1
, dc
->postinc
? "+]" : "]",
2398 cris_alu_m_alloc_temps(t
);
2399 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2400 cris_cc_mask(dc
, CC_MASK_NZVC
);
2401 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1], 4);
2402 do_postinc(dc
, memsize
);
2403 cris_alu_m_free_temps(t
);
2407 static unsigned int dec_cmps_m(DisasContext
*dc
)
2410 int memsize
= memsize_z(dc
);
2412 DIS(fprintf (logfile
, "cmps.%c [$r%u%s, $r%u\n",
2413 memsize_char(memsize
),
2414 dc
->op1
, dc
->postinc
? "+]" : "]",
2417 cris_alu_m_alloc_temps(t
);
2418 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2419 cris_cc_mask(dc
, CC_MASK_NZVC
);
2420 cris_alu(dc
, CC_OP_CMP
,
2421 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2423 do_postinc(dc
, memsize
);
2424 cris_alu_m_free_temps(t
);
2428 static unsigned int dec_cmp_m(DisasContext
*dc
)
2431 int memsize
= memsize_zz(dc
);
2433 DIS(fprintf (logfile
, "cmp.%c [$r%u%s, $r%u\n",
2434 memsize_char(memsize
),
2435 dc
->op1
, dc
->postinc
? "+]" : "]",
2438 cris_alu_m_alloc_temps(t
);
2439 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2440 cris_cc_mask(dc
, CC_MASK_NZVC
);
2441 cris_alu(dc
, CC_OP_CMP
,
2442 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], t
[1],
2444 do_postinc(dc
, memsize
);
2445 cris_alu_m_free_temps(t
);
2449 static unsigned int dec_test_m(DisasContext
*dc
)
2452 int memsize
= memsize_zz(dc
);
2454 DIS(fprintf (logfile
, "test.%d [$r%u%s] op2=%x\n",
2455 memsize_char(memsize
),
2456 dc
->op1
, dc
->postinc
? "+]" : "]",
2459 cris_evaluate_flags(dc
);
2461 cris_alu_m_alloc_temps(t
);
2462 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2463 cris_cc_mask(dc
, CC_MASK_NZ
);
2464 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2466 cris_alu(dc
, CC_OP_CMP
,
2467 cpu_R
[dc
->op2
], t
[1], tcg_const_tl(0), memsize_zz(dc
));
2468 do_postinc(dc
, memsize
);
2469 cris_alu_m_free_temps(t
);
2473 static unsigned int dec_and_m(DisasContext
*dc
)
2476 int memsize
= memsize_zz(dc
);
2478 DIS(fprintf (logfile
, "and.%d [$r%u%s, $r%u\n",
2479 memsize_char(memsize
),
2480 dc
->op1
, dc
->postinc
? "+]" : "]",
2483 cris_alu_m_alloc_temps(t
);
2484 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2485 cris_cc_mask(dc
, CC_MASK_NZ
);
2486 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2487 do_postinc(dc
, memsize
);
2488 cris_alu_m_free_temps(t
);
2492 static unsigned int dec_add_m(DisasContext
*dc
)
2495 int memsize
= memsize_zz(dc
);
2497 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2498 memsize_char(memsize
),
2499 dc
->op1
, dc
->postinc
? "+]" : "]",
2502 cris_alu_m_alloc_temps(t
);
2503 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2504 cris_cc_mask(dc
, CC_MASK_NZVC
);
2505 cris_alu(dc
, CC_OP_ADD
,
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 unsigned int dec_addo_m(DisasContext
*dc
)
2515 int memsize
= memsize_zz(dc
);
2517 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2518 memsize_char(memsize
),
2519 dc
->op1
, dc
->postinc
? "+]" : "]",
2522 cris_alu_m_alloc_temps(t
);
2523 insn_len
= dec_prep_alu_m(dc
, 1, memsize
, t
[0], t
[1]);
2524 cris_cc_mask(dc
, 0);
2525 cris_alu(dc
, CC_OP_ADD
, cpu_R
[R_ACR
], t
[0], t
[1], 4);
2526 do_postinc(dc
, memsize
);
2527 cris_alu_m_free_temps(t
);
2531 static unsigned int dec_bound_m(DisasContext
*dc
)
2534 int memsize
= memsize_zz(dc
);
2536 DIS(fprintf (logfile
, "bound.%d [$r%u%s, $r%u\n",
2537 memsize_char(memsize
),
2538 dc
->op1
, dc
->postinc
? "+]" : "]",
2541 l
[0] = tcg_temp_local_new();
2542 l
[1] = tcg_temp_local_new();
2543 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, l
[0], l
[1]);
2544 cris_cc_mask(dc
, CC_MASK_NZ
);
2545 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->op2
], l
[0], l
[1], 4);
2546 do_postinc(dc
, memsize
);
2547 tcg_temp_free(l
[0]);
2548 tcg_temp_free(l
[1]);
2552 static unsigned int dec_addc_mr(DisasContext
*dc
)
2556 DIS(fprintf (logfile
, "addc [$r%u%s, $r%u\n",
2557 dc
->op1
, dc
->postinc
? "+]" : "]",
2560 cris_evaluate_flags(dc
);
2562 /* Set for this insn. */
2563 dc
->flagx_known
= 1;
2564 dc
->flags_x
= X_FLAG
;
2566 cris_alu_m_alloc_temps(t
);
2567 insn_len
= dec_prep_alu_m(dc
, 0, 4, t
[0], t
[1]);
2568 cris_cc_mask(dc
, CC_MASK_NZVC
);
2569 cris_alu(dc
, CC_OP_ADDC
, cpu_R
[dc
->op2
], t
[0], t
[1], 4);
2571 cris_alu_m_free_temps(t
);
2575 static unsigned int dec_sub_m(DisasContext
*dc
)
2578 int memsize
= memsize_zz(dc
);
2580 DIS(fprintf (logfile
, "sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2581 memsize_char(memsize
),
2582 dc
->op1
, dc
->postinc
? "+]" : "]",
2583 dc
->op2
, dc
->ir
, dc
->zzsize
));
2585 cris_alu_m_alloc_temps(t
);
2586 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2587 cris_cc_mask(dc
, CC_MASK_NZVC
);
2588 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->op2
], t
[0], t
[1], memsize
);
2589 do_postinc(dc
, memsize
);
2590 cris_alu_m_free_temps(t
);
2594 static unsigned int dec_or_m(DisasContext
*dc
)
2597 int memsize
= memsize_zz(dc
);
2599 DIS(fprintf (logfile
, "or.%d [$r%u%s, $r%u pc=%x\n",
2600 memsize_char(memsize
),
2601 dc
->op1
, dc
->postinc
? "+]" : "]",
2604 cris_alu_m_alloc_temps(t
);
2605 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2606 cris_cc_mask(dc
, CC_MASK_NZ
);
2607 cris_alu(dc
, CC_OP_OR
,
2608 cpu_R
[dc
->op2
], t
[0], t
[1], memsize_zz(dc
));
2609 do_postinc(dc
, memsize
);
2610 cris_alu_m_free_temps(t
);
2614 static unsigned int dec_move_mp(DisasContext
*dc
)
2617 int memsize
= memsize_zz(dc
);
2620 DIS(fprintf (logfile
, "move.%c [$r%u%s, $p%u\n",
2621 memsize_char(memsize
),
2623 dc
->postinc
? "+]" : "]",
2626 cris_alu_m_alloc_temps(t
);
2627 insn_len
= dec_prep_alu_m(dc
, 0, memsize
, t
[0], t
[1]);
2628 cris_cc_mask(dc
, 0);
2629 if (dc
->op2
== PR_CCS
) {
2630 cris_evaluate_flags(dc
);
2631 if (dc
->tb_flags
& U_FLAG
) {
2632 /* User space is not allowed to touch all flags. */
2633 tcg_gen_andi_tl(t
[1], t
[1], 0x39f);
2634 tcg_gen_andi_tl(t
[0], cpu_PR
[PR_CCS
], ~0x39f);
2635 tcg_gen_or_tl(t
[1], t
[0], t
[1]);
2639 t_gen_mov_preg_TN(dc
, dc
->op2
, t
[1]);
2641 do_postinc(dc
, memsize
);
2642 cris_alu_m_free_temps(t
);
2646 static unsigned int dec_move_pm(DisasContext
*dc
)
2651 memsize
= preg_sizes
[dc
->op2
];
2653 DIS(fprintf (logfile
, "move.%c $p%u, [$r%u%s\n",
2654 memsize_char(memsize
),
2655 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]"));
2657 /* prepare store. Address in T0, value in T1. */
2658 if (dc
->op2
== PR_CCS
)
2659 cris_evaluate_flags(dc
);
2660 t0
= tcg_temp_new();
2661 t_gen_mov_TN_preg(t0
, dc
->op2
);
2662 cris_flush_cc_state(dc
);
2663 gen_store(dc
, cpu_R
[dc
->op1
], t0
, memsize
);
2666 cris_cc_mask(dc
, 0);
2668 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2672 static unsigned int dec_movem_mr(DisasContext
*dc
)
2678 int nr
= dc
->op2
+ 1;
2680 DIS(fprintf (logfile
, "movem [$r%u%s, $r%u\n", dc
->op1
,
2681 dc
->postinc
? "+]" : "]", dc
->op2
));
2683 addr
= tcg_temp_new();
2684 /* There are probably better ways of doing this. */
2685 cris_flush_cc_state(dc
);
2686 for (i
= 0; i
< (nr
>> 1); i
++) {
2687 tmp
[i
] = tcg_temp_new_i64();
2688 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2689 gen_load64(dc
, tmp
[i
], addr
);
2692 tmp32
= tcg_temp_new_i32();
2693 tcg_gen_addi_tl(addr
, cpu_R
[dc
->op1
], i
* 8);
2694 gen_load(dc
, tmp32
, addr
, 4, 0);
2696 tcg_temp_free(addr
);
2698 for (i
= 0; i
< (nr
>> 1); i
++) {
2699 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2], tmp
[i
]);
2700 tcg_gen_shri_i64(tmp
[i
], tmp
[i
], 32);
2701 tcg_gen_trunc_i64_i32(cpu_R
[i
* 2 + 1], tmp
[i
]);
2702 tcg_temp_free_i64(tmp
[i
]);
2705 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tmp32
);
2706 tcg_temp_free(tmp32
);
2709 /* writeback the updated pointer value. */
2711 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], nr
* 4);
2713 /* gen_load might want to evaluate the previous insns flags. */
2714 cris_cc_mask(dc
, 0);
2718 static unsigned int dec_movem_rm(DisasContext
*dc
)
2724 DIS(fprintf (logfile
, "movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2725 dc
->postinc
? "+]" : "]"));
2727 cris_flush_cc_state(dc
);
2729 tmp
= tcg_temp_new();
2730 addr
= tcg_temp_new();
2731 tcg_gen_movi_tl(tmp
, 4);
2732 tcg_gen_mov_tl(addr
, cpu_R
[dc
->op1
]);
2733 for (i
= 0; i
<= dc
->op2
; i
++) {
2734 /* Displace addr. */
2735 /* Perform the store. */
2736 gen_store(dc
, addr
, cpu_R
[i
], 4);
2737 tcg_gen_add_tl(addr
, addr
, tmp
);
2740 tcg_gen_mov_tl(cpu_R
[dc
->op1
], addr
);
2741 cris_cc_mask(dc
, 0);
2743 tcg_temp_free(addr
);
2747 static unsigned int dec_move_rm(DisasContext
*dc
)
2751 memsize
= memsize_zz(dc
);
2753 DIS(fprintf (logfile
, "move.%d $r%u, [$r%u]\n",
2754 memsize
, dc
->op2
, dc
->op1
));
2756 /* prepare store. */
2757 cris_flush_cc_state(dc
);
2758 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2761 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2762 cris_cc_mask(dc
, 0);
2766 static unsigned int dec_lapcq(DisasContext
*dc
)
2768 DIS(fprintf (logfile
, "lapcq %x, $r%u\n",
2769 dc
->pc
+ dc
->op1
*2, dc
->op2
));
2770 cris_cc_mask(dc
, 0);
2771 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2775 static unsigned int dec_lapc_im(DisasContext
*dc
)
2783 cris_cc_mask(dc
, 0);
2784 imm
= ldl_code(dc
->pc
+ 2);
2785 DIS(fprintf (logfile
, "lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
));
2789 t_gen_mov_reg_TN(rd
, tcg_const_tl(pc
));
2793 /* Jump to special reg. */
2794 static unsigned int dec_jump_p(DisasContext
*dc
)
2796 DIS(fprintf (logfile
, "jump $p%u\n", dc
->op2
));
2798 if (dc
->op2
== PR_CCS
)
2799 cris_evaluate_flags(dc
);
2800 t_gen_mov_TN_preg(env_btarget
, dc
->op2
);
2801 /* rete will often have low bit set to indicate delayslot. */
2802 tcg_gen_andi_tl(env_btarget
, env_btarget
, ~1);
2803 cris_cc_mask(dc
, 0);
2804 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2808 /* Jump and save. */
2809 static unsigned int dec_jas_r(DisasContext
*dc
)
2811 DIS(fprintf (logfile
, "jas $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2812 cris_cc_mask(dc
, 0);
2813 /* Store the return address in Pd. */
2814 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2817 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2819 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2823 static unsigned int dec_jas_im(DisasContext
*dc
)
2827 imm
= ldl_code(dc
->pc
+ 2);
2829 DIS(fprintf (logfile
, "jas 0x%x\n", imm
));
2830 cris_cc_mask(dc
, 0);
2831 /* Store the return address in Pd. */
2832 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2835 cris_prepare_jmp(dc
, JMP_DIRECT
);
2839 static unsigned int dec_jasc_im(DisasContext
*dc
)
2843 imm
= ldl_code(dc
->pc
+ 2);
2845 DIS(fprintf (logfile
, "jasc 0x%x\n", imm
));
2846 cris_cc_mask(dc
, 0);
2847 /* Store the return address in Pd. */
2848 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2851 cris_prepare_jmp(dc
, JMP_DIRECT
);
2855 static unsigned int dec_jasc_r(DisasContext
*dc
)
2857 DIS(fprintf (logfile
, "jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2858 cris_cc_mask(dc
, 0);
2859 /* Store the return address in Pd. */
2860 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2861 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2862 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2866 static unsigned int dec_bcc_im(DisasContext
*dc
)
2869 uint32_t cond
= dc
->op2
;
2871 offset
= ldsw_code(dc
->pc
+ 2);
2873 DIS(fprintf (logfile
, "b%s %d pc=%x dst=%x\n",
2874 cc_name(cond
), offset
,
2875 dc
->pc
, dc
->pc
+ offset
));
2877 cris_cc_mask(dc
, 0);
2878 /* op2 holds the condition-code. */
2879 cris_prepare_cc_branch (dc
, offset
, cond
);
2883 static unsigned int dec_bas_im(DisasContext
*dc
)
2888 simm
= ldl_code(dc
->pc
+ 2);
2890 DIS(fprintf (logfile
, "bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2891 cris_cc_mask(dc
, 0);
2892 /* Store the return address in Pd. */
2893 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2895 dc
->jmp_pc
= dc
->pc
+ simm
;
2896 cris_prepare_jmp(dc
, JMP_DIRECT
);
2900 static unsigned int dec_basc_im(DisasContext
*dc
)
2903 simm
= ldl_code(dc
->pc
+ 2);
2905 DIS(fprintf (logfile
, "basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2906 cris_cc_mask(dc
, 0);
2907 /* Store the return address in Pd. */
2908 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2910 dc
->jmp_pc
= dc
->pc
+ simm
;
2911 cris_prepare_jmp(dc
, JMP_DIRECT
);
2915 static unsigned int dec_rfe_etc(DisasContext
*dc
)
2917 cris_cc_mask(dc
, 0);
2919 if (dc
->op2
== 15) {
2920 t_gen_mov_env_TN(halted
, tcg_const_tl(1));
2921 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2922 t_gen_raise_exception(EXCP_HLT
);
2926 switch (dc
->op2
& 7) {
2929 DIS(fprintf(logfile
, "rfe\n"));
2930 cris_evaluate_flags(dc
);
2932 dc
->is_jmp
= DISAS_UPDATE
;
2936 DIS(fprintf(logfile
, "rfn\n"));
2937 cris_evaluate_flags(dc
);
2939 dc
->is_jmp
= DISAS_UPDATE
;
2942 DIS(fprintf(logfile
, "break %d\n", dc
->op1
));
2943 cris_evaluate_flags (dc
);
2945 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2947 /* Breaks start at 16 in the exception vector. */
2948 t_gen_mov_env_TN(trap_vector
,
2949 tcg_const_tl(dc
->op1
+ 16));
2950 t_gen_raise_exception(EXCP_BREAK
);
2951 dc
->is_jmp
= DISAS_UPDATE
;
2954 printf ("op2=%x\n", dc
->op2
);
2962 static unsigned int dec_ftag_fidx_d_m(DisasContext
*dc
)
2967 static unsigned int dec_ftag_fidx_i_m(DisasContext
*dc
)
2972 static unsigned int dec_null(DisasContext
*dc
)
2974 printf ("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2975 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2981 static struct decoder_info
{
2986 unsigned int (*dec
)(DisasContext
*dc
);
2988 /* Order matters here. */
2989 {DEC_MOVEQ
, dec_moveq
},
2990 {DEC_BTSTQ
, dec_btstq
},
2991 {DEC_CMPQ
, dec_cmpq
},
2992 {DEC_ADDOQ
, dec_addoq
},
2993 {DEC_ADDQ
, dec_addq
},
2994 {DEC_SUBQ
, dec_subq
},
2995 {DEC_ANDQ
, dec_andq
},
2997 {DEC_ASRQ
, dec_asrq
},
2998 {DEC_LSLQ
, dec_lslq
},
2999 {DEC_LSRQ
, dec_lsrq
},
3000 {DEC_BCCQ
, dec_bccq
},
3002 {DEC_BCC_IM
, dec_bcc_im
},
3003 {DEC_JAS_IM
, dec_jas_im
},
3004 {DEC_JAS_R
, dec_jas_r
},
3005 {DEC_JASC_IM
, dec_jasc_im
},
3006 {DEC_JASC_R
, dec_jasc_r
},
3007 {DEC_BAS_IM
, dec_bas_im
},
3008 {DEC_BASC_IM
, dec_basc_im
},
3009 {DEC_JUMP_P
, dec_jump_p
},
3010 {DEC_LAPC_IM
, dec_lapc_im
},
3011 {DEC_LAPCQ
, dec_lapcq
},
3013 {DEC_RFE_ETC
, dec_rfe_etc
},
3014 {DEC_ADDC_MR
, dec_addc_mr
},
3016 {DEC_MOVE_MP
, dec_move_mp
},
3017 {DEC_MOVE_PM
, dec_move_pm
},
3018 {DEC_MOVEM_MR
, dec_movem_mr
},
3019 {DEC_MOVEM_RM
, dec_movem_rm
},
3020 {DEC_MOVE_PR
, dec_move_pr
},
3021 {DEC_SCC_R
, dec_scc_r
},
3022 {DEC_SETF
, dec_setclrf
},
3023 {DEC_CLEARF
, dec_setclrf
},
3025 {DEC_MOVE_SR
, dec_move_sr
},
3026 {DEC_MOVE_RP
, dec_move_rp
},
3027 {DEC_SWAP_R
, dec_swap_r
},
3028 {DEC_ABS_R
, dec_abs_r
},
3029 {DEC_LZ_R
, dec_lz_r
},
3030 {DEC_MOVE_RS
, dec_move_rs
},
3031 {DEC_BTST_R
, dec_btst_r
},
3032 {DEC_ADDC_R
, dec_addc_r
},
3034 {DEC_DSTEP_R
, dec_dstep_r
},
3035 {DEC_XOR_R
, dec_xor_r
},
3036 {DEC_MCP_R
, dec_mcp_r
},
3037 {DEC_CMP_R
, dec_cmp_r
},
3039 {DEC_ADDI_R
, dec_addi_r
},
3040 {DEC_ADDI_ACR
, dec_addi_acr
},
3042 {DEC_ADD_R
, dec_add_r
},
3043 {DEC_SUB_R
, dec_sub_r
},
3045 {DEC_ADDU_R
, dec_addu_r
},
3046 {DEC_ADDS_R
, dec_adds_r
},
3047 {DEC_SUBU_R
, dec_subu_r
},
3048 {DEC_SUBS_R
, dec_subs_r
},
3049 {DEC_LSL_R
, dec_lsl_r
},
3051 {DEC_AND_R
, dec_and_r
},
3052 {DEC_OR_R
, dec_or_r
},
3053 {DEC_BOUND_R
, dec_bound_r
},
3054 {DEC_ASR_R
, dec_asr_r
},
3055 {DEC_LSR_R
, dec_lsr_r
},
3057 {DEC_MOVU_R
, dec_movu_r
},
3058 {DEC_MOVS_R
, dec_movs_r
},
3059 {DEC_NEG_R
, dec_neg_r
},
3060 {DEC_MOVE_R
, dec_move_r
},
3062 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
3063 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
3065 {DEC_MULS_R
, dec_muls_r
},
3066 {DEC_MULU_R
, dec_mulu_r
},
3068 {DEC_ADDU_M
, dec_addu_m
},
3069 {DEC_ADDS_M
, dec_adds_m
},
3070 {DEC_SUBU_M
, dec_subu_m
},
3071 {DEC_SUBS_M
, dec_subs_m
},
3073 {DEC_CMPU_M
, dec_cmpu_m
},
3074 {DEC_CMPS_M
, dec_cmps_m
},
3075 {DEC_MOVU_M
, dec_movu_m
},
3076 {DEC_MOVS_M
, dec_movs_m
},
3078 {DEC_CMP_M
, dec_cmp_m
},
3079 {DEC_ADDO_M
, dec_addo_m
},
3080 {DEC_BOUND_M
, dec_bound_m
},
3081 {DEC_ADD_M
, dec_add_m
},
3082 {DEC_SUB_M
, dec_sub_m
},
3083 {DEC_AND_M
, dec_and_m
},
3084 {DEC_OR_M
, dec_or_m
},
3085 {DEC_MOVE_RM
, dec_move_rm
},
3086 {DEC_TEST_M
, dec_test_m
},
3087 {DEC_MOVE_MR
, dec_move_mr
},
3092 static inline unsigned int
3093 cris_decoder(DisasContext
*dc
)
3095 unsigned int insn_len
= 2;
3098 if (unlikely(loglevel
& CPU_LOG_TB_OP
))
3099 tcg_gen_debug_insn_start(dc
->pc
);
3101 /* Load a halfword onto the instruction register. */
3102 dc
->ir
= lduw_code(dc
->pc
);
3104 /* Now decode it. */
3105 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
3106 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
3107 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
3108 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
3109 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
3110 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
3112 /* Large switch for all insns. */
3113 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
3114 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
)
3116 insn_len
= decinfo
[i
].dec(dc
);
3121 #if !defined(CONFIG_USER_ONLY)
3122 /* Single-stepping ? */
3123 if (dc
->tb_flags
& S_FLAG
) {
3126 l1
= gen_new_label();
3127 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_PR
[PR_SPC
], dc
->pc
, l1
);
3128 /* We treat SPC as a break with an odd trap vector. */
3129 cris_evaluate_flags (dc
);
3130 t_gen_mov_env_TN(trap_vector
, tcg_const_tl(3));
3131 tcg_gen_movi_tl(env_pc
, dc
->pc
+ insn_len
);
3132 tcg_gen_movi_tl(cpu_PR
[PR_SPC
], dc
->pc
+ insn_len
);
3133 t_gen_raise_exception(EXCP_BREAK
);
3140 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
3144 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
3145 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
3146 if (bp
->pc
== dc
->pc
) {
3147 cris_evaluate_flags (dc
);
3148 tcg_gen_movi_tl(env_pc
, dc
->pc
);
3149 t_gen_raise_exception(EXCP_DEBUG
);
3150 dc
->is_jmp
= DISAS_UPDATE
;
3158 * Delay slots on QEMU/CRIS.
3160 * If an exception hits on a delayslot, the core will let ERP (the Exception
3161 * Return Pointer) point to the branch (the previous) insn and set the lsb to
3162 * to give SW a hint that the exception actually hit on the dslot.
3164 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
3165 * the core and any jmp to an odd addresses will mask off that lsb. It is
3166 * simply there to let sw know there was an exception on a dslot.
3168 * When the software returns from an exception, the branch will re-execute.
3169 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3170 * and the branch and delayslot dont share pages.
3172 * The TB contaning the branch insn will set up env->btarget and evaluate
3173 * env->btaken. When the translation loop exits we will note that the branch
3174 * sequence is broken and let env->dslot be the size of the branch insn (those
3177 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3178 * set). It will also expect to have env->dslot setup with the size of the
3179 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3180 * will execute the dslot and take the branch, either to btarget or just one
3183 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3184 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3185 * branch and set lsb). Then env->dslot gets cleared so that the exception
3186 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3187 * masked off and we will reexecute the branch insn.
3191 /* generate intermediate code for basic block 'tb'. */
3193 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
3196 uint16_t *gen_opc_end
;
3198 unsigned int insn_len
;
3200 struct DisasContext ctx
;
3201 struct DisasContext
*dc
= &ctx
;
3202 uint32_t next_page_start
;
3210 /* Odd PC indicates that branch is rexecuting due to exception in the
3211 * delayslot, like in real hw.
3213 pc_start
= tb
->pc
& ~1;
3217 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3219 dc
->is_jmp
= DISAS_NEXT
;
3222 dc
->singlestep_enabled
= env
->singlestep_enabled
;
3223 dc
->flags_uptodate
= 1;
3224 dc
->flagx_known
= 1;
3225 dc
->flags_x
= tb
->flags
& X_FLAG
;
3226 dc
->cc_x_uptodate
= 0;
3230 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3231 dc
->cc_size_uptodate
= -1;
3233 /* Decode TB flags. */
3234 dc
->tb_flags
= tb
->flags
& (S_FLAG
| P_FLAG
| U_FLAG
| X_FLAG
);
3235 dc
->delayed_branch
= !!(tb
->flags
& 7);
3236 if (dc
->delayed_branch
)
3237 dc
->jmp
= JMP_INDIRECT
;
3239 dc
->jmp
= JMP_NOJMP
;
3241 dc
->cpustate_changed
= 0;
3243 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3245 "srch=%d pc=%x %x flg=%llx bt=%x ds=%u ccs=%x\n"
3251 search_pc
, dc
->pc
, dc
->ppc
,
3252 (unsigned long long)tb
->flags
,
3253 env
->btarget
, (unsigned)tb
->flags
& 7,
3255 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3256 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3257 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3258 env
->regs
[8], env
->regs
[9],
3259 env
->regs
[10], env
->regs
[11],
3260 env
->regs
[12], env
->regs
[13],
3261 env
->regs
[14], env
->regs
[15]);
3262 fprintf(logfile
, "--------------\n");
3263 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
3266 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3269 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3271 max_insns
= CF_COUNT_MASK
;
3276 check_breakpoint(env
, dc
);
3279 j
= gen_opc_ptr
- gen_opc_buf
;
3283 gen_opc_instr_start
[lj
++] = 0;
3285 if (dc
->delayed_branch
== 1)
3286 gen_opc_pc
[lj
] = dc
->ppc
| 1;
3288 gen_opc_pc
[lj
] = dc
->pc
;
3289 gen_opc_instr_start
[lj
] = 1;
3290 gen_opc_icount
[lj
] = num_insns
;
3294 DIS(fprintf(logfile
, "%8.8x:\t", dc
->pc
));
3296 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3300 insn_len
= cris_decoder(dc
);
3304 cris_clear_x_flag(dc
);
3307 /* Check for delayed branches here. If we do it before
3308 actually generating any host code, the simulator will just
3309 loop doing nothing for on this program location. */
3310 if (dc
->delayed_branch
) {
3311 dc
->delayed_branch
--;
3312 if (dc
->delayed_branch
== 0)
3315 t_gen_mov_env_TN(dslot
,
3317 if (dc
->jmp
== JMP_DIRECT
) {
3318 dc
->is_jmp
= DISAS_NEXT
;
3320 t_gen_cc_jmp(env_btarget
,
3321 tcg_const_tl(dc
->pc
));
3322 dc
->is_jmp
= DISAS_JUMP
;
3328 /* If we are rexecuting a branch due to exceptions on
3329 delay slots dont break. */
3330 if (!(tb
->pc
& 1) && env
->singlestep_enabled
)
3332 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
3333 && gen_opc_ptr
< gen_opc_end
3334 && (dc
->pc
< next_page_start
)
3335 && num_insns
< max_insns
);
3338 if (dc
->jmp
== JMP_DIRECT
&& !dc
->delayed_branch
)
3341 if (tb
->cflags
& CF_LAST_IO
)
3343 /* Force an update if the per-tb cpu state has changed. */
3344 if (dc
->is_jmp
== DISAS_NEXT
3345 && (dc
->cpustate_changed
|| !dc
->flagx_known
3346 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3347 dc
->is_jmp
= DISAS_UPDATE
;
3348 tcg_gen_movi_tl(env_pc
, npc
);
3350 /* Broken branch+delayslot sequence. */
3351 if (dc
->delayed_branch
== 1) {
3352 /* Set env->dslot to the size of the branch insn. */
3353 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3354 cris_store_direct_jmp(dc
);
3357 cris_evaluate_flags (dc
);
3359 if (unlikely(env
->singlestep_enabled
)) {
3360 if (dc
->is_jmp
== DISAS_NEXT
)
3361 tcg_gen_movi_tl(env_pc
, npc
);
3362 t_gen_raise_exception(EXCP_DEBUG
);
3364 switch(dc
->is_jmp
) {
3366 gen_goto_tb(dc
, 1, npc
);
3371 /* indicate that the hash table must be used
3372 to find the next TB */
3377 /* nothing more to generate */
3381 gen_icount_end(tb
, num_insns
);
3382 *gen_opc_ptr
= INDEX_op_end
;
3384 j
= gen_opc_ptr
- gen_opc_buf
;
3387 gen_opc_instr_start
[lj
++] = 0;
3389 tb
->size
= dc
->pc
- pc_start
;
3390 tb
->icount
= num_insns
;
3395 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3396 target_disas(logfile
, pc_start
, dc
->pc
- pc_start
, 0);
3397 fprintf(logfile
, "\nisize=%d osize=%zd\n",
3398 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
3404 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3406 gen_intermediate_code_internal(env
, tb
, 0);
3409 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3411 gen_intermediate_code_internal(env
, tb
, 1);
3414 void cpu_dump_state (CPUState
*env
, FILE *f
,
3415 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
3424 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3425 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3426 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3428 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3431 for (i
= 0; i
< 16; i
++) {
3432 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
3433 if ((i
+ 1) % 4 == 0)
3434 cpu_fprintf(f
, "\n");
3436 cpu_fprintf(f
, "\nspecial regs:\n");
3437 for (i
= 0; i
< 16; i
++) {
3438 cpu_fprintf(f
, "p%2.2d=%8.8x ", i
, env
->pregs
[i
]);
3439 if ((i
+ 1) % 4 == 0)
3440 cpu_fprintf(f
, "\n");
3442 srs
= env
->pregs
[PR_SRS
];
3443 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3445 for (i
= 0; i
< 16; i
++) {
3446 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3447 i
, env
->sregs
[srs
][i
]);
3448 if ((i
+ 1) % 4 == 0)
3449 cpu_fprintf(f
, "\n");
3452 cpu_fprintf(f
, "\n\n");
3456 CPUCRISState
*cpu_cris_init (const char *cpu_model
)
3459 static int tcg_initialized
= 0;
3462 env
= qemu_mallocz(sizeof(CPUCRISState
));
3469 if (tcg_initialized
)
3472 tcg_initialized
= 1;
3474 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
3475 cc_x
= tcg_global_mem_new(TCG_AREG0
,
3476 offsetof(CPUState
, cc_x
), "cc_x");
3477 cc_src
= tcg_global_mem_new(TCG_AREG0
,
3478 offsetof(CPUState
, cc_src
), "cc_src");
3479 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
3480 offsetof(CPUState
, cc_dest
),
3482 cc_result
= tcg_global_mem_new(TCG_AREG0
,
3483 offsetof(CPUState
, cc_result
),
3485 cc_op
= tcg_global_mem_new(TCG_AREG0
,
3486 offsetof(CPUState
, cc_op
), "cc_op");
3487 cc_size
= tcg_global_mem_new(TCG_AREG0
,
3488 offsetof(CPUState
, cc_size
),
3490 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
3491 offsetof(CPUState
, cc_mask
),
3494 env_pc
= tcg_global_mem_new(TCG_AREG0
,
3495 offsetof(CPUState
, pc
),
3497 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
3498 offsetof(CPUState
, btarget
),
3500 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
3501 offsetof(CPUState
, btaken
),
3503 for (i
= 0; i
< 16; i
++) {
3504 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
3505 offsetof(CPUState
, regs
[i
]),
3508 for (i
= 0; i
< 16; i
++) {
3509 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
3510 offsetof(CPUState
, pregs
[i
]),
3514 #define GEN_HELPER 2
3520 void cpu_reset (CPUCRISState
*env
)
3522 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));
3525 env
->pregs
[PR_VR
] = 32;
3526 #if defined(CONFIG_USER_ONLY)
3527 /* start in user mode with interrupts enabled. */
3528 env
->pregs
[PR_CCS
] |= U_FLAG
| I_FLAG
;
3530 env
->pregs
[PR_CCS
] = 0;
3534 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
3535 unsigned long searched_pc
, int pc_pos
, void *puc
)
3537 env
->pc
= gen_opc_pc
[pc_pos
];