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_DIRECT_CC 2
84 #define JMP_INDIRECT 3
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 /* True if ALU operand b is a small immediate that may deserve
158 static inline int dec_alu_op_b_is_small_imm(DisasContext
*dc
)
160 /* Immediate insn without the imm prefix ? */
161 return dc
->type_b
&& !(dc
->tb_flags
& IMM_FLAG
);
164 static inline TCGv
*dec_alu_op_b(DisasContext
*dc
)
167 if (dc
->tb_flags
& IMM_FLAG
)
168 tcg_gen_ori_tl(env_imm
, env_imm
, dc
->imm
);
170 tcg_gen_movi_tl(env_imm
, (int32_t)((int16_t)dc
->imm
));
173 return &cpu_R
[dc
->rb
];
176 static void dec_add(DisasContext
*dc
)
183 LOG_DIS("add%s%s%s r%d r%d r%d\n",
184 dc
->type_b
? "i" : "", k
? "k" : "", c
? "c" : "",
185 dc
->rd
, dc
->ra
, dc
->rb
);
187 if (k
&& !c
&& dc
->rd
)
188 tcg_gen_add_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
190 gen_helper_addkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
191 tcg_const_tl(k
), tcg_const_tl(c
));
193 TCGv d
= tcg_temp_new();
194 gen_helper_addkc(d
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
195 tcg_const_tl(k
), tcg_const_tl(c
));
200 static void dec_sub(DisasContext
*dc
)
202 unsigned int u
, cmp
, k
, c
;
207 cmp
= (dc
->imm
& 1) && (!dc
->type_b
) && k
;
210 LOG_DIS("cmp%s r%d, r%d ir=%x\n", u
? "u" : "", dc
->rd
, dc
->ra
, dc
->ir
);
213 gen_helper_cmpu(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
215 gen_helper_cmp(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
218 LOG_DIS("sub%s%s r%d, r%d r%d\n",
219 k
? "k" : "", c
? "c" : "", dc
->rd
, dc
->ra
, dc
->rb
);
225 gen_helper_subkc(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
226 tcg_const_tl(k
), tcg_const_tl(c
));
228 gen_helper_subkc(t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)),
229 tcg_const_tl(k
), tcg_const_tl(c
));
233 tcg_gen_sub_tl(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
237 static void dec_pattern(DisasContext
*dc
)
242 if ((dc
->tb_flags
& MSR_EE_FLAG
)
243 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
244 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_PCMP_INSTR
))) {
245 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
246 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
249 mode
= dc
->opcode
& 3;
253 LOG_DIS("pcmpbf r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
255 gen_helper_pcmpbf(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
258 LOG_DIS("pcmpeq r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
260 TCGv t0
= tcg_temp_local_new();
261 l1
= gen_new_label();
262 tcg_gen_movi_tl(t0
, 1);
263 tcg_gen_brcond_tl(TCG_COND_EQ
,
264 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
265 tcg_gen_movi_tl(t0
, 0);
267 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
272 LOG_DIS("pcmpne r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
273 l1
= gen_new_label();
275 TCGv t0
= tcg_temp_local_new();
276 tcg_gen_movi_tl(t0
, 1);
277 tcg_gen_brcond_tl(TCG_COND_NE
,
278 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
], l1
);
279 tcg_gen_movi_tl(t0
, 0);
281 tcg_gen_mov_tl(cpu_R
[dc
->rd
], t0
);
287 "unsupported pattern insn opcode=%x\n", dc
->opcode
);
292 static void dec_and(DisasContext
*dc
)
296 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
301 not = dc
->opcode
& (1 << 1);
302 LOG_DIS("and%s\n", not ? "n" : "");
308 TCGv t
= tcg_temp_new();
309 tcg_gen_not_tl(t
, *(dec_alu_op_b(dc
)));
310 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t
);
313 tcg_gen_and_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
316 static void dec_or(DisasContext
*dc
)
318 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
323 LOG_DIS("or r%d r%d r%d imm=%x\n", dc
->rd
, dc
->ra
, dc
->rb
, dc
->imm
);
325 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
328 static void dec_xor(DisasContext
*dc
)
330 if (!dc
->type_b
&& (dc
->imm
& (1 << 10))) {
335 LOG_DIS("xor r%d\n", dc
->rd
);
337 tcg_gen_xor_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
340 static void read_carry(DisasContext
*dc
, TCGv d
)
342 tcg_gen_shri_tl(d
, cpu_SR
[SR_MSR
], 31);
345 static void write_carry(DisasContext
*dc
, TCGv v
)
347 TCGv t0
= tcg_temp_new();
348 tcg_gen_shli_tl(t0
, v
, 31);
349 tcg_gen_sari_tl(t0
, t0
, 31);
350 tcg_gen_mov_tl(env_debug
, t0
);
351 tcg_gen_andi_tl(t0
, t0
, (MSR_C
| MSR_CC
));
352 tcg_gen_andi_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
],
354 tcg_gen_or_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], t0
);
359 static inline void msr_read(DisasContext
*dc
, TCGv d
)
361 tcg_gen_mov_tl(d
, cpu_SR
[SR_MSR
]);
364 static inline void msr_write(DisasContext
*dc
, TCGv v
)
366 dc
->cpustate_changed
= 1;
367 tcg_gen_mov_tl(cpu_SR
[SR_MSR
], v
);
368 /* PVR, we have a processor version register. */
369 tcg_gen_ori_tl(cpu_SR
[SR_MSR
], cpu_SR
[SR_MSR
], (1 << 10));
372 static void dec_msr(DisasContext
*dc
)
375 unsigned int sr
, to
, rn
;
376 int mem_index
= cpu_mmu_index(dc
->env
);
378 sr
= dc
->imm
& ((1 << 14) - 1);
379 to
= dc
->imm
& (1 << 14);
382 dc
->cpustate_changed
= 1;
384 /* msrclr and msrset. */
385 if (!(dc
->imm
& (1 << 15))) {
386 unsigned int clr
= dc
->ir
& (1 << 16);
388 LOG_DIS("msr%s r%d imm=%x\n", clr
? "clr" : "set",
391 if (!(dc
->env
->pvr
.regs
[2] & PVR2_USE_MSR_INSTR
)) {
396 if ((dc
->tb_flags
& MSR_EE_FLAG
)
397 && mem_index
== MMU_USER_IDX
&& (dc
->imm
!= 4 && dc
->imm
!= 0)) {
398 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
399 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
404 msr_read(dc
, cpu_R
[dc
->rd
]);
409 tcg_gen_mov_tl(t1
, *(dec_alu_op_b(dc
)));
412 tcg_gen_not_tl(t1
, t1
);
413 tcg_gen_and_tl(t0
, t0
, t1
);
415 tcg_gen_or_tl(t0
, t0
, t1
);
419 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
+ 4);
420 dc
->is_jmp
= DISAS_UPDATE
;
425 if ((dc
->tb_flags
& MSR_EE_FLAG
)
426 && mem_index
== MMU_USER_IDX
) {
427 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
428 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
433 #if !defined(CONFIG_USER_ONLY)
434 /* Catch read/writes to the mmu block. */
435 if ((sr
& ~0xff) == 0x1000) {
437 LOG_DIS("m%ss sr%d r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
439 gen_helper_mmu_write(tcg_const_tl(sr
), cpu_R
[dc
->ra
]);
441 gen_helper_mmu_read(cpu_R
[dc
->rd
], tcg_const_tl(sr
));
447 LOG_DIS("m%ss sr%x r%d imm=%x\n", to
? "t" : "f", sr
, dc
->ra
, dc
->imm
);
452 msr_write(dc
, cpu_R
[dc
->ra
]);
455 tcg_gen_mov_tl(cpu_SR
[SR_EAR
], cpu_R
[dc
->ra
]);
458 tcg_gen_mov_tl(cpu_SR
[SR_ESR
], cpu_R
[dc
->ra
]);
461 tcg_gen_andi_tl(cpu_SR
[SR_FSR
], cpu_R
[dc
->ra
], 31);
464 cpu_abort(dc
->env
, "unknown mts reg %x\n", sr
);
468 LOG_DIS("m%ss r%d sr%x imm=%x\n", to
? "t" : "f", dc
->rd
, sr
, dc
->imm
);
472 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
475 msr_read(dc
, cpu_R
[dc
->rd
]);
478 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_EAR
]);
481 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_ESR
]);
484 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_FSR
]);
487 tcg_gen_mov_tl(cpu_R
[dc
->rd
], cpu_SR
[SR_BTR
]);
503 tcg_gen_ld_tl(cpu_R
[dc
->rd
],
504 cpu_env
, offsetof(CPUState
, pvr
.regs
[rn
]));
507 cpu_abort(dc
->env
, "unknown mfs reg %x\n", sr
);
513 tcg_gen_movi_tl(cpu_R
[0], 0);
517 /* 64-bit signed mul, lower result in d and upper in d2. */
518 static void t_gen_muls(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
522 t0
= tcg_temp_new_i64();
523 t1
= tcg_temp_new_i64();
525 tcg_gen_ext_i32_i64(t0
, a
);
526 tcg_gen_ext_i32_i64(t1
, b
);
527 tcg_gen_mul_i64(t0
, t0
, t1
);
529 tcg_gen_trunc_i64_i32(d
, t0
);
530 tcg_gen_shri_i64(t0
, t0
, 32);
531 tcg_gen_trunc_i64_i32(d2
, t0
);
533 tcg_temp_free_i64(t0
);
534 tcg_temp_free_i64(t1
);
537 /* 64-bit unsigned muls, lower result in d and upper in d2. */
538 static void t_gen_mulu(TCGv d
, TCGv d2
, TCGv a
, TCGv b
)
542 t0
= tcg_temp_new_i64();
543 t1
= tcg_temp_new_i64();
545 tcg_gen_extu_i32_i64(t0
, a
);
546 tcg_gen_extu_i32_i64(t1
, b
);
547 tcg_gen_mul_i64(t0
, t0
, t1
);
549 tcg_gen_trunc_i64_i32(d
, t0
);
550 tcg_gen_shri_i64(t0
, t0
, 32);
551 tcg_gen_trunc_i64_i32(d2
, t0
);
553 tcg_temp_free_i64(t0
);
554 tcg_temp_free_i64(t1
);
557 /* Multiplier unit. */
558 static void dec_mul(DisasContext
*dc
)
561 unsigned int subcode
;
563 if ((dc
->tb_flags
& MSR_EE_FLAG
)
564 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
565 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_HW_MUL_MASK
)) {
566 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
567 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
571 subcode
= dc
->imm
& 3;
572 d
[0] = tcg_temp_new();
573 d
[1] = tcg_temp_new();
576 LOG_DIS("muli r%d r%d %x\n", dc
->rd
, dc
->ra
, dc
->imm
);
577 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
581 /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */
582 if (subcode
>= 1 && subcode
<= 3
583 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_MUL64_MASK
))) {
589 LOG_DIS("mul r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
590 t_gen_mulu(cpu_R
[dc
->rd
], d
[1], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
593 LOG_DIS("mulh r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
594 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
597 LOG_DIS("mulhsu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
598 t_gen_muls(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
601 LOG_DIS("mulhu r%d r%d r%d\n", dc
->rd
, dc
->ra
, dc
->rb
);
602 t_gen_mulu(d
[0], cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
605 cpu_abort(dc
->env
, "unknown MUL insn %x\n", subcode
);
614 static void dec_div(DisasContext
*dc
)
621 if ((dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
622 && !((dc
->env
->pvr
.regs
[0] & PVR0_USE_DIV_MASK
))) {
623 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
624 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
628 gen_helper_divu(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
630 gen_helper_divs(cpu_R
[dc
->rd
], *(dec_alu_op_b(dc
)), cpu_R
[dc
->ra
]);
632 tcg_gen_movi_tl(cpu_R
[dc
->rd
], 0);
635 static void dec_barrel(DisasContext
*dc
)
640 if ((dc
->tb_flags
& MSR_EE_FLAG
)
641 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
642 && !(dc
->env
->pvr
.regs
[0] & PVR0_USE_BARREL_MASK
)) {
643 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
644 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
648 s
= dc
->imm
& (1 << 10);
649 t
= dc
->imm
& (1 << 9);
651 LOG_DIS("bs%s%s r%d r%d r%d\n",
652 s
? "l" : "r", t
? "a" : "l", dc
->rd
, dc
->ra
, dc
->rb
);
656 tcg_gen_mov_tl(t0
, *(dec_alu_op_b(dc
)));
657 tcg_gen_andi_tl(t0
, t0
, 31);
660 tcg_gen_shl_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
663 tcg_gen_sar_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
665 tcg_gen_shr_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], t0
);
669 static void dec_bit(DisasContext
*dc
)
673 int mem_index
= cpu_mmu_index(dc
->env
);
675 op
= dc
->ir
& ((1 << 8) - 1);
681 LOG_DIS("src r%d r%d\n", dc
->rd
, dc
->ra
);
682 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
686 tcg_gen_shli_tl(t1
, t1
, 31);
688 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
689 tcg_gen_or_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->rd
], t1
);
702 LOG_DIS("srl r%d r%d\n", dc
->rd
, dc
->ra
);
705 tcg_gen_andi_tl(t0
, cpu_R
[dc
->ra
], 1);
710 tcg_gen_shri_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
712 tcg_gen_sari_tl(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], 1);
716 LOG_DIS("ext8s r%d r%d\n", dc
->rd
, dc
->ra
);
717 tcg_gen_ext8s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
720 LOG_DIS("ext16s r%d r%d\n", dc
->rd
, dc
->ra
);
721 tcg_gen_ext16s_i32(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
728 LOG_DIS("wdc r%d\n", dc
->ra
);
729 if ((dc
->tb_flags
& MSR_EE_FLAG
)
730 && mem_index
== MMU_USER_IDX
) {
731 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
732 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
738 LOG_DIS("wic r%d\n", dc
->ra
);
739 if ((dc
->tb_flags
& MSR_EE_FLAG
)
740 && mem_index
== MMU_USER_IDX
) {
741 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
742 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
747 cpu_abort(dc
->env
, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n",
748 dc
->pc
, op
, dc
->rd
, dc
->ra
, dc
->rb
);
753 static inline void sync_jmpstate(DisasContext
*dc
)
755 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
756 if (dc
->jmp
== JMP_DIRECT
) {
757 tcg_gen_movi_tl(env_btaken
, 1);
759 dc
->jmp
= JMP_INDIRECT
;
760 tcg_gen_movi_tl(env_btarget
, dc
->jmp_pc
);
764 static void dec_imm(DisasContext
*dc
)
766 LOG_DIS("imm %x\n", dc
->imm
<< 16);
767 tcg_gen_movi_tl(env_imm
, (dc
->imm
<< 16));
768 dc
->tb_flags
|= IMM_FLAG
;
772 static inline void gen_load(DisasContext
*dc
, TCGv dst
, TCGv addr
,
775 int mem_index
= cpu_mmu_index(dc
->env
);
778 tcg_gen_qemu_ld8u(dst
, addr
, mem_index
);
779 } else if (size
== 2) {
780 tcg_gen_qemu_ld16u(dst
, addr
, mem_index
);
781 } else if (size
== 4) {
782 tcg_gen_qemu_ld32u(dst
, addr
, mem_index
);
784 cpu_abort(dc
->env
, "Incorrect load size %d\n", size
);
787 static inline TCGv
*compute_ldst_addr(DisasContext
*dc
, TCGv
*t
)
789 unsigned int extimm
= dc
->tb_flags
& IMM_FLAG
;
791 /* Treat the fast cases first. */
793 /* If any of the regs is r0, return a ptr to the other. */
795 return &cpu_R
[dc
->rb
];
796 } else if (dc
->rb
== 0) {
797 return &cpu_R
[dc
->ra
];
801 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
807 return &cpu_R
[dc
->ra
];
810 tcg_gen_movi_tl(*t
, (int32_t)((int16_t)dc
->imm
));
811 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *t
);
814 tcg_gen_add_tl(*t
, cpu_R
[dc
->ra
], *(dec_alu_op_b(dc
)));
820 static void dec_load(DisasContext
*dc
)
825 size
= 1 << (dc
->opcode
& 3);
826 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
827 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
828 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
829 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
833 LOG_DIS("l %x %d\n", dc
->opcode
, size
);
835 addr
= compute_ldst_addr(dc
, &t
);
837 /* If we get a fault on a dslot, the jmpstate better be in sync. */
840 /* Verify alignment if needed. */
841 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
842 TCGv v
= tcg_temp_new();
845 * Microblaze gives MMU faults priority over faults due to
846 * unaligned addresses. That's why we speculatively do the load
847 * into v. If the load succeeds, we verify alignment of the
848 * address and if that succeeds we write into the destination reg.
850 gen_load(dc
, v
, *addr
, size
);
852 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
853 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
854 tcg_const_tl(0), tcg_const_tl(size
- 1));
856 tcg_gen_mov_tl(cpu_R
[dc
->rd
], v
);
860 gen_load(dc
, cpu_R
[dc
->rd
], *addr
, size
);
862 gen_load(dc
, env_imm
, *addr
, size
);
870 static void gen_store(DisasContext
*dc
, TCGv addr
, TCGv val
,
873 int mem_index
= cpu_mmu_index(dc
->env
);
876 tcg_gen_qemu_st8(val
, addr
, mem_index
);
877 else if (size
== 2) {
878 tcg_gen_qemu_st16(val
, addr
, mem_index
);
879 } else if (size
== 4) {
880 tcg_gen_qemu_st32(val
, addr
, mem_index
);
882 cpu_abort(dc
->env
, "Incorrect store size %d\n", size
);
885 static void dec_store(DisasContext
*dc
)
890 size
= 1 << (dc
->opcode
& 3);
892 if (size
> 4 && (dc
->tb_flags
& MSR_EE_FLAG
)
893 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
894 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
895 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
899 LOG_DIS("s%d%s\n", size
, dc
->type_b
? "i" : "");
901 /* If we get a fault on a dslot, the jmpstate better be in sync. */
903 addr
= compute_ldst_addr(dc
, &t
);
905 gen_store(dc
, *addr
, cpu_R
[dc
->rd
], size
);
907 /* Verify alignment if needed. */
908 if ((dc
->env
->pvr
.regs
[2] & PVR2_UNALIGNED_EXC_MASK
) && size
> 1) {
909 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
910 /* FIXME: if the alignment is wrong, we should restore the value
913 gen_helper_memalign(*addr
, tcg_const_tl(dc
->rd
),
914 tcg_const_tl(1), tcg_const_tl(size
- 1));
921 static inline void eval_cc(DisasContext
*dc
, unsigned int cc
,
922 TCGv d
, TCGv a
, TCGv b
)
926 tcg_gen_setcond_tl(TCG_COND_EQ
, d
, a
, b
);
929 tcg_gen_setcond_tl(TCG_COND_NE
, d
, a
, b
);
932 tcg_gen_setcond_tl(TCG_COND_LT
, d
, a
, b
);
935 tcg_gen_setcond_tl(TCG_COND_LE
, d
, a
, b
);
938 tcg_gen_setcond_tl(TCG_COND_GE
, d
, a
, b
);
941 tcg_gen_setcond_tl(TCG_COND_GT
, d
, a
, b
);
944 cpu_abort(dc
->env
, "Unknown condition code %x.\n", cc
);
949 static void eval_cond_jmp(DisasContext
*dc
, TCGv pc_true
, TCGv pc_false
)
953 l1
= gen_new_label();
954 /* Conditional jmp. */
955 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_false
);
956 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, l1
);
957 tcg_gen_mov_tl(cpu_SR
[SR_PC
], pc_true
);
961 static void dec_bcc(DisasContext
*dc
)
966 cc
= EXTRACT_FIELD(dc
->ir
, 21, 23);
967 dslot
= dc
->ir
& (1 << 25);
968 LOG_DIS("bcc%s r%d %x\n", dslot
? "d" : "", dc
->ra
, dc
->imm
);
970 dc
->delayed_branch
= 1;
972 dc
->delayed_branch
= 2;
973 dc
->tb_flags
|= D_FLAG
;
974 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
975 cpu_env
, offsetof(CPUState
, bimm
));
978 if (dec_alu_op_b_is_small_imm(dc
)) {
979 int32_t offset
= (int32_t)((int16_t)dc
->imm
); /* sign-extend. */
981 tcg_gen_movi_tl(env_btarget
, dc
->pc
+ offset
);
982 dc
->jmp
= JMP_DIRECT_CC
;
983 dc
->jmp_pc
= dc
->pc
+ offset
;
985 dc
->jmp
= JMP_INDIRECT
;
986 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
987 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));
992 static void dec_br(DisasContext
*dc
)
994 unsigned int dslot
, link
, abs
;
995 int mem_index
= cpu_mmu_index(dc
->env
);
997 dslot
= dc
->ir
& (1 << 20);
998 abs
= dc
->ir
& (1 << 19);
999 link
= dc
->ir
& (1 << 18);
1000 LOG_DIS("br%s%s%s%s imm=%x\n",
1001 abs
? "a" : "", link
? "l" : "",
1002 dc
->type_b
? "i" : "", dslot
? "d" : "",
1005 dc
->delayed_branch
= 1;
1007 dc
->delayed_branch
= 2;
1008 dc
->tb_flags
|= D_FLAG
;
1009 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1010 cpu_env
, offsetof(CPUState
, bimm
));
1013 tcg_gen_movi_tl(cpu_R
[dc
->rd
], dc
->pc
);
1015 dc
->jmp
= JMP_INDIRECT
;
1017 tcg_gen_movi_tl(env_btaken
, 1);
1018 tcg_gen_mov_tl(env_btarget
, *(dec_alu_op_b(dc
)));
1019 if (link
&& !dslot
) {
1020 if (!(dc
->tb_flags
& IMM_FLAG
) && (dc
->imm
== 8 || dc
->imm
== 0x18))
1021 t_gen_raise_exception(dc
, EXCP_BREAK
);
1023 if ((dc
->tb_flags
& MSR_EE_FLAG
) && mem_index
== MMU_USER_IDX
) {
1024 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1025 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1029 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1033 if (dec_alu_op_b_is_small_imm(dc
)) {
1034 dc
->jmp
= JMP_DIRECT
;
1035 dc
->jmp_pc
= dc
->pc
+ (int32_t)((int16_t)dc
->imm
);
1037 tcg_gen_movi_tl(env_btaken
, 1);
1038 tcg_gen_movi_tl(env_btarget
, dc
->pc
);
1039 tcg_gen_add_tl(env_btarget
, env_btarget
, *(dec_alu_op_b(dc
)));
1044 static inline void do_rti(DisasContext
*dc
)
1047 t0
= tcg_temp_new();
1048 t1
= tcg_temp_new();
1049 tcg_gen_shri_tl(t0
, cpu_SR
[SR_MSR
], 1);
1050 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_IE
);
1051 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1053 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1054 tcg_gen_or_tl(t1
, t1
, t0
);
1058 dc
->tb_flags
&= ~DRTI_FLAG
;
1061 static inline void do_rtb(DisasContext
*dc
)
1064 t0
= tcg_temp_new();
1065 t1
= tcg_temp_new();
1066 tcg_gen_andi_tl(t1
, cpu_SR
[SR_MSR
], ~MSR_BIP
);
1067 tcg_gen_shri_tl(t0
, t1
, 1);
1068 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1070 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1071 tcg_gen_or_tl(t1
, t1
, t0
);
1075 dc
->tb_flags
&= ~DRTB_FLAG
;
1078 static inline void do_rte(DisasContext
*dc
)
1081 t0
= tcg_temp_new();
1082 t1
= tcg_temp_new();
1084 tcg_gen_ori_tl(t1
, cpu_SR
[SR_MSR
], MSR_EE
);
1085 tcg_gen_andi_tl(t1
, t1
, ~MSR_EIP
);
1086 tcg_gen_shri_tl(t0
, t1
, 1);
1087 tcg_gen_andi_tl(t0
, t0
, (MSR_VM
| MSR_UM
));
1089 tcg_gen_andi_tl(t1
, t1
, ~(MSR_VM
| MSR_UM
));
1090 tcg_gen_or_tl(t1
, t1
, t0
);
1094 dc
->tb_flags
&= ~DRTE_FLAG
;
1097 static void dec_rts(DisasContext
*dc
)
1099 unsigned int b_bit
, i_bit
, e_bit
;
1100 int mem_index
= cpu_mmu_index(dc
->env
);
1102 i_bit
= dc
->ir
& (1 << 21);
1103 b_bit
= dc
->ir
& (1 << 22);
1104 e_bit
= dc
->ir
& (1 << 23);
1106 dc
->delayed_branch
= 2;
1107 dc
->tb_flags
|= D_FLAG
;
1108 tcg_gen_st_tl(tcg_const_tl(dc
->type_b
&& (dc
->tb_flags
& IMM_FLAG
)),
1109 cpu_env
, offsetof(CPUState
, bimm
));
1112 LOG_DIS("rtid ir=%x\n", dc
->ir
);
1113 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1114 && mem_index
== MMU_USER_IDX
) {
1115 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1116 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1118 dc
->tb_flags
|= DRTI_FLAG
;
1120 LOG_DIS("rtbd ir=%x\n", dc
->ir
);
1121 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1122 && mem_index
== MMU_USER_IDX
) {
1123 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1124 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1126 dc
->tb_flags
|= DRTB_FLAG
;
1128 LOG_DIS("rted ir=%x\n", dc
->ir
);
1129 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1130 && mem_index
== MMU_USER_IDX
) {
1131 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_PRIVINSN
);
1132 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1134 dc
->tb_flags
|= DRTE_FLAG
;
1136 LOG_DIS("rts ir=%x\n", dc
->ir
);
1138 dc
->jmp
= JMP_INDIRECT
;
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 int dec_check_fpuv2(DisasContext
*dc
)
1147 r
= dc
->env
->pvr
.regs
[2] & PVR2_USE_FPU2_MASK
;
1149 if (!r
&& (dc
->tb_flags
& MSR_EE_FLAG
)) {
1150 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_FPU
);
1151 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1156 static void dec_fpu(DisasContext
*dc
)
1158 unsigned int fpu_insn
;
1160 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1161 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1162 && !((dc
->env
->pvr
.regs
[2] & PVR2_USE_FPU_MASK
))) {
1163 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1164 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1168 fpu_insn
= (dc
->ir
>> 7) & 7;
1172 gen_helper_fadd(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1176 gen_helper_frsub(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1180 gen_helper_fmul(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1184 gen_helper_fdiv(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1188 switch ((dc
->ir
>> 4) & 7) {
1190 gen_helper_fcmp_un(cpu_R
[dc
->rd
],
1191 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1194 gen_helper_fcmp_lt(cpu_R
[dc
->rd
],
1195 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1198 gen_helper_fcmp_eq(cpu_R
[dc
->rd
],
1199 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1202 gen_helper_fcmp_le(cpu_R
[dc
->rd
],
1203 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1206 gen_helper_fcmp_gt(cpu_R
[dc
->rd
],
1207 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1210 gen_helper_fcmp_ne(cpu_R
[dc
->rd
],
1211 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1214 gen_helper_fcmp_ge(cpu_R
[dc
->rd
],
1215 cpu_R
[dc
->ra
], cpu_R
[dc
->rb
]);
1218 qemu_log ("unimplemented fcmp fpu_insn=%x pc=%x opc=%x\n",
1219 fpu_insn
, dc
->pc
, dc
->opcode
);
1220 dc
->abort_at_next_insn
= 1;
1226 if (!dec_check_fpuv2(dc
)) {
1229 gen_helper_flt(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1233 if (!dec_check_fpuv2(dc
)) {
1236 gen_helper_fint(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1240 if (!dec_check_fpuv2(dc
)) {
1243 gen_helper_fsqrt(cpu_R
[dc
->rd
], cpu_R
[dc
->ra
]);
1247 qemu_log ("unimplemented FPU insn fpu_insn=%x pc=%x opc=%x\n",
1248 fpu_insn
, dc
->pc
, dc
->opcode
);
1249 dc
->abort_at_next_insn
= 1;
1254 static void dec_null(DisasContext
*dc
)
1256 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1257 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)) {
1258 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1259 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1262 qemu_log ("unknown insn pc=%x opc=%x\n", dc
->pc
, dc
->opcode
);
1263 dc
->abort_at_next_insn
= 1;
1266 static struct decoder_info
{
1271 void (*dec
)(DisasContext
*dc
);
1279 {DEC_BARREL
, dec_barrel
},
1281 {DEC_ST
, dec_store
},
1293 static inline void decode(DisasContext
*dc
)
1298 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
1299 tcg_gen_debug_insn_start(dc
->pc
);
1301 dc
->ir
= ir
= ldl_code(dc
->pc
);
1302 LOG_DIS("%8.8x\t", dc
->ir
);
1307 if ((dc
->tb_flags
& MSR_EE_FLAG
)
1308 && (dc
->env
->pvr
.regs
[2] & PVR2_ILL_OPCODE_EXC_MASK
)
1309 && (dc
->env
->pvr
.regs
[2] & PVR2_OPCODE_0x0_ILL_MASK
)) {
1310 tcg_gen_movi_tl(cpu_SR
[SR_ESR
], ESR_EC_ILLEGAL_OP
);
1311 t_gen_raise_exception(dc
, EXCP_HW_EXCP
);
1315 LOG_DIS("nr_nops=%d\t", dc
->nr_nops
);
1317 if (dc
->nr_nops
> 4)
1318 cpu_abort(dc
->env
, "fetching nop sequence\n");
1320 /* bit 2 seems to indicate insn type. */
1321 dc
->type_b
= ir
& (1 << 29);
1323 dc
->opcode
= EXTRACT_FIELD(ir
, 26, 31);
1324 dc
->rd
= EXTRACT_FIELD(ir
, 21, 25);
1325 dc
->ra
= EXTRACT_FIELD(ir
, 16, 20);
1326 dc
->rb
= EXTRACT_FIELD(ir
, 11, 15);
1327 dc
->imm
= EXTRACT_FIELD(ir
, 0, 15);
1329 /* Large switch for all insns. */
1330 for (i
= 0; i
< ARRAY_SIZE(decinfo
); i
++) {
1331 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
) {
1338 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
1342 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
1343 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
1344 if (bp
->pc
== dc
->pc
) {
1345 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1346 dc
->is_jmp
= DISAS_UPDATE
;
1352 /* generate intermediate code for basic block 'tb'. */
1354 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
1357 uint16_t *gen_opc_end
;
1360 struct DisasContext ctx
;
1361 struct DisasContext
*dc
= &ctx
;
1362 uint32_t next_page_start
, org_flags
;
1367 qemu_log_try_set_file(stderr
);
1372 org_flags
= dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1374 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1376 dc
->is_jmp
= DISAS_NEXT
;
1378 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1379 if (dc
->delayed_branch
) {
1380 dc
->jmp
= JMP_INDIRECT
;
1383 dc
->singlestep_enabled
= env
->singlestep_enabled
;
1384 dc
->cpustate_changed
= 0;
1385 dc
->abort_at_next_insn
= 0;
1389 cpu_abort(env
, "Microblaze: unaligned PC=%x\n", pc_start
);
1391 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1393 qemu_log("--------------\n");
1394 log_cpu_state(env
, 0);
1398 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1401 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1403 max_insns
= CF_COUNT_MASK
;
1409 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1410 tcg_gen_movi_tl(cpu_SR
[SR_PC
], dc
->pc
);
1414 check_breakpoint(env
, dc
);
1417 j
= gen_opc_ptr
- gen_opc_buf
;
1421 gen_opc_instr_start
[lj
++] = 0;
1423 gen_opc_pc
[lj
] = dc
->pc
;
1424 gen_opc_instr_start
[lj
] = 1;
1425 gen_opc_icount
[lj
] = num_insns
;
1429 LOG_DIS("%8.8x:\t", dc
->pc
);
1431 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
1437 dc
->tb_flags
&= ~IMM_FLAG
;
1441 if (dc
->delayed_branch
) {
1442 dc
->delayed_branch
--;
1443 if (!dc
->delayed_branch
) {
1444 if (dc
->tb_flags
& DRTI_FLAG
)
1446 if (dc
->tb_flags
& DRTB_FLAG
)
1448 if (dc
->tb_flags
& DRTE_FLAG
)
1450 /* Clear the delay slot flag. */
1451 dc
->tb_flags
&= ~D_FLAG
;
1452 /* If it is a direct jump, try direct chaining. */
1453 if (dc
->jmp
== JMP_INDIRECT
) {
1454 eval_cond_jmp(dc
, env_btarget
, tcg_const_tl(dc
->pc
));
1455 dc
->is_jmp
= DISAS_JUMP
;
1456 } else if (dc
->jmp
== JMP_DIRECT
) {
1458 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
1459 dc
->is_jmp
= DISAS_TB_JUMP
;
1460 } else if (dc
->jmp
== JMP_DIRECT_CC
) {
1464 l1
= gen_new_label();
1465 /* Conditional jmp. */
1466 tcg_gen_brcondi_tl(TCG_COND_NE
, env_btaken
, 0, l1
);
1467 gen_goto_tb(dc
, 1, dc
->pc
);
1469 gen_goto_tb(dc
, 0, dc
->jmp_pc
);
1471 dc
->is_jmp
= DISAS_TB_JUMP
;
1476 if (env
->singlestep_enabled
)
1478 } while (!dc
->is_jmp
&& !dc
->cpustate_changed
1479 && gen_opc_ptr
< gen_opc_end
1481 && (dc
->pc
< next_page_start
)
1482 && num_insns
< max_insns
);
1485 if (dc
->jmp
== JMP_DIRECT
|| dc
->jmp
== JMP_DIRECT_CC
) {
1486 if (dc
->tb_flags
& D_FLAG
) {
1487 dc
->is_jmp
= DISAS_UPDATE
;
1488 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1494 if (tb
->cflags
& CF_LAST_IO
)
1496 /* Force an update if the per-tb cpu state has changed. */
1497 if (dc
->is_jmp
== DISAS_NEXT
1498 && (dc
->cpustate_changed
|| org_flags
!= dc
->tb_flags
)) {
1499 dc
->is_jmp
= DISAS_UPDATE
;
1500 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1504 if (unlikely(env
->singlestep_enabled
)) {
1505 t_gen_raise_exception(dc
, EXCP_DEBUG
);
1506 if (dc
->is_jmp
== DISAS_NEXT
)
1507 tcg_gen_movi_tl(cpu_SR
[SR_PC
], npc
);
1509 switch(dc
->is_jmp
) {
1511 gen_goto_tb(dc
, 1, npc
);
1516 /* indicate that the hash table must be used
1517 to find the next TB */
1521 /* nothing more to generate */
1525 gen_icount_end(tb
, num_insns
);
1526 *gen_opc_ptr
= INDEX_op_end
;
1528 j
= gen_opc_ptr
- gen_opc_buf
;
1531 gen_opc_instr_start
[lj
++] = 0;
1533 tb
->size
= dc
->pc
- pc_start
;
1534 tb
->icount
= num_insns
;
1539 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1542 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
1544 qemu_log("\nisize=%d osize=%td\n",
1545 dc
->pc
- pc_start
, gen_opc_ptr
- gen_opc_buf
);
1549 assert(!dc
->abort_at_next_insn
);
1552 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
1554 gen_intermediate_code_internal(env
, tb
, 0);
1557 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
1559 gen_intermediate_code_internal(env
, tb
, 1);
1562 void cpu_dump_state (CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
1570 cpu_fprintf(f
, "IN: PC=%x %s\n",
1571 env
->sregs
[SR_PC
], lookup_symbol(env
->sregs
[SR_PC
]));
1572 cpu_fprintf(f
, "rmsr=%x resr=%x rear=%x debug=%x imm=%x iflags=%x fsr=%x\n",
1573 env
->sregs
[SR_MSR
], env
->sregs
[SR_ESR
], env
->sregs
[SR_EAR
],
1574 env
->debug
, env
->imm
, env
->iflags
, env
->sregs
[SR_FSR
]);
1575 cpu_fprintf(f
, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
1576 env
->btaken
, env
->btarget
,
1577 (env
->sregs
[SR_MSR
] & MSR_UM
) ? "user" : "kernel",
1578 (env
->sregs
[SR_MSR
] & MSR_UMS
) ? "user" : "kernel",
1579 (env
->sregs
[SR_MSR
] & MSR_EIP
),
1580 (env
->sregs
[SR_MSR
] & MSR_IE
));
1582 for (i
= 0; i
< 32; i
++) {
1583 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
1584 if ((i
+ 1) % 4 == 0)
1585 cpu_fprintf(f
, "\n");
1587 cpu_fprintf(f
, "\n\n");
1590 CPUState
*cpu_mb_init (const char *cpu_model
)
1593 static int tcg_initialized
= 0;
1596 env
= qemu_mallocz(sizeof(CPUState
));
1600 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
1602 if (tcg_initialized
)
1605 tcg_initialized
= 1;
1607 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
1609 env_debug
= tcg_global_mem_new(TCG_AREG0
,
1610 offsetof(CPUState
, debug
),
1612 env_iflags
= tcg_global_mem_new(TCG_AREG0
,
1613 offsetof(CPUState
, iflags
),
1615 env_imm
= tcg_global_mem_new(TCG_AREG0
,
1616 offsetof(CPUState
, imm
),
1618 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
1619 offsetof(CPUState
, btarget
),
1621 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
1622 offsetof(CPUState
, btaken
),
1624 for (i
= 0; i
< ARRAY_SIZE(cpu_R
); i
++) {
1625 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
1626 offsetof(CPUState
, regs
[i
]),
1629 for (i
= 0; i
< ARRAY_SIZE(cpu_SR
); i
++) {
1630 cpu_SR
[i
] = tcg_global_mem_new(TCG_AREG0
,
1631 offsetof(CPUState
, sregs
[i
]),
1632 special_regnames
[i
]);
1634 #define GEN_HELPER 2
1640 void cpu_reset (CPUState
*env
)
1642 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
1643 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
1644 log_cpu_state(env
, 0);
1647 memset(env
, 0, offsetof(CPUMBState
, breakpoints
));
1650 env
->pvr
.regs
[0] = PVR0_PVR_FULL_MASK \
1651 | PVR0_USE_BARREL_MASK \
1652 | PVR0_USE_DIV_MASK \
1653 | PVR0_USE_HW_MUL_MASK \
1654 | PVR0_USE_EXC_MASK \
1655 | PVR0_USE_ICACHE_MASK \
1656 | PVR0_USE_DCACHE_MASK \
1659 env
->pvr
.regs
[2] = PVR2_D_OPB_MASK \
1663 | PVR2_USE_MSR_INSTR \
1664 | PVR2_USE_PCMP_INSTR \
1665 | PVR2_USE_BARREL_MASK \
1666 | PVR2_USE_DIV_MASK \
1667 | PVR2_USE_HW_MUL_MASK \
1668 | PVR2_USE_MUL64_MASK \
1669 | PVR2_USE_FPU_MASK \
1670 | PVR2_USE_FPU2_MASK \
1671 | PVR2_FPU_EXC_MASK \
1673 env
->pvr
.regs
[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
1674 env
->pvr
.regs
[11] = PVR11_USE_MMU
| (16 << 17);
1676 #if defined(CONFIG_USER_ONLY)
1677 /* start in user mode with interrupts enabled. */
1678 env
->sregs
[SR_MSR
] = MSR_EE
| MSR_IE
| MSR_VM
| MSR_UM
;
1679 env
->pvr
.regs
[10] = 0x0c000000; /* Spartan 3a dsp. */
1681 env
->sregs
[SR_MSR
] = 0;
1682 mmu_init(&env
->mmu
);
1684 env
->mmu
.c_mmu_tlb_access
= 3;
1685 env
->mmu
.c_mmu_zones
= 16;
1689 void gen_pc_load(CPUState
*env
, struct TranslationBlock
*tb
,
1690 unsigned long searched_pc
, int pc_pos
, void *puc
)
1692 env
->sregs
[SR_PC
] = gen_opc_pc
[pc_pos
];