2 * Xilinx MicroBlaze emulation for qemu: main translation routines.
4 * Copyright (c) 2009 Edgar E. Iglesias.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
32 #include "microblaze-decode.h"
33 #include "qemu-common.h"
41 #if DISAS_MB && !SIM_COMPAT
42 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
44 # define LOG_DIS(...) do { } while (0)
49 #define EXTRACT_FIELD(src, start, end) \
50 (((src) >> start) & ((1 << (end - start + 1)) - 1))
52 static TCGv env_debug
;
53 static TCGv_ptr cpu_env
;
54 static TCGv cpu_R
[32];
55 static TCGv cpu_SR
[18];
57 static TCGv env_btaken
;
58 static TCGv env_btarget
;
59 static TCGv env_iflags
;
61 #include "gen-icount.h"
63 /* This is the state at translation time. */
64 typedef struct DisasContext
{
75 unsigned int cpustate_changed
;
76 unsigned int delayed_branch
;
77 unsigned int tb_flags
, synced_flags
; /* tb dependent flags. */
78 unsigned int clear_imm
;
83 #define JMP_INDIRECT 2
87 int abort_at_next_insn
;
89 struct TranslationBlock
*tb
;
90 int singlestep_enabled
;
93 static const char *regnames
[] =
95 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
96 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
97 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
98 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
101 static const char *special_regnames
[] =
103 "rpc", "rmsr", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
104 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
105 "sr16", "sr17", "sr18"
108 /* Sign extend at translation time. */
109 static inline int sign_extend(unsigned int val
, unsigned int width
)
121 static inline void t_sync_flags(DisasContext
*dc
)
123 /* Synch the tb dependant flags between translator and runtime. */
124 if (dc
->tb_flags
!= dc
->synced_flags
) {
125 tcg_gen_movi_tl(env_iflags
, dc
->tb_flags
);
126 dc
->synced_flags
= dc
->tb_flags
;
130 static inline void t_gen_raise_exception(DisasContext
*dc
, uint32_t index
)
132 TCGv_i32 tmp
= tcg_const_i32(index
);
135 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
136 gen_helper_raise_exception(tmp
);
137 tcg_temp_free_i32(tmp
);
138 dc
->is_jmp
= DISAS_UPDATE
;
141 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
143 TranslationBlock
*tb
;
145 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
147 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dest
);
148 tcg_gen_exit_tb((long)tb
+ n
);
150 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dest
);
155 /* True if ALU operand b is a small immediate that may deserve
157 static inline int dec_alu_op_b_is_small_imm(DisasContext
*dc
)
159 /* Immediate insn without the imm prefix ? */
160 return dc
->type_b
&& !(dc
->tb_flags
& IMM_FLAG
);
163 static inline TCGv
*dec_alu_op_b(DisasContext
*dc
)
166 if (dc
->tb_flags
& IMM_FLAG
)
167 tcg_gen_ori_tl(env_imm
, env_imm
, dc
->imm
);
169 tcg_gen_movi_tl(env_imm
, (int32_t)((int16_t)dc
->imm
));
172 return &cpu_R
[dc
->rb
];
175 static void dec_add(DisasContext
*dc
)
182 LOG_DIS("add%s%s%s r%d r%d r%d\n",
183 dc
->type_b
? "i" : "", k
? "k" : "", c
? "c" : "",
184 dc
->rd
, dc
->ra
, dc
->rb
);
186 if (k
&& !c
&& dc
->rd
)
187 tcg_gen_add_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
189 gen_helper_addkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
190 tcg_const_tl(k
), tcg_const_tl(c
));
192 TCGv d
= tcg_temp_new();
193 gen_helper_addkc(d
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
194 tcg_const_tl(k
), tcg_const_tl(c
));
199 static void dec_sub(DisasContext
*dc
)
201 unsigned int u
, cmp
, k
, c
;
206 cmp
= (dc
->imm
& 1) && (!dc
->type_b
) && k
;
209 LOG_DIS("cmp%s r%d, r%d ir=%x\n", u
? "u" : "", dc
->rd
, dc
->ra
, dc
->ir
);
212 gen_helper_cmpu(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
214 gen_helper_cmp(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
217 LOG_DIS("sub%s%s r%d, r%d r%d\n",
218 k
? "k" : "", c
? "c" : "", dc
->rd
, dc
->ra
, dc
->rb
);
224 gen_helper_subkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
225 tcg_const_tl(k
), tcg_const_tl(c
));
227 gen_helper_subkc(t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
228 tcg_const_tl(k
), tcg_const_tl(c
));
232 tcg_gen_sub_tl(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
236 static void dec_pattern(DisasContext
*dc
)
241 if ((dc
->tb_flags
& MSR_EE_FLAG
)
242 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
243 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_PCMP_INSTR
))) {
244 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
245 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
248 mode
= dc
->opcode
& 3;
252 LOG_DIS("pcmpbf r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
254 gen_helper_pcmpbf(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
257 LOG_DIS("pcmpeq r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
259 TCGv t0
= tcg_temp_local_new();
260 l1
= gen_new_label();
261 tcg_gen_movi_tl(t0
, 1);
262 tcg_gen_brcond_tl(TCG_COND_EQ
,
263 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
264 tcg_gen_movi_tl(t0
, 0);
266 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
271 LOG_DIS("pcmpne r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
272 l1
= gen_new_label();
274 TCGv t0
= tcg_temp_local_new();
275 tcg_gen_movi_tl(t0
, 1);
276 tcg_gen_brcond_tl(TCG_COND_NE
,
277 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
278 tcg_gen_movi_tl(t0
, 0);
280 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
286 "unsupported pattern insn opcode=%x\n", dc
->opcode
);
291 static void dec_and(DisasContext
*dc
)
295 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
300 not = dc
->opcode
& (1 << 1);
301 LOG_DIS("and%s\n", not ? "n" : "");
307 TCGv t
= tcg_temp_new();
308 tcg_gen_not_tl(t
, *(dec_alu_op_b(dc
)));
309 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t
);
312 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
315 static void dec_or(DisasContext
*dc
)
317 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
322 LOG_DIS("or r%d r%d r%d imm=%x\n", dc
->rd
, dc
->ra
, dc
->rb
, dc
->imm
);
324 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
327 static void dec_xor(DisasContext
*dc
)
329 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
334 LOG_DIS("xor r%d\n", dc
->rd
);
336 tcg_gen_xor_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
339 static void read_carry(DisasContext
*dc
, TCGv d
)
341 tcg_gen_shri_tl(d
, cpu_SR
[SR_MSR
], 31);
344 static void write_carry(DisasContext
*dc
, TCGv v
)
346 TCGv t0
= tcg_temp_new();
347 tcg_gen_shli_tl(t0
, v
, 31);
348 tcg_gen_sari_tl(t0
, t0
, 31);
349 tcg_gen_mov_tl(env_debug
, t0
);
350 tcg_gen_andi_tl(t0
, t0
, (MSR_C
| MSR_CC
));
351 tcg_gen_andi_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
],
353 tcg_gen_or_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], t0
);
358 static inline void msr_read(DisasContext
*dc
, TCGv d
)
360 tcg_gen_mov_tl(d
, cpu_SR
[SR_MSR
]);
363 static inline void msr_write(DisasContext
*dc
, TCGv v
)
365 dc
->cpustate_changed
= 1;
366 tcg_gen_mov_tl(cpu_SR
[SR_MSR
], v
);
367 /* PVR, we have a processor version register. */
368 tcg_gen_ori_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], (1 << 10));
371 static void dec_msr(DisasContext
*dc
)
374 unsigned int sr
, to
, rn
;
375 int mem_index
= cpu_mmu_index(dc
->env
);
377 sr
= dc
->imm
& ((1 << 14) - 1);
378 to
= dc
->imm
& (1 << 14);
381 dc
->cpustate_changed
= 1;
383 /* msrclr and msrset. */
384 if (!(dc
->imm
& (1 << 15))) {
385 unsigned int clr
= dc
->ir
& (1 << 16);
387 LOG_DIS("msr%s r%d imm=%x\n", clr
? "clr" : "set",
390 if (!(dc
->env
->pvr
.regs
[2] & PVR2_USE_MSR_INSTR
)) {
395 if ((dc
->tb_flags
& MSR_EE_FLAG
)
396 && mem_index
== MMU_USER_IDX
&& (dc
->imm
!= 4 && dc
->imm
!= 0)) {
397 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
398 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
403 msr_read(dc
, cpu_R
[dc
->rd
]);
408 tcg_gen_mov_tl(t1
, *(dec_alu_op_b(dc
)));
411 tcg_gen_not_tl(t1
, t1
);
412 tcg_gen_and_tl(t0
, t0
, t1
);
414 tcg_gen_or_tl(t0
, t0
, t1
);
418 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
+ 4);
419 dc
->is_jmp
= DISAS_UPDATE
;
424 if ((dc
->tb_flags
& MSR_EE_FLAG
)
425 && mem_index
== MMU_USER_IDX
) {
426 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
427 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
432 #if !defined(CONFIG_USER_ONLY)
433 /* Catch read/writes to the mmu block. */
434 if ((sr
& ~0xff) == 0x1000) {
436 LOG_DIS("m%ss sr%d r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
438 gen_helper_mmu_write(tcg_const_tl(sr
), cpu_R
[dc
->ra
]);
440 gen_helper_mmu_read(cpu_R
[dc
->rd
], tcg_const_tl(sr
));
446 LOG_DIS("m%ss sr%x r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
451 msr_write(dc
, cpu_R
[dc
->ra
]);
454 tcg_gen_mov_tl(cpu_SR
[SR_EAR
], cpu_R
[dc
->ra
]);
457 tcg_gen_mov_tl(cpu_SR
[SR_ESR
], cpu_R
[dc
->ra
]);
460 tcg_gen_andi_tl(cpu_SR
[SR_FSR
], cpu_R
[dc
->ra
], 31);
463 cpu_abort(dc
->env
, "unknown mts reg %x\n", sr
);
467 LOG_DIS("m%ss r%d sr%x imm=%x\n", to
? "t" : "f", dc
->rd
, sr
, dc
->imm
);
471 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
474 msr_read(dc
, cpu_R
[dc
->rd
]);
477 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_EAR
]);
480 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_ESR
]);
483 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_FSR
]);
486 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_BTR
]);
502 tcg_gen_ld_tl(cpu_R
[dc
->rd
],
503 cpu_env
, offsetof(CPUState
, pvr
.regs
[rn
]));
506 cpu_abort(dc
->env
, "unknown mfs reg %x\n", sr
);
512 tcg_gen_movi_tl(cpu_R
[0], 0);
516 /* 64-bit signed mul, lower result in d and upper in d2. */
517 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
521 t0
= tcg_temp_new_i64();
522 t1
= tcg_temp_new_i64();
524 tcg_gen_ext_i32_i64(t0
, a
);
525 tcg_gen_ext_i32_i64(t1
, b
);
526 tcg_gen_mul_i64(t0
, t0
, t1
);
528 tcg_gen_trunc_i64_i32(d
, t0
);
529 tcg_gen_shri_i64(t0
, t0
, 32);
530 tcg_gen_trunc_i64_i32(d2
, t0
);
532 tcg_temp_free_i64(t0
);
533 tcg_temp_free_i64(t1
);
536 /* 64-bit unsigned muls, lower result in d and upper in d2. */
537 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
541 t0
= tcg_temp_new_i64();
542 t1
= tcg_temp_new_i64();
544 tcg_gen_extu_i32_i64(t0
, a
);
545 tcg_gen_extu_i32_i64(t1
, b
);
546 tcg_gen_mul_i64(t0
, t0
, t1
);
548 tcg_gen_trunc_i64_i32(d
, t0
);
549 tcg_gen_shri_i64(t0
, t0
, 32);
550 tcg_gen_trunc_i64_i32(d2
, t0
);
552 tcg_temp_free_i64(t0
);
553 tcg_temp_free_i64(t1
);
556 /* Multiplier unit. */
557 static void dec_mul(DisasContext
*dc
)
560 unsigned int subcode
;
562 if ((dc
->tb_flags
& MSR_EE_FLAG
)
563 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
564 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_HW_MUL_MASK
)) {
565 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
566 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
570 subcode
= dc
->imm
& 3;
571 d
[0] = tcg_temp_new();
572 d
[1] = tcg_temp_new();
575 LOG_DIS("muli r%d r%d %x\n", dc
->rd
, dc
->ra
, dc
->imm
);
576 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
580 /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */
581 if (subcode
>= 1 && subcode
<= 3
582 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_MUL64_MASK
))) {
588 LOG_DIS("mul r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
589 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
592 LOG_DIS("mulh r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
593 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
596 LOG_DIS("mulhsu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
597 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
600 LOG_DIS("mulhu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
601 t_gen_mulu(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
604 cpu_abort(dc
->env
, "unknown MUL insn %x\n", subcode
);
613 static void dec_div(DisasContext
*dc
)
620 if ((dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
621 && !((dc
->env
->pvr
.regs
[0] & PVR0_USE_DIV_MASK
))) {
622 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
623 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
627 gen_helper_divu(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
629 gen_helper_divs(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
631 tcg_gen_movi_tl(cpu_R
[dc
->rd
], 0);
634 static void dec_barrel(DisasContext
*dc
)
639 if ((dc
->tb_flags
& MSR_EE_FLAG
)
640 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
641 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_BARREL_MASK
)) {
642 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
643 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
647 s
= dc
->imm
& (1 << 10);
648 t
= dc
->imm
& (1 << 9);
650 LOG_DIS("bs%s%s r%d r%d r%d\n",
651 s
? "l" : "r", t
? "a" : "l", dc
->rd
, dc
->ra
, dc
->rb
);
655 tcg_gen_mov_tl(t0
, *(dec_alu_op_b(dc
)));
656 tcg_gen_andi_tl(t0
, t0
, 31);
659 tcg_gen_shl_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
662 tcg_gen_sar_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
664 tcg_gen_shr_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
668 static void dec_bit(DisasContext
*dc
)
672 int mem_index
= cpu_mmu_index(dc
->env
);
674 op
= dc
->ir
& ((1 << 8) - 1);
680 LOG_DIS("src r%d r%d\n", dc
->rd
, dc
->ra
);
681 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
685 tcg_gen_shli_tl(t1
, t1
, 31);
687 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
688 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->rd
], t1
);
701 LOG_DIS("srl r%d r%d\n", dc
->rd
, dc
->ra
);
704 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
709 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
711 tcg_gen_sari_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
715 LOG_DIS("ext8s r%d r%d\n", dc
->rd
, dc
->ra
);
716 tcg_gen_ext8s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
719 LOG_DIS("ext16s r%d r%d\n", dc
->rd
, dc
->ra
);
720 tcg_gen_ext16s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
727 LOG_DIS("wdc r%d\n", dc
->ra
);
728 if ((dc
->tb_flags
& MSR_EE_FLAG
)
729 && mem_index
== MMU_USER_IDX
) {
730 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
731 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
737 LOG_DIS("wic r%d\n", dc
->ra
);
738 if ((dc
->tb_flags
& MSR_EE_FLAG
)
739 && mem_index
== MMU_USER_IDX
) {
740 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
741 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
746 cpu_abort(dc
->env
, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n",
747 dc
->pc
, op
, dc
->rd
, dc
->ra
, dc
->rb
);
752 static inline void sync_jmpstate(DisasContext
*dc
)
754 if (dc
->jmp
== JMP_DIRECT
) {
755 dc
->jmp
= JMP_INDIRECT
;
756 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
760 static void dec_imm(DisasContext
*dc
)
762 LOG_DIS("imm %x\n", dc
->imm
<< 16);
763 tcg_gen_movi_tl(env_imm
, (dc
->imm
<< 16));
764 dc
->tb_flags
|= IMM_FLAG
;
768 static inline void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
771 int mem_index
= cpu_mmu_index(dc
->env
);
774 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
775 } else if (size
== 2) {
776 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
777 } else if (size
== 4) {
778 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
780 cpu_abort(dc
->env
, "Incorrect load size %d\n", size
);
783 static inline TCGv
*compute_ldst_addr(DisasContext
*dc
, TCGv
*t
)
785 unsigned int extimm
= dc
->tb_flags
& IMM_FLAG
;
787 /* Treat the fast cases first. */
789 /* If any of the regs is r0, return a ptr to the other. */
791 return &cpu_R
[dc
->rb
];
792 } else if (dc
->rb
== 0) {
793 return &cpu_R
[dc
->ra
];
797 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
803 return &cpu_R
[dc
->ra
];
806 tcg_gen_movi_tl(*t
, (int32_t)((int16_t)dc
->imm
));
807 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *t
);
810 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
816 static void dec_load(DisasContext
*dc
)
821 size
= 1 << (dc
->opcode
& 3);
822 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
823 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
824 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
825 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
829 LOG_DIS("l %x %d\n", dc
->opcode
, size
);
831 addr
= compute_ldst_addr(dc
, &t
);
833 /* If we get a fault on a dslot, the jmpstate better be in sync. */
836 /* Verify alignment if needed. */
837 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
838 TCGv v
= tcg_temp_new();
841 * Microblaze gives MMU faults priority over faults due to
842 * unaligned addresses. That's why we speculatively do the load
843 * into v. If the load succeeds, we verify alignment of the
844 * address and if that succeeds we write into the destination reg.
846 gen_load(dc
, v
, *addr
, size
);
848 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
849 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
850 tcg_const_tl(0), tcg_const_tl(size
- 1));
852 tcg_gen_mov_tl(cpu_R
[dc
->rd
], v
);
856 gen_load(dc
, cpu_R
[dc
->rd
], *addr
, size
);
858 gen_load(dc
, env_imm
, *addr
, size
);
866 static void gen_store(DisasContext
*dc
, TCGv addr
, TCGv val
,
869 int mem_index
= cpu_mmu_index(dc
->env
);
872 tcg_gen_qemu_st8(val
, addr
, mem_index
);
873 else if (size
== 2) {
874 tcg_gen_qemu_st16(val
, addr
, mem_index
);
875 } else if (size
== 4) {
876 tcg_gen_qemu_st32(val
, addr
, mem_index
);
878 cpu_abort(dc
->env
, "Incorrect store size %d\n", size
);
881 static void dec_store(DisasContext
*dc
)
886 size
= 1 << (dc
->opcode
& 3);
888 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
889 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
890 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
891 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
895 LOG_DIS("s%d%s\n", size
, dc
->type_b
? "i" : "");
897 /* If we get a fault on a dslot, the jmpstate better be in sync. */
899 addr
= compute_ldst_addr(dc
, &t
);
901 gen_store(dc
, *addr
, cpu_R
[dc
->rd
], size
);
903 /* Verify alignment if needed. */
904 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
905 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
906 /* FIXME: if the alignment is wrong, we should restore the value
909 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
910 tcg_const_tl(1), tcg_const_tl(size
- 1));
917 static inline void eval_cc(DisasContext
*dc
, unsigned int cc
,
918 TCGv d
, TCGv a
, TCGv b
)
922 tcg_gen_setcond_tl(TCG_COND_EQ
, d
, a
, b
);
925 tcg_gen_setcond_tl(TCG_COND_NE
, d
, a
, b
);
928 tcg_gen_setcond_tl(TCG_COND_LT
, d
, a
, b
);
931 tcg_gen_setcond_tl(TCG_COND_LE
, d
, a
, b
);
934 tcg_gen_setcond_tl(TCG_COND_GE
, d
, a
, b
);
937 tcg_gen_setcond_tl(TCG_COND_GT
, d
, a
, b
);
940 cpu_abort(dc
->env
, "Unknown condition code %x.\n", cc
);
945 static void eval_cond_jmp(DisasContext
*dc
, TCGv pc_true
, TCGv pc_false
)
949 l1
= gen_new_label();
950 /* Conditional jmp. */
951 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_false
);
952 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
953 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_true
);
957 static void dec_bcc(DisasContext
*dc
)
962 cc
= EXTRACT_FIELD(dc
->ir
, 21, 23);
963 dslot
= dc
->ir
& (1 << 25);
964 LOG_DIS("bcc%s r%d %x\n", dslot
? "d" : "", dc
->ra
, dc
->imm
);
966 dc
->delayed_branch
= 1;
968 dc
->delayed_branch
= 2;
969 dc
->tb_flags
|= D_FLAG
;
970 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
971 cpu_env
, offsetof(CPUState
, bimm
));
974 if (dec_alu_op_b_is_small_imm(dc
)) {
975 int32_t offset
= (int32_t)((int16_t)dc
->imm
); /* sign-extend. */
977 tcg_gen_movi_tl(env_btarget
, dc
->pc
+ offset
);
978 dc
->jmp
= JMP_DIRECT
;
979 dc
->jmp_pc
= dc
->pc
+ offset
;
981 dc
->jmp
= JMP_INDIRECT
;
982 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
983 tcg_gen_add_tl(env_btarget
, env_btarget
, *(dec_alu_op_b(dc
)));
985 eval_cc(dc
, cc
, env_btaken
, cpu_R
[dc
->ra
], tcg_const_tl(0));
988 static void dec_br(DisasContext
*dc
)
990 unsigned int dslot
, link
, abs
;
991 int mem_index
= cpu_mmu_index(dc
->env
);
993 dslot
= dc
->ir
& (1 << 20);
994 abs
= dc
->ir
& (1 << 19);
995 link
= dc
->ir
& (1 << 18);
996 LOG_DIS("br%s%s%s%s imm=%x\n",
997 abs
? "a" : "", link
? "l" : "",
998 dc
->type_b
? "i" : "", dslot
? "d" : "",
1001 dc
->delayed_branch
= 1;
1003 dc
->delayed_branch
= 2;
1004 dc
->tb_flags
|= D_FLAG
;
1005 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1006 cpu_env
, offsetof(CPUState
, bimm
));
1009 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
1011 dc
->jmp
= JMP_INDIRECT
;
1013 tcg_gen_movi_tl(env_btaken
, 1);
1014 tcg_gen_mov_tl(env_btarget
, *(dec_alu_op_b(dc
)));
1015 if (link
&& !dslot
) {
1016 if (!(dc
->tb_flags
& IMM_FLAG
) && (dc
->imm
== 8 || dc
->imm
== 0x18))
1017 t_gen_raise_exception(dc
, EXCP_BREAK
);
1019 if ((dc
->tb_flags
& MSR_EE_FLAG
) && mem_index
== MMU_USER_IDX
) {
1020 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1021 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1025 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1029 if (dec_alu_op_b_is_small_imm(dc
)) {
1030 dc
->jmp
= JMP_DIRECT
;
1031 dc
->jmp_pc
= dc
->pc
+ (int32_t)((int16_t)dc
->imm
);
1032 tcg_gen_movi_tl(env_btaken
, 1);
1034 tcg_gen_movi_tl(env_btaken
, 1);
1035 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
1036 tcg_gen_add_tl(env_btarget
, env_btarget
, *(dec_alu_op_b(dc
)));
1041 static inline void do_rti(DisasContext
*dc
)
1044 t0
= tcg_temp_new();
1045 t1
= tcg_temp_new();
1046 tcg_gen_shri_tl(t0
, cpu_SR
[SR_MSR
], 1);
1047 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_IE
);
1048 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1050 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1051 tcg_gen_or_tl(t1
, t1
, t0
);
1055 dc
->tb_flags
&= ~DRTI_FLAG
;
1058 static inline void do_rtb(DisasContext
*dc
)
1061 t0
= tcg_temp_new();
1062 t1
= tcg_temp_new();
1063 tcg_gen_andi_tl(t1
, cpu_SR
[SR_MSR
], ~MSR_BIP
);
1064 tcg_gen_shri_tl(t0
, t1
, 1);
1065 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1067 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1068 tcg_gen_or_tl(t1
, t1
, t0
);
1072 dc
->tb_flags
&= ~DRTB_FLAG
;
1075 static inline void do_rte(DisasContext
*dc
)
1078 t0
= tcg_temp_new();
1079 t1
= tcg_temp_new();
1081 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_EE
);
1082 tcg_gen_andi_tl(t1
, t1
, ~MSR_EIP
);
1083 tcg_gen_shri_tl(t0
, t1
, 1);
1084 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1086 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1087 tcg_gen_or_tl(t1
, t1
, t0
);
1091 dc
->tb_flags
&= ~DRTE_FLAG
;
1094 static void dec_rts(DisasContext
*dc
)
1096 unsigned int b_bit
, i_bit
, e_bit
;
1097 int mem_index
= cpu_mmu_index(dc
->env
);
1099 i_bit
= dc
->ir
& (1 << 21);
1100 b_bit
= dc
->ir
& (1 << 22);
1101 e_bit
= dc
->ir
& (1 << 23);
1103 dc
->delayed_branch
= 2;
1104 dc
->tb_flags
|= D_FLAG
;
1105 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1106 cpu_env
, offsetof(CPUState
, bimm
));
1109 LOG_DIS("rtid ir=%x\n", dc
->ir
);
1110 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1111 && mem_index
== MMU_USER_IDX
) {
1112 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1113 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1115 dc
->tb_flags
|= DRTI_FLAG
;
1117 LOG_DIS("rtbd ir=%x\n", dc
->ir
);
1118 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1119 && mem_index
== MMU_USER_IDX
) {
1120 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1121 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1123 dc
->tb_flags
|= DRTB_FLAG
;
1125 LOG_DIS("rted ir=%x\n", dc
->ir
);
1126 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1127 && mem_index
== MMU_USER_IDX
) {
1128 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1129 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1131 dc
->tb_flags
|= DRTE_FLAG
;
1133 LOG_DIS("rts ir=%x\n", dc
->ir
);
1135 dc
->jmp
= JMP_INDIRECT
;
1136 tcg_gen_movi_tl(env_btaken
, 1);
1137 tcg_gen_add_tl(env_btarget
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
1140 static int dec_check_fpuv2(DisasContext
*dc
)
1144 r
= dc
->env
->pvr
.regs
[2] & PVR2_USE_FPU2_MASK
;
1146 if (!r
&& (dc
->tb_flags
& MSR_EE_FLAG
)) {
1147 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_FPU
);
1148 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1153 static void dec_fpu(DisasContext
*dc
)
1155 unsigned int fpu_insn
;
1157 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1158 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1159 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_FPU_MASK
))) {
1160 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1161 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1165 fpu_insn
= (dc
->ir
>> 7) & 7;
1169 gen_helper_fadd(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1173 gen_helper_frsub(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1177 gen_helper_fmul(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1181 gen_helper_fdiv(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1185 switch ((dc
->ir
>> 4) & 7) {
1187 gen_helper_fcmp_un(cpu_R
[dc
->rd
],
1188 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1191 gen_helper_fcmp_lt(cpu_R
[dc
->rd
],
1192 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1195 gen_helper_fcmp_eq(cpu_R
[dc
->rd
],
1196 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1199 gen_helper_fcmp_le(cpu_R
[dc
->rd
],
1200 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1203 gen_helper_fcmp_gt(cpu_R
[dc
->rd
],
1204 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1207 gen_helper_fcmp_ne(cpu_R
[dc
->rd
],
1208 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1211 gen_helper_fcmp_ge(cpu_R
[dc
->rd
],
1212 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1215 qemu_log ("unimplemented fcmp fpu_insn=%x pc=%x opc=%x\n",
1216 fpu_insn
, dc
->pc
, dc
->opcode
);
1217 dc
->abort_at_next_insn
= 1;
1223 if (!dec_check_fpuv2(dc
)) {
1226 gen_helper_flt(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1230 if (!dec_check_fpuv2(dc
)) {
1233 gen_helper_fint(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1237 if (!dec_check_fpuv2(dc
)) {
1240 gen_helper_fsqrt(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1244 qemu_log ("unimplemented FPU insn fpu_insn=%x pc=%x opc=%x\n",
1245 fpu_insn
, dc
->pc
, dc
->opcode
);
1246 dc
->abort_at_next_insn
= 1;
1251 static void dec_null(DisasContext
*dc
)
1253 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1254 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
1255 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1256 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1259 qemu_log ("unknown insn pc=%x opc=%x\n", dc
->pc
, dc
->opcode
);
1260 dc
->abort_at_next_insn
= 1;
1263 static struct decoder_info
{
1268 void (*dec
)(DisasContext
*dc
);
1276 {DEC_BARREL
, dec_barrel
},
1278 {DEC_ST
, dec_store
},
1290 static inline void decode(DisasContext
*dc
)
1295 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
1296 tcg_gen_debug_insn_start(dc
->pc
);
1298 dc
->ir
= ir
= ldl_code(dc
->pc
);
1299 LOG_DIS("%8.8x\t", dc
->ir
);
1304 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1305 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1306 && (dc
->env
->pvr
.regs
[2] & PVR2_OPCODE_0x0_ILL_MASK
)) {
1307 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1308 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1312 LOG_DIS("nr_nops=%d\t", dc
->nr_nops
);
1314 if (dc
->nr_nops
> 4)
1315 cpu_abort(dc
->env
, "fetching nop sequence\n");
1317 /* bit 2 seems to indicate insn type. */
1318 dc
->type_b
= ir
& (1 << 29);
1320 dc
->opcode
= EXTRACT_FIELD(ir
, 26, 31);
1321 dc
->rd
= EXTRACT_FIELD(ir
, 21, 25);
1322 dc
->ra
= EXTRACT_FIELD(ir
, 16, 20);
1323 dc
->rb
= EXTRACT_FIELD(ir
, 11, 15);
1324 dc
->imm
= EXTRACT_FIELD(ir
, 0, 15);
1326 /* Large switch for all insns. */
1327 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
1328 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
1335 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
1339 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
1340 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
1341 if (bp
->pc
== dc
->pc
) {
1342 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1343 dc
->is_jmp
= DISAS_UPDATE
;
1349 /* generate intermediate code for basic block 'tb'. */
1351 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
1354 uint16_t *gen_opc_end
;
1357 struct DisasContext ctx
;
1358 struct DisasContext
*dc
= &ctx
;
1359 uint32_t next_page_start
, org_flags
;
1364 qemu_log_try_set_file(stderr
);
1369 org_flags
= dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1371 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1373 dc
->is_jmp
= DISAS_NEXT
;
1375 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1376 if (dc
->delayed_branch
) {
1377 dc
->jmp
= JMP_INDIRECT
;
1380 dc
->singlestep_enabled
= env
->singlestep_enabled
;
1381 dc
->cpustate_changed
= 0;
1382 dc
->abort_at_next_insn
= 0;
1386 cpu_abort(env
, "Microblaze: unaligned PC=%x\n", pc_start
);
1388 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1390 qemu_log("--------------\n");
1391 log_cpu_state(env
, 0);
1395 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1398 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1400 max_insns
= CF_COUNT_MASK
;
1406 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1407 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
1411 check_breakpoint(env
, dc
);
1414 j
= gen_opc_ptr
- gen_opc_buf
;
1418 gen_opc_instr_start
[lj
++] = 0;
1420 gen_opc_pc
[lj
] = dc
->pc
;
1421 gen_opc_instr_start
[lj
] = 1;
1422 gen_opc_icount
[lj
] = num_insns
;
1426 LOG_DIS("%8.8x:\t", dc
->pc
);
1428 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
1434 dc
->tb_flags
&= ~IMM_FLAG
;
1438 if (dc
->delayed_branch
) {
1439 dc
->delayed_branch
--;
1440 if (!dc
->delayed_branch
) {
1441 if (dc
->tb_flags
& DRTI_FLAG
)
1443 if (dc
->tb_flags
& DRTB_FLAG
)
1445 if (dc
->tb_flags
& DRTE_FLAG
)
1447 /* Clear the delay slot flag. */
1448 dc
->tb_flags
&= ~D_FLAG
;
1449 /* If it is a direct jump, try direct chaining. */
1450 if (dc
->jmp
== JMP_INDIRECT
) {
1451 eval_cond_jmp(dc
, env_btarget
, tcg_const_tl(dc
->pc
));
1452 dc
->is_jmp
= DISAS_JUMP
;
1453 } else if (dc
->jmp
== JMP_DIRECT
) {
1457 l1
= gen_new_label();
1458 /* Conditional jmp. */
1459 tcg_gen_brcondi_tl(TCG_COND_NE
, env_btaken
, 0, l1
);
1460 gen_goto_tb(dc
, 1, dc
->pc
);
1462 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
1464 dc
->is_jmp
= DISAS_TB_JUMP
;
1469 if (env
->singlestep_enabled
)
1471 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
1472 && gen_opc_ptr
< gen_opc_end
1474 && (dc
->pc
< next_page_start
)
1475 && num_insns
< max_insns
);
1478 if (dc
->jmp
== JMP_DIRECT
) {
1479 if (dc
->tb_flags
& D_FLAG
) {
1480 dc
->is_jmp
= DISAS_UPDATE
;
1481 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1487 if (tb
->cflags
& CF_LAST_IO
)
1489 /* Force an update if the per-tb cpu state has changed. */
1490 if (dc
->is_jmp
== DISAS_NEXT
1491 && (dc
->cpustate_changed
|| org_flags
!= dc
->tb_flags
)) {
1492 dc
->is_jmp
= DISAS_UPDATE
;
1493 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1497 if (unlikely(env
->singlestep_enabled
)) {
1498 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1499 if (dc
->is_jmp
== DISAS_NEXT
)
1500 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1502 switch(dc
->is_jmp
) {
1504 gen_goto_tb(dc
, 1, npc
);
1509 /* indicate that the hash table must be used
1510 to find the next TB */
1514 /* nothing more to generate */
1518 gen_icount_end(tb
, num_insns
);
1519 *gen_opc_ptr
= INDEX_op_end
;
1521 j
= gen_opc_ptr
- gen_opc_buf
;
1524 gen_opc_instr_start
[lj
++] = 0;
1526 tb
->size
= dc
->pc
- pc_start
;
1527 tb
->icount
= num_insns
;
1532 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1535 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
1537 qemu_log("\nisize=%d osize=%td\n",
1538 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
1542 assert(!dc
->abort_at_next_insn
);
1545 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
1547 gen_intermediate_code_internal(env
, tb
, 0);
1550 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
1552 gen_intermediate_code_internal(env
, tb
, 1);
1555 void cpu_dump_state (CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
1563 cpu_fprintf(f
, "IN: PC=%x %s\n",
1564 env
->sregs
[SR_PC
], lookup_symbol(env
->sregs
[SR_PC
]));
1565 cpu_fprintf(f
, "rmsr=%x resr=%x rear=%x debug=%x imm=%x iflags=%x fsr=%x\n",
1566 env
->sregs
[SR_MSR
], env
->sregs
[SR_ESR
], env
->sregs
[SR_EAR
],
1567 env
->debug
, env
->imm
, env
->iflags
, env
->sregs
[SR_FSR
]);
1568 cpu_fprintf(f
, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
1569 env
->btaken
, env
->btarget
,
1570 (env
->sregs
[SR_MSR
] & MSR_UM
) ? "user" : "kernel",
1571 (env
->sregs
[SR_MSR
] & MSR_UMS
) ? "user" : "kernel",
1572 (env
->sregs
[SR_MSR
] & MSR_EIP
),
1573 (env
->sregs
[SR_MSR
] & MSR_IE
));
1575 for (i
= 0; i
< 32; i
++) {
1576 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
1577 if ((i
+ 1) % 4 == 0)
1578 cpu_fprintf(f
, "\n");
1580 cpu_fprintf(f
, "\n\n");
1583 CPUState
*cpu_mb_init (const char *cpu_model
)
1586 static int tcg_initialized
= 0;
1589 env
= qemu_mallocz(sizeof(CPUState
));
1593 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
1595 if (tcg_initialized
)
1598 tcg_initialized
= 1;
1600 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
1602 env_debug
= tcg_global_mem_new(TCG_AREG0
,
1603 offsetof(CPUState
, debug
),
1605 env_iflags
= tcg_global_mem_new(TCG_AREG0
,
1606 offsetof(CPUState
, iflags
),
1608 env_imm
= tcg_global_mem_new(TCG_AREG0
,
1609 offsetof(CPUState
, imm
),
1611 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
1612 offsetof(CPUState
, btarget
),
1614 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
1615 offsetof(CPUState
, btaken
),
1617 for (i
= 0; i
< ARRAY_SIZE(cpu_R
); i
++) {
1618 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
1619 offsetof(CPUState
, regs
[i
]),
1622 for (i
= 0; i
< ARRAY_SIZE(cpu_SR
); i
++) {
1623 cpu_SR
[i
] = tcg_global_mem_new(TCG_AREG0
,
1624 offsetof(CPUState
, sregs
[i
]),
1625 special_regnames
[i
]);
1627 #define GEN_HELPER 2
1633 void cpu_reset (CPUState
*env
)
1635 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
1636 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
1637 log_cpu_state(env
, 0);
1640 memset(env
, 0, offsetof(CPUMBState
, breakpoints
));
1643 env
->pvr
.regs
[0] = PVR0_PVR_FULL_MASK \
1644 | PVR0_USE_BARREL_MASK \
1645 | PVR0_USE_DIV_MASK \
1646 | PVR0_USE_HW_MUL_MASK \
1647 | PVR0_USE_EXC_MASK \
1648 | PVR0_USE_ICACHE_MASK \
1649 | PVR0_USE_DCACHE_MASK \
1652 env
->pvr
.regs
[2] = PVR2_D_OPB_MASK \
1656 | PVR2_USE_MSR_INSTR \
1657 | PVR2_USE_PCMP_INSTR \
1658 | PVR2_USE_BARREL_MASK \
1659 | PVR2_USE_DIV_MASK \
1660 | PVR2_USE_HW_MUL_MASK \
1661 | PVR2_USE_MUL64_MASK \
1662 | PVR2_USE_FPU_MASK \
1663 | PVR2_USE_FPU2_MASK \
1664 | PVR2_FPU_EXC_MASK \
1666 env
->pvr
.regs
[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
1667 env
->pvr
.regs
[11] = PVR11_USE_MMU
| (16 << 17);
1669 #if defined(CONFIG_USER_ONLY)
1670 /* start in user mode with interrupts enabled. */
1671 env
->sregs
[SR_MSR
] = MSR_EE
| MSR_IE
| MSR_VM
| MSR_UM
;
1672 env
->pvr
.regs
[10] = 0x0c000000; /* Spartan 3a dsp. */
1674 env
->sregs
[SR_MSR
] = 0;
1675 mmu_init(&env
->mmu
);
1677 env
->mmu
.c_mmu_tlb_access
= 3;
1678 env
->mmu
.c_mmu_zones
= 16;
1682 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
1683 unsigned long searched_pc
, int pc_pos
, void *puc
)
1685 env
->sregs
[SR_PC
] = gen_opc_pc
[pc_pos
];