2 * UniCore32 translation
4 * Copyright (C) 2010-2011 GUAN Xue-tao
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.
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
;
40 /* These instructions trap after executing, so defer them until after the
41 conditional executions state has been updated. */
42 #define DISAS_SYSCALL 5
44 static TCGv_ptr cpu_env
;
45 static TCGv_i32 cpu_R
[32];
47 /* FIXME: These should be removed. */
48 static TCGv cpu_F0s
, cpu_F1s
;
49 static TCGv_i64 cpu_F0d
, cpu_F1d
;
51 #include "gen-icount.h"
53 static const char *regnames
[] = {
54 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
55 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
56 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
57 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
59 /* initialize TCG globals. */
60 void uc32_translate_init(void)
64 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
66 for (i
= 0; i
< 32; i
++) {
67 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
68 offsetof(CPUState
, regs
[i
]), regnames
[i
]);
77 /* Allocate a temporary variable. */
78 static TCGv_i32
new_tmp(void)
81 return tcg_temp_new_i32();
84 /* Release a temporary variable. */
85 static void dead_tmp(TCGv tmp
)
91 static inline TCGv
load_cpu_offset(int offset
)
94 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
98 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUState, name))
100 static inline void store_cpu_offset(TCGv var
, int offset
)
102 tcg_gen_st_i32(var
, cpu_env
, offset
);
106 #define store_cpu_field(var, name) \
107 store_cpu_offset(var, offsetof(CPUState, name))
109 /* Set a variable to the value of a CPU register. */
110 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
114 /* normaly, since we updated PC */
116 tcg_gen_movi_i32(var
, addr
);
118 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
122 /* Create a new temporary and set it to the value of a CPU register. */
123 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
125 TCGv tmp
= new_tmp();
126 load_reg_var(s
, tmp
, reg
);
130 /* Set a CPU register. The source must be a temporary and will be
132 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
135 tcg_gen_andi_i32(var
, var
, ~3);
136 s
->is_jmp
= DISAS_JUMP
;
138 tcg_gen_mov_i32(cpu_R
[reg
], var
);
142 /* Value extensions. */
143 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
144 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
145 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
146 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
148 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
149 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
150 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
151 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
152 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
153 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
154 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
155 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
156 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
157 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
158 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
159 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
160 #define UCOP_COND (((insn) >> 25) & 0x0f)
161 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
162 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
163 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
164 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
165 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
167 #define UCOP_SET(i) ((insn) & (1 << (i)))
168 #define UCOP_SET_P UCOP_SET(28)
169 #define UCOP_SET_U UCOP_SET(27)
170 #define UCOP_SET_B UCOP_SET(26)
171 #define UCOP_SET_W UCOP_SET(25)
172 #define UCOP_SET_L UCOP_SET(24)
173 #define UCOP_SET_S UCOP_SET(24)
175 #define ILLEGAL cpu_abort(env, \
176 "Illegal UniCore32 instruction %x at line %d!", \
179 static inline void gen_set_asr(TCGv var
, uint32_t mask
)
181 TCGv tmp_mask
= tcg_const_i32(mask
);
182 gen_helper_asr_write(var
, tmp_mask
);
183 tcg_temp_free_i32(tmp_mask
);
185 /* Set NZCV flags from the high 4 bits of var. */
186 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
188 static void gen_exception(int excp
)
190 TCGv tmp
= new_tmp();
191 tcg_gen_movi_i32(tmp
, excp
);
192 gen_helper_exception(tmp
);
196 /* FIXME: Most targets have native widening multiplication.
197 It would be good to use that instead of a full wide multiply. */
198 /* 32x32->64 multiply. Marks inputs as dead. */
199 static TCGv_i64
gen_mulu_i64_i32(TCGv a
, TCGv b
)
201 TCGv_i64 tmp1
= tcg_temp_new_i64();
202 TCGv_i64 tmp2
= tcg_temp_new_i64();
204 tcg_gen_extu_i32_i64(tmp1
, a
);
206 tcg_gen_extu_i32_i64(tmp2
, b
);
208 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
209 tcg_temp_free_i64(tmp2
);
213 static TCGv_i64
gen_muls_i64_i32(TCGv a
, TCGv b
)
215 TCGv_i64 tmp1
= tcg_temp_new_i64();
216 TCGv_i64 tmp2
= tcg_temp_new_i64();
218 tcg_gen_ext_i32_i64(tmp1
, a
);
220 tcg_gen_ext_i32_i64(tmp2
, b
);
222 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
223 tcg_temp_free_i64(tmp2
);
227 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, CF))
229 /* Set CF to the top bit of var. */
230 static void gen_set_CF_bit31(TCGv var
)
232 TCGv tmp
= new_tmp();
233 tcg_gen_shri_i32(tmp
, var
, 31);
238 /* Set N and Z flags from var. */
239 static inline void gen_logic_CC(TCGv var
)
241 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, NF
));
242 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, ZF
));
245 /* dest = T0 + T1 + CF. */
246 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
249 tcg_gen_add_i32(dest
, t0
, t1
);
250 tmp
= load_cpu_field(CF
);
251 tcg_gen_add_i32(dest
, dest
, tmp
);
255 /* dest = T0 - T1 + CF - 1. */
256 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
259 tcg_gen_sub_i32(dest
, t0
, t1
);
260 tmp
= load_cpu_field(CF
);
261 tcg_gen_add_i32(dest
, dest
, tmp
);
262 tcg_gen_subi_i32(dest
, dest
, 1);
266 static void shifter_out_im(TCGv var
, int shift
)
268 TCGv tmp
= new_tmp();
270 tcg_gen_andi_i32(tmp
, var
, 1);
272 tcg_gen_shri_i32(tmp
, var
, shift
);
274 tcg_gen_andi_i32(tmp
, tmp
, 1);
281 /* Shift by immediate. Includes special handling for shift == 0. */
282 static inline void gen_uc32_shift_im(TCGv var
, int shiftop
, int shift
,
289 shifter_out_im(var
, 32 - shift
);
291 tcg_gen_shli_i32(var
, var
, shift
);
297 tcg_gen_shri_i32(var
, var
, 31);
300 tcg_gen_movi_i32(var
, 0);
303 shifter_out_im(var
, shift
- 1);
305 tcg_gen_shri_i32(var
, var
, shift
);
313 shifter_out_im(var
, shift
- 1);
318 tcg_gen_sari_i32(var
, var
, shift
);
320 case 3: /* ROR/RRX */
323 shifter_out_im(var
, shift
- 1);
325 tcg_gen_rotri_i32(var
, var
, shift
); break;
327 TCGv tmp
= load_cpu_field(CF
);
329 shifter_out_im(var
, 0);
331 tcg_gen_shri_i32(var
, var
, 1);
332 tcg_gen_shli_i32(tmp
, tmp
, 31);
333 tcg_gen_or_i32(var
, var
, tmp
);
339 static inline void gen_uc32_shift_reg(TCGv var
, int shiftop
,
340 TCGv shift
, int flags
)
345 gen_helper_shl_cc(var
, var
, shift
);
348 gen_helper_shr_cc(var
, var
, shift
);
351 gen_helper_sar_cc(var
, var
, shift
);
354 gen_helper_ror_cc(var
, var
, shift
);
360 gen_helper_shl(var
, var
, shift
);
363 gen_helper_shr(var
, var
, shift
);
366 gen_helper_sar(var
, var
, shift
);
369 tcg_gen_andi_i32(shift
, shift
, 0x1f);
370 tcg_gen_rotr_i32(var
, var
, shift
);
377 static void gen_test_cc(int cc
, int label
)
385 tmp
= load_cpu_field(ZF
);
386 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
389 tmp
= load_cpu_field(ZF
);
390 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
393 tmp
= load_cpu_field(CF
);
394 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
397 tmp
= load_cpu_field(CF
);
398 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
401 tmp
= load_cpu_field(NF
);
402 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
405 tmp
= load_cpu_field(NF
);
406 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
409 tmp
= load_cpu_field(VF
);
410 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
413 tmp
= load_cpu_field(VF
);
414 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
416 case 8: /* hi: C && !Z */
417 inv
= gen_new_label();
418 tmp
= load_cpu_field(CF
);
419 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
421 tmp
= load_cpu_field(ZF
);
422 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
425 case 9: /* ls: !C || Z */
426 tmp
= load_cpu_field(CF
);
427 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
429 tmp
= load_cpu_field(ZF
);
430 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
432 case 10: /* ge: N == V -> N ^ V == 0 */
433 tmp
= load_cpu_field(VF
);
434 tmp2
= load_cpu_field(NF
);
435 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
437 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
439 case 11: /* lt: N != V -> N ^ V != 0 */
440 tmp
= load_cpu_field(VF
);
441 tmp2
= load_cpu_field(NF
);
442 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
444 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
446 case 12: /* gt: !Z && N == V */
447 inv
= gen_new_label();
448 tmp
= load_cpu_field(ZF
);
449 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
451 tmp
= load_cpu_field(VF
);
452 tmp2
= load_cpu_field(NF
);
453 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
455 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
458 case 13: /* le: Z || N != V */
459 tmp
= load_cpu_field(ZF
);
460 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
462 tmp
= load_cpu_field(VF
);
463 tmp2
= load_cpu_field(NF
);
464 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
466 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
469 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
475 static const uint8_t table_logic_cc
[16] = {
476 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
477 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
478 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
479 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
482 /* Set PC state from an immediate address. */
483 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
485 s
->is_jmp
= DISAS_UPDATE
;
486 tcg_gen_movi_i32(cpu_R
[31], addr
& ~3);
489 /* Set PC state from var. var is marked as dead. */
490 static inline void gen_bx(DisasContext
*s
, TCGv var
)
492 s
->is_jmp
= DISAS_UPDATE
;
493 tcg_gen_andi_i32(cpu_R
[31], var
, ~3);
497 static inline void store_reg_bx(DisasContext
*s
, int reg
, TCGv var
)
499 store_reg(s
, reg
, var
);
502 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
504 TCGv tmp
= new_tmp();
505 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
509 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
511 TCGv tmp
= new_tmp();
512 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
516 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
518 TCGv tmp
= new_tmp();
519 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
523 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
525 TCGv tmp
= new_tmp();
526 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
530 static inline TCGv
gen_ld32(TCGv addr
, int index
)
532 TCGv tmp
= new_tmp();
533 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
537 static inline TCGv_i64
gen_ld64(TCGv addr
, int index
)
539 TCGv_i64 tmp
= tcg_temp_new_i64();
540 tcg_gen_qemu_ld64(tmp
, addr
, index
);
544 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
546 tcg_gen_qemu_st8(val
, addr
, index
);
550 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
552 tcg_gen_qemu_st16(val
, addr
, index
);
556 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
558 tcg_gen_qemu_st32(val
, addr
, index
);
562 static inline void gen_st64(TCGv_i64 val
, TCGv addr
, int index
)
564 tcg_gen_qemu_st64(val
, addr
, index
);
565 tcg_temp_free_i64(val
);
568 static inline void gen_set_pc_im(uint32_t val
)
570 tcg_gen_movi_i32(cpu_R
[31], val
);
573 /* Force a TB lookup after an instruction that changes the CPU state. */
574 static inline void gen_lookup_tb(DisasContext
*s
)
576 tcg_gen_movi_i32(cpu_R
[31], s
->pc
& ~1);
577 s
->is_jmp
= DISAS_UPDATE
;
580 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
593 tcg_gen_addi_i32(var
, var
, val
);
597 offset
= load_reg(s
, UCOP_REG_M
);
598 gen_uc32_shift_im(offset
, UCOP_SH_OP
, UCOP_SH_IM
, 0);
600 tcg_gen_sub_i32(var
, var
, offset
);
602 tcg_gen_add_i32(var
, var
, offset
);
608 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
616 val
= (insn
& 0x1f) | ((insn
>> 4) & 0x3e0);
621 tcg_gen_addi_i32(var
, var
, val
);
625 offset
= load_reg(s
, UCOP_REG_M
);
627 tcg_gen_sub_i32(var
, var
, offset
);
629 tcg_gen_add_i32(var
, var
, offset
);
635 static inline long ucf64_reg_offset(int reg
)
638 return offsetof(CPUState
, ucf64
.regs
[reg
>> 1])
639 + offsetof(CPU_DoubleU
, l
.upper
);
641 return offsetof(CPUState
, ucf64
.regs
[reg
>> 1])
642 + offsetof(CPU_DoubleU
, l
.lower
);
646 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
647 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
649 /* UniCore-F64 single load/store I_offset */
650 static void do_ucf64_ldst_i(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
656 addr
= load_reg(s
, UCOP_REG_N
);
657 if (!UCOP_SET_P
&& !UCOP_SET_W
) {
662 offset
= UCOP_IMM10
<< 2;
667 tcg_gen_addi_i32(addr
, addr
, offset
);
671 if (UCOP_SET_L
) { /* load */
672 tmp
= gen_ld32(addr
, IS_USER(s
));
673 ucf64_gen_st32(tmp
, UCOP_REG_D
);
675 tmp
= ucf64_gen_ld32(UCOP_REG_D
);
676 gen_st32(tmp
, addr
, IS_USER(s
));
680 offset
= UCOP_IMM10
<< 2;
685 tcg_gen_addi_i32(addr
, addr
, offset
);
689 store_reg(s
, UCOP_REG_N
, addr
);
695 /* UniCore-F64 load/store multiple words */
696 static void do_ucf64_ldst_m(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
703 if (UCOP_REG_D
!= 0) {
706 if (UCOP_REG_N
== 31) {
709 if ((insn
<< 24) == 0) {
713 addr
= load_reg(s
, UCOP_REG_N
);
716 for (i
= 0; i
< 8; i
++) {
723 if (UCOP_SET_P
) { /* pre increment */
724 tcg_gen_addi_i32(addr
, addr
, 4);
725 } /* unnecessary to do anything when post increment */
727 if (UCOP_SET_P
) { /* pre decrement */
728 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
729 } else { /* post decrement */
731 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
736 freg
= ((insn
>> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
738 for (i
= 0, j
= 0; i
< 8; i
++, freg
++) {
743 if (UCOP_SET_L
) { /* load */
744 tmp
= gen_ld32(addr
, IS_USER(s
));
745 ucf64_gen_st32(tmp
, freg
);
747 tmp
= ucf64_gen_ld32(freg
);
748 gen_st32(tmp
, addr
, IS_USER(s
));
752 /* unnecessary to add after the last transfer */
754 tcg_gen_addi_i32(addr
, addr
, 4);
758 if (UCOP_SET_W
) { /* write back */
760 if (!UCOP_SET_P
) { /* post increment */
761 tcg_gen_addi_i32(addr
, addr
, 4);
762 } /* unnecessary to do anything when pre increment */
767 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
771 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
774 store_reg(s
, UCOP_REG_N
, addr
);
780 /* UniCore-F64 mrc/mcr */
781 static void do_ucf64_trans(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
785 if ((insn
& 0xfe0003ff) == 0xe2000000) {
786 /* control register */
787 if ((UCOP_REG_N
!= UC32_UCF64_FPSCR
) || (UCOP_REG_D
== 31)) {
793 gen_helper_ucf64_get_fpscr(tmp
, cpu_env
);
794 store_reg(s
, UCOP_REG_D
, tmp
);
797 tmp
= load_reg(s
, UCOP_REG_D
);
798 gen_helper_ucf64_set_fpscr(cpu_env
, tmp
);
804 if ((insn
& 0xfe0003ff) == 0xe0000000) {
805 /* general register */
806 if (UCOP_REG_D
== 31) {
809 if (UCOP_SET(24)) { /* MFF */
810 tmp
= ucf64_gen_ld32(UCOP_REG_N
);
811 store_reg(s
, UCOP_REG_D
, tmp
);
813 tmp
= load_reg(s
, UCOP_REG_D
);
814 ucf64_gen_st32(tmp
, UCOP_REG_N
);
818 if ((insn
& 0xfb000000) == 0xe9000000) {
820 if (UCOP_REG_D
!= 31) {
823 if (UCOP_UCF64_COND
& 0x8) {
828 tcg_gen_movi_i32(tmp
, UCOP_UCF64_COND
);
830 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
831 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
832 gen_helper_ucf64_cmpd(cpu_F0d
, cpu_F1d
, tmp
, cpu_env
);
834 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
835 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
836 gen_helper_ucf64_cmps(cpu_F0s
, cpu_F1s
, tmp
, cpu_env
);
844 /* UniCore-F64 convert instructions */
845 static void do_ucf64_fcvt(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
847 if (UCOP_UCF64_FMT
== 3) {
850 if (UCOP_REG_N
!= 0) {
853 switch (UCOP_UCF64_FUNC
) {
855 switch (UCOP_UCF64_FMT
) {
857 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
858 gen_helper_ucf64_df2sf(cpu_F0s
, cpu_F0d
, cpu_env
);
859 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
862 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
863 gen_helper_ucf64_si2sf(cpu_F0s
, cpu_F0s
, cpu_env
);
864 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
872 switch (UCOP_UCF64_FMT
) {
874 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
875 gen_helper_ucf64_sf2df(cpu_F0d
, cpu_F0s
, cpu_env
);
876 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
879 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
880 gen_helper_ucf64_si2df(cpu_F0d
, cpu_F0s
, cpu_env
);
881 tcg_gen_st_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
889 switch (UCOP_UCF64_FMT
) {
891 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
892 gen_helper_ucf64_sf2si(cpu_F0s
, cpu_F0s
, cpu_env
);
893 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
896 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
897 gen_helper_ucf64_df2si(cpu_F0s
, cpu_F0d
, cpu_env
);
898 tcg_gen_st_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_D
));
910 /* UniCore-F64 compare instructions */
911 static void do_ucf64_fcmp(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
916 if (UCOP_REG_D
!= 0) {
922 tcg_gen_ld_i64(cpu_F0d
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
923 tcg_gen_ld_i64(cpu_F1d
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
924 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
926 tcg_gen_ld_i32(cpu_F0s
, cpu_env
, ucf64_reg_offset(UCOP_REG_N
));
927 tcg_gen_ld_i32(cpu_F1s
, cpu_env
, ucf64_reg_offset(UCOP_REG_M
));
928 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
932 #define gen_helper_ucf64_movs(x, y) do { } while (0)
933 #define gen_helper_ucf64_movd(x, y) do { } while (0)
935 #define UCF64_OP1(name) do { \
936 if (UCOP_REG_N != 0) { \
939 switch (UCOP_UCF64_FMT) { \
941 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
942 ucf64_reg_offset(UCOP_REG_M)); \
943 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
944 tcg_gen_st_i32(cpu_F0s, cpu_env, \
945 ucf64_reg_offset(UCOP_REG_D)); \
948 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
949 ucf64_reg_offset(UCOP_REG_M)); \
950 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
951 tcg_gen_st_i64(cpu_F0d, cpu_env, \
952 ucf64_reg_offset(UCOP_REG_D)); \
960 #define UCF64_OP2(name) do { \
961 switch (UCOP_UCF64_FMT) { \
963 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
964 ucf64_reg_offset(UCOP_REG_N)); \
965 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
966 ucf64_reg_offset(UCOP_REG_M)); \
967 gen_helper_ucf64_##name##s(cpu_F0s, \
968 cpu_F0s, cpu_F1s, cpu_env); \
969 tcg_gen_st_i32(cpu_F0s, cpu_env, \
970 ucf64_reg_offset(UCOP_REG_D)); \
973 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
974 ucf64_reg_offset(UCOP_REG_N)); \
975 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
976 ucf64_reg_offset(UCOP_REG_M)); \
977 gen_helper_ucf64_##name##d(cpu_F0d, \
978 cpu_F0d, cpu_F1d, cpu_env); \
979 tcg_gen_st_i64(cpu_F0d, cpu_env, \
980 ucf64_reg_offset(UCOP_REG_D)); \
988 /* UniCore-F64 data processing */
989 static void do_ucf64_datap(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
991 if (UCOP_UCF64_FMT
== 3) {
994 switch (UCOP_UCF64_FUNC
) {
1021 /* Disassemble an F64 instruction */
1022 static void disas_ucf64_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1024 if (!UCOP_SET(29)) {
1026 do_ucf64_ldst_m(env
, s
, insn
);
1028 do_ucf64_ldst_i(env
, s
, insn
);
1032 switch ((insn
>> 26) & 0x3) {
1034 do_ucf64_datap(env
, s
, insn
);
1040 do_ucf64_fcvt(env
, s
, insn
);
1043 do_ucf64_fcmp(env
, s
, insn
);
1047 do_ucf64_trans(env
, s
, insn
);
1052 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
1054 TranslationBlock
*tb
;
1057 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1059 gen_set_pc_im(dest
);
1060 tcg_gen_exit_tb((long)tb
+ n
);
1062 gen_set_pc_im(dest
);
1067 static inline void gen_jmp(DisasContext
*s
, uint32_t dest
)
1069 if (unlikely(s
->singlestep_enabled
)) {
1070 /* An indirect jump so that we still trigger the debug exception. */
1073 gen_goto_tb(s
, 0, dest
);
1074 s
->is_jmp
= DISAS_TB_JUMP
;
1078 static inline void gen_mulxy(TCGv t0
, TCGv t1
, int x
, int y
)
1081 tcg_gen_sari_i32(t0
, t0
, 16);
1086 tcg_gen_sari_i32(t1
, t1
, 16);
1090 tcg_gen_mul_i32(t0
, t0
, t1
);
1093 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1094 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int bsr
, TCGv t0
)
1098 /* ??? This is also undefined in system mode. */
1103 tmp
= load_cpu_field(bsr
);
1104 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
1105 tcg_gen_andi_i32(t0
, t0
, mask
);
1106 tcg_gen_or_i32(tmp
, tmp
, t0
);
1107 store_cpu_field(tmp
, bsr
);
1109 gen_set_asr(t0
, mask
);
1116 /* Generate an old-style exception return. Marks pc as dead. */
1117 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
1120 store_reg(s
, 31, pc
);
1121 tmp
= load_cpu_field(bsr
);
1122 gen_set_asr(tmp
, 0xffffffff);
1124 s
->is_jmp
= DISAS_UPDATE
;
1127 static void disas_coproc_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1129 switch (UCOP_CPNUM
) {
1131 disas_ucf64_insn(env
, s
, insn
);
1134 /* Unknown coprocessor. */
1135 cpu_abort(env
, "Unknown coprocessor!");
1140 /* Store a 64-bit value to a register pair. Clobbers val. */
1141 static void gen_storeq_reg(DisasContext
*s
, int rlow
, int rhigh
, TCGv_i64 val
)
1145 tcg_gen_trunc_i64_i32(tmp
, val
);
1146 store_reg(s
, rlow
, tmp
);
1148 tcg_gen_shri_i64(val
, val
, 32);
1149 tcg_gen_trunc_i64_i32(tmp
, val
);
1150 store_reg(s
, rhigh
, tmp
);
1153 /* load and add a 64-bit value from a register pair. */
1154 static void gen_addq(DisasContext
*s
, TCGv_i64 val
, int rlow
, int rhigh
)
1160 /* Load 64-bit value rd:rn. */
1161 tmpl
= load_reg(s
, rlow
);
1162 tmph
= load_reg(s
, rhigh
);
1163 tmp
= tcg_temp_new_i64();
1164 tcg_gen_concat_i32_i64(tmp
, tmpl
, tmph
);
1167 tcg_gen_add_i64(val
, val
, tmp
);
1168 tcg_temp_free_i64(tmp
);
1171 /* data processing instructions */
1172 static void do_datap(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1178 if (UCOP_OPCODES
== 0x0f || UCOP_OPCODES
== 0x0d) {
1179 if (UCOP_SET(23)) { /* CMOV instructions */
1180 if ((UCOP_CMOV_COND
== 0xe) || (UCOP_CMOV_COND
== 0xf)) {
1183 /* if not always execute, we generate a conditional jump to
1185 s
->condlabel
= gen_new_label();
1186 gen_test_cc(UCOP_CMOV_COND
^ 1, s
->condlabel
);
1191 logic_cc
= table_logic_cc
[UCOP_OPCODES
] & (UCOP_SET_S
>> 24);
1195 /* immediate operand */
1198 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1201 tcg_gen_movi_i32(tmp2
, val
);
1202 if (logic_cc
&& UCOP_SH_IM
) {
1203 gen_set_CF_bit31(tmp2
);
1207 tmp2
= load_reg(s
, UCOP_REG_M
);
1209 tmp
= load_reg(s
, UCOP_REG_S
);
1210 gen_uc32_shift_reg(tmp2
, UCOP_SH_OP
, tmp
, logic_cc
);
1212 gen_uc32_shift_im(tmp2
, UCOP_SH_OP
, UCOP_SH_IM
, logic_cc
);
1216 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1217 tmp
= load_reg(s
, UCOP_REG_N
);
1222 switch (UCOP_OPCODES
) {
1224 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1228 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1231 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1235 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1238 if (UCOP_SET_S
&& UCOP_REG_D
== 31) {
1239 /* SUBS r31, ... is used for exception return. */
1243 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
1244 gen_exception_return(s
, tmp
);
1247 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
1249 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
1251 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1256 gen_helper_sub_cc(tmp
, tmp2
, tmp
);
1258 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
1260 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1264 gen_helper_add_cc(tmp
, tmp
, tmp2
);
1266 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1268 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1272 gen_helper_adc_cc(tmp
, tmp
, tmp2
);
1274 gen_add_carry(tmp
, tmp
, tmp2
);
1276 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1280 gen_helper_sbc_cc(tmp
, tmp
, tmp2
);
1282 gen_sub_carry(tmp
, tmp
, tmp2
);
1284 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1288 gen_helper_sbc_cc(tmp
, tmp2
, tmp
);
1290 gen_sub_carry(tmp
, tmp2
, tmp
);
1292 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1296 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1303 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
1310 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
1316 gen_helper_add_cc(tmp
, tmp
, tmp2
);
1321 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1325 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1328 if (logic_cc
&& UCOP_REG_D
== 31) {
1329 /* MOVS r31, ... is used for exception return. */
1333 gen_exception_return(s
, tmp2
);
1338 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1342 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1346 store_reg_bx(s
, UCOP_REG_D
, tmp
);
1350 tcg_gen_not_i32(tmp2
, tmp2
);
1354 store_reg_bx(s
, UCOP_REG_D
, tmp2
);
1357 if (UCOP_OPCODES
!= 0x0f && UCOP_OPCODES
!= 0x0d) {
1363 static void do_mult(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1371 tmp
= load_reg(s
, UCOP_REG_M
);
1372 tmp2
= load_reg(s
, UCOP_REG_N
);
1374 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
1376 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
1378 if (UCOP_SET(25)) { /* mult accumulate */
1379 gen_addq(s
, tmp64
, UCOP_REG_LO
, UCOP_REG_HI
);
1381 gen_storeq_reg(s
, UCOP_REG_LO
, UCOP_REG_HI
, tmp64
);
1382 tcg_temp_free_i64(tmp64
);
1385 tmp
= load_reg(s
, UCOP_REG_M
);
1386 tmp2
= load_reg(s
, UCOP_REG_N
);
1387 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
1391 tmp2
= load_reg(s
, UCOP_REG_S
);
1392 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
1398 store_reg(s
, UCOP_REG_D
, tmp
);
1402 /* miscellaneous instructions */
1403 static void do_misc(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1408 if ((insn
& 0xffffffe0) == 0x10ffc120) {
1409 /* Trivial implementation equivalent to bx. */
1410 tmp
= load_reg(s
, UCOP_REG_M
);
1415 if ((insn
& 0xfbffc000) == 0x30ffc000) {
1416 /* PSR = immediate */
1419 val
= (val
>> UCOP_SH_IM
) | (val
<< (32 - UCOP_SH_IM
));
1422 tcg_gen_movi_i32(tmp
, val
);
1423 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1429 if ((insn
& 0xfbffffe0) == 0x12ffc020) {
1430 /* PSR.flag = reg */
1431 tmp
= load_reg(s
, UCOP_REG_M
);
1432 if (gen_set_psr(s
, ASR_NZCV
, UCOP_SET_B
, tmp
)) {
1438 if ((insn
& 0xfbffffe0) == 0x10ffc020) {
1440 tmp
= load_reg(s
, UCOP_REG_M
);
1441 if (gen_set_psr(s
, ~ASR_RESERVED
, UCOP_SET_B
, tmp
)) {
1447 if ((insn
& 0xfbf83fff) == 0x10f80000) {
1453 tmp
= load_cpu_field(bsr
);
1456 gen_helper_asr_read(tmp
);
1458 store_reg(s
, UCOP_REG_D
, tmp
);
1462 if ((insn
& 0xfbf83fe0) == 0x12f80120) {
1464 tmp
= load_reg(s
, UCOP_REG_M
);
1466 gen_helper_clo(tmp
, tmp
);
1468 gen_helper_clz(tmp
, tmp
);
1470 store_reg(s
, UCOP_REG_D
, tmp
);
1478 /* load/store I_offset and R_offset */
1479 static void do_ldst_ir(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1485 tmp2
= load_reg(s
, UCOP_REG_N
);
1486 i
= (IS_USER(s
) || (!UCOP_SET_P
&& UCOP_SET_W
));
1490 gen_add_data_offset(s
, insn
, tmp2
);
1496 tmp
= gen_ld8u(tmp2
, i
);
1498 tmp
= gen_ld32(tmp2
, i
);
1502 tmp
= load_reg(s
, UCOP_REG_D
);
1504 gen_st8(tmp
, tmp2
, i
);
1506 gen_st32(tmp
, tmp2
, i
);
1510 gen_add_data_offset(s
, insn
, tmp2
);
1511 store_reg(s
, UCOP_REG_N
, tmp2
);
1512 } else if (UCOP_SET_W
) {
1513 store_reg(s
, UCOP_REG_N
, tmp2
);
1518 /* Complete the load. */
1519 if (UCOP_REG_D
== 31) {
1522 store_reg(s
, UCOP_REG_D
, tmp
);
1527 /* SWP instruction */
1528 static void do_swap(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1534 if ((insn
& 0xff003fe0) != 0x40000120) {
1538 /* ??? This is not really atomic. However we know
1539 we never have multiple CPUs running in parallel,
1540 so it is good enough. */
1541 addr
= load_reg(s
, UCOP_REG_N
);
1542 tmp
= load_reg(s
, UCOP_REG_M
);
1544 tmp2
= gen_ld8u(addr
, IS_USER(s
));
1545 gen_st8(tmp
, addr
, IS_USER(s
));
1547 tmp2
= gen_ld32(addr
, IS_USER(s
));
1548 gen_st32(tmp
, addr
, IS_USER(s
));
1551 store_reg(s
, UCOP_REG_D
, tmp2
);
1554 /* load/store hw/sb */
1555 static void do_ldst_hwsb(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1560 if (UCOP_SH_OP
== 0) {
1561 do_swap(env
, s
, insn
);
1565 addr
= load_reg(s
, UCOP_REG_N
);
1567 gen_add_datah_offset(s
, insn
, addr
);
1570 if (UCOP_SET_L
) { /* load */
1571 switch (UCOP_SH_OP
) {
1573 tmp
= gen_ld16u(addr
, IS_USER(s
));
1576 tmp
= gen_ld8s(addr
, IS_USER(s
));
1578 default: /* see do_swap */
1580 tmp
= gen_ld16s(addr
, IS_USER(s
));
1583 } else { /* store */
1584 if (UCOP_SH_OP
!= 1) {
1587 tmp
= load_reg(s
, UCOP_REG_D
);
1588 gen_st16(tmp
, addr
, IS_USER(s
));
1590 /* Perform base writeback before the loaded value to
1591 ensure correct behavior with overlapping index registers. */
1593 gen_add_datah_offset(s
, insn
, addr
);
1594 store_reg(s
, UCOP_REG_N
, addr
);
1595 } else if (UCOP_SET_W
) {
1596 store_reg(s
, UCOP_REG_N
, addr
);
1601 /* Complete the load. */
1602 store_reg(s
, UCOP_REG_D
, tmp
);
1606 /* load/store multiple words */
1607 static void do_ldst_m(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1609 unsigned int val
, i
;
1610 int j
, n
, reg
, user
, loaded_base
;
1619 /* XXX: store correct base if write back */
1621 if (UCOP_SET_B
) { /* S bit in instruction table */
1623 ILLEGAL
; /* only usable in supervisor mode */
1625 if (UCOP_SET(18) == 0) { /* pc reg */
1630 addr
= load_reg(s
, UCOP_REG_N
);
1632 /* compute total size */
1634 TCGV_UNUSED(loaded_var
);
1636 for (i
= 0; i
< 6; i
++) {
1641 for (i
= 9; i
< 19; i
++) {
1646 /* XXX: test invalid n == 0 case ? */
1650 tcg_gen_addi_i32(addr
, addr
, 4);
1652 /* post increment */
1657 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1659 /* post decrement */
1661 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1667 reg
= UCOP_SET(6) ? 16 : 0;
1668 for (i
= 0; i
< 19; i
++, reg
++) {
1673 if (UCOP_SET_L
) { /* load */
1674 tmp
= gen_ld32(addr
, IS_USER(s
));
1678 tmp2
= tcg_const_i32(reg
);
1679 gen_helper_set_user_reg(tmp2
, tmp
);
1680 tcg_temp_free_i32(tmp2
);
1682 } else if (reg
== UCOP_REG_N
) {
1686 store_reg(s
, reg
, tmp
);
1688 } else { /* store */
1690 /* special case: r31 = PC + 4 */
1693 tcg_gen_movi_i32(tmp
, val
);
1696 tmp2
= tcg_const_i32(reg
);
1697 gen_helper_get_user_reg(tmp
, tmp2
);
1698 tcg_temp_free_i32(tmp2
);
1700 tmp
= load_reg(s
, reg
);
1702 gen_st32(tmp
, addr
, IS_USER(s
));
1705 /* no need to add after the last transfer */
1707 tcg_gen_addi_i32(addr
, addr
, 4);
1711 if (UCOP_SET_W
) { /* write back */
1716 /* post increment */
1717 tcg_gen_addi_i32(addr
, addr
, 4);
1723 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
1726 /* post decrement */
1727 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
1730 store_reg(s
, UCOP_REG_N
, addr
);
1735 store_reg(s
, UCOP_REG_N
, loaded_var
);
1737 if (UCOP_SET_B
&& !user
) {
1738 /* Restore ASR from BSR. */
1739 tmp
= load_cpu_field(bsr
);
1740 gen_set_asr(tmp
, 0xffffffff);
1742 s
->is_jmp
= DISAS_UPDATE
;
1746 /* branch (and link) */
1747 static void do_branch(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1753 if (UCOP_COND
== 0xf) {
1757 if (UCOP_COND
!= 0xe) {
1758 /* if not always execute, we generate a conditional jump to
1760 s
->condlabel
= gen_new_label();
1761 gen_test_cc(UCOP_COND
^ 1, s
->condlabel
);
1765 val
= (int32_t)s
->pc
;
1768 tcg_gen_movi_i32(tmp
, val
);
1769 store_reg(s
, 30, tmp
);
1771 offset
= (((int32_t)insn
<< 8) >> 8);
1772 val
+= (offset
<< 2); /* unicore is pc+4 */
1776 static void disas_uc32_insn(CPUState
*env
, DisasContext
*s
)
1780 insn
= ldl_code(s
->pc
);
1783 /* UniCore instructions class:
1784 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1785 * AAA : see switch case
1786 * BBBB : opcodes or cond or PUBW
1791 switch (insn
>> 29) {
1793 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1794 do_mult(env
, s
, insn
);
1799 do_misc(env
, s
, insn
);
1803 if (((UCOP_OPCODES
>> 2) == 2) && !UCOP_SET_S
) {
1804 do_misc(env
, s
, insn
);
1807 do_datap(env
, s
, insn
);
1811 if (UCOP_SET(8) && UCOP_SET(5)) {
1812 do_ldst_hwsb(env
, s
, insn
);
1815 if (UCOP_SET(8) || UCOP_SET(5)) {
1819 do_ldst_ir(env
, s
, insn
);
1824 ILLEGAL
; /* extended instructions */
1826 do_ldst_m(env
, s
, insn
);
1829 do_branch(env
, s
, insn
);
1833 disas_coproc_insn(env
, s
, insn
);
1836 if (!UCOP_SET(28)) {
1837 disas_coproc_insn(env
, s
, insn
);
1840 if ((insn
& 0xff000000) == 0xff000000) { /* syscall */
1841 gen_set_pc_im(s
->pc
);
1842 s
->is_jmp
= DISAS_SYSCALL
;
1851 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
1852 basic block 'tb'. If search_pc is TRUE, also generate PC
1853 information for each intermediate instruction. */
1854 static inline void gen_intermediate_code_internal(CPUState
*env
,
1855 TranslationBlock
*tb
, int search_pc
)
1857 DisasContext dc1
, *dc
= &dc1
;
1859 uint16_t *gen_opc_end
;
1861 target_ulong pc_start
;
1862 uint32_t next_page_start
;
1866 /* generate intermediate code */
1873 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1875 dc
->is_jmp
= DISAS_NEXT
;
1877 dc
->singlestep_enabled
= env
->singlestep_enabled
;
1879 cpu_F0s
= tcg_temp_new_i32();
1880 cpu_F1s
= tcg_temp_new_i32();
1881 cpu_F0d
= tcg_temp_new_i64();
1882 cpu_F1d
= tcg_temp_new_i64();
1883 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1886 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1887 if (max_insns
== 0) {
1888 max_insns
= CF_COUNT_MASK
;
1893 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
1894 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
1895 if (bp
->pc
== dc
->pc
) {
1896 gen_set_pc_im(dc
->pc
);
1897 gen_exception(EXCP_DEBUG
);
1898 dc
->is_jmp
= DISAS_JUMP
;
1899 /* Advance PC so that clearing the breakpoint will
1900 invalidate this TB. */
1901 dc
->pc
+= 2; /* FIXME */
1902 goto done_generating
;
1908 j
= gen_opc_ptr
- gen_opc_buf
;
1912 gen_opc_instr_start
[lj
++] = 0;
1915 gen_opc_pc
[lj
] = dc
->pc
;
1916 gen_opc_instr_start
[lj
] = 1;
1917 gen_opc_icount
[lj
] = num_insns
;
1920 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1924 disas_uc32_insn(env
, dc
);
1927 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
1931 if (dc
->condjmp
&& !dc
->is_jmp
) {
1932 gen_set_label(dc
->condlabel
);
1935 /* Translation stops when a conditional branch is encountered.
1936 * Otherwise the subsequent code could get translated several times.
1937 * Also stop translation when a page boundary is reached. This
1938 * ensures prefetch aborts occur at the right place. */
1940 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
&&
1941 !env
->singlestep_enabled
&&
1943 dc
->pc
< next_page_start
&&
1944 num_insns
< max_insns
);
1946 if (tb
->cflags
& CF_LAST_IO
) {
1948 /* FIXME: This can theoretically happen with self-modifying
1950 cpu_abort(env
, "IO on conditional branch instruction");
1955 /* At this stage dc->condjmp will only be set when the skipped
1956 instruction was a conditional branch or trap, and the PC has
1957 already been written. */
1958 if (unlikely(env
->singlestep_enabled
)) {
1959 /* Make sure the pc is updated, and raise a debug exception. */
1961 if (dc
->is_jmp
== DISAS_SYSCALL
) {
1962 gen_exception(UC32_EXCP_PRIV
);
1964 gen_exception(EXCP_DEBUG
);
1966 gen_set_label(dc
->condlabel
);
1968 if (dc
->condjmp
|| !dc
->is_jmp
) {
1969 gen_set_pc_im(dc
->pc
);
1972 if (dc
->is_jmp
== DISAS_SYSCALL
&& !dc
->condjmp
) {
1973 gen_exception(UC32_EXCP_PRIV
);
1975 gen_exception(EXCP_DEBUG
);
1978 /* While branches must always occur at the end of an IT block,
1979 there are a few other things that can cause us to terminate
1980 the TB in the middel of an IT block:
1981 - Exception generating instructions (bkpt, swi, undefined).
1983 - Hardware watchpoints.
1984 Hardware breakpoints have already been handled and skip this code.
1986 switch (dc
->is_jmp
) {
1988 gen_goto_tb(dc
, 1, dc
->pc
);
1993 /* indicate that the hash table must be used to find the next TB */
1997 /* nothing more to generate */
2000 gen_exception(UC32_EXCP_PRIV
);
2004 gen_set_label(dc
->condlabel
);
2005 gen_goto_tb(dc
, 1, dc
->pc
);
2011 gen_icount_end(tb
, num_insns
);
2012 *gen_opc_ptr
= INDEX_op_end
;
2015 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2016 qemu_log("----------------\n");
2017 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2018 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
2023 j
= gen_opc_ptr
- gen_opc_buf
;
2026 gen_opc_instr_start
[lj
++] = 0;
2029 tb
->size
= dc
->pc
- pc_start
;
2030 tb
->icount
= num_insns
;
2034 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
2036 gen_intermediate_code_internal(env
, tb
, 0);
2039 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
2041 gen_intermediate_code_internal(env
, tb
, 1);
2044 static const char *cpu_mode_names
[16] = {
2045 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2046 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2049 #define UCF64_DUMP_STATE
2050 void cpu_dump_state(CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
2054 #ifdef UCF64_DUMP_STATE
2060 /* ??? This assumes float64 and double have the same layout.
2061 Oh well, it's only debug dumps. */
2069 for (i
= 0; i
< 32; i
++) {
2070 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
2072 cpu_fprintf(f
, "\n");
2074 cpu_fprintf(f
, " ");
2077 psr
= cpu_asr_read(env
);
2078 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %s\n",
2080 psr
& (1 << 31) ? 'N' : '-',
2081 psr
& (1 << 30) ? 'Z' : '-',
2082 psr
& (1 << 29) ? 'C' : '-',
2083 psr
& (1 << 28) ? 'V' : '-',
2084 cpu_mode_names
[psr
& 0xf]);
2086 #ifdef UCF64_DUMP_STATE
2087 for (i
= 0; i
< 16; i
++) {
2088 d
.d
= env
->ucf64
.regs
[i
];
2092 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g) d%02d=%" PRIx64
"(%8g)\n",
2093 i
* 2, (int)s0
.i
, s0
.s
,
2094 i
* 2 + 1, (int)s1
.i
, s1
.s
,
2095 i
, (uint64_t)d0
.f64
, d0
.d
);
2097 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->ucf64
.xregs
[UC32_UCF64_FPSCR
]);
2101 void restore_state_to_opc(CPUState
*env
, TranslationBlock
*tb
, int pc_pos
)
2103 env
->regs
[31] = gen_opc_pc
[pc_pos
];