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"
19 #include "exec/translator.h"
20 #include "qemu/qemu-print.h"
22 #include "exec/helper-proto.h"
23 #include "exec/helper-gen.h"
25 #include "trace-tcg.h"
29 /* internal defines */
30 typedef struct DisasContext {
33 /* Nonzero if this instruction has been conditionally skipped. */
35 /* The label that will be jumped to when the instruction is skipped. */
37 struct TranslationBlock *tb;
38 int singlestep_enabled;
39 #ifndef CONFIG_USER_ONLY
44 #ifndef CONFIG_USER_ONLY
45 #define IS_USER(s) (s->user)
50 /* is_jmp field values */
51 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
52 #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */
53 #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
54 /* These instructions trap after executing, so defer them until after the
55 conditional executions state has been updated. */
56 #define DISAS_SYSCALL DISAS_TARGET_3
58 static TCGv_i32 cpu_R[32];
60 /* FIXME: These should be removed. */
61 static TCGv cpu_F0s, cpu_F1s;
62 static TCGv_i64 cpu_F0d, cpu_F1d;
64 #include "exec/gen-icount.h"
66 static const char *regnames[] = {
67 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
68 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
69 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
70 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
72 /* initialize TCG globals. */
73 void uc32_translate_init(void)
77 for (i = 0; i < 32; i++) {
78 cpu_R[i] = tcg_global_mem_new_i32(cpu_env,
79 offsetof(CPUUniCore32State, regs[i]), regnames[i]);
85 /* Allocate a temporary variable. */
86 static TCGv_i32 new_tmp(void)
89 return tcg_temp_new_i32();
92 /* Release a temporary variable. */
93 static void dead_tmp(TCGv tmp)
99 static inline TCGv load_cpu_offset(int offset)
101 TCGv tmp = new_tmp();
102 tcg_gen_ld_i32(tmp, cpu_env, offset);
106 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUUniCore32State, name))
108 static inline void store_cpu_offset(TCGv var, int offset)
110 tcg_gen_st_i32(var, cpu_env, offset);
114 #define store_cpu_field(var, name) \
115 store_cpu_offset(var, offsetof(CPUUniCore32State, name))
117 /* Set a variable to the value of a CPU register. */
118 static void load_reg_var(DisasContext *s, TCGv var, int reg)
122 /* normaly, since we updated PC */
124 tcg_gen_movi_i32(var, addr);
126 tcg_gen_mov_i32(var, cpu_R[reg]);
130 /* Create a new temporary and set it to the value of a CPU register. */
131 static inline TCGv load_reg(DisasContext *s, int reg)
133 TCGv tmp = new_tmp();
134 load_reg_var(s, tmp, reg);
138 /* Set a CPU register. The source must be a temporary and will be
140 static void store_reg(DisasContext *s, int reg, TCGv var)
143 tcg_gen_andi_i32(var, var, ~3);
144 s->is_jmp = DISAS_JUMP;
146 tcg_gen_mov_i32(cpu_R[reg], var);
150 /* Value extensions. */
151 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
152 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
153 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
154 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
156 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
157 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
158 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
159 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
160 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
161 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
162 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
163 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
164 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
165 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
166 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
167 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
168 #define UCOP_COND (((insn) >> 25) & 0x0f)
169 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
170 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
171 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
172 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
173 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
175 #define UCOP_SET(i) ((insn) & (1 << (i)))
176 #define UCOP_SET_P UCOP_SET(28)
177 #define UCOP_SET_U UCOP_SET(27)
178 #define UCOP_SET_B UCOP_SET(26)
179 #define UCOP_SET_W UCOP_SET(25)
180 #define UCOP_SET_L UCOP_SET(24)
181 #define UCOP_SET_S UCOP_SET(24)
183 #define ILLEGAL cpu_abort(env_cpu(env), \
184 "Illegal UniCore32 instruction %x at line %d!", \
187 #ifndef CONFIG_USER_ONLY
188 static void disas_cp0_insn(CPUUniCore32State *env, DisasContext *s,
191 TCGv tmp, tmp2, tmp3;
192 if ((insn & 0xfe000000) == 0xe0000000) {
195 tcg_gen_movi_i32(tmp2, UCOP_REG_N);
196 tcg_gen_movi_i32(tmp3, UCOP_IMM10);
199 gen_helper_cp0_get(tmp, cpu_env, tmp2, tmp3);
200 store_reg(s, UCOP_REG_D, tmp);
202 tmp = load_reg(s, UCOP_REG_D);
203 gen_helper_cp0_set(cpu_env, tmp, tmp2, tmp3);
213 static void disas_ocd_insn(CPUUniCore32State *env, DisasContext *s,
218 if ((insn & 0xff003fff) == 0xe1000400) {
220 * movc rd, pp.nn, #imm9
222 * nn: UCOP_REG_N (must be 0)
225 if (UCOP_REG_N == 0) {
227 tcg_gen_movi_i32(tmp, 0);
228 store_reg(s, UCOP_REG_D, tmp);
234 if ((insn & 0xff003fff) == 0xe0000401) {
236 * movc pp.nn, rn, #imm9
238 * nn: UCOP_REG_N (must be 1)
241 if (UCOP_REG_N == 1) {
242 tmp = load_reg(s, UCOP_REG_D);
243 gen_helper_cp1_putc(tmp);
254 static inline void gen_set_asr(TCGv var, uint32_t mask)
256 TCGv tmp_mask = tcg_const_i32(mask);
257 gen_helper_asr_write(cpu_env, var, tmp_mask);
258 tcg_temp_free_i32(tmp_mask);
260 /* Set NZCV flags from the high 4 bits of var. */
261 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
263 static void gen_exception(int excp)
265 TCGv tmp = new_tmp();
266 tcg_gen_movi_i32(tmp, excp);
267 gen_helper_exception(cpu_env, tmp);
271 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, CF))
273 /* Set CF to the top bit of var. */
274 static void gen_set_CF_bit31(TCGv var)
276 TCGv tmp = new_tmp();
277 tcg_gen_shri_i32(tmp, var, 31);
282 /* Set N and Z flags from var. */
283 static inline void gen_logic_CC(TCGv var)
285 tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, NF));
286 tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, ZF));
289 /* dest = T0 + T1 + CF. */
290 static void gen_add_carry(TCGv dest, TCGv t0, TCGv t1)
293 tcg_gen_add_i32(dest, t0, t1);
294 tmp = load_cpu_field(CF);
295 tcg_gen_add_i32(dest, dest, tmp);
299 /* dest = T0 - T1 + CF - 1. */
300 static void gen_sub_carry(TCGv dest, TCGv t0, TCGv t1)
303 tcg_gen_sub_i32(dest, t0, t1);
304 tmp = load_cpu_field(CF);
305 tcg_gen_add_i32(dest, dest, tmp);
306 tcg_gen_subi_i32(dest, dest, 1);
310 static void shifter_out_im(TCGv var, int shift)
312 TCGv tmp = new_tmp();
314 tcg_gen_andi_i32(tmp, var, 1);
316 tcg_gen_shri_i32(tmp, var, shift);
318 tcg_gen_andi_i32(tmp, tmp, 1);
325 /* Shift by immediate. Includes special handling for shift == 0. */
326 static inline void gen_uc32_shift_im(TCGv var, int shiftop, int shift,
333 shifter_out_im(var, 32 - shift);
335 tcg_gen_shli_i32(var, var, shift);
341 tcg_gen_shri_i32(var, var, 31);
344 tcg_gen_movi_i32(var, 0);
347 shifter_out_im(var, shift - 1);
349 tcg_gen_shri_i32(var, var, shift);
357 shifter_out_im(var, shift - 1);
362 tcg_gen_sari_i32(var, var, shift);
364 case 3: /* ROR/RRX */
367 shifter_out_im(var, shift - 1);
369 tcg_gen_rotri_i32(var, var, shift); break;
371 TCGv tmp = load_cpu_field(CF);
373 shifter_out_im(var, 0);
375 tcg_gen_shri_i32(var, var, 1);
376 tcg_gen_shli_i32(tmp, tmp, 31);
377 tcg_gen_or_i32(var, var, tmp);
383 static inline void gen_uc32_shift_reg(TCGv var, int shiftop,
384 TCGv shift, int flags)
389 gen_helper_shl_cc(var, cpu_env, var, shift);
392 gen_helper_shr_cc(var, cpu_env, var, shift);
395 gen_helper_sar_cc(var, cpu_env, var, shift);
398 gen_helper_ror_cc(var, cpu_env, var, shift);
404 gen_helper_shl(var, var, shift);
407 gen_helper_shr(var, var, shift);
410 gen_helper_sar(var, var, shift);
413 tcg_gen_andi_i32(shift, shift, 0x1f);
414 tcg_gen_rotr_i32(var, var, shift);
421 static void gen_test_cc(int cc, TCGLabel *label)
429 tmp = load_cpu_field(ZF);
430 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
433 tmp = load_cpu_field(ZF);
434 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
437 tmp = load_cpu_field(CF);
438 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
441 tmp = load_cpu_field(CF);
442 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
445 tmp = load_cpu_field(NF);
446 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
449 tmp = load_cpu_field(NF);
450 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
453 tmp = load_cpu_field(VF);
454 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
457 tmp = load_cpu_field(VF);
458 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
460 case 8: /* hi: C && !Z */
461 inv = gen_new_label();
462 tmp = load_cpu_field(CF);
463 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
465 tmp = load_cpu_field(ZF);
466 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
469 case 9: /* ls: !C || Z */
470 tmp = load_cpu_field(CF);
471 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
473 tmp = load_cpu_field(ZF);
474 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
476 case 10: /* ge: N == V -> N ^ V == 0 */
477 tmp = load_cpu_field(VF);
478 tmp2 = load_cpu_field(NF);
479 tcg_gen_xor_i32(tmp, tmp, tmp2);
481 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
483 case 11: /* lt: N != V -> N ^ V != 0 */
484 tmp = load_cpu_field(VF);
485 tmp2 = load_cpu_field(NF);
486 tcg_gen_xor_i32(tmp, tmp, tmp2);
488 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
490 case 12: /* gt: !Z && N == V */
491 inv = gen_new_label();
492 tmp = load_cpu_field(ZF);
493 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
495 tmp = load_cpu_field(VF);
496 tmp2 = load_cpu_field(NF);
497 tcg_gen_xor_i32(tmp, tmp, tmp2);
499 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
502 case 13: /* le: Z || N != V */
503 tmp = load_cpu_field(ZF);
504 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
506 tmp = load_cpu_field(VF);
507 tmp2 = load_cpu_field(NF);
508 tcg_gen_xor_i32(tmp, tmp, tmp2);
510 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
513 fprintf(stderr, "Bad condition code 0x%x\n", cc);
519 static const uint8_t table_logic_cc[16] = {
520 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
521 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
522 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
523 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
526 /* Set PC state from an immediate address. */
527 static inline void gen_bx_im(DisasContext *s, uint32_t addr)
529 s->is_jmp = DISAS_UPDATE;
530 tcg_gen_movi_i32(cpu_R[31], addr & ~3);
533 /* Set PC state from var. var is marked as dead. */
534 static inline void gen_bx(DisasContext *s, TCGv var)
536 s->is_jmp = DISAS_UPDATE;
537 tcg_gen_andi_i32(cpu_R[31], var, ~3);
541 static inline void store_reg_bx(DisasContext *s, int reg, TCGv var)
543 store_reg(s, reg, var);
546 static inline TCGv gen_ld8s(TCGv addr, int index)
548 TCGv tmp = new_tmp();
549 tcg_gen_qemu_ld8s(tmp, addr, index);
553 static inline TCGv gen_ld8u(TCGv addr, int index)
555 TCGv tmp = new_tmp();
556 tcg_gen_qemu_ld8u(tmp, addr, index);
560 static inline TCGv gen_ld16s(TCGv addr, int index)
562 TCGv tmp = new_tmp();
563 tcg_gen_qemu_ld16s(tmp, addr, index);
567 static inline TCGv gen_ld16u(TCGv addr, int index)
569 TCGv tmp = new_tmp();
570 tcg_gen_qemu_ld16u(tmp, addr, index);
574 static inline TCGv gen_ld32(TCGv addr, int index)
576 TCGv tmp = new_tmp();
577 tcg_gen_qemu_ld32u(tmp, addr, index);
581 static inline void gen_st8(TCGv val, TCGv addr, int index)
583 tcg_gen_qemu_st8(val, addr, index);
587 static inline void gen_st16(TCGv val, TCGv addr, int index)
589 tcg_gen_qemu_st16(val, addr, index);
593 static inline void gen_st32(TCGv val, TCGv addr, int index)
595 tcg_gen_qemu_st32(val, addr, index);
599 static inline void gen_set_pc_im(uint32_t val)
601 tcg_gen_movi_i32(cpu_R[31], val);
604 /* Force a TB lookup after an instruction that changes the CPU state. */
605 static inline void gen_lookup_tb(DisasContext *s)
607 tcg_gen_movi_i32(cpu_R[31], s->pc & ~1);
608 s->is_jmp = DISAS_UPDATE;
611 static inline void gen_add_data_offset(DisasContext *s, unsigned int insn,
624 tcg_gen_addi_i32(var, var, val);
628 offset = load_reg(s, UCOP_REG_M);
629 gen_uc32_shift_im(offset, UCOP_SH_OP, UCOP_SH_IM, 0);
631 tcg_gen_sub_i32(var, var, offset);
633 tcg_gen_add_i32(var, var, offset);
639 static inline void gen_add_datah_offset(DisasContext *s, unsigned int insn,
647 val = (insn & 0x1f) | ((insn >> 4) & 0x3e0);
652 tcg_gen_addi_i32(var, var, val);
656 offset = load_reg(s, UCOP_REG_M);
658 tcg_gen_sub_i32(var, var, offset);
660 tcg_gen_add_i32(var, var, offset);
666 static inline long ucf64_reg_offset(int reg)
669 return offsetof(CPUUniCore32State, ucf64.regs[reg >> 1])
670 + offsetof(CPU_DoubleU, l.upper);
672 return offsetof(CPUUniCore32State, ucf64.regs[reg >> 1])
673 + offsetof(CPU_DoubleU, l.lower);
677 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
678 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
680 /* UniCore-F64 single load/store I_offset */
681 static void do_ucf64_ldst_i(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
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)
734 if (UCOP_REG_D != 0) {
737 if (UCOP_REG_N == 31) {
740 if ((insn << 24) == 0) {
744 addr = load_reg(s, UCOP_REG_N);
747 for (i = 0; i < 8; i++) {
754 if (UCOP_SET_P) { /* pre increment */
755 tcg_gen_addi_i32(addr, addr, 4);
756 } /* unnecessary to do anything when post increment */
758 if (UCOP_SET_P) { /* pre decrement */
759 tcg_gen_addi_i32(addr, addr, -(n * 4));
760 } else { /* post decrement */
762 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
767 freg = ((insn >> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
769 for (i = 0, j = 0; i < 8; i++, freg++) {
774 if (UCOP_SET_L) { /* load */
775 tmp = gen_ld32(addr, IS_USER(s));
776 ucf64_gen_st32(tmp, freg);
778 tmp = ucf64_gen_ld32(freg);
779 gen_st32(tmp, addr, IS_USER(s));
783 /* unnecessary to add after the last transfer */
785 tcg_gen_addi_i32(addr, addr, 4);
789 if (UCOP_SET_W) { /* write back */
791 if (!UCOP_SET_P) { /* post increment */
792 tcg_gen_addi_i32(addr, addr, 4);
793 } /* unnecessary to do anything when pre increment */
798 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
802 tcg_gen_addi_i32(addr, addr, -(n * 4));
805 store_reg(s, UCOP_REG_N, addr);
811 /* UniCore-F64 mrc/mcr */
812 static void do_ucf64_trans(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
816 if ((insn & 0xfe0003ff) == 0xe2000000) {
817 /* control register */
818 if ((UCOP_REG_N != UC32_UCF64_FPSCR) || (UCOP_REG_D == 31)) {
824 gen_helper_ucf64_get_fpscr(tmp, cpu_env);
825 store_reg(s, UCOP_REG_D, tmp);
828 tmp = load_reg(s, UCOP_REG_D);
829 gen_helper_ucf64_set_fpscr(cpu_env, tmp);
835 if ((insn & 0xfe0003ff) == 0xe0000000) {
836 /* general register */
837 if (UCOP_REG_D == 31) {
840 if (UCOP_SET(24)) { /* MFF */
841 tmp = ucf64_gen_ld32(UCOP_REG_N);
842 store_reg(s, UCOP_REG_D, tmp);
844 tmp = load_reg(s, UCOP_REG_D);
845 ucf64_gen_st32(tmp, UCOP_REG_N);
849 if ((insn & 0xfb000000) == 0xe9000000) {
851 if (UCOP_REG_D != 31) {
854 if (UCOP_UCF64_COND & 0x8) {
859 tcg_gen_movi_i32(tmp, UCOP_UCF64_COND);
861 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_N));
862 tcg_gen_ld_i64(cpu_F1d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
863 gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, tmp, cpu_env);
865 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_N));
866 tcg_gen_ld_i32(cpu_F1s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
867 gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, tmp, cpu_env);
875 /* UniCore-F64 convert instructions */
876 static void do_ucf64_fcvt(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
878 if (UCOP_UCF64_FMT == 3) {
881 if (UCOP_REG_N != 0) {
884 switch (UCOP_UCF64_FUNC) {
886 switch (UCOP_UCF64_FMT) {
888 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
889 gen_helper_ucf64_df2sf(cpu_F0s, cpu_F0d, cpu_env);
890 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
893 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
894 gen_helper_ucf64_si2sf(cpu_F0s, cpu_F0s, cpu_env);
895 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
903 switch (UCOP_UCF64_FMT) {
905 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
906 gen_helper_ucf64_sf2df(cpu_F0d, cpu_F0s, cpu_env);
907 tcg_gen_st_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_D));
910 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
911 gen_helper_ucf64_si2df(cpu_F0d, cpu_F0s, cpu_env);
912 tcg_gen_st_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_D));
920 switch (UCOP_UCF64_FMT) {
922 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
923 gen_helper_ucf64_sf2si(cpu_F0s, cpu_F0s, cpu_env);
924 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
927 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
928 gen_helper_ucf64_df2si(cpu_F0s, cpu_F0d, cpu_env);
929 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
941 /* UniCore-F64 compare instructions */
942 static void do_ucf64_fcmp(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
947 if (UCOP_REG_D != 0) {
953 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_N));
954 tcg_gen_ld_i64(cpu_F1d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
955 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
957 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_N));
958 tcg_gen_ld_i32(cpu_F1s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
959 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
963 #define gen_helper_ucf64_movs(x, y) do { } while (0)
964 #define gen_helper_ucf64_movd(x, y) do { } while (0)
966 #define UCF64_OP1(name) do { \
967 if (UCOP_REG_N != 0) { \
970 switch (UCOP_UCF64_FMT) { \
972 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
973 ucf64_reg_offset(UCOP_REG_M)); \
974 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
975 tcg_gen_st_i32(cpu_F0s, cpu_env, \
976 ucf64_reg_offset(UCOP_REG_D)); \
979 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
980 ucf64_reg_offset(UCOP_REG_M)); \
981 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
982 tcg_gen_st_i64(cpu_F0d, cpu_env, \
983 ucf64_reg_offset(UCOP_REG_D)); \
991 #define UCF64_OP2(name) do { \
992 switch (UCOP_UCF64_FMT) { \
994 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
995 ucf64_reg_offset(UCOP_REG_N)); \
996 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
997 ucf64_reg_offset(UCOP_REG_M)); \
998 gen_helper_ucf64_##name##s(cpu_F0s, \
999 cpu_F0s, cpu_F1s, cpu_env); \
1000 tcg_gen_st_i32(cpu_F0s, cpu_env, \
1001 ucf64_reg_offset(UCOP_REG_D)); \
1004 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
1005 ucf64_reg_offset(UCOP_REG_N)); \
1006 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
1007 ucf64_reg_offset(UCOP_REG_M)); \
1008 gen_helper_ucf64_##name##d(cpu_F0d, \
1009 cpu_F0d, cpu_F1d, cpu_env); \
1010 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1011 ucf64_reg_offset(UCOP_REG_D)); \
1019 /* UniCore-F64 data processing */
1020 static void do_ucf64_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1022 if (UCOP_UCF64_FMT == 3) {
1025 switch (UCOP_UCF64_FUNC) {
1052 /* Disassemble an F64 instruction */
1053 static void disas_ucf64_insn(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1055 if (!UCOP_SET(29)) {
1057 do_ucf64_ldst_m(env, s, insn);
1059 do_ucf64_ldst_i(env, s, insn);
1063 switch ((insn >> 26) & 0x3) {
1065 do_ucf64_datap(env, s, insn);
1071 do_ucf64_fcvt(env, s, insn);
1074 do_ucf64_fcmp(env, s, insn);
1078 do_ucf64_trans(env, s, insn);
1083 static inline bool use_goto_tb(DisasContext *s, uint32_t dest)
1085 #ifndef CONFIG_USER_ONLY
1086 return (s->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
1092 static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
1094 if (use_goto_tb(s, dest)) {
1096 gen_set_pc_im(dest);
1097 tcg_gen_exit_tb(s->tb, n);
1099 gen_set_pc_im(dest);
1100 tcg_gen_exit_tb(NULL, 0);
1104 static inline void gen_jmp(DisasContext *s, uint32_t dest)
1106 if (unlikely(s->singlestep_enabled)) {
1107 /* An indirect jump so that we still trigger the debug exception. */
1110 gen_goto_tb(s, 0, dest);
1111 s->is_jmp = DISAS_TB_JUMP;
1115 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1116 static int gen_set_psr(DisasContext *s, uint32_t mask, int bsr, TCGv t0)
1120 /* ??? This is also undefined in system mode. */
1125 tmp = load_cpu_field(bsr);
1126 tcg_gen_andi_i32(tmp, tmp, ~mask);
1127 tcg_gen_andi_i32(t0, t0, mask);
1128 tcg_gen_or_i32(tmp, tmp, t0);
1129 store_cpu_field(tmp, bsr);
1131 gen_set_asr(t0, mask);
1138 /* Generate an old-style exception return. Marks pc as dead. */
1139 static void gen_exception_return(DisasContext *s, TCGv pc)
1142 store_reg(s, 31, pc);
1143 tmp = load_cpu_field(bsr);
1144 gen_set_asr(tmp, 0xffffffff);
1146 s->is_jmp = DISAS_UPDATE;
1149 static void disas_coproc_insn(CPUUniCore32State *env, DisasContext *s,
1152 switch (UCOP_CPNUM) {
1153 #ifndef CONFIG_USER_ONLY
1155 disas_cp0_insn(env, s, insn);
1158 disas_ocd_insn(env, s, insn);
1162 disas_ucf64_insn(env, s, insn);
1165 /* Unknown coprocessor. */
1166 cpu_abort(env_cpu(env), "Unknown coprocessor!");
1170 /* data processing instructions */
1171 static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1177 if (UCOP_OPCODES == 0x0f || UCOP_OPCODES == 0x0d) {
1178 if (UCOP_SET(23)) { /* CMOV instructions */
1179 if ((UCOP_CMOV_COND == 0xe) || (UCOP_CMOV_COND == 0xf)) {
1182 /* if not always execute, we generate a conditional jump to
1184 s->condlabel = gen_new_label();
1185 gen_test_cc(UCOP_CMOV_COND ^ 1, s->condlabel);
1190 logic_cc = table_logic_cc[UCOP_OPCODES] & (UCOP_SET_S >> 24);
1194 /* immediate operand */
1197 val = (val >> UCOP_SH_IM) | (val << (32 - UCOP_SH_IM));
1200 tcg_gen_movi_i32(tmp2, val);
1201 if (logic_cc && UCOP_SH_IM) {
1202 gen_set_CF_bit31(tmp2);
1206 tmp2 = load_reg(s, UCOP_REG_M);
1208 tmp = load_reg(s, UCOP_REG_S);
1209 gen_uc32_shift_reg(tmp2, UCOP_SH_OP, tmp, logic_cc);
1211 gen_uc32_shift_im(tmp2, UCOP_SH_OP, UCOP_SH_IM, logic_cc);
1215 if (UCOP_OPCODES != 0x0f && UCOP_OPCODES != 0x0d) {
1216 tmp = load_reg(s, UCOP_REG_N);
1221 switch (UCOP_OPCODES) {
1223 tcg_gen_and_i32(tmp, tmp, tmp2);
1227 store_reg_bx(s, UCOP_REG_D, tmp);
1230 tcg_gen_xor_i32(tmp, tmp, tmp2);
1234 store_reg_bx(s, UCOP_REG_D, tmp);
1237 if (UCOP_SET_S && UCOP_REG_D == 31) {
1238 /* SUBS r31, ... is used for exception return. */
1242 gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
1243 gen_exception_return(s, tmp);
1246 gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
1248 tcg_gen_sub_i32(tmp, tmp, tmp2);
1250 store_reg_bx(s, UCOP_REG_D, tmp);
1255 gen_helper_sub_cc(tmp, cpu_env, tmp2, tmp);
1257 tcg_gen_sub_i32(tmp, tmp2, tmp);
1259 store_reg_bx(s, UCOP_REG_D, tmp);
1263 gen_helper_add_cc(tmp, cpu_env, tmp, tmp2);
1265 tcg_gen_add_i32(tmp, tmp, tmp2);
1267 store_reg_bx(s, UCOP_REG_D, tmp);
1271 gen_helper_adc_cc(tmp, cpu_env, tmp, tmp2);
1273 gen_add_carry(tmp, tmp, tmp2);
1275 store_reg_bx(s, UCOP_REG_D, tmp);
1279 gen_helper_sbc_cc(tmp, cpu_env, tmp, tmp2);
1281 gen_sub_carry(tmp, tmp, tmp2);
1283 store_reg_bx(s, UCOP_REG_D, tmp);
1287 gen_helper_sbc_cc(tmp, cpu_env, tmp2, tmp);
1289 gen_sub_carry(tmp, tmp2, tmp);
1291 store_reg_bx(s, UCOP_REG_D, tmp);
1295 tcg_gen_and_i32(tmp, tmp, tmp2);
1302 tcg_gen_xor_i32(tmp, tmp, tmp2);
1309 gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
1315 gen_helper_add_cc(tmp, cpu_env, tmp, tmp2);
1320 tcg_gen_or_i32(tmp, tmp, tmp2);
1324 store_reg_bx(s, UCOP_REG_D, tmp);
1327 if (logic_cc && UCOP_REG_D == 31) {
1328 /* MOVS r31, ... is used for exception return. */
1332 gen_exception_return(s, tmp2);
1337 store_reg_bx(s, UCOP_REG_D, tmp2);
1341 tcg_gen_andc_i32(tmp, tmp, tmp2);
1345 store_reg_bx(s, UCOP_REG_D, tmp);
1349 tcg_gen_not_i32(tmp2, tmp2);
1353 store_reg_bx(s, UCOP_REG_D, tmp2);
1356 if (UCOP_OPCODES != 0x0f && UCOP_OPCODES != 0x0d) {
1362 static void do_mult(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1364 TCGv tmp, tmp2, tmp3, tmp4;
1368 tmp = load_reg(s, UCOP_REG_M);
1369 tmp2 = load_reg(s, UCOP_REG_N);
1371 tcg_gen_muls2_i32(tmp, tmp2, tmp, tmp2);
1373 tcg_gen_mulu2_i32(tmp, tmp2, tmp, tmp2);
1375 if (UCOP_SET(25)) { /* mult accumulate */
1376 tmp3 = load_reg(s, UCOP_REG_LO);
1377 tmp4 = load_reg(s, UCOP_REG_HI);
1378 tcg_gen_add2_i32(tmp, tmp2, tmp, tmp2, tmp3, tmp4);
1382 store_reg(s, UCOP_REG_LO, tmp);
1383 store_reg(s, UCOP_REG_HI, tmp2);
1386 tmp = load_reg(s, UCOP_REG_M);
1387 tmp2 = load_reg(s, UCOP_REG_N);
1388 tcg_gen_mul_i32(tmp, tmp, tmp2);
1392 tmp2 = load_reg(s, UCOP_REG_S);
1393 tcg_gen_add_i32(tmp, tmp, tmp2);
1399 store_reg(s, UCOP_REG_D, tmp);
1403 /* miscellaneous instructions */
1404 static void do_misc(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1409 if ((insn & 0xffffffe0) == 0x10ffc120) {
1410 /* Trivial implementation equivalent to bx. */
1411 tmp = load_reg(s, UCOP_REG_M);
1416 if ((insn & 0xfbffc000) == 0x30ffc000) {
1417 /* PSR = immediate */
1420 val = (val >> UCOP_SH_IM) | (val << (32 - UCOP_SH_IM));
1423 tcg_gen_movi_i32(tmp, val);
1424 if (gen_set_psr(s, ~ASR_RESERVED, UCOP_SET_B, tmp)) {
1430 if ((insn & 0xfbffffe0) == 0x12ffc020) {
1431 /* PSR.flag = reg */
1432 tmp = load_reg(s, UCOP_REG_M);
1433 if (gen_set_psr(s, ASR_NZCV, UCOP_SET_B, tmp)) {
1439 if ((insn & 0xfbffffe0) == 0x10ffc020) {
1441 tmp = load_reg(s, UCOP_REG_M);
1442 if (gen_set_psr(s, ~ASR_RESERVED, UCOP_SET_B, tmp)) {
1448 if ((insn & 0xfbf83fff) == 0x10f80000) {
1454 tmp = load_cpu_field(bsr);
1457 gen_helper_asr_read(tmp, cpu_env);
1459 store_reg(s, UCOP_REG_D, tmp);
1463 if ((insn & 0xfbf83fe0) == 0x12f80120) {
1465 tmp = load_reg(s, UCOP_REG_M);
1468 tcg_gen_not_i32(tmp, tmp);
1470 tcg_gen_clzi_i32(tmp, tmp, 32);
1471 store_reg(s, UCOP_REG_D, tmp);
1479 /* load/store I_offset and R_offset */
1480 static void do_ldst_ir(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1482 unsigned int mmu_idx;
1486 tmp2 = load_reg(s, UCOP_REG_N);
1487 mmu_idx = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
1491 gen_add_data_offset(s, insn, tmp2);
1497 tmp = gen_ld8u(tmp2, mmu_idx);
1499 tmp = gen_ld32(tmp2, mmu_idx);
1503 tmp = load_reg(s, UCOP_REG_D);
1505 gen_st8(tmp, tmp2, mmu_idx);
1507 gen_st32(tmp, tmp2, mmu_idx);
1511 gen_add_data_offset(s, insn, tmp2);
1512 store_reg(s, UCOP_REG_N, tmp2);
1513 } else if (UCOP_SET_W) {
1514 store_reg(s, UCOP_REG_N, tmp2);
1519 /* Complete the load. */
1520 if (UCOP_REG_D == 31) {
1523 store_reg(s, UCOP_REG_D, tmp);
1528 /* SWP instruction */
1529 static void do_swap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1535 if ((insn & 0xff003fe0) != 0x40000120) {
1539 /* ??? This is not really atomic. However we know
1540 we never have multiple CPUs running in parallel,
1541 so it is good enough. */
1542 addr = load_reg(s, UCOP_REG_N);
1543 tmp = load_reg(s, UCOP_REG_M);
1545 tmp2 = gen_ld8u(addr, IS_USER(s));
1546 gen_st8(tmp, addr, IS_USER(s));
1548 tmp2 = gen_ld32(addr, IS_USER(s));
1549 gen_st32(tmp, addr, IS_USER(s));
1552 store_reg(s, UCOP_REG_D, tmp2);
1555 /* load/store hw/sb */
1556 static void do_ldst_hwsb(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1561 if (UCOP_SH_OP == 0) {
1562 do_swap(env, s, insn);
1566 addr = load_reg(s, UCOP_REG_N);
1568 gen_add_datah_offset(s, insn, addr);
1571 if (UCOP_SET_L) { /* load */
1572 switch (UCOP_SH_OP) {
1574 tmp = gen_ld16u(addr, IS_USER(s));
1577 tmp = gen_ld8s(addr, IS_USER(s));
1579 default: /* see do_swap */
1581 tmp = gen_ld16s(addr, IS_USER(s));
1584 } else { /* store */
1585 if (UCOP_SH_OP != 1) {
1588 tmp = load_reg(s, UCOP_REG_D);
1589 gen_st16(tmp, addr, IS_USER(s));
1591 /* Perform base writeback before the loaded value to
1592 ensure correct behavior with overlapping index registers. */
1594 gen_add_datah_offset(s, insn, addr);
1595 store_reg(s, UCOP_REG_N, addr);
1596 } else if (UCOP_SET_W) {
1597 store_reg(s, UCOP_REG_N, addr);
1602 /* Complete the load. */
1603 store_reg(s, UCOP_REG_D, tmp);
1607 /* load/store multiple words */
1608 static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1610 unsigned int val, i, mmu_idx;
1611 int j, n, reg, user, loaded_base;
1620 /* XXX: store correct base if write back */
1622 if (UCOP_SET_B) { /* S bit in instruction table */
1624 ILLEGAL; /* only usable in supervisor mode */
1626 if (UCOP_SET(18) == 0) { /* pc reg */
1631 mmu_idx = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
1632 addr = load_reg(s, UCOP_REG_N);
1634 /* compute total size */
1638 for (i = 0; i < 6; i++) {
1643 for (i = 9; i < 19; i++) {
1648 /* XXX: test invalid n == 0 case ? */
1652 tcg_gen_addi_i32(addr, addr, 4);
1654 /* post increment */
1659 tcg_gen_addi_i32(addr, addr, -(n * 4));
1661 /* post decrement */
1663 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
1669 reg = UCOP_SET(6) ? 16 : 0;
1670 for (i = 0; i < 19; i++, reg++) {
1675 if (UCOP_SET_L) { /* load */
1676 tmp = gen_ld32(addr, mmu_idx);
1680 tmp2 = tcg_const_i32(reg);
1681 gen_helper_set_user_reg(cpu_env, tmp2, tmp);
1682 tcg_temp_free_i32(tmp2);
1684 } else if (reg == UCOP_REG_N) {
1688 store_reg(s, reg, tmp);
1690 } else { /* store */
1692 /* special case: r31 = PC + 4 */
1695 tcg_gen_movi_i32(tmp, val);
1698 tmp2 = tcg_const_i32(reg);
1699 gen_helper_get_user_reg(tmp, cpu_env, tmp2);
1700 tcg_temp_free_i32(tmp2);
1702 tmp = load_reg(s, reg);
1704 gen_st32(tmp, addr, mmu_idx);
1707 /* no need to add after the last transfer */
1709 tcg_gen_addi_i32(addr, addr, 4);
1713 if (UCOP_SET_W) { /* write back */
1718 /* post increment */
1719 tcg_gen_addi_i32(addr, addr, 4);
1725 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
1728 /* post decrement */
1729 tcg_gen_addi_i32(addr, addr, -(n * 4));
1732 store_reg(s, UCOP_REG_N, addr);
1737 store_reg(s, UCOP_REG_N, loaded_var);
1739 if (UCOP_SET_B && !user) {
1740 /* Restore ASR from BSR. */
1741 tmp = load_cpu_field(bsr);
1742 gen_set_asr(tmp, 0xffffffff);
1744 s->is_jmp = DISAS_UPDATE;
1748 /* branch (and link) */
1749 static void do_branch(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
1755 if (UCOP_COND == 0xf) {
1759 if (UCOP_COND != 0xe) {
1760 /* if not always execute, we generate a conditional jump to
1762 s->condlabel = gen_new_label();
1763 gen_test_cc(UCOP_COND ^ 1, s->condlabel);
1767 val = (int32_t)s->pc;
1770 tcg_gen_movi_i32(tmp, val);
1771 store_reg(s, 30, tmp);
1773 offset = (((int32_t)insn << 8) >> 8);
1774 val += (offset << 2); /* unicore is pc+4 */
1778 static void disas_uc32_insn(CPUUniCore32State *env, DisasContext *s)
1782 insn = cpu_ldl_code(env, s->pc);
1785 /* UniCore instructions class:
1786 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1787 * AAA : see switch case
1788 * BBBB : opcodes or cond or PUBW
1793 switch (insn >> 29) {
1795 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1796 do_mult(env, s, insn);
1801 do_misc(env, s, insn);
1805 if (((UCOP_OPCODES >> 2) == 2) && !UCOP_SET_S) {
1806 do_misc(env, s, insn);
1809 do_datap(env, s, insn);
1813 if (UCOP_SET(8) && UCOP_SET(5)) {
1814 do_ldst_hwsb(env, s, insn);
1817 if (UCOP_SET(8) || UCOP_SET(5)) {
1821 do_ldst_ir(env, s, insn);
1826 ILLEGAL; /* extended instructions */
1828 do_ldst_m(env, s, insn);
1831 do_branch(env, s, insn);
1835 disas_coproc_insn(env, s, insn);
1838 if (!UCOP_SET(28)) {
1839 disas_coproc_insn(env, s, insn);
1842 if ((insn & 0xff000000) == 0xff000000) { /* syscall */
1843 gen_set_pc_im(s->pc);
1844 s->is_jmp = DISAS_SYSCALL;
1851 /* generate intermediate code for basic block 'tb'. */
1852 void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
1854 CPUUniCore32State *env = cs->env_ptr;
1855 DisasContext dc1, *dc = &dc1;
1856 target_ulong pc_start;
1857 uint32_t page_start;
1860 /* generate intermediate code */
1867 dc->is_jmp = DISAS_NEXT;
1869 dc->singlestep_enabled = cs->singlestep_enabled;
1871 cpu_F0s = tcg_temp_new_i32();
1872 cpu_F1s = tcg_temp_new_i32();
1873 cpu_F0d = tcg_temp_new_i64();
1874 cpu_F1d = tcg_temp_new_i64();
1875 page_start = pc_start & TARGET_PAGE_MASK;
1878 #ifndef CONFIG_USER_ONLY
1879 if ((env->uncached_asr & ASR_M) == ASR_MODE_USER) {
1888 tcg_gen_insn_start(dc->pc);
1891 if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {
1892 gen_set_pc_im(dc->pc);
1893 gen_exception(EXCP_DEBUG);
1894 dc->is_jmp = DISAS_JUMP;
1895 /* The address covered by the breakpoint must be included in
1896 [tb->pc, tb->pc + tb->size) in order to for it to be
1897 properly cleared -- thus we increment the PC here so that
1898 the logic setting tb->size below does the right thing. */
1900 goto done_generating;
1903 if (num_insns == max_insns && (tb_cflags(tb) & CF_LAST_IO)) {
1907 disas_uc32_insn(env, dc);
1910 fprintf(stderr, "Internal resource leak before %08x\n", dc->pc);
1914 if (dc->condjmp && !dc->is_jmp) {
1915 gen_set_label(dc->condlabel);
1918 /* Translation stops when a conditional branch is encountered.
1919 * Otherwise the subsequent code could get translated several times.
1920 * Also stop translation when a page boundary is reached. This
1921 * ensures prefetch aborts occur at the right place. */
1922 } while (!dc->is_jmp && !tcg_op_buf_full() &&
1923 !cs->singlestep_enabled &&
1925 dc->pc - page_start < TARGET_PAGE_SIZE &&
1926 num_insns < max_insns);
1928 if (tb_cflags(tb) & CF_LAST_IO) {
1930 /* FIXME: This can theoretically happen with self-modifying
1932 cpu_abort(cs, "IO on conditional branch instruction");
1937 /* At this stage dc->condjmp will only be set when the skipped
1938 instruction was a conditional branch or trap, and the PC has
1939 already been written. */
1940 if (unlikely(cs->singlestep_enabled)) {
1941 /* Make sure the pc is updated, and raise a debug exception. */
1943 if (dc->is_jmp == DISAS_SYSCALL) {
1944 gen_exception(UC32_EXCP_PRIV);
1946 gen_exception(EXCP_DEBUG);
1948 gen_set_label(dc->condlabel);
1950 if (dc->condjmp || !dc->is_jmp) {
1951 gen_set_pc_im(dc->pc);
1954 if (dc->is_jmp == DISAS_SYSCALL && !dc->condjmp) {
1955 gen_exception(UC32_EXCP_PRIV);
1957 gen_exception(EXCP_DEBUG);
1960 /* While branches must always occur at the end of an IT block,
1961 there are a few other things that can cause us to terminate
1962 the TB in the middel of an IT block:
1963 - Exception generating instructions (bkpt, swi, undefined).
1965 - Hardware watchpoints.
1966 Hardware breakpoints have already been handled and skip this code.
1968 switch (dc->is_jmp) {
1970 gen_goto_tb(dc, 1, dc->pc);
1975 /* indicate that the hash table must be used to find the next TB */
1976 tcg_gen_exit_tb(NULL, 0);
1979 /* nothing more to generate */
1982 gen_exception(UC32_EXCP_PRIV);
1986 gen_set_label(dc->condlabel);
1987 gen_goto_tb(dc, 1, dc->pc);
1993 gen_tb_end(tb, num_insns);
1996 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
1997 && qemu_log_in_addr_range(pc_start)) {
1999 qemu_log("----------------\n");
2000 qemu_log("IN: %s\n", lookup_symbol(pc_start));
2001 log_target_disas(cs, pc_start, dc->pc - pc_start);
2006 tb->size = dc->pc - pc_start;
2007 tb->icount = num_insns;
2010 static const char *cpu_mode_names[16] = {
2011 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2012 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2015 #undef UCF64_DUMP_STATE
2016 #ifdef UCF64_DUMP_STATE
2017 static void cpu_dump_state_ucf64(CPUUniCore32State *env, int flags)
2025 /* ??? This assumes float64 and double have the same layout.
2026 Oh well, it's only debug dumps. */
2032 for (i = 0; i < 16; i++) {
2033 d.d = env->ucf64.regs[i];
2037 qemu_fprintf(f, "s%02d=%08x(%8g) s%02d=%08x(%8g)",
2038 i * 2, (int)s0.i, s0.s,
2039 i * 2 + 1, (int)s1.i, s1.s);
2040 qemu_fprintf(f, " d%02d=%" PRIx64 "(%8g)\n",
2041 i, (uint64_t)d0.f64, d0.d);
2043 qemu_fprintf(f, "FPSCR: %08x\n", (int)env->ucf64.xregs[UC32_UCF64_FPSCR]);
2046 #define cpu_dump_state_ucf64(env, file, pr, flags) do { } while (0)
2049 void uc32_cpu_dump_state(CPUState *cs, FILE *f, int flags)
2051 UniCore32CPU *cpu = UNICORE32_CPU(cs);
2052 CPUUniCore32State *env = &cpu->env;
2056 for (i = 0; i < 32; i++) {
2057 qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
2059 qemu_fprintf(f, "\n");
2061 qemu_fprintf(f, " ");
2064 psr = cpu_asr_read(env);
2065 qemu_fprintf(f, "PSR=%08x %c%c%c%c %s\n",
2067 psr & (1 << 31) ? 'N' : '-',
2068 psr & (1 << 30) ? 'Z' : '-',
2069 psr & (1 << 29) ? 'C' : '-',
2070 psr & (1 << 28) ? 'V' : '-',
2071 cpu_mode_names[psr & 0xf]);
2073 if (flags & CPU_DUMP_FPU) {
2074 cpu_dump_state_ucf64(env, f, cpu_fprintf, flags);
2078 void restore_state_to_opc(CPUUniCore32State *env, TranslationBlock *tb,
2081 env->regs[31] = data[0];