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"
21 #include "exec/helper-proto.h"
22 #include "exec/helper-gen.h"
24 #include "trace-tcg.h"
28 /* internal defines */
29 typedef struct DisasContext
{
32 /* Nonzero if this instruction has been conditionally skipped. */
34 /* The label that will be jumped to when the instruction is skipped. */
36 struct TranslationBlock
*tb
;
37 int singlestep_enabled
;
38 #ifndef CONFIG_USER_ONLY
43 #ifndef CONFIG_USER_ONLY
44 #define IS_USER(s) (s->user)
49 /* is_jmp field values */
50 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
51 #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */
52 #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
53 /* These instructions trap after executing, so defer them until after the
54 conditional executions state has been updated. */
55 #define DISAS_SYSCALL DISAS_TARGET_3
57 static TCGv_i32 cpu_R
[32];
59 /* FIXME: These should be removed. */
60 static TCGv cpu_F0s
, cpu_F1s
;
61 static TCGv_i64 cpu_F0d
, cpu_F1d
;
63 #include "exec/gen-icount.h"
65 static const char *regnames
[] = {
66 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
67 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
68 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
69 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
71 /* initialize TCG globals. */
72 void uc32_translate_init(void)
76 for (i
= 0; i
< 32; i
++) {
77 cpu_R
[i
] = tcg_global_mem_new_i32(cpu_env
,
78 offsetof(CPUUniCore32State
, regs
[i
]), regnames
[i
]);
84 /* Allocate a temporary variable. */
85 static TCGv_i32
new_tmp(void)
88 return tcg_temp_new_i32();
91 /* Release a temporary variable. */
92 static void dead_tmp(TCGv tmp
)
98 static inline TCGv
load_cpu_offset(int offset
)
100 TCGv tmp
= new_tmp();
101 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
105 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUUniCore32State, name))
107 static inline void store_cpu_offset(TCGv var
, int offset
)
109 tcg_gen_st_i32(var
, cpu_env
, offset
);
113 #define store_cpu_field(var, name) \
114 store_cpu_offset(var, offsetof(CPUUniCore32State, name))
116 /* Set a variable to the value of a CPU register. */
117 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
121 /* normaly, since we updated PC */
123 tcg_gen_movi_i32(var
, addr
);
125 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
129 /* Create a new temporary and set it to the value of a CPU register. */
130 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
132 TCGv tmp
= new_tmp();
133 load_reg_var(s
, tmp
, reg
);
137 /* Set a CPU register. The source must be a temporary and will be
139 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
142 tcg_gen_andi_i32(var
, var
, ~3);
143 s
->is_jmp
= DISAS_JUMP
;
145 tcg_gen_mov_i32(cpu_R
[reg
], var
);
149 /* Value extensions. */
150 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
151 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
152 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
153 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
155 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
156 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
157 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
158 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
159 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
160 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
161 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
162 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
163 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
164 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
165 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
166 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
167 #define UCOP_COND (((insn) >> 25) & 0x0f)
168 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
169 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
170 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
171 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
172 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
174 #define UCOP_SET(i) ((insn) & (1 << (i)))
175 #define UCOP_SET_P UCOP_SET(28)
176 #define UCOP_SET_U UCOP_SET(27)
177 #define UCOP_SET_B UCOP_SET(26)
178 #define UCOP_SET_W UCOP_SET(25)
179 #define UCOP_SET_L UCOP_SET(24)
180 #define UCOP_SET_S UCOP_SET(24)
182 #define ILLEGAL cpu_abort(CPU(cpu), \
183 "Illegal UniCore32 instruction %x at line %d!", \
186 #ifndef CONFIG_USER_ONLY
187 static void disas_cp0_insn(CPUUniCore32State
*env
, DisasContext
*s
,
190 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
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
,
216 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
219 if ((insn
& 0xff003fff) == 0xe1000400) {
221 * movc rd, pp.nn, #imm9
223 * nn: UCOP_REG_N (must be 0)
226 if (UCOP_REG_N
== 0) {
228 tcg_gen_movi_i32(tmp
, 0);
229 store_reg(s
, UCOP_REG_D
, tmp
);
235 if ((insn
& 0xff003fff) == 0xe0000401) {
237 * movc pp.nn, rn, #imm9
239 * nn: UCOP_REG_N (must be 1)
242 if (UCOP_REG_N
== 1) {
243 tmp
= load_reg(s
, UCOP_REG_D
);
244 gen_helper_cp1_putc(tmp
);
255 static inline void gen_set_asr(TCGv var
, uint32_t mask
)
257 TCGv tmp_mask
= tcg_const_i32(mask
);
258 gen_helper_asr_write(cpu_env
, var
, tmp_mask
);
259 tcg_temp_free_i32(tmp_mask
);
261 /* Set NZCV flags from the high 4 bits of var. */
262 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
264 static void gen_exception(int excp
)
266 TCGv tmp
= new_tmp();
267 tcg_gen_movi_i32(tmp
, excp
);
268 gen_helper_exception(cpu_env
, tmp
);
272 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUUniCore32State, CF))
274 /* Set CF to the top bit of var. */
275 static void gen_set_CF_bit31(TCGv var
)
277 TCGv tmp
= new_tmp();
278 tcg_gen_shri_i32(tmp
, var
, 31);
283 /* Set N and Z flags from var. */
284 static inline void gen_logic_CC(TCGv var
)
286 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, NF
));
287 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUUniCore32State
, ZF
));
290 /* dest = T0 + T1 + CF. */
291 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
294 tcg_gen_add_i32(dest
, t0
, t1
);
295 tmp
= load_cpu_field(CF
);
296 tcg_gen_add_i32(dest
, dest
, tmp
);
300 /* dest = T0 - T1 + CF - 1. */
301 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
304 tcg_gen_sub_i32(dest
, t0
, t1
);
305 tmp
= load_cpu_field(CF
);
306 tcg_gen_add_i32(dest
, dest
, tmp
);
307 tcg_gen_subi_i32(dest
, dest
, 1);
311 static void shifter_out_im(TCGv var
, int shift
)
313 TCGv tmp
= new_tmp();
315 tcg_gen_andi_i32(tmp
, var
, 1);
317 tcg_gen_shri_i32(tmp
, var
, shift
);
319 tcg_gen_andi_i32(tmp
, tmp
, 1);
326 /* Shift by immediate. Includes special handling for shift == 0. */
327 static inline void gen_uc32_shift_im(TCGv var
, int shiftop
, int shift
,
334 shifter_out_im(var
, 32 - shift
);
336 tcg_gen_shli_i32(var
, var
, shift
);
342 tcg_gen_shri_i32(var
, var
, 31);
345 tcg_gen_movi_i32(var
, 0);
348 shifter_out_im(var
, shift
- 1);
350 tcg_gen_shri_i32(var
, var
, shift
);
358 shifter_out_im(var
, shift
- 1);
363 tcg_gen_sari_i32(var
, var
, shift
);
365 case 3: /* ROR/RRX */
368 shifter_out_im(var
, shift
- 1);
370 tcg_gen_rotri_i32(var
, var
, shift
); break;
372 TCGv tmp
= load_cpu_field(CF
);
374 shifter_out_im(var
, 0);
376 tcg_gen_shri_i32(var
, var
, 1);
377 tcg_gen_shli_i32(tmp
, tmp
, 31);
378 tcg_gen_or_i32(var
, var
, tmp
);
384 static inline void gen_uc32_shift_reg(TCGv var
, int shiftop
,
385 TCGv shift
, int flags
)
390 gen_helper_shl_cc(var
, cpu_env
, var
, shift
);
393 gen_helper_shr_cc(var
, cpu_env
, var
, shift
);
396 gen_helper_sar_cc(var
, cpu_env
, var
, shift
);
399 gen_helper_ror_cc(var
, cpu_env
, var
, shift
);
405 gen_helper_shl(var
, var
, shift
);
408 gen_helper_shr(var
, var
, shift
);
411 gen_helper_sar(var
, var
, shift
);
414 tcg_gen_andi_i32(shift
, shift
, 0x1f);
415 tcg_gen_rotr_i32(var
, var
, shift
);
422 static void gen_test_cc(int cc
, TCGLabel
*label
)
430 tmp
= load_cpu_field(ZF
);
431 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
434 tmp
= load_cpu_field(ZF
);
435 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
438 tmp
= load_cpu_field(CF
);
439 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
442 tmp
= load_cpu_field(CF
);
443 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
446 tmp
= load_cpu_field(NF
);
447 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
450 tmp
= load_cpu_field(NF
);
451 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
454 tmp
= load_cpu_field(VF
);
455 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
458 tmp
= load_cpu_field(VF
);
459 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
461 case 8: /* hi: C && !Z */
462 inv
= gen_new_label();
463 tmp
= load_cpu_field(CF
);
464 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
466 tmp
= load_cpu_field(ZF
);
467 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
470 case 9: /* ls: !C || Z */
471 tmp
= load_cpu_field(CF
);
472 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
474 tmp
= load_cpu_field(ZF
);
475 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
477 case 10: /* ge: N == V -> N ^ V == 0 */
478 tmp
= load_cpu_field(VF
);
479 tmp2
= load_cpu_field(NF
);
480 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
482 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
484 case 11: /* lt: N != V -> N ^ V != 0 */
485 tmp
= load_cpu_field(VF
);
486 tmp2
= load_cpu_field(NF
);
487 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
489 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
491 case 12: /* gt: !Z && N == V */
492 inv
= gen_new_label();
493 tmp
= load_cpu_field(ZF
);
494 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
496 tmp
= load_cpu_field(VF
);
497 tmp2
= load_cpu_field(NF
);
498 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
500 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
503 case 13: /* le: Z || N != V */
504 tmp
= load_cpu_field(ZF
);
505 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
507 tmp
= load_cpu_field(VF
);
508 tmp2
= load_cpu_field(NF
);
509 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
511 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
514 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
520 static const uint8_t table_logic_cc
[16] = {
521 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
522 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
523 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
524 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
527 /* Set PC state from an immediate address. */
528 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
530 s
->is_jmp
= DISAS_UPDATE
;
531 tcg_gen_movi_i32(cpu_R
[31], addr
& ~3);
534 /* Set PC state from var. var is marked as dead. */
535 static inline void gen_bx(DisasContext
*s
, TCGv var
)
537 s
->is_jmp
= DISAS_UPDATE
;
538 tcg_gen_andi_i32(cpu_R
[31], var
, ~3);
542 static inline void store_reg_bx(DisasContext
*s
, int reg
, TCGv var
)
544 store_reg(s
, reg
, var
);
547 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
549 TCGv tmp
= new_tmp();
550 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
554 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
556 TCGv tmp
= new_tmp();
557 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
561 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
563 TCGv tmp
= new_tmp();
564 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
568 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
570 TCGv tmp
= new_tmp();
571 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
575 static inline TCGv
gen_ld32(TCGv addr
, int index
)
577 TCGv tmp
= new_tmp();
578 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
582 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
584 tcg_gen_qemu_st8(val
, addr
, index
);
588 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
590 tcg_gen_qemu_st16(val
, addr
, index
);
594 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
596 tcg_gen_qemu_st32(val
, addr
, index
);
600 static inline void gen_set_pc_im(uint32_t val
)
602 tcg_gen_movi_i32(cpu_R
[31], val
);
605 /* Force a TB lookup after an instruction that changes the CPU state. */
606 static inline void gen_lookup_tb(DisasContext
*s
)
608 tcg_gen_movi_i32(cpu_R
[31], s
->pc
& ~1);
609 s
->is_jmp
= DISAS_UPDATE
;
612 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
625 tcg_gen_addi_i32(var
, var
, val
);
629 offset
= load_reg(s
, UCOP_REG_M
);
630 gen_uc32_shift_im(offset
, UCOP_SH_OP
, UCOP_SH_IM
, 0);
632 tcg_gen_sub_i32(var
, var
, offset
);
634 tcg_gen_add_i32(var
, var
, offset
);
640 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
648 val
= (insn
& 0x1f) | ((insn
>> 4) & 0x3e0);
653 tcg_gen_addi_i32(var
, var
, val
);
657 offset
= load_reg(s
, UCOP_REG_M
);
659 tcg_gen_sub_i32(var
, var
, offset
);
661 tcg_gen_add_i32(var
, var
, offset
);
667 static inline long ucf64_reg_offset(int reg
)
670 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
671 + offsetof(CPU_DoubleU
, l
.upper
);
673 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
674 + offsetof(CPU_DoubleU
, l
.lower
);
678 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
679 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
681 /* UniCore-F64 single load/store I_offset */
682 static void do_ucf64_ldst_i(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
684 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
689 addr
= load_reg(s
, UCOP_REG_N
);
690 if (!UCOP_SET_P
&& !UCOP_SET_W
) {
695 offset
= UCOP_IMM10
<< 2;
700 tcg_gen_addi_i32(addr
, addr
, offset
);
704 if (UCOP_SET_L
) { /* load */
705 tmp
= gen_ld32(addr
, IS_USER(s
));
706 ucf64_gen_st32(tmp
, UCOP_REG_D
);
708 tmp
= ucf64_gen_ld32(UCOP_REG_D
);
709 gen_st32(tmp
, addr
, IS_USER(s
));
713 offset
= UCOP_IMM10
<< 2;
718 tcg_gen_addi_i32(addr
, addr
, offset
);
722 store_reg(s
, UCOP_REG_N
, addr
);
728 /* UniCore-F64 load/store multiple words */
729 static void do_ucf64_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
731 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
737 if (UCOP_REG_D
!= 0) {
740 if (UCOP_REG_N
== 31) {
743 if ((insn
<< 24) == 0) {
747 addr
= load_reg(s
, UCOP_REG_N
);
750 for (i
= 0; i
< 8; i
++) {
757 if (UCOP_SET_P
) { /* pre increment */
758 tcg_gen_addi_i32(addr
, addr
, 4);
759 } /* unnecessary to do anything when post increment */
761 if (UCOP_SET_P
) { /* pre decrement */
762 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
763 } else { /* post decrement */
765 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
770 freg
= ((insn
>> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
772 for (i
= 0, j
= 0; i
< 8; i
++, freg
++) {
777 if (UCOP_SET_L
) { /* load */
778 tmp
= gen_ld32(addr
, IS_USER(s
));
779 ucf64_gen_st32(tmp
, freg
);
781 tmp
= ucf64_gen_ld32(freg
);
782 gen_st32(tmp
, addr
, IS_USER(s
));
786 /* unnecessary to add after the last transfer */
788 tcg_gen_addi_i32(addr
, addr
, 4);
792 if (UCOP_SET_W
) { /* write back */
794 if (!UCOP_SET_P
) { /* post increment */
795 tcg_gen_addi_i32(addr
, addr
, 4);
796 } /* unnecessary to do anything when pre increment */
801 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
805 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
808 store_reg(s
, UCOP_REG_N
, addr
);
814 /* UniCore-F64 mrc/mcr */
815 static void do_ucf64_trans(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
817 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
820 if ((insn
& 0xfe0003ff) == 0xe2000000) {
821 /* control register */
822 if ((UCOP_REG_N
!= UC32_UCF64_FPSCR
) || (UCOP_REG_D
== 31)) {
828 gen_helper_ucf64_get_fpscr(tmp
, cpu_env
);
829 store_reg(s
, UCOP_REG_D
, tmp
);
832 tmp
= load_reg(s
, UCOP_REG_D
);
833 gen_helper_ucf64_set_fpscr(cpu_env
, tmp
);
839 if ((insn
& 0xfe0003ff) == 0xe0000000) {
840 /* general register */
841 if (UCOP_REG_D
== 31) {
844 if (UCOP_SET(24)) { /* MFF */
845 tmp
= ucf64_gen_ld32(UCOP_REG_N
);
846 store_reg(s
, UCOP_REG_D
, tmp
);
848 tmp
= load_reg(s
, UCOP_REG_D
);
849 ucf64_gen_st32(tmp
, UCOP_REG_N
);
853 if ((insn
& 0xfb000000) == 0xe9000000) {
855 if (UCOP_REG_D
!= 31) {
858 if (UCOP_UCF64_COND
& 0x8) {
863 tcg_gen_movi_i32(tmp
, UCOP_UCF64_COND
);
865 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
866 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
867 gen_helper_ucf64_cmpd(cpu_F0d
, cpu_F1d
, tmp
, cpu_env
);
869 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
870 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
871 gen_helper_ucf64_cmps(cpu_F0s
, cpu_F1s
, tmp
, cpu_env
);
879 /* UniCore-F64 convert instructions */
880 static void do_ucf64_fcvt(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
882 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
884 if (UCOP_UCF64_FMT
== 3) {
887 if (UCOP_REG_N
!= 0) {
890 switch (UCOP_UCF64_FUNC
) {
892 switch (UCOP_UCF64_FMT
) {
894 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
895 gen_helper_ucf64_df2sf(cpu_F0s
, cpu_F0d
, cpu_env
);
896 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
899 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
900 gen_helper_ucf64_si2sf(cpu_F0s
, cpu_F0s
, cpu_env
);
901 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
909 switch (UCOP_UCF64_FMT
) {
911 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
912 gen_helper_ucf64_sf2df(cpu_F0d
, cpu_F0s
, cpu_env
);
913 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
916 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
917 gen_helper_ucf64_si2df(cpu_F0d
, cpu_F0s
, cpu_env
);
918 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
926 switch (UCOP_UCF64_FMT
) {
928 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
929 gen_helper_ucf64_sf2si(cpu_F0s
, cpu_F0s
, cpu_env
);
930 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
933 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
934 gen_helper_ucf64_df2si(cpu_F0s
, cpu_F0d
, cpu_env
);
935 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
947 /* UniCore-F64 compare instructions */
948 static void do_ucf64_fcmp(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
950 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
955 if (UCOP_REG_D
!= 0) {
961 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
962 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
963 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
965 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
966 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
967 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
971 #define gen_helper_ucf64_movs(x, y) do { } while (0)
972 #define gen_helper_ucf64_movd(x, y) do { } while (0)
974 #define UCF64_OP1(name) do { \
975 if (UCOP_REG_N != 0) { \
978 switch (UCOP_UCF64_FMT) { \
980 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
981 ucf64_reg_offset(UCOP_REG_M)); \
982 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
983 tcg_gen_st_i32(cpu_F0s, cpu_env, \
984 ucf64_reg_offset(UCOP_REG_D)); \
987 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
988 ucf64_reg_offset(UCOP_REG_M)); \
989 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
990 tcg_gen_st_i64(cpu_F0d, cpu_env, \
991 ucf64_reg_offset(UCOP_REG_D)); \
999 #define UCF64_OP2(name) do { \
1000 switch (UCOP_UCF64_FMT) { \
1002 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
1003 ucf64_reg_offset(UCOP_REG_N)); \
1004 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
1005 ucf64_reg_offset(UCOP_REG_M)); \
1006 gen_helper_ucf64_##name##s(cpu_F0s, \
1007 cpu_F0s, cpu_F1s, cpu_env); \
1008 tcg_gen_st_i32(cpu_F0s, cpu_env, \
1009 ucf64_reg_offset(UCOP_REG_D)); \
1012 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
1013 ucf64_reg_offset(UCOP_REG_N)); \
1014 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
1015 ucf64_reg_offset(UCOP_REG_M)); \
1016 gen_helper_ucf64_##name##d(cpu_F0d, \
1017 cpu_F0d, cpu_F1d, cpu_env); \
1018 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1019 ucf64_reg_offset(UCOP_REG_D)); \
1027 /* UniCore-F64 data processing */
1028 static void do_ucf64_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1030 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1032 if (UCOP_UCF64_FMT
== 3) {
1035 switch (UCOP_UCF64_FUNC
) {
1062 /* Disassemble an F64 instruction */
1063 static void disas_ucf64_insn(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1065 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1067 if (!UCOP_SET(29)) {
1069 do_ucf64_ldst_m(env
, s
, insn
);
1071 do_ucf64_ldst_i(env
, s
, insn
);
1075 switch ((insn
>> 26) & 0x3) {
1077 do_ucf64_datap(env
, s
, insn
);
1083 do_ucf64_fcvt(env
, s
, insn
);
1086 do_ucf64_fcmp(env
, s
, insn
);
1090 do_ucf64_trans(env
, s
, insn
);
1095 static inline bool use_goto_tb(DisasContext
*s
, uint32_t dest
)
1097 #ifndef CONFIG_USER_ONLY
1098 return (s
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
1104 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
1106 if (use_goto_tb(s
, dest
)) {
1108 gen_set_pc_im(dest
);
1109 tcg_gen_exit_tb(s
->tb
, n
);
1111 gen_set_pc_im(dest
);
1112 tcg_gen_exit_tb(NULL
, 0);
1116 static inline void gen_jmp(DisasContext
*s
, uint32_t dest
)
1118 if (unlikely(s
->singlestep_enabled
)) {
1119 /* An indirect jump so that we still trigger the debug exception. */
1122 gen_goto_tb(s
, 0, dest
);
1123 s
->is_jmp
= DISAS_TB_JUMP
;
1127 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1128 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int bsr
, TCGv t0
)
1132 /* ??? This is also undefined in system mode. */
1137 tmp
= load_cpu_field(bsr
);
1138 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
1139 tcg_gen_andi_i32(t0
, t0
, mask
);
1140 tcg_gen_or_i32(tmp
, tmp
, t0
);
1141 store_cpu_field(tmp
, bsr
);
1143 gen_set_asr(t0
, mask
);
1150 /* Generate an old-style exception return. Marks pc as dead. */
1151 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
1154 store_reg(s
, 31, pc
);
1155 tmp
= load_cpu_field(bsr
);
1156 gen_set_asr(tmp
, 0xffffffff);
1158 s
->is_jmp
= DISAS_UPDATE
;
1161 static void disas_coproc_insn(CPUUniCore32State
*env
, DisasContext
*s
,
1164 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1166 switch (UCOP_CPNUM
) {
1167 #ifndef CONFIG_USER_ONLY
1169 disas_cp0_insn(env
, s
, insn
);
1172 disas_ocd_insn(env
, s
, insn
);
1176 disas_ucf64_insn(env
, s
, insn
);
1179 /* Unknown coprocessor. */
1180 cpu_abort(CPU(cpu
), "Unknown coprocessor!");
1184 /* data processing instructions */
1185 static void do_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1187 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1192 if (UCOP_OPCODES
== 0x0f || UCOP_OPCODES
== 0x0d) {
1193 if (UCOP_SET(23)) { /* CMOV instructions */
1194 if ((UCOP_CMOV_COND
== 0xe) || (UCOP_CMOV_COND
== 0xf)) {
1197 /* if not always execute, we generate a conditional jump to
1199 s
->condlabel
= gen_new_label();
1200 gen_test_cc(UCOP_CMOV_COND
^ 1, s
->condlabel
);
1205 logic_cc
= table_logic_cc
[UCOP_OPCODES
] & (UCOP_SET_S
>> 24);
1209 /* immediate operand */
1212 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1215 tcg_gen_movi_i32(tmp2
, val
);
1216 if (logic_cc
&& UCOP_SH_IM
) {
1217 gen_set_CF_bit31(tmp2
);
1221 tmp2
= load_reg(s
, UCOP_REG_M
);
1223 tmp
= load_reg(s
, UCOP_REG_S
);
1224 gen_uc32_shift_reg(tmp2
, UCOP_SH_OP
, tmp
, logic_cc
);
1226 gen_uc32_shift_im(tmp2
, UCOP_SH_OP
, UCOP_SH_IM
, logic_cc
);
1230 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1231 tmp
= load_reg(s
, UCOP_REG_N
);
1236 switch (UCOP_OPCODES
) {
1238 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1242 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1245 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1249 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1252 if (UCOP_SET_S
&& UCOP_REG_D
== 31) {
1253 /* SUBS r31, ... is used for exception return. */
1257 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1258 gen_exception_return(s
, tmp
);
1261 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1263 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
1265 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1270 gen_helper_sub_cc(tmp
, cpu_env
, tmp2
, tmp
);
1272 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
1274 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1278 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1280 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1282 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1286 gen_helper_adc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1288 gen_add_carry(tmp
, tmp
, tmp2
);
1290 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1294 gen_helper_sbc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1296 gen_sub_carry(tmp
, tmp
, tmp2
);
1298 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1302 gen_helper_sbc_cc(tmp
, cpu_env
, tmp2
, tmp
);
1304 gen_sub_carry(tmp
, tmp2
, tmp
);
1306 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1310 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1317 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1324 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1330 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1335 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1339 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1342 if (logic_cc
&& UCOP_REG_D
== 31) {
1343 /* MOVS r31, ... is used for exception return. */
1347 gen_exception_return(s
, tmp2
);
1352 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1356 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1360 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1364 tcg_gen_not_i32(tmp2
, tmp2
);
1368 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1371 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1377 static void do_mult(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1379 TCGv tmp
, tmp2
, tmp3
, tmp4
;
1383 tmp
= load_reg(s
, UCOP_REG_M
);
1384 tmp2
= load_reg(s
, UCOP_REG_N
);
1386 tcg_gen_muls2_i32(tmp
, tmp2
, tmp
, tmp2
);
1388 tcg_gen_mulu2_i32(tmp
, tmp2
, tmp
, tmp2
);
1390 if (UCOP_SET(25)) { /* mult accumulate */
1391 tmp3
= load_reg(s
, UCOP_REG_LO
);
1392 tmp4
= load_reg(s
, UCOP_REG_HI
);
1393 tcg_gen_add2_i32(tmp
, tmp2
, tmp
, tmp2
, tmp3
, tmp4
);
1397 store_reg(s
, UCOP_REG_LO
, tmp
);
1398 store_reg(s
, UCOP_REG_HI
, tmp2
);
1401 tmp
= load_reg(s
, UCOP_REG_M
);
1402 tmp2
= load_reg(s
, UCOP_REG_N
);
1403 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
1407 tmp2
= load_reg(s
, UCOP_REG_S
);
1408 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1414 store_reg(s
, UCOP_REG_D
, tmp
);
1418 /* miscellaneous instructions */
1419 static void do_misc(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1421 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1425 if ((insn
& 0xffffffe0) == 0x10ffc120) {
1426 /* Trivial implementation equivalent to bx. */
1427 tmp
= load_reg(s
, UCOP_REG_M
);
1432 if ((insn
& 0xfbffc000) == 0x30ffc000) {
1433 /* PSR = immediate */
1436 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1439 tcg_gen_movi_i32(tmp
, val
);
1440 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1446 if ((insn
& 0xfbffffe0) == 0x12ffc020) {
1447 /* PSR.flag = reg */
1448 tmp
= load_reg(s
, UCOP_REG_M
);
1449 if (gen_set_psr(s
, ASR_NZCV
, UCOP_SET_B
, tmp
)) {
1455 if ((insn
& 0xfbffffe0) == 0x10ffc020) {
1457 tmp
= load_reg(s
, UCOP_REG_M
);
1458 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1464 if ((insn
& 0xfbf83fff) == 0x10f80000) {
1470 tmp
= load_cpu_field(bsr
);
1473 gen_helper_asr_read(tmp
, cpu_env
);
1475 store_reg(s
, UCOP_REG_D
, tmp
);
1479 if ((insn
& 0xfbf83fe0) == 0x12f80120) {
1481 tmp
= load_reg(s
, UCOP_REG_M
);
1484 tcg_gen_not_i32(tmp
, tmp
);
1486 tcg_gen_clzi_i32(tmp
, tmp
, 32);
1487 store_reg(s
, UCOP_REG_D
, tmp
);
1495 /* load/store I_offset and R_offset */
1496 static void do_ldst_ir(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1498 unsigned int mmu_idx
;
1502 tmp2
= load_reg(s
, UCOP_REG_N
);
1503 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1507 gen_add_data_offset(s
, insn
, tmp2
);
1513 tmp
= gen_ld8u(tmp2
, mmu_idx
);
1515 tmp
= gen_ld32(tmp2
, mmu_idx
);
1519 tmp
= load_reg(s
, UCOP_REG_D
);
1521 gen_st8(tmp
, tmp2
, mmu_idx
);
1523 gen_st32(tmp
, tmp2
, mmu_idx
);
1527 gen_add_data_offset(s
, insn
, tmp2
);
1528 store_reg(s
, UCOP_REG_N
, tmp2
);
1529 } else if (UCOP_SET_W
) {
1530 store_reg(s
, UCOP_REG_N
, tmp2
);
1535 /* Complete the load. */
1536 if (UCOP_REG_D
== 31) {
1539 store_reg(s
, UCOP_REG_D
, tmp
);
1544 /* SWP instruction */
1545 static void do_swap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1547 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1552 if ((insn
& 0xff003fe0) != 0x40000120) {
1556 /* ??? This is not really atomic. However we know
1557 we never have multiple CPUs running in parallel,
1558 so it is good enough. */
1559 addr
= load_reg(s
, UCOP_REG_N
);
1560 tmp
= load_reg(s
, UCOP_REG_M
);
1562 tmp2
= gen_ld8u(addr
, IS_USER(s
));
1563 gen_st8(tmp
, addr
, IS_USER(s
));
1565 tmp2
= gen_ld32(addr
, IS_USER(s
));
1566 gen_st32(tmp
, addr
, IS_USER(s
));
1569 store_reg(s
, UCOP_REG_D
, tmp2
);
1572 /* load/store hw/sb */
1573 static void do_ldst_hwsb(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1575 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1579 if (UCOP_SH_OP
== 0) {
1580 do_swap(env
, s
, insn
);
1584 addr
= load_reg(s
, UCOP_REG_N
);
1586 gen_add_datah_offset(s
, insn
, addr
);
1589 if (UCOP_SET_L
) { /* load */
1590 switch (UCOP_SH_OP
) {
1592 tmp
= gen_ld16u(addr
, IS_USER(s
));
1595 tmp
= gen_ld8s(addr
, IS_USER(s
));
1597 default: /* see do_swap */
1599 tmp
= gen_ld16s(addr
, IS_USER(s
));
1602 } else { /* store */
1603 if (UCOP_SH_OP
!= 1) {
1606 tmp
= load_reg(s
, UCOP_REG_D
);
1607 gen_st16(tmp
, addr
, IS_USER(s
));
1609 /* Perform base writeback before the loaded value to
1610 ensure correct behavior with overlapping index registers. */
1612 gen_add_datah_offset(s
, insn
, addr
);
1613 store_reg(s
, UCOP_REG_N
, addr
);
1614 } else if (UCOP_SET_W
) {
1615 store_reg(s
, UCOP_REG_N
, addr
);
1620 /* Complete the load. */
1621 store_reg(s
, UCOP_REG_D
, tmp
);
1625 /* load/store multiple words */
1626 static void do_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1628 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1629 unsigned int val
, i
, mmu_idx
;
1630 int j
, n
, reg
, user
, loaded_base
;
1639 /* XXX: store correct base if write back */
1641 if (UCOP_SET_B
) { /* S bit in instruction table */
1643 ILLEGAL
; /* only usable in supervisor mode */
1645 if (UCOP_SET(18) == 0) { /* pc reg */
1650 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1651 addr
= load_reg(s
, UCOP_REG_N
);
1653 /* compute total size */
1657 for (i
= 0; i
< 6; i
++) {
1662 for (i
= 9; i
< 19; i
++) {
1667 /* XXX: test invalid n == 0 case ? */
1671 tcg_gen_addi_i32(addr
, addr
, 4);
1673 /* post increment */
1678 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1680 /* post decrement */
1682 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1688 reg
= UCOP_SET(6) ? 16 : 0;
1689 for (i
= 0; i
< 19; i
++, reg
++) {
1694 if (UCOP_SET_L
) { /* load */
1695 tmp
= gen_ld32(addr
, mmu_idx
);
1699 tmp2
= tcg_const_i32(reg
);
1700 gen_helper_set_user_reg(cpu_env
, tmp2
, tmp
);
1701 tcg_temp_free_i32(tmp2
);
1703 } else if (reg
== UCOP_REG_N
) {
1707 store_reg(s
, reg
, tmp
);
1709 } else { /* store */
1711 /* special case: r31 = PC + 4 */
1714 tcg_gen_movi_i32(tmp
, val
);
1717 tmp2
= tcg_const_i32(reg
);
1718 gen_helper_get_user_reg(tmp
, cpu_env
, tmp2
);
1719 tcg_temp_free_i32(tmp2
);
1721 tmp
= load_reg(s
, reg
);
1723 gen_st32(tmp
, addr
, mmu_idx
);
1726 /* no need to add after the last transfer */
1728 tcg_gen_addi_i32(addr
, addr
, 4);
1732 if (UCOP_SET_W
) { /* write back */
1737 /* post increment */
1738 tcg_gen_addi_i32(addr
, addr
, 4);
1744 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1747 /* post decrement */
1748 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1751 store_reg(s
, UCOP_REG_N
, addr
);
1756 store_reg(s
, UCOP_REG_N
, loaded_var
);
1758 if (UCOP_SET_B
&& !user
) {
1759 /* Restore ASR from BSR. */
1760 tmp
= load_cpu_field(bsr
);
1761 gen_set_asr(tmp
, 0xffffffff);
1763 s
->is_jmp
= DISAS_UPDATE
;
1767 /* branch (and link) */
1768 static void do_branch(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1770 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1775 if (UCOP_COND
== 0xf) {
1779 if (UCOP_COND
!= 0xe) {
1780 /* if not always execute, we generate a conditional jump to
1782 s
->condlabel
= gen_new_label();
1783 gen_test_cc(UCOP_COND
^ 1, s
->condlabel
);
1787 val
= (int32_t)s
->pc
;
1790 tcg_gen_movi_i32(tmp
, val
);
1791 store_reg(s
, 30, tmp
);
1793 offset
= (((int32_t)insn
<< 8) >> 8);
1794 val
+= (offset
<< 2); /* unicore is pc+4 */
1798 static void disas_uc32_insn(CPUUniCore32State
*env
, DisasContext
*s
)
1800 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
1803 insn
= cpu_ldl_code(env
, s
->pc
);
1806 /* UniCore instructions class:
1807 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1808 * AAA : see switch case
1809 * BBBB : opcodes or cond or PUBW
1814 switch (insn
>> 29) {
1816 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1817 do_mult(env
, s
, insn
);
1822 do_misc(env
, s
, insn
);
1826 if (((UCOP_OPCODES
>> 2) == 2) && !UCOP_SET_S
) {
1827 do_misc(env
, s
, insn
);
1830 do_datap(env
, s
, insn
);
1834 if (UCOP_SET(8) && UCOP_SET(5)) {
1835 do_ldst_hwsb(env
, s
, insn
);
1838 if (UCOP_SET(8) || UCOP_SET(5)) {
1842 do_ldst_ir(env
, s
, insn
);
1847 ILLEGAL
; /* extended instructions */
1849 do_ldst_m(env
, s
, insn
);
1852 do_branch(env
, s
, insn
);
1856 disas_coproc_insn(env
, s
, insn
);
1859 if (!UCOP_SET(28)) {
1860 disas_coproc_insn(env
, s
, insn
);
1863 if ((insn
& 0xff000000) == 0xff000000) { /* syscall */
1864 gen_set_pc_im(s
->pc
);
1865 s
->is_jmp
= DISAS_SYSCALL
;
1872 /* generate intermediate code for basic block 'tb'. */
1873 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
)
1875 CPUUniCore32State
*env
= cs
->env_ptr
;
1876 DisasContext dc1
, *dc
= &dc1
;
1877 target_ulong pc_start
;
1878 uint32_t page_start
;
1882 /* generate intermediate code */
1889 dc
->is_jmp
= DISAS_NEXT
;
1891 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1893 cpu_F0s
= tcg_temp_new_i32();
1894 cpu_F1s
= tcg_temp_new_i32();
1895 cpu_F0d
= tcg_temp_new_i64();
1896 cpu_F1d
= tcg_temp_new_i64();
1897 page_start
= pc_start
& TARGET_PAGE_MASK
;
1899 max_insns
= tb_cflags(tb
) & CF_COUNT_MASK
;
1900 if (max_insns
== 0) {
1901 max_insns
= CF_COUNT_MASK
;
1903 if (max_insns
> TCG_MAX_INSNS
) {
1904 max_insns
= TCG_MAX_INSNS
;
1907 #ifndef CONFIG_USER_ONLY
1908 if ((env
->uncached_asr
& ASR_M
) == ASR_MODE_USER
) {
1917 tcg_gen_insn_start(dc
->pc
);
1920 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
1921 gen_set_pc_im(dc
->pc
);
1922 gen_exception(EXCP_DEBUG
);
1923 dc
->is_jmp
= DISAS_JUMP
;
1924 /* The address covered by the breakpoint must be included in
1925 [tb->pc, tb->pc + tb->size) in order to for it to be
1926 properly cleared -- thus we increment the PC here so that
1927 the logic setting tb->size below does the right thing. */
1929 goto done_generating
;
1932 if (num_insns
== max_insns
&& (tb_cflags(tb
) & CF_LAST_IO
)) {
1936 disas_uc32_insn(env
, dc
);
1939 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
1943 if (dc
->condjmp
&& !dc
->is_jmp
) {
1944 gen_set_label(dc
->condlabel
);
1947 /* Translation stops when a conditional branch is encountered.
1948 * Otherwise the subsequent code could get translated several times.
1949 * Also stop translation when a page boundary is reached. This
1950 * ensures prefetch aborts occur at the right place. */
1951 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
1952 !cs
->singlestep_enabled
&&
1954 dc
->pc
- page_start
< TARGET_PAGE_SIZE
&&
1955 num_insns
< max_insns
);
1957 if (tb_cflags(tb
) & CF_LAST_IO
) {
1959 /* FIXME: This can theoretically happen with self-modifying
1961 cpu_abort(cs
, "IO on conditional branch instruction");
1966 /* At this stage dc->condjmp will only be set when the skipped
1967 instruction was a conditional branch or trap, and the PC has
1968 already been written. */
1969 if (unlikely(cs
->singlestep_enabled
)) {
1970 /* Make sure the pc is updated, and raise a debug exception. */
1972 if (dc
->is_jmp
== DISAS_SYSCALL
) {
1973 gen_exception(UC32_EXCP_PRIV
);
1975 gen_exception(EXCP_DEBUG
);
1977 gen_set_label(dc
->condlabel
);
1979 if (dc
->condjmp
|| !dc
->is_jmp
) {
1980 gen_set_pc_im(dc
->pc
);
1983 if (dc
->is_jmp
== DISAS_SYSCALL
&& !dc
->condjmp
) {
1984 gen_exception(UC32_EXCP_PRIV
);
1986 gen_exception(EXCP_DEBUG
);
1989 /* While branches must always occur at the end of an IT block,
1990 there are a few other things that can cause us to terminate
1991 the TB in the middel of an IT block:
1992 - Exception generating instructions (bkpt, swi, undefined).
1994 - Hardware watchpoints.
1995 Hardware breakpoints have already been handled and skip this code.
1997 switch (dc
->is_jmp
) {
1999 gen_goto_tb(dc
, 1, dc
->pc
);
2004 /* indicate that the hash table must be used to find the next TB */
2005 tcg_gen_exit_tb(NULL
, 0);
2008 /* nothing more to generate */
2011 gen_exception(UC32_EXCP_PRIV
);
2015 gen_set_label(dc
->condlabel
);
2016 gen_goto_tb(dc
, 1, dc
->pc
);
2022 gen_tb_end(tb
, num_insns
);
2025 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
2026 && qemu_log_in_addr_range(pc_start
)) {
2028 qemu_log("----------------\n");
2029 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2030 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
);
2035 tb
->size
= dc
->pc
- pc_start
;
2036 tb
->icount
= num_insns
;
2039 static const char *cpu_mode_names
[16] = {
2040 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2041 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2044 #undef UCF64_DUMP_STATE
2045 #ifdef UCF64_DUMP_STATE
2046 static void cpu_dump_state_ucf64(CPUUniCore32State
*env
, FILE *f
,
2047 fprintf_function cpu_fprintf
, int flags
)
2055 /* ??? This assumes float64 and double have the same layout.
2056 Oh well, it's only debug dumps. */
2062 for (i
= 0; i
< 16; i
++) {
2063 d
.d
= env
->ucf64
.regs
[i
];
2067 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g)",
2068 i
* 2, (int)s0
.i
, s0
.s
,
2069 i
* 2 + 1, (int)s1
.i
, s1
.s
);
2070 cpu_fprintf(f
, " d%02d=%" PRIx64
"(%8g)\n",
2071 i
, (uint64_t)d0
.f64
, d0
.d
);
2073 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->ucf64
.xregs
[UC32_UCF64_FPSCR
]);
2076 #define cpu_dump_state_ucf64(env, file, pr, flags) do { } while (0)
2079 void uc32_cpu_dump_state(CPUState
*cs
, FILE *f
,
2080 fprintf_function cpu_fprintf
, int flags
)
2082 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
2083 CPUUniCore32State
*env
= &cpu
->env
;
2087 for (i
= 0; i
< 32; i
++) {
2088 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
2090 cpu_fprintf(f
, "\n");
2092 cpu_fprintf(f
, " ");
2095 psr
= cpu_asr_read(env
);
2096 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %s\n",
2098 psr
& (1 << 31) ? 'N' : '-',
2099 psr
& (1 << 30) ? 'Z' : '-',
2100 psr
& (1 << 29) ? 'C' : '-',
2101 psr
& (1 << 28) ? 'V' : '-',
2102 cpu_mode_names
[psr
& 0xf]);
2104 if (flags
& CPU_DUMP_FPU
) {
2105 cpu_dump_state_ucf64(env
, f
, cpu_fprintf
, flags
);
2109 void restore_state_to_opc(CPUUniCore32State
*env
, TranslationBlock
*tb
,
2112 env
->regs
[31] = data
[0];