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 desperate need of attention. It's slow
25 * and for system simulation it seems buggy. It sucks.
40 #include "crisv32-decode.h"
41 #include "qemu-common.h"
58 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
59 #define BUG_ON(x) ({if (x) BUG();})
63 /* Used by the decoder. */
64 #define EXTRACT_FIELD(src, start, end) \
65 (((src) >> start) & ((1 << (end - start + 1)) - 1))
67 #define CC_MASK_NZ 0xc
68 #define CC_MASK_NZV 0xe
69 #define CC_MASK_NZVC 0xf
70 #define CC_MASK_RNZV 0x10e
86 /* This is the state at translation time. */
87 typedef struct DisasContext
{
96 unsigned int zsize
, zzsize
;
104 int flags_live
; /* Wether or not $ccs is uptodate. */
105 int flagx_live
; /* Wether or not flags_x has the x flag known at
108 int clear_x
; /* Clear x after this insn? */
110 int user
; /* user or kernel mode. */
119 struct TranslationBlock
*tb
;
120 int singlestep_enabled
;
123 void cris_prepare_jmp (DisasContext
*dc
, uint32_t dst
);
124 static void gen_BUG(DisasContext
*dc
, char *file
, int line
)
126 printf ("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
127 fprintf (logfile
, "BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
128 cpu_dump_state (dc
->env
, stdout
, fprintf
, 0);
130 cris_prepare_jmp (dc
, 0x70000000 + 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(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);
220 tcg_gen_helper_0_0(helper_tlb_flush
);
222 tcg_gen_mov_tl(cpu_PR
[r
], tn
);
226 static inline void t_gen_raise_exception(uint32_t index
)
228 tcg_gen_helper_0_1(helper_raise_exception
, tcg_const_tl(index
));
231 static void t_gen_lsl(TCGv d
, TCGv a
, TCGv b
)
235 l1
= gen_new_label();
236 /* Speculative shift. */
237 tcg_gen_shl_tl(d
, a
, b
);
238 tcg_gen_brcond_tl(TCG_COND_LEU
, b
, tcg_const_tl(31), l1
);
239 /* Clear dst if shift operands were to large. */
240 tcg_gen_movi_tl(d
, 0);
244 static void t_gen_lsr(TCGv d
, TCGv a
, TCGv b
)
248 l1
= gen_new_label();
249 /* Speculative shift. */
250 tcg_gen_shr_tl(d
, a
, b
);
251 tcg_gen_brcond_tl(TCG_COND_LEU
, b
, tcg_const_tl(31), l1
);
252 /* Clear dst if shift operands were to large. */
253 tcg_gen_movi_tl(d
, 0);
257 static void t_gen_asr(TCGv d
, TCGv a
, TCGv b
)
261 l1
= gen_new_label();
262 /* Speculative shift. */
263 tcg_gen_sar_tl(d
, a
, b
);
264 tcg_gen_brcond_tl(TCG_COND_LEU
, b
, tcg_const_tl(31), l1
);
265 /* Clear dst if shift operands were to large. */
266 tcg_gen_sar_tl(d
, a
, tcg_const_tl(30));
270 /* 64-bit signed mul, lower result in d and upper in d2. */
271 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
275 t0
= tcg_temp_new(TCG_TYPE_I64
);
276 t1
= tcg_temp_new(TCG_TYPE_I64
);
278 tcg_gen_ext32s_i64(t0
, a
);
279 tcg_gen_ext32s_i64(t1
, b
);
280 tcg_gen_mul_i64(t0
, t0
, t1
);
282 tcg_gen_trunc_i64_i32(d
, t0
);
283 tcg_gen_shri_i64(t0
, t0
, 32);
284 tcg_gen_trunc_i64_i32(d2
, t0
);
286 tcg_gen_discard_i64(t0
);
287 tcg_gen_discard_i64(t1
);
290 /* 64-bit unsigned muls, lower result in d and upper in d2. */
291 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
295 t0
= tcg_temp_new(TCG_TYPE_I64
);
296 t1
= tcg_temp_new(TCG_TYPE_I64
);
298 tcg_gen_extu_i32_i64(t0
, a
);
299 tcg_gen_extu_i32_i64(t1
, b
);
300 tcg_gen_mul_i64(t0
, t0
, t1
);
302 tcg_gen_trunc_i64_i32(d
, t0
);
303 tcg_gen_shri_i64(t0
, t0
, 32);
304 tcg_gen_trunc_i64_i32(d2
, t0
);
306 tcg_gen_discard_i64(t0
);
307 tcg_gen_discard_i64(t1
);
310 /* 32bit branch-free binary search for counting leading zeros. */
311 static void t_gen_lz_i32(TCGv d
, TCGv x
)
315 y
= tcg_temp_new(TCG_TYPE_I32
);
316 m
= tcg_temp_new(TCG_TYPE_I32
);
317 n
= tcg_temp_new(TCG_TYPE_I32
);
320 tcg_gen_shri_i32(y
, x
, 16);
321 tcg_gen_sub_i32(y
, tcg_const_i32(0), y
);
323 /* m = (y >> 16) & 16 */
324 tcg_gen_sari_i32(m
, y
, 16);
325 tcg_gen_andi_i32(m
, m
, 16);
328 tcg_gen_sub_i32(n
, tcg_const_i32(16), m
);
330 tcg_gen_shr_i32(x
, x
, m
);
333 tcg_gen_subi_i32(y
, x
, 0x100);
334 /* m = (y >> 16) & 8 */
335 tcg_gen_sari_i32(m
, y
, 16);
336 tcg_gen_andi_i32(m
, m
, 8);
338 tcg_gen_add_i32(n
, n
, m
);
340 tcg_gen_shl_i32(x
, x
, m
);
343 tcg_gen_subi_i32(y
, x
, 0x1000);
344 /* m = (y >> 16) & 4 */
345 tcg_gen_sari_i32(m
, y
, 16);
346 tcg_gen_andi_i32(m
, m
, 4);
348 tcg_gen_add_i32(n
, n
, m
);
350 tcg_gen_shl_i32(x
, x
, m
);
353 tcg_gen_subi_i32(y
, x
, 0x4000);
354 /* m = (y >> 16) & 2 */
355 tcg_gen_sari_i32(m
, y
, 16);
356 tcg_gen_andi_i32(m
, m
, 2);
358 tcg_gen_add_i32(n
, n
, m
);
360 tcg_gen_shl_i32(x
, x
, m
);
363 tcg_gen_shri_i32(y
, x
, 14);
364 /* m = y & ~(y >> 1) */
365 tcg_gen_sari_i32(m
, y
, 1);
366 tcg_gen_xori_i32(m
, m
, 0xffffffff);
367 tcg_gen_and_i32(m
, m
, y
);
370 tcg_gen_addi_i32(d
, n
, 2);
371 tcg_gen_sub_i32(d
, d
, m
);
373 tcg_gen_discard_i32(y
);
374 tcg_gen_discard_i32(m
);
375 tcg_gen_discard_i32(n
);
378 static void t_gen_btst(TCGv d
, TCGv s
)
385 The N flag is set according to the selected bit in the dest reg.
386 The Z flag is set if the selected bit and all bits to the right are
388 The X flag is cleared.
389 Other flags are left untouched.
390 The destination reg is not affected.
392 unsigned int fz, sbit, bset, mask, masked_t0;
395 bset = !!(T0 & (1 << sbit));
396 mask = sbit == 31 ? -1 : (1 << (sbit + 1)) - 1;
397 masked_t0 = T0 & mask;
398 fz = !(masked_t0 | bset);
400 // Clear the X, N and Z flags.
401 T0 = env->pregs[PR_CCS] & ~(X_FLAG | N_FLAG | Z_FLAG);
402 // Set the N and Z flags accordingly.
403 T0 |= (bset << 3) | (fz << 2);
406 l1
= gen_new_label();
407 sbit
= tcg_temp_new(TCG_TYPE_TL
);
408 bset
= tcg_temp_new(TCG_TYPE_TL
);
410 /* Compute bset and sbit. */
411 tcg_gen_andi_tl(sbit
, s
, 31);
412 tcg_gen_shl_tl(s
, tcg_const_tl(1), sbit
);
413 tcg_gen_and_tl(bset
, d
, s
);
414 tcg_gen_shr_tl(bset
, bset
, sbit
);
415 /* Displace to N_FLAG. */
416 tcg_gen_shli_tl(bset
, bset
, 3);
418 tcg_gen_shl_tl(sbit
, tcg_const_tl(2), sbit
);
419 tcg_gen_subi_tl(sbit
, sbit
, 1);
420 tcg_gen_and_tl(sbit
, d
, sbit
);
422 tcg_gen_andi_tl(d
, cpu_PR
[PR_CCS
], ~(X_FLAG
| N_FLAG
| Z_FLAG
));
423 /* or in the N_FLAG. */
424 tcg_gen_or_tl(d
, d
, bset
);
425 tcg_gen_brcond_tl(TCG_COND_NE
, sbit
, tcg_const_tl(0), l1
);
426 /* or in the Z_FLAG. */
427 tcg_gen_ori_tl(d
, d
, Z_FLAG
);
430 tcg_gen_discard_tl(sbit
);
431 tcg_gen_discard_tl(bset
);
434 static void t_gen_cris_dstep(TCGv d
, TCGv s
)
438 l1
= gen_new_label();
445 tcg_gen_shli_tl(d
, d
, 1);
446 tcg_gen_brcond_tl(TCG_COND_LTU
, d
, s
, l1
);
447 tcg_gen_sub_tl(d
, d
, s
);
451 /* Extended arithmetics on CRIS. */
452 static inline void t_gen_add_flag(TCGv d
, int flag
)
456 c
= tcg_temp_new(TCG_TYPE_TL
);
457 t_gen_mov_TN_preg(c
, PR_CCS
);
458 /* Propagate carry into d. */
459 tcg_gen_andi_tl(c
, c
, 1 << flag
);
461 tcg_gen_shri_tl(c
, c
, flag
);
462 tcg_gen_add_tl(d
, d
, c
);
463 tcg_gen_discard_tl(c
);
466 static inline void t_gen_addx_carry(TCGv d
)
470 x
= tcg_temp_new(TCG_TYPE_TL
);
471 c
= tcg_temp_new(TCG_TYPE_TL
);
472 t_gen_mov_TN_preg(x
, PR_CCS
);
473 tcg_gen_mov_tl(c
, x
);
475 /* Propagate carry into d if X is set. Branch free. */
476 tcg_gen_andi_tl(c
, c
, C_FLAG
);
477 tcg_gen_andi_tl(x
, x
, X_FLAG
);
478 tcg_gen_shri_tl(x
, x
, 4);
480 tcg_gen_and_tl(x
, x
, c
);
481 tcg_gen_add_tl(d
, d
, x
);
482 tcg_gen_discard_tl(x
);
483 tcg_gen_discard_tl(c
);
486 static inline void t_gen_subx_carry(TCGv d
)
490 x
= tcg_temp_new(TCG_TYPE_TL
);
491 c
= tcg_temp_new(TCG_TYPE_TL
);
492 t_gen_mov_TN_preg(x
, PR_CCS
);
493 tcg_gen_mov_tl(c
, x
);
495 /* Propagate carry into d if X is set. Branch free. */
496 tcg_gen_andi_tl(c
, c
, C_FLAG
);
497 tcg_gen_andi_tl(x
, x
, X_FLAG
);
498 tcg_gen_shri_tl(x
, x
, 4);
500 tcg_gen_and_tl(x
, x
, c
);
501 tcg_gen_sub_tl(d
, d
, x
);
502 tcg_gen_discard_tl(x
);
503 tcg_gen_discard_tl(c
);
506 /* Swap the two bytes within each half word of the s operand.
507 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff) */
508 static inline void t_gen_swapb(TCGv d
, TCGv s
)
512 t
= tcg_temp_new(TCG_TYPE_TL
);
513 org_s
= tcg_temp_new(TCG_TYPE_TL
);
515 /* d and s may refer to the same object. */
516 tcg_gen_mov_tl(org_s
, s
);
517 tcg_gen_shli_tl(t
, org_s
, 8);
518 tcg_gen_andi_tl(d
, t
, 0xff00ff00);
519 tcg_gen_shri_tl(t
, org_s
, 8);
520 tcg_gen_andi_tl(t
, t
, 0x00ff00ff);
521 tcg_gen_or_tl(d
, d
, t
);
522 tcg_gen_discard_tl(t
);
523 tcg_gen_discard_tl(org_s
);
526 /* Swap the halfwords of the s operand. */
527 static inline void t_gen_swapw(TCGv d
, TCGv s
)
530 /* d and s refer the same object. */
531 t
= tcg_temp_new(TCG_TYPE_TL
);
532 tcg_gen_mov_tl(t
, s
);
533 tcg_gen_shli_tl(d
, t
, 16);
534 tcg_gen_shri_tl(t
, t
, 16);
535 tcg_gen_or_tl(d
, d
, t
);
536 tcg_gen_discard_tl(t
);
539 /* Reverse the within each byte.
540 T0 = (((T0 << 7) & 0x80808080) |
541 ((T0 << 5) & 0x40404040) |
542 ((T0 << 3) & 0x20202020) |
543 ((T0 << 1) & 0x10101010) |
544 ((T0 >> 1) & 0x08080808) |
545 ((T0 >> 3) & 0x04040404) |
546 ((T0 >> 5) & 0x02020202) |
547 ((T0 >> 7) & 0x01010101));
549 static inline void t_gen_swapr(TCGv d
, TCGv s
)
552 int shift
; /* LSL when positive, LSR when negative. */
567 /* d and s refer the same object. */
568 t
= tcg_temp_new(TCG_TYPE_TL
);
569 org_s
= tcg_temp_new(TCG_TYPE_TL
);
570 tcg_gen_mov_tl(org_s
, s
);
572 tcg_gen_shli_tl(t
, org_s
, bitrev
[0].shift
);
573 tcg_gen_andi_tl(d
, t
, bitrev
[0].mask
);
574 for (i
= 1; i
< sizeof bitrev
/ sizeof bitrev
[0]; i
++) {
575 if (bitrev
[i
].shift
>= 0) {
576 tcg_gen_shli_tl(t
, org_s
, bitrev
[i
].shift
);
578 tcg_gen_shri_tl(t
, org_s
, -bitrev
[i
].shift
);
580 tcg_gen_andi_tl(t
, t
, bitrev
[i
].mask
);
581 tcg_gen_or_tl(d
, d
, t
);
583 tcg_gen_discard_tl(t
);
584 tcg_gen_discard_tl(org_s
);
587 static void t_gen_cc_jmp(target_ulong pc_true
, target_ulong pc_false
)
592 l1
= gen_new_label();
593 btaken
= tcg_temp_new(TCG_TYPE_TL
);
595 /* Conditional jmp. */
596 t_gen_mov_TN_env(btaken
, btaken
);
597 tcg_gen_movi_tl(env_pc
, pc_false
);
598 tcg_gen_brcond_tl(TCG_COND_EQ
, btaken
, tcg_const_tl(0), l1
);
599 tcg_gen_movi_tl(env_pc
, pc_true
);
602 tcg_gen_discard_tl(btaken
);
605 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
607 TranslationBlock
*tb
;
609 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
611 tcg_gen_movi_tl(env_pc
, dest
);
612 tcg_gen_exit_tb((long)tb
+ n
);
614 tcg_gen_mov_tl(env_pc
, cpu_T
[0]);
619 /* Sign extend at translation time. */
620 static int sign_extend(unsigned int val
, unsigned int width
)
632 static inline void cris_clear_x_flag(DisasContext
*dc
)
635 || (dc
->flagx_live
&& dc
->flags_x
)
636 || dc
->cc_op
!= CC_OP_FLAGS
)
637 tcg_gen_andi_i32(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~X_FLAG
);
642 static void cris_evaluate_flags(DisasContext
*dc
)
644 if (!dc
->flags_live
) {
645 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
646 tcg_gen_movi_tl(cc_size
, dc
->cc_size
);
647 tcg_gen_movi_tl(cc_mask
, dc
->cc_mask
);
652 tcg_gen_helper_0_0(helper_evaluate_flags_mcp
);
655 tcg_gen_helper_0_0(helper_evaluate_flags_muls
);
658 tcg_gen_helper_0_0(helper_evaluate_flags_mulu
);
664 tcg_gen_helper_0_0(helper_evaluate_flags_move_4
);
667 tcg_gen_helper_0_0(helper_evaluate_flags_move_2
);
670 tcg_gen_helper_0_0(helper_evaluate_flags
);
682 tcg_gen_helper_0_0(helper_evaluate_flags_alu_4
);
685 tcg_gen_helper_0_0(helper_evaluate_flags
);
695 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
699 /* Check if we need to evaluate the condition codes due to
701 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
703 /* TODO: optimize this case. It trigs all the time. */
704 cris_evaluate_flags (dc
);
715 static void cris_update_cc_op(DisasContext
*dc
, int op
, int size
)
722 /* op is the operation.
723 T0, T1 are the operands.
724 dst is the destination reg.
726 static void crisv32_alu_op(DisasContext
*dc
, int op
, int rd
, int size
)
730 cris_update_cc_op(dc
, op
, size
);
731 tcg_gen_mov_tl(cc_dest
, cpu_T
[0]);
733 /* FIXME: This shouldn't be needed. But we don't pass the
734 tests without it. Investigate. */
735 t_gen_mov_env_TN(cc_x_live
, tcg_const_tl(dc
->flagx_live
));
736 t_gen_mov_env_TN(cc_x
, tcg_const_tl(dc
->flags_x
));
739 /* Emit the ALU insns. */
743 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
744 /* Extended arithmetics. */
745 t_gen_addx_carry(cpu_T
[0]);
748 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
749 t_gen_add_flag(cpu_T
[0], 0); /* C_FLAG. */
752 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
753 t_gen_add_flag(cpu_T
[0], 8); /* R_FLAG. */
756 tcg_gen_sub_tl(cpu_T
[1], tcg_const_tl(0), cpu_T
[1]);
757 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
758 tcg_gen_sub_tl(cpu_T
[1], tcg_const_tl(0), cpu_T
[1]);
759 /* CRIS flag evaluation needs ~src. */
760 tcg_gen_xori_tl(cpu_T
[1], cpu_T
[1], -1);
762 /* Extended arithmetics. */
763 t_gen_subx_carry(cpu_T
[0]);
766 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
769 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
772 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
775 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
778 t_gen_lsl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
781 t_gen_lsr(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
784 t_gen_asr(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
787 /* Hopefully the TCG backend recognizes this pattern
788 and makes a real neg out of it. */
789 tcg_gen_sub_tl(cpu_T
[0], tcg_const_tl(0), cpu_T
[1]);
790 /* Extended arithmetics. */
791 t_gen_subx_carry(cpu_T
[0]);
794 t_gen_lz_i32(cpu_T
[0], cpu_T
[1]);
797 t_gen_btst(cpu_T
[0], cpu_T
[1]);
803 mof
= tcg_temp_new(TCG_TYPE_TL
);
804 t_gen_muls(cpu_T
[0], mof
, cpu_T
[0], cpu_T
[1]);
805 t_gen_mov_preg_TN(PR_MOF
, mof
);
806 tcg_gen_discard_tl(mof
);
812 mof
= tcg_temp_new(TCG_TYPE_TL
);
813 t_gen_mulu(cpu_T
[0], mof
, cpu_T
[0], cpu_T
[1]);
814 t_gen_mov_preg_TN(PR_MOF
, mof
);
815 tcg_gen_discard_tl(mof
);
819 t_gen_cris_dstep(cpu_T
[0], cpu_T
[1]);
824 l1
= gen_new_label();
825 tcg_gen_brcond_tl(TCG_COND_LEU
,
826 cpu_T
[0], cpu_T
[1], l1
);
827 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
832 tcg_gen_sub_tl(cpu_T
[1], tcg_const_tl(0), cpu_T
[1]);
833 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
834 /* CRIS flag evaluation needs ~src. */
835 tcg_gen_sub_tl(cpu_T
[1], tcg_const_tl(0), cpu_T
[1]);
836 /* CRIS flag evaluation needs ~src. */
837 tcg_gen_xori_tl(cpu_T
[1], cpu_T
[1], -1);
839 /* Extended arithmetics. */
840 t_gen_subx_carry(cpu_T
[0]);
844 fprintf (logfile
, "illegal ALU op.\n");
850 tcg_gen_mov_tl(cc_src
, cpu_T
[1]);
853 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xff);
855 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0xffff);
860 t_gen_mov_reg_TN(rd
, cpu_T
[0]);
862 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
863 t_gen_mov_TN_reg(cpu_T
[0], rd
);
865 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], ~0xff);
867 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], ~0xffff);
868 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
869 t_gen_mov_reg_TN(rd
, cpu_T
[0]);
870 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
874 tcg_gen_mov_tl(cc_result
, cpu_T
[0]);
877 /* TODO: Optimize this. */
879 cris_evaluate_flags(dc
);
883 static int arith_cc(DisasContext
*dc
)
887 case CC_OP_ADD
: return 1;
888 case CC_OP_SUB
: return 1;
889 case CC_OP_LSL
: return 1;
890 case CC_OP_LSR
: return 1;
891 case CC_OP_ASR
: return 1;
892 case CC_OP_CMP
: return 1;
900 static void gen_tst_cc (DisasContext
*dc
, int cond
)
904 /* TODO: optimize more condition codes. */
907 * If the flags are live, we've gotta look into the bits of CCS.
908 * Otherwise, if we just did an arithmetic operation we try to
909 * evaluate the condition code faster.
911 * When this function is done, T0 should be non-zero if the condition
914 arith_opt
= arith_cc(dc
) && !dc
->flags_live
;
918 /* If cc_result is zero, T0 should be
919 non-zero otherwise T0 should be zero. */
921 l1
= gen_new_label();
922 tcg_gen_movi_tl(cpu_T
[0], 0);
923 tcg_gen_brcond_tl(TCG_COND_NE
, cc_result
,
924 tcg_const_tl(0), l1
);
925 tcg_gen_movi_tl(cpu_T
[0], 1);
929 cris_evaluate_flags(dc
);
930 tcg_gen_andi_tl(cpu_T
[0],
931 cpu_PR
[PR_CCS
], Z_FLAG
);
936 tcg_gen_mov_tl(cpu_T
[0], cc_result
);
938 cris_evaluate_flags(dc
);
939 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
941 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], Z_FLAG
);
945 cris_evaluate_flags(dc
);
946 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], C_FLAG
);
949 cris_evaluate_flags(dc
);
950 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
952 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], C_FLAG
);
955 cris_evaluate_flags(dc
);
956 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], V_FLAG
);
959 cris_evaluate_flags(dc
);
960 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
962 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], V_FLAG
);
966 tcg_gen_shli_tl(cpu_T
[0], cc_result
, 31);
968 cris_evaluate_flags(dc
);
969 tcg_gen_xori_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
971 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
976 tcg_gen_shli_tl(cpu_T
[0], cc_result
, 31);
977 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], 1);
980 cris_evaluate_flags(dc
);
981 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
986 cris_evaluate_flags(dc
);
987 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
],
991 cris_evaluate_flags(dc
);
995 tmp
= tcg_temp_new(TCG_TYPE_TL
);
996 tcg_gen_xori_tl(tmp
, cpu_PR
[PR_CCS
],
998 /* Overlay the C flag on top of the Z. */
999 tcg_gen_shli_tl(cpu_T
[0], tmp
, 2);
1000 tcg_gen_and_tl(cpu_T
[0], tmp
, cpu_T
[0]);
1001 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], Z_FLAG
);
1003 tcg_gen_discard_tl(tmp
);
1007 cris_evaluate_flags(dc
);
1008 /* Overlay the V flag on top of the N. */
1009 tcg_gen_shli_tl(cpu_T
[0], cpu_PR
[PR_CCS
], 2);
1010 tcg_gen_xor_tl(cpu_T
[0],
1011 cpu_PR
[PR_CCS
], cpu_T
[0]);
1012 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1013 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1016 cris_evaluate_flags(dc
);
1017 /* Overlay the V flag on top of the N. */
1018 tcg_gen_shli_tl(cpu_T
[0], cpu_PR
[PR_CCS
], 2);
1019 tcg_gen_xor_tl(cpu_T
[0],
1020 cpu_PR
[PR_CCS
], cpu_T
[0]);
1021 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], N_FLAG
);
1024 cris_evaluate_flags(dc
);
1028 n
= tcg_temp_new(TCG_TYPE_TL
);
1029 z
= tcg_temp_new(TCG_TYPE_TL
);
1031 /* To avoid a shift we overlay everything on
1033 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1034 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1036 tcg_gen_xori_tl(z
, z
, 2);
1038 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1039 tcg_gen_xori_tl(n
, n
, 2);
1040 tcg_gen_and_tl(cpu_T
[0], z
, n
);
1041 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 2);
1043 tcg_gen_discard_tl(n
);
1044 tcg_gen_discard_tl(z
);
1048 cris_evaluate_flags(dc
);
1052 n
= tcg_temp_new(TCG_TYPE_TL
);
1053 z
= tcg_temp_new(TCG_TYPE_TL
);
1055 /* To avoid a shift we overlay everything on
1057 tcg_gen_shri_tl(n
, cpu_PR
[PR_CCS
], 2);
1058 tcg_gen_shri_tl(z
, cpu_PR
[PR_CCS
], 1);
1060 tcg_gen_xor_tl(n
, n
, cpu_PR
[PR_CCS
]);
1061 tcg_gen_or_tl(cpu_T
[0], z
, n
);
1062 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 2);
1064 tcg_gen_discard_tl(n
);
1065 tcg_gen_discard_tl(z
);
1069 cris_evaluate_flags(dc
);
1070 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], P_FLAG
);
1073 cris_evaluate_flags(dc
);
1074 tcg_gen_movi_tl(cpu_T
[0], 1);
1082 static void cris_prepare_cc_branch (DisasContext
*dc
, int offset
, int cond
)
1084 /* This helps us re-schedule the micro-code to insns in delay-slots
1085 before the actual jump. */
1086 dc
->delayed_branch
= 2;
1087 dc
->delayed_pc
= dc
->pc
+ offset
;
1091 gen_tst_cc (dc
, cond
);
1092 t_gen_mov_env_TN(btaken
, cpu_T
[0]);
1094 tcg_gen_movi_tl(env_btarget
, dc
->delayed_pc
);
1098 /* Dynamic jumps, when the dest is in a live reg for example. */
1099 void cris_prepare_dyn_jmp (DisasContext
*dc
)
1101 /* This helps us re-schedule the micro-code to insns in delay-slots
1102 before the actual jump. */
1103 dc
->delayed_branch
= 2;
1108 void cris_prepare_jmp (DisasContext
*dc
, uint32_t dst
)
1110 /* This helps us re-schedule the micro-code to insns in delay-slots
1111 before the actual jump. */
1112 dc
->delayed_branch
= 2;
1113 dc
->delayed_pc
= dst
;
1118 void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
1119 unsigned int size
, int sign
)
1121 int mem_index
= cpu_mmu_index(dc
->env
);
1123 cris_evaluate_flags(dc
);
1126 tcg_gen_qemu_ld8s(dst
, addr
, mem_index
);
1128 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
1130 else if (size
== 2) {
1132 tcg_gen_qemu_ld16s(dst
, addr
, mem_index
);
1134 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
1137 tcg_gen_qemu_ld32s(dst
, addr
, mem_index
);
1141 void gen_store (DisasContext
*dc
, TCGv addr
, TCGv val
,
1144 int mem_index
= cpu_mmu_index(dc
->env
);
1146 cris_evaluate_flags(dc
);
1148 /* Remember, operands are flipped. CRIS has reversed order. */
1150 tcg_gen_qemu_st8(val
, addr
, mem_index
);
1152 tcg_gen_qemu_st16(val
, addr
, mem_index
);
1154 tcg_gen_qemu_st32(val
, addr
, mem_index
);
1157 static inline void t_gen_sext(TCGv d
, TCGv s
, int size
)
1160 tcg_gen_ext8s_i32(d
, s
);
1162 tcg_gen_ext16s_i32(d
, s
);
1164 tcg_gen_mov_tl(d
, s
);
1167 static inline void t_gen_zext(TCGv d
, TCGv s
, int size
)
1169 /* TCG-FIXME: this is not optimal. Many archs have fast zext insns. */
1171 tcg_gen_andi_i32(d
, s
, 0xff);
1173 tcg_gen_andi_i32(d
, s
, 0xffff);
1175 tcg_gen_mov_tl(d
, s
);
1179 static char memsize_char(int size
)
1183 case 1: return 'b'; break;
1184 case 2: return 'w'; break;
1185 case 4: return 'd'; break;
1193 static unsigned int memsize_z(DisasContext
*dc
)
1195 return dc
->zsize
+ 1;
1198 static unsigned int memsize_zz(DisasContext
*dc
)
1209 static inline void do_postinc (DisasContext
*dc
, int size
)
1212 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], size
);
1216 static void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
1217 int size
, int s_ext
)
1220 t_gen_sext(cpu_T
[1], cpu_R
[rs
], size
);
1222 t_gen_zext(cpu_T
[1], cpu_R
[rs
], size
);
1225 /* Prepare T0 and T1 for a register alu operation.
1226 s_ext decides if the operand1 should be sign-extended or zero-extended when
1228 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
1229 int size
, int s_ext
)
1231 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
);
1234 t_gen_sext(cpu_T
[0], cpu_R
[rd
], size
);
1236 t_gen_zext(cpu_T
[0], cpu_R
[rd
], size
);
1239 /* Prepare T0 and T1 for a memory + alu operation.
1240 s_ext decides if the operand1 should be sign-extended or zero-extended when
1242 static int dec_prep_alu_m(DisasContext
*dc
, int s_ext
, int memsize
)
1244 unsigned int rs
, rd
;
1251 is_imm
= rs
== 15 && dc
->postinc
;
1253 /* Load [$rs] onto T1. */
1255 insn_len
= 2 + memsize
;
1262 imm
= ldsb_code(dc
->pc
+ 2);
1264 imm
= ldsw_code(dc
->pc
+ 2);
1267 imm
= ldub_code(dc
->pc
+ 2);
1269 imm
= lduw_code(dc
->pc
+ 2);
1272 imm
= ldl_code(dc
->pc
+ 2);
1274 DIS(fprintf (logfile
, "imm=%x rd=%d sext=%d ms=%d\n",
1275 imm
, rd
, s_ext
, memsize
));
1276 tcg_gen_movi_tl(cpu_T
[1], imm
);
1279 /* FIXME: qemu_ld does not act as a barrier? */
1280 tcg_gen_helper_0_0(helper_dummy
);
1281 gen_load(dc
, cpu_T
[1], cpu_R
[rs
], memsize
, 0);
1283 t_gen_sext(cpu_T
[1], cpu_T
[1], memsize
);
1285 t_gen_zext(cpu_T
[1], cpu_T
[1], memsize
);
1288 /* put dest in T0. */
1289 t_gen_mov_TN_reg(cpu_T
[0], rd
);
1294 static const char *cc_name(int cc
)
1296 static char *cc_names
[16] = {
1297 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
1298 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
1301 return cc_names
[cc
];
1305 /* Start of insn decoders. */
1307 static unsigned int dec_bccq(DisasContext
*dc
)
1311 uint32_t cond
= dc
->op2
;
1314 offset
= EXTRACT_FIELD (dc
->ir
, 1, 7);
1315 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
1318 offset
|= sign
<< 8;
1320 offset
= sign_extend(offset
, 8);
1322 /* op2 holds the condition-code. */
1323 cris_cc_mask(dc
, 0);
1324 cris_prepare_cc_branch (dc
, offset
, cond
);
1327 static unsigned int dec_addoq(DisasContext
*dc
)
1331 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
1332 imm
= sign_extend(dc
->op1
, 7);
1334 DIS(fprintf (logfile
, "addoq %d, $r%u\n", imm
, dc
->op2
));
1335 cris_cc_mask(dc
, 0);
1336 /* Fetch register operand, */
1337 tcg_gen_addi_tl(cpu_R
[R_ACR
], cpu_R
[dc
->op2
], imm
);
1340 static unsigned int dec_addq(DisasContext
*dc
)
1342 DIS(fprintf (logfile
, "addq %u, $r%u\n", dc
->op1
, dc
->op2
));
1344 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1346 cris_cc_mask(dc
, CC_MASK_NZVC
);
1347 /* Fetch register operand, */
1348 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1349 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1350 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1353 static unsigned int dec_moveq(DisasContext
*dc
)
1357 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1358 imm
= sign_extend(dc
->op1
, 5);
1359 DIS(fprintf (logfile
, "moveq %d, $r%u\n", imm
, dc
->op2
));
1361 t_gen_mov_reg_TN(dc
->op2
, tcg_const_tl(imm
));
1364 static unsigned int dec_subq(DisasContext
*dc
)
1366 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1368 DIS(fprintf (logfile
, "subq %u, $r%u\n", dc
->op1
, dc
->op2
));
1370 cris_cc_mask(dc
, CC_MASK_NZVC
);
1371 /* Fetch register operand, */
1372 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1373 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1374 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1377 static unsigned int dec_cmpq(DisasContext
*dc
)
1380 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1381 imm
= sign_extend(dc
->op1
, 5);
1383 DIS(fprintf (logfile
, "cmpq %d, $r%d\n", imm
, dc
->op2
));
1384 cris_cc_mask(dc
, CC_MASK_NZVC
);
1385 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1386 tcg_gen_movi_tl(cpu_T
[1], imm
);
1387 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, 4);
1390 static unsigned int dec_andq(DisasContext
*dc
)
1393 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1394 imm
= sign_extend(dc
->op1
, 5);
1396 DIS(fprintf (logfile
, "andq %d, $r%d\n", imm
, dc
->op2
));
1397 cris_cc_mask(dc
, CC_MASK_NZ
);
1398 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1399 tcg_gen_movi_tl(cpu_T
[1], imm
);
1400 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, 4);
1403 static unsigned int dec_orq(DisasContext
*dc
)
1406 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
1407 imm
= sign_extend(dc
->op1
, 5);
1408 DIS(fprintf (logfile
, "orq %d, $r%d\n", imm
, dc
->op2
));
1409 cris_cc_mask(dc
, CC_MASK_NZ
);
1410 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1411 tcg_gen_movi_tl(cpu_T
[1], imm
);
1412 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, 4);
1415 static unsigned int dec_btstq(DisasContext
*dc
)
1417 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1418 DIS(fprintf (logfile
, "btstq %u, $r%d\n", dc
->op1
, dc
->op2
));
1420 cris_cc_mask(dc
, CC_MASK_NZ
);
1421 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1422 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1423 crisv32_alu_op(dc
, CC_OP_BTST
, dc
->op2
, 4);
1425 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1426 t_gen_mov_preg_TN(PR_CCS
, cpu_T
[0]);
1430 static unsigned int dec_asrq(DisasContext
*dc
)
1432 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1433 DIS(fprintf (logfile
, "asrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1434 cris_cc_mask(dc
, CC_MASK_NZ
);
1435 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1436 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1437 crisv32_alu_op(dc
, CC_OP_ASR
, dc
->op2
, 4);
1440 static unsigned int dec_lslq(DisasContext
*dc
)
1442 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1443 DIS(fprintf (logfile
, "lslq %u, $r%d\n", dc
->op1
, dc
->op2
));
1445 cris_cc_mask(dc
, CC_MASK_NZ
);
1446 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1447 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1448 crisv32_alu_op(dc
, CC_OP_LSL
, dc
->op2
, 4);
1451 static unsigned int dec_lsrq(DisasContext
*dc
)
1453 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1454 DIS(fprintf (logfile
, "lsrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1456 cris_cc_mask(dc
, CC_MASK_NZ
);
1457 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1458 tcg_gen_movi_tl(cpu_T
[1], dc
->op1
);
1459 crisv32_alu_op(dc
, CC_OP_LSR
, dc
->op2
, 4);
1463 static unsigned int dec_move_r(DisasContext
*dc
)
1465 int size
= memsize_zz(dc
);
1467 DIS(fprintf (logfile
, "move.%c $r%u, $r%u\n",
1468 memsize_char(size
), dc
->op1
, dc
->op2
));
1470 cris_cc_mask(dc
, CC_MASK_NZ
);
1471 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1472 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, size
);
1476 static unsigned int dec_scc_r(DisasContext
*dc
)
1480 DIS(fprintf (logfile
, "s%s $r%u\n",
1481 cc_name(cond
), dc
->op1
));
1487 gen_tst_cc (dc
, cond
);
1489 l1
= gen_new_label();
1490 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 0);
1491 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[0], tcg_const_tl(0), l1
);
1492 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1496 tcg_gen_movi_tl(cpu_R
[dc
->op1
], 1);
1498 cris_cc_mask(dc
, 0);
1502 static unsigned int dec_and_r(DisasContext
*dc
)
1504 int size
= memsize_zz(dc
);
1506 DIS(fprintf (logfile
, "and.%c $r%u, $r%u\n",
1507 memsize_char(size
), dc
->op1
, dc
->op2
));
1508 cris_cc_mask(dc
, CC_MASK_NZ
);
1509 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1510 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, size
);
1514 static unsigned int dec_lz_r(DisasContext
*dc
)
1516 DIS(fprintf (logfile
, "lz $r%u, $r%u\n",
1518 cris_cc_mask(dc
, CC_MASK_NZ
);
1519 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1520 crisv32_alu_op(dc
, CC_OP_LZ
, dc
->op2
, 4);
1524 static unsigned int dec_lsl_r(DisasContext
*dc
)
1526 int size
= memsize_zz(dc
);
1528 DIS(fprintf (logfile
, "lsl.%c $r%u, $r%u\n",
1529 memsize_char(size
), dc
->op1
, dc
->op2
));
1530 cris_cc_mask(dc
, CC_MASK_NZ
);
1531 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1532 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1533 crisv32_alu_op(dc
, CC_OP_LSL
, dc
->op2
, size
);
1537 static unsigned int dec_lsr_r(DisasContext
*dc
)
1539 int size
= memsize_zz(dc
);
1541 DIS(fprintf (logfile
, "lsr.%c $r%u, $r%u\n",
1542 memsize_char(size
), dc
->op1
, dc
->op2
));
1543 cris_cc_mask(dc
, CC_MASK_NZ
);
1544 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1545 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1546 crisv32_alu_op(dc
, CC_OP_LSR
, dc
->op2
, size
);
1550 static unsigned int dec_asr_r(DisasContext
*dc
)
1552 int size
= memsize_zz(dc
);
1554 DIS(fprintf (logfile
, "asr.%c $r%u, $r%u\n",
1555 memsize_char(size
), dc
->op1
, dc
->op2
));
1556 cris_cc_mask(dc
, CC_MASK_NZ
);
1557 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1558 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 63);
1559 crisv32_alu_op(dc
, CC_OP_ASR
, dc
->op2
, size
);
1563 static unsigned int dec_muls_r(DisasContext
*dc
)
1565 int size
= memsize_zz(dc
);
1567 DIS(fprintf (logfile
, "muls.%c $r%u, $r%u\n",
1568 memsize_char(size
), dc
->op1
, dc
->op2
));
1569 cris_cc_mask(dc
, CC_MASK_NZV
);
1570 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1571 t_gen_sext(cpu_T
[0], cpu_T
[0], size
);
1572 crisv32_alu_op(dc
, CC_OP_MULS
, dc
->op2
, 4);
1576 static unsigned int dec_mulu_r(DisasContext
*dc
)
1578 int size
= memsize_zz(dc
);
1580 DIS(fprintf (logfile
, "mulu.%c $r%u, $r%u\n",
1581 memsize_char(size
), dc
->op1
, dc
->op2
));
1582 cris_cc_mask(dc
, CC_MASK_NZV
);
1583 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1584 t_gen_zext(cpu_T
[0], cpu_T
[0], size
);
1585 crisv32_alu_op(dc
, CC_OP_MULU
, dc
->op2
, 4);
1590 static unsigned int dec_dstep_r(DisasContext
*dc
)
1592 DIS(fprintf (logfile
, "dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
));
1593 cris_cc_mask(dc
, CC_MASK_NZ
);
1594 t_gen_mov_TN_reg(cpu_T
[1], dc
->op1
);
1595 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1596 crisv32_alu_op(dc
, CC_OP_DSTEP
, dc
->op2
, 4);
1600 static unsigned int dec_xor_r(DisasContext
*dc
)
1602 int size
= memsize_zz(dc
);
1603 DIS(fprintf (logfile
, "xor.%c $r%u, $r%u\n",
1604 memsize_char(size
), dc
->op1
, dc
->op2
));
1605 BUG_ON(size
!= 4); /* xor is dword. */
1606 cris_cc_mask(dc
, CC_MASK_NZ
);
1607 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1608 crisv32_alu_op(dc
, CC_OP_XOR
, dc
->op2
, 4);
1612 static unsigned int dec_bound_r(DisasContext
*dc
)
1614 int size
= memsize_zz(dc
);
1615 DIS(fprintf (logfile
, "bound.%c $r%u, $r%u\n",
1616 memsize_char(size
), dc
->op1
, dc
->op2
));
1617 cris_cc_mask(dc
, CC_MASK_NZ
);
1618 /* TODO: needs optmimization. */
1619 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1620 /* rd should be 4. */
1621 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1622 crisv32_alu_op(dc
, CC_OP_BOUND
, dc
->op2
, 4);
1626 static unsigned int dec_cmp_r(DisasContext
*dc
)
1628 int size
= memsize_zz(dc
);
1629 DIS(fprintf (logfile
, "cmp.%c $r%u, $r%u\n",
1630 memsize_char(size
), dc
->op1
, dc
->op2
));
1631 cris_cc_mask(dc
, CC_MASK_NZVC
);
1632 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1633 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, size
);
1637 static unsigned int dec_abs_r(DisasContext
*dc
)
1641 DIS(fprintf (logfile
, "abs $r%u, $r%u\n",
1643 cris_cc_mask(dc
, CC_MASK_NZ
);
1644 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1646 /* TODO: consider a branch free approach. */
1647 l1
= gen_new_label();
1648 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_T
[1], tcg_const_tl(0), l1
);
1649 tcg_gen_sub_tl(cpu_T
[1], tcg_const_tl(0), cpu_T
[1]);
1651 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1655 static unsigned int dec_add_r(DisasContext
*dc
)
1657 int size
= memsize_zz(dc
);
1658 DIS(fprintf (logfile
, "add.%c $r%u, $r%u\n",
1659 memsize_char(size
), dc
->op1
, dc
->op2
));
1660 cris_cc_mask(dc
, CC_MASK_NZVC
);
1661 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1662 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, size
);
1666 static unsigned int dec_addc_r(DisasContext
*dc
)
1668 DIS(fprintf (logfile
, "addc $r%u, $r%u\n",
1670 cris_evaluate_flags(dc
);
1671 cris_cc_mask(dc
, CC_MASK_NZVC
);
1672 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1673 crisv32_alu_op(dc
, CC_OP_ADDC
, dc
->op2
, 4);
1677 static unsigned int dec_mcp_r(DisasContext
*dc
)
1679 DIS(fprintf (logfile
, "mcp $p%u, $r%u\n",
1681 cris_evaluate_flags(dc
);
1682 cris_cc_mask(dc
, CC_MASK_RNZV
);
1683 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1684 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
1685 crisv32_alu_op(dc
, CC_OP_MCP
, dc
->op1
, 4);
1690 static char * swapmode_name(int mode
, char *modename
) {
1693 modename
[i
++] = 'n';
1695 modename
[i
++] = 'w';
1697 modename
[i
++] = 'b';
1699 modename
[i
++] = 'r';
1705 static unsigned int dec_swap_r(DisasContext
*dc
)
1707 DIS(char modename
[4]);
1708 DIS(fprintf (logfile
, "swap%s $r%u\n",
1709 swapmode_name(dc
->op2
, modename
), dc
->op1
));
1711 cris_cc_mask(dc
, CC_MASK_NZ
);
1712 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1714 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], -1);
1716 t_gen_swapw(cpu_T
[0], cpu_T
[0]);
1718 t_gen_swapb(cpu_T
[0], cpu_T
[0]);
1720 t_gen_swapr(cpu_T
[0], cpu_T
[0]);
1721 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
1722 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op1
, 4);
1726 static unsigned int dec_or_r(DisasContext
*dc
)
1728 int size
= memsize_zz(dc
);
1729 DIS(fprintf (logfile
, "or.%c $r%u, $r%u\n",
1730 memsize_char(size
), dc
->op1
, dc
->op2
));
1731 cris_cc_mask(dc
, CC_MASK_NZ
);
1732 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1733 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, size
);
1737 static unsigned int dec_addi_r(DisasContext
*dc
)
1739 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u\n",
1740 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1741 cris_cc_mask(dc
, 0);
1742 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1743 t_gen_lsl(cpu_T
[0], cpu_T
[0], tcg_const_tl(dc
->zzsize
));
1744 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1745 t_gen_mov_reg_TN(dc
->op1
, cpu_T
[0]);
1749 static unsigned int dec_addi_acr(DisasContext
*dc
)
1751 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u, $acr\n",
1752 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1753 cris_cc_mask(dc
, 0);
1754 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1755 t_gen_lsl(cpu_T
[0], cpu_T
[0], tcg_const_tl(dc
->zzsize
));
1757 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1758 t_gen_mov_reg_TN(R_ACR
, cpu_T
[0]);
1762 static unsigned int dec_neg_r(DisasContext
*dc
)
1764 int size
= memsize_zz(dc
);
1765 DIS(fprintf (logfile
, "neg.%c $r%u, $r%u\n",
1766 memsize_char(size
), dc
->op1
, dc
->op2
));
1767 cris_cc_mask(dc
, CC_MASK_NZVC
);
1768 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1769 crisv32_alu_op(dc
, CC_OP_NEG
, dc
->op2
, size
);
1773 static unsigned int dec_btst_r(DisasContext
*dc
)
1775 DIS(fprintf (logfile
, "btst $r%u, $r%u\n",
1777 cris_cc_mask(dc
, CC_MASK_NZ
);
1778 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1779 crisv32_alu_op(dc
, CC_OP_BTST
, dc
->op2
, 4);
1781 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1782 t_gen_mov_preg_TN(PR_CCS
, cpu_T
[0]);
1787 static unsigned int dec_sub_r(DisasContext
*dc
)
1789 int size
= memsize_zz(dc
);
1790 DIS(fprintf (logfile
, "sub.%c $r%u, $r%u\n",
1791 memsize_char(size
), dc
->op1
, dc
->op2
));
1792 cris_cc_mask(dc
, CC_MASK_NZVC
);
1793 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1794 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, size
);
1798 /* Zero extension. From size to dword. */
1799 static unsigned int dec_movu_r(DisasContext
*dc
)
1801 int size
= memsize_z(dc
);
1802 DIS(fprintf (logfile
, "movu.%c $r%u, $r%u\n",
1806 cris_cc_mask(dc
, CC_MASK_NZ
);
1807 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1808 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1812 /* Sign extension. From size to dword. */
1813 static unsigned int dec_movs_r(DisasContext
*dc
)
1815 int size
= memsize_z(dc
);
1816 DIS(fprintf (logfile
, "movs.%c $r%u, $r%u\n",
1820 cris_cc_mask(dc
, CC_MASK_NZ
);
1821 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1822 /* Size can only be qi or hi. */
1823 t_gen_sext(cpu_T
[1], cpu_T
[0], size
);
1824 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1828 /* zero extension. From size to dword. */
1829 static unsigned int dec_addu_r(DisasContext
*dc
)
1831 int size
= memsize_z(dc
);
1832 DIS(fprintf (logfile
, "addu.%c $r%u, $r%u\n",
1836 cris_cc_mask(dc
, CC_MASK_NZVC
);
1837 t_gen_mov_TN_reg(cpu_T
[1], dc
->op1
);
1838 /* Size can only be qi or hi. */
1839 t_gen_zext(cpu_T
[1], cpu_T
[1], size
);
1840 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1841 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1845 /* Sign extension. From size to dword. */
1846 static unsigned int dec_adds_r(DisasContext
*dc
)
1848 int size
= memsize_z(dc
);
1849 DIS(fprintf (logfile
, "adds.%c $r%u, $r%u\n",
1853 cris_cc_mask(dc
, CC_MASK_NZVC
);
1854 t_gen_mov_TN_reg(cpu_T
[1], dc
->op1
);
1855 /* Size can only be qi or hi. */
1856 t_gen_sext(cpu_T
[1], cpu_T
[1], size
);
1857 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1859 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1863 /* Zero extension. From size to dword. */
1864 static unsigned int dec_subu_r(DisasContext
*dc
)
1866 int size
= memsize_z(dc
);
1867 DIS(fprintf (logfile
, "subu.%c $r%u, $r%u\n",
1871 cris_cc_mask(dc
, CC_MASK_NZVC
);
1872 t_gen_mov_TN_reg(cpu_T
[1], dc
->op1
);
1873 /* Size can only be qi or hi. */
1874 t_gen_zext(cpu_T
[1], cpu_T
[1], size
);
1875 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1876 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1880 /* Sign extension. From size to dword. */
1881 static unsigned int dec_subs_r(DisasContext
*dc
)
1883 int size
= memsize_z(dc
);
1884 DIS(fprintf (logfile
, "subs.%c $r%u, $r%u\n",
1888 cris_cc_mask(dc
, CC_MASK_NZVC
);
1889 t_gen_mov_TN_reg(cpu_T
[1], dc
->op1
);
1890 /* Size can only be qi or hi. */
1891 t_gen_sext(cpu_T
[1], cpu_T
[1], size
);
1892 t_gen_mov_TN_reg(cpu_T
[0], dc
->op2
);
1893 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1897 static unsigned int dec_setclrf(DisasContext
*dc
)
1900 int set
= (~dc
->opcode
>> 2) & 1;
1902 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1903 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1904 DIS(fprintf (logfile
, "set=%d flags=%x\n", set
, flags
));
1905 if (set
&& flags
== 0)
1906 DIS(fprintf (logfile
, "nop\n"));
1907 else if (!set
&& (flags
& 0x20))
1908 DIS(fprintf (logfile
, "di\n"));
1910 DIS(fprintf (logfile
, "%sf %x\n",
1911 set
? "set" : "clr",
1914 if (set
&& (flags
& X_FLAG
)) {
1919 /* Simply decode the flags. */
1920 cris_evaluate_flags (dc
);
1921 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1922 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
1925 if (!dc
->user
&& (flags
& U_FLAG
)) {
1926 /* Enter user mode. */
1927 t_gen_mov_env_TN(ksp
, cpu_R
[R_SP
]);
1928 tcg_gen_mov_tl(cpu_R
[R_SP
], cpu_PR
[PR_USP
]);
1929 dc
->is_jmp
= DISAS_UPDATE
;
1931 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
1934 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
1941 static unsigned int dec_move_rs(DisasContext
*dc
)
1943 DIS(fprintf (logfile
, "move $r%u, $s%u\n", dc
->op1
, dc
->op2
));
1944 cris_cc_mask(dc
, 0);
1945 tcg_gen_helper_0_2(helper_movl_sreg_reg
,
1946 tcg_const_tl(dc
->op2
), tcg_const_tl(dc
->op1
));
1949 static unsigned int dec_move_sr(DisasContext
*dc
)
1951 DIS(fprintf (logfile
, "move $s%u, $r%u\n", dc
->op2
, dc
->op1
));
1952 cris_cc_mask(dc
, 0);
1953 tcg_gen_helper_0_2(helper_movl_reg_sreg
,
1954 tcg_const_tl(dc
->op1
), tcg_const_tl(dc
->op2
));
1958 static unsigned int dec_move_rp(DisasContext
*dc
)
1960 DIS(fprintf (logfile
, "move $r%u, $p%u\n", dc
->op1
, dc
->op2
));
1961 cris_cc_mask(dc
, 0);
1963 if (dc
->op2
== PR_CCS
) {
1964 cris_evaluate_flags(dc
);
1965 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1967 /* User space is not allowed to touch all flags. */
1968 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x39f);
1969 tcg_gen_andi_tl(cpu_T
[1], cpu_PR
[PR_CCS
], ~0x39f);
1970 tcg_gen_or_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1974 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
1976 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[0]);
1977 if (dc
->op2
== PR_CCS
) {
1978 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
1983 static unsigned int dec_move_pr(DisasContext
*dc
)
1985 DIS(fprintf (logfile
, "move $p%u, $r%u\n", dc
->op1
, dc
->op2
));
1986 cris_cc_mask(dc
, 0);
1987 /* Support register 0 is hardwired to zero.
1988 Treat it specially. */
1990 tcg_gen_movi_tl(cpu_T
[1], 0);
1991 else if (dc
->op2
== PR_CCS
) {
1992 cris_evaluate_flags(dc
);
1993 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
1995 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
1996 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op1
, preg_sizes
[dc
->op2
]);
2000 static unsigned int dec_move_mr(DisasContext
*dc
)
2002 int memsize
= memsize_zz(dc
);
2004 DIS(fprintf (logfile
, "move.%c [$r%u%s, $r%u\n",
2005 memsize_char(memsize
),
2006 dc
->op1
, dc
->postinc
? "+]" : "]",
2009 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2010 cris_cc_mask(dc
, CC_MASK_NZ
);
2011 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, memsize
);
2012 do_postinc(dc
, memsize
);
2016 static unsigned int dec_movs_m(DisasContext
*dc
)
2018 int memsize
= memsize_z(dc
);
2020 DIS(fprintf (logfile
, "movs.%c [$r%u%s, $r%u\n",
2021 memsize_char(memsize
),
2022 dc
->op1
, dc
->postinc
? "+]" : "]",
2026 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2027 cris_cc_mask(dc
, CC_MASK_NZ
);
2028 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
2029 do_postinc(dc
, memsize
);
2033 static unsigned int dec_addu_m(DisasContext
*dc
)
2035 int memsize
= memsize_z(dc
);
2037 DIS(fprintf (logfile
, "addu.%c [$r%u%s, $r%u\n",
2038 memsize_char(memsize
),
2039 dc
->op1
, dc
->postinc
? "+]" : "]",
2043 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2044 cris_cc_mask(dc
, CC_MASK_NZVC
);
2045 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
2046 do_postinc(dc
, memsize
);
2050 static unsigned int dec_adds_m(DisasContext
*dc
)
2052 int memsize
= memsize_z(dc
);
2054 DIS(fprintf (logfile
, "adds.%c [$r%u%s, $r%u\n",
2055 memsize_char(memsize
),
2056 dc
->op1
, dc
->postinc
? "+]" : "]",
2060 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2061 cris_cc_mask(dc
, CC_MASK_NZVC
);
2062 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
2063 do_postinc(dc
, memsize
);
2067 static unsigned int dec_subu_m(DisasContext
*dc
)
2069 int memsize
= memsize_z(dc
);
2071 DIS(fprintf (logfile
, "subu.%c [$r%u%s, $r%u\n",
2072 memsize_char(memsize
),
2073 dc
->op1
, dc
->postinc
? "+]" : "]",
2077 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2078 cris_cc_mask(dc
, CC_MASK_NZVC
);
2079 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
2080 do_postinc(dc
, memsize
);
2084 static unsigned int dec_subs_m(DisasContext
*dc
)
2086 int memsize
= memsize_z(dc
);
2088 DIS(fprintf (logfile
, "subs.%c [$r%u%s, $r%u\n",
2089 memsize_char(memsize
),
2090 dc
->op1
, dc
->postinc
? "+]" : "]",
2094 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2095 cris_cc_mask(dc
, CC_MASK_NZVC
);
2096 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
2097 do_postinc(dc
, memsize
);
2101 static unsigned int dec_movu_m(DisasContext
*dc
)
2103 int memsize
= memsize_z(dc
);
2106 DIS(fprintf (logfile
, "movu.%c [$r%u%s, $r%u\n",
2107 memsize_char(memsize
),
2108 dc
->op1
, dc
->postinc
? "+]" : "]",
2111 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2112 cris_cc_mask(dc
, CC_MASK_NZ
);
2113 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
2114 do_postinc(dc
, memsize
);
2118 static unsigned int dec_cmpu_m(DisasContext
*dc
)
2120 int memsize
= memsize_z(dc
);
2122 DIS(fprintf (logfile
, "cmpu.%c [$r%u%s, $r%u\n",
2123 memsize_char(memsize
),
2124 dc
->op1
, dc
->postinc
? "+]" : "]",
2127 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2128 cris_cc_mask(dc
, CC_MASK_NZVC
);
2129 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, 4);
2130 do_postinc(dc
, memsize
);
2134 static unsigned int dec_cmps_m(DisasContext
*dc
)
2136 int memsize
= memsize_z(dc
);
2138 DIS(fprintf (logfile
, "cmps.%c [$r%u%s, $r%u\n",
2139 memsize_char(memsize
),
2140 dc
->op1
, dc
->postinc
? "+]" : "]",
2143 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2144 cris_cc_mask(dc
, CC_MASK_NZVC
);
2145 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
2146 do_postinc(dc
, memsize
);
2150 static unsigned int dec_cmp_m(DisasContext
*dc
)
2152 int memsize
= memsize_zz(dc
);
2154 DIS(fprintf (logfile
, "cmp.%c [$r%u%s, $r%u\n",
2155 memsize_char(memsize
),
2156 dc
->op1
, dc
->postinc
? "+]" : "]",
2159 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2160 cris_cc_mask(dc
, CC_MASK_NZVC
);
2161 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
2162 do_postinc(dc
, memsize
);
2166 static unsigned int dec_test_m(DisasContext
*dc
)
2168 int memsize
= memsize_zz(dc
);
2170 DIS(fprintf (logfile
, "test.%d [$r%u%s] op2=%x\n",
2171 memsize_char(memsize
),
2172 dc
->op1
, dc
->postinc
? "+]" : "]",
2175 cris_evaluate_flags(dc
);
2177 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2178 cris_cc_mask(dc
, CC_MASK_NZ
);
2179 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
2181 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
2182 tcg_gen_movi_tl(cpu_T
[1], 0);
2183 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
2184 do_postinc(dc
, memsize
);
2188 static unsigned int dec_and_m(DisasContext
*dc
)
2190 int memsize
= memsize_zz(dc
);
2192 DIS(fprintf (logfile
, "and.%d [$r%u%s, $r%u\n",
2193 memsize_char(memsize
),
2194 dc
->op1
, dc
->postinc
? "+]" : "]",
2197 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2198 cris_cc_mask(dc
, CC_MASK_NZ
);
2199 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, memsize_zz(dc
));
2200 do_postinc(dc
, memsize
);
2204 static unsigned int dec_add_m(DisasContext
*dc
)
2206 int memsize
= memsize_zz(dc
);
2208 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2209 memsize_char(memsize
),
2210 dc
->op1
, dc
->postinc
? "+]" : "]",
2213 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2214 cris_cc_mask(dc
, CC_MASK_NZVC
);
2215 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, memsize_zz(dc
));
2216 do_postinc(dc
, memsize
);
2220 static unsigned int dec_addo_m(DisasContext
*dc
)
2222 int memsize
= memsize_zz(dc
);
2224 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
2225 memsize_char(memsize
),
2226 dc
->op1
, dc
->postinc
? "+]" : "]",
2229 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
2230 cris_cc_mask(dc
, 0);
2231 crisv32_alu_op(dc
, CC_OP_ADD
, R_ACR
, 4);
2232 do_postinc(dc
, memsize
);
2236 static unsigned int dec_bound_m(DisasContext
*dc
)
2238 int memsize
= memsize_zz(dc
);
2240 DIS(fprintf (logfile
, "bound.%d [$r%u%s, $r%u\n",
2241 memsize_char(memsize
),
2242 dc
->op1
, dc
->postinc
? "+]" : "]",
2245 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2246 cris_cc_mask(dc
, CC_MASK_NZ
);
2247 crisv32_alu_op(dc
, CC_OP_BOUND
, dc
->op2
, 4);
2248 do_postinc(dc
, memsize
);
2252 static unsigned int dec_addc_mr(DisasContext
*dc
)
2255 DIS(fprintf (logfile
, "addc [$r%u%s, $r%u\n",
2256 dc
->op1
, dc
->postinc
? "+]" : "]",
2259 cris_evaluate_flags(dc
);
2260 insn_len
= dec_prep_alu_m(dc
, 0, 4);
2261 cris_cc_mask(dc
, CC_MASK_NZVC
);
2262 crisv32_alu_op(dc
, CC_OP_ADDC
, dc
->op2
, 4);
2267 static unsigned int dec_sub_m(DisasContext
*dc
)
2269 int memsize
= memsize_zz(dc
);
2271 DIS(fprintf (logfile
, "sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
2272 memsize_char(memsize
),
2273 dc
->op1
, dc
->postinc
? "+]" : "]",
2274 dc
->op2
, dc
->ir
, dc
->zzsize
));
2276 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2277 cris_cc_mask(dc
, CC_MASK_NZVC
);
2278 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, memsize
);
2279 do_postinc(dc
, memsize
);
2283 static unsigned int dec_or_m(DisasContext
*dc
)
2285 int memsize
= memsize_zz(dc
);
2287 DIS(fprintf (logfile
, "or.%d [$r%u%s, $r%u pc=%x\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 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, memsize_zz(dc
));
2295 do_postinc(dc
, memsize
);
2299 static unsigned int dec_move_mp(DisasContext
*dc
)
2301 int memsize
= memsize_zz(dc
);
2304 DIS(fprintf (logfile
, "move.%c [$r%u%s, $p%u\n",
2305 memsize_char(memsize
),
2307 dc
->postinc
? "+]" : "]",
2310 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
2311 cris_cc_mask(dc
, 0);
2312 if (dc
->op2
== PR_CCS
) {
2313 cris_evaluate_flags(dc
);
2315 /* User space is not allowed to touch all flags. */
2316 tcg_gen_andi_tl(cpu_T
[1], cpu_T
[1], 0x39f);
2317 tcg_gen_andi_tl(cpu_T
[0], cpu_PR
[PR_CCS
], ~0x39f);
2318 tcg_gen_or_tl(cpu_T
[1], cpu_T
[0], cpu_T
[1]);
2322 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[1]);
2324 do_postinc(dc
, memsize
);
2328 static unsigned int dec_move_pm(DisasContext
*dc
)
2332 memsize
= preg_sizes
[dc
->op2
];
2334 DIS(fprintf (logfile
, "move.%c $p%u, [$r%u%s\n",
2335 memsize_char(memsize
),
2336 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]"));
2338 /* prepare store. Address in T0, value in T1. */
2339 if (dc
->op2
== PR_CCS
)
2340 cris_evaluate_flags(dc
);
2341 t_gen_mov_TN_preg(cpu_T
[1], dc
->op2
);
2343 /* FIXME: qemu_st does not act as a barrier? */
2344 tcg_gen_helper_0_0(helper_dummy
);
2345 gen_store(dc
, cpu_R
[dc
->op1
], cpu_T
[1], memsize
);
2347 cris_cc_mask(dc
, 0);
2349 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2353 static unsigned int dec_movem_mr(DisasContext
*dc
)
2358 DIS(fprintf (logfile
, "movem [$r%u%s, $r%u\n", dc
->op1
,
2359 dc
->postinc
? "+]" : "]", dc
->op2
));
2361 /* FIXME: qemu_ld does not act as a barrier? */
2362 tcg_gen_helper_0_0(helper_dummy
);
2364 /* fetch the address into T0 and T1. */
2365 for (i
= 0; i
<= dc
->op2
; i
++) {
2366 tmp
[i
] = tcg_temp_new(TCG_TYPE_TL
);
2367 /* Perform the load onto regnum i. Always dword wide. */
2368 tcg_gen_addi_tl(cpu_T
[0], cpu_R
[dc
->op1
], i
* 4);
2369 gen_load(dc
, tmp
[i
], cpu_T
[0], 4, 0);
2372 for (i
= 0; i
<= dc
->op2
; i
++) {
2373 tcg_gen_mov_tl(cpu_R
[i
], tmp
[i
]);
2374 tcg_gen_discard_tl(tmp
[i
]);
2377 /* writeback the updated pointer value. */
2379 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], i
* 4);
2381 /* gen_load might want to evaluate the previous insns flags. */
2382 cris_cc_mask(dc
, 0);
2386 static unsigned int dec_movem_rm(DisasContext
*dc
)
2390 DIS(fprintf (logfile
, "movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
2391 dc
->postinc
? "+]" : "]"));
2393 /* FIXME: qemu_st does not act as a barrier? */
2394 tcg_gen_helper_0_0(helper_dummy
);
2396 for (i
= 0; i
<= dc
->op2
; i
++) {
2397 /* Displace addr. */
2398 tcg_gen_addi_tl(cpu_T
[0], cpu_R
[dc
->op1
], i
* 4);
2399 /* Perform the store. */
2400 gen_store(dc
, cpu_T
[0], cpu_R
[i
], 4);
2403 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], i
* 4);
2404 cris_cc_mask(dc
, 0);
2408 static unsigned int dec_move_rm(DisasContext
*dc
)
2412 memsize
= memsize_zz(dc
);
2414 DIS(fprintf (logfile
, "move.%d $r%u, [$r%u]\n",
2415 memsize
, dc
->op2
, dc
->op1
));
2417 /* prepare store. */
2418 /* FIXME: qemu_st does not act as a barrier? */
2419 tcg_gen_helper_0_0(helper_dummy
);
2420 gen_store(dc
, cpu_R
[dc
->op1
], cpu_R
[dc
->op2
], memsize
);
2423 tcg_gen_addi_tl(cpu_R
[dc
->op1
], cpu_R
[dc
->op1
], memsize
);
2424 cris_cc_mask(dc
, 0);
2428 static unsigned int dec_lapcq(DisasContext
*dc
)
2430 DIS(fprintf (logfile
, "lapcq %x, $r%u\n",
2431 dc
->pc
+ dc
->op1
*2, dc
->op2
));
2432 cris_cc_mask(dc
, 0);
2433 tcg_gen_movi_tl(cpu_T
[1], dc
->pc
+ dc
->op1
* 2);
2434 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
2438 static unsigned int dec_lapc_im(DisasContext
*dc
)
2446 cris_cc_mask(dc
, 0);
2447 imm
= ldl_code(dc
->pc
+ 2);
2448 DIS(fprintf (logfile
, "lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
));
2452 t_gen_mov_reg_TN(rd
, tcg_const_tl(pc
));
2456 /* Jump to special reg. */
2457 static unsigned int dec_jump_p(DisasContext
*dc
)
2459 DIS(fprintf (logfile
, "jump $p%u\n", dc
->op2
));
2461 if (dc
->op2
== PR_CCS
)
2462 cris_evaluate_flags(dc
);
2463 t_gen_mov_TN_preg(cpu_T
[0], dc
->op2
);
2464 /* rete will often have low bit set to indicate delayslot. */
2465 tcg_gen_andi_tl(env_btarget
, cpu_T
[0], ~1);
2466 cris_cc_mask(dc
, 0);
2467 cris_prepare_dyn_jmp(dc
);
2471 /* Jump and save. */
2472 static unsigned int dec_jas_r(DisasContext
*dc
)
2474 DIS(fprintf (logfile
, "jas $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2475 cris_cc_mask(dc
, 0);
2476 /* Store the return address in Pd. */
2477 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->op1
]);
2480 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ 4);
2481 tcg_gen_mov_tl(cpu_PR
[dc
->op2
], cpu_T
[0]);
2483 cris_prepare_dyn_jmp(dc
);
2487 static unsigned int dec_jas_im(DisasContext
*dc
)
2491 imm
= ldl_code(dc
->pc
+ 2);
2493 DIS(fprintf (logfile
, "jas 0x%x\n", imm
));
2494 cris_cc_mask(dc
, 0);
2495 /* Store the return address in Pd. */
2496 tcg_gen_movi_tl(env_btarget
, imm
);
2497 t_gen_mov_preg_TN(dc
->op2
, tcg_const_tl(dc
->pc
+ 8));
2498 cris_prepare_dyn_jmp(dc
);
2502 static unsigned int dec_jasc_im(DisasContext
*dc
)
2506 imm
= ldl_code(dc
->pc
+ 2);
2508 DIS(fprintf (logfile
, "jasc 0x%x\n", imm
));
2509 cris_cc_mask(dc
, 0);
2510 /* Store the return address in Pd. */
2511 tcg_gen_movi_tl(cpu_T
[0], imm
);
2512 tcg_gen_mov_tl(env_btarget
, cpu_T
[0]);
2513 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ 8 + 4);
2514 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[0]);
2515 cris_prepare_dyn_jmp(dc
);
2519 static unsigned int dec_jasc_r(DisasContext
*dc
)
2521 DIS(fprintf (logfile
, "jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2522 cris_cc_mask(dc
, 0);
2523 /* Store the return address in Pd. */
2524 t_gen_mov_TN_reg(cpu_T
[0], dc
->op1
);
2525 tcg_gen_mov_tl(env_btarget
, cpu_T
[0]);
2526 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ 4 + 4);
2527 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[0]);
2528 cris_prepare_dyn_jmp(dc
);
2532 static unsigned int dec_bcc_im(DisasContext
*dc
)
2535 uint32_t cond
= dc
->op2
;
2537 offset
= ldsw_code(dc
->pc
+ 2);
2539 DIS(fprintf (logfile
, "b%s %d pc=%x dst=%x\n",
2540 cc_name(cond
), offset
,
2541 dc
->pc
, dc
->pc
+ offset
));
2543 cris_cc_mask(dc
, 0);
2544 /* op2 holds the condition-code. */
2545 cris_prepare_cc_branch (dc
, offset
, cond
);
2549 static unsigned int dec_bas_im(DisasContext
*dc
)
2554 simm
= ldl_code(dc
->pc
+ 2);
2556 DIS(fprintf (logfile
, "bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2557 cris_cc_mask(dc
, 0);
2558 /* Stor the return address in Pd. */
2559 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ simm
);
2560 tcg_gen_mov_tl(env_btarget
, cpu_T
[0]);
2561 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ 8);
2562 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[0]);
2563 cris_prepare_dyn_jmp(dc
);
2567 static unsigned int dec_basc_im(DisasContext
*dc
)
2570 simm
= ldl_code(dc
->pc
+ 2);
2572 DIS(fprintf (logfile
, "basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2573 cris_cc_mask(dc
, 0);
2574 /* Stor the return address in Pd. */
2575 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ simm
);
2576 tcg_gen_mov_tl(env_btarget
, cpu_T
[0]);
2577 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
+ 12);
2578 t_gen_mov_preg_TN(dc
->op2
, cpu_T
[0]);
2579 cris_prepare_dyn_jmp(dc
);
2583 static unsigned int dec_rfe_etc(DisasContext
*dc
)
2585 DIS(fprintf (logfile
, "rfe_etc opc=%x pc=0x%x op1=%d op2=%d\n",
2586 dc
->opcode
, dc
->pc
, dc
->op1
, dc
->op2
));
2588 cris_cc_mask(dc
, 0);
2590 if (dc
->op2
== 15) /* ignore halt. */
2593 switch (dc
->op2
& 7) {
2596 cris_evaluate_flags(dc
);
2597 tcg_gen_helper_0_0(helper_rfe
);
2598 dc
->is_jmp
= DISAS_UPDATE
;
2606 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
);
2607 t_gen_mov_env_TN(pc
, cpu_T
[0]);
2608 /* Breaks start at 16 in the exception vector. */
2609 t_gen_mov_env_TN(trap_vector
,
2610 tcg_const_tl(dc
->op1
+ 16));
2611 t_gen_raise_exception(EXCP_BREAK
);
2612 dc
->is_jmp
= DISAS_UPDATE
;
2615 printf ("op2=%x\n", dc
->op2
);
2623 static unsigned int dec_ftag_fidx_d_m(DisasContext
*dc
)
2625 /* Ignore D-cache flushes. */
2629 static unsigned int dec_ftag_fidx_i_m(DisasContext
*dc
)
2631 /* Ignore I-cache flushes. */
2635 static unsigned int dec_null(DisasContext
*dc
)
2637 printf ("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2638 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2644 struct decoder_info
{
2649 unsigned int (*dec
)(DisasContext
*dc
);
2651 /* Order matters here. */
2652 {DEC_MOVEQ
, dec_moveq
},
2653 {DEC_BTSTQ
, dec_btstq
},
2654 {DEC_CMPQ
, dec_cmpq
},
2655 {DEC_ADDOQ
, dec_addoq
},
2656 {DEC_ADDQ
, dec_addq
},
2657 {DEC_SUBQ
, dec_subq
},
2658 {DEC_ANDQ
, dec_andq
},
2660 {DEC_ASRQ
, dec_asrq
},
2661 {DEC_LSLQ
, dec_lslq
},
2662 {DEC_LSRQ
, dec_lsrq
},
2663 {DEC_BCCQ
, dec_bccq
},
2665 {DEC_BCC_IM
, dec_bcc_im
},
2666 {DEC_JAS_IM
, dec_jas_im
},
2667 {DEC_JAS_R
, dec_jas_r
},
2668 {DEC_JASC_IM
, dec_jasc_im
},
2669 {DEC_JASC_R
, dec_jasc_r
},
2670 {DEC_BAS_IM
, dec_bas_im
},
2671 {DEC_BASC_IM
, dec_basc_im
},
2672 {DEC_JUMP_P
, dec_jump_p
},
2673 {DEC_LAPC_IM
, dec_lapc_im
},
2674 {DEC_LAPCQ
, dec_lapcq
},
2676 {DEC_RFE_ETC
, dec_rfe_etc
},
2677 {DEC_ADDC_MR
, dec_addc_mr
},
2679 {DEC_MOVE_MP
, dec_move_mp
},
2680 {DEC_MOVE_PM
, dec_move_pm
},
2681 {DEC_MOVEM_MR
, dec_movem_mr
},
2682 {DEC_MOVEM_RM
, dec_movem_rm
},
2683 {DEC_MOVE_PR
, dec_move_pr
},
2684 {DEC_SCC_R
, dec_scc_r
},
2685 {DEC_SETF
, dec_setclrf
},
2686 {DEC_CLEARF
, dec_setclrf
},
2688 {DEC_MOVE_SR
, dec_move_sr
},
2689 {DEC_MOVE_RP
, dec_move_rp
},
2690 {DEC_SWAP_R
, dec_swap_r
},
2691 {DEC_ABS_R
, dec_abs_r
},
2692 {DEC_LZ_R
, dec_lz_r
},
2693 {DEC_MOVE_RS
, dec_move_rs
},
2694 {DEC_BTST_R
, dec_btst_r
},
2695 {DEC_ADDC_R
, dec_addc_r
},
2697 {DEC_DSTEP_R
, dec_dstep_r
},
2698 {DEC_XOR_R
, dec_xor_r
},
2699 {DEC_MCP_R
, dec_mcp_r
},
2700 {DEC_CMP_R
, dec_cmp_r
},
2702 {DEC_ADDI_R
, dec_addi_r
},
2703 {DEC_ADDI_ACR
, dec_addi_acr
},
2705 {DEC_ADD_R
, dec_add_r
},
2706 {DEC_SUB_R
, dec_sub_r
},
2708 {DEC_ADDU_R
, dec_addu_r
},
2709 {DEC_ADDS_R
, dec_adds_r
},
2710 {DEC_SUBU_R
, dec_subu_r
},
2711 {DEC_SUBS_R
, dec_subs_r
},
2712 {DEC_LSL_R
, dec_lsl_r
},
2714 {DEC_AND_R
, dec_and_r
},
2715 {DEC_OR_R
, dec_or_r
},
2716 {DEC_BOUND_R
, dec_bound_r
},
2717 {DEC_ASR_R
, dec_asr_r
},
2718 {DEC_LSR_R
, dec_lsr_r
},
2720 {DEC_MOVU_R
, dec_movu_r
},
2721 {DEC_MOVS_R
, dec_movs_r
},
2722 {DEC_NEG_R
, dec_neg_r
},
2723 {DEC_MOVE_R
, dec_move_r
},
2725 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2726 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2728 {DEC_MULS_R
, dec_muls_r
},
2729 {DEC_MULU_R
, dec_mulu_r
},
2731 {DEC_ADDU_M
, dec_addu_m
},
2732 {DEC_ADDS_M
, dec_adds_m
},
2733 {DEC_SUBU_M
, dec_subu_m
},
2734 {DEC_SUBS_M
, dec_subs_m
},
2736 {DEC_CMPU_M
, dec_cmpu_m
},
2737 {DEC_CMPS_M
, dec_cmps_m
},
2738 {DEC_MOVU_M
, dec_movu_m
},
2739 {DEC_MOVS_M
, dec_movs_m
},
2741 {DEC_CMP_M
, dec_cmp_m
},
2742 {DEC_ADDO_M
, dec_addo_m
},
2743 {DEC_BOUND_M
, dec_bound_m
},
2744 {DEC_ADD_M
, dec_add_m
},
2745 {DEC_SUB_M
, dec_sub_m
},
2746 {DEC_AND_M
, dec_and_m
},
2747 {DEC_OR_M
, dec_or_m
},
2748 {DEC_MOVE_RM
, dec_move_rm
},
2749 {DEC_TEST_M
, dec_test_m
},
2750 {DEC_MOVE_MR
, dec_move_mr
},
2755 static inline unsigned int
2756 cris_decoder(DisasContext
*dc
)
2758 unsigned int insn_len
= 2;
2761 /* Load a halfword onto the instruction register. */
2762 dc
->ir
= lduw_code(dc
->pc
);
2764 /* Now decode it. */
2765 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
2766 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
2767 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
2768 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
2769 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
2770 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
2772 /* Large switch for all insns. */
2773 for (i
= 0; i
< sizeof decinfo
/ sizeof decinfo
[0]; i
++) {
2774 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
)
2776 insn_len
= decinfo
[i
].dec(dc
);
2784 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
2787 if (env
->nb_breakpoints
> 0) {
2788 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
2789 if (env
->breakpoints
[j
] == dc
->pc
) {
2790 cris_evaluate_flags (dc
);
2791 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
);
2792 t_gen_mov_env_TN(pc
, cpu_T
[0]);
2793 t_gen_raise_exception(EXCP_DEBUG
);
2794 dc
->is_jmp
= DISAS_UPDATE
;
2800 /* generate intermediate code for basic block 'tb'. */
2801 struct DisasContext ctx
;
2803 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
2806 uint16_t *gen_opc_end
;
2808 unsigned int insn_len
;
2810 struct DisasContext
*dc
= &ctx
;
2811 uint32_t next_page_start
;
2816 /* Odd PC indicates that branch is rexecuting due to exception in the
2817 * delayslot, like in real hw.
2818 * FIXME: we need to handle the case were the branch and the insn in
2819 * the delayslot do not share pages.
2821 pc_start
= tb
->pc
& ~1;
2825 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2827 dc
->is_jmp
= DISAS_NEXT
;
2830 dc
->singlestep_enabled
= env
->singlestep_enabled
;
2835 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
2837 dc
->user
= env
->pregs
[PR_CCS
] & U_FLAG
;
2838 dc
->delayed_branch
= 0;
2840 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2842 "search=%d pc=%x ccs=%x pid=%x usp=%x dbg=%x %x %x\n"
2847 search_pc
, env
->pc
, env
->pregs
[PR_CCS
],
2848 env
->pregs
[PR_PID
], env
->pregs
[PR_USP
],
2849 env
->debug1
, env
->debug2
, env
->debug3
,
2850 env
->regs
[0], env
->regs
[1], env
->regs
[2], env
->regs
[3],
2851 env
->regs
[4], env
->regs
[5], env
->regs
[6], env
->regs
[7],
2852 env
->regs
[8], env
->regs
[9],
2853 env
->regs
[10], env
->regs
[11],
2854 env
->regs
[12], env
->regs
[13],
2855 env
->regs
[14], env
->regs
[15]);
2859 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2863 check_breakpoint(env
, dc
);
2864 if (dc
->is_jmp
== DISAS_JUMP
2865 || dc
->is_jmp
== DISAS_SWI
)
2869 j
= gen_opc_ptr
- gen_opc_buf
;
2873 gen_opc_instr_start
[lj
++] = 0;
2875 if (dc
->delayed_branch
== 1) {
2876 gen_opc_pc
[lj
] = dc
->ppc
| 1;
2877 gen_opc_instr_start
[lj
] = 0;
2880 gen_opc_pc
[lj
] = dc
->pc
;
2881 gen_opc_instr_start
[lj
] = 1;
2886 insn_len
= cris_decoder(dc
);
2890 cris_clear_x_flag(dc
);
2892 /* Check for delayed branches here. If we do it before
2893 actually genereating any host code, the simulator will just
2894 loop doing nothing for on this program location. */
2895 if (dc
->delayed_branch
) {
2896 dc
->delayed_branch
--;
2897 if (dc
->delayed_branch
== 0)
2899 if (dc
->bcc
== CC_A
) {
2900 tcg_gen_mov_tl(env_pc
, env_btarget
);
2901 dc
->is_jmp
= DISAS_JUMP
;
2904 t_gen_cc_jmp(dc
->delayed_pc
, dc
->pc
);
2905 dc
->is_jmp
= DISAS_JUMP
;
2910 /* If we are rexecuting a branch due to exceptions on
2911 delay slots dont break. */
2912 if (!(tb
->pc
& 1) && env
->singlestep_enabled
)
2914 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
2915 && ((dc
->pc
< next_page_start
) || dc
->delayed_branch
));
2917 if (dc
->delayed_branch
== 1) {
2918 /* Reexecute the last insn. */
2919 dc
->pc
= dc
->ppc
| 1;
2923 D(printf("!jmp pc=%x jmp=%d db=%d\n", dc
->pc
,
2924 dc
->is_jmp
, dc
->delayed_branch
));
2925 /* T0 and env_pc should hold the new pc. */
2926 tcg_gen_movi_tl(cpu_T
[0], dc
->pc
);
2927 tcg_gen_mov_tl(env_pc
, cpu_T
[0]);
2930 cris_evaluate_flags (dc
);
2932 if (__builtin_expect(env
->singlestep_enabled
, 0)) {
2933 t_gen_raise_exception(EXCP_DEBUG
);
2935 switch(dc
->is_jmp
) {
2937 gen_goto_tb(dc
, 1, dc
->pc
);
2942 /* indicate that the hash table must be used
2943 to find the next TB */
2948 /* nothing more to generate */
2952 *gen_opc_ptr
= INDEX_op_end
;
2954 j
= gen_opc_ptr
- gen_opc_buf
;
2957 gen_opc_instr_start
[lj
++] = 0;
2959 tb
->size
= dc
->pc
- pc_start
;
2963 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2964 fprintf(logfile
, "--------------\n");
2965 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
2966 target_disas(logfile
, pc_start
, dc
->pc
- pc_start
, 0);
2967 fprintf(logfile
, "\nisize=%d osize=%d\n",
2968 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
2974 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
2976 return gen_intermediate_code_internal(env
, tb
, 0);
2979 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
2981 return gen_intermediate_code_internal(env
, tb
, 1);
2984 void cpu_dump_state (CPUState
*env
, FILE *f
,
2985 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
2994 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
2995 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n"
2997 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
2999 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
,
3000 env
->debug1
, env
->debug2
, env
->debug3
);
3002 for (i
= 0; i
< 16; i
++) {
3003 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
3004 if ((i
+ 1) % 4 == 0)
3005 cpu_fprintf(f
, "\n");
3007 cpu_fprintf(f
, "\nspecial regs:\n");
3008 for (i
= 0; i
< 16; i
++) {
3009 cpu_fprintf(f
, "p%2.2d=%8.8x ", i
, env
->pregs
[i
]);
3010 if ((i
+ 1) % 4 == 0)
3011 cpu_fprintf(f
, "\n");
3013 srs
= env
->pregs
[PR_SRS
];
3014 cpu_fprintf(f
, "\nsupport function regs bank %x:\n", srs
);
3016 for (i
= 0; i
< 16; i
++) {
3017 cpu_fprintf(f
, "s%2.2d=%8.8x ",
3018 i
, env
->sregs
[srs
][i
]);
3019 if ((i
+ 1) % 4 == 0)
3020 cpu_fprintf(f
, "\n");
3023 cpu_fprintf(f
, "\n\n");
3027 static void tcg_macro_func(TCGContext
*s
, int macro_id
, const int *dead_args
)
3031 CPUCRISState
*cpu_cris_init (const char *cpu_model
)
3036 env
= qemu_mallocz(sizeof(CPUCRISState
));
3041 tcg_set_macro_func(&tcg_ctx
, tcg_macro_func
);
3042 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
3043 #if TARGET_LONG_BITS > HOST_LONG_BITS
3044 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
3045 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
3046 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
3047 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
3049 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
3050 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
3053 cc_src
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3054 offsetof(CPUState
, cc_src
), "cc_src");
3055 cc_dest
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3056 offsetof(CPUState
, cc_dest
),
3058 cc_result
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3059 offsetof(CPUState
, cc_result
),
3061 cc_op
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3062 offsetof(CPUState
, cc_op
), "cc_op");
3063 cc_size
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3064 offsetof(CPUState
, cc_size
),
3066 cc_mask
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3067 offsetof(CPUState
, cc_mask
),
3070 env_pc
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3071 offsetof(CPUState
, pc
),
3073 env_btarget
= tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3074 offsetof(CPUState
, btarget
),
3077 for (i
= 0; i
< 16; i
++) {
3078 cpu_R
[i
] = tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3079 offsetof(CPUState
, regs
[i
]),
3082 for (i
= 0; i
< 16; i
++) {
3083 cpu_PR
[i
] = tcg_global_mem_new(TCG_TYPE_PTR
, TCG_AREG0
,
3084 offsetof(CPUState
, pregs
[i
]),
3088 TCG_HELPER(helper_raise_exception
);
3089 TCG_HELPER(helper_store
);
3090 TCG_HELPER(helper_dump
);
3091 TCG_HELPER(helper_dummy
);
3093 TCG_HELPER(helper_tlb_flush
);
3094 TCG_HELPER(helper_movl_sreg_reg
);
3095 TCG_HELPER(helper_movl_reg_sreg
);
3096 TCG_HELPER(helper_rfe
);
3098 TCG_HELPER(helper_evaluate_flags_muls
);
3099 TCG_HELPER(helper_evaluate_flags_mulu
);
3100 TCG_HELPER(helper_evaluate_flags_mcp
);
3101 TCG_HELPER(helper_evaluate_flags_alu_4
);
3102 TCG_HELPER(helper_evaluate_flags_move_4
);
3103 TCG_HELPER(helper_evaluate_flags_move_2
);
3104 TCG_HELPER(helper_evaluate_flags
);
3110 void cpu_reset (CPUCRISState
*env
)
3112 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));
3115 #if defined(CONFIG_USER_ONLY)
3116 /* start in user mode with interrupts enabled. */
3117 env
->pregs
[PR_CCS
] |= U_FLAG
| I_FLAG
;
3119 env
->pregs
[PR_CCS
] = 0;
3123 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
3124 unsigned long searched_pc
, int pc_pos
, void *puc
)
3126 env
->pc
= gen_opc_pc
[pc_pos
];