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.
25 /* internal defines */
26 typedef struct DisasContext {
29 /* Nonzero if this instruction has been conditionally skipped. */
31 /* The label that will be jumped to when the instruction is skipped. */
33 struct TranslationBlock *tb;
34 int singlestep_enabled;
39 /* These instructions trap after executing, so defer them until after the
40 conditional executions state has been updated. */
41 #define DISAS_SYSCALL 5
43 static TCGv_ptr cpu_env;
44 static TCGv_i32 cpu_R[32];
46 /* FIXME: These should be removed. */
47 static TCGv cpu_F0s, cpu_F1s;
48 static TCGv_i64 cpu_F0d, cpu_F1d;
50 #include "gen-icount.h"
52 static const char *regnames[] = {
53 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
54 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
55 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
56 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "pc" };
58 /* initialize TCG globals. */
59 void uc32_translate_init(void)
63 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
65 for (i = 0; i < 32; i++) {
66 cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
67 offsetof(CPUState, regs[i]), regnames[i]);
76 /* Allocate a temporary variable. */
77 static TCGv_i32 new_tmp(void)
80 return tcg_temp_new_i32();
83 /* Release a temporary variable. */
84 static void dead_tmp(TCGv tmp)
90 static inline TCGv load_cpu_offset(int offset)
93 tcg_gen_ld_i32(tmp, cpu_env, offset);
97 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUState, name))
99 static inline void store_cpu_offset(TCGv var, int offset)
101 tcg_gen_st_i32(var, cpu_env, offset);
105 #define store_cpu_field(var, name) \
106 store_cpu_offset(var, offsetof(CPUState, name))
108 /* Set a variable to the value of a CPU register. */
109 static void load_reg_var(DisasContext *s, TCGv var, int reg)
113 /* normaly, since we updated PC */
115 tcg_gen_movi_i32(var, addr);
117 tcg_gen_mov_i32(var, cpu_R[reg]);
121 /* Create a new temporary and set it to the value of a CPU register. */
122 static inline TCGv load_reg(DisasContext *s, int reg)
124 TCGv tmp = new_tmp();
125 load_reg_var(s, tmp, reg);
129 /* Set a CPU register. The source must be a temporary and will be
131 static void store_reg(DisasContext *s, int reg, TCGv var)
134 tcg_gen_andi_i32(var, var, ~3);
135 s->is_jmp = DISAS_JUMP;
137 tcg_gen_mov_i32(cpu_R[reg], var);
141 /* Value extensions. */
142 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
143 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
144 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
145 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
147 #define UCOP_REG_M (((insn) >> 0) & 0x1f)
148 #define UCOP_REG_N (((insn) >> 19) & 0x1f)
149 #define UCOP_REG_D (((insn) >> 14) & 0x1f)
150 #define UCOP_REG_S (((insn) >> 9) & 0x1f)
151 #define UCOP_REG_LO (((insn) >> 14) & 0x1f)
152 #define UCOP_REG_HI (((insn) >> 9) & 0x1f)
153 #define UCOP_SH_OP (((insn) >> 6) & 0x03)
154 #define UCOP_SH_IM (((insn) >> 9) & 0x1f)
155 #define UCOP_OPCODES (((insn) >> 25) & 0x0f)
156 #define UCOP_IMM_9 (((insn) >> 0) & 0x1ff)
157 #define UCOP_IMM10 (((insn) >> 0) & 0x3ff)
158 #define UCOP_IMM14 (((insn) >> 0) & 0x3fff)
159 #define UCOP_COND (((insn) >> 25) & 0x0f)
160 #define UCOP_CMOV_COND (((insn) >> 19) & 0x0f)
161 #define UCOP_CPNUM (((insn) >> 10) & 0x0f)
162 #define UCOP_UCF64_FMT (((insn) >> 24) & 0x03)
163 #define UCOP_UCF64_FUNC (((insn) >> 6) & 0x0f)
164 #define UCOP_UCF64_COND (((insn) >> 6) & 0x0f)
166 #define UCOP_SET(i) ((insn) & (1 << (i)))
167 #define UCOP_SET_P UCOP_SET(28)
168 #define UCOP_SET_U UCOP_SET(27)
169 #define UCOP_SET_B UCOP_SET(26)
170 #define UCOP_SET_W UCOP_SET(25)
171 #define UCOP_SET_L UCOP_SET(24)
172 #define UCOP_SET_S UCOP_SET(24)
174 #define ILLEGAL cpu_abort(env, \
175 "Illegal UniCore32 instruction %x at line %d!", \
178 static inline void gen_set_asr(TCGv var, uint32_t mask)
180 TCGv tmp_mask = tcg_const_i32(mask);
181 gen_helper_asr_write(var, tmp_mask);
182 tcg_temp_free_i32(tmp_mask);
184 /* Set NZCV flags from the high 4 bits of var. */
185 #define gen_set_nzcv(var) gen_set_asr(var, ASR_NZCV)
187 static void gen_exception(int excp)
189 TCGv tmp = new_tmp();
190 tcg_gen_movi_i32(tmp, excp);
191 gen_helper_exception(tmp);
195 /* FIXME: Most targets have native widening multiplication.
196 It would be good to use that instead of a full wide multiply. */
197 /* 32x32->64 multiply. Marks inputs as dead. */
198 static TCGv_i64 gen_mulu_i64_i32(TCGv a, TCGv b)
200 TCGv_i64 tmp1 = tcg_temp_new_i64();
201 TCGv_i64 tmp2 = tcg_temp_new_i64();
203 tcg_gen_extu_i32_i64(tmp1, a);
205 tcg_gen_extu_i32_i64(tmp2, b);
207 tcg_gen_mul_i64(tmp1, tmp1, tmp2);
208 tcg_temp_free_i64(tmp2);
212 static TCGv_i64 gen_muls_i64_i32(TCGv a, TCGv b)
214 TCGv_i64 tmp1 = tcg_temp_new_i64();
215 TCGv_i64 tmp2 = tcg_temp_new_i64();
217 tcg_gen_ext_i32_i64(tmp1, a);
219 tcg_gen_ext_i32_i64(tmp2, b);
221 tcg_gen_mul_i64(tmp1, tmp1, tmp2);
222 tcg_temp_free_i64(tmp2);
226 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, CF))
228 /* Set CF to the top bit of var. */
229 static void gen_set_CF_bit31(TCGv var)
231 TCGv tmp = new_tmp();
232 tcg_gen_shri_i32(tmp, var, 31);
237 /* Set N and Z flags from var. */
238 static inline void gen_logic_CC(TCGv var)
240 tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, NF));
241 tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, ZF));
244 /* dest = T0 + T1 + CF. */
245 static void gen_add_carry(TCGv dest, TCGv t0, TCGv t1)
248 tcg_gen_add_i32(dest, t0, t1);
249 tmp = load_cpu_field(CF);
250 tcg_gen_add_i32(dest, dest, tmp);
254 /* dest = T0 - T1 + CF - 1. */
255 static void gen_sub_carry(TCGv dest, TCGv t0, TCGv t1)
258 tcg_gen_sub_i32(dest, t0, t1);
259 tmp = load_cpu_field(CF);
260 tcg_gen_add_i32(dest, dest, tmp);
261 tcg_gen_subi_i32(dest, dest, 1);
265 static void shifter_out_im(TCGv var, int shift)
267 TCGv tmp = new_tmp();
269 tcg_gen_andi_i32(tmp, var, 1);
271 tcg_gen_shri_i32(tmp, var, shift);
273 tcg_gen_andi_i32(tmp, tmp, 1);
280 /* Shift by immediate. Includes special handling for shift == 0. */
281 static inline void gen_uc32_shift_im(TCGv var, int shiftop, int shift,
288 shifter_out_im(var, 32 - shift);
290 tcg_gen_shli_i32(var, var, shift);
296 tcg_gen_shri_i32(var, var, 31);
299 tcg_gen_movi_i32(var, 0);
302 shifter_out_im(var, shift - 1);
304 tcg_gen_shri_i32(var, var, shift);
312 shifter_out_im(var, shift - 1);
317 tcg_gen_sari_i32(var, var, shift);
319 case 3: /* ROR/RRX */
322 shifter_out_im(var, shift - 1);
324 tcg_gen_rotri_i32(var, var, shift); break;
326 TCGv tmp = load_cpu_field(CF);
328 shifter_out_im(var, 0);
330 tcg_gen_shri_i32(var, var, 1);
331 tcg_gen_shli_i32(tmp, tmp, 31);
332 tcg_gen_or_i32(var, var, tmp);
338 static inline void gen_uc32_shift_reg(TCGv var, int shiftop,
339 TCGv shift, int flags)
344 gen_helper_shl_cc(var, var, shift);
347 gen_helper_shr_cc(var, var, shift);
350 gen_helper_sar_cc(var, var, shift);
353 gen_helper_ror_cc(var, var, shift);
359 gen_helper_shl(var, var, shift);
362 gen_helper_shr(var, var, shift);
365 gen_helper_sar(var, var, shift);
368 tcg_gen_andi_i32(shift, shift, 0x1f);
369 tcg_gen_rotr_i32(var, var, shift);
376 static void gen_test_cc(int cc, int label)
384 tmp = load_cpu_field(ZF);
385 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
388 tmp = load_cpu_field(ZF);
389 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
392 tmp = load_cpu_field(CF);
393 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
396 tmp = load_cpu_field(CF);
397 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
400 tmp = load_cpu_field(NF);
401 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
404 tmp = load_cpu_field(NF);
405 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
408 tmp = load_cpu_field(VF);
409 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
412 tmp = load_cpu_field(VF);
413 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
415 case 8: /* hi: C && !Z */
416 inv = gen_new_label();
417 tmp = load_cpu_field(CF);
418 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
420 tmp = load_cpu_field(ZF);
421 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
424 case 9: /* ls: !C || Z */
425 tmp = load_cpu_field(CF);
426 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
428 tmp = load_cpu_field(ZF);
429 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
431 case 10: /* ge: N == V -> N ^ V == 0 */
432 tmp = load_cpu_field(VF);
433 tmp2 = load_cpu_field(NF);
434 tcg_gen_xor_i32(tmp, tmp, tmp2);
436 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
438 case 11: /* lt: N != V -> N ^ V != 0 */
439 tmp = load_cpu_field(VF);
440 tmp2 = load_cpu_field(NF);
441 tcg_gen_xor_i32(tmp, tmp, tmp2);
443 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
445 case 12: /* gt: !Z && N == V */
446 inv = gen_new_label();
447 tmp = load_cpu_field(ZF);
448 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
450 tmp = load_cpu_field(VF);
451 tmp2 = load_cpu_field(NF);
452 tcg_gen_xor_i32(tmp, tmp, tmp2);
454 tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
457 case 13: /* le: Z || N != V */
458 tmp = load_cpu_field(ZF);
459 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
461 tmp = load_cpu_field(VF);
462 tmp2 = load_cpu_field(NF);
463 tcg_gen_xor_i32(tmp, tmp, tmp2);
465 tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
468 fprintf(stderr, "Bad condition code 0x%x\n", cc);
474 static const uint8_t table_logic_cc[16] = {
475 1, /* and */ 1, /* xor */ 0, /* sub */ 0, /* rsb */
476 0, /* add */ 0, /* adc */ 0, /* sbc */ 0, /* rsc */
477 1, /* andl */ 1, /* xorl */ 0, /* cmp */ 0, /* cmn */
478 1, /* orr */ 1, /* mov */ 1, /* bic */ 1, /* mvn */
481 /* Set PC state from an immediate address. */
482 static inline void gen_bx_im(DisasContext *s, uint32_t addr)
484 s->is_jmp = DISAS_UPDATE;
485 tcg_gen_movi_i32(cpu_R[31], addr & ~3);
488 /* Set PC state from var. var is marked as dead. */
489 static inline void gen_bx(DisasContext *s, TCGv var)
491 s->is_jmp = DISAS_UPDATE;
492 tcg_gen_andi_i32(cpu_R[31], var, ~3);
496 static inline void store_reg_bx(DisasContext *s, int reg, TCGv var)
498 store_reg(s, reg, var);
501 static inline TCGv gen_ld8s(TCGv addr, int index)
503 TCGv tmp = new_tmp();
504 tcg_gen_qemu_ld8s(tmp, addr, index);
508 static inline TCGv gen_ld8u(TCGv addr, int index)
510 TCGv tmp = new_tmp();
511 tcg_gen_qemu_ld8u(tmp, addr, index);
515 static inline TCGv gen_ld16s(TCGv addr, int index)
517 TCGv tmp = new_tmp();
518 tcg_gen_qemu_ld16s(tmp, addr, index);
522 static inline TCGv gen_ld16u(TCGv addr, int index)
524 TCGv tmp = new_tmp();
525 tcg_gen_qemu_ld16u(tmp, addr, index);
529 static inline TCGv gen_ld32(TCGv addr, int index)
531 TCGv tmp = new_tmp();
532 tcg_gen_qemu_ld32u(tmp, addr, index);
536 static inline TCGv_i64 gen_ld64(TCGv addr, int index)
538 TCGv_i64 tmp = tcg_temp_new_i64();
539 tcg_gen_qemu_ld64(tmp, addr, index);
543 static inline void gen_st8(TCGv val, TCGv addr, int index)
545 tcg_gen_qemu_st8(val, addr, index);
549 static inline void gen_st16(TCGv val, TCGv addr, int index)
551 tcg_gen_qemu_st16(val, addr, index);
555 static inline void gen_st32(TCGv val, TCGv addr, int index)
557 tcg_gen_qemu_st32(val, addr, index);
561 static inline void gen_st64(TCGv_i64 val, TCGv addr, int index)
563 tcg_gen_qemu_st64(val, addr, index);
564 tcg_temp_free_i64(val);
567 static inline void gen_set_pc_im(uint32_t val)
569 tcg_gen_movi_i32(cpu_R[31], val);
572 /* Force a TB lookup after an instruction that changes the CPU state. */
573 static inline void gen_lookup_tb(DisasContext *s)
575 tcg_gen_movi_i32(cpu_R[31], s->pc & ~1);
576 s->is_jmp = DISAS_UPDATE;
579 static inline void gen_add_data_offset(DisasContext *s, unsigned int insn,
592 tcg_gen_addi_i32(var, var, val);
596 offset = load_reg(s, UCOP_REG_M);
597 gen_uc32_shift_im(offset, UCOP_SH_OP, UCOP_SH_IM, 0);
599 tcg_gen_sub_i32(var, var, offset);
601 tcg_gen_add_i32(var, var, offset);
607 static inline void gen_add_datah_offset(DisasContext *s, unsigned int insn,
615 val = (insn & 0x1f) | ((insn >> 4) & 0x3e0);
620 tcg_gen_addi_i32(var, var, val);
624 offset = load_reg(s, UCOP_REG_M);
626 tcg_gen_sub_i32(var, var, offset);
628 tcg_gen_add_i32(var, var, offset);
634 static inline long ucf64_reg_offset(int reg)
637 return offsetof(CPUState, ucf64.regs[reg >> 1])
638 + offsetof(CPU_DoubleU, l.upper);
640 return offsetof(CPUState, ucf64.regs[reg >> 1])
641 + offsetof(CPU_DoubleU, l.lower);
645 #define ucf64_gen_ld32(reg) load_cpu_offset(ucf64_reg_offset(reg))
646 #define ucf64_gen_st32(var, reg) store_cpu_offset(var, ucf64_reg_offset(reg))
648 /* UniCore-F64 single load/store I_offset */
649 static void do_ucf64_ldst_i(CPUState *env, DisasContext *s, uint32_t insn)
655 addr = load_reg(s, UCOP_REG_N);
656 if (!UCOP_SET_P && !UCOP_SET_W) {
661 offset = UCOP_IMM10 << 2;
666 tcg_gen_addi_i32(addr, addr, offset);
670 if (UCOP_SET_L) { /* load */
671 tmp = gen_ld32(addr, IS_USER(s));
672 ucf64_gen_st32(tmp, UCOP_REG_D);
674 tmp = ucf64_gen_ld32(UCOP_REG_D);
675 gen_st32(tmp, addr, IS_USER(s));
679 offset = UCOP_IMM10 << 2;
684 tcg_gen_addi_i32(addr, addr, offset);
688 store_reg(s, UCOP_REG_N, addr);
694 /* UniCore-F64 load/store multiple words */
695 static void do_ucf64_ldst_m(CPUState *env, DisasContext *s, uint32_t insn)
702 if (UCOP_REG_D != 0) {
705 if (UCOP_REG_N == 31) {
708 if ((insn << 24) == 0) {
712 addr = load_reg(s, UCOP_REG_N);
715 for (i = 0; i < 8; i++) {
722 if (UCOP_SET_P) { /* pre increment */
723 tcg_gen_addi_i32(addr, addr, 4);
724 } /* unnecessary to do anything when post increment */
726 if (UCOP_SET_P) { /* pre decrement */
727 tcg_gen_addi_i32(addr, addr, -(n * 4));
728 } else { /* post decrement */
730 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
735 freg = ((insn >> 8) & 3) << 3; /* freg should be 0, 8, 16, 24 */
737 for (i = 0, j = 0; i < 8; i++, freg++) {
742 if (UCOP_SET_L) { /* load */
743 tmp = gen_ld32(addr, IS_USER(s));
744 ucf64_gen_st32(tmp, freg);
746 tmp = ucf64_gen_ld32(freg);
747 gen_st32(tmp, addr, IS_USER(s));
751 /* unnecessary to add after the last transfer */
753 tcg_gen_addi_i32(addr, addr, 4);
757 if (UCOP_SET_W) { /* write back */
759 if (!UCOP_SET_P) { /* post increment */
760 tcg_gen_addi_i32(addr, addr, 4);
761 } /* unnecessary to do anything when pre increment */
766 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
770 tcg_gen_addi_i32(addr, addr, -(n * 4));
773 store_reg(s, UCOP_REG_N, addr);
779 /* UniCore-F64 mrc/mcr */
780 static void do_ucf64_trans(CPUState *env, DisasContext *s, uint32_t insn)
784 if ((insn & 0xfe0003ff) == 0xe2000000) {
785 /* control register */
786 if ((UCOP_REG_N != UC32_UCF64_FPSCR) || (UCOP_REG_D == 31)) {
792 gen_helper_ucf64_get_fpscr(tmp, cpu_env);
793 store_reg(s, UCOP_REG_D, tmp);
796 tmp = load_reg(s, UCOP_REG_D);
797 gen_helper_ucf64_set_fpscr(cpu_env, tmp);
803 if ((insn & 0xfe0003ff) == 0xe0000000) {
804 /* general register */
805 if (UCOP_REG_D == 31) {
808 if (UCOP_SET(24)) { /* MFF */
809 tmp = ucf64_gen_ld32(UCOP_REG_N);
810 store_reg(s, UCOP_REG_D, tmp);
812 tmp = load_reg(s, UCOP_REG_D);
813 ucf64_gen_st32(tmp, UCOP_REG_N);
817 if ((insn & 0xfb000000) == 0xe9000000) {
819 if (UCOP_REG_D != 31) {
822 if (UCOP_UCF64_COND & 0x8) {
827 tcg_gen_movi_i32(tmp, UCOP_UCF64_COND);
829 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_N));
830 tcg_gen_ld_i64(cpu_F1d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
831 gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, tmp, cpu_env);
833 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_N));
834 tcg_gen_ld_i32(cpu_F1s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
835 gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, tmp, cpu_env);
843 /* UniCore-F64 convert instructions */
844 static void do_ucf64_fcvt(CPUState *env, DisasContext *s, uint32_t insn)
846 if (UCOP_UCF64_FMT == 3) {
849 if (UCOP_REG_N != 0) {
852 switch (UCOP_UCF64_FUNC) {
854 switch (UCOP_UCF64_FMT) {
856 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
857 gen_helper_ucf64_df2sf(cpu_F0s, cpu_F0d, cpu_env);
858 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
861 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
862 gen_helper_ucf64_si2sf(cpu_F0s, cpu_F0s, cpu_env);
863 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
871 switch (UCOP_UCF64_FMT) {
873 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
874 gen_helper_ucf64_sf2df(cpu_F0d, cpu_F0s, cpu_env);
875 tcg_gen_st_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_D));
878 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
879 gen_helper_ucf64_si2df(cpu_F0d, cpu_F0s, cpu_env);
880 tcg_gen_st_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_D));
888 switch (UCOP_UCF64_FMT) {
890 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
891 gen_helper_ucf64_sf2si(cpu_F0s, cpu_F0s, cpu_env);
892 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
895 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
896 gen_helper_ucf64_df2si(cpu_F0s, cpu_F0d, cpu_env);
897 tcg_gen_st_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_D));
909 /* UniCore-F64 compare instructions */
910 static void do_ucf64_fcmp(CPUState *env, DisasContext *s, uint32_t insn)
915 if (UCOP_REG_D != 0) {
921 tcg_gen_ld_i64(cpu_F0d, cpu_env, ucf64_reg_offset(UCOP_REG_N));
922 tcg_gen_ld_i64(cpu_F1d, cpu_env, ucf64_reg_offset(UCOP_REG_M));
923 /* gen_helper_ucf64_cmpd(cpu_F0d, cpu_F1d, cpu_env); */
925 tcg_gen_ld_i32(cpu_F0s, cpu_env, ucf64_reg_offset(UCOP_REG_N));
926 tcg_gen_ld_i32(cpu_F1s, cpu_env, ucf64_reg_offset(UCOP_REG_M));
927 /* gen_helper_ucf64_cmps(cpu_F0s, cpu_F1s, cpu_env); */
931 #define gen_helper_ucf64_movs(x, y) do { } while (0)
932 #define gen_helper_ucf64_movd(x, y) do { } while (0)
934 #define UCF64_OP1(name) do { \
935 if (UCOP_REG_N != 0) { \
938 switch (UCOP_UCF64_FMT) { \
940 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
941 ucf64_reg_offset(UCOP_REG_M)); \
942 gen_helper_ucf64_##name##s(cpu_F0s, cpu_F0s); \
943 tcg_gen_st_i32(cpu_F0s, cpu_env, \
944 ucf64_reg_offset(UCOP_REG_D)); \
947 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
948 ucf64_reg_offset(UCOP_REG_M)); \
949 gen_helper_ucf64_##name##d(cpu_F0d, cpu_F0d); \
950 tcg_gen_st_i64(cpu_F0d, cpu_env, \
951 ucf64_reg_offset(UCOP_REG_D)); \
959 #define UCF64_OP2(name) do { \
960 switch (UCOP_UCF64_FMT) { \
962 tcg_gen_ld_i32(cpu_F0s, cpu_env, \
963 ucf64_reg_offset(UCOP_REG_N)); \
964 tcg_gen_ld_i32(cpu_F1s, cpu_env, \
965 ucf64_reg_offset(UCOP_REG_M)); \
966 gen_helper_ucf64_##name##s(cpu_F0s, \
967 cpu_F0s, cpu_F1s, cpu_env); \
968 tcg_gen_st_i32(cpu_F0s, cpu_env, \
969 ucf64_reg_offset(UCOP_REG_D)); \
972 tcg_gen_ld_i64(cpu_F0d, cpu_env, \
973 ucf64_reg_offset(UCOP_REG_N)); \
974 tcg_gen_ld_i64(cpu_F1d, cpu_env, \
975 ucf64_reg_offset(UCOP_REG_M)); \
976 gen_helper_ucf64_##name##d(cpu_F0d, \
977 cpu_F0d, cpu_F1d, cpu_env); \
978 tcg_gen_st_i64(cpu_F0d, cpu_env, \
979 ucf64_reg_offset(UCOP_REG_D)); \
987 /* UniCore-F64 data processing */
988 static void do_ucf64_datap(CPUState *env, DisasContext *s, uint32_t insn)
990 if (UCOP_UCF64_FMT == 3) {
993 switch (UCOP_UCF64_FUNC) {
1020 /* Disassemble an F64 instruction */
1021 static void disas_ucf64_insn(CPUState *env, DisasContext *s, uint32_t insn)
1023 if (!UCOP_SET(29)) {
1025 do_ucf64_ldst_m(env, s, insn);
1027 do_ucf64_ldst_i(env, s, insn);
1031 switch ((insn >> 26) & 0x3) {
1033 do_ucf64_datap(env, s, insn);
1039 do_ucf64_fcvt(env, s, insn);
1042 do_ucf64_fcmp(env, s, insn);
1046 do_ucf64_trans(env, s, insn);
1051 static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
1053 TranslationBlock *tb;
1056 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1058 gen_set_pc_im(dest);
1059 tcg_gen_exit_tb((tcg_target_long)tb + n);
1061 gen_set_pc_im(dest);
1066 static inline void gen_jmp(DisasContext *s, uint32_t dest)
1068 if (unlikely(s->singlestep_enabled)) {
1069 /* An indirect jump so that we still trigger the debug exception. */
1072 gen_goto_tb(s, 0, dest);
1073 s->is_jmp = DISAS_TB_JUMP;
1077 static inline void gen_mulxy(TCGv t0, TCGv t1, int x, int y)
1080 tcg_gen_sari_i32(t0, t0, 16);
1085 tcg_gen_sari_i32(t1, t1, 16);
1089 tcg_gen_mul_i32(t0, t0, t1);
1092 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
1093 static int gen_set_psr(DisasContext *s, uint32_t mask, int bsr, TCGv t0)
1097 /* ??? This is also undefined in system mode. */
1102 tmp = load_cpu_field(bsr);
1103 tcg_gen_andi_i32(tmp, tmp, ~mask);
1104 tcg_gen_andi_i32(t0, t0, mask);
1105 tcg_gen_or_i32(tmp, tmp, t0);
1106 store_cpu_field(tmp, bsr);
1108 gen_set_asr(t0, mask);
1115 /* Generate an old-style exception return. Marks pc as dead. */
1116 static void gen_exception_return(DisasContext *s, TCGv pc)
1119 store_reg(s, 31, pc);
1120 tmp = load_cpu_field(bsr);
1121 gen_set_asr(tmp, 0xffffffff);
1123 s->is_jmp = DISAS_UPDATE;
1126 static void disas_coproc_insn(CPUState *env, DisasContext *s, uint32_t insn)
1128 switch (UCOP_CPNUM) {
1130 disas_ucf64_insn(env, s, insn);
1133 /* Unknown coprocessor. */
1134 cpu_abort(env, "Unknown coprocessor!");
1139 /* Store a 64-bit value to a register pair. Clobbers val. */
1140 static void gen_storeq_reg(DisasContext *s, int rlow, int rhigh, TCGv_i64 val)
1144 tcg_gen_trunc_i64_i32(tmp, val);
1145 store_reg(s, rlow, tmp);
1147 tcg_gen_shri_i64(val, val, 32);
1148 tcg_gen_trunc_i64_i32(tmp, val);
1149 store_reg(s, rhigh, tmp);
1152 /* load and add a 64-bit value from a register pair. */
1153 static void gen_addq(DisasContext *s, TCGv_i64 val, int rlow, int rhigh)
1159 /* Load 64-bit value rd:rn. */
1160 tmpl = load_reg(s, rlow);
1161 tmph = load_reg(s, rhigh);
1162 tmp = tcg_temp_new_i64();
1163 tcg_gen_concat_i32_i64(tmp, tmpl, tmph);
1166 tcg_gen_add_i64(val, val, tmp);
1167 tcg_temp_free_i64(tmp);
1170 /* data processing instructions */
1171 static void do_datap(CPUState *env, DisasContext *s, uint32_t insn)
1177 if (UCOP_OPCODES == 0x0f || UCOP_OPCODES == 0x0d) {
1178 if (UCOP_SET(23)) { /* CMOV instructions */
1179 if ((UCOP_CMOV_COND == 0xe) || (UCOP_CMOV_COND == 0xf)) {
1182 /* if not always execute, we generate a conditional jump to
1184 s->condlabel = gen_new_label();
1185 gen_test_cc(UCOP_CMOV_COND ^ 1, s->condlabel);
1190 logic_cc = table_logic_cc[UCOP_OPCODES] & (UCOP_SET_S >> 24);
1194 /* immediate operand */
1197 val = (val >> UCOP_SH_IM) | (val << (32 - UCOP_SH_IM));
1200 tcg_gen_movi_i32(tmp2, val);
1201 if (logic_cc && UCOP_SH_IM) {
1202 gen_set_CF_bit31(tmp2);
1206 tmp2 = load_reg(s, UCOP_REG_M);
1208 tmp = load_reg(s, UCOP_REG_S);
1209 gen_uc32_shift_reg(tmp2, UCOP_SH_OP, tmp, logic_cc);
1211 gen_uc32_shift_im(tmp2, UCOP_SH_OP, UCOP_SH_IM, logic_cc);
1215 if (UCOP_OPCODES != 0x0f && UCOP_OPCODES != 0x0d) {
1216 tmp = load_reg(s, UCOP_REG_N);
1221 switch (UCOP_OPCODES) {
1223 tcg_gen_and_i32(tmp, tmp, tmp2);
1227 store_reg_bx(s, UCOP_REG_D, tmp);
1230 tcg_gen_xor_i32(tmp, tmp, tmp2);
1234 store_reg_bx(s, UCOP_REG_D, tmp);
1237 if (UCOP_SET_S && UCOP_REG_D == 31) {
1238 /* SUBS r31, ... is used for exception return. */
1242 gen_helper_sub_cc(tmp, tmp, tmp2);
1243 gen_exception_return(s, tmp);
1246 gen_helper_sub_cc(tmp, tmp, tmp2);
1248 tcg_gen_sub_i32(tmp, tmp, tmp2);
1250 store_reg_bx(s, UCOP_REG_D, tmp);
1255 gen_helper_sub_cc(tmp, tmp2, tmp);
1257 tcg_gen_sub_i32(tmp, tmp2, tmp);
1259 store_reg_bx(s, UCOP_REG_D, tmp);
1263 gen_helper_add_cc(tmp, tmp, tmp2);
1265 tcg_gen_add_i32(tmp, tmp, tmp2);
1267 store_reg_bx(s, UCOP_REG_D, tmp);
1271 gen_helper_adc_cc(tmp, tmp, tmp2);
1273 gen_add_carry(tmp, tmp, tmp2);
1275 store_reg_bx(s, UCOP_REG_D, tmp);
1279 gen_helper_sbc_cc(tmp, tmp, tmp2);
1281 gen_sub_carry(tmp, tmp, tmp2);
1283 store_reg_bx(s, UCOP_REG_D, tmp);
1287 gen_helper_sbc_cc(tmp, tmp2, tmp);
1289 gen_sub_carry(tmp, tmp2, tmp);
1291 store_reg_bx(s, UCOP_REG_D, tmp);
1295 tcg_gen_and_i32(tmp, tmp, tmp2);
1302 tcg_gen_xor_i32(tmp, tmp, tmp2);
1309 gen_helper_sub_cc(tmp, tmp, tmp2);
1315 gen_helper_add_cc(tmp, tmp, tmp2);
1320 tcg_gen_or_i32(tmp, tmp, tmp2);
1324 store_reg_bx(s, UCOP_REG_D, tmp);
1327 if (logic_cc && UCOP_REG_D == 31) {
1328 /* MOVS r31, ... is used for exception return. */
1332 gen_exception_return(s, tmp2);
1337 store_reg_bx(s, UCOP_REG_D, tmp2);
1341 tcg_gen_andc_i32(tmp, tmp, tmp2);
1345 store_reg_bx(s, UCOP_REG_D, tmp);
1349 tcg_gen_not_i32(tmp2, tmp2);
1353 store_reg_bx(s, UCOP_REG_D, tmp2);
1356 if (UCOP_OPCODES != 0x0f && UCOP_OPCODES != 0x0d) {
1362 static void do_mult(CPUState *env, DisasContext *s, uint32_t insn)
1370 tmp = load_reg(s, UCOP_REG_M);
1371 tmp2 = load_reg(s, UCOP_REG_N);
1373 tmp64 = gen_muls_i64_i32(tmp, tmp2);
1375 tmp64 = gen_mulu_i64_i32(tmp, tmp2);
1377 if (UCOP_SET(25)) { /* mult accumulate */
1378 gen_addq(s, tmp64, UCOP_REG_LO, UCOP_REG_HI);
1380 gen_storeq_reg(s, UCOP_REG_LO, UCOP_REG_HI, tmp64);
1381 tcg_temp_free_i64(tmp64);
1384 tmp = load_reg(s, UCOP_REG_M);
1385 tmp2 = load_reg(s, UCOP_REG_N);
1386 tcg_gen_mul_i32(tmp, tmp, tmp2);
1390 tmp2 = load_reg(s, UCOP_REG_S);
1391 tcg_gen_add_i32(tmp, tmp, tmp2);
1397 store_reg(s, UCOP_REG_D, tmp);
1401 /* miscellaneous instructions */
1402 static void do_misc(CPUState *env, DisasContext *s, uint32_t insn)
1407 if ((insn & 0xffffffe0) == 0x10ffc120) {
1408 /* Trivial implementation equivalent to bx. */
1409 tmp = load_reg(s, UCOP_REG_M);
1414 if ((insn & 0xfbffc000) == 0x30ffc000) {
1415 /* PSR = immediate */
1418 val = (val >> UCOP_SH_IM) | (val << (32 - UCOP_SH_IM));
1421 tcg_gen_movi_i32(tmp, val);
1422 if (gen_set_psr(s, ~ASR_RESERVED, UCOP_SET_B, tmp)) {
1428 if ((insn & 0xfbffffe0) == 0x12ffc020) {
1429 /* PSR.flag = reg */
1430 tmp = load_reg(s, UCOP_REG_M);
1431 if (gen_set_psr(s, ASR_NZCV, UCOP_SET_B, tmp)) {
1437 if ((insn & 0xfbffffe0) == 0x10ffc020) {
1439 tmp = load_reg(s, UCOP_REG_M);
1440 if (gen_set_psr(s, ~ASR_RESERVED, UCOP_SET_B, tmp)) {
1446 if ((insn & 0xfbf83fff) == 0x10f80000) {
1452 tmp = load_cpu_field(bsr);
1455 gen_helper_asr_read(tmp);
1457 store_reg(s, UCOP_REG_D, tmp);
1461 if ((insn & 0xfbf83fe0) == 0x12f80120) {
1463 tmp = load_reg(s, UCOP_REG_M);
1465 gen_helper_clo(tmp, tmp);
1467 gen_helper_clz(tmp, tmp);
1469 store_reg(s, UCOP_REG_D, tmp);
1477 /* load/store I_offset and R_offset */
1478 static void do_ldst_ir(CPUState *env, DisasContext *s, uint32_t insn)
1484 tmp2 = load_reg(s, UCOP_REG_N);
1485 i = (IS_USER(s) || (!UCOP_SET_P && UCOP_SET_W));
1489 gen_add_data_offset(s, insn, tmp2);
1495 tmp = gen_ld8u(tmp2, i);
1497 tmp = gen_ld32(tmp2, i);
1501 tmp = load_reg(s, UCOP_REG_D);
1503 gen_st8(tmp, tmp2, i);
1505 gen_st32(tmp, tmp2, i);
1509 gen_add_data_offset(s, insn, tmp2);
1510 store_reg(s, UCOP_REG_N, tmp2);
1511 } else if (UCOP_SET_W) {
1512 store_reg(s, UCOP_REG_N, tmp2);
1517 /* Complete the load. */
1518 if (UCOP_REG_D == 31) {
1521 store_reg(s, UCOP_REG_D, tmp);
1526 /* SWP instruction */
1527 static void do_swap(CPUState *env, DisasContext *s, uint32_t insn)
1533 if ((insn & 0xff003fe0) != 0x40000120) {
1537 /* ??? This is not really atomic. However we know
1538 we never have multiple CPUs running in parallel,
1539 so it is good enough. */
1540 addr = load_reg(s, UCOP_REG_N);
1541 tmp = load_reg(s, UCOP_REG_M);
1543 tmp2 = gen_ld8u(addr, IS_USER(s));
1544 gen_st8(tmp, addr, IS_USER(s));
1546 tmp2 = gen_ld32(addr, IS_USER(s));
1547 gen_st32(tmp, addr, IS_USER(s));
1550 store_reg(s, UCOP_REG_D, tmp2);
1553 /* load/store hw/sb */
1554 static void do_ldst_hwsb(CPUState *env, DisasContext *s, uint32_t insn)
1559 if (UCOP_SH_OP == 0) {
1560 do_swap(env, s, insn);
1564 addr = load_reg(s, UCOP_REG_N);
1566 gen_add_datah_offset(s, insn, addr);
1569 if (UCOP_SET_L) { /* load */
1570 switch (UCOP_SH_OP) {
1572 tmp = gen_ld16u(addr, IS_USER(s));
1575 tmp = gen_ld8s(addr, IS_USER(s));
1577 default: /* see do_swap */
1579 tmp = gen_ld16s(addr, IS_USER(s));
1582 } else { /* store */
1583 if (UCOP_SH_OP != 1) {
1586 tmp = load_reg(s, UCOP_REG_D);
1587 gen_st16(tmp, addr, IS_USER(s));
1589 /* Perform base writeback before the loaded value to
1590 ensure correct behavior with overlapping index registers. */
1592 gen_add_datah_offset(s, insn, addr);
1593 store_reg(s, UCOP_REG_N, addr);
1594 } else if (UCOP_SET_W) {
1595 store_reg(s, UCOP_REG_N, addr);
1600 /* Complete the load. */
1601 store_reg(s, UCOP_REG_D, tmp);
1605 /* load/store multiple words */
1606 static void do_ldst_m(CPUState *env, DisasContext *s, uint32_t insn)
1608 unsigned int val, i;
1609 int j, n, reg, user, loaded_base;
1618 /* XXX: store correct base if write back */
1620 if (UCOP_SET_B) { /* S bit in instruction table */
1622 ILLEGAL; /* only usable in supervisor mode */
1624 if (UCOP_SET(18) == 0) { /* pc reg */
1629 addr = load_reg(s, UCOP_REG_N);
1631 /* compute total size */
1633 TCGV_UNUSED(loaded_var);
1635 for (i = 0; i < 6; i++) {
1640 for (i = 9; i < 19; i++) {
1645 /* XXX: test invalid n == 0 case ? */
1649 tcg_gen_addi_i32(addr, addr, 4);
1651 /* post increment */
1656 tcg_gen_addi_i32(addr, addr, -(n * 4));
1658 /* post decrement */
1660 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
1666 reg = UCOP_SET(6) ? 16 : 0;
1667 for (i = 0; i < 19; i++, reg++) {
1672 if (UCOP_SET_L) { /* load */
1673 tmp = gen_ld32(addr, IS_USER(s));
1677 tmp2 = tcg_const_i32(reg);
1678 gen_helper_set_user_reg(tmp2, tmp);
1679 tcg_temp_free_i32(tmp2);
1681 } else if (reg == UCOP_REG_N) {
1685 store_reg(s, reg, tmp);
1687 } else { /* store */
1689 /* special case: r31 = PC + 4 */
1692 tcg_gen_movi_i32(tmp, val);
1695 tmp2 = tcg_const_i32(reg);
1696 gen_helper_get_user_reg(tmp, tmp2);
1697 tcg_temp_free_i32(tmp2);
1699 tmp = load_reg(s, reg);
1701 gen_st32(tmp, addr, IS_USER(s));
1704 /* no need to add after the last transfer */
1706 tcg_gen_addi_i32(addr, addr, 4);
1710 if (UCOP_SET_W) { /* write back */
1715 /* post increment */
1716 tcg_gen_addi_i32(addr, addr, 4);
1722 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
1725 /* post decrement */
1726 tcg_gen_addi_i32(addr, addr, -(n * 4));
1729 store_reg(s, UCOP_REG_N, addr);
1734 store_reg(s, UCOP_REG_N, loaded_var);
1736 if (UCOP_SET_B && !user) {
1737 /* Restore ASR from BSR. */
1738 tmp = load_cpu_field(bsr);
1739 gen_set_asr(tmp, 0xffffffff);
1741 s->is_jmp = DISAS_UPDATE;
1745 /* branch (and link) */
1746 static void do_branch(CPUState *env, DisasContext *s, uint32_t insn)
1752 if (UCOP_COND == 0xf) {
1756 if (UCOP_COND != 0xe) {
1757 /* if not always execute, we generate a conditional jump to
1759 s->condlabel = gen_new_label();
1760 gen_test_cc(UCOP_COND ^ 1, s->condlabel);
1764 val = (int32_t)s->pc;
1767 tcg_gen_movi_i32(tmp, val);
1768 store_reg(s, 30, tmp);
1770 offset = (((int32_t)insn << 8) >> 8);
1771 val += (offset << 2); /* unicore is pc+4 */
1775 static void disas_uc32_insn(CPUState *env, DisasContext *s)
1779 insn = ldl_code(s->pc);
1782 /* UniCore instructions class:
1783 * AAAB BBBC xxxx xxxx xxxx xxxD xxEx xxxx
1784 * AAA : see switch case
1785 * BBBB : opcodes or cond or PUBW
1790 switch (insn >> 29) {
1792 if (UCOP_SET(5) && UCOP_SET(8) && !UCOP_SET(28)) {
1793 do_mult(env, s, insn);
1798 do_misc(env, s, insn);
1802 if (((UCOP_OPCODES >> 2) == 2) && !UCOP_SET_S) {
1803 do_misc(env, s, insn);
1806 do_datap(env, s, insn);
1810 if (UCOP_SET(8) && UCOP_SET(5)) {
1811 do_ldst_hwsb(env, s, insn);
1814 if (UCOP_SET(8) || UCOP_SET(5)) {
1818 do_ldst_ir(env, s, insn);
1823 ILLEGAL; /* extended instructions */
1825 do_ldst_m(env, s, insn);
1828 do_branch(env, s, insn);
1832 disas_coproc_insn(env, s, insn);
1835 if (!UCOP_SET(28)) {
1836 disas_coproc_insn(env, s, insn);
1839 if ((insn & 0xff000000) == 0xff000000) { /* syscall */
1840 gen_set_pc_im(s->pc);
1841 s->is_jmp = DISAS_SYSCALL;
1850 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
1851 basic block 'tb'. If search_pc is TRUE, also generate PC
1852 information for each intermediate instruction. */
1853 static inline void gen_intermediate_code_internal(CPUState *env,
1854 TranslationBlock *tb, int search_pc)
1856 DisasContext dc1, *dc = &dc1;
1858 uint16_t *gen_opc_end;
1860 target_ulong pc_start;
1861 uint32_t next_page_start;
1865 /* generate intermediate code */
1872 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
1874 dc->is_jmp = DISAS_NEXT;
1876 dc->singlestep_enabled = env->singlestep_enabled;
1878 cpu_F0s = tcg_temp_new_i32();
1879 cpu_F1s = tcg_temp_new_i32();
1880 cpu_F0d = tcg_temp_new_i64();
1881 cpu_F1d = tcg_temp_new_i64();
1882 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
1885 max_insns = tb->cflags & CF_COUNT_MASK;
1886 if (max_insns == 0) {
1887 max_insns = CF_COUNT_MASK;
1892 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
1893 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
1894 if (bp->pc == dc->pc) {
1895 gen_set_pc_im(dc->pc);
1896 gen_exception(EXCP_DEBUG);
1897 dc->is_jmp = DISAS_JUMP;
1898 /* Advance PC so that clearing the breakpoint will
1899 invalidate this TB. */
1900 dc->pc += 2; /* FIXME */
1901 goto done_generating;
1907 j = gen_opc_ptr - gen_opc_buf;
1911 gen_opc_instr_start[lj++] = 0;
1914 gen_opc_pc[lj] = dc->pc;
1915 gen_opc_instr_start[lj] = 1;
1916 gen_opc_icount[lj] = num_insns;
1919 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {
1923 disas_uc32_insn(env, dc);
1926 fprintf(stderr, "Internal resource leak before %08x\n", dc->pc);
1930 if (dc->condjmp && !dc->is_jmp) {
1931 gen_set_label(dc->condlabel);
1934 /* Translation stops when a conditional branch is encountered.
1935 * Otherwise the subsequent code could get translated several times.
1936 * Also stop translation when a page boundary is reached. This
1937 * ensures prefetch aborts occur at the right place. */
1939 } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
1940 !env->singlestep_enabled &&
1942 dc->pc < next_page_start &&
1943 num_insns < max_insns);
1945 if (tb->cflags & CF_LAST_IO) {
1947 /* FIXME: This can theoretically happen with self-modifying
1949 cpu_abort(env, "IO on conditional branch instruction");
1954 /* At this stage dc->condjmp will only be set when the skipped
1955 instruction was a conditional branch or trap, and the PC has
1956 already been written. */
1957 if (unlikely(env->singlestep_enabled)) {
1958 /* Make sure the pc is updated, and raise a debug exception. */
1960 if (dc->is_jmp == DISAS_SYSCALL) {
1961 gen_exception(UC32_EXCP_PRIV);
1963 gen_exception(EXCP_DEBUG);
1965 gen_set_label(dc->condlabel);
1967 if (dc->condjmp || !dc->is_jmp) {
1968 gen_set_pc_im(dc->pc);
1971 if (dc->is_jmp == DISAS_SYSCALL && !dc->condjmp) {
1972 gen_exception(UC32_EXCP_PRIV);
1974 gen_exception(EXCP_DEBUG);
1977 /* While branches must always occur at the end of an IT block,
1978 there are a few other things that can cause us to terminate
1979 the TB in the middel of an IT block:
1980 - Exception generating instructions (bkpt, swi, undefined).
1982 - Hardware watchpoints.
1983 Hardware breakpoints have already been handled and skip this code.
1985 switch (dc->is_jmp) {
1987 gen_goto_tb(dc, 1, dc->pc);
1992 /* indicate that the hash table must be used to find the next TB */
1996 /* nothing more to generate */
1999 gen_exception(UC32_EXCP_PRIV);
2003 gen_set_label(dc->condlabel);
2004 gen_goto_tb(dc, 1, dc->pc);
2010 gen_icount_end(tb, num_insns);
2011 *gen_opc_ptr = INDEX_op_end;
2014 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
2015 qemu_log("----------------\n");
2016 qemu_log("IN: %s\n", lookup_symbol(pc_start));
2017 log_target_disas(pc_start, dc->pc - pc_start, 0);
2022 j = gen_opc_ptr - gen_opc_buf;
2025 gen_opc_instr_start[lj++] = 0;
2028 tb->size = dc->pc - pc_start;
2029 tb->icount = num_insns;
2033 void gen_intermediate_code(CPUState *env, TranslationBlock *tb)
2035 gen_intermediate_code_internal(env, tb, 0);
2038 void gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
2040 gen_intermediate_code_internal(env, tb, 1);
2043 static const char *cpu_mode_names[16] = {
2044 "USER", "REAL", "INTR", "PRIV", "UM14", "UM15", "UM16", "TRAP",
2045 "UM18", "UM19", "UM1A", "EXTN", "UM1C", "UM1D", "UM1E", "SUSR"
2048 #define UCF64_DUMP_STATE
2049 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
2053 #ifdef UCF64_DUMP_STATE
2059 /* ??? This assumes float64 and double have the same layout.
2060 Oh well, it's only debug dumps. */
2068 for (i = 0; i < 32; i++) {
2069 cpu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
2071 cpu_fprintf(f, "\n");
2073 cpu_fprintf(f, " ");
2076 psr = cpu_asr_read(env);
2077 cpu_fprintf(f, "PSR=%08x %c%c%c%c %s\n",
2079 psr & (1 << 31) ? 'N' : '-',
2080 psr & (1 << 30) ? 'Z' : '-',
2081 psr & (1 << 29) ? 'C' : '-',
2082 psr & (1 << 28) ? 'V' : '-',
2083 cpu_mode_names[psr & 0xf]);
2085 #ifdef UCF64_DUMP_STATE
2086 for (i = 0; i < 16; i++) {
2087 d.d = env->ucf64.regs[i];
2091 cpu_fprintf(f, "s%02d=%08x(%8g) s%02d=%08x(%8g) d%02d=%" PRIx64 "(%8g)\n",
2092 i * 2, (int)s0.i, s0.s,
2093 i * 2 + 1, (int)s1.i, s1.s,
2094 i, (uint64_t)d0.f64, d0.d);
2096 cpu_fprintf(f, "FPSCR: %08x\n", (int)env->ucf64.xregs[UC32_UCF64_FPSCR]);
2100 void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
2102 env->regs[31] = gen_opc_pc[pc_pos];