2 * UniCore32 translation
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or (at your option) any
9 * later version. See the COPYING file in the top-level directory.
18 #include "disas/disas.h"
26 /* internal defines */
27 typedef struct DisasContext
{
30 /* Nonzero if this instruction has been conditionally skipped. */
32 /* The label that will be jumped to when the instruction is skipped. */
34 struct TranslationBlock
*tb
;
35 int singlestep_enabled
;
36 #ifndef CONFIG_USER_ONLY
41 #ifndef CONFIG_USER_ONLY
42 #define IS_USER(s) (s->user)
47 /* These instructions trap after executing, so defer them until after the
48 conditional executions state has been updated. */
49 #define DISAS_SYSCALL 5
51 static TCGv_ptr cpu_env
;
52 static TCGv_i32 cpu_R
[32];
54 /* FIXME: These should be removed. */
55 static TCGv cpu_F0s
, cpu_F1s
;
56 static TCGv_i64 cpu_F0d
, cpu_F1d
;
58 #include "exec/gen-icount.h"
60 static const char *regnames
[] = {
61 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
62 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
63 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
64 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
66 /* initialize TCG globals. */
67 void uc32_translate_init(void)
71 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
73 for (i
= 0; i
< 32; i
++) {
74 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
75 offsetof(CPUUniCore32State
, regs
[i
]), regnames
[i
]);
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(env, \
183 "Illegal UniCore32 instruction %x at line %d!", \
186 #ifndef CONFIG_USER_ONLY
187 static void disas_cp0_insn(CPUUniCore32State
*env
, DisasContext
*s
,
190 TCGv tmp
, tmp2
, tmp3
;
191 if ((insn
& 0xfe000000) == 0xe0000000) {
194 tcg_gen_movi_i32(tmp2
, UCOP_REG_N
);
195 tcg_gen_movi_i32(tmp3
, UCOP_IMM10
);
198 gen_helper_cp0_get(tmp
, cpu_env
, tmp2
, tmp3
);
199 store_reg(s
, UCOP_REG_D
, tmp
);
201 tmp
= load_reg(s
, UCOP_REG_D
);
202 gen_helper_cp0_set(cpu_env
, tmp
, tmp2
, tmp3
);
212 static void disas_ocd_insn(CPUUniCore32State
*env
, DisasContext
*s
,
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
, int 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 TCGv_i64
gen_ld64(TCGv addr
, int index
)
582 TCGv_i64 tmp
= tcg_temp_new_i64();
583 tcg_gen_qemu_ld64(tmp
, addr
, index
);
587 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
589 tcg_gen_qemu_st8(val
, addr
, index
);
593 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
595 tcg_gen_qemu_st16(val
, addr
, index
);
599 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
601 tcg_gen_qemu_st32(val
, addr
, index
);
605 static inline void gen_st64(TCGv_i64 val
, TCGv addr
, int index
)
607 tcg_gen_qemu_st64(val
, addr
, index
);
608 tcg_temp_free_i64(val
);
611 static inline void gen_set_pc_im(uint32_t val
)
613 tcg_gen_movi_i32(cpu_R
[31], val
);
616 /* Force a TB lookup after an instruction that changes the CPU state. */
617 static inline void gen_lookup_tb(DisasContext
*s
)
619 tcg_gen_movi_i32(cpu_R
[31], s
->pc
& ~1);
620 s
->is_jmp
= DISAS_UPDATE
;
623 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
636 tcg_gen_addi_i32(var
, var
, val
);
640 offset
= load_reg(s
, UCOP_REG_M
);
641 gen_uc32_shift_im(offset
, UCOP_SH_OP
, UCOP_SH_IM
, 0);
643 tcg_gen_sub_i32(var
, var
, offset
);
645 tcg_gen_add_i32(var
, var
, offset
);
651 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
659 val
= (insn
& 0x1f) | ((insn
>> 4) & 0x3e0);
664 tcg_gen_addi_i32(var
, var
, val
);
668 offset
= load_reg(s
, UCOP_REG_M
);
670 tcg_gen_sub_i32(var
, var
, offset
);
672 tcg_gen_add_i32(var
, var
, offset
);
678 static inline long ucf64_reg_offset(int reg
)
681 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
682 + offsetof(CPU_DoubleU
, l
.upper
);
684 return offsetof(CPUUniCore32State
, ucf64
.regs
[reg
>> 1])
685 + offsetof(CPU_DoubleU
, l
.lower
);
689 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
690 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
692 /* UniCore-F64 single load/store I_offset */
693 static void do_ucf64_ldst_i(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
699 addr
= load_reg(s
, UCOP_REG_N
);
700 if (!UCOP_SET_P
&& !UCOP_SET_W
) {
705 offset
= UCOP_IMM10
<< 2;
710 tcg_gen_addi_i32(addr
, addr
, offset
);
714 if (UCOP_SET_L
) { /* load */
715 tmp
= gen_ld32(addr
, IS_USER(s
));
716 ucf64_gen_st32(tmp
, UCOP_REG_D
);
718 tmp
= ucf64_gen_ld32(UCOP_REG_D
);
719 gen_st32(tmp
, addr
, IS_USER(s
));
723 offset
= UCOP_IMM10
<< 2;
728 tcg_gen_addi_i32(addr
, addr
, offset
);
732 store_reg(s
, UCOP_REG_N
, addr
);
738 /* UniCore-F64 load/store multiple words */
739 static void do_ucf64_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
746 if (UCOP_REG_D
!= 0) {
749 if (UCOP_REG_N
== 31) {
752 if ((insn
<< 24) == 0) {
756 addr
= load_reg(s
, UCOP_REG_N
);
759 for (i
= 0; i
< 8; i
++) {
766 if (UCOP_SET_P
) { /* pre increment */
767 tcg_gen_addi_i32(addr
, addr
, 4);
768 } /* unnecessary to do anything when post increment */
770 if (UCOP_SET_P
) { /* pre decrement */
771 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
772 } else { /* post decrement */
774 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
779 freg
= ((insn
>> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
781 for (i
= 0, j
= 0; i
< 8; i
++, freg
++) {
786 if (UCOP_SET_L
) { /* load */
787 tmp
= gen_ld32(addr
, IS_USER(s
));
788 ucf64_gen_st32(tmp
, freg
);
790 tmp
= ucf64_gen_ld32(freg
);
791 gen_st32(tmp
, addr
, IS_USER(s
));
795 /* unnecessary to add after the last transfer */
797 tcg_gen_addi_i32(addr
, addr
, 4);
801 if (UCOP_SET_W
) { /* write back */
803 if (!UCOP_SET_P
) { /* post increment */
804 tcg_gen_addi_i32(addr
, addr
, 4);
805 } /* unnecessary to do anything when pre increment */
810 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
814 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
817 store_reg(s
, UCOP_REG_N
, addr
);
823 /* UniCore-F64 mrc/mcr */
824 static void do_ucf64_trans(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
828 if ((insn
& 0xfe0003ff) == 0xe2000000) {
829 /* control register */
830 if ((UCOP_REG_N
!= UC32_UCF64_FPSCR
) || (UCOP_REG_D
== 31)) {
836 gen_helper_ucf64_get_fpscr(tmp
, cpu_env
);
837 store_reg(s
, UCOP_REG_D
, tmp
);
840 tmp
= load_reg(s
, UCOP_REG_D
);
841 gen_helper_ucf64_set_fpscr(cpu_env
, tmp
);
847 if ((insn
& 0xfe0003ff) == 0xe0000000) {
848 /* general register */
849 if (UCOP_REG_D
== 31) {
852 if (UCOP_SET(24)) { /* MFF */
853 tmp
= ucf64_gen_ld32(UCOP_REG_N
);
854 store_reg(s
, UCOP_REG_D
, tmp
);
856 tmp
= load_reg(s
, UCOP_REG_D
);
857 ucf64_gen_st32(tmp
, UCOP_REG_N
);
861 if ((insn
& 0xfb000000) == 0xe9000000) {
863 if (UCOP_REG_D
!= 31) {
866 if (UCOP_UCF64_COND
& 0x8) {
871 tcg_gen_movi_i32(tmp
, UCOP_UCF64_COND
);
873 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
874 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
875 gen_helper_ucf64_cmpd(cpu_F0d
, cpu_F1d
, tmp
, cpu_env
);
877 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
878 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
879 gen_helper_ucf64_cmps(cpu_F0s
, cpu_F1s
, tmp
, cpu_env
);
887 /* UniCore-F64 convert instructions */
888 static void do_ucf64_fcvt(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
890 if (UCOP_UCF64_FMT
== 3) {
893 if (UCOP_REG_N
!= 0) {
896 switch (UCOP_UCF64_FUNC
) {
898 switch (UCOP_UCF64_FMT
) {
900 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
901 gen_helper_ucf64_df2sf(cpu_F0s
, cpu_F0d
, cpu_env
);
902 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
905 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
906 gen_helper_ucf64_si2sf(cpu_F0s
, cpu_F0s
, cpu_env
);
907 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
915 switch (UCOP_UCF64_FMT
) {
917 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
918 gen_helper_ucf64_sf2df(cpu_F0d
, cpu_F0s
, cpu_env
);
919 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
922 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
923 gen_helper_ucf64_si2df(cpu_F0d
, cpu_F0s
, cpu_env
);
924 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
932 switch (UCOP_UCF64_FMT
) {
934 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
935 gen_helper_ucf64_sf2si(cpu_F0s
, cpu_F0s
, cpu_env
);
936 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
939 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
940 gen_helper_ucf64_df2si(cpu_F0s
, cpu_F0d
, cpu_env
);
941 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
953 /* UniCore-F64 compare instructions */
954 static void do_ucf64_fcmp(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
959 if (UCOP_REG_D
!= 0) {
965 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
966 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
967 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
969 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
970 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
971 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
975 #define gen_helper_ucf64_movs(x, y) do { } while (0)
976 #define gen_helper_ucf64_movd(x, y) do { } while (0)
978 #define UCF64_OP1(name) do { \
979 if (UCOP_REG_N != 0) { \
982 switch (UCOP_UCF64_FMT) { \
984 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
985 ucf64_reg_offset(UCOP_REG_M)); \
986 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
987 tcg_gen_st_i32(cpu_F0s, cpu_env, \
988 ucf64_reg_offset(UCOP_REG_D)); \
991 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
992 ucf64_reg_offset(UCOP_REG_M)); \
993 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
994 tcg_gen_st_i64(cpu_F0d, cpu_env, \
995 ucf64_reg_offset(UCOP_REG_D)); \
1003 #define UCF64_OP2(name) do { \
1004 switch (UCOP_UCF64_FMT) { \
1006 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
1007 ucf64_reg_offset(UCOP_REG_N)); \
1008 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
1009 ucf64_reg_offset(UCOP_REG_M)); \
1010 gen_helper_ucf64_##name##s(cpu_F0s, \
1011 cpu_F0s, cpu_F1s, cpu_env); \
1012 tcg_gen_st_i32(cpu_F0s, cpu_env, \
1013 ucf64_reg_offset(UCOP_REG_D)); \
1016 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
1017 ucf64_reg_offset(UCOP_REG_N)); \
1018 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
1019 ucf64_reg_offset(UCOP_REG_M)); \
1020 gen_helper_ucf64_##name##d(cpu_F0d, \
1021 cpu_F0d, cpu_F1d, cpu_env); \
1022 tcg_gen_st_i64(cpu_F0d, cpu_env, \
1023 ucf64_reg_offset(UCOP_REG_D)); \
1031 /* UniCore-F64 data processing */
1032 static void do_ucf64_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1034 if (UCOP_UCF64_FMT
== 3) {
1037 switch (UCOP_UCF64_FUNC
) {
1064 /* Disassemble an F64 instruction */
1065 static void disas_ucf64_insn(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
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 void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
1097 TranslationBlock
*tb
;
1100 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1102 gen_set_pc_im(dest
);
1103 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
1105 gen_set_pc_im(dest
);
1110 static inline void gen_jmp(DisasContext
*s
, uint32_t dest
)
1112 if (unlikely(s
->singlestep_enabled
)) {
1113 /* An indirect jump so that we still trigger the debug exception. */
1116 gen_goto_tb(s
, 0, dest
);
1117 s
->is_jmp
= DISAS_TB_JUMP
;
1121 static inline void gen_mulxy(TCGv t0
, TCGv t1
, int x
, int y
)
1124 tcg_gen_sari_i32(t0
, t0
, 16);
1129 tcg_gen_sari_i32(t1
, t1
, 16);
1133 tcg_gen_mul_i32(t0
, t0
, t1
);
1136 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1137 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int bsr
, TCGv t0
)
1141 /* ??? This is also undefined in system mode. */
1146 tmp
= load_cpu_field(bsr
);
1147 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
1148 tcg_gen_andi_i32(t0
, t0
, mask
);
1149 tcg_gen_or_i32(tmp
, tmp
, t0
);
1150 store_cpu_field(tmp
, bsr
);
1152 gen_set_asr(t0
, mask
);
1159 /* Generate an old-style exception return. Marks pc as dead. */
1160 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
1163 store_reg(s
, 31, pc
);
1164 tmp
= load_cpu_field(bsr
);
1165 gen_set_asr(tmp
, 0xffffffff);
1167 s
->is_jmp
= DISAS_UPDATE
;
1170 static void disas_coproc_insn(CPUUniCore32State
*env
, DisasContext
*s
,
1173 switch (UCOP_CPNUM
) {
1174 #ifndef CONFIG_USER_ONLY
1176 disas_cp0_insn(env
, s
, insn
);
1179 disas_ocd_insn(env
, s
, insn
);
1183 disas_ucf64_insn(env
, s
, insn
);
1186 /* Unknown coprocessor. */
1187 cpu_abort(env
, "Unknown coprocessor!");
1191 /* data processing instructions */
1192 static void do_datap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1198 if (UCOP_OPCODES
== 0x0f || UCOP_OPCODES
== 0x0d) {
1199 if (UCOP_SET(23)) { /* CMOV instructions */
1200 if ((UCOP_CMOV_COND
== 0xe) || (UCOP_CMOV_COND
== 0xf)) {
1203 /* if not always execute, we generate a conditional jump to
1205 s
->condlabel
= gen_new_label();
1206 gen_test_cc(UCOP_CMOV_COND
^ 1, s
->condlabel
);
1211 logic_cc
= table_logic_cc
[UCOP_OPCODES
] & (UCOP_SET_S
>> 24);
1215 /* immediate operand */
1218 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1221 tcg_gen_movi_i32(tmp2
, val
);
1222 if (logic_cc
&& UCOP_SH_IM
) {
1223 gen_set_CF_bit31(tmp2
);
1227 tmp2
= load_reg(s
, UCOP_REG_M
);
1229 tmp
= load_reg(s
, UCOP_REG_S
);
1230 gen_uc32_shift_reg(tmp2
, UCOP_SH_OP
, tmp
, logic_cc
);
1232 gen_uc32_shift_im(tmp2
, UCOP_SH_OP
, UCOP_SH_IM
, logic_cc
);
1236 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1237 tmp
= load_reg(s
, UCOP_REG_N
);
1242 switch (UCOP_OPCODES
) {
1244 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1248 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1251 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1255 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1258 if (UCOP_SET_S
&& UCOP_REG_D
== 31) {
1259 /* SUBS r31, ... is used for exception return. */
1263 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1264 gen_exception_return(s
, tmp
);
1267 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1269 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
1271 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1276 gen_helper_sub_cc(tmp
, cpu_env
, tmp2
, tmp
);
1278 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
1280 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1284 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1286 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1288 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1292 gen_helper_adc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1294 gen_add_carry(tmp
, tmp
, tmp2
);
1296 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1300 gen_helper_sbc_cc(tmp
, cpu_env
, tmp
, tmp2
);
1302 gen_sub_carry(tmp
, tmp
, tmp2
);
1304 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1308 gen_helper_sbc_cc(tmp
, cpu_env
, tmp2
, tmp
);
1310 gen_sub_carry(tmp
, tmp2
, tmp
);
1312 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1316 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1323 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1330 gen_helper_sub_cc(tmp
, cpu_env
, tmp
, tmp2
);
1336 gen_helper_add_cc(tmp
, cpu_env
, tmp
, tmp2
);
1341 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1345 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1348 if (logic_cc
&& UCOP_REG_D
== 31) {
1349 /* MOVS r31, ... is used for exception return. */
1353 gen_exception_return(s
, tmp2
);
1358 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1362 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1366 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1370 tcg_gen_not_i32(tmp2
, tmp2
);
1374 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1377 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1383 static void do_mult(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1385 TCGv tmp
, tmp2
, tmp3
, tmp4
;
1389 tmp
= load_reg(s
, UCOP_REG_M
);
1390 tmp2
= load_reg(s
, UCOP_REG_N
);
1392 tcg_gen_muls2_i32(tmp
, tmp2
, tmp
, tmp2
);
1394 tcg_gen_mulu2_i32(tmp
, tmp2
, tmp
, tmp2
);
1396 if (UCOP_SET(25)) { /* mult accumulate */
1397 tmp3
= load_reg(s
, UCOP_REG_LO
);
1398 tmp4
= load_reg(s
, UCOP_REG_HI
);
1399 tcg_gen_add2_i32(tmp
, tmp2
, tmp
, tmp2
, tmp3
, tmp4
);
1403 store_reg(s
, UCOP_REG_LO
, tmp
);
1404 store_reg(s
, UCOP_REG_HI
, tmp2
);
1407 tmp
= load_reg(s
, UCOP_REG_M
);
1408 tmp2
= load_reg(s
, UCOP_REG_N
);
1409 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
1413 tmp2
= load_reg(s
, UCOP_REG_S
);
1414 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1420 store_reg(s
, UCOP_REG_D
, tmp
);
1424 /* miscellaneous instructions */
1425 static void do_misc(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1430 if ((insn
& 0xffffffe0) == 0x10ffc120) {
1431 /* Trivial implementation equivalent to bx. */
1432 tmp
= load_reg(s
, UCOP_REG_M
);
1437 if ((insn
& 0xfbffc000) == 0x30ffc000) {
1438 /* PSR = immediate */
1441 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1444 tcg_gen_movi_i32(tmp
, val
);
1445 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1451 if ((insn
& 0xfbffffe0) == 0x12ffc020) {
1452 /* PSR.flag = reg */
1453 tmp
= load_reg(s
, UCOP_REG_M
);
1454 if (gen_set_psr(s
, ASR_NZCV
, UCOP_SET_B
, tmp
)) {
1460 if ((insn
& 0xfbffffe0) == 0x10ffc020) {
1462 tmp
= load_reg(s
, UCOP_REG_M
);
1463 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1469 if ((insn
& 0xfbf83fff) == 0x10f80000) {
1475 tmp
= load_cpu_field(bsr
);
1478 gen_helper_asr_read(tmp
, cpu_env
);
1480 store_reg(s
, UCOP_REG_D
, tmp
);
1484 if ((insn
& 0xfbf83fe0) == 0x12f80120) {
1486 tmp
= load_reg(s
, UCOP_REG_M
);
1488 gen_helper_clo(tmp
, tmp
);
1490 gen_helper_clz(tmp
, tmp
);
1492 store_reg(s
, UCOP_REG_D
, tmp
);
1500 /* load/store I_offset and R_offset */
1501 static void do_ldst_ir(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1503 unsigned int mmu_idx
;
1507 tmp2
= load_reg(s
, UCOP_REG_N
);
1508 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1512 gen_add_data_offset(s
, insn
, tmp2
);
1518 tmp
= gen_ld8u(tmp2
, mmu_idx
);
1520 tmp
= gen_ld32(tmp2
, mmu_idx
);
1524 tmp
= load_reg(s
, UCOP_REG_D
);
1526 gen_st8(tmp
, tmp2
, mmu_idx
);
1528 gen_st32(tmp
, tmp2
, mmu_idx
);
1532 gen_add_data_offset(s
, insn
, tmp2
);
1533 store_reg(s
, UCOP_REG_N
, tmp2
);
1534 } else if (UCOP_SET_W
) {
1535 store_reg(s
, UCOP_REG_N
, tmp2
);
1540 /* Complete the load. */
1541 if (UCOP_REG_D
== 31) {
1544 store_reg(s
, UCOP_REG_D
, tmp
);
1549 /* SWP instruction */
1550 static void do_swap(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1556 if ((insn
& 0xff003fe0) != 0x40000120) {
1560 /* ??? This is not really atomic. However we know
1561 we never have multiple CPUs running in parallel,
1562 so it is good enough. */
1563 addr
= load_reg(s
, UCOP_REG_N
);
1564 tmp
= load_reg(s
, UCOP_REG_M
);
1566 tmp2
= gen_ld8u(addr
, IS_USER(s
));
1567 gen_st8(tmp
, addr
, IS_USER(s
));
1569 tmp2
= gen_ld32(addr
, IS_USER(s
));
1570 gen_st32(tmp
, addr
, IS_USER(s
));
1573 store_reg(s
, UCOP_REG_D
, tmp2
);
1576 /* load/store hw/sb */
1577 static void do_ldst_hwsb(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1582 if (UCOP_SH_OP
== 0) {
1583 do_swap(env
, s
, insn
);
1587 addr
= load_reg(s
, UCOP_REG_N
);
1589 gen_add_datah_offset(s
, insn
, addr
);
1592 if (UCOP_SET_L
) { /* load */
1593 switch (UCOP_SH_OP
) {
1595 tmp
= gen_ld16u(addr
, IS_USER(s
));
1598 tmp
= gen_ld8s(addr
, IS_USER(s
));
1600 default: /* see do_swap */
1602 tmp
= gen_ld16s(addr
, IS_USER(s
));
1605 } else { /* store */
1606 if (UCOP_SH_OP
!= 1) {
1609 tmp
= load_reg(s
, UCOP_REG_D
);
1610 gen_st16(tmp
, addr
, IS_USER(s
));
1612 /* Perform base writeback before the loaded value to
1613 ensure correct behavior with overlapping index registers. */
1615 gen_add_datah_offset(s
, insn
, addr
);
1616 store_reg(s
, UCOP_REG_N
, addr
);
1617 } else if (UCOP_SET_W
) {
1618 store_reg(s
, UCOP_REG_N
, addr
);
1623 /* Complete the load. */
1624 store_reg(s
, UCOP_REG_D
, tmp
);
1628 /* load/store multiple words */
1629 static void do_ldst_m(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1631 unsigned int val
, i
, mmu_idx
;
1632 int j
, n
, reg
, user
, loaded_base
;
1641 /* XXX: store correct base if write back */
1643 if (UCOP_SET_B
) { /* S bit in instruction table */
1645 ILLEGAL
; /* only usable in supervisor mode */
1647 if (UCOP_SET(18) == 0) { /* pc reg */
1652 mmu_idx
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1653 addr
= load_reg(s
, UCOP_REG_N
);
1655 /* compute total size */
1657 TCGV_UNUSED(loaded_var
);
1659 for (i
= 0; i
< 6; i
++) {
1664 for (i
= 9; i
< 19; i
++) {
1669 /* XXX: test invalid n == 0 case ? */
1673 tcg_gen_addi_i32(addr
, addr
, 4);
1675 /* post increment */
1680 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1682 /* post decrement */
1684 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1690 reg
= UCOP_SET(6) ? 16 : 0;
1691 for (i
= 0; i
< 19; i
++, reg
++) {
1696 if (UCOP_SET_L
) { /* load */
1697 tmp
= gen_ld32(addr
, mmu_idx
);
1701 tmp2
= tcg_const_i32(reg
);
1702 gen_helper_set_user_reg(cpu_env
, tmp2
, tmp
);
1703 tcg_temp_free_i32(tmp2
);
1705 } else if (reg
== UCOP_REG_N
) {
1709 store_reg(s
, reg
, tmp
);
1711 } else { /* store */
1713 /* special case: r31 = PC + 4 */
1716 tcg_gen_movi_i32(tmp
, val
);
1719 tmp2
= tcg_const_i32(reg
);
1720 gen_helper_get_user_reg(tmp
, cpu_env
, tmp2
);
1721 tcg_temp_free_i32(tmp2
);
1723 tmp
= load_reg(s
, reg
);
1725 gen_st32(tmp
, addr
, mmu_idx
);
1728 /* no need to add after the last transfer */
1730 tcg_gen_addi_i32(addr
, addr
, 4);
1734 if (UCOP_SET_W
) { /* write back */
1739 /* post increment */
1740 tcg_gen_addi_i32(addr
, addr
, 4);
1746 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1749 /* post decrement */
1750 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1753 store_reg(s
, UCOP_REG_N
, addr
);
1758 store_reg(s
, UCOP_REG_N
, loaded_var
);
1760 if (UCOP_SET_B
&& !user
) {
1761 /* Restore ASR from BSR. */
1762 tmp
= load_cpu_field(bsr
);
1763 gen_set_asr(tmp
, 0xffffffff);
1765 s
->is_jmp
= DISAS_UPDATE
;
1769 /* branch (and link) */
1770 static void do_branch(CPUUniCore32State
*env
, DisasContext
*s
, uint32_t insn
)
1776 if (UCOP_COND
== 0xf) {
1780 if (UCOP_COND
!= 0xe) {
1781 /* if not always execute, we generate a conditional jump to
1783 s
->condlabel
= gen_new_label();
1784 gen_test_cc(UCOP_COND
^ 1, s
->condlabel
);
1788 val
= (int32_t)s
->pc
;
1791 tcg_gen_movi_i32(tmp
, val
);
1792 store_reg(s
, 30, tmp
);
1794 offset
= (((int32_t)insn
<< 8) >> 8);
1795 val
+= (offset
<< 2); /* unicore is pc+4 */
1799 static void disas_uc32_insn(CPUUniCore32State
*env
, DisasContext
*s
)
1803 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
1804 tcg_gen_debug_insn_start(s
->pc
);
1807 insn
= cpu_ldl_code(env
, s
->pc
);
1810 /* UniCore instructions class:
1811 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1812 * AAA : see switch case
1813 * BBBB : opcodes or cond or PUBW
1818 switch (insn
>> 29) {
1820 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1821 do_mult(env
, s
, insn
);
1826 do_misc(env
, s
, insn
);
1830 if (((UCOP_OPCODES
>> 2) == 2) && !UCOP_SET_S
) {
1831 do_misc(env
, s
, insn
);
1834 do_datap(env
, s
, insn
);
1838 if (UCOP_SET(8) && UCOP_SET(5)) {
1839 do_ldst_hwsb(env
, s
, insn
);
1842 if (UCOP_SET(8) || UCOP_SET(5)) {
1846 do_ldst_ir(env
, s
, insn
);
1851 ILLEGAL
; /* extended instructions */
1853 do_ldst_m(env
, s
, insn
);
1856 do_branch(env
, s
, insn
);
1860 disas_coproc_insn(env
, s
, insn
);
1863 if (!UCOP_SET(28)) {
1864 disas_coproc_insn(env
, s
, insn
);
1867 if ((insn
& 0xff000000) == 0xff000000) { /* syscall */
1868 gen_set_pc_im(s
->pc
);
1869 s
->is_jmp
= DISAS_SYSCALL
;
1876 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
1877 basic block 'tb'. If search_pc is TRUE, also generate PC
1878 information for each intermediate instruction. */
1879 static inline void gen_intermediate_code_internal(UniCore32CPU
*cpu
,
1880 TranslationBlock
*tb
, bool search_pc
)
1882 CPUState
*cs
= CPU(cpu
);
1883 CPUUniCore32State
*env
= &cpu
->env
;
1884 DisasContext dc1
, *dc
= &dc1
;
1886 uint16_t *gen_opc_end
;
1888 target_ulong pc_start
;
1889 uint32_t next_page_start
;
1893 /* generate intermediate code */
1900 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
1902 dc
->is_jmp
= DISAS_NEXT
;
1904 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1906 cpu_F0s
= tcg_temp_new_i32();
1907 cpu_F1s
= tcg_temp_new_i32();
1908 cpu_F0d
= tcg_temp_new_i64();
1909 cpu_F1d
= tcg_temp_new_i64();
1910 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1913 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1914 if (max_insns
== 0) {
1915 max_insns
= CF_COUNT_MASK
;
1918 #ifndef CONFIG_USER_ONLY
1919 if ((env
->uncached_asr
& ASR_M
) == ASR_MODE_USER
) {
1928 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
1929 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
1930 if (bp
->pc
== dc
->pc
) {
1931 gen_set_pc_im(dc
->pc
);
1932 gen_exception(EXCP_DEBUG
);
1933 dc
->is_jmp
= DISAS_JUMP
;
1934 /* Advance PC so that clearing the breakpoint will
1935 invalidate this TB. */
1936 dc
->pc
+= 2; /* FIXME */
1937 goto done_generating
;
1942 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1946 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
1949 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
1950 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
1951 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
1954 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1958 disas_uc32_insn(env
, dc
);
1961 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
1965 if (dc
->condjmp
&& !dc
->is_jmp
) {
1966 gen_set_label(dc
->condlabel
);
1969 /* Translation stops when a conditional branch is encountered.
1970 * Otherwise the subsequent code could get translated several times.
1971 * Also stop translation when a page boundary is reached. This
1972 * ensures prefetch aborts occur at the right place. */
1974 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
1975 !cs
->singlestep_enabled
&&
1977 dc
->pc
< next_page_start
&&
1978 num_insns
< max_insns
);
1980 if (tb
->cflags
& CF_LAST_IO
) {
1982 /* FIXME: This can theoretically happen with self-modifying
1984 cpu_abort(env
, "IO on conditional branch instruction");
1989 /* At this stage dc->condjmp will only be set when the skipped
1990 instruction was a conditional branch or trap, and the PC has
1991 already been written. */
1992 if (unlikely(cs
->singlestep_enabled
)) {
1993 /* Make sure the pc is updated, and raise a debug exception. */
1995 if (dc
->is_jmp
== DISAS_SYSCALL
) {
1996 gen_exception(UC32_EXCP_PRIV
);
1998 gen_exception(EXCP_DEBUG
);
2000 gen_set_label(dc
->condlabel
);
2002 if (dc
->condjmp
|| !dc
->is_jmp
) {
2003 gen_set_pc_im(dc
->pc
);
2006 if (dc
->is_jmp
== DISAS_SYSCALL
&& !dc
->condjmp
) {
2007 gen_exception(UC32_EXCP_PRIV
);
2009 gen_exception(EXCP_DEBUG
);
2012 /* While branches must always occur at the end of an IT block,
2013 there are a few other things that can cause us to terminate
2014 the TB in the middel of an IT block:
2015 - Exception generating instructions (bkpt, swi, undefined).
2017 - Hardware watchpoints.
2018 Hardware breakpoints have already been handled and skip this code.
2020 switch (dc
->is_jmp
) {
2022 gen_goto_tb(dc
, 1, dc
->pc
);
2027 /* indicate that the hash table must be used to find the next TB */
2031 /* nothing more to generate */
2034 gen_exception(UC32_EXCP_PRIV
);
2038 gen_set_label(dc
->condlabel
);
2039 gen_goto_tb(dc
, 1, dc
->pc
);
2045 gen_tb_end(tb
, num_insns
);
2046 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
2049 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2050 qemu_log("----------------\n");
2051 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2052 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
, 0);
2057 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2060 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2063 tb
->size
= dc
->pc
- pc_start
;
2064 tb
->icount
= num_insns
;
2068 void gen_intermediate_code(CPUUniCore32State
*env
, TranslationBlock
*tb
)
2070 gen_intermediate_code_internal(uc32_env_get_cpu(env
), tb
, false);
2073 void gen_intermediate_code_pc(CPUUniCore32State
*env
, TranslationBlock
*tb
)
2075 gen_intermediate_code_internal(uc32_env_get_cpu(env
), tb
, true);
2078 static const char *cpu_mode_names
[16] = {
2079 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2080 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2083 #undef UCF64_DUMP_STATE
2084 #ifdef UCF64_DUMP_STATE
2085 static void cpu_dump_state_ucf64(CPUUniCore32State
*env
, FILE *f
,
2086 fprintf_function cpu_fprintf
, int flags
)
2094 /* ??? This assumes float64 and double have the same layout.
2095 Oh well, it's only debug dumps. */
2101 for (i
= 0; i
< 16; i
++) {
2102 d
.d
= env
->ucf64
.regs
[i
];
2106 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g)",
2107 i
* 2, (int)s0
.i
, s0
.s
,
2108 i
* 2 + 1, (int)s1
.i
, s1
.s
);
2109 cpu_fprintf(f
, " d%02d=%" PRIx64
"(%8g)\n",
2110 i
, (uint64_t)d0
.f64
, d0
.d
);
2112 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->ucf64
.xregs
[UC32_UCF64_FPSCR
]);
2115 #define cpu_dump_state_ucf64(env, file, pr, flags) do { } while (0)
2118 void uc32_cpu_dump_state(CPUState
*cs
, FILE *f
,
2119 fprintf_function cpu_fprintf
, int flags
)
2121 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
2122 CPUUniCore32State
*env
= &cpu
->env
;
2126 for (i
= 0; i
< 32; i
++) {
2127 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
2129 cpu_fprintf(f
, "\n");
2131 cpu_fprintf(f
, " ");
2134 psr
= cpu_asr_read(env
);
2135 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %s\n",
2137 psr
& (1 << 31) ? 'N' : '-',
2138 psr
& (1 << 30) ? 'Z' : '-',
2139 psr
& (1 << 29) ? 'C' : '-',
2140 psr
& (1 << 28) ? 'V' : '-',
2141 cpu_mode_names
[psr
& 0xf]);
2143 cpu_dump_state_ucf64(env
, f
, cpu_fprintf
, flags
);
2146 void restore_state_to_opc(CPUUniCore32State
*env
, TranslationBlock
*tb
, int pc_pos
)
2148 env
->regs
[31] = tcg_ctx
.gen_opc_pc
[pc_pos
];