2 * UniCore32 translation
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or (at your option) any
9 * later version. See the COPYING file in the top-level directory.
18 #include "disas/disas.h"
26 /* internal defines */
27 typedef struct DisasContext
{
30 /* Nonzero if this instruction has been conditionally skipped. */
32 /* The label that will be jumped to when the instruction is skipped. */
34 struct TranslationBlock
*tb
;
35 int singlestep_enabled
;
36 #ifndef CONFIG_USER_ONLY
41 #ifndef CONFIG_USER_ONLY
42 #define IS_USER(s) (s->user)
47 /* These instructions trap after executing, so defer them until after the
48 conditional executions state has been updated. */
49 #define DISAS_SYSCALL 5
51 static TCGv_ptr cpu_env
;
52 static TCGv_i32 cpu_R
[32];
54 /* FIXME: These should be removed. */
55 static TCGv cpu_F0s
, cpu_F1s
;
56 static TCGv_i64 cpu_F0d
, cpu_F1d
;
58 #include "exec/gen-icount.h"
60 static const char *regnames
[] = {
61 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
62 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
63 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
64 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
66 /* initialize TCG globals. */
67 void uc32_translate_init(void)
71 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
73 for (i
= 0; i
< 32; i
++) {
74 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
75 offsetof(CPUUniCore32State
, regs
[i
]), regnames
[i
]);
81 /* Allocate a temporary variable. */
82 static TCGv_i32
new_tmp(void)
85 return tcg_temp_new_i32();
88 /* Release a temporary variable. */
89 static void dead_tmp(TCGv tmp
)
95 static inline TCGv
load_cpu_offset(int offset
)
98 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
102 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUUniCore32State, name))
104 static inline void store_cpu_offset(TCGv var
, int offset
)
106 tcg_gen_st_i32(var
, cpu_env
, offset
);
110 #define store_cpu_field(var, name) \
111 store_cpu_offset(var, offsetof(CPUUniCore32State, name))
113 /* Set a variable to the value of a CPU register. */
114 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
118 /* normaly, since we updated PC */
120 tcg_gen_movi_i32(var
, addr
);
122 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
126 /* Create a new temporary and set it to the value of a CPU register. */
127 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
129 TCGv tmp
= new_tmp();
130 load_reg_var(s
, tmp
, reg
);
134 /* Set a CPU register. The source must be a temporary and will be
136 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
139 tcg_gen_andi_i32(var
, var
, ~3);
140 s
->is_jmp
= DISAS_JUMP
;
142 tcg_gen_mov_i32(cpu_R
[reg
], var
);
146 /* Value extensions. */
147 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
148 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
149 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
150 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
152 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
153 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
154 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
155 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
156 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
157 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
158 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
159 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
160 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
161 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
162 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
163 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
164 #define UCOP_COND (((insn) >> 25) & 0x0f)
165 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
166 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
167 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
168 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
169 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
171 #define UCOP_SET(i) ((insn) & (1 << (i)))
172 #define UCOP_SET_P UCOP_SET(28)
173 #define UCOP_SET_U UCOP_SET(27)
174 #define UCOP_SET_B UCOP_SET(26)
175 #define UCOP_SET_W UCOP_SET(25)
176 #define UCOP_SET_L UCOP_SET(24)
177 #define UCOP_SET_S UCOP_SET(24)
179 #define ILLEGAL cpu_abort(CPU(cpu), \
180 "Illegal UniCore32 instruction %x at line %d!", \
183 #ifndef CONFIG_USER_ONLY
184 static void disas_cp0_insn(CPUUniCore32State
*env
, DisasContext
*s
,
187 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
188 TCGv tmp
, tmp2
, tmp3
;
189 if ((insn
& 0xfe000000) == 0xe0000000) {
192 tcg_gen_movi_i32(tmp2
, UCOP_REG_N
);
193 tcg_gen_movi_i32(tmp3
, UCOP_IMM10
);
196 gen_helper_cp0_get(tmp
, cpu_env
, tmp2
, tmp3
);
197 store_reg(s
, UCOP_REG_D
, tmp
);
199 tmp
= load_reg(s
, UCOP_REG_D
);
200 gen_helper_cp0_set(cpu_env
, tmp
, tmp2
, tmp3
);
210 static void disas_ocd_insn(CPUUniCore32State
*env
, DisasContext
*s
,
213 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
216 if ((insn
& 0xff003fff) == 0xe1000400) {
218 * movc rd, pp.nn, #imm9
220 * nn: UCOP_REG_N (must be 0)
223 if (UCOP_REG_N
== 0) {
225 tcg_gen_movi_i32(tmp
, 0);
226 store_reg(s
, UCOP_REG_D
, tmp
);
232 if ((insn
& 0xff003fff) == 0xe0000401) {
234 * movc pp.nn, rn, #imm9
236 * nn: UCOP_REG_N (must be 1)
239 if (UCOP_REG_N
== 1) {
240 tmp
= load_reg(s
, UCOP_REG_D
);
241 gen_helper_cp1_putc(tmp
);
252 static inline void gen_set_asr(TCGv var
, uint32_t mask
)
254 TCGv tmp_mask
= tcg_const_i32(mask
);
255 gen_helper_asr_write(cpu_env
, var
, tmp_mask
);
256 tcg_temp_free_i32(tmp_mask
);
258 /* Set NZCV flags from the high 4 bits of var. */
259 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
261 static void gen_exception(int excp
)
263 TCGv tmp
= new_tmp();
264 tcg_gen_movi_i32(tmp
, excp
);
265 gen_helper_exception(cpu_env
, tmp
);
269 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, CF))
271 /* Set CF to the top bit of var. */
272 static void gen_set_CF_bit31(TCGv var
)
274 TCGv tmp
= new_tmp();
275 tcg_gen_shri_i32(tmp
, var
, 31);
280 /* Set N and Z flags from var. */
281 static inline void gen_logic_CC(TCGv var
)
283 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, NF
));
284 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, ZF
));
287 /* dest = T0 + T1 + CF. */
288 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
291 tcg_gen_add_i32(dest
, t0
, t1
);
292 tmp
= load_cpu_field(CF
);
293 tcg_gen_add_i32(dest
, dest
, tmp
);
297 /* dest = T0 - T1 + CF - 1. */
298 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
301 tcg_gen_sub_i32(dest
, t0
, t1
);
302 tmp
= load_cpu_field(CF
);
303 tcg_gen_add_i32(dest
, dest
, tmp
);
304 tcg_gen_subi_i32(dest
, dest
, 1);
308 static void shifter_out_im(TCGv var
, int shift
)
310 TCGv tmp
= new_tmp();
312 tcg_gen_andi_i32(tmp
, var
, 1);
314 tcg_gen_shri_i32(tmp
, var
, shift
);
316 tcg_gen_andi_i32(tmp
, tmp
, 1);
323 /* Shift by immediate. Includes special handling for shift == 0. */
324 static inline void gen_uc32_shift_im(TCGv var
, int shiftop
, int shift
,
331 shifter_out_im(var
, 32 - shift
);
333 tcg_gen_shli_i32(var
, var
, shift
);
339 tcg_gen_shri_i32(var
, var
, 31);
342 tcg_gen_movi_i32(var
, 0);
345 shifter_out_im(var
, shift
- 1);
347 tcg_gen_shri_i32(var
, var
, shift
);
355 shifter_out_im(var
, shift
- 1);
360 tcg_gen_sari_i32(var
, var
, shift
);
362 case 3: /* ROR/RRX */
365 shifter_out_im(var
, shift
- 1);
367 tcg_gen_rotri_i32(var
, var
, shift
); break;
369 TCGv tmp
= load_cpu_field(CF
);
371 shifter_out_im(var
, 0);
373 tcg_gen_shri_i32(var
, var
, 1);
374 tcg_gen_shli_i32(tmp
, tmp
, 31);
375 tcg_gen_or_i32(var
, var
, tmp
);
381 static inline void gen_uc32_shift_reg(TCGv var
, int shiftop
,
382 TCGv shift
, int flags
)
387 gen_helper_shl_cc(var
, cpu_env
, var
, shift
);
390 gen_helper_shr_cc(var
, cpu_env
, var
, shift
);
393 gen_helper_sar_cc(var
, cpu_env
, var
, shift
);
396 gen_helper_ror_cc(var
, cpu_env
, var
, shift
);
402 gen_helper_shl(var
, var
, shift
);
405 gen_helper_shr(var
, var
, shift
);
408 gen_helper_sar(var
, var
, shift
);
411 tcg_gen_andi_i32(shift
, shift
, 0x1f);
412 tcg_gen_rotr_i32(var
, var
, shift
);
419 static void gen_test_cc(int cc
, int label
)
427 tmp
= load_cpu_field(ZF
);
428 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
431 tmp
= load_cpu_field(ZF
);
432 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
435 tmp
= load_cpu_field(CF
);
436 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
439 tmp
= load_cpu_field(CF
);
440 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
443 tmp
= load_cpu_field(NF
);
444 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
447 tmp
= load_cpu_field(NF
);
448 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
451 tmp
= load_cpu_field(VF
);
452 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
455 tmp
= load_cpu_field(VF
);
456 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
458 case 8: /* hi: C && !Z */
459 inv
= gen_new_label();
460 tmp
= load_cpu_field(CF
);
461 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
463 tmp
= load_cpu_field(ZF
);
464 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
467 case 9: /* ls: !C || Z */
468 tmp
= load_cpu_field(CF
);
469 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
471 tmp
= load_cpu_field(ZF
);
472 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
474 case 10: /* ge: N == V -> N ^ V == 0 */
475 tmp
= load_cpu_field(VF
);
476 tmp2
= load_cpu_field(NF
);
477 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
479 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
481 case 11: /* lt: N != V -> N ^ V != 0 */
482 tmp
= load_cpu_field(VF
);
483 tmp2
= load_cpu_field(NF
);
484 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
486 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
488 case 12: /* gt: !Z && N == V */
489 inv
= gen_new_label();
490 tmp
= load_cpu_field(ZF
);
491 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
493 tmp
= load_cpu_field(VF
);
494 tmp2
= load_cpu_field(NF
);
495 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
497 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
500 case 13: /* le: Z || N != V */
501 tmp
= load_cpu_field(ZF
);
502 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
504 tmp
= load_cpu_field(VF
);
505 tmp2
= load_cpu_field(NF
);
506 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
508 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
511 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
517 static const uint8_t table_logic_cc
[16] = {
518 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
519 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
520 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
521 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
524 /* Set PC state from an immediate address. */
525 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
527 s
->is_jmp
= DISAS_UPDATE
;
528 tcg_gen_movi_i32(cpu_R
[31], addr
& ~3);
531 /* Set PC state from var. var is marked as dead. */
532 static inline void gen_bx(DisasContext
*s
, TCGv var
)
534 s
->is_jmp
= DISAS_UPDATE
;
535 tcg_gen_andi_i32(cpu_R
[31], var
, ~3);
539 static inline void store_reg_bx(DisasContext
*s
, int reg
, TCGv var
)
541 store_reg(s
, reg
, var
);
544 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
546 TCGv tmp
= new_tmp();
547 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
551 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
553 TCGv tmp
= new_tmp();
554 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
558 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
560 TCGv tmp
= new_tmp();
561 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
565 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
567 TCGv tmp
= new_tmp();
568 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
572 static inline TCGv
gen_ld32(TCGv addr
, int index
)
574 TCGv tmp
= new_tmp();
575 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
579 static inline TCGv_i64
gen_ld64(TCGv addr
, int index
)
581 TCGv_i64 tmp
= tcg_temp_new_i64();
582 tcg_gen_qemu_ld64(tmp
, addr
, index
);
586 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
588 tcg_gen_qemu_st8(val
, addr
, index
);
592 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
594 tcg_gen_qemu_st16(val
, addr
, index
);
598 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
600 tcg_gen_qemu_st32(val
, addr
, index
);
604 static inline void gen_st64(TCGv_i64 val
, TCGv addr
, int index
)
606 tcg_gen_qemu_st64(val
, addr
, index
);
607 tcg_temp_free_i64(val
);
610 static inline void gen_set_pc_im(uint32_t val
)
612 tcg_gen_movi_i32(cpu_R
[31], val
);
615 /* Force a TB lookup after an instruction that changes the CPU state. */
616 static inline void gen_lookup_tb(DisasContext
*s
)
618 tcg_gen_movi_i32(cpu_R
[31], s
->pc
& ~1);
619 s
->is_jmp
= DISAS_UPDATE
;
622 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
635 tcg_gen_addi_i32(var
, var
, val
);
639 offset
= load_reg(s
, UCOP_REG_M
);
640 gen_uc32_shift_im(offset
, UCOP_SH_OP
, UCOP_SH_IM
, 0);
642 tcg_gen_sub_i32(var
, var
, offset
);
644 tcg_gen_add_i32(var
, var
, offset
);
650 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
658 val
= (insn
& 0x1f) | ((insn
>> 4) & 0x3e0);
663 tcg_gen_addi_i32(var
, var
, val
);
667 offset
= load_reg(s
, UCOP_REG_M
);
669 tcg_gen_sub_i32(var
, var
, offset
);
671 tcg_gen_add_i32(var
, var
, offset
);
677 static inline long ucf64_reg_offset(int reg
)
680 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
681 + offsetof(CPU_DoubleU
, l
.upper
);
683 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
684 + offsetof(CPU_DoubleU
, l
.lower
);
688 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
689 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
691 /* UniCore-F64 single load/store I_offset */
692 static void do_ucf64_ldst_i(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
694 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
699 addr
= load_reg(s
, UCOP_REG_N
);
700 if (!UCOP_SET_P
&& !UCOP_SET_W
) {
705 offset
= UCOP_IMM10
<< 2;
710 tcg_gen_addi_i32(addr
, addr
, offset
);
714 if (UCOP_SET_L
) { /* load */
715 tmp
= gen_ld32(addr
, IS_USER(s
));
716 ucf64_gen_st32(tmp
, UCOP_REG_D
);
718 tmp
= ucf64_gen_ld32(UCOP_REG_D
);
719 gen_st32(tmp
, addr
, IS_USER(s
));
723 offset
= UCOP_IMM10
<< 2;
728 tcg_gen_addi_i32(addr
, addr
, offset
);
732 store_reg(s
, UCOP_REG_N
, addr
);
738 /* UniCore-F64 load/store multiple words */
739 static void do_ucf64_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
741 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
747 if (UCOP_REG_D
!= 0) {
750 if (UCOP_REG_N
== 31) {
753 if ((insn
<< 24) == 0) {
757 addr
= load_reg(s
, UCOP_REG_N
);
760 for (i
= 0; i
< 8; i
++) {
767 if (UCOP_SET_P
) { /* pre increment */
768 tcg_gen_addi_i32(addr
, addr
, 4);
769 } /* unnecessary to do anything when post increment */
771 if (UCOP_SET_P
) { /* pre decrement */
772 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
773 } else { /* post decrement */
775 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
780 freg
= ((insn
>> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
782 for (i
= 0, j
= 0; i
< 8; i
++, freg
++) {
787 if (UCOP_SET_L
) { /* load */
788 tmp
= gen_ld32(addr
, IS_USER(s
));
789 ucf64_gen_st32(tmp
, freg
);
791 tmp
= ucf64_gen_ld32(freg
);
792 gen_st32(tmp
, addr
, IS_USER(s
));
796 /* unnecessary to add after the last transfer */
798 tcg_gen_addi_i32(addr
, addr
, 4);
802 if (UCOP_SET_W
) { /* write back */
804 if (!UCOP_SET_P
) { /* post increment */
805 tcg_gen_addi_i32(addr
, addr
, 4);
806 } /* unnecessary to do anything when pre increment */
811 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
815 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
818 store_reg(s
, UCOP_REG_N
, addr
);
824 /* UniCore-F64 mrc/mcr */
825 static void do_ucf64_trans(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
827 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
830 if ((insn
& 0xfe0003ff) == 0xe2000000) {
831 /* control register */
832 if ((UCOP_REG_N
!= UC32_UCF64_FPSCR
) || (UCOP_REG_D
== 31)) {
838 gen_helper_ucf64_get_fpscr(tmp
, cpu_env
);
839 store_reg(s
, UCOP_REG_D
, tmp
);
842 tmp
= load_reg(s
, UCOP_REG_D
);
843 gen_helper_ucf64_set_fpscr(cpu_env
, tmp
);
849 if ((insn
& 0xfe0003ff) == 0xe0000000) {
850 /* general register */
851 if (UCOP_REG_D
== 31) {
854 if (UCOP_SET(24)) { /* MFF */
855 tmp
= ucf64_gen_ld32(UCOP_REG_N
);
856 store_reg(s
, UCOP_REG_D
, tmp
);
858 tmp
= load_reg(s
, UCOP_REG_D
);
859 ucf64_gen_st32(tmp
, UCOP_REG_N
);
863 if ((insn
& 0xfb000000) == 0xe9000000) {
865 if (UCOP_REG_D
!= 31) {
868 if (UCOP_UCF64_COND
& 0x8) {
873 tcg_gen_movi_i32(tmp
, UCOP_UCF64_COND
);
875 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
876 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
877 gen_helper_ucf64_cmpd(cpu_F0d
, cpu_F1d
, tmp
, cpu_env
);
879 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
880 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
881 gen_helper_ucf64_cmps(cpu_F0s
, cpu_F1s
, tmp
, cpu_env
);
889 /* UniCore-F64 convert instructions */
890 static void do_ucf64_fcvt(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
892 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
894 if (UCOP_UCF64_FMT
== 3) {
897 if (UCOP_REG_N
!= 0) {
900 switch (UCOP_UCF64_FUNC
) {
902 switch (UCOP_UCF64_FMT
) {
904 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
905 gen_helper_ucf64_df2sf(cpu_F0s
, cpu_F0d
, cpu_env
);
906 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
909 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
910 gen_helper_ucf64_si2sf(cpu_F0s
, cpu_F0s
, cpu_env
);
911 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
919 switch (UCOP_UCF64_FMT
) {
921 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
922 gen_helper_ucf64_sf2df(cpu_F0d
, cpu_F0s
, cpu_env
);
923 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
926 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
927 gen_helper_ucf64_si2df(cpu_F0d
, cpu_F0s
, cpu_env
);
928 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
936 switch (UCOP_UCF64_FMT
) {
938 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
939 gen_helper_ucf64_sf2si(cpu_F0s
, cpu_F0s
, cpu_env
);
940 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
943 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
944 gen_helper_ucf64_df2si(cpu_F0s
, cpu_F0d
, cpu_env
);
945 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
957 /* UniCore-F64 compare instructions */
958 static void do_ucf64_fcmp(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
960 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
965 if (UCOP_REG_D
!= 0) {
971 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
972 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
973 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
975 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
976 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
977 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
981 #define gen_helper_ucf64_movs(x, y) do { } while (0)
982 #define gen_helper_ucf64_movd(x, y) do { } while (0)
984 #define UCF64_OP1(name) do { \
985 if (UCOP_REG_N != 0) { \
988 switch (UCOP_UCF64_FMT) { \
990 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
991 ucf64_reg_offset(UCOP_REG_M)); \
992 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
993 tcg_gen_st_i32(cpu_F0s, cpu_env, \
994 ucf64_reg_offset(UCOP_REG_D)); \
997 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
998 ucf64_reg_offset(UCOP_REG_M)); \
999 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
1000 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1001 ucf64_reg_offset(UCOP_REG_D)); \
1009 #define UCF64_OP2(name) do { \
1010 switch (UCOP_UCF64_FMT) { \
1012 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
1013 ucf64_reg_offset(UCOP_REG_N)); \
1014 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
1015 ucf64_reg_offset(UCOP_REG_M)); \
1016 gen_helper_ucf64_##name##s(cpu_F0s, \
1017 cpu_F0s, cpu_F1s, cpu_env); \
1018 tcg_gen_st_i32(cpu_F0s, cpu_env, \
1019 ucf64_reg_offset(UCOP_REG_D)); \
1022 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
1023 ucf64_reg_offset(UCOP_REG_N)); \
1024 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
1025 ucf64_reg_offset(UCOP_REG_M)); \
1026 gen_helper_ucf64_##name##d(cpu_F0d, \
1027 cpu_F0d, cpu_F1d, cpu_env); \
1028 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1029 ucf64_reg_offset(UCOP_REG_D)); \
1037 /* UniCore-F64 data processing */
1038 static void do_ucf64_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1040 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1042 if (UCOP_UCF64_FMT
== 3) {
1045 switch (UCOP_UCF64_FUNC
) {
1072 /* Disassemble an F64 instruction */
1073 static void disas_ucf64_insn(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1075 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1077 if (!UCOP_SET(29)) {
1079 do_ucf64_ldst_m(env
, s
, insn
);
1081 do_ucf64_ldst_i(env
, s
, insn
);
1085 switch ((insn
>> 26) & 0x3) {
1087 do_ucf64_datap(env
, s
, insn
);
1093 do_ucf64_fcvt(env
, s
, insn
);
1096 do_ucf64_fcmp(env
, s
, insn
);
1100 do_ucf64_trans(env
, s
, insn
);
1105 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
1107 TranslationBlock
*tb
;
1110 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1112 gen_set_pc_im(dest
);
1113 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
1115 gen_set_pc_im(dest
);
1120 static inline void gen_jmp(DisasContext
*s
, uint32_t dest
)
1122 if (unlikely(s
->singlestep_enabled
)) {
1123 /* An indirect jump so that we still trigger the debug exception. */
1126 gen_goto_tb(s
, 0, dest
);
1127 s
->is_jmp
= DISAS_TB_JUMP
;
1131 static inline void gen_mulxy(TCGv t0
, TCGv t1
, int x
, int y
)
1134 tcg_gen_sari_i32(t0
, t0
, 16);
1139 tcg_gen_sari_i32(t1
, t1
, 16);
1143 tcg_gen_mul_i32(t0
, t0
, t1
);
1146 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1147 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int bsr
, TCGv t0
)
1151 /* ??? This is also undefined in system mode. */
1156 tmp
= load_cpu_field(bsr
);
1157 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
1158 tcg_gen_andi_i32(t0
, t0
, mask
);
1159 tcg_gen_or_i32(tmp
, tmp
, t0
);
1160 store_cpu_field(tmp
, bsr
);
1162 gen_set_asr(t0
, mask
);
1169 /* Generate an old-style exception return. Marks pc as dead. */
1170 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
1173 store_reg(s
, 31, pc
);
1174 tmp
= load_cpu_field(bsr
);
1175 gen_set_asr(tmp
, 0xffffffff);
1177 s
->is_jmp
= DISAS_UPDATE
;
1180 static void disas_coproc_insn(CPUUniCore32State
*env
, DisasContext
*s
,
1183 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1185 switch (UCOP_CPNUM
) {
1186 #ifndef CONFIG_USER_ONLY
1188 disas_cp0_insn(env
, s
, insn
);
1191 disas_ocd_insn(env
, s
, insn
);
1195 disas_ucf64_insn(env
, s
, insn
);
1198 /* Unknown coprocessor. */
1199 cpu_abort(CPU(cpu
), "Unknown coprocessor!");
1203 /* data processing instructions */
1204 static void do_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1206 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1211 if (UCOP_OPCODES
== 0x0f || UCOP_OPCODES
== 0x0d) {
1212 if (UCOP_SET(23)) { /* CMOV instructions */
1213 if ((UCOP_CMOV_COND
== 0xe) || (UCOP_CMOV_COND
== 0xf)) {
1216 /* if not always execute, we generate a conditional jump to
1218 s
->condlabel
= gen_new_label();
1219 gen_test_cc(UCOP_CMOV_COND
^ 1, s
->condlabel
);
1224 logic_cc
= table_logic_cc
[UCOP_OPCODES
] & (UCOP_SET_S
>> 24);
1228 /* immediate operand */
1231 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1234 tcg_gen_movi_i32(tmp2
, val
);
1235 if (logic_cc
&& UCOP_SH_IM
) {
1236 gen_set_CF_bit31(tmp2
);
1240 tmp2
= load_reg(s
, UCOP_REG_M
);
1242 tmp
= load_reg(s
, UCOP_REG_S
);
1243 gen_uc32_shift_reg(tmp2
, UCOP_SH_OP
, tmp
, logic_cc
);
1245 gen_uc32_shift_im(tmp2
, UCOP_SH_OP
, UCOP_SH_IM
, logic_cc
);
1249 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1250 tmp
= load_reg(s
, UCOP_REG_N
);
1255 switch (UCOP_OPCODES
) {
1257 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1261 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1264 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1268 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1271 if (UCOP_SET_S
&& UCOP_REG_D
== 31) {
1272 /* SUBS r31, ... is used for exception return. */
1276 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1277 gen_exception_return(s
, tmp
);
1280 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1282 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
1284 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1289 gen_helper_sub_cc(tmp
, cpu_env
, tmp2
, tmp
);
1291 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
1293 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1297 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1299 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1301 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1305 gen_helper_adc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1307 gen_add_carry(tmp
, tmp
, tmp2
);
1309 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1313 gen_helper_sbc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1315 gen_sub_carry(tmp
, tmp
, tmp2
);
1317 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1321 gen_helper_sbc_cc(tmp
, cpu_env
, tmp2
, tmp
);
1323 gen_sub_carry(tmp
, tmp2
, tmp
);
1325 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1329 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1336 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1343 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1349 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1354 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1358 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1361 if (logic_cc
&& UCOP_REG_D
== 31) {
1362 /* MOVS r31, ... is used for exception return. */
1366 gen_exception_return(s
, tmp2
);
1371 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1375 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1379 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1383 tcg_gen_not_i32(tmp2
, tmp2
);
1387 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1390 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1396 static void do_mult(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1398 TCGv tmp
, tmp2
, tmp3
, tmp4
;
1402 tmp
= load_reg(s
, UCOP_REG_M
);
1403 tmp2
= load_reg(s
, UCOP_REG_N
);
1405 tcg_gen_muls2_i32(tmp
, tmp2
, tmp
, tmp2
);
1407 tcg_gen_mulu2_i32(tmp
, tmp2
, tmp
, tmp2
);
1409 if (UCOP_SET(25)) { /* mult accumulate */
1410 tmp3
= load_reg(s
, UCOP_REG_LO
);
1411 tmp4
= load_reg(s
, UCOP_REG_HI
);
1412 tcg_gen_add2_i32(tmp
, tmp2
, tmp
, tmp2
, tmp3
, tmp4
);
1416 store_reg(s
, UCOP_REG_LO
, tmp
);
1417 store_reg(s
, UCOP_REG_HI
, tmp2
);
1420 tmp
= load_reg(s
, UCOP_REG_M
);
1421 tmp2
= load_reg(s
, UCOP_REG_N
);
1422 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
1426 tmp2
= load_reg(s
, UCOP_REG_S
);
1427 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1433 store_reg(s
, UCOP_REG_D
, tmp
);
1437 /* miscellaneous instructions */
1438 static void do_misc(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1440 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1444 if ((insn
& 0xffffffe0) == 0x10ffc120) {
1445 /* Trivial implementation equivalent to bx. */
1446 tmp
= load_reg(s
, UCOP_REG_M
);
1451 if ((insn
& 0xfbffc000) == 0x30ffc000) {
1452 /* PSR = immediate */
1455 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1458 tcg_gen_movi_i32(tmp
, val
);
1459 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1465 if ((insn
& 0xfbffffe0) == 0x12ffc020) {
1466 /* PSR.flag = reg */
1467 tmp
= load_reg(s
, UCOP_REG_M
);
1468 if (gen_set_psr(s
, ASR_NZCV
, UCOP_SET_B
, tmp
)) {
1474 if ((insn
& 0xfbffffe0) == 0x10ffc020) {
1476 tmp
= load_reg(s
, UCOP_REG_M
);
1477 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1483 if ((insn
& 0xfbf83fff) == 0x10f80000) {
1489 tmp
= load_cpu_field(bsr
);
1492 gen_helper_asr_read(tmp
, cpu_env
);
1494 store_reg(s
, UCOP_REG_D
, tmp
);
1498 if ((insn
& 0xfbf83fe0) == 0x12f80120) {
1500 tmp
= load_reg(s
, UCOP_REG_M
);
1502 gen_helper_clo(tmp
, tmp
);
1504 gen_helper_clz(tmp
, tmp
);
1506 store_reg(s
, UCOP_REG_D
, tmp
);
1514 /* load/store I_offset and R_offset */
1515 static void do_ldst_ir(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1517 unsigned int mmu_idx
;
1521 tmp2
= load_reg(s
, UCOP_REG_N
);
1522 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1526 gen_add_data_offset(s
, insn
, tmp2
);
1532 tmp
= gen_ld8u(tmp2
, mmu_idx
);
1534 tmp
= gen_ld32(tmp2
, mmu_idx
);
1538 tmp
= load_reg(s
, UCOP_REG_D
);
1540 gen_st8(tmp
, tmp2
, mmu_idx
);
1542 gen_st32(tmp
, tmp2
, mmu_idx
);
1546 gen_add_data_offset(s
, insn
, tmp2
);
1547 store_reg(s
, UCOP_REG_N
, tmp2
);
1548 } else if (UCOP_SET_W
) {
1549 store_reg(s
, UCOP_REG_N
, tmp2
);
1554 /* Complete the load. */
1555 if (UCOP_REG_D
== 31) {
1558 store_reg(s
, UCOP_REG_D
, tmp
);
1563 /* SWP instruction */
1564 static void do_swap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1566 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1571 if ((insn
& 0xff003fe0) != 0x40000120) {
1575 /* ??? This is not really atomic. However we know
1576 we never have multiple CPUs running in parallel,
1577 so it is good enough. */
1578 addr
= load_reg(s
, UCOP_REG_N
);
1579 tmp
= load_reg(s
, UCOP_REG_M
);
1581 tmp2
= gen_ld8u(addr
, IS_USER(s
));
1582 gen_st8(tmp
, addr
, IS_USER(s
));
1584 tmp2
= gen_ld32(addr
, IS_USER(s
));
1585 gen_st32(tmp
, addr
, IS_USER(s
));
1588 store_reg(s
, UCOP_REG_D
, tmp2
);
1591 /* load/store hw/sb */
1592 static void do_ldst_hwsb(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1594 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1598 if (UCOP_SH_OP
== 0) {
1599 do_swap(env
, s
, insn
);
1603 addr
= load_reg(s
, UCOP_REG_N
);
1605 gen_add_datah_offset(s
, insn
, addr
);
1608 if (UCOP_SET_L
) { /* load */
1609 switch (UCOP_SH_OP
) {
1611 tmp
= gen_ld16u(addr
, IS_USER(s
));
1614 tmp
= gen_ld8s(addr
, IS_USER(s
));
1616 default: /* see do_swap */
1618 tmp
= gen_ld16s(addr
, IS_USER(s
));
1621 } else { /* store */
1622 if (UCOP_SH_OP
!= 1) {
1625 tmp
= load_reg(s
, UCOP_REG_D
);
1626 gen_st16(tmp
, addr
, IS_USER(s
));
1628 /* Perform base writeback before the loaded value to
1629 ensure correct behavior with overlapping index registers. */
1631 gen_add_datah_offset(s
, insn
, addr
);
1632 store_reg(s
, UCOP_REG_N
, addr
);
1633 } else if (UCOP_SET_W
) {
1634 store_reg(s
, UCOP_REG_N
, addr
);
1639 /* Complete the load. */
1640 store_reg(s
, UCOP_REG_D
, tmp
);
1644 /* load/store multiple words */
1645 static void do_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1647 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1648 unsigned int val
, i
, mmu_idx
;
1649 int j
, n
, reg
, user
, loaded_base
;
1658 /* XXX: store correct base if write back */
1660 if (UCOP_SET_B
) { /* S bit in instruction table */
1662 ILLEGAL
; /* only usable in supervisor mode */
1664 if (UCOP_SET(18) == 0) { /* pc reg */
1669 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1670 addr
= load_reg(s
, UCOP_REG_N
);
1672 /* compute total size */
1674 TCGV_UNUSED(loaded_var
);
1676 for (i
= 0; i
< 6; i
++) {
1681 for (i
= 9; i
< 19; i
++) {
1686 /* XXX: test invalid n == 0 case ? */
1690 tcg_gen_addi_i32(addr
, addr
, 4);
1692 /* post increment */
1697 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1699 /* post decrement */
1701 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1707 reg
= UCOP_SET(6) ? 16 : 0;
1708 for (i
= 0; i
< 19; i
++, reg
++) {
1713 if (UCOP_SET_L
) { /* load */
1714 tmp
= gen_ld32(addr
, mmu_idx
);
1718 tmp2
= tcg_const_i32(reg
);
1719 gen_helper_set_user_reg(cpu_env
, tmp2
, tmp
);
1720 tcg_temp_free_i32(tmp2
);
1722 } else if (reg
== UCOP_REG_N
) {
1726 store_reg(s
, reg
, tmp
);
1728 } else { /* store */
1730 /* special case: r31 = PC + 4 */
1733 tcg_gen_movi_i32(tmp
, val
);
1736 tmp2
= tcg_const_i32(reg
);
1737 gen_helper_get_user_reg(tmp
, cpu_env
, tmp2
);
1738 tcg_temp_free_i32(tmp2
);
1740 tmp
= load_reg(s
, reg
);
1742 gen_st32(tmp
, addr
, mmu_idx
);
1745 /* no need to add after the last transfer */
1747 tcg_gen_addi_i32(addr
, addr
, 4);
1751 if (UCOP_SET_W
) { /* write back */
1756 /* post increment */
1757 tcg_gen_addi_i32(addr
, addr
, 4);
1763 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1766 /* post decrement */
1767 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1770 store_reg(s
, UCOP_REG_N
, addr
);
1775 store_reg(s
, UCOP_REG_N
, loaded_var
);
1777 if (UCOP_SET_B
&& !user
) {
1778 /* Restore ASR from BSR. */
1779 tmp
= load_cpu_field(bsr
);
1780 gen_set_asr(tmp
, 0xffffffff);
1782 s
->is_jmp
= DISAS_UPDATE
;
1786 /* branch (and link) */
1787 static void do_branch(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1789 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1794 if (UCOP_COND
== 0xf) {
1798 if (UCOP_COND
!= 0xe) {
1799 /* if not always execute, we generate a conditional jump to
1801 s
->condlabel
= gen_new_label();
1802 gen_test_cc(UCOP_COND
^ 1, s
->condlabel
);
1806 val
= (int32_t)s
->pc
;
1809 tcg_gen_movi_i32(tmp
, val
);
1810 store_reg(s
, 30, tmp
);
1812 offset
= (((int32_t)insn
<< 8) >> 8);
1813 val
+= (offset
<< 2); /* unicore is pc+4 */
1817 static void disas_uc32_insn(CPUUniCore32State
*env
, DisasContext
*s
)
1819 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1822 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
1823 tcg_gen_debug_insn_start(s
->pc
);
1826 insn
= cpu_ldl_code(env
, s
->pc
);
1829 /* UniCore instructions class:
1830 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1831 * AAA : see switch case
1832 * BBBB : opcodes or cond or PUBW
1837 switch (insn
>> 29) {
1839 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1840 do_mult(env
, s
, insn
);
1845 do_misc(env
, s
, insn
);
1849 if (((UCOP_OPCODES
>> 2) == 2) && !UCOP_SET_S
) {
1850 do_misc(env
, s
, insn
);
1853 do_datap(env
, s
, insn
);
1857 if (UCOP_SET(8) && UCOP_SET(5)) {
1858 do_ldst_hwsb(env
, s
, insn
);
1861 if (UCOP_SET(8) || UCOP_SET(5)) {
1865 do_ldst_ir(env
, s
, insn
);
1870 ILLEGAL
; /* extended instructions */
1872 do_ldst_m(env
, s
, insn
);
1875 do_branch(env
, s
, insn
);
1879 disas_coproc_insn(env
, s
, insn
);
1882 if (!UCOP_SET(28)) {
1883 disas_coproc_insn(env
, s
, insn
);
1886 if ((insn
& 0xff000000) == 0xff000000) { /* syscall */
1887 gen_set_pc_im(s
->pc
);
1888 s
->is_jmp
= DISAS_SYSCALL
;
1895 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
1896 basic block 'tb'. If search_pc is TRUE, also generate PC
1897 information for each intermediate instruction. */
1898 static inline void gen_intermediate_code_internal(UniCore32CPU
*cpu
,
1899 TranslationBlock
*tb
, bool search_pc
)
1901 CPUState
*cs
= CPU(cpu
);
1902 CPUUniCore32State
*env
= &cpu
->env
;
1903 DisasContext dc1
, *dc
= &dc1
;
1905 uint16_t *gen_opc_end
;
1907 target_ulong pc_start
;
1908 uint32_t next_page_start
;
1912 /* generate intermediate code */
1919 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
1921 dc
->is_jmp
= DISAS_NEXT
;
1923 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1925 cpu_F0s
= tcg_temp_new_i32();
1926 cpu_F1s
= tcg_temp_new_i32();
1927 cpu_F0d
= tcg_temp_new_i64();
1928 cpu_F1d
= tcg_temp_new_i64();
1929 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1932 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1933 if (max_insns
== 0) {
1934 max_insns
= CF_COUNT_MASK
;
1937 #ifndef CONFIG_USER_ONLY
1938 if ((env
->uncached_asr
& ASR_M
) == ASR_MODE_USER
) {
1947 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
1948 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
1949 if (bp
->pc
== dc
->pc
) {
1950 gen_set_pc_im(dc
->pc
);
1951 gen_exception(EXCP_DEBUG
);
1952 dc
->is_jmp
= DISAS_JUMP
;
1953 /* Advance PC so that clearing the breakpoint will
1954 invalidate this TB. */
1955 dc
->pc
+= 2; /* FIXME */
1956 goto done_generating
;
1961 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1965 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
1968 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
1969 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
1970 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
1973 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1977 disas_uc32_insn(env
, dc
);
1980 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
1984 if (dc
->condjmp
&& !dc
->is_jmp
) {
1985 gen_set_label(dc
->condlabel
);
1988 /* Translation stops when a conditional branch is encountered.
1989 * Otherwise the subsequent code could get translated several times.
1990 * Also stop translation when a page boundary is reached. This
1991 * ensures prefetch aborts occur at the right place. */
1993 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
1994 !cs
->singlestep_enabled
&&
1996 dc
->pc
< next_page_start
&&
1997 num_insns
< max_insns
);
1999 if (tb
->cflags
& CF_LAST_IO
) {
2001 /* FIXME: This can theoretically happen with self-modifying
2003 cpu_abort(cs
, "IO on conditional branch instruction");
2008 /* At this stage dc->condjmp will only be set when the skipped
2009 instruction was a conditional branch or trap, and the PC has
2010 already been written. */
2011 if (unlikely(cs
->singlestep_enabled
)) {
2012 /* Make sure the pc is updated, and raise a debug exception. */
2014 if (dc
->is_jmp
== DISAS_SYSCALL
) {
2015 gen_exception(UC32_EXCP_PRIV
);
2017 gen_exception(EXCP_DEBUG
);
2019 gen_set_label(dc
->condlabel
);
2021 if (dc
->condjmp
|| !dc
->is_jmp
) {
2022 gen_set_pc_im(dc
->pc
);
2025 if (dc
->is_jmp
== DISAS_SYSCALL
&& !dc
->condjmp
) {
2026 gen_exception(UC32_EXCP_PRIV
);
2028 gen_exception(EXCP_DEBUG
);
2031 /* While branches must always occur at the end of an IT block,
2032 there are a few other things that can cause us to terminate
2033 the TB in the middel of an IT block:
2034 - Exception generating instructions (bkpt, swi, undefined).
2036 - Hardware watchpoints.
2037 Hardware breakpoints have already been handled and skip this code.
2039 switch (dc
->is_jmp
) {
2041 gen_goto_tb(dc
, 1, dc
->pc
);
2046 /* indicate that the hash table must be used to find the next TB */
2050 /* nothing more to generate */
2053 gen_exception(UC32_EXCP_PRIV
);
2057 gen_set_label(dc
->condlabel
);
2058 gen_goto_tb(dc
, 1, dc
->pc
);
2064 gen_tb_end(tb
, num_insns
);
2065 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
2068 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2069 qemu_log("----------------\n");
2070 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2071 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
, 0);
2076 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2079 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2082 tb
->size
= dc
->pc
- pc_start
;
2083 tb
->icount
= num_insns
;
2087 void gen_intermediate_code(CPUUniCore32State
*env
, TranslationBlock
*tb
)
2089 gen_intermediate_code_internal(uc32_env_get_cpu(env
), tb
, false);
2092 void gen_intermediate_code_pc(CPUUniCore32State
*env
, TranslationBlock
*tb
)
2094 gen_intermediate_code_internal(uc32_env_get_cpu(env
), tb
, true);
2097 static const char *cpu_mode_names
[16] = {
2098 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2099 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2102 #undef UCF64_DUMP_STATE
2103 #ifdef UCF64_DUMP_STATE
2104 static void cpu_dump_state_ucf64(CPUUniCore32State
*env
, FILE *f
,
2105 fprintf_function cpu_fprintf
, int flags
)
2113 /* ??? This assumes float64 and double have the same layout.
2114 Oh well, it's only debug dumps. */
2120 for (i
= 0; i
< 16; i
++) {
2121 d
.d
= env
->ucf64
.regs
[i
];
2125 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g)",
2126 i
* 2, (int)s0
.i
, s0
.s
,
2127 i
* 2 + 1, (int)s1
.i
, s1
.s
);
2128 cpu_fprintf(f
, " d%02d=%" PRIx64
"(%8g)\n",
2129 i
, (uint64_t)d0
.f64
, d0
.d
);
2131 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->ucf64
.xregs
[UC32_UCF64_FPSCR
]);
2134 #define cpu_dump_state_ucf64(env, file, pr, flags) do { } while (0)
2137 void uc32_cpu_dump_state(CPUState
*cs
, FILE *f
,
2138 fprintf_function cpu_fprintf
, int flags
)
2140 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
2141 CPUUniCore32State
*env
= &cpu
->env
;
2145 for (i
= 0; i
< 32; i
++) {
2146 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
2148 cpu_fprintf(f
, "\n");
2150 cpu_fprintf(f
, " ");
2153 psr
= cpu_asr_read(env
);
2154 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %s\n",
2156 psr
& (1 << 31) ? 'N' : '-',
2157 psr
& (1 << 30) ? 'Z' : '-',
2158 psr
& (1 << 29) ? 'C' : '-',
2159 psr
& (1 << 28) ? 'V' : '-',
2160 cpu_mode_names
[psr
& 0xf]);
2162 cpu_dump_state_ucf64(env
, f
, cpu_fprintf
, flags
);
2165 void restore_state_to_opc(CPUUniCore32State
*env
, TranslationBlock
*tb
, int pc_pos
)
2167 env
->regs
[31] = tcg_ctx
.gen_opc_pc
[pc_pos
];