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.
11 #include "qemu/osdep.h"
14 #include "disas/disas.h"
15 #include "exec/exec-all.h"
18 #include "exec/cpu_ldst.h"
20 #include "exec/helper-proto.h"
21 #include "exec/helper-gen.h"
23 #include "trace-tcg.h"
27 /* internal defines */
28 typedef struct DisasContext
{
31 /* Nonzero if this instruction has been conditionally skipped. */
33 /* The label that will be jumped to when the instruction is skipped. */
35 struct TranslationBlock
*tb
;
36 int singlestep_enabled
;
37 #ifndef CONFIG_USER_ONLY
42 #ifndef CONFIG_USER_ONLY
43 #define IS_USER(s) (s->user)
48 /* These instructions trap after executing, so defer them until after the
49 conditional executions state has been updated. */
50 #define DISAS_SYSCALL 5
52 static TCGv_env cpu_env
;
53 static TCGv_i32 cpu_R
[32];
55 /* FIXME: These should be removed. */
56 static TCGv cpu_F0s
, cpu_F1s
;
57 static TCGv_i64 cpu_F0d
, cpu_F1d
;
59 #include "exec/gen-icount.h"
61 static const char *regnames
[] = {
62 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
63 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
64 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
65 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
67 /* initialize TCG globals. */
68 void uc32_translate_init(void)
72 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
74 for (i
= 0; i
< 32; i
++) {
75 cpu_R
[i
] = tcg_global_mem_new_i32(cpu_env
,
76 offsetof(CPUUniCore32State
, regs
[i
]), regnames
[i
]);
82 /* Allocate a temporary variable. */
83 static TCGv_i32
new_tmp(void)
86 return tcg_temp_new_i32();
89 /* Release a temporary variable. */
90 static void dead_tmp(TCGv tmp
)
96 static inline TCGv
load_cpu_offset(int offset
)
99 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
103 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUUniCore32State, name))
105 static inline void store_cpu_offset(TCGv var
, int offset
)
107 tcg_gen_st_i32(var
, cpu_env
, offset
);
111 #define store_cpu_field(var, name) \
112 store_cpu_offset(var, offsetof(CPUUniCore32State, name))
114 /* Set a variable to the value of a CPU register. */
115 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
119 /* normaly, since we updated PC */
121 tcg_gen_movi_i32(var
, addr
);
123 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
127 /* Create a new temporary and set it to the value of a CPU register. */
128 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
130 TCGv tmp
= new_tmp();
131 load_reg_var(s
, tmp
, reg
);
135 /* Set a CPU register. The source must be a temporary and will be
137 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
140 tcg_gen_andi_i32(var
, var
, ~3);
141 s
->is_jmp
= DISAS_JUMP
;
143 tcg_gen_mov_i32(cpu_R
[reg
], var
);
147 /* Value extensions. */
148 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
149 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
150 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
151 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
153 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
154 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
155 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
156 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
157 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
158 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
159 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
160 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
161 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
162 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
163 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
164 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
165 #define UCOP_COND (((insn) >> 25) & 0x0f)
166 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
167 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
168 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
169 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
170 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
172 #define UCOP_SET(i) ((insn) & (1 << (i)))
173 #define UCOP_SET_P UCOP_SET(28)
174 #define UCOP_SET_U UCOP_SET(27)
175 #define UCOP_SET_B UCOP_SET(26)
176 #define UCOP_SET_W UCOP_SET(25)
177 #define UCOP_SET_L UCOP_SET(24)
178 #define UCOP_SET_S UCOP_SET(24)
180 #define ILLEGAL cpu_abort(CPU(cpu), \
181 "Illegal UniCore32 instruction %x at line %d!", \
184 #ifndef CONFIG_USER_ONLY
185 static void disas_cp0_insn(CPUUniCore32State
*env
, DisasContext
*s
,
188 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
189 TCGv tmp
, tmp2
, tmp3
;
190 if ((insn
& 0xfe000000) == 0xe0000000) {
193 tcg_gen_movi_i32(tmp2
, UCOP_REG_N
);
194 tcg_gen_movi_i32(tmp3
, UCOP_IMM10
);
197 gen_helper_cp0_get(tmp
, cpu_env
, tmp2
, tmp3
);
198 store_reg(s
, UCOP_REG_D
, tmp
);
200 tmp
= load_reg(s
, UCOP_REG_D
);
201 gen_helper_cp0_set(cpu_env
, tmp
, tmp2
, tmp3
);
211 static void disas_ocd_insn(CPUUniCore32State
*env
, DisasContext
*s
,
214 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
217 if ((insn
& 0xff003fff) == 0xe1000400) {
219 * movc rd, pp.nn, #imm9
221 * nn: UCOP_REG_N (must be 0)
224 if (UCOP_REG_N
== 0) {
226 tcg_gen_movi_i32(tmp
, 0);
227 store_reg(s
, UCOP_REG_D
, tmp
);
233 if ((insn
& 0xff003fff) == 0xe0000401) {
235 * movc pp.nn, rn, #imm9
237 * nn: UCOP_REG_N (must be 1)
240 if (UCOP_REG_N
== 1) {
241 tmp
= load_reg(s
, UCOP_REG_D
);
242 gen_helper_cp1_putc(tmp
);
253 static inline void gen_set_asr(TCGv var
, uint32_t mask
)
255 TCGv tmp_mask
= tcg_const_i32(mask
);
256 gen_helper_asr_write(cpu_env
, var
, tmp_mask
);
257 tcg_temp_free_i32(tmp_mask
);
259 /* Set NZCV flags from the high 4 bits of var. */
260 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
262 static void gen_exception(int excp
)
264 TCGv tmp
= new_tmp();
265 tcg_gen_movi_i32(tmp
, excp
);
266 gen_helper_exception(cpu_env
, tmp
);
270 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, CF))
272 /* Set CF to the top bit of var. */
273 static void gen_set_CF_bit31(TCGv var
)
275 TCGv tmp
= new_tmp();
276 tcg_gen_shri_i32(tmp
, var
, 31);
281 /* Set N and Z flags from var. */
282 static inline void gen_logic_CC(TCGv var
)
284 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, NF
));
285 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, ZF
));
288 /* dest = T0 + T1 + CF. */
289 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
292 tcg_gen_add_i32(dest
, t0
, t1
);
293 tmp
= load_cpu_field(CF
);
294 tcg_gen_add_i32(dest
, dest
, tmp
);
298 /* dest = T0 - T1 + CF - 1. */
299 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
302 tcg_gen_sub_i32(dest
, t0
, t1
);
303 tmp
= load_cpu_field(CF
);
304 tcg_gen_add_i32(dest
, dest
, tmp
);
305 tcg_gen_subi_i32(dest
, dest
, 1);
309 static void shifter_out_im(TCGv var
, int shift
)
311 TCGv tmp
= new_tmp();
313 tcg_gen_andi_i32(tmp
, var
, 1);
315 tcg_gen_shri_i32(tmp
, var
, shift
);
317 tcg_gen_andi_i32(tmp
, tmp
, 1);
324 /* Shift by immediate. Includes special handling for shift == 0. */
325 static inline void gen_uc32_shift_im(TCGv var
, int shiftop
, int shift
,
332 shifter_out_im(var
, 32 - shift
);
334 tcg_gen_shli_i32(var
, var
, shift
);
340 tcg_gen_shri_i32(var
, var
, 31);
343 tcg_gen_movi_i32(var
, 0);
346 shifter_out_im(var
, shift
- 1);
348 tcg_gen_shri_i32(var
, var
, shift
);
356 shifter_out_im(var
, shift
- 1);
361 tcg_gen_sari_i32(var
, var
, shift
);
363 case 3: /* ROR/RRX */
366 shifter_out_im(var
, shift
- 1);
368 tcg_gen_rotri_i32(var
, var
, shift
); break;
370 TCGv tmp
= load_cpu_field(CF
);
372 shifter_out_im(var
, 0);
374 tcg_gen_shri_i32(var
, var
, 1);
375 tcg_gen_shli_i32(tmp
, tmp
, 31);
376 tcg_gen_or_i32(var
, var
, tmp
);
382 static inline void gen_uc32_shift_reg(TCGv var
, int shiftop
,
383 TCGv shift
, int flags
)
388 gen_helper_shl_cc(var
, cpu_env
, var
, shift
);
391 gen_helper_shr_cc(var
, cpu_env
, var
, shift
);
394 gen_helper_sar_cc(var
, cpu_env
, var
, shift
);
397 gen_helper_ror_cc(var
, cpu_env
, var
, shift
);
403 gen_helper_shl(var
, var
, shift
);
406 gen_helper_shr(var
, var
, shift
);
409 gen_helper_sar(var
, var
, shift
);
412 tcg_gen_andi_i32(shift
, shift
, 0x1f);
413 tcg_gen_rotr_i32(var
, var
, shift
);
420 static void gen_test_cc(int cc
, TCGLabel
*label
)
428 tmp
= load_cpu_field(ZF
);
429 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
432 tmp
= load_cpu_field(ZF
);
433 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
436 tmp
= load_cpu_field(CF
);
437 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
440 tmp
= load_cpu_field(CF
);
441 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
444 tmp
= load_cpu_field(NF
);
445 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
448 tmp
= load_cpu_field(NF
);
449 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
452 tmp
= load_cpu_field(VF
);
453 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
456 tmp
= load_cpu_field(VF
);
457 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
459 case 8: /* hi: C && !Z */
460 inv
= gen_new_label();
461 tmp
= load_cpu_field(CF
);
462 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
464 tmp
= load_cpu_field(ZF
);
465 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
468 case 9: /* ls: !C || Z */
469 tmp
= load_cpu_field(CF
);
470 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
472 tmp
= load_cpu_field(ZF
);
473 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
475 case 10: /* ge: N == V -> N ^ V == 0 */
476 tmp
= load_cpu_field(VF
);
477 tmp2
= load_cpu_field(NF
);
478 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
480 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
482 case 11: /* lt: N != V -> N ^ V != 0 */
483 tmp
= load_cpu_field(VF
);
484 tmp2
= load_cpu_field(NF
);
485 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
487 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
489 case 12: /* gt: !Z && N == V */
490 inv
= gen_new_label();
491 tmp
= load_cpu_field(ZF
);
492 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
494 tmp
= load_cpu_field(VF
);
495 tmp2
= load_cpu_field(NF
);
496 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
498 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
501 case 13: /* le: Z || N != V */
502 tmp
= load_cpu_field(ZF
);
503 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
505 tmp
= load_cpu_field(VF
);
506 tmp2
= load_cpu_field(NF
);
507 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
509 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
512 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
518 static const uint8_t table_logic_cc
[16] = {
519 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
520 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
521 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
522 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
525 /* Set PC state from an immediate address. */
526 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
528 s
->is_jmp
= DISAS_UPDATE
;
529 tcg_gen_movi_i32(cpu_R
[31], addr
& ~3);
532 /* Set PC state from var. var is marked as dead. */
533 static inline void gen_bx(DisasContext
*s
, TCGv var
)
535 s
->is_jmp
= DISAS_UPDATE
;
536 tcg_gen_andi_i32(cpu_R
[31], var
, ~3);
540 static inline void store_reg_bx(DisasContext
*s
, int reg
, TCGv var
)
542 store_reg(s
, reg
, var
);
545 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
547 TCGv tmp
= new_tmp();
548 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
552 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
554 TCGv tmp
= new_tmp();
555 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
559 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
561 TCGv tmp
= new_tmp();
562 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
566 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
568 TCGv tmp
= new_tmp();
569 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
573 static inline TCGv
gen_ld32(TCGv addr
, int index
)
575 TCGv tmp
= new_tmp();
576 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
580 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
582 tcg_gen_qemu_st8(val
, addr
, index
);
586 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
588 tcg_gen_qemu_st16(val
, addr
, index
);
592 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
594 tcg_gen_qemu_st32(val
, addr
, index
);
598 static inline void gen_set_pc_im(uint32_t val
)
600 tcg_gen_movi_i32(cpu_R
[31], val
);
603 /* Force a TB lookup after an instruction that changes the CPU state. */
604 static inline void gen_lookup_tb(DisasContext
*s
)
606 tcg_gen_movi_i32(cpu_R
[31], s
->pc
& ~1);
607 s
->is_jmp
= DISAS_UPDATE
;
610 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
623 tcg_gen_addi_i32(var
, var
, val
);
627 offset
= load_reg(s
, UCOP_REG_M
);
628 gen_uc32_shift_im(offset
, UCOP_SH_OP
, UCOP_SH_IM
, 0);
630 tcg_gen_sub_i32(var
, var
, offset
);
632 tcg_gen_add_i32(var
, var
, offset
);
638 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
646 val
= (insn
& 0x1f) | ((insn
>> 4) & 0x3e0);
651 tcg_gen_addi_i32(var
, var
, val
);
655 offset
= load_reg(s
, UCOP_REG_M
);
657 tcg_gen_sub_i32(var
, var
, offset
);
659 tcg_gen_add_i32(var
, var
, offset
);
665 static inline long ucf64_reg_offset(int reg
)
668 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
669 + offsetof(CPU_DoubleU
, l
.upper
);
671 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
672 + offsetof(CPU_DoubleU
, l
.lower
);
676 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
677 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
679 /* UniCore-F64 single load/store I_offset */
680 static void do_ucf64_ldst_i(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
682 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
687 addr
= load_reg(s
, UCOP_REG_N
);
688 if (!UCOP_SET_P
&& !UCOP_SET_W
) {
693 offset
= UCOP_IMM10
<< 2;
698 tcg_gen_addi_i32(addr
, addr
, offset
);
702 if (UCOP_SET_L
) { /* load */
703 tmp
= gen_ld32(addr
, IS_USER(s
));
704 ucf64_gen_st32(tmp
, UCOP_REG_D
);
706 tmp
= ucf64_gen_ld32(UCOP_REG_D
);
707 gen_st32(tmp
, addr
, IS_USER(s
));
711 offset
= UCOP_IMM10
<< 2;
716 tcg_gen_addi_i32(addr
, addr
, offset
);
720 store_reg(s
, UCOP_REG_N
, addr
);
726 /* UniCore-F64 load/store multiple words */
727 static void do_ucf64_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
729 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
735 if (UCOP_REG_D
!= 0) {
738 if (UCOP_REG_N
== 31) {
741 if ((insn
<< 24) == 0) {
745 addr
= load_reg(s
, UCOP_REG_N
);
748 for (i
= 0; i
< 8; i
++) {
755 if (UCOP_SET_P
) { /* pre increment */
756 tcg_gen_addi_i32(addr
, addr
, 4);
757 } /* unnecessary to do anything when post increment */
759 if (UCOP_SET_P
) { /* pre decrement */
760 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
761 } else { /* post decrement */
763 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
768 freg
= ((insn
>> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
770 for (i
= 0, j
= 0; i
< 8; i
++, freg
++) {
775 if (UCOP_SET_L
) { /* load */
776 tmp
= gen_ld32(addr
, IS_USER(s
));
777 ucf64_gen_st32(tmp
, freg
);
779 tmp
= ucf64_gen_ld32(freg
);
780 gen_st32(tmp
, addr
, IS_USER(s
));
784 /* unnecessary to add after the last transfer */
786 tcg_gen_addi_i32(addr
, addr
, 4);
790 if (UCOP_SET_W
) { /* write back */
792 if (!UCOP_SET_P
) { /* post increment */
793 tcg_gen_addi_i32(addr
, addr
, 4);
794 } /* unnecessary to do anything when pre increment */
799 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
803 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
806 store_reg(s
, UCOP_REG_N
, addr
);
812 /* UniCore-F64 mrc/mcr */
813 static void do_ucf64_trans(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
815 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
818 if ((insn
& 0xfe0003ff) == 0xe2000000) {
819 /* control register */
820 if ((UCOP_REG_N
!= UC32_UCF64_FPSCR
) || (UCOP_REG_D
== 31)) {
826 gen_helper_ucf64_get_fpscr(tmp
, cpu_env
);
827 store_reg(s
, UCOP_REG_D
, tmp
);
830 tmp
= load_reg(s
, UCOP_REG_D
);
831 gen_helper_ucf64_set_fpscr(cpu_env
, tmp
);
837 if ((insn
& 0xfe0003ff) == 0xe0000000) {
838 /* general register */
839 if (UCOP_REG_D
== 31) {
842 if (UCOP_SET(24)) { /* MFF */
843 tmp
= ucf64_gen_ld32(UCOP_REG_N
);
844 store_reg(s
, UCOP_REG_D
, tmp
);
846 tmp
= load_reg(s
, UCOP_REG_D
);
847 ucf64_gen_st32(tmp
, UCOP_REG_N
);
851 if ((insn
& 0xfb000000) == 0xe9000000) {
853 if (UCOP_REG_D
!= 31) {
856 if (UCOP_UCF64_COND
& 0x8) {
861 tcg_gen_movi_i32(tmp
, UCOP_UCF64_COND
);
863 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
864 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
865 gen_helper_ucf64_cmpd(cpu_F0d
, cpu_F1d
, tmp
, cpu_env
);
867 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
868 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
869 gen_helper_ucf64_cmps(cpu_F0s
, cpu_F1s
, tmp
, cpu_env
);
877 /* UniCore-F64 convert instructions */
878 static void do_ucf64_fcvt(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
880 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
882 if (UCOP_UCF64_FMT
== 3) {
885 if (UCOP_REG_N
!= 0) {
888 switch (UCOP_UCF64_FUNC
) {
890 switch (UCOP_UCF64_FMT
) {
892 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
893 gen_helper_ucf64_df2sf(cpu_F0s
, cpu_F0d
, cpu_env
);
894 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
897 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
898 gen_helper_ucf64_si2sf(cpu_F0s
, cpu_F0s
, cpu_env
);
899 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
907 switch (UCOP_UCF64_FMT
) {
909 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
910 gen_helper_ucf64_sf2df(cpu_F0d
, cpu_F0s
, cpu_env
);
911 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
914 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
915 gen_helper_ucf64_si2df(cpu_F0d
, cpu_F0s
, cpu_env
);
916 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
924 switch (UCOP_UCF64_FMT
) {
926 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
927 gen_helper_ucf64_sf2si(cpu_F0s
, cpu_F0s
, cpu_env
);
928 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
931 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
932 gen_helper_ucf64_df2si(cpu_F0s
, cpu_F0d
, cpu_env
);
933 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
945 /* UniCore-F64 compare instructions */
946 static void do_ucf64_fcmp(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
948 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
953 if (UCOP_REG_D
!= 0) {
959 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
960 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
961 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
963 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
964 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
965 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
969 #define gen_helper_ucf64_movs(x, y) do { } while (0)
970 #define gen_helper_ucf64_movd(x, y) do { } while (0)
972 #define UCF64_OP1(name) do { \
973 if (UCOP_REG_N != 0) { \
976 switch (UCOP_UCF64_FMT) { \
978 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
979 ucf64_reg_offset(UCOP_REG_M)); \
980 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
981 tcg_gen_st_i32(cpu_F0s, cpu_env, \
982 ucf64_reg_offset(UCOP_REG_D)); \
985 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
986 ucf64_reg_offset(UCOP_REG_M)); \
987 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
988 tcg_gen_st_i64(cpu_F0d, cpu_env, \
989 ucf64_reg_offset(UCOP_REG_D)); \
997 #define UCF64_OP2(name) do { \
998 switch (UCOP_UCF64_FMT) { \
1000 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
1001 ucf64_reg_offset(UCOP_REG_N)); \
1002 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
1003 ucf64_reg_offset(UCOP_REG_M)); \
1004 gen_helper_ucf64_##name##s(cpu_F0s, \
1005 cpu_F0s, cpu_F1s, cpu_env); \
1006 tcg_gen_st_i32(cpu_F0s, cpu_env, \
1007 ucf64_reg_offset(UCOP_REG_D)); \
1010 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
1011 ucf64_reg_offset(UCOP_REG_N)); \
1012 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
1013 ucf64_reg_offset(UCOP_REG_M)); \
1014 gen_helper_ucf64_##name##d(cpu_F0d, \
1015 cpu_F0d, cpu_F1d, cpu_env); \
1016 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1017 ucf64_reg_offset(UCOP_REG_D)); \
1025 /* UniCore-F64 data processing */
1026 static void do_ucf64_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1028 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1030 if (UCOP_UCF64_FMT
== 3) {
1033 switch (UCOP_UCF64_FUNC
) {
1060 /* Disassemble an F64 instruction */
1061 static void disas_ucf64_insn(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1063 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1065 if (!UCOP_SET(29)) {
1067 do_ucf64_ldst_m(env
, s
, insn
);
1069 do_ucf64_ldst_i(env
, s
, insn
);
1073 switch ((insn
>> 26) & 0x3) {
1075 do_ucf64_datap(env
, s
, insn
);
1081 do_ucf64_fcvt(env
, s
, insn
);
1084 do_ucf64_fcmp(env
, s
, insn
);
1088 do_ucf64_trans(env
, s
, insn
);
1093 static inline bool use_goto_tb(DisasContext
*s
, uint32_t dest
)
1095 #ifndef CONFIG_USER_ONLY
1096 return (s
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
1102 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
1104 if (use_goto_tb(s
, dest
)) {
1106 gen_set_pc_im(dest
);
1107 tcg_gen_exit_tb((uintptr_t)s
->tb
+ n
);
1109 gen_set_pc_im(dest
);
1114 static inline void gen_jmp(DisasContext
*s
, uint32_t dest
)
1116 if (unlikely(s
->singlestep_enabled
)) {
1117 /* An indirect jump so that we still trigger the debug exception. */
1120 gen_goto_tb(s
, 0, dest
);
1121 s
->is_jmp
= DISAS_TB_JUMP
;
1125 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1126 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int bsr
, TCGv t0
)
1130 /* ??? This is also undefined in system mode. */
1135 tmp
= load_cpu_field(bsr
);
1136 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
1137 tcg_gen_andi_i32(t0
, t0
, mask
);
1138 tcg_gen_or_i32(tmp
, tmp
, t0
);
1139 store_cpu_field(tmp
, bsr
);
1141 gen_set_asr(t0
, mask
);
1148 /* Generate an old-style exception return. Marks pc as dead. */
1149 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
1152 store_reg(s
, 31, pc
);
1153 tmp
= load_cpu_field(bsr
);
1154 gen_set_asr(tmp
, 0xffffffff);
1156 s
->is_jmp
= DISAS_UPDATE
;
1159 static void disas_coproc_insn(CPUUniCore32State
*env
, DisasContext
*s
,
1162 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1164 switch (UCOP_CPNUM
) {
1165 #ifndef CONFIG_USER_ONLY
1167 disas_cp0_insn(env
, s
, insn
);
1170 disas_ocd_insn(env
, s
, insn
);
1174 disas_ucf64_insn(env
, s
, insn
);
1177 /* Unknown coprocessor. */
1178 cpu_abort(CPU(cpu
), "Unknown coprocessor!");
1182 /* data processing instructions */
1183 static void do_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1185 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1190 if (UCOP_OPCODES
== 0x0f || UCOP_OPCODES
== 0x0d) {
1191 if (UCOP_SET(23)) { /* CMOV instructions */
1192 if ((UCOP_CMOV_COND
== 0xe) || (UCOP_CMOV_COND
== 0xf)) {
1195 /* if not always execute, we generate a conditional jump to
1197 s
->condlabel
= gen_new_label();
1198 gen_test_cc(UCOP_CMOV_COND
^ 1, s
->condlabel
);
1203 logic_cc
= table_logic_cc
[UCOP_OPCODES
] & (UCOP_SET_S
>> 24);
1207 /* immediate operand */
1210 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1213 tcg_gen_movi_i32(tmp2
, val
);
1214 if (logic_cc
&& UCOP_SH_IM
) {
1215 gen_set_CF_bit31(tmp2
);
1219 tmp2
= load_reg(s
, UCOP_REG_M
);
1221 tmp
= load_reg(s
, UCOP_REG_S
);
1222 gen_uc32_shift_reg(tmp2
, UCOP_SH_OP
, tmp
, logic_cc
);
1224 gen_uc32_shift_im(tmp2
, UCOP_SH_OP
, UCOP_SH_IM
, logic_cc
);
1228 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1229 tmp
= load_reg(s
, UCOP_REG_N
);
1234 switch (UCOP_OPCODES
) {
1236 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1240 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1243 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1247 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1250 if (UCOP_SET_S
&& UCOP_REG_D
== 31) {
1251 /* SUBS r31, ... is used for exception return. */
1255 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1256 gen_exception_return(s
, tmp
);
1259 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1261 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
1263 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1268 gen_helper_sub_cc(tmp
, cpu_env
, tmp2
, tmp
);
1270 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
1272 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1276 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1278 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1280 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1284 gen_helper_adc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1286 gen_add_carry(tmp
, tmp
, tmp2
);
1288 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1292 gen_helper_sbc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1294 gen_sub_carry(tmp
, tmp
, tmp2
);
1296 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1300 gen_helper_sbc_cc(tmp
, cpu_env
, tmp2
, tmp
);
1302 gen_sub_carry(tmp
, tmp2
, tmp
);
1304 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1308 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1315 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1322 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1328 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1333 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1337 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1340 if (logic_cc
&& UCOP_REG_D
== 31) {
1341 /* MOVS r31, ... is used for exception return. */
1345 gen_exception_return(s
, tmp2
);
1350 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1354 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1358 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1362 tcg_gen_not_i32(tmp2
, tmp2
);
1366 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1369 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1375 static void do_mult(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1377 TCGv tmp
, tmp2
, tmp3
, tmp4
;
1381 tmp
= load_reg(s
, UCOP_REG_M
);
1382 tmp2
= load_reg(s
, UCOP_REG_N
);
1384 tcg_gen_muls2_i32(tmp
, tmp2
, tmp
, tmp2
);
1386 tcg_gen_mulu2_i32(tmp
, tmp2
, tmp
, tmp2
);
1388 if (UCOP_SET(25)) { /* mult accumulate */
1389 tmp3
= load_reg(s
, UCOP_REG_LO
);
1390 tmp4
= load_reg(s
, UCOP_REG_HI
);
1391 tcg_gen_add2_i32(tmp
, tmp2
, tmp
, tmp2
, tmp3
, tmp4
);
1395 store_reg(s
, UCOP_REG_LO
, tmp
);
1396 store_reg(s
, UCOP_REG_HI
, tmp2
);
1399 tmp
= load_reg(s
, UCOP_REG_M
);
1400 tmp2
= load_reg(s
, UCOP_REG_N
);
1401 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
1405 tmp2
= load_reg(s
, UCOP_REG_S
);
1406 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1412 store_reg(s
, UCOP_REG_D
, tmp
);
1416 /* miscellaneous instructions */
1417 static void do_misc(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1419 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1423 if ((insn
& 0xffffffe0) == 0x10ffc120) {
1424 /* Trivial implementation equivalent to bx. */
1425 tmp
= load_reg(s
, UCOP_REG_M
);
1430 if ((insn
& 0xfbffc000) == 0x30ffc000) {
1431 /* PSR = immediate */
1434 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1437 tcg_gen_movi_i32(tmp
, val
);
1438 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1444 if ((insn
& 0xfbffffe0) == 0x12ffc020) {
1445 /* PSR.flag = reg */
1446 tmp
= load_reg(s
, UCOP_REG_M
);
1447 if (gen_set_psr(s
, ASR_NZCV
, UCOP_SET_B
, tmp
)) {
1453 if ((insn
& 0xfbffffe0) == 0x10ffc020) {
1455 tmp
= load_reg(s
, UCOP_REG_M
);
1456 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1462 if ((insn
& 0xfbf83fff) == 0x10f80000) {
1468 tmp
= load_cpu_field(bsr
);
1471 gen_helper_asr_read(tmp
, cpu_env
);
1473 store_reg(s
, UCOP_REG_D
, tmp
);
1477 if ((insn
& 0xfbf83fe0) == 0x12f80120) {
1479 tmp
= load_reg(s
, UCOP_REG_M
);
1481 gen_helper_clo(tmp
, tmp
);
1483 gen_helper_clz(tmp
, tmp
);
1485 store_reg(s
, UCOP_REG_D
, tmp
);
1493 /* load/store I_offset and R_offset */
1494 static void do_ldst_ir(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1496 unsigned int mmu_idx
;
1500 tmp2
= load_reg(s
, UCOP_REG_N
);
1501 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1505 gen_add_data_offset(s
, insn
, tmp2
);
1511 tmp
= gen_ld8u(tmp2
, mmu_idx
);
1513 tmp
= gen_ld32(tmp2
, mmu_idx
);
1517 tmp
= load_reg(s
, UCOP_REG_D
);
1519 gen_st8(tmp
, tmp2
, mmu_idx
);
1521 gen_st32(tmp
, tmp2
, mmu_idx
);
1525 gen_add_data_offset(s
, insn
, tmp2
);
1526 store_reg(s
, UCOP_REG_N
, tmp2
);
1527 } else if (UCOP_SET_W
) {
1528 store_reg(s
, UCOP_REG_N
, tmp2
);
1533 /* Complete the load. */
1534 if (UCOP_REG_D
== 31) {
1537 store_reg(s
, UCOP_REG_D
, tmp
);
1542 /* SWP instruction */
1543 static void do_swap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1545 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1550 if ((insn
& 0xff003fe0) != 0x40000120) {
1554 /* ??? This is not really atomic. However we know
1555 we never have multiple CPUs running in parallel,
1556 so it is good enough. */
1557 addr
= load_reg(s
, UCOP_REG_N
);
1558 tmp
= load_reg(s
, UCOP_REG_M
);
1560 tmp2
= gen_ld8u(addr
, IS_USER(s
));
1561 gen_st8(tmp
, addr
, IS_USER(s
));
1563 tmp2
= gen_ld32(addr
, IS_USER(s
));
1564 gen_st32(tmp
, addr
, IS_USER(s
));
1567 store_reg(s
, UCOP_REG_D
, tmp2
);
1570 /* load/store hw/sb */
1571 static void do_ldst_hwsb(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1573 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1577 if (UCOP_SH_OP
== 0) {
1578 do_swap(env
, s
, insn
);
1582 addr
= load_reg(s
, UCOP_REG_N
);
1584 gen_add_datah_offset(s
, insn
, addr
);
1587 if (UCOP_SET_L
) { /* load */
1588 switch (UCOP_SH_OP
) {
1590 tmp
= gen_ld16u(addr
, IS_USER(s
));
1593 tmp
= gen_ld8s(addr
, IS_USER(s
));
1595 default: /* see do_swap */
1597 tmp
= gen_ld16s(addr
, IS_USER(s
));
1600 } else { /* store */
1601 if (UCOP_SH_OP
!= 1) {
1604 tmp
= load_reg(s
, UCOP_REG_D
);
1605 gen_st16(tmp
, addr
, IS_USER(s
));
1607 /* Perform base writeback before the loaded value to
1608 ensure correct behavior with overlapping index registers. */
1610 gen_add_datah_offset(s
, insn
, addr
);
1611 store_reg(s
, UCOP_REG_N
, addr
);
1612 } else if (UCOP_SET_W
) {
1613 store_reg(s
, UCOP_REG_N
, addr
);
1618 /* Complete the load. */
1619 store_reg(s
, UCOP_REG_D
, tmp
);
1623 /* load/store multiple words */
1624 static void do_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1626 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1627 unsigned int val
, i
, mmu_idx
;
1628 int j
, n
, reg
, user
, loaded_base
;
1637 /* XXX: store correct base if write back */
1639 if (UCOP_SET_B
) { /* S bit in instruction table */
1641 ILLEGAL
; /* only usable in supervisor mode */
1643 if (UCOP_SET(18) == 0) { /* pc reg */
1648 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1649 addr
= load_reg(s
, UCOP_REG_N
);
1651 /* compute total size */
1653 TCGV_UNUSED(loaded_var
);
1655 for (i
= 0; i
< 6; i
++) {
1660 for (i
= 9; i
< 19; i
++) {
1665 /* XXX: test invalid n == 0 case ? */
1669 tcg_gen_addi_i32(addr
, addr
, 4);
1671 /* post increment */
1676 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1678 /* post decrement */
1680 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1686 reg
= UCOP_SET(6) ? 16 : 0;
1687 for (i
= 0; i
< 19; i
++, reg
++) {
1692 if (UCOP_SET_L
) { /* load */
1693 tmp
= gen_ld32(addr
, mmu_idx
);
1697 tmp2
= tcg_const_i32(reg
);
1698 gen_helper_set_user_reg(cpu_env
, tmp2
, tmp
);
1699 tcg_temp_free_i32(tmp2
);
1701 } else if (reg
== UCOP_REG_N
) {
1705 store_reg(s
, reg
, tmp
);
1707 } else { /* store */
1709 /* special case: r31 = PC + 4 */
1712 tcg_gen_movi_i32(tmp
, val
);
1715 tmp2
= tcg_const_i32(reg
);
1716 gen_helper_get_user_reg(tmp
, cpu_env
, tmp2
);
1717 tcg_temp_free_i32(tmp2
);
1719 tmp
= load_reg(s
, reg
);
1721 gen_st32(tmp
, addr
, mmu_idx
);
1724 /* no need to add after the last transfer */
1726 tcg_gen_addi_i32(addr
, addr
, 4);
1730 if (UCOP_SET_W
) { /* write back */
1735 /* post increment */
1736 tcg_gen_addi_i32(addr
, addr
, 4);
1742 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1745 /* post decrement */
1746 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1749 store_reg(s
, UCOP_REG_N
, addr
);
1754 store_reg(s
, UCOP_REG_N
, loaded_var
);
1756 if (UCOP_SET_B
&& !user
) {
1757 /* Restore ASR from BSR. */
1758 tmp
= load_cpu_field(bsr
);
1759 gen_set_asr(tmp
, 0xffffffff);
1761 s
->is_jmp
= DISAS_UPDATE
;
1765 /* branch (and link) */
1766 static void do_branch(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1768 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1773 if (UCOP_COND
== 0xf) {
1777 if (UCOP_COND
!= 0xe) {
1778 /* if not always execute, we generate a conditional jump to
1780 s
->condlabel
= gen_new_label();
1781 gen_test_cc(UCOP_COND
^ 1, s
->condlabel
);
1785 val
= (int32_t)s
->pc
;
1788 tcg_gen_movi_i32(tmp
, val
);
1789 store_reg(s
, 30, tmp
);
1791 offset
= (((int32_t)insn
<< 8) >> 8);
1792 val
+= (offset
<< 2); /* unicore is pc+4 */
1796 static void disas_uc32_insn(CPUUniCore32State
*env
, DisasContext
*s
)
1798 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1801 insn
= cpu_ldl_code(env
, s
->pc
);
1804 /* UniCore instructions class:
1805 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1806 * AAA : see switch case
1807 * BBBB : opcodes or cond or PUBW
1812 switch (insn
>> 29) {
1814 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1815 do_mult(env
, s
, insn
);
1820 do_misc(env
, s
, insn
);
1824 if (((UCOP_OPCODES
>> 2) == 2) && !UCOP_SET_S
) {
1825 do_misc(env
, s
, insn
);
1828 do_datap(env
, s
, insn
);
1832 if (UCOP_SET(8) && UCOP_SET(5)) {
1833 do_ldst_hwsb(env
, s
, insn
);
1836 if (UCOP_SET(8) || UCOP_SET(5)) {
1840 do_ldst_ir(env
, s
, insn
);
1845 ILLEGAL
; /* extended instructions */
1847 do_ldst_m(env
, s
, insn
);
1850 do_branch(env
, s
, insn
);
1854 disas_coproc_insn(env
, s
, insn
);
1857 if (!UCOP_SET(28)) {
1858 disas_coproc_insn(env
, s
, insn
);
1861 if ((insn
& 0xff000000) == 0xff000000) { /* syscall */
1862 gen_set_pc_im(s
->pc
);
1863 s
->is_jmp
= DISAS_SYSCALL
;
1870 /* generate intermediate code for basic block 'tb'. */
1871 void gen_intermediate_code(CPUUniCore32State
*env
, TranslationBlock
*tb
)
1873 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1874 CPUState
*cs
= CPU(cpu
);
1875 DisasContext dc1
, *dc
= &dc1
;
1876 target_ulong pc_start
;
1877 uint32_t next_page_start
;
1881 /* generate intermediate code */
1888 dc
->is_jmp
= DISAS_NEXT
;
1890 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1892 cpu_F0s
= tcg_temp_new_i32();
1893 cpu_F1s
= tcg_temp_new_i32();
1894 cpu_F0d
= tcg_temp_new_i64();
1895 cpu_F1d
= tcg_temp_new_i64();
1896 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1898 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1899 if (max_insns
== 0) {
1900 max_insns
= CF_COUNT_MASK
;
1902 if (max_insns
> TCG_MAX_INSNS
) {
1903 max_insns
= TCG_MAX_INSNS
;
1906 #ifndef CONFIG_USER_ONLY
1907 if ((env
->uncached_asr
& ASR_M
) == ASR_MODE_USER
) {
1916 tcg_gen_insn_start(dc
->pc
);
1919 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
1920 gen_set_pc_im(dc
->pc
);
1921 gen_exception(EXCP_DEBUG
);
1922 dc
->is_jmp
= DISAS_JUMP
;
1923 /* The address covered by the breakpoint must be included in
1924 [tb->pc, tb->pc + tb->size) in order to for it to be
1925 properly cleared -- thus we increment the PC here so that
1926 the logic setting tb->size below does the right thing. */
1928 goto done_generating
;
1931 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1935 disas_uc32_insn(env
, dc
);
1938 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
1942 if (dc
->condjmp
&& !dc
->is_jmp
) {
1943 gen_set_label(dc
->condlabel
);
1946 /* Translation stops when a conditional branch is encountered.
1947 * Otherwise the subsequent code could get translated several times.
1948 * Also stop translation when a page boundary is reached. This
1949 * ensures prefetch aborts occur at the right place. */
1950 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
1951 !cs
->singlestep_enabled
&&
1953 dc
->pc
< next_page_start
&&
1954 num_insns
< max_insns
);
1956 if (tb
->cflags
& CF_LAST_IO
) {
1958 /* FIXME: This can theoretically happen with self-modifying
1960 cpu_abort(cs
, "IO on conditional branch instruction");
1965 /* At this stage dc->condjmp will only be set when the skipped
1966 instruction was a conditional branch or trap, and the PC has
1967 already been written. */
1968 if (unlikely(cs
->singlestep_enabled
)) {
1969 /* Make sure the pc is updated, and raise a debug exception. */
1971 if (dc
->is_jmp
== DISAS_SYSCALL
) {
1972 gen_exception(UC32_EXCP_PRIV
);
1974 gen_exception(EXCP_DEBUG
);
1976 gen_set_label(dc
->condlabel
);
1978 if (dc
->condjmp
|| !dc
->is_jmp
) {
1979 gen_set_pc_im(dc
->pc
);
1982 if (dc
->is_jmp
== DISAS_SYSCALL
&& !dc
->condjmp
) {
1983 gen_exception(UC32_EXCP_PRIV
);
1985 gen_exception(EXCP_DEBUG
);
1988 /* While branches must always occur at the end of an IT block,
1989 there are a few other things that can cause us to terminate
1990 the TB in the middel of an IT block:
1991 - Exception generating instructions (bkpt, swi, undefined).
1993 - Hardware watchpoints.
1994 Hardware breakpoints have already been handled and skip this code.
1996 switch (dc
->is_jmp
) {
1998 gen_goto_tb(dc
, 1, dc
->pc
);
2003 /* indicate that the hash table must be used to find the next TB */
2007 /* nothing more to generate */
2010 gen_exception(UC32_EXCP_PRIV
);
2014 gen_set_label(dc
->condlabel
);
2015 gen_goto_tb(dc
, 1, dc
->pc
);
2021 gen_tb_end(tb
, num_insns
);
2024 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2025 qemu_log("----------------\n");
2026 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2027 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
, 0);
2031 tb
->size
= dc
->pc
- pc_start
;
2032 tb
->icount
= num_insns
;
2035 static const char *cpu_mode_names
[16] = {
2036 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2037 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2040 #undef UCF64_DUMP_STATE
2041 #ifdef UCF64_DUMP_STATE
2042 static void cpu_dump_state_ucf64(CPUUniCore32State
*env
, FILE *f
,
2043 fprintf_function cpu_fprintf
, int flags
)
2051 /* ??? This assumes float64 and double have the same layout.
2052 Oh well, it's only debug dumps. */
2058 for (i
= 0; i
< 16; i
++) {
2059 d
.d
= env
->ucf64
.regs
[i
];
2063 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g)",
2064 i
* 2, (int)s0
.i
, s0
.s
,
2065 i
* 2 + 1, (int)s1
.i
, s1
.s
);
2066 cpu_fprintf(f
, " d%02d=%" PRIx64
"(%8g)\n",
2067 i
, (uint64_t)d0
.f64
, d0
.d
);
2069 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->ucf64
.xregs
[UC32_UCF64_FPSCR
]);
2072 #define cpu_dump_state_ucf64(env, file, pr, flags) do { } while (0)
2075 void uc32_cpu_dump_state(CPUState
*cs
, FILE *f
,
2076 fprintf_function cpu_fprintf
, int flags
)
2078 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
2079 CPUUniCore32State
*env
= &cpu
->env
;
2083 for (i
= 0; i
< 32; i
++) {
2084 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
2086 cpu_fprintf(f
, "\n");
2088 cpu_fprintf(f
, " ");
2091 psr
= cpu_asr_read(env
);
2092 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %s\n",
2094 psr
& (1 << 31) ? 'N' : '-',
2095 psr
& (1 << 30) ? 'Z' : '-',
2096 psr
& (1 << 29) ? 'C' : '-',
2097 psr
& (1 << 28) ? 'V' : '-',
2098 cpu_mode_names
[psr
& 0xf]);
2100 cpu_dump_state_ucf64(env
, f
, cpu_fprintf
, flags
);
2103 void restore_state_to_opc(CPUUniCore32State
*env
, TranslationBlock
*tb
,
2106 env
->regs
[31] = data
[0];