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
{
67 target_ulong cache_pc
;
76 unsigned int cpustate_changed
;
77 unsigned int delayed_branch
;
78 unsigned int tb_flags
, synced_flags
; /* tb dependent flags. */
79 unsigned int clear_imm
;
84 #define JMP_INDIRECT 2
88 int abort_at_next_insn
;
90 struct TranslationBlock
*tb
;
91 int singlestep_enabled
;
94 static const char *regnames
[] =
96 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
97 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
98 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
99 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
102 static const char *special_regnames
[] =
104 "rpc", "rmsr", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
105 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
106 "sr16", "sr17", "sr18"
109 /* Sign extend at translation time. */
110 static inline int sign_extend(unsigned int val
, unsigned int width
)
122 static inline void t_sync_flags(DisasContext
*dc
)
124 /* Synch the tb dependant flags between translator and runtime. */
125 if (dc
->tb_flags
!= dc
->synced_flags
) {
126 tcg_gen_movi_tl(env_iflags
, dc
->tb_flags
);
127 dc
->synced_flags
= dc
->tb_flags
;
131 static inline void t_gen_raise_exception(DisasContext
*dc
, uint32_t index
)
133 TCGv_i32 tmp
= tcg_const_i32(index
);
136 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
137 gen_helper_raise_exception(tmp
);
138 tcg_temp_free_i32(tmp
);
139 dc
->is_jmp
= DISAS_UPDATE
;
142 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
144 TranslationBlock
*tb
;
146 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
148 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dest
);
149 tcg_gen_exit_tb((long)tb
+ n
);
151 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dest
);
156 static inline TCGv
*dec_alu_op_b(DisasContext
*dc
)
159 if (dc
->tb_flags
& IMM_FLAG
)
160 tcg_gen_ori_tl(env_imm
, env_imm
, dc
->imm
);
162 tcg_gen_movi_tl(env_imm
, (int32_t)((int16_t)dc
->imm
));
165 return &cpu_R
[dc
->rb
];
168 static void dec_add(DisasContext
*dc
)
175 LOG_DIS("add%s%s%s r%d r%d r%d\n",
176 dc
->type_b
? "i" : "", k
? "k" : "", c
? "c" : "",
177 dc
->rd
, dc
->ra
, dc
->rb
);
179 if (k
&& !c
&& dc
->rd
)
180 tcg_gen_add_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
182 gen_helper_addkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
183 tcg_const_tl(k
), tcg_const_tl(c
));
185 TCGv d
= tcg_temp_new();
186 gen_helper_addkc(d
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
187 tcg_const_tl(k
), tcg_const_tl(c
));
192 static void dec_sub(DisasContext
*dc
)
194 unsigned int u
, cmp
, k
, c
;
199 cmp
= (dc
->imm
& 1) && (!dc
->type_b
) && k
;
202 LOG_DIS("cmp%s r%d, r%d ir=%x\n", u
? "u" : "", dc
->rd
, dc
->ra
, dc
->ir
);
205 gen_helper_cmpu(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
207 gen_helper_cmp(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
210 LOG_DIS("sub%s%s r%d, r%d r%d\n",
211 k
? "k" : "", c
? "c" : "", dc
->rd
, dc
->ra
, dc
->rb
);
217 gen_helper_subkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
218 tcg_const_tl(k
), tcg_const_tl(c
));
220 gen_helper_subkc(t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
221 tcg_const_tl(k
), tcg_const_tl(c
));
225 tcg_gen_sub_tl(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
229 static void dec_pattern(DisasContext
*dc
)
234 if ((dc
->tb_flags
& MSR_EE_FLAG
)
235 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
236 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_PCMP_INSTR
))) {
237 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
238 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
241 mode
= dc
->opcode
& 3;
245 LOG_DIS("pcmpbf r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
247 gen_helper_pcmpbf(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
250 LOG_DIS("pcmpeq r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
252 TCGv t0
= tcg_temp_local_new();
253 l1
= gen_new_label();
254 tcg_gen_movi_tl(t0
, 1);
255 tcg_gen_brcond_tl(TCG_COND_EQ
,
256 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
257 tcg_gen_movi_tl(t0
, 0);
259 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
264 LOG_DIS("pcmpne r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
265 l1
= gen_new_label();
267 TCGv t0
= tcg_temp_local_new();
268 tcg_gen_movi_tl(t0
, 1);
269 tcg_gen_brcond_tl(TCG_COND_NE
,
270 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
271 tcg_gen_movi_tl(t0
, 0);
273 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
279 "unsupported pattern insn opcode=%x\n", dc
->opcode
);
284 static void dec_and(DisasContext
*dc
)
288 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
293 not = dc
->opcode
& (1 << 1);
294 LOG_DIS("and%s\n", not ? "n" : "");
300 TCGv t
= tcg_temp_new();
301 tcg_gen_not_tl(t
, *(dec_alu_op_b(dc
)));
302 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t
);
305 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
308 static void dec_or(DisasContext
*dc
)
310 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
315 LOG_DIS("or r%d r%d r%d imm=%x\n", dc
->rd
, dc
->ra
, dc
->rb
, dc
->imm
);
317 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
320 static void dec_xor(DisasContext
*dc
)
322 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
327 LOG_DIS("xor r%d\n", dc
->rd
);
329 tcg_gen_xor_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
332 static void read_carry(DisasContext
*dc
, TCGv d
)
334 tcg_gen_shri_tl(d
, cpu_SR
[SR_MSR
], 31);
337 static void write_carry(DisasContext
*dc
, TCGv v
)
339 TCGv t0
= tcg_temp_new();
340 tcg_gen_shli_tl(t0
, v
, 31);
341 tcg_gen_sari_tl(t0
, t0
, 31);
342 tcg_gen_mov_tl(env_debug
, t0
);
343 tcg_gen_andi_tl(t0
, t0
, (MSR_C
| MSR_CC
));
344 tcg_gen_andi_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
],
346 tcg_gen_or_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], t0
);
351 static inline void msr_read(DisasContext
*dc
, TCGv d
)
353 tcg_gen_mov_tl(d
, cpu_SR
[SR_MSR
]);
356 static inline void msr_write(DisasContext
*dc
, TCGv v
)
358 dc
->cpustate_changed
= 1;
359 tcg_gen_mov_tl(cpu_SR
[SR_MSR
], v
);
360 /* PVR, we have a processor version register. */
361 tcg_gen_ori_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], (1 << 10));
364 static void dec_msr(DisasContext
*dc
)
367 unsigned int sr
, to
, rn
;
368 int mem_index
= cpu_mmu_index(dc
->env
);
370 sr
= dc
->imm
& ((1 << 14) - 1);
371 to
= dc
->imm
& (1 << 14);
374 dc
->cpustate_changed
= 1;
376 /* msrclr and msrset. */
377 if (!(dc
->imm
& (1 << 15))) {
378 unsigned int clr
= dc
->ir
& (1 << 16);
380 LOG_DIS("msr%s r%d imm=%x\n", clr
? "clr" : "set",
383 if (!(dc
->env
->pvr
.regs
[2] & PVR2_USE_MSR_INSTR
)) {
388 if ((dc
->tb_flags
& MSR_EE_FLAG
)
389 && mem_index
== MMU_USER_IDX
&& (dc
->imm
!= 4 && dc
->imm
!= 0)) {
390 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
391 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
396 msr_read(dc
, cpu_R
[dc
->rd
]);
401 tcg_gen_mov_tl(t1
, *(dec_alu_op_b(dc
)));
404 tcg_gen_not_tl(t1
, t1
);
405 tcg_gen_and_tl(t0
, t0
, t1
);
407 tcg_gen_or_tl(t0
, t0
, t1
);
411 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
+ 4);
412 dc
->is_jmp
= DISAS_UPDATE
;
417 if ((dc
->tb_flags
& MSR_EE_FLAG
)
418 && mem_index
== MMU_USER_IDX
) {
419 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
420 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
425 #if !defined(CONFIG_USER_ONLY)
426 /* Catch read/writes to the mmu block. */
427 if ((sr
& ~0xff) == 0x1000) {
429 LOG_DIS("m%ss sr%d r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
431 gen_helper_mmu_write(tcg_const_tl(sr
), cpu_R
[dc
->ra
]);
433 gen_helper_mmu_read(cpu_R
[dc
->rd
], tcg_const_tl(sr
));
439 LOG_DIS("m%ss sr%x r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
444 msr_write(dc
, cpu_R
[dc
->ra
]);
447 tcg_gen_mov_tl(cpu_SR
[SR_EAR
], cpu_R
[dc
->ra
]);
450 tcg_gen_mov_tl(cpu_SR
[SR_ESR
], cpu_R
[dc
->ra
]);
453 /* Ignored at the moment. */
456 cpu_abort(dc
->env
, "unknown mts reg %x\n", sr
);
460 LOG_DIS("m%ss r%d sr%x imm=%x\n", to
? "t" : "f", dc
->rd
, sr
, dc
->imm
);
464 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
467 msr_read(dc
, cpu_R
[dc
->rd
]);
470 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_EAR
]);
473 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_ESR
]);
476 tcg_gen_movi_tl(cpu_R
[dc
->rd
], 0);
479 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_BTR
]);
495 tcg_gen_ld_tl(cpu_R
[dc
->rd
],
496 cpu_env
, offsetof(CPUState
, pvr
.regs
[rn
]));
499 cpu_abort(dc
->env
, "unknown mfs reg %x\n", sr
);
505 tcg_gen_movi_tl(cpu_R
[0], 0);
509 /* 64-bit signed mul, lower result in d and upper in d2. */
510 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
514 t0
= tcg_temp_new_i64();
515 t1
= tcg_temp_new_i64();
517 tcg_gen_ext_i32_i64(t0
, a
);
518 tcg_gen_ext_i32_i64(t1
, b
);
519 tcg_gen_mul_i64(t0
, t0
, t1
);
521 tcg_gen_trunc_i64_i32(d
, t0
);
522 tcg_gen_shri_i64(t0
, t0
, 32);
523 tcg_gen_trunc_i64_i32(d2
, t0
);
525 tcg_temp_free_i64(t0
);
526 tcg_temp_free_i64(t1
);
529 /* 64-bit unsigned muls, lower result in d and upper in d2. */
530 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
534 t0
= tcg_temp_new_i64();
535 t1
= tcg_temp_new_i64();
537 tcg_gen_extu_i32_i64(t0
, a
);
538 tcg_gen_extu_i32_i64(t1
, b
);
539 tcg_gen_mul_i64(t0
, t0
, t1
);
541 tcg_gen_trunc_i64_i32(d
, t0
);
542 tcg_gen_shri_i64(t0
, t0
, 32);
543 tcg_gen_trunc_i64_i32(d2
, t0
);
545 tcg_temp_free_i64(t0
);
546 tcg_temp_free_i64(t1
);
549 /* Multiplier unit. */
550 static void dec_mul(DisasContext
*dc
)
553 unsigned int subcode
;
555 if ((dc
->tb_flags
& MSR_EE_FLAG
)
556 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
557 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_HW_MUL_MASK
)) {
558 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
559 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
563 subcode
= dc
->imm
& 3;
564 d
[0] = tcg_temp_new();
565 d
[1] = tcg_temp_new();
568 LOG_DIS("muli r%d r%d %x\n", dc
->rd
, dc
->ra
, dc
->imm
);
569 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
573 /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */
574 if (subcode
>= 1 && subcode
<= 3
575 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_MUL64_MASK
))) {
581 LOG_DIS("mul r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
582 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
585 LOG_DIS("mulh r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
586 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
589 LOG_DIS("mulhsu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
590 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
593 LOG_DIS("mulhu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
594 t_gen_mulu(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
597 cpu_abort(dc
->env
, "unknown MUL insn %x\n", subcode
);
606 static void dec_div(DisasContext
*dc
)
613 if ((dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
614 && !((dc
->env
->pvr
.regs
[0] & PVR0_USE_DIV_MASK
))) {
615 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
616 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
620 gen_helper_divu(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
622 gen_helper_divs(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
624 tcg_gen_movi_tl(cpu_R
[dc
->rd
], 0);
627 static void dec_barrel(DisasContext
*dc
)
632 if ((dc
->tb_flags
& MSR_EE_FLAG
)
633 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
634 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_BARREL_MASK
)) {
635 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
636 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
640 s
= dc
->imm
& (1 << 10);
641 t
= dc
->imm
& (1 << 9);
643 LOG_DIS("bs%s%s r%d r%d r%d\n",
644 s
? "l" : "r", t
? "a" : "l", dc
->rd
, dc
->ra
, dc
->rb
);
648 tcg_gen_mov_tl(t0
, *(dec_alu_op_b(dc
)));
649 tcg_gen_andi_tl(t0
, t0
, 31);
652 tcg_gen_shl_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
655 tcg_gen_sar_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
657 tcg_gen_shr_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
661 static void dec_bit(DisasContext
*dc
)
665 int mem_index
= cpu_mmu_index(dc
->env
);
667 op
= dc
->ir
& ((1 << 8) - 1);
673 LOG_DIS("src r%d r%d\n", dc
->rd
, dc
->ra
);
674 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
678 tcg_gen_shli_tl(t1
, t1
, 31);
680 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
681 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->rd
], t1
);
694 LOG_DIS("srl r%d r%d\n", dc
->rd
, dc
->ra
);
697 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
702 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
704 tcg_gen_sari_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
708 LOG_DIS("ext8s r%d r%d\n", dc
->rd
, dc
->ra
);
709 tcg_gen_ext8s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
712 LOG_DIS("ext16s r%d r%d\n", dc
->rd
, dc
->ra
);
713 tcg_gen_ext16s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
720 LOG_DIS("wdc r%d\n", dc
->ra
);
721 if ((dc
->tb_flags
& MSR_EE_FLAG
)
722 && mem_index
== MMU_USER_IDX
) {
723 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
724 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
730 LOG_DIS("wic r%d\n", dc
->ra
);
731 if ((dc
->tb_flags
& MSR_EE_FLAG
)
732 && mem_index
== MMU_USER_IDX
) {
733 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
734 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
739 cpu_abort(dc
->env
, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n",
740 dc
->pc
, op
, dc
->rd
, dc
->ra
, dc
->rb
);
745 static inline void sync_jmpstate(DisasContext
*dc
)
747 if (dc
->jmp
== JMP_DIRECT
) {
748 dc
->jmp
= JMP_INDIRECT
;
749 tcg_gen_movi_tl(env_btaken
, 1);
750 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
754 static void dec_imm(DisasContext
*dc
)
756 LOG_DIS("imm %x\n", dc
->imm
<< 16);
757 tcg_gen_movi_tl(env_imm
, (dc
->imm
<< 16));
758 dc
->tb_flags
|= IMM_FLAG
;
762 static inline void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
765 int mem_index
= cpu_mmu_index(dc
->env
);
768 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
769 } else if (size
== 2) {
770 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
771 } else if (size
== 4) {
772 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
774 cpu_abort(dc
->env
, "Incorrect load size %d\n", size
);
777 static inline TCGv
*compute_ldst_addr(DisasContext
*dc
, TCGv
*t
)
779 unsigned int extimm
= dc
->tb_flags
& IMM_FLAG
;
781 /* Treat the fast cases first. */
784 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
790 return &cpu_R
[dc
->ra
];
793 tcg_gen_movi_tl(*t
, (int32_t)((int16_t)dc
->imm
));
794 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *t
);
797 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
803 static void dec_load(DisasContext
*dc
)
808 size
= 1 << (dc
->opcode
& 3);
809 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
810 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
811 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
812 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
816 LOG_DIS("l %x %d\n", dc
->opcode
, size
);
818 addr
= compute_ldst_addr(dc
, &t
);
820 /* If we get a fault on a dslot, the jmpstate better be in sync. */
823 /* Verify alignment if needed. */
824 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
825 TCGv v
= tcg_temp_new();
828 * Microblaze gives MMU faults priority over faults due to
829 * unaligned addresses. That's why we speculatively do the load
830 * into v. If the load succeeds, we verify alignment of the
831 * address and if that succeeds we write into the destination reg.
833 gen_load(dc
, v
, *addr
, size
);
835 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
836 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
837 tcg_const_tl(0), tcg_const_tl(size
- 1));
839 tcg_gen_mov_tl(cpu_R
[dc
->rd
], v
);
843 gen_load(dc
, cpu_R
[dc
->rd
], *addr
, size
);
845 gen_load(dc
, env_imm
, *addr
, size
);
853 static void gen_store(DisasContext
*dc
, TCGv addr
, TCGv val
,
856 int mem_index
= cpu_mmu_index(dc
->env
);
859 tcg_gen_qemu_st8(val
, addr
, mem_index
);
860 else if (size
== 2) {
861 tcg_gen_qemu_st16(val
, addr
, mem_index
);
862 } else if (size
== 4) {
863 tcg_gen_qemu_st32(val
, addr
, mem_index
);
865 cpu_abort(dc
->env
, "Incorrect store size %d\n", size
);
868 static void dec_store(DisasContext
*dc
)
873 size
= 1 << (dc
->opcode
& 3);
875 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
876 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
877 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
878 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
882 LOG_DIS("s%d%s\n", size
, dc
->type_b
? "i" : "");
884 /* If we get a fault on a dslot, the jmpstate better be in sync. */
886 addr
= compute_ldst_addr(dc
, &t
);
888 gen_store(dc
, *addr
, cpu_R
[dc
->rd
], size
);
890 /* Verify alignment if needed. */
891 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
892 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
893 /* FIXME: if the alignment is wrong, we should restore the value
896 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
897 tcg_const_tl(1), tcg_const_tl(size
- 1));
904 static inline void eval_cc(DisasContext
*dc
, unsigned int cc
,
905 TCGv d
, TCGv a
, TCGv b
)
911 l1
= gen_new_label();
912 tcg_gen_movi_tl(env_btaken
, 1);
913 tcg_gen_brcond_tl(TCG_COND_EQ
, a
, b
, l1
);
914 tcg_gen_movi_tl(env_btaken
, 0);
918 l1
= gen_new_label();
919 tcg_gen_movi_tl(env_btaken
, 1);
920 tcg_gen_brcond_tl(TCG_COND_NE
, a
, b
, l1
);
921 tcg_gen_movi_tl(env_btaken
, 0);
925 l1
= gen_new_label();
926 tcg_gen_movi_tl(env_btaken
, 1);
927 tcg_gen_brcond_tl(TCG_COND_LT
, a
, b
, l1
);
928 tcg_gen_movi_tl(env_btaken
, 0);
932 l1
= gen_new_label();
933 tcg_gen_movi_tl(env_btaken
, 1);
934 tcg_gen_brcond_tl(TCG_COND_LE
, a
, b
, l1
);
935 tcg_gen_movi_tl(env_btaken
, 0);
939 l1
= gen_new_label();
940 tcg_gen_movi_tl(env_btaken
, 1);
941 tcg_gen_brcond_tl(TCG_COND_GE
, a
, b
, l1
);
942 tcg_gen_movi_tl(env_btaken
, 0);
946 l1
= gen_new_label();
947 tcg_gen_movi_tl(env_btaken
, 1);
948 tcg_gen_brcond_tl(TCG_COND_GT
, a
, b
, l1
);
949 tcg_gen_movi_tl(env_btaken
, 0);
953 cpu_abort(dc
->env
, "Unknown condition code %x.\n", cc
);
958 static void eval_cond_jmp(DisasContext
*dc
, TCGv pc_true
, TCGv pc_false
)
962 l1
= gen_new_label();
963 /* Conditional jmp. */
964 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_false
);
965 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
966 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_true
);
970 static void dec_bcc(DisasContext
*dc
)
975 cc
= EXTRACT_FIELD(dc
->ir
, 21, 23);
976 dslot
= dc
->ir
& (1 << 25);
977 LOG_DIS("bcc%s r%d %x\n", dslot
? "d" : "", dc
->ra
, dc
->imm
);
979 dc
->delayed_branch
= 1;
981 dc
->delayed_branch
= 2;
982 dc
->tb_flags
|= D_FLAG
;
983 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
984 cpu_env
, offsetof(CPUState
, bimm
));
987 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
988 tcg_gen_add_tl(env_btarget
, env_btarget
, *(dec_alu_op_b(dc
)));
989 eval_cc(dc
, cc
, env_btaken
, cpu_R
[dc
->ra
], tcg_const_tl(0));
990 dc
->jmp
= JMP_INDIRECT
;
993 static void dec_br(DisasContext
*dc
)
995 unsigned int dslot
, link
, abs
;
996 int mem_index
= cpu_mmu_index(dc
->env
);
998 dslot
= dc
->ir
& (1 << 20);
999 abs
= dc
->ir
& (1 << 19);
1000 link
= dc
->ir
& (1 << 18);
1001 LOG_DIS("br%s%s%s%s imm=%x\n",
1002 abs
? "a" : "", link
? "l" : "",
1003 dc
->type_b
? "i" : "", dslot
? "d" : "",
1006 dc
->delayed_branch
= 1;
1008 dc
->delayed_branch
= 2;
1009 dc
->tb_flags
|= D_FLAG
;
1010 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1011 cpu_env
, offsetof(CPUState
, bimm
));
1014 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
1016 dc
->jmp
= JMP_INDIRECT
;
1018 tcg_gen_movi_tl(env_btaken
, 1);
1019 tcg_gen_mov_tl(env_btarget
, *(dec_alu_op_b(dc
)));
1020 if (link
&& !dslot
) {
1021 if (!(dc
->tb_flags
& IMM_FLAG
) && (dc
->imm
== 8 || dc
->imm
== 0x18))
1022 t_gen_raise_exception(dc
, EXCP_BREAK
);
1024 if ((dc
->tb_flags
& MSR_EE_FLAG
) && mem_index
== MMU_USER_IDX
) {
1025 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1026 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1030 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1034 if (!dc
->type_b
|| (dc
->tb_flags
& IMM_FLAG
)) {
1035 tcg_gen_movi_tl(env_btaken
, 1);
1036 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
1037 tcg_gen_add_tl(env_btarget
, env_btarget
, *(dec_alu_op_b(dc
)));
1039 dc
->jmp
= JMP_DIRECT
;
1040 dc
->jmp_pc
= dc
->pc
+ (int32_t)((int16_t)dc
->imm
);
1045 static inline void do_rti(DisasContext
*dc
)
1048 t0
= tcg_temp_new();
1049 t1
= tcg_temp_new();
1050 tcg_gen_shri_tl(t0
, cpu_SR
[SR_MSR
], 1);
1051 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_IE
);
1052 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1054 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1055 tcg_gen_or_tl(t1
, t1
, t0
);
1059 dc
->tb_flags
&= ~DRTI_FLAG
;
1062 static inline void do_rtb(DisasContext
*dc
)
1065 t0
= tcg_temp_new();
1066 t1
= tcg_temp_new();
1067 tcg_gen_andi_tl(t1
, cpu_SR
[SR_MSR
], ~MSR_BIP
);
1068 tcg_gen_shri_tl(t0
, t1
, 1);
1069 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1071 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1072 tcg_gen_or_tl(t1
, t1
, t0
);
1076 dc
->tb_flags
&= ~DRTB_FLAG
;
1079 static inline void do_rte(DisasContext
*dc
)
1082 t0
= tcg_temp_new();
1083 t1
= tcg_temp_new();
1085 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_EE
);
1086 tcg_gen_andi_tl(t1
, t1
, ~MSR_EIP
);
1087 tcg_gen_shri_tl(t0
, t1
, 1);
1088 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1090 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1091 tcg_gen_or_tl(t1
, t1
, t0
);
1095 dc
->tb_flags
&= ~DRTE_FLAG
;
1098 static void dec_rts(DisasContext
*dc
)
1100 unsigned int b_bit
, i_bit
, e_bit
;
1101 int mem_index
= cpu_mmu_index(dc
->env
);
1103 i_bit
= dc
->ir
& (1 << 21);
1104 b_bit
= dc
->ir
& (1 << 22);
1105 e_bit
= dc
->ir
& (1 << 23);
1107 dc
->delayed_branch
= 2;
1108 dc
->tb_flags
|= D_FLAG
;
1109 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1110 cpu_env
, offsetof(CPUState
, bimm
));
1113 LOG_DIS("rtid ir=%x\n", dc
->ir
);
1114 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1115 && mem_index
== MMU_USER_IDX
) {
1116 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1117 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1119 dc
->tb_flags
|= DRTI_FLAG
;
1121 LOG_DIS("rtbd ir=%x\n", dc
->ir
);
1122 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1123 && mem_index
== MMU_USER_IDX
) {
1124 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1125 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1127 dc
->tb_flags
|= DRTB_FLAG
;
1129 LOG_DIS("rted ir=%x\n", dc
->ir
);
1130 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1131 && mem_index
== MMU_USER_IDX
) {
1132 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1133 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1135 dc
->tb_flags
|= DRTE_FLAG
;
1137 LOG_DIS("rts ir=%x\n", dc
->ir
);
1139 tcg_gen_movi_tl(env_btaken
, 1);
1140 tcg_gen_add_tl(env_btarget
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
1143 static void dec_fpu(DisasContext
*dc
)
1145 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1146 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1147 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_FPU_MASK
))) {
1148 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_FPU
);
1149 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1153 qemu_log ("unimplemented FPU insn pc=%x opc=%x\n", dc
->pc
, dc
->opcode
);
1154 dc
->abort_at_next_insn
= 1;
1157 static void dec_null(DisasContext
*dc
)
1159 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1160 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
1161 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1162 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1165 qemu_log ("unknown insn pc=%x opc=%x\n", dc
->pc
, dc
->opcode
);
1166 dc
->abort_at_next_insn
= 1;
1169 static struct decoder_info
{
1174 void (*dec
)(DisasContext
*dc
);
1182 {DEC_BARREL
, dec_barrel
},
1184 {DEC_ST
, dec_store
},
1196 static inline void decode(DisasContext
*dc
)
1201 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
1202 tcg_gen_debug_insn_start(dc
->pc
);
1204 dc
->ir
= ir
= ldl_code(dc
->pc
);
1205 LOG_DIS("%8.8x\t", dc
->ir
);
1210 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1211 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1212 && (dc
->env
->pvr
.regs
[2] & PVR2_OPCODE_0x0_ILL_MASK
)) {
1213 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1214 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1218 LOG_DIS("nr_nops=%d\t", dc
->nr_nops
);
1220 if (dc
->nr_nops
> 4)
1221 cpu_abort(dc
->env
, "fetching nop sequence\n");
1223 /* bit 2 seems to indicate insn type. */
1224 dc
->type_b
= ir
& (1 << 29);
1226 dc
->opcode
= EXTRACT_FIELD(ir
, 26, 31);
1227 dc
->rd
= EXTRACT_FIELD(ir
, 21, 25);
1228 dc
->ra
= EXTRACT_FIELD(ir
, 16, 20);
1229 dc
->rb
= EXTRACT_FIELD(ir
, 11, 15);
1230 dc
->imm
= EXTRACT_FIELD(ir
, 0, 15);
1232 /* Large switch for all insns. */
1233 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
1234 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
1241 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
1245 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
1246 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
1247 if (bp
->pc
== dc
->pc
) {
1248 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1249 dc
->is_jmp
= DISAS_UPDATE
;
1255 /* generate intermediate code for basic block 'tb'. */
1257 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
1260 uint16_t *gen_opc_end
;
1263 struct DisasContext ctx
;
1264 struct DisasContext
*dc
= &ctx
;
1265 uint32_t next_page_start
, org_flags
;
1270 qemu_log_try_set_file(stderr
);
1275 org_flags
= dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1277 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1279 dc
->is_jmp
= DISAS_NEXT
;
1281 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1285 dc
->singlestep_enabled
= env
->singlestep_enabled
;
1286 dc
->cpustate_changed
= 0;
1287 dc
->abort_at_next_insn
= 0;
1291 cpu_abort(env
, "Microblaze: unaligned PC=%x\n", pc_start
);
1293 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1295 qemu_log("--------------\n");
1296 log_cpu_state(env
, 0);
1300 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1303 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1305 max_insns
= CF_COUNT_MASK
;
1311 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1312 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
1316 check_breakpoint(env
, dc
);
1319 j
= gen_opc_ptr
- gen_opc_buf
;
1323 gen_opc_instr_start
[lj
++] = 0;
1325 gen_opc_pc
[lj
] = dc
->pc
;
1326 gen_opc_instr_start
[lj
] = 1;
1327 gen_opc_icount
[lj
] = num_insns
;
1331 LOG_DIS("%8.8x:\t", dc
->pc
);
1333 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
1339 dc
->tb_flags
&= ~IMM_FLAG
;
1344 if (dc
->delayed_branch
) {
1345 dc
->delayed_branch
--;
1346 if (!dc
->delayed_branch
) {
1347 if (dc
->tb_flags
& DRTI_FLAG
)
1349 if (dc
->tb_flags
& DRTB_FLAG
)
1351 if (dc
->tb_flags
& DRTE_FLAG
)
1353 /* Clear the delay slot flag. */
1354 dc
->tb_flags
&= ~D_FLAG
;
1355 /* If it is a direct jump, try direct chaining. */
1356 if (dc
->jmp
!= JMP_DIRECT
) {
1357 eval_cond_jmp(dc
, env_btarget
, tcg_const_tl(dc
->pc
));
1358 dc
->is_jmp
= DISAS_JUMP
;
1363 if (env
->singlestep_enabled
)
1365 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
1366 && gen_opc_ptr
< gen_opc_end
1368 && (dc
->pc
< next_page_start
)
1369 && num_insns
< max_insns
);
1372 if (dc
->jmp
== JMP_DIRECT
) {
1373 if (dc
->tb_flags
& D_FLAG
) {
1374 dc
->is_jmp
= DISAS_UPDATE
;
1375 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1381 if (tb
->cflags
& CF_LAST_IO
)
1383 /* Force an update if the per-tb cpu state has changed. */
1384 if (dc
->is_jmp
== DISAS_NEXT
1385 && (dc
->cpustate_changed
|| org_flags
!= dc
->tb_flags
)) {
1386 dc
->is_jmp
= DISAS_UPDATE
;
1387 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1391 if (unlikely(env
->singlestep_enabled
)) {
1392 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1393 if (dc
->is_jmp
== DISAS_NEXT
)
1394 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1396 switch(dc
->is_jmp
) {
1398 gen_goto_tb(dc
, 1, npc
);
1403 /* indicate that the hash table must be used
1404 to find the next TB */
1408 /* nothing more to generate */
1412 gen_icount_end(tb
, num_insns
);
1413 *gen_opc_ptr
= INDEX_op_end
;
1415 j
= gen_opc_ptr
- gen_opc_buf
;
1418 gen_opc_instr_start
[lj
++] = 0;
1420 tb
->size
= dc
->pc
- pc_start
;
1421 tb
->icount
= num_insns
;
1426 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1429 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
1431 qemu_log("\nisize=%d osize=%zd\n",
1432 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
1436 assert(!dc
->abort_at_next_insn
);
1439 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
1441 gen_intermediate_code_internal(env
, tb
, 0);
1444 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
1446 gen_intermediate_code_internal(env
, tb
, 1);
1449 void cpu_dump_state (CPUState
*env
, FILE *f
,
1450 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
1458 cpu_fprintf(f
, "IN: PC=%x %s\n",
1459 env
->sregs
[SR_PC
], lookup_symbol(env
->sregs
[SR_PC
]));
1460 cpu_fprintf(f
, "rmsr=%x resr=%x rear=%x debug[%x] imm=%x iflags=%x\n",
1461 env
->sregs
[SR_MSR
], env
->sregs
[SR_ESR
], env
->sregs
[SR_EAR
],
1462 env
->debug
, env
->imm
, env
->iflags
);
1463 cpu_fprintf(f
, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
1464 env
->btaken
, env
->btarget
,
1465 (env
->sregs
[SR_MSR
] & MSR_UM
) ? "user" : "kernel",
1466 (env
->sregs
[SR_MSR
] & MSR_UMS
) ? "user" : "kernel",
1467 (env
->sregs
[SR_MSR
] & MSR_EIP
),
1468 (env
->sregs
[SR_MSR
] & MSR_IE
));
1470 for (i
= 0; i
< 32; i
++) {
1471 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
1472 if ((i
+ 1) % 4 == 0)
1473 cpu_fprintf(f
, "\n");
1475 cpu_fprintf(f
, "\n\n");
1478 CPUState
*cpu_mb_init (const char *cpu_model
)
1481 static int tcg_initialized
= 0;
1484 env
= qemu_mallocz(sizeof(CPUState
));
1490 if (tcg_initialized
)
1493 tcg_initialized
= 1;
1495 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
1497 env_debug
= tcg_global_mem_new(TCG_AREG0
,
1498 offsetof(CPUState
, debug
),
1500 env_iflags
= tcg_global_mem_new(TCG_AREG0
,
1501 offsetof(CPUState
, iflags
),
1503 env_imm
= tcg_global_mem_new(TCG_AREG0
,
1504 offsetof(CPUState
, imm
),
1506 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
1507 offsetof(CPUState
, btarget
),
1509 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
1510 offsetof(CPUState
, btaken
),
1512 for (i
= 0; i
< ARRAY_SIZE(cpu_R
); i
++) {
1513 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
1514 offsetof(CPUState
, regs
[i
]),
1517 for (i
= 0; i
< ARRAY_SIZE(cpu_SR
); i
++) {
1518 cpu_SR
[i
] = tcg_global_mem_new(TCG_AREG0
,
1519 offsetof(CPUState
, sregs
[i
]),
1520 special_regnames
[i
]);
1522 #define GEN_HELPER 2
1528 void cpu_reset (CPUState
*env
)
1530 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
1531 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
1532 log_cpu_state(env
, 0);
1535 memset(env
, 0, offsetof(CPUMBState
, breakpoints
));
1538 env
->pvr
.regs
[0] = PVR0_PVR_FULL_MASK \
1539 | PVR0_USE_BARREL_MASK \
1540 | PVR0_USE_DIV_MASK \
1541 | PVR0_USE_HW_MUL_MASK \
1542 | PVR0_USE_EXC_MASK \
1543 | PVR0_USE_ICACHE_MASK \
1544 | PVR0_USE_DCACHE_MASK \
1547 env
->pvr
.regs
[2] = PVR2_D_OPB_MASK \
1551 | PVR2_USE_MSR_INSTR \
1552 | PVR2_USE_PCMP_INSTR \
1553 | PVR2_USE_BARREL_MASK \
1554 | PVR2_USE_DIV_MASK \
1555 | PVR2_USE_HW_MUL_MASK \
1556 | PVR2_USE_MUL64_MASK \
1558 env
->pvr
.regs
[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
1559 env
->pvr
.regs
[11] = PVR11_USE_MMU
| (16 << 17);
1561 env
->sregs
[SR_MSR
] = 0;
1562 #if defined(CONFIG_USER_ONLY)
1563 /* start in user mode with interrupts enabled. */
1564 env
->pvr
.regs
[10] = 0x0c000000; /* Spartan 3a dsp. */
1566 mmu_init(&env
->mmu
);
1568 env
->mmu
.c_mmu_tlb_access
= 3;
1569 env
->mmu
.c_mmu_zones
= 16;
1573 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
1574 unsigned long searched_pc
, int pc_pos
, void *puc
)
1576 env
->sregs
[SR_PC
] = gen_opc_pc
[pc_pos
];