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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * The condition code translation is in need of attention.
39 #include "crisv32-decode.h"
40 #include "qemu-common.h"
50 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
51 #define BUG_ON(x) ({if (x) BUG();})
55 /* Used by the decoder. */
56 #define EXTRACT_FIELD(src, start, end) \
57 (((src) >> start) & ((1 << (end - start + 1)) - 1))
59 #define CC_MASK_NZ 0xc
60 #define CC_MASK_NZV 0xe
61 #define CC_MASK_NZVC 0xf
62 #define CC_MASK_RNZV 0x10e
80 #include "gen-icount.h"
82 /* This is the state at translation time. */
83 typedef struct DisasContext
{
92 unsigned int zsize
, zzsize
;
101 int cc_size_uptodate
; /* -1 invalid or last written value. */
103 int cc_x_uptodate
; /* 1 - ccs, 2 - known | X_FLAG. 0 not uptodate. */
104 int flags_uptodate
; /* Wether or not $ccs is uptodate. */
105 int flagx_known
; /* Wether or not flags_x has the x flag known at
109 int clear_x
; /* Clear x after this insn? */
110 int cpustate_changed
;
111 unsigned int tb_flags
; /* tb dependent flags. */
116 #define JMP_INDIRECT 2
117 int jmp
; /* 0=nojmp, 1=direct, 2=indirect. */
122 struct TranslationBlock
*tb
;
123 int singlestep_enabled
;
126 static void gen_BUG(DisasContext
*dc
, char *file
, int line
)
128 printf ("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
129 fprintf (logfile
, "BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
130 cpu_abort(dc
->env
, "%s:%d\n", file
, line
);
133 const char *regnames
[] =
135 "$r0", "$r1", "$r2", "$r3",
136 "$r4", "$r5", "$r6", "$r7",
137 "$r8", "$r9", "$r10", "$r11",
138 "$r12", "$r13", "$sp", "$acr",
140 const char *pregnames
[] =
142 "$bz", "$vr", "$pid", "$srs",
143 "$wz", "$exs", "$eda", "$mof",
144 "$dz", "$ebp", "$erp", "$srp",
145 "$nrp", "$ccs", "$usp", "$spc",
148 /* We need this table to handle preg-moves with implicit width. */
160 #define t_gen_mov_TN_env(tn, member) \
161 _t_gen_mov_TN_env((tn), offsetof(CPUState, member))
162 #define t_gen_mov_env_TN(member, tn) \
163 _t_gen_mov_env_TN(offsetof(CPUState, member), (tn))
165 static inline void t_gen_mov_TN_reg(TCGv tn
, int r
)
168 fprintf(stderr
, "wrong register read $r%d\n", r
);
169 tcg_gen_mov_tl(tn
, cpu_R
[r
]);
171 static inline void t_gen_mov_reg_TN(int r
, TCGv tn
)
174 fprintf(stderr
, "wrong register write $r%d\n", r
);
175 tcg_gen_mov_tl(cpu_R
[r
], tn
);
178 static inline void _t_gen_mov_TN_env(TCGv tn
, int offset
)
180 if (offset
> sizeof (CPUState
))
181 fprintf(stderr
, "wrong load from env from off=%d\n", offset
);
182 tcg_gen_ld_tl(tn
, cpu_env
, offset
);
184 static inline void _t_gen_mov_env_TN(int offset
, TCGv tn
)
186 if (offset
> sizeof (CPUState
))
187 fprintf(stderr
, "wrong store to env at off=%d\n", offset
);
188 tcg_gen_st_tl(tn
, cpu_env
, offset
);
191 static inline void t_gen_mov_TN_preg(TCGv tn
, int r
)
194 fprintf(stderr
, "wrong register read $p%d\n", r
);
195 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
196 tcg_gen_mov_tl(tn
, tcg_const_tl(0));
198 tcg_gen_mov_tl(tn
, tcg_const_tl(32));
199 else if (r
== PR_EXS
) {
200 printf("read from EXS!\n");
201 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
203 else if (r
== PR_EDA
) {
204 printf("read from EDA!\n");
205 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
208 tcg_gen_mov_tl(tn
, cpu_PR
[r
]);
210 static inline void t_gen_mov_preg_TN(DisasContext
*dc
, int r
, TCGv tn
)
213 fprintf(stderr
, "wrong register write $p%d\n", r
);
214 if (r
== PR_BZ
|| r
== PR_WZ
|| r
== PR_DZ
)
216 else if (r
== PR_SRS
)
217 tcg_gen_andi_tl(cpu_PR
[r
], tn
, 3);
219 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
221 tcg_gen_helper_0_1(helper_tlb_flush_pid
, tn
);
222 else if (r
== PR_CCS
)
223 dc
->cpustate_changed
= 1;
227 static inline void t_gen_raise_exception(uint32_t index
)
229 tcg_gen_helper_0_1(helper_raise_exception
, tcg_const_tl(index
));
232 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
236 l1
= gen_new_label();
237 /* Speculative shift. */
238 tcg_gen_shl_tl(d
, a
, b
);
239 tcg_gen_brcondi_tl(TCG_COND_LEU
, b
, 31, l1
);
240 /* Clear dst if shift operands were to large. */
241 tcg_gen_movi_tl(d
, 0);
245 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
249 l1
= gen_new_label();
250 /* Speculative shift. */
251 tcg_gen_shr_tl(d
, a
, b
);
252 tcg_gen_brcondi_tl(TCG_COND_LEU
, b
, 31, l1
);
253 /* Clear dst if shift operands were to large. */
254 tcg_gen_movi_tl(d
, 0);
258 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
262 l1
= gen_new_label();
263 /* Speculative shift. */
264 tcg_gen_sar_tl(d
, a
, b
);
265 tcg_gen_brcondi_tl(TCG_COND_LEU
, b
, 31, l1
);
266 /* Clear dst if shift operands were to large. */
267 tcg_gen_sar_tl(d
, a
, tcg_const_tl(30));
271 /* 64-bit signed mul, lower result in d and upper in d2. */
272 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
276 t0
= tcg_temp_new(TCG_TYPE_I64
);
277 t1
= tcg_temp_new(TCG_TYPE_I64
);
279 tcg_gen_ext32s_i64(t0
, a
);
280 tcg_gen_ext32s_i64(t1
, b
);
281 tcg_gen_mul_i64(t0
, t0
, t1
);
283 tcg_gen_trunc_i64_i32(d
, t0
);
284 tcg_gen_shri_i64(t0
, t0
, 32);
285 tcg_gen_trunc_i64_i32(d2
, t0
);
291 /* 64-bit unsigned muls, lower result in d and upper in d2. */
292 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
296 t0
= tcg_temp_new(TCG_TYPE_I64
);
297 t1
= tcg_temp_new(TCG_TYPE_I64
);
299 tcg_gen_extu_i32_i64(t0
, a
);
300 tcg_gen_extu_i32_i64(t1
, b
);
301 tcg_gen_mul_i64(t0
, t0
, t1
);
303 tcg_gen_trunc_i64_i32(d
, t0
);
304 tcg_gen_shri_i64(t0
, t0
, 32);
305 tcg_gen_trunc_i64_i32(d2
, t0
);
311 /* 32bit branch-free binary search for counting leading zeros. */
312 static void t_gen_lz_i32(TCGv d
, TCGv x
)
316 y
= tcg_temp_new(TCG_TYPE_I32
);
317 m
= tcg_temp_new(TCG_TYPE_I32
);
318 n
= tcg_temp_new(TCG_TYPE_I32
);
321 tcg_gen_shri_i32(y
, x
, 16);
322 tcg_gen_neg_i32(y
, y
);
324 /* m = (y >> 16) & 16 */
325 tcg_gen_sari_i32(m
, y
, 16);
326 tcg_gen_andi_i32(m
, m
, 16);
329 tcg_gen_sub_i32(n
, tcg_const_i32(16), m
);
331 tcg_gen_shr_i32(x
, x
, m
);
334 tcg_gen_subi_i32(y
, x
, 0x100);
335 /* m = (y >> 16) & 8 */
336 tcg_gen_sari_i32(m
, y
, 16);
337 tcg_gen_andi_i32(m
, m
, 8);
339 tcg_gen_add_i32(n
, n
, m
);
341 tcg_gen_shl_i32(x
, x
, m
);
344 tcg_gen_subi_i32(y
, x
, 0x1000);
345 /* m = (y >> 16) & 4 */
346 tcg_gen_sari_i32(m
, y
, 16);
347 tcg_gen_andi_i32(m
, m
, 4);
349 tcg_gen_add_i32(n
, n
, m
);
351 tcg_gen_shl_i32(x
, x
, m
);
354 tcg_gen_subi_i32(y
, x
, 0x4000);
355 /* m = (y >> 16) & 2 */
356 tcg_gen_sari_i32(m
, y
, 16);
357 tcg_gen_andi_i32(m
, m
, 2);
359 tcg_gen_add_i32(n
, n
, m
);
361 tcg_gen_shl_i32(x
, x
, m
);
364 tcg_gen_shri_i32(y
, x
, 14);
365 /* m = y & ~(y >> 1) */
366 tcg_gen_sari_i32(m
, y
, 1);
367 tcg_gen_not_i32(m
, m
);
368 tcg_gen_and_i32(m
, m
, y
);
371 tcg_gen_addi_i32(d
, n
, 2);
372 tcg_gen_sub_i32(d
, d
, m
);
379 static void t_gen_btst(TCGv d
, TCGv a
, TCGv b
)
387 The N flag is set according to the selected bit in the dest reg.
388 The Z flag is set if the selected bit and all bits to the right are
390 The X flag is cleared.
391 Other flags are left untouched.
392 The destination reg is not affected.
394 unsigned int fz, sbit, bset, mask, masked_t0;
397 bset = !!(T0 & (1 << sbit));
398 mask = sbit == 31 ? -1 : (1 << (sbit + 1)) - 1;
399 masked_t0 = T0 & mask;
400 fz = !(masked_t0 | bset);
402 // Clear the X, N and Z flags.
403 T0 = env->pregs[PR_CCS] & ~(X_FLAG | N_FLAG | Z_FLAG);
404 // Set the N and Z flags accordingly.
405 T0 |= (bset << 3) | (fz << 2);
408 l1
= gen_new_label();
409 sbit
= tcg_temp_new(TCG_TYPE_TL
);
410 bset
= tcg_temp_new(TCG_TYPE_TL
);
411 t0
= tcg_temp_new(TCG_TYPE_TL
);
413 /* Compute bset and sbit. */
414 tcg_gen_andi_tl(sbit
, b
, 31);
415 tcg_gen_shl_tl(t0
, tcg_const_tl(1), sbit
);
416 tcg_gen_and_tl(bset
, a
, t0
);
417 tcg_gen_shr_tl(bset
, bset
, sbit
);
418 /* Displace to N_FLAG. */
419 tcg_gen_shli_tl(bset
, bset
, 3);
421 tcg_gen_shl_tl(sbit
, tcg_const_tl(2), sbit
);
422 tcg_gen_subi_tl(sbit
, sbit
, 1);
423 tcg_gen_and_tl(sbit
, a
, sbit
);
425 tcg_gen_andi_tl(d
, cpu_PR
[PR_CCS
], ~(X_FLAG
| N_FLAG
| Z_FLAG
));
426 /* or in the N_FLAG. */
427 tcg_gen_or_tl(d
, d
, bset
);
428 tcg_gen_brcondi_tl(TCG_COND_NE
, sbit
, 0, l1
);
429 /* or in the Z_FLAG. */
430 tcg_gen_ori_tl(d
, d
, Z_FLAG
);
437 static void t_gen_cris_dstep(TCGv d
, TCGv a
, TCGv b
)
441 l1
= gen_new_label();
448 tcg_gen_shli_tl(d
, a
, 1);
449 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, b
, l1
);
450 tcg_gen_sub_tl(d
, d
, b
);
454 /* Extended arithmetics on CRIS. */
455 static inline void t_gen_add_flag(TCGv d
, int flag
)
459 c
= tcg_temp_new(TCG_TYPE_TL
);
460 t_gen_mov_TN_preg(c
, PR_CCS
);
461 /* Propagate carry into d. */
462 tcg_gen_andi_tl(c
, c
, 1 << flag
);
464 tcg_gen_shri_tl(c
, c
, flag
);
465 tcg_gen_add_tl(d
, d
, c
);
469 static inline void t_gen_addx_carry(DisasContext
*dc
, TCGv d
)
471 if (dc
->flagx_known
) {
475 c
= tcg_temp_new(TCG_TYPE_TL
);
476 t_gen_mov_TN_preg(c
, PR_CCS
);
477 /* C flag is already at bit 0. */
478 tcg_gen_andi_tl(c
, c
, C_FLAG
);
479 tcg_gen_add_tl(d
, d
, c
);
485 x
= tcg_temp_new(TCG_TYPE_TL
);
486 c
= tcg_temp_new(TCG_TYPE_TL
);
487 t_gen_mov_TN_preg(x
, PR_CCS
);
488 tcg_gen_mov_tl(c
, x
);
490 /* Propagate carry into d if X is set. Branch free. */
491 tcg_gen_andi_tl(c
, c
, C_FLAG
);
492 tcg_gen_andi_tl(x
, x
, X_FLAG
);
493 tcg_gen_shri_tl(x
, x
, 4);
495 tcg_gen_and_tl(x
, x
, c
);
496 tcg_gen_add_tl(d
, d
, x
);
502 static inline void t_gen_subx_carry(DisasContext
*dc
, TCGv d
)
504 if (dc
->flagx_known
) {
508 c
= tcg_temp_new(TCG_TYPE_TL
);
509 t_gen_mov_TN_preg(c
, PR_CCS
);
510 /* C flag is already at bit 0. */
511 tcg_gen_andi_tl(c
, c
, C_FLAG
);
512 tcg_gen_sub_tl(d
, d
, c
);
518 x
= tcg_temp_new(TCG_TYPE_TL
);
519 c
= tcg_temp_new(TCG_TYPE_TL
);
520 t_gen_mov_TN_preg(x
, PR_CCS
);
521 tcg_gen_mov_tl(c
, x
);
523 /* Propagate carry into d if X is set. Branch free. */
524 tcg_gen_andi_tl(c
, c
, C_FLAG
);
525 tcg_gen_andi_tl(x
, x
, X_FLAG
);
526 tcg_gen_shri_tl(x
, x
, 4);
528 tcg_gen_and_tl(x
, x
, c
);
529 tcg_gen_sub_tl(d
, d
, x
);
535 /* Swap the two bytes within each half word of the s operand.
536 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
537 static inline void t_gen_swapb(TCGv d
, TCGv s
)
541 t
= tcg_temp_new(TCG_TYPE_TL
);
542 org_s
= tcg_temp_new(TCG_TYPE_TL
);
544 /* d and s may refer to the same object. */
545 tcg_gen_mov_tl(org_s
, s
);
546 tcg_gen_shli_tl(t
, org_s
, 8);
547 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
548 tcg_gen_shri_tl(t
, org_s
, 8);
549 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
550 tcg_gen_or_tl(d
, d
, t
);
552 tcg_temp_free(org_s
);
555 /* Swap the halfwords of the s operand. */
556 static inline void t_gen_swapw(TCGv d
, TCGv s
)
559 /* d and s refer the same object. */
560 t
= tcg_temp_new(TCG_TYPE_TL
);
561 tcg_gen_mov_tl(t
, s
);
562 tcg_gen_shli_tl(d
, t
, 16);
563 tcg_gen_shri_tl(t
, t
, 16);
564 tcg_gen_or_tl(d
, d
, t
);
568 /* Reverse the within each byte.
569 T0 = (((T0 << 7) & 0x80808080) |
570 ((T0 << 5) & 0x40404040) |
571 ((T0 << 3) & 0x20202020) |
572 ((T0 << 1) & 0x10101010) |
573 ((T0 >> 1) & 0x08080808) |
574 ((T0 >> 3) & 0x04040404) |
575 ((T0 >> 5) & 0x02020202) |
576 ((T0 >> 7) & 0x01010101));
578 static inline void t_gen_swapr(TCGv d
, TCGv s
)
581 int shift
; /* LSL when positive, LSR when negative. */
596 /* d and s refer the same object. */
597 t
= tcg_temp_new(TCG_TYPE_TL
);
598 org_s
= tcg_temp_new(TCG_TYPE_TL
);
599 tcg_gen_mov_tl(org_s
, s
);
601 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
602 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
603 for (i
= 1; i
< sizeof bitrev
/ sizeof bitrev
[0]; i
++) {
604 if (bitrev
[i
].shift
>= 0) {
605 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
607 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
609 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
610 tcg_gen_or_tl(d
, d
, t
);
613 tcg_temp_free(org_s
);
616 static void t_gen_cc_jmp(TCGv pc_true
, TCGv pc_false
)
621 l1
= gen_new_label();
622 btaken
= tcg_temp_new(TCG_TYPE_TL
);
624 /* Conditional jmp. */
625 tcg_gen_mov_tl(btaken
, env_btaken
);
626 tcg_gen_mov_tl(env_pc
, pc_false
);
627 tcg_gen_brcondi_tl(TCG_COND_EQ
, btaken
, 0, l1
);
628 tcg_gen_mov_tl(env_pc
, pc_true
);
631 tcg_temp_free(btaken
);
634 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
636 TranslationBlock
*tb
;
638 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
640 tcg_gen_movi_tl(env_pc
, dest
);
641 tcg_gen_exit_tb((long)tb
+ n
);
643 tcg_gen_movi_tl(env_pc
, dest
);
648 /* Sign extend at translation time. */
649 static int sign_extend(unsigned int val
, unsigned int width
)
661 static inline void cris_clear_x_flag(DisasContext
*dc
)
663 if (dc
->flagx_known
&& dc
->flags_x
)
664 dc
->flags_uptodate
= 0;
670 static void cris_flush_cc_state(DisasContext
*dc
)
672 if (dc
->cc_size_uptodate
!= dc
->cc_size
) {
673 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
674 dc
->cc_size_uptodate
= dc
->cc_size
;
676 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
677 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
680 static void cris_evaluate_flags(DisasContext
*dc
)
682 if (!dc
->flags_uptodate
) {
683 cris_flush_cc_state(dc
);
688 tcg_gen_helper_0_0(helper_evaluate_flags_mcp
);
691 tcg_gen_helper_0_0(helper_evaluate_flags_muls
);
694 tcg_gen_helper_0_0(helper_evaluate_flags_mulu
);
706 tcg_gen_helper_0_0(helper_evaluate_flags_move_4
);
709 tcg_gen_helper_0_0(helper_evaluate_flags_move_2
);
712 tcg_gen_helper_0_0(helper_evaluate_flags
);
724 tcg_gen_helper_0_0(helper_evaluate_flags_alu_4
);
727 tcg_gen_helper_0_0(helper_evaluate_flags
);
733 if (dc
->flagx_known
) {
735 tcg_gen_ori_tl(cpu_PR
[PR_CCS
],
736 cpu_PR
[PR_CCS
], X_FLAG
);
738 tcg_gen_andi_tl(cpu_PR
[PR_CCS
],
739 cpu_PR
[PR_CCS
], ~X_FLAG
);
742 dc
->flags_uptodate
= 1;
746 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
755 /* Check if we need to evaluate the condition codes due to
757 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
759 /* TODO: optimize this case. It trigs all the time. */
760 cris_evaluate_flags (dc
);
766 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
770 dc
->flags_uptodate
= 0;
773 static inline void cris_update_cc_x(DisasContext
*dc
)
775 /* Save the x flag state at the time of the cc snapshot. */
776 if (dc
->flagx_known
) {
777 if (dc
->cc_x_uptodate
== (2 | dc
->flags_x
))
779 tcg_gen_movi_tl(cc_x
, dc
->flags_x
);
780 dc
->cc_x_uptodate
= 2 | dc
->flags_x
;
783 tcg_gen_andi_tl(cc_x
, cpu_PR
[PR_CCS
], X_FLAG
);
784 dc
->cc_x_uptodate
= 1;
788 /* Update cc prior to executing ALU op. Needs source operands untouched. */
789 static void cris_pre_alu_update_cc(DisasContext
*dc
, int op
,
790 TCGv dst
, TCGv src
, int size
)
793 cris_update_cc_op(dc
, op
, size
);
794 tcg_gen_mov_tl(cc_src
, src
);
803 tcg_gen_mov_tl(cc_dest
, dst
);
805 cris_update_cc_x(dc
);
809 /* Update cc after executing ALU op. needs the result. */
810 static inline void cris_update_result(DisasContext
*dc
, TCGv res
)
813 if (dc
->cc_size
== 4 &&
814 (dc
->cc_op
== CC_OP_SUB
815 || dc
->cc_op
== CC_OP_ADD
))
817 tcg_gen_mov_tl(cc_result
, res
);
821 /* Returns one if the write back stage should execute. */
822 static void cris_alu_op_exec(DisasContext
*dc
, int op
,
823 TCGv dst
, TCGv a
, TCGv b
, int size
)
825 /* Emit the ALU insns. */
829 tcg_gen_add_tl(dst
, a
, b
);
830 /* Extended arithmetics. */
831 t_gen_addx_carry(dc
, dst
);
834 tcg_gen_add_tl(dst
, a
, b
);
835 t_gen_add_flag(dst
, 0); /* C_FLAG. */
838 tcg_gen_add_tl(dst
, a
, b
);
839 t_gen_add_flag(dst
, 8); /* R_FLAG. */
842 tcg_gen_sub_tl(dst
, a
, b
);
843 /* Extended arithmetics. */
844 t_gen_subx_carry(dc
, dst
);
847 tcg_gen_mov_tl(dst
, b
);
850 tcg_gen_or_tl(dst
, a
, b
);
853 tcg_gen_and_tl(dst
, a
, b
);
856 tcg_gen_xor_tl(dst
, a
, b
);
859 t_gen_lsl(dst
, a
, b
);
862 t_gen_lsr(dst
, a
, b
);
865 t_gen_asr(dst
, a
, b
);
868 tcg_gen_neg_tl(dst
, b
);
869 /* Extended arithmetics. */
870 t_gen_subx_carry(dc
, dst
);
873 t_gen_lz_i32(dst
, b
);
876 t_gen_btst(dst
, a
, b
);
879 t_gen_muls(dst
, cpu_PR
[PR_MOF
], a
, b
);
882 t_gen_mulu(dst
, cpu_PR
[PR_MOF
], a
, b
);
885 t_gen_cris_dstep(dst
, a
, b
);
890 l1
= gen_new_label();
891 tcg_gen_mov_tl(dst
, a
);
892 tcg_gen_brcond_tl(TCG_COND_LEU
, a
, b
, l1
);
893 tcg_gen_mov_tl(dst
, b
);
898 tcg_gen_sub_tl(dst
, a
, b
);
899 /* Extended arithmetics. */
900 t_gen_subx_carry(dc
, dst
);
903 fprintf (logfile
, "illegal ALU op.\n");
909 tcg_gen_andi_tl(dst
, dst
, 0xff);
911 tcg_gen_andi_tl(dst
, dst
, 0xffff);
914 static void cris_alu(DisasContext
*dc
, int op
,
915 TCGv d
, TCGv op_a
, TCGv op_b
, int size
)
924 else if (size
== 4) {
929 cris_pre_alu_update_cc(dc
, op
, op_a
, op_b
, size
);
930 cris_alu_op_exec(dc
, op
, tmp
, op_a
, op_b
, size
);
931 cris_update_result(dc
, tmp
);
936 tcg_gen_andi_tl(d
, d
, ~0xff);
938 tcg_gen_andi_tl(d
, d
, ~0xffff);
939 tcg_gen_or_tl(d
, d
, tmp
);
943 static int arith_cc(DisasContext
*dc
)
947 case CC_OP_ADDC
: return 1;
948 case CC_OP_ADD
: return 1;
949 case CC_OP_SUB
: return 1;
950 case CC_OP_DSTEP
: return 1;
951 case CC_OP_LSL
: return 1;
952 case CC_OP_LSR
: return 1;
953 case CC_OP_ASR
: return 1;
954 case CC_OP_CMP
: return 1;
955 case CC_OP_NEG
: return 1;
956 case CC_OP_OR
: return 1;
957 case CC_OP_XOR
: return 1;
958 case CC_OP_MULU
: return 1;
959 case CC_OP_MULS
: return 1;
967 static void gen_tst_cc (DisasContext
*dc
, int cond
)
969 int arith_opt
, move_opt
;
971 /* TODO: optimize more condition codes. */
974 * If the flags are live, we've gotta look into the bits of CCS.
975 * Otherwise, if we just did an arithmetic operation we try to
976 * evaluate the condition code faster.
978 * When this function is done, T0 should be non-zero if the condition
981 arith_opt
= arith_cc(dc
) && !dc
->flags_uptodate
;
982 move_opt
= (dc
->cc_op
== CC_OP_MOVE
) && dc
->flags_uptodate
;
985 if (arith_opt
|| move_opt
) {
986 /* If cc_result is zero, T0 should be
987 non-zero otherwise T0 should be zero. */
989 l1
= gen_new_label();
990 tcg_gen_movi_tl(cpu_T
[0], 0);
991 tcg_gen_brcondi_tl(TCG_COND_NE
, cc_result
,
993 tcg_gen_movi_tl(cpu_T
[0], 1);
997 cris_evaluate_flags(dc
);
998 tcg_gen_andi_tl(cpu_T
[0],
999 cpu_PR
[PR_CCS
], Z_FLAG
);
1003 if (arith_opt
|| move_opt
)
1004 tcg_gen_mov_tl(cpu_T
[0], cc_result
);
1006 cris_evaluate_flags(dc
);
1007 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
1009 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], Z_FLAG
);
1013 cris_evaluate_flags(dc
);
1014 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], C_FLAG
);
1017 cris_evaluate_flags(dc
);
1018 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
], C_FLAG
);
1019 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], C_FLAG
);
1022 cris_evaluate_flags(dc
);
1023 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], V_FLAG
);
1026 cris_evaluate_flags(dc
);
1027 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
1029 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], V_FLAG
);
1032 if (arith_opt
|| move_opt
) {
1035 if (dc
->cc_size
== 1)
1037 else if (dc
->cc_size
== 2)
1040 tcg_gen_shri_tl(cpu_T
[0], cc_result
, bits
);
1041 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
1043 cris_evaluate_flags(dc
);
1044 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
1046 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1050 if (arith_opt
|| move_opt
) {
1053 if (dc
->cc_size
== 1)
1055 else if (dc
->cc_size
== 2)
1058 tcg_gen_shri_tl(cpu_T
[0], cc_result
, 31);
1061 cris_evaluate_flags(dc
);
1062 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
1067 cris_evaluate_flags(dc
);
1068 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
1072 cris_evaluate_flags(dc
);
1076 tmp
= tcg_temp_new(TCG_TYPE_TL
);
1077 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
1079 /* Overlay the C flag on top of the Z. */
1080 tcg_gen_shli_tl(cpu_T
[0], tmp
, 2);
1081 tcg_gen_and_tl(cpu_T
[0], tmp
, cpu_T
[0]);
1082 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], Z_FLAG
);
1088 cris_evaluate_flags(dc
);
1089 /* Overlay the V flag on top of the N. */
1090 tcg_gen_shli_tl(cpu_T
[0], cpu_PR
[PR_CCS
], 2);
1091 tcg_gen_xor_tl(cpu_T
[0],
1092 cpu_PR
[PR_CCS
], cpu_T
[0]);
1093 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1094 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1097 cris_evaluate_flags(dc
);
1098 /* Overlay the V flag on top of the N. */
1099 tcg_gen_shli_tl(cpu_T
[0], cpu_PR
[PR_CCS
], 2);
1100 tcg_gen_xor_tl(cpu_T
[0],
1101 cpu_PR
[PR_CCS
], cpu_T
[0]);
1102 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1105 cris_evaluate_flags(dc
);
1109 n
= tcg_temp_new(TCG_TYPE_TL
);
1110 z
= tcg_temp_new(TCG_TYPE_TL
);
1112 /* To avoid a shift we overlay everything on
1114 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1115 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1117 tcg_gen_xori_tl(z
, z
, 2);
1119 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1120 tcg_gen_xori_tl(n
, n
, 2);
1121 tcg_gen_and_tl(cpu_T
[0], z
, n
);
1122 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 2);
1129 cris_evaluate_flags(dc
);
1133 n
= tcg_temp_new(TCG_TYPE_TL
);
1134 z
= tcg_temp_new(TCG_TYPE_TL
);
1136 /* To avoid a shift we overlay everything on
1138 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1139 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1141 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1142 tcg_gen_or_tl(cpu_T
[0], z
, n
);
1143 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 2);
1150 cris_evaluate_flags(dc
);
1151 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], P_FLAG
);
1154 tcg_gen_movi_tl(cpu_T
[0], 1);
1162 static void cris_store_direct_jmp(DisasContext
*dc
)
1164 /* Store the direct jmp state into the cpu-state. */
1165 if (dc
->jmp
== JMP_DIRECT
) {
1166 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1167 tcg_gen_movi_tl(env_btaken
, 1);
1171 static void cris_prepare_cc_branch (DisasContext
*dc
,
1172 int offset
, int cond
)
1174 /* This helps us re-schedule the micro-code to insns in delay-slots
1175 before the actual jump. */
1176 dc
->delayed_branch
= 2;
1177 dc
->jmp_pc
= dc
->pc
+ offset
;
1181 dc
->jmp
= JMP_INDIRECT
;
1182 gen_tst_cc (dc
, cond
);
1183 tcg_gen_mov_tl(env_btaken
, cpu_T
[0]);
1184 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
1186 /* Allow chaining. */
1187 dc
->jmp
= JMP_DIRECT
;
1192 /* jumps, when the dest is in a live reg for example. Direct should be set
1193 when the dest addr is constant to allow tb chaining. */
1194 static inline void cris_prepare_jmp (DisasContext
*dc
, unsigned int type
)
1196 /* This helps us re-schedule the micro-code to insns in delay-slots
1197 before the actual jump. */
1198 dc
->delayed_branch
= 2;
1200 if (type
== JMP_INDIRECT
)
1201 tcg_gen_movi_tl(env_btaken
, 1);
1204 void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1205 unsigned int size
, int sign
)
1207 int mem_index
= cpu_mmu_index(dc
->env
);
1209 /* If we get a fault on a delayslot we must keep the jmp state in
1210 the cpu-state to be able to re-execute the jmp. */
1211 if (dc
->delayed_branch
== 1)
1212 cris_store_direct_jmp(dc
);
1216 tcg_gen_qemu_ld8s(dst
, addr
, mem_index
);
1218 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
1220 else if (size
== 2) {
1222 tcg_gen_qemu_ld16s(dst
, addr
, mem_index
);
1224 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
1227 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
1231 void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1234 int mem_index
= cpu_mmu_index(dc
->env
);
1236 /* If we get a fault on a delayslot we must keep the jmp state in
1237 the cpu-state to be able to re-execute the jmp. */
1238 if (dc
->delayed_branch
== 1)
1239 cris_store_direct_jmp(dc
);
1242 /* Conditional writes. We only support the kind were X and P are known
1243 at translation time. */
1244 if (dc
->flagx_known
&& dc
->flags_x
&& (dc
->tb_flags
& P_FLAG
)) {
1246 cris_evaluate_flags(dc
);
1247 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], C_FLAG
);
1251 /* Remember, operands are flipped. CRIS has reversed order. */
1253 tcg_gen_qemu_st8(val
, addr
, mem_index
);
1255 tcg_gen_qemu_st16(val
, addr
, mem_index
);
1257 tcg_gen_qemu_st32(val
, addr
, mem_index
);
1259 if (dc
->flagx_known
&& dc
->flags_x
) {
1260 cris_evaluate_flags(dc
);
1261 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~C_FLAG
);
1265 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1268 tcg_gen_ext8s_i32(d
, s
);
1270 tcg_gen_ext16s_i32(d
, s
);
1272 tcg_gen_mov_tl(d
, s
);
1275 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1278 tcg_gen_ext8u_i32(d
, s
);
1280 tcg_gen_ext16u_i32(d
, s
);
1282 tcg_gen_mov_tl(d
, s
);
1286 static char memsize_char(int size
)
1290 case 1: return 'b'; break;
1291 case 2: return 'w'; break;
1292 case 4: return 'd'; break;
1300 static inline unsigned int memsize_z(DisasContext
*dc
)
1302 return dc
->zsize
+ 1;
1305 static inline unsigned int memsize_zz(DisasContext
*dc
)
1316 static inline void do_postinc (DisasContext
*dc
, int size
)
1319 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1322 static inline void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1323 int size
, int s_ext
, TCGv dst
)
1326 t_gen_sext(dst
, cpu_R
[rs
], size
);
1328 t_gen_zext(dst
, cpu_R
[rs
], size
);
1331 /* Prepare T0 and T1 for a register alu operation.
1332 s_ext decides if the operand1 should be sign-extended or zero-extended when
1334 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1335 int size
, int s_ext
)
1337 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
, cpu_T
[1]);
1340 t_gen_sext(cpu_T
[0], cpu_R
[rd
], size
);
1342 t_gen_zext(cpu_T
[0], cpu_R
[rd
], size
);
1345 static int dec_prep_move_m(DisasContext
*dc
, int s_ext
, int memsize
,
1348 unsigned int rs
, rd
;
1355 is_imm
= rs
== 15 && dc
->postinc
;
1357 /* Load [$rs] onto T1. */
1359 insn_len
= 2 + memsize
;
1366 imm
= ldsb_code(dc
->pc
+ 2);
1368 imm
= ldsw_code(dc
->pc
+ 2);
1371 imm
= ldub_code(dc
->pc
+ 2);
1373 imm
= lduw_code(dc
->pc
+ 2);
1376 imm
= ldl_code(dc
->pc
+ 2);
1378 DIS(fprintf (logfile
, "imm=%x rd=%d sext=%d ms=%d\n",
1379 imm
, rd
, s_ext
, memsize
));
1380 tcg_gen_movi_tl(dst
, imm
);
1383 cris_flush_cc_state(dc
);
1384 gen_load(dc
, dst
, cpu_R
[rs
], memsize
, 0);
1386 t_gen_sext(dst
, dst
, memsize
);
1388 t_gen_zext(dst
, dst
, memsize
);
1393 /* Prepare T0 and T1 for a memory + alu operation.
1394 s_ext decides if the operand1 should be sign-extended or zero-extended when
1396 static int dec_prep_alu_m(DisasContext
*dc
, int s_ext
, int memsize
)
1400 insn_len
= dec_prep_move_m(dc
, s_ext
, memsize
, cpu_T
[1]);
1402 /* put dest in T0. */
1403 tcg_gen_mov_tl(cpu_T
[0], cpu_R
[dc
->op2
]);
1408 static const char *cc_name(int cc
)
1410 static char *cc_names
[16] = {
1411 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1412 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1415 return cc_names
[cc
];
1419 /* Start of insn decoders. */
1421 static unsigned int dec_bccq(DisasContext
*dc
)
1425 uint32_t cond
= dc
->op2
;
1428 offset
= EXTRACT_FIELD (dc
->ir
, 1, 7);
1429 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1432 offset
|= sign
<< 8;
1434 offset
= sign_extend(offset
, 8);
1436 DIS(fprintf (logfile
, "b%s %x\n", cc_name(cond
), dc
->pc
+ offset
));
1438 /* op2 holds the condition-code. */
1439 cris_cc_mask(dc
, 0);
1440 cris_prepare_cc_branch (dc
, offset
, cond
);
1443 static unsigned int dec_addoq(DisasContext
*dc
)
1447 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1448 imm
= sign_extend(dc
->op1
, 7);
1450 DIS(fprintf (logfile
, "addoq %d, $r%u\n", imm
, dc
->op2
));
1451 cris_cc_mask(dc
, 0);
1452 /* Fetch register operand, */
1453 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1456 static unsigned int dec_addq(DisasContext
*dc
)
1458 DIS(fprintf (logfile
, "addq %u, $r%u\n", dc
->op1
, dc
->op2
));
1460 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1462 cris_cc_mask(dc
, CC_MASK_NZVC
);
1464 cris_alu(dc
, CC_OP_ADD
,
1465 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1468 static unsigned int dec_moveq(DisasContext
*dc
)
1472 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1473 imm
= sign_extend(dc
->op1
, 5);
1474 DIS(fprintf (logfile
, "moveq %d, $r%u\n", imm
, dc
->op2
));
1476 tcg_gen_mov_tl(cpu_R
[dc
->op2
], tcg_const_tl(imm
));
1479 static unsigned int dec_subq(DisasContext
*dc
)
1481 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1483 DIS(fprintf (logfile
, "subq %u, $r%u\n", dc
->op1
, dc
->op2
));
1485 cris_cc_mask(dc
, CC_MASK_NZVC
);
1486 cris_alu(dc
, CC_OP_SUB
,
1487 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1490 static unsigned int dec_cmpq(DisasContext
*dc
)
1493 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1494 imm
= sign_extend(dc
->op1
, 5);
1496 DIS(fprintf (logfile
, "cmpq %d, $r%d\n", imm
, dc
->op2
));
1497 cris_cc_mask(dc
, CC_MASK_NZVC
);
1499 cris_alu(dc
, CC_OP_CMP
,
1500 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1503 static unsigned int dec_andq(DisasContext
*dc
)
1506 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1507 imm
= sign_extend(dc
->op1
, 5);
1509 DIS(fprintf (logfile
, "andq %d, $r%d\n", imm
, dc
->op2
));
1510 cris_cc_mask(dc
, CC_MASK_NZ
);
1512 cris_alu(dc
, CC_OP_AND
,
1513 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1516 static unsigned int dec_orq(DisasContext
*dc
)
1519 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1520 imm
= sign_extend(dc
->op1
, 5);
1521 DIS(fprintf (logfile
, "orq %d, $r%d\n", imm
, dc
->op2
));
1522 cris_cc_mask(dc
, CC_MASK_NZ
);
1524 cris_alu(dc
, CC_OP_OR
,
1525 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], tcg_const_tl(imm
), 4);
1528 static unsigned int dec_btstq(DisasContext
*dc
)
1530 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1531 DIS(fprintf (logfile
, "btstq %u, $r%d\n", dc
->op1
, dc
->op2
));
1533 cris_cc_mask(dc
, CC_MASK_NZ
);
1535 cris_alu(dc
, CC_OP_BTST
,
1536 cpu_T
[0], cpu_R
[dc
->op2
], tcg_const_tl(dc
->op1
), 4);
1537 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1538 t_gen_mov_preg_TN(dc
, PR_CCS
, cpu_T
[0]);
1539 dc
->flags_uptodate
= 1;
1542 static unsigned int dec_asrq(DisasContext
*dc
)
1544 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1545 DIS(fprintf (logfile
, "asrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1546 cris_cc_mask(dc
, CC_MASK_NZ
);
1548 tcg_gen_sari_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);
1554 static unsigned int dec_lslq(DisasContext
*dc
)
1556 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1557 DIS(fprintf (logfile
, "lslq %u, $r%d\n", dc
->op1
, dc
->op2
));
1559 cris_cc_mask(dc
, CC_MASK_NZ
);
1561 tcg_gen_shli_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1563 cris_alu(dc
, CC_OP_MOVE
,
1565 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1568 static unsigned int dec_lsrq(DisasContext
*dc
)
1570 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1571 DIS(fprintf (logfile
, "lsrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1573 cris_cc_mask(dc
, CC_MASK_NZ
);
1575 tcg_gen_shri_tl(cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], dc
->op1
);
1576 cris_alu(dc
, CC_OP_MOVE
,
1578 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], 4);
1582 static unsigned int dec_move_r(DisasContext
*dc
)
1584 int size
= memsize_zz(dc
);
1586 DIS(fprintf (logfile
, "move.%c $r%u, $r%u\n",
1587 memsize_char(size
), dc
->op1
, dc
->op2
));
1589 cris_cc_mask(dc
, CC_MASK_NZ
);
1591 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_R
[dc
->op2
]);
1592 cris_cc_mask(dc
, CC_MASK_NZ
);
1593 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
1594 cris_update_cc_x(dc
);
1595 cris_update_result(dc
, cpu_R
[dc
->op2
]);
1598 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_T
[1]);
1599 cris_alu(dc
, CC_OP_MOVE
,
1601 cpu_R
[dc
->op2
], cpu_T
[1], size
);
1606 static unsigned int dec_scc_r(DisasContext
*dc
)
1610 DIS(fprintf (logfile
, "s%s $r%u\n",
1611 cc_name(cond
), dc
->op1
));
1617 gen_tst_cc (dc
, cond
);
1619 l1
= gen_new_label();
1620 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
1621 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
1622 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1626 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1628 cris_cc_mask(dc
, 0);
1632 static unsigned int dec_and_r(DisasContext
*dc
)
1634 int size
= memsize_zz(dc
);
1636 DIS(fprintf (logfile
, "and.%c $r%u, $r%u\n",
1637 memsize_char(size
), dc
->op1
, dc
->op2
));
1638 cris_cc_mask(dc
, CC_MASK_NZ
);
1639 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1641 cris_alu(dc
, CC_OP_AND
,
1643 cpu_R
[dc
->op2
], cpu_T
[1], size
);
1647 static unsigned int dec_lz_r(DisasContext
*dc
)
1649 DIS(fprintf (logfile
, "lz $r%u, $r%u\n",
1651 cris_cc_mask(dc
, CC_MASK_NZ
);
1652 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1653 cris_alu(dc
, CC_OP_LZ
,
1654 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
1658 static unsigned int dec_lsl_r(DisasContext
*dc
)
1660 int size
= memsize_zz(dc
);
1662 DIS(fprintf (logfile
, "lsl.%c $r%u, $r%u\n",
1663 memsize_char(size
), dc
->op1
, dc
->op2
));
1664 cris_cc_mask(dc
, CC_MASK_NZ
);
1665 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1666 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1668 cris_alu(dc
, CC_OP_LSL
,
1669 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1673 static unsigned int dec_lsr_r(DisasContext
*dc
)
1675 int size
= memsize_zz(dc
);
1677 DIS(fprintf (logfile
, "lsr.%c $r%u, $r%u\n",
1678 memsize_char(size
), dc
->op1
, dc
->op2
));
1679 cris_cc_mask(dc
, CC_MASK_NZ
);
1680 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1681 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1683 cris_alu(dc
, CC_OP_LSR
,
1684 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1688 static unsigned int dec_asr_r(DisasContext
*dc
)
1690 int size
= memsize_zz(dc
);
1692 DIS(fprintf (logfile
, "asr.%c $r%u, $r%u\n",
1693 memsize_char(size
), dc
->op1
, dc
->op2
));
1694 cris_cc_mask(dc
, CC_MASK_NZ
);
1695 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1696 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1698 cris_alu(dc
, CC_OP_ASR
,
1699 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1703 static unsigned int dec_muls_r(DisasContext
*dc
)
1705 int size
= memsize_zz(dc
);
1707 DIS(fprintf (logfile
, "muls.%c $r%u, $r%u\n",
1708 memsize_char(size
), dc
->op1
, dc
->op2
));
1709 cris_cc_mask(dc
, CC_MASK_NZV
);
1710 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1712 cris_alu(dc
, CC_OP_MULS
,
1713 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
1717 static unsigned int dec_mulu_r(DisasContext
*dc
)
1719 int size
= memsize_zz(dc
);
1721 DIS(fprintf (logfile
, "mulu.%c $r%u, $r%u\n",
1722 memsize_char(size
), dc
->op1
, dc
->op2
));
1723 cris_cc_mask(dc
, CC_MASK_NZV
);
1724 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1726 cris_alu(dc
, CC_OP_MULU
,
1727 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
1732 static unsigned int dec_dstep_r(DisasContext
*dc
)
1734 DIS(fprintf (logfile
, "dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
));
1735 cris_cc_mask(dc
, CC_MASK_NZ
);
1736 cris_alu(dc
, CC_OP_DSTEP
,
1737 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], 4);
1741 static unsigned int dec_xor_r(DisasContext
*dc
)
1743 int size
= memsize_zz(dc
);
1744 DIS(fprintf (logfile
, "xor.%c $r%u, $r%u\n",
1745 memsize_char(size
), dc
->op1
, dc
->op2
));
1746 BUG_ON(size
!= 4); /* xor is dword. */
1747 cris_cc_mask(dc
, CC_MASK_NZ
);
1748 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1750 cris_alu(dc
, CC_OP_XOR
,
1751 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
1755 static unsigned int dec_bound_r(DisasContext
*dc
)
1757 int size
= memsize_zz(dc
);
1758 DIS(fprintf (logfile
, "bound.%c $r%u, $r%u\n",
1759 memsize_char(size
), dc
->op1
, dc
->op2
));
1760 cris_cc_mask(dc
, CC_MASK_NZ
);
1761 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_T
[1]);
1762 cris_alu(dc
, CC_OP_BOUND
,
1763 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
1767 static unsigned int dec_cmp_r(DisasContext
*dc
)
1769 int size
= memsize_zz(dc
);
1770 DIS(fprintf (logfile
, "cmp.%c $r%u, $r%u\n",
1771 memsize_char(size
), dc
->op1
, dc
->op2
));
1772 cris_cc_mask(dc
, CC_MASK_NZVC
);
1773 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1775 cris_alu(dc
, CC_OP_CMP
,
1776 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1780 static unsigned int dec_abs_r(DisasContext
*dc
)
1784 DIS(fprintf (logfile
, "abs $r%u, $r%u\n",
1786 cris_cc_mask(dc
, CC_MASK_NZ
);
1787 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, 4, 0, cpu_T
[1]);
1789 /* TODO: consider a branch free approach. */
1790 l1
= gen_new_label();
1791 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_T
[1], 0, l1
);
1792 tcg_gen_neg_tl(cpu_T
[1], cpu_T
[1]);
1794 cris_alu(dc
, CC_OP_MOVE
,
1795 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
1799 static unsigned int dec_add_r(DisasContext
*dc
)
1801 int size
= memsize_zz(dc
);
1802 DIS(fprintf (logfile
, "add.%c $r%u, $r%u\n",
1803 memsize_char(size
), dc
->op1
, dc
->op2
));
1804 cris_cc_mask(dc
, CC_MASK_NZVC
);
1805 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1807 cris_alu(dc
, CC_OP_ADD
,
1808 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1812 static unsigned int dec_addc_r(DisasContext
*dc
)
1814 DIS(fprintf (logfile
, "addc $r%u, $r%u\n",
1816 cris_evaluate_flags(dc
);
1817 cris_cc_mask(dc
, CC_MASK_NZVC
);
1818 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1819 cris_alu(dc
, CC_OP_ADDC
,
1820 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
1824 static unsigned int dec_mcp_r(DisasContext
*dc
)
1826 DIS(fprintf (logfile
, "mcp $p%u, $r%u\n",
1828 cris_evaluate_flags(dc
);
1829 cris_cc_mask(dc
, CC_MASK_RNZV
);
1830 cris_alu(dc
, CC_OP_MCP
,
1831 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_PR
[dc
->op2
], 4);
1836 static char * swapmode_name(int mode
, char *modename
) {
1839 modename
[i
++] = 'n';
1841 modename
[i
++] = 'w';
1843 modename
[i
++] = 'b';
1845 modename
[i
++] = 'r';
1851 static unsigned int dec_swap_r(DisasContext
*dc
)
1856 DIS(fprintf (logfile
, "swap%s $r%u\n",
1857 swapmode_name(dc
->op2
, modename
), dc
->op1
));
1859 cris_cc_mask(dc
, CC_MASK_NZ
);
1860 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1862 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
1864 t_gen_swapw(cpu_T
[0], cpu_T
[0]);
1866 t_gen_swapb(cpu_T
[0], cpu_T
[0]);
1868 t_gen_swapr(cpu_T
[0], cpu_T
[0]);
1869 cris_alu(dc
, CC_OP_MOVE
,
1870 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_T
[0], 4);
1875 static unsigned int dec_or_r(DisasContext
*dc
)
1877 int size
= memsize_zz(dc
);
1878 DIS(fprintf (logfile
, "or.%c $r%u, $r%u\n",
1879 memsize_char(size
), dc
->op1
, dc
->op2
));
1880 cris_cc_mask(dc
, CC_MASK_NZ
);
1881 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1883 cris_alu(dc
, CC_OP_OR
,
1884 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1888 static unsigned int dec_addi_r(DisasContext
*dc
)
1890 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u\n",
1891 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1892 cris_cc_mask(dc
, 0);
1893 tcg_gen_shl_tl(cpu_T
[0], cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1894 tcg_gen_add_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_T
[0]);
1898 static unsigned int dec_addi_acr(DisasContext
*dc
)
1900 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u, $acr\n",
1901 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1902 cris_cc_mask(dc
, 0);
1903 tcg_gen_shl_tl(cpu_T
[0], cpu_R
[dc
->op2
], tcg_const_tl(dc
->zzsize
));
1904 tcg_gen_add_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op1
], cpu_T
[0]);
1908 static unsigned int dec_neg_r(DisasContext
*dc
)
1910 int size
= memsize_zz(dc
);
1911 DIS(fprintf (logfile
, "neg.%c $r%u, $r%u\n",
1912 memsize_char(size
), dc
->op1
, dc
->op2
));
1913 cris_cc_mask(dc
, CC_MASK_NZVC
);
1914 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1916 cris_alu(dc
, CC_OP_NEG
,
1917 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1921 static unsigned int dec_btst_r(DisasContext
*dc
)
1923 DIS(fprintf (logfile
, "btst $r%u, $r%u\n",
1925 cris_cc_mask(dc
, CC_MASK_NZ
);
1926 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1928 cris_alu(dc
, CC_OP_BTST
,
1929 cpu_T
[0], cpu_T
[0], cpu_T
[1], 4);
1930 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1931 t_gen_mov_preg_TN(dc
, PR_CCS
, cpu_T
[0]);
1932 dc
->flags_uptodate
= 1;
1936 static unsigned int dec_sub_r(DisasContext
*dc
)
1938 int size
= memsize_zz(dc
);
1939 DIS(fprintf (logfile
, "sub.%c $r%u, $r%u\n",
1940 memsize_char(size
), dc
->op1
, dc
->op2
));
1941 cris_cc_mask(dc
, CC_MASK_NZVC
);
1942 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1943 cris_alu(dc
, CC_OP_SUB
,
1944 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], size
);
1948 /* Zero extension. From size to dword. */
1949 static unsigned int dec_movu_r(DisasContext
*dc
)
1951 int size
= memsize_z(dc
);
1952 DIS(fprintf (logfile
, "movu.%c $r%u, $r%u\n",
1956 cris_cc_mask(dc
, CC_MASK_NZ
);
1957 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0, cpu_T
[1]);
1958 cris_alu(dc
, CC_OP_MOVE
,
1959 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
1963 /* Sign extension. From size to dword. */
1964 static unsigned int dec_movs_r(DisasContext
*dc
)
1966 int size
= memsize_z(dc
);
1967 DIS(fprintf (logfile
, "movs.%c $r%u, $r%u\n",
1971 cris_cc_mask(dc
, CC_MASK_NZ
);
1972 /* Size can only be qi or hi. */
1973 t_gen_sext(cpu_T
[1], cpu_R
[dc
->op1
], size
);
1974 cris_alu(dc
, CC_OP_MOVE
,
1975 cpu_R
[dc
->op2
], cpu_R
[dc
->op1
], cpu_T
[1], 4);
1979 /* zero extension. From size to dword. */
1980 static unsigned int dec_addu_r(DisasContext
*dc
)
1982 int size
= memsize_z(dc
);
1983 DIS(fprintf (logfile
, "addu.%c $r%u, $r%u\n",
1987 cris_cc_mask(dc
, CC_MASK_NZVC
);
1988 /* Size can only be qi or hi. */
1989 t_gen_zext(cpu_T
[1], cpu_R
[dc
->op1
], size
);
1990 cris_alu(dc
, CC_OP_ADD
,
1991 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
1995 /* Sign extension. From size to dword. */
1996 static unsigned int dec_adds_r(DisasContext
*dc
)
1998 int size
= memsize_z(dc
);
1999 DIS(fprintf (logfile
, "adds.%c $r%u, $r%u\n",
2003 cris_cc_mask(dc
, CC_MASK_NZVC
);
2004 /* Size can only be qi or hi. */
2005 t_gen_sext(cpu_T
[1], cpu_R
[dc
->op1
], size
);
2006 cris_alu(dc
, CC_OP_ADD
,
2007 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2011 /* Zero extension. From size to dword. */
2012 static unsigned int dec_subu_r(DisasContext
*dc
)
2014 int size
= memsize_z(dc
);
2015 DIS(fprintf (logfile
, "subu.%c $r%u, $r%u\n",
2019 cris_cc_mask(dc
, CC_MASK_NZVC
);
2020 /* Size can only be qi or hi. */
2021 t_gen_zext(cpu_T
[1], cpu_R
[dc
->op1
], size
);
2022 cris_alu(dc
, CC_OP_SUB
,
2023 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2027 /* Sign extension. From size to dword. */
2028 static unsigned int dec_subs_r(DisasContext
*dc
)
2030 int size
= memsize_z(dc
);
2031 DIS(fprintf (logfile
, "subs.%c $r%u, $r%u\n",
2035 cris_cc_mask(dc
, CC_MASK_NZVC
);
2036 /* Size can only be qi or hi. */
2037 t_gen_sext(cpu_T
[1], cpu_R
[dc
->op1
], size
);
2038 cris_alu(dc
, CC_OP_SUB
,
2039 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2043 static unsigned int dec_setclrf(DisasContext
*dc
)
2046 int set
= (~dc
->opcode
>> 2) & 1;
2048 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
2049 | EXTRACT_FIELD(dc
->ir
, 0, 3);
2050 if (set
&& flags
== 0) {
2051 DIS(fprintf (logfile
, "nop\n"));
2053 } else if (!set
&& (flags
& 0x20)) {
2054 DIS(fprintf (logfile
, "di\n"));
2057 DIS(fprintf (logfile
, "%sf %x\n",
2058 set
? "set" : "clr",
2062 /* User space is not allowed to touch these. Silently ignore. */
2063 if (dc
->tb_flags
& U_FLAG
) {
2064 flags
&= ~(I_FLAG
| U_FLAG
);
2067 if (flags
& X_FLAG
) {
2068 dc
->flagx_known
= 1;
2070 dc
->flags_x
= X_FLAG
;
2075 /* Break the TB if the P flag changes. */
2076 if (flags
& P_FLAG
) {
2077 if ((set
&& !(dc
->tb_flags
& P_FLAG
))
2078 || (!set
&& (dc
->tb_flags
& P_FLAG
))) {
2079 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
2080 dc
->is_jmp
= DISAS_UPDATE
;
2081 dc
->cpustate_changed
= 1;
2086 /* Simply decode the flags. */
2087 cris_evaluate_flags (dc
);
2088 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2089 cris_update_cc_x(dc
);
2090 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
2093 if (!(dc
->tb_flags
& U_FLAG
) && (flags
& U_FLAG
)) {
2094 /* Enter user mode. */
2095 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
2096 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
2097 dc
->cpustate_changed
= 1;
2099 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
2102 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
2104 dc
->flags_uptodate
= 1;
2109 static unsigned int dec_move_rs(DisasContext
*dc
)
2111 DIS(fprintf (logfile
, "move $r%u, $s%u\n", dc
->op1
, dc
->op2
));
2112 cris_cc_mask(dc
, 0);
2113 tcg_gen_helper_0_2(helper_movl_sreg_reg
,
2114 tcg_const_tl(dc
->op2
), tcg_const_tl(dc
->op1
));
2117 static unsigned int dec_move_sr(DisasContext
*dc
)
2119 DIS(fprintf (logfile
, "move $s%u, $r%u\n", dc
->op2
, dc
->op1
));
2120 cris_cc_mask(dc
, 0);
2121 tcg_gen_helper_0_2(helper_movl_reg_sreg
,
2122 tcg_const_tl(dc
->op1
), tcg_const_tl(dc
->op2
));
2126 static unsigned int dec_move_rp(DisasContext
*dc
)
2128 DIS(fprintf (logfile
, "move $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2129 cris_cc_mask(dc
, 0);
2131 if (dc
->op2
== PR_CCS
) {
2132 cris_evaluate_flags(dc
);
2133 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
2134 if (dc
->tb_flags
& U_FLAG
) {
2135 /* User space is not allowed to touch all flags. */
2136 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x39f);
2137 tcg_gen_andi_tl(cpu_T
[1], cpu_PR
[PR_CCS
], ~0x39f);
2138 tcg_gen_or_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
2142 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
2144 t_gen_mov_preg_TN(dc
, dc
->op2
, cpu_T
[0]);
2145 if (dc
->op2
== PR_CCS
) {
2146 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2147 dc
->flags_uptodate
= 1;
2151 static unsigned int dec_move_pr(DisasContext
*dc
)
2153 DIS(fprintf (logfile
, "move $p%u, $r%u\n", dc
->op1
, dc
->op2
));
2154 cris_cc_mask(dc
, 0);
2156 if (dc
->op2
== PR_CCS
)
2157 cris_evaluate_flags(dc
);
2159 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
2160 cris_alu(dc
, CC_OP_MOVE
,
2161 cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], cpu_T
[1],
2162 preg_sizes
[dc
->op2
]);
2166 static unsigned int dec_move_mr(DisasContext
*dc
)
2168 int memsize
= memsize_zz(dc
);
2170 DIS(fprintf (logfile
, "move.%c [$r%u%s, $r%u\n",
2171 memsize_char(memsize
),
2172 dc
->op1
, dc
->postinc
? "+]" : "]",
2176 insn_len
= dec_prep_move_m(dc
, 0, 4, cpu_R
[dc
->op2
]);
2177 cris_cc_mask(dc
, CC_MASK_NZ
);
2178 cris_update_cc_op(dc
, CC_OP_MOVE
, 4);
2179 cris_update_cc_x(dc
);
2180 cris_update_result(dc
, cpu_R
[dc
->op2
]);
2183 insn_len
= dec_prep_move_m(dc
, 0, memsize
, cpu_T
[1]);
2184 cris_cc_mask(dc
, CC_MASK_NZ
);
2185 cris_alu(dc
, CC_OP_MOVE
,
2186 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], memsize
);
2188 do_postinc(dc
, memsize
);
2192 static unsigned int dec_movs_m(DisasContext
*dc
)
2194 int memsize
= memsize_z(dc
);
2196 DIS(fprintf (logfile
, "movs.%c [$r%u%s, $r%u\n",
2197 memsize_char(memsize
),
2198 dc
->op1
, dc
->postinc
? "+]" : "]",
2202 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2203 cris_cc_mask(dc
, CC_MASK_NZ
);
2204 cris_alu(dc
, CC_OP_MOVE
,
2205 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2206 do_postinc(dc
, memsize
);
2210 static unsigned int dec_addu_m(DisasContext
*dc
)
2212 int memsize
= memsize_z(dc
);
2214 DIS(fprintf (logfile
, "addu.%c [$r%u%s, $r%u\n",
2215 memsize_char(memsize
),
2216 dc
->op1
, dc
->postinc
? "+]" : "]",
2220 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2221 cris_cc_mask(dc
, CC_MASK_NZVC
);
2222 cris_alu(dc
, CC_OP_ADD
,
2223 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2224 do_postinc(dc
, memsize
);
2228 static unsigned int dec_adds_m(DisasContext
*dc
)
2230 int memsize
= memsize_z(dc
);
2232 DIS(fprintf (logfile
, "adds.%c [$r%u%s, $r%u\n",
2233 memsize_char(memsize
),
2234 dc
->op1
, dc
->postinc
? "+]" : "]",
2238 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2239 cris_cc_mask(dc
, CC_MASK_NZVC
);
2240 cris_alu(dc
, CC_OP_ADD
,
2241 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2242 do_postinc(dc
, memsize
);
2246 static unsigned int dec_subu_m(DisasContext
*dc
)
2248 int memsize
= memsize_z(dc
);
2250 DIS(fprintf (logfile
, "subu.%c [$r%u%s, $r%u\n",
2251 memsize_char(memsize
),
2252 dc
->op1
, dc
->postinc
? "+]" : "]",
2256 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2257 cris_cc_mask(dc
, CC_MASK_NZVC
);
2258 cris_alu(dc
, CC_OP_SUB
,
2259 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2260 do_postinc(dc
, memsize
);
2264 static unsigned int dec_subs_m(DisasContext
*dc
)
2266 int memsize
= memsize_z(dc
);
2268 DIS(fprintf (logfile
, "subs.%c [$r%u%s, $r%u\n",
2269 memsize_char(memsize
),
2270 dc
->op1
, dc
->postinc
? "+]" : "]",
2274 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2275 cris_cc_mask(dc
, CC_MASK_NZVC
);
2276 cris_alu(dc
, CC_OP_SUB
,
2277 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2278 do_postinc(dc
, memsize
);
2282 static unsigned int dec_movu_m(DisasContext
*dc
)
2284 int memsize
= memsize_z(dc
);
2287 DIS(fprintf (logfile
, "movu.%c [$r%u%s, $r%u\n",
2288 memsize_char(memsize
),
2289 dc
->op1
, dc
->postinc
? "+]" : "]",
2292 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2293 cris_cc_mask(dc
, CC_MASK_NZ
);
2294 cris_alu(dc
, CC_OP_MOVE
,
2295 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2296 do_postinc(dc
, memsize
);
2300 static unsigned int dec_cmpu_m(DisasContext
*dc
)
2302 int memsize
= memsize_z(dc
);
2304 DIS(fprintf (logfile
, "cmpu.%c [$r%u%s, $r%u\n",
2305 memsize_char(memsize
),
2306 dc
->op1
, dc
->postinc
? "+]" : "]",
2309 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2310 cris_cc_mask(dc
, CC_MASK_NZVC
);
2311 cris_alu(dc
, CC_OP_CMP
,
2312 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1], 4);
2313 do_postinc(dc
, memsize
);
2317 static unsigned int dec_cmps_m(DisasContext
*dc
)
2319 int memsize
= memsize_z(dc
);
2321 DIS(fprintf (logfile
, "cmps.%c [$r%u%s, $r%u\n",
2322 memsize_char(memsize
),
2323 dc
->op1
, dc
->postinc
? "+]" : "]",
2326 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2327 cris_cc_mask(dc
, CC_MASK_NZVC
);
2328 cris_alu(dc
, CC_OP_CMP
,
2329 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1],
2331 do_postinc(dc
, memsize
);
2335 static unsigned int dec_cmp_m(DisasContext
*dc
)
2337 int memsize
= memsize_zz(dc
);
2339 DIS(fprintf (logfile
, "cmp.%c [$r%u%s, $r%u\n",
2340 memsize_char(memsize
),
2341 dc
->op1
, dc
->postinc
? "+]" : "]",
2344 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2345 cris_cc_mask(dc
, CC_MASK_NZVC
);
2346 cris_alu(dc
, CC_OP_CMP
,
2347 cpu_R
[dc
->op2
], cpu_R
[dc
->op2
], cpu_T
[1],
2349 do_postinc(dc
, memsize
);
2353 static unsigned int dec_test_m(DisasContext
*dc
)
2355 int memsize
= memsize_zz(dc
);
2357 DIS(fprintf (logfile
, "test.%d [$r%u%s] op2=%x\n",
2358 memsize_char(memsize
),
2359 dc
->op1
, dc
->postinc
? "+]" : "]",
2362 cris_evaluate_flags(dc
);
2364 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2365 cris_cc_mask(dc
, CC_MASK_NZ
);
2366 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2368 cris_alu(dc
, CC_OP_CMP
,
2369 cpu_R
[dc
->op2
], cpu_T
[1], tcg_const_tl(0),
2371 do_postinc(dc
, memsize
);
2375 static unsigned int dec_and_m(DisasContext
*dc
)
2377 int memsize
= memsize_zz(dc
);
2379 DIS(fprintf (logfile
, "and.%d [$r%u%s, $r%u\n",
2380 memsize_char(memsize
),
2381 dc
->op1
, dc
->postinc
? "+]" : "]",
2384 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2385 cris_cc_mask(dc
, CC_MASK_NZ
);
2386 cris_alu(dc
, CC_OP_AND
,
2387 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1],
2389 do_postinc(dc
, memsize
);
2393 static unsigned int dec_add_m(DisasContext
*dc
)
2395 int memsize
= memsize_zz(dc
);
2397 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2398 memsize_char(memsize
),
2399 dc
->op1
, dc
->postinc
? "+]" : "]",
2402 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2403 cris_cc_mask(dc
, CC_MASK_NZVC
);
2404 cris_alu(dc
, CC_OP_ADD
,
2405 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1],
2407 do_postinc(dc
, memsize
);
2411 static unsigned int dec_addo_m(DisasContext
*dc
)
2413 int memsize
= memsize_zz(dc
);
2415 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2416 memsize_char(memsize
),
2417 dc
->op1
, dc
->postinc
? "+]" : "]",
2420 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2421 cris_cc_mask(dc
, 0);
2422 cris_alu(dc
, CC_OP_ADD
,
2423 cpu_R
[R_ACR
], cpu_T
[0], cpu_T
[1], 4);
2424 do_postinc(dc
, memsize
);
2428 static unsigned int dec_bound_m(DisasContext
*dc
)
2430 int memsize
= memsize_zz(dc
);
2432 DIS(fprintf (logfile
, "bound.%d [$r%u%s, $r%u\n",
2433 memsize_char(memsize
),
2434 dc
->op1
, dc
->postinc
? "+]" : "]",
2437 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2438 cris_cc_mask(dc
, CC_MASK_NZ
);
2439 cris_alu(dc
, CC_OP_BOUND
,
2440 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
2441 do_postinc(dc
, memsize
);
2445 static unsigned int dec_addc_mr(DisasContext
*dc
)
2448 DIS(fprintf (logfile
, "addc [$r%u%s, $r%u\n",
2449 dc
->op1
, dc
->postinc
? "+]" : "]",
2452 cris_evaluate_flags(dc
);
2453 insn_len
= dec_prep_alu_m(dc
, 0, 4);
2454 cris_cc_mask(dc
, CC_MASK_NZVC
);
2455 cris_alu(dc
, CC_OP_ADDC
,
2456 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], 4);
2461 static unsigned int dec_sub_m(DisasContext
*dc
)
2463 int memsize
= memsize_zz(dc
);
2465 DIS(fprintf (logfile
, "sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2466 memsize_char(memsize
),
2467 dc
->op1
, dc
->postinc
? "+]" : "]",
2468 dc
->op2
, dc
->ir
, dc
->zzsize
));
2470 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2471 cris_cc_mask(dc
, CC_MASK_NZVC
);
2472 cris_alu(dc
, CC_OP_SUB
,
2473 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], memsize
);
2474 do_postinc(dc
, memsize
);
2478 static unsigned int dec_or_m(DisasContext
*dc
)
2480 int memsize
= memsize_zz(dc
);
2482 DIS(fprintf (logfile
, "or.%d [$r%u%s, $r%u pc=%x\n",
2483 memsize_char(memsize
),
2484 dc
->op1
, dc
->postinc
? "+]" : "]",
2487 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2488 cris_cc_mask(dc
, CC_MASK_NZ
);
2489 cris_alu(dc
, CC_OP_OR
,
2490 cpu_R
[dc
->op2
], cpu_T
[0], cpu_T
[1], memsize_zz(dc
));
2491 do_postinc(dc
, memsize
);
2495 static unsigned int dec_move_mp(DisasContext
*dc
)
2497 int memsize
= memsize_zz(dc
);
2500 DIS(fprintf (logfile
, "move.%c [$r%u%s, $p%u\n",
2501 memsize_char(memsize
),
2503 dc
->postinc
? "+]" : "]",
2506 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2507 cris_cc_mask(dc
, 0);
2508 if (dc
->op2
== PR_CCS
) {
2509 cris_evaluate_flags(dc
);
2510 if (dc
->tb_flags
& U_FLAG
) {
2511 /* User space is not allowed to touch all flags. */
2512 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 0x39f);
2513 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], ~0x39f);
2514 tcg_gen_or_tl(cpu_T
[1], cpu_T
[0], cpu_T
[1]);
2518 t_gen_mov_preg_TN(dc
, dc
->op2
, cpu_T
[1]);
2520 do_postinc(dc
, memsize
);
2524 static unsigned int dec_move_pm(DisasContext
*dc
)
2528 memsize
= preg_sizes
[dc
->op2
];
2530 DIS(fprintf (logfile
, "move.%c $p%u, [$r%u%s\n",
2531 memsize_char(memsize
),
2532 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]"));
2534 /* prepare store. Address in T0, value in T1. */
2535 if (dc
->op2
== PR_CCS
)
2536 cris_evaluate_flags(dc
);
2537 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
2538 cris_flush_cc_state(dc
);
2539 gen_store(dc
, cpu_R
[dc
->op1
], cpu_T
[1], memsize
);
2541 cris_cc_mask(dc
, 0);
2543 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2547 static unsigned int dec_movem_mr(DisasContext
*dc
)
2552 DIS(fprintf (logfile
, "movem [$r%u%s, $r%u\n", dc
->op1
,
2553 dc
->postinc
? "+]" : "]", dc
->op2
));
2555 /* fetch the address into T0 and T1. */
2556 cris_flush_cc_state(dc
);
2557 for (i
= 0; i
<= dc
->op2
; i
++) {
2558 tmp
[i
] = tcg_temp_new(TCG_TYPE_TL
);
2559 /* Perform the load onto regnum i. Always dword wide. */
2560 tcg_gen_addi_tl(cpu_T
[0], cpu_R
[dc
->op1
], i
* 4);
2561 gen_load(dc
, tmp
[i
], cpu_T
[0], 4, 0);
2564 for (i
= 0; i
<= dc
->op2
; i
++) {
2565 tcg_gen_mov_tl(cpu_R
[i
], tmp
[i
]);
2566 tcg_temp_free(tmp
[i
]);
2569 /* writeback the updated pointer value. */
2571 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], i
* 4);
2573 /* gen_load might want to evaluate the previous insns flags. */
2574 cris_cc_mask(dc
, 0);
2578 static unsigned int dec_movem_rm(DisasContext
*dc
)
2583 DIS(fprintf (logfile
, "movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2584 dc
->postinc
? "+]" : "]"));
2586 cris_flush_cc_state(dc
);
2588 tmp
= tcg_temp_new(TCG_TYPE_TL
);
2589 tcg_gen_movi_tl(tmp
, 4);
2590 tcg_gen_mov_tl(cpu_T
[0], cpu_R
[dc
->op1
]);
2591 for (i
= 0; i
<= dc
->op2
; i
++) {
2592 /* Displace addr. */
2593 /* Perform the store. */
2594 gen_store(dc
, cpu_T
[0], cpu_R
[i
], 4);
2595 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], tmp
);
2598 tcg_gen_mov_tl(cpu_R
[dc
->op1
], cpu_T
[0]);
2599 cris_cc_mask(dc
, 0);
2604 static unsigned int dec_move_rm(DisasContext
*dc
)
2608 memsize
= memsize_zz(dc
);
2610 DIS(fprintf (logfile
, "move.%d $r%u, [$r%u]\n",
2611 memsize
, dc
->op2
, dc
->op1
));
2613 /* prepare store. */
2614 cris_flush_cc_state(dc
);
2615 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2618 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2619 cris_cc_mask(dc
, 0);
2623 static unsigned int dec_lapcq(DisasContext
*dc
)
2625 DIS(fprintf (logfile
, "lapcq %x, $r%u\n",
2626 dc
->pc
+ dc
->op1
*2, dc
->op2
));
2627 cris_cc_mask(dc
, 0);
2628 tcg_gen_movi_tl(cpu_R
[dc
->op2
], dc
->pc
+ dc
->op1
* 2);
2632 static unsigned int dec_lapc_im(DisasContext
*dc
)
2640 cris_cc_mask(dc
, 0);
2641 imm
= ldl_code(dc
->pc
+ 2);
2642 DIS(fprintf (logfile
, "lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
));
2646 t_gen_mov_reg_TN(rd
, tcg_const_tl(pc
));
2650 /* Jump to special reg. */
2651 static unsigned int dec_jump_p(DisasContext
*dc
)
2653 DIS(fprintf (logfile
, "jump $p%u\n", dc
->op2
));
2655 if (dc
->op2
== PR_CCS
)
2656 cris_evaluate_flags(dc
);
2657 t_gen_mov_TN_preg(cpu_T
[0], dc
->op2
);
2658 /* rete will often have low bit set to indicate delayslot. */
2659 tcg_gen_andi_tl(env_btarget
, cpu_T
[0], ~1);
2660 cris_cc_mask(dc
, 0);
2661 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2665 /* Jump and save. */
2666 static unsigned int dec_jas_r(DisasContext
*dc
)
2668 DIS(fprintf (logfile
, "jas $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2669 cris_cc_mask(dc
, 0);
2670 /* Store the return address in Pd. */
2671 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2674 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4));
2676 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2680 static unsigned int dec_jas_im(DisasContext
*dc
)
2684 imm
= ldl_code(dc
->pc
+ 2);
2686 DIS(fprintf (logfile
, "jas 0x%x\n", imm
));
2687 cris_cc_mask(dc
, 0);
2688 /* Store the return address in Pd. */
2689 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2692 cris_prepare_jmp(dc
, JMP_DIRECT
);
2696 static unsigned int dec_jasc_im(DisasContext
*dc
)
2700 imm
= ldl_code(dc
->pc
+ 2);
2702 DIS(fprintf (logfile
, "jasc 0x%x\n", imm
));
2703 cris_cc_mask(dc
, 0);
2704 /* Store the return address in Pd. */
2705 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8 + 4));
2708 cris_prepare_jmp(dc
, JMP_DIRECT
);
2712 static unsigned int dec_jasc_r(DisasContext
*dc
)
2714 DIS(fprintf (logfile
, "jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2715 cris_cc_mask(dc
, 0);
2716 /* Store the return address in Pd. */
2717 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2718 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 4 + 4));
2719 cris_prepare_jmp(dc
, JMP_INDIRECT
);
2723 static unsigned int dec_bcc_im(DisasContext
*dc
)
2726 uint32_t cond
= dc
->op2
;
2728 offset
= ldsw_code(dc
->pc
+ 2);
2730 DIS(fprintf (logfile
, "b%s %d pc=%x dst=%x\n",
2731 cc_name(cond
), offset
,
2732 dc
->pc
, dc
->pc
+ offset
));
2734 cris_cc_mask(dc
, 0);
2735 /* op2 holds the condition-code. */
2736 cris_prepare_cc_branch (dc
, offset
, cond
);
2740 static unsigned int dec_bas_im(DisasContext
*dc
)
2745 simm
= ldl_code(dc
->pc
+ 2);
2747 DIS(fprintf (logfile
, "bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2748 cris_cc_mask(dc
, 0);
2749 /* Store the return address in Pd. */
2750 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2752 dc
->jmp_pc
= dc
->pc
+ simm
;
2753 cris_prepare_jmp(dc
, JMP_DIRECT
);
2757 static unsigned int dec_basc_im(DisasContext
*dc
)
2760 simm
= ldl_code(dc
->pc
+ 2);
2762 DIS(fprintf (logfile
, "basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2763 cris_cc_mask(dc
, 0);
2764 /* Store the return address in Pd. */
2765 t_gen_mov_preg_TN(dc
, dc
->op2
, tcg_const_tl(dc
->pc
+ 12));
2767 dc
->jmp_pc
= dc
->pc
+ simm
;
2768 cris_prepare_jmp(dc
, JMP_DIRECT
);
2772 static unsigned int dec_rfe_etc(DisasContext
*dc
)
2774 DIS(fprintf (logfile
, "rfe_etc opc=%x pc=0x%x op1=%d op2=%d\n",
2775 dc
->opcode
, dc
->pc
, dc
->op1
, dc
->op2
));
2777 cris_cc_mask(dc
, 0);
2779 if (dc
->op2
== 15) /* ignore halt. */
2782 switch (dc
->op2
& 7) {
2785 cris_evaluate_flags(dc
);
2786 tcg_gen_helper_0_0(helper_rfe
);
2787 dc
->is_jmp
= DISAS_UPDATE
;
2791 cris_evaluate_flags(dc
);
2792 tcg_gen_helper_0_0(helper_rfn
);
2793 dc
->is_jmp
= DISAS_UPDATE
;
2797 tcg_gen_movi_tl(env_pc
, dc
->pc
);
2798 /* Breaks start at 16 in the exception vector. */
2799 t_gen_mov_env_TN(trap_vector
,
2800 tcg_const_tl(dc
->op1
+ 16));
2801 t_gen_raise_exception(EXCP_BREAK
);
2802 dc
->is_jmp
= DISAS_UPDATE
;
2805 printf ("op2=%x\n", dc
->op2
);
2813 static unsigned int dec_ftag_fidx_d_m(DisasContext
*dc
)
2815 /* Ignore D-cache flushes. */
2819 static unsigned int dec_ftag_fidx_i_m(DisasContext
*dc
)
2821 /* Ignore I-cache flushes. */
2825 static unsigned int dec_null(DisasContext
*dc
)
2827 printf ("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2828 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2834 struct decoder_info
{
2839 unsigned int (*dec
)(DisasContext
*dc
);
2841 /* Order matters here. */
2842 {DEC_MOVEQ
, dec_moveq
},
2843 {DEC_BTSTQ
, dec_btstq
},
2844 {DEC_CMPQ
, dec_cmpq
},
2845 {DEC_ADDOQ
, dec_addoq
},
2846 {DEC_ADDQ
, dec_addq
},
2847 {DEC_SUBQ
, dec_subq
},
2848 {DEC_ANDQ
, dec_andq
},
2850 {DEC_ASRQ
, dec_asrq
},
2851 {DEC_LSLQ
, dec_lslq
},
2852 {DEC_LSRQ
, dec_lsrq
},
2853 {DEC_BCCQ
, dec_bccq
},
2855 {DEC_BCC_IM
, dec_bcc_im
},
2856 {DEC_JAS_IM
, dec_jas_im
},
2857 {DEC_JAS_R
, dec_jas_r
},
2858 {DEC_JASC_IM
, dec_jasc_im
},
2859 {DEC_JASC_R
, dec_jasc_r
},
2860 {DEC_BAS_IM
, dec_bas_im
},
2861 {DEC_BASC_IM
, dec_basc_im
},
2862 {DEC_JUMP_P
, dec_jump_p
},
2863 {DEC_LAPC_IM
, dec_lapc_im
},
2864 {DEC_LAPCQ
, dec_lapcq
},
2866 {DEC_RFE_ETC
, dec_rfe_etc
},
2867 {DEC_ADDC_MR
, dec_addc_mr
},
2869 {DEC_MOVE_MP
, dec_move_mp
},
2870 {DEC_MOVE_PM
, dec_move_pm
},
2871 {DEC_MOVEM_MR
, dec_movem_mr
},
2872 {DEC_MOVEM_RM
, dec_movem_rm
},
2873 {DEC_MOVE_PR
, dec_move_pr
},
2874 {DEC_SCC_R
, dec_scc_r
},
2875 {DEC_SETF
, dec_setclrf
},
2876 {DEC_CLEARF
, dec_setclrf
},
2878 {DEC_MOVE_SR
, dec_move_sr
},
2879 {DEC_MOVE_RP
, dec_move_rp
},
2880 {DEC_SWAP_R
, dec_swap_r
},
2881 {DEC_ABS_R
, dec_abs_r
},
2882 {DEC_LZ_R
, dec_lz_r
},
2883 {DEC_MOVE_RS
, dec_move_rs
},
2884 {DEC_BTST_R
, dec_btst_r
},
2885 {DEC_ADDC_R
, dec_addc_r
},
2887 {DEC_DSTEP_R
, dec_dstep_r
},
2888 {DEC_XOR_R
, dec_xor_r
},
2889 {DEC_MCP_R
, dec_mcp_r
},
2890 {DEC_CMP_R
, dec_cmp_r
},
2892 {DEC_ADDI_R
, dec_addi_r
},
2893 {DEC_ADDI_ACR
, dec_addi_acr
},
2895 {DEC_ADD_R
, dec_add_r
},
2896 {DEC_SUB_R
, dec_sub_r
},
2898 {DEC_ADDU_R
, dec_addu_r
},
2899 {DEC_ADDS_R
, dec_adds_r
},
2900 {DEC_SUBU_R
, dec_subu_r
},
2901 {DEC_SUBS_R
, dec_subs_r
},
2902 {DEC_LSL_R
, dec_lsl_r
},
2904 {DEC_AND_R
, dec_and_r
},
2905 {DEC_OR_R
, dec_or_r
},
2906 {DEC_BOUND_R
, dec_bound_r
},
2907 {DEC_ASR_R
, dec_asr_r
},
2908 {DEC_LSR_R
, dec_lsr_r
},
2910 {DEC_MOVU_R
, dec_movu_r
},
2911 {DEC_MOVS_R
, dec_movs_r
},
2912 {DEC_NEG_R
, dec_neg_r
},
2913 {DEC_MOVE_R
, dec_move_r
},
2915 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2916 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2918 {DEC_MULS_R
, dec_muls_r
},
2919 {DEC_MULU_R
, dec_mulu_r
},
2921 {DEC_ADDU_M
, dec_addu_m
},
2922 {DEC_ADDS_M
, dec_adds_m
},
2923 {DEC_SUBU_M
, dec_subu_m
},
2924 {DEC_SUBS_M
, dec_subs_m
},
2926 {DEC_CMPU_M
, dec_cmpu_m
},
2927 {DEC_CMPS_M
, dec_cmps_m
},
2928 {DEC_MOVU_M
, dec_movu_m
},
2929 {DEC_MOVS_M
, dec_movs_m
},
2931 {DEC_CMP_M
, dec_cmp_m
},
2932 {DEC_ADDO_M
, dec_addo_m
},
2933 {DEC_BOUND_M
, dec_bound_m
},
2934 {DEC_ADD_M
, dec_add_m
},
2935 {DEC_SUB_M
, dec_sub_m
},
2936 {DEC_AND_M
, dec_and_m
},
2937 {DEC_OR_M
, dec_or_m
},
2938 {DEC_MOVE_RM
, dec_move_rm
},
2939 {DEC_TEST_M
, dec_test_m
},
2940 {DEC_MOVE_MR
, dec_move_mr
},
2945 static inline unsigned int
2946 cris_decoder(DisasContext
*dc
)
2948 unsigned int insn_len
= 2;
2951 /* Load a halfword onto the instruction register. */
2952 dc
->ir
= lduw_code(dc
->pc
);
2954 /* Now decode it. */
2955 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
2956 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
2957 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
2958 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
2959 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
2960 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
2962 /* Large switch for all insns. */
2963 for (i
= 0; i
< sizeof decinfo
/ sizeof decinfo
[0]; i
++) {
2964 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
)
2966 insn_len
= decinfo
[i
].dec(dc
);
2974 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
2977 if (env
->nb_breakpoints
> 0) {
2978 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
2979 if (env
->breakpoints
[j
] == dc
->pc
) {
2980 cris_evaluate_flags (dc
);
2981 tcg_gen_movi_tl(env_pc
, dc
->pc
);
2982 t_gen_raise_exception(EXCP_DEBUG
);
2983 dc
->is_jmp
= DISAS_UPDATE
;
2991 * Delay slots on QEMU/CRIS.
2993 * If an exception hits on a delayslot, the core will let ERP (the Exception
2994 * Return Pointer) point to the branch (the previous) insn and set the lsb to
2995 * to give SW a hint that the exception actually hit on the dslot.
2997 * CRIS expects all PC addresses to be 16-bit aligned. The lsb is ignored by
2998 * the core and any jmp to an odd addresses will mask off that lsb. It is
2999 * simply there to let sw know there was an exception on a dslot.
3001 * When the software returns from an exception, the branch will re-execute.
3002 * On QEMU care needs to be taken when a branch+delayslot sequence is broken
3003 * and the branch and delayslot dont share pages.
3005 * The TB contaning the branch insn will set up env->btarget and evaluate
3006 * env->btaken. When the translation loop exits we will note that the branch
3007 * sequence is broken and let env->dslot be the size of the branch insn (those
3010 * The TB contaning the delayslot will have the PC of its real insn (i.e no lsb
3011 * set). It will also expect to have env->dslot setup with the size of the
3012 * delay slot so that env->pc - env->dslot point to the branch insn. This TB
3013 * will execute the dslot and take the branch, either to btarget or just one
3016 * When exceptions occur, we check for env->dslot in do_interrupt to detect
3017 * broken branch sequences and setup $erp accordingly (i.e let it point to the
3018 * branch and set lsb). Then env->dslot gets cleared so that the exception
3019 * handler can enter. When returning from exceptions (jump $erp) the lsb gets
3020 * masked off and we will reexecute the branch insn.
3024 /* generate intermediate code for basic block 'tb'. */
3026 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
3029 uint16_t *gen_opc_end
;
3031 unsigned int insn_len
;
3033 struct DisasContext ctx
;
3034 struct DisasContext
*dc
= &ctx
;
3035 uint32_t next_page_start
;
3043 /* Odd PC indicates that branch is rexecuting due to exception in the
3044 * delayslot, like in real hw.
3046 pc_start
= tb
->pc
& ~1;
3050 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3052 dc
->is_jmp
= DISAS_NEXT
;
3055 dc
->singlestep_enabled
= env
->singlestep_enabled
;
3056 dc
->flags_uptodate
= 1;
3057 dc
->flagx_known
= 1;
3058 dc
->flags_x
= tb
->flags
& X_FLAG
;
3059 dc
->cc_x_uptodate
= 0;
3063 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
3064 dc
->cc_size_uptodate
= -1;
3066 /* Decode TB flags. */
3067 dc
->tb_flags
= tb
->flags
& (P_FLAG
| U_FLAG
| X_FLAG
);
3068 dc
->delayed_branch
= !!(tb
->flags
& 7);
3069 if (dc
->delayed_branch
)
3070 dc
->jmp
= JMP_INDIRECT
;
3072 dc
->jmp
= JMP_NOJMP
;
3074 dc
->cpustate_changed
= 0;
3076 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3078 "srch=%d pc=%x %x flg=%llx bt=%x ds=%u ccs=%x\n"
3084 search_pc
, dc
->pc
, dc
->ppc
,
3085 (unsigned long long)tb
->flags
,
3086 env
->btarget
, (unsigned)tb
->flags
& 7,
3088 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
3089 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
3090 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
3091 env
->regs
[8], env
->regs
[9],
3092 env
->regs
[10], env
->regs
[11],
3093 env
->regs
[12], env
->regs
[13],
3094 env
->regs
[14], env
->regs
[15]);
3098 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3101 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3103 max_insns
= CF_COUNT_MASK
;
3108 check_breakpoint(env
, dc
);
3111 j
= gen_opc_ptr
- gen_opc_buf
;
3115 gen_opc_instr_start
[lj
++] = 0;
3117 if (dc
->delayed_branch
== 1)
3118 gen_opc_pc
[lj
] = dc
->ppc
| 1;
3120 gen_opc_pc
[lj
] = dc
->pc
;
3121 gen_opc_instr_start
[lj
] = 1;
3122 gen_opc_icount
[lj
] = num_insns
;
3126 DIS(fprintf(logfile
, "%x ", dc
->pc
));
3128 DIS(fprintf(logfile
, "%x ", dc
->pc
));
3131 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3134 if (unlikely(loglevel
& CPU_LOG_TB_OP
))
3135 tcg_gen_debug_insn_start(dc
->pc
);
3136 insn_len
= cris_decoder(dc
);
3140 cris_clear_x_flag(dc
);
3143 /* Check for delayed branches here. If we do it before
3144 actually generating any host code, the simulator will just
3145 loop doing nothing for on this program location. */
3146 if (dc
->delayed_branch
) {
3147 dc
->delayed_branch
--;
3148 if (dc
->delayed_branch
== 0)
3151 t_gen_mov_env_TN(dslot
,
3153 if (dc
->jmp
== JMP_DIRECT
) {
3154 dc
->is_jmp
= DISAS_NEXT
;
3156 t_gen_cc_jmp(env_btarget
,
3157 tcg_const_tl(dc
->pc
));
3158 dc
->is_jmp
= DISAS_JUMP
;
3164 /* If we are rexecuting a branch due to exceptions on
3165 delay slots dont break. */
3166 if (!(tb
->pc
& 1) && env
->singlestep_enabled
)
3168 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
3169 && (dc
->pc
< next_page_start
)
3170 && num_insns
< max_insns
);
3173 if (dc
->jmp
== JMP_DIRECT
&& !dc
->delayed_branch
)
3176 if (tb
->cflags
& CF_LAST_IO
)
3178 /* Force an update if the per-tb cpu state has changed. */
3179 if (dc
->is_jmp
== DISAS_NEXT
3180 && (dc
->cpustate_changed
|| !dc
->flagx_known
3181 || (dc
->flags_x
!= (tb
->flags
& X_FLAG
)))) {
3182 dc
->is_jmp
= DISAS_UPDATE
;
3183 tcg_gen_movi_tl(env_pc
, npc
);
3185 /* Broken branch+delayslot sequence. */
3186 if (dc
->delayed_branch
== 1) {
3187 /* Set env->dslot to the size of the branch insn. */
3188 t_gen_mov_env_TN(dslot
, tcg_const_tl(dc
->pc
- dc
->ppc
));
3189 cris_store_direct_jmp(dc
);
3192 cris_evaluate_flags (dc
);
3194 if (unlikely(env
->singlestep_enabled
)) {
3195 if (dc
->is_jmp
== DISAS_NEXT
)
3196 tcg_gen_movi_tl(env_pc
, npc
);
3197 t_gen_raise_exception(EXCP_DEBUG
);
3199 switch(dc
->is_jmp
) {
3201 gen_goto_tb(dc
, 1, npc
);
3206 /* indicate that the hash table must be used
3207 to find the next TB */
3212 /* nothing more to generate */
3216 gen_icount_end(tb
, num_insns
);
3217 *gen_opc_ptr
= INDEX_op_end
;
3219 j
= gen_opc_ptr
- gen_opc_buf
;
3222 gen_opc_instr_start
[lj
++] = 0;
3224 tb
->size
= dc
->pc
- pc_start
;
3225 tb
->icount
= num_insns
;
3229 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3230 fprintf(logfile
, "--------------\n");
3231 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
3232 target_disas(logfile
, pc_start
, dc
->pc
- pc_start
, 0);
3233 fprintf(logfile
, "\nisize=%d osize=%zd\n",
3234 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
3239 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3241 gen_intermediate_code_internal(env
, tb
, 0);
3244 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3246 gen_intermediate_code_internal(env
, tb
, 1);
3249 void cpu_dump_state (CPUState
*env
, FILE *f
,
3250 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
3259 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
3260 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
3261 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
3263 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
);
3266 for (i
= 0; i
< 16; i
++) {
3267 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
3268 if ((i
+ 1) % 4 == 0)
3269 cpu_fprintf(f
, "\n");
3271 cpu_fprintf(f
, "\nspecial regs:\n");
3272 for (i
= 0; i
< 16; i
++) {
3273 cpu_fprintf(f
, "p%2.2d=%8.8x ", i
, env
->pregs
[i
]);
3274 if ((i
+ 1) % 4 == 0)
3275 cpu_fprintf(f
, "\n");
3277 srs
= env
->pregs
[PR_SRS
];
3278 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3280 for (i
= 0; i
< 16; i
++) {
3281 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3282 i
, env
->sregs
[srs
][i
]);
3283 if ((i
+ 1) % 4 == 0)
3284 cpu_fprintf(f
, "\n");
3287 cpu_fprintf(f
, "\n\n");
3291 CPUCRISState
*cpu_cris_init (const char *cpu_model
)
3294 static int tcg_initialized
= 0;
3297 env
= qemu_mallocz(sizeof(CPUCRISState
));
3304 if (tcg_initialized
)
3307 tcg_initialized
= 1;
3309 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
3310 #if TARGET_LONG_BITS > HOST_LONG_BITS
3311 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
3312 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
3313 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
3314 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
3316 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
3317 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
3320 cc_x
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3321 offsetof(CPUState
, cc_x
), "cc_x");
3322 cc_src
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3323 offsetof(CPUState
, cc_src
), "cc_src");
3324 cc_dest
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3325 offsetof(CPUState
, cc_dest
),
3327 cc_result
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3328 offsetof(CPUState
, cc_result
),
3330 cc_op
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3331 offsetof(CPUState
, cc_op
), "cc_op");
3332 cc_size
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3333 offsetof(CPUState
, cc_size
),
3335 cc_mask
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3336 offsetof(CPUState
, cc_mask
),
3339 env_pc
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3340 offsetof(CPUState
, pc
),
3342 env_btarget
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3343 offsetof(CPUState
, btarget
),
3345 env_btaken
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3346 offsetof(CPUState
, btaken
),
3348 for (i
= 0; i
< 16; i
++) {
3349 cpu_R
[i
] = tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3350 offsetof(CPUState
, regs
[i
]),
3353 for (i
= 0; i
< 16; i
++) {
3354 cpu_PR
[i
] = tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3355 offsetof(CPUState
, pregs
[i
]),
3359 TCG_HELPER(helper_raise_exception
);
3360 TCG_HELPER(helper_store
);
3361 TCG_HELPER(helper_dump
);
3362 TCG_HELPER(helper_dummy
);
3364 TCG_HELPER(helper_tlb_flush_pid
);
3365 TCG_HELPER(helper_movl_sreg_reg
);
3366 TCG_HELPER(helper_movl_reg_sreg
);
3367 TCG_HELPER(helper_rfe
);
3368 TCG_HELPER(helper_rfn
);
3370 TCG_HELPER(helper_evaluate_flags_muls
);
3371 TCG_HELPER(helper_evaluate_flags_mulu
);
3372 TCG_HELPER(helper_evaluate_flags_mcp
);
3373 TCG_HELPER(helper_evaluate_flags_alu_4
);
3374 TCG_HELPER(helper_evaluate_flags_move_4
);
3375 TCG_HELPER(helper_evaluate_flags_move_2
);
3376 TCG_HELPER(helper_evaluate_flags
);
3377 TCG_HELPER(helper_top_evaluate_flags
);
3381 void cpu_reset (CPUCRISState
*env
)
3383 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));
3386 #if defined(CONFIG_USER_ONLY)
3387 /* start in user mode with interrupts enabled. */
3388 env
->pregs
[PR_CCS
] |= U_FLAG
| I_FLAG
;
3390 env
->pregs
[PR_CCS
] = 0;
3394 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
3395 unsigned long searched_pc
, int pc_pos
, void *puc
)
3397 env
->pc
= gen_opc_pc
[pc_pos
];