remove #if 0 code for timers
[qemu/opensuse.git] / target-microblaze / translate.c
blob96ce2ece5183041fcf965251fa9e85ddb4473895
1 /*
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/>.
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <inttypes.h>
25 #include <assert.h>
27 #include "cpu.h"
28 #include "disas.h"
29 #include "tcg-op.h"
30 #include "helper.h"
31 #include "microblaze-decode.h"
32 #include "qemu-common.h"
34 #define GEN_HELPER 1
35 #include "helper.h"
37 #define SIM_COMPAT 0
38 #define DISAS_GNU 1
39 #define DISAS_MB 1
40 #if DISAS_MB && !SIM_COMPAT
41 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
42 #else
43 # define LOG_DIS(...) do { } while (0)
44 #endif
46 #define D(x)
48 #define EXTRACT_FIELD(src, start, end) \
49 (((src) >> start) & ((1 << (end - start + 1)) - 1))
51 static TCGv env_debug;
52 static TCGv_ptr cpu_env;
53 static TCGv cpu_R[32];
54 static TCGv cpu_SR[18];
55 static TCGv env_imm;
56 static TCGv env_btaken;
57 static TCGv env_btarget;
58 static TCGv env_iflags;
60 #include "gen-icount.h"
62 /* This is the state at translation time. */
63 typedef struct DisasContext {
64 CPUState *env;
65 target_ulong pc;
67 /* Decoder. */
68 int type_b;
69 uint32_t ir;
70 uint8_t opcode;
71 uint8_t rd, ra, rb;
72 uint16_t imm;
74 unsigned int cpustate_changed;
75 unsigned int delayed_branch;
76 unsigned int tb_flags, synced_flags; /* tb dependent flags. */
77 unsigned int clear_imm;
78 int is_jmp;
80 #define JMP_NOJMP 0
81 #define JMP_DIRECT 1
82 #define JMP_DIRECT_CC 2
83 #define JMP_INDIRECT 3
84 unsigned int jmp;
85 uint32_t jmp_pc;
87 int abort_at_next_insn;
88 int nr_nops;
89 struct TranslationBlock *tb;
90 int singlestep_enabled;
91 } DisasContext;
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)
111 int sval;
113 /* LSL. */
114 val <<= 31 - width;
115 sval = val;
116 /* ASR. */
117 sval >>= 31 - width;
118 return sval;
121 static inline void t_sync_flags(DisasContext *dc)
123 /* Synch the tb dependent 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);
134 t_sync_flags(dc);
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;
144 tb = dc->tb;
145 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
146 tcg_gen_goto_tb(n);
147 tcg_gen_movi_tl(cpu_SR[SR_PC], dest);
148 tcg_gen_exit_tb((tcg_target_long)tb + n);
149 } else {
150 tcg_gen_movi_tl(cpu_SR[SR_PC], dest);
151 tcg_gen_exit_tb(0);
155 static void read_carry(DisasContext *dc, TCGv d)
157 tcg_gen_shri_tl(d, cpu_SR[SR_MSR], 31);
160 static void write_carry(DisasContext *dc, TCGv v)
162 TCGv t0 = tcg_temp_new();
163 tcg_gen_shli_tl(t0, v, 31);
164 tcg_gen_sari_tl(t0, t0, 31);
165 tcg_gen_andi_tl(t0, t0, (MSR_C | MSR_CC));
166 tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR],
167 ~(MSR_C | MSR_CC));
168 tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t0);
169 tcg_temp_free(t0);
172 /* True if ALU operand b is a small immediate that may deserve
173 faster treatment. */
174 static inline int dec_alu_op_b_is_small_imm(DisasContext *dc)
176 /* Immediate insn without the imm prefix ? */
177 return dc->type_b && !(dc->tb_flags & IMM_FLAG);
180 static inline TCGv *dec_alu_op_b(DisasContext *dc)
182 if (dc->type_b) {
183 if (dc->tb_flags & IMM_FLAG)
184 tcg_gen_ori_tl(env_imm, env_imm, dc->imm);
185 else
186 tcg_gen_movi_tl(env_imm, (int32_t)((int16_t)dc->imm));
187 return &env_imm;
188 } else
189 return &cpu_R[dc->rb];
192 static void dec_add(DisasContext *dc)
194 unsigned int k, c;
195 TCGv cf;
197 k = dc->opcode & 4;
198 c = dc->opcode & 2;
200 LOG_DIS("add%s%s%s r%d r%d r%d\n",
201 dc->type_b ? "i" : "", k ? "k" : "", c ? "c" : "",
202 dc->rd, dc->ra, dc->rb);
204 /* Take care of the easy cases first. */
205 if (k) {
206 /* k - keep carry, no need to update MSR. */
207 /* If rd == r0, it's a nop. */
208 if (dc->rd) {
209 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
211 if (c) {
212 /* c - Add carry into the result. */
213 cf = tcg_temp_new();
215 read_carry(dc, cf);
216 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf);
217 tcg_temp_free(cf);
220 return;
223 /* From now on, we can assume k is zero. So we need to update MSR. */
224 /* Extract carry. */
225 cf = tcg_temp_new();
226 if (c) {
227 read_carry(dc, cf);
228 } else {
229 tcg_gen_movi_tl(cf, 0);
232 if (dc->rd) {
233 TCGv ncf = tcg_temp_new();
234 gen_helper_carry(ncf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf);
235 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
236 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf);
237 write_carry(dc, ncf);
238 tcg_temp_free(ncf);
239 } else {
240 gen_helper_carry(cf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf);
241 write_carry(dc, cf);
243 tcg_temp_free(cf);
246 static void dec_sub(DisasContext *dc)
248 unsigned int u, cmp, k, c;
249 TCGv cf, na;
251 u = dc->imm & 2;
252 k = dc->opcode & 4;
253 c = dc->opcode & 2;
254 cmp = (dc->imm & 1) && (!dc->type_b) && k;
256 if (cmp) {
257 LOG_DIS("cmp%s r%d, r%d ir=%x\n", u ? "u" : "", dc->rd, dc->ra, dc->ir);
258 if (dc->rd) {
259 if (u)
260 gen_helper_cmpu(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
261 else
262 gen_helper_cmp(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
264 return;
267 LOG_DIS("sub%s%s r%d, r%d r%d\n",
268 k ? "k" : "", c ? "c" : "", dc->rd, dc->ra, dc->rb);
270 /* Take care of the easy cases first. */
271 if (k) {
272 /* k - keep carry, no need to update MSR. */
273 /* If rd == r0, it's a nop. */
274 if (dc->rd) {
275 tcg_gen_sub_tl(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
277 if (c) {
278 /* c - Add carry into the result. */
279 cf = tcg_temp_new();
281 read_carry(dc, cf);
282 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf);
283 tcg_temp_free(cf);
286 return;
289 /* From now on, we can assume k is zero. So we need to update MSR. */
290 /* Extract carry. And complement a into na. */
291 cf = tcg_temp_new();
292 na = tcg_temp_new();
293 if (c) {
294 read_carry(dc, cf);
295 } else {
296 tcg_gen_movi_tl(cf, 1);
299 /* d = b + ~a + c. carry defaults to 1. */
300 tcg_gen_not_tl(na, cpu_R[dc->ra]);
302 if (dc->rd) {
303 TCGv ncf = tcg_temp_new();
304 gen_helper_carry(ncf, na, *(dec_alu_op_b(dc)), cf);
305 tcg_gen_add_tl(cpu_R[dc->rd], na, *(dec_alu_op_b(dc)));
306 tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf);
307 write_carry(dc, ncf);
308 tcg_temp_free(ncf);
309 } else {
310 gen_helper_carry(cf, na, *(dec_alu_op_b(dc)), cf);
311 write_carry(dc, cf);
313 tcg_temp_free(cf);
314 tcg_temp_free(na);
317 static void dec_pattern(DisasContext *dc)
319 unsigned int mode;
320 int l1;
322 if ((dc->tb_flags & MSR_EE_FLAG)
323 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
324 && !((dc->env->pvr.regs[2] & PVR2_USE_PCMP_INSTR))) {
325 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
326 t_gen_raise_exception(dc, EXCP_HW_EXCP);
329 mode = dc->opcode & 3;
330 switch (mode) {
331 case 0:
332 /* pcmpbf. */
333 LOG_DIS("pcmpbf r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
334 if (dc->rd)
335 gen_helper_pcmpbf(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
336 break;
337 case 2:
338 LOG_DIS("pcmpeq r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
339 if (dc->rd) {
340 TCGv t0 = tcg_temp_local_new();
341 l1 = gen_new_label();
342 tcg_gen_movi_tl(t0, 1);
343 tcg_gen_brcond_tl(TCG_COND_EQ,
344 cpu_R[dc->ra], cpu_R[dc->rb], l1);
345 tcg_gen_movi_tl(t0, 0);
346 gen_set_label(l1);
347 tcg_gen_mov_tl(cpu_R[dc->rd], t0);
348 tcg_temp_free(t0);
350 break;
351 case 3:
352 LOG_DIS("pcmpne r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
353 l1 = gen_new_label();
354 if (dc->rd) {
355 TCGv t0 = tcg_temp_local_new();
356 tcg_gen_movi_tl(t0, 1);
357 tcg_gen_brcond_tl(TCG_COND_NE,
358 cpu_R[dc->ra], cpu_R[dc->rb], l1);
359 tcg_gen_movi_tl(t0, 0);
360 gen_set_label(l1);
361 tcg_gen_mov_tl(cpu_R[dc->rd], t0);
362 tcg_temp_free(t0);
364 break;
365 default:
366 cpu_abort(dc->env,
367 "unsupported pattern insn opcode=%x\n", dc->opcode);
368 break;
372 static void dec_and(DisasContext *dc)
374 unsigned int not;
376 if (!dc->type_b && (dc->imm & (1 << 10))) {
377 dec_pattern(dc);
378 return;
381 not = dc->opcode & (1 << 1);
382 LOG_DIS("and%s\n", not ? "n" : "");
384 if (!dc->rd)
385 return;
387 if (not) {
388 TCGv t = tcg_temp_new();
389 tcg_gen_not_tl(t, *(dec_alu_op_b(dc)));
390 tcg_gen_and_tl(cpu_R[dc->rd], cpu_R[dc->ra], t);
391 tcg_temp_free(t);
392 } else
393 tcg_gen_and_tl(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
396 static void dec_or(DisasContext *dc)
398 if (!dc->type_b && (dc->imm & (1 << 10))) {
399 dec_pattern(dc);
400 return;
403 LOG_DIS("or r%d r%d r%d imm=%x\n", dc->rd, dc->ra, dc->rb, dc->imm);
404 if (dc->rd)
405 tcg_gen_or_tl(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
408 static void dec_xor(DisasContext *dc)
410 if (!dc->type_b && (dc->imm & (1 << 10))) {
411 dec_pattern(dc);
412 return;
415 LOG_DIS("xor r%d\n", dc->rd);
416 if (dc->rd)
417 tcg_gen_xor_tl(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
420 static inline void msr_read(DisasContext *dc, TCGv d)
422 tcg_gen_mov_tl(d, cpu_SR[SR_MSR]);
425 static inline void msr_write(DisasContext *dc, TCGv v)
427 TCGv t;
429 t = tcg_temp_new();
430 dc->cpustate_changed = 1;
431 /* PVR bit is not writable. */
432 tcg_gen_andi_tl(t, v, ~MSR_PVR);
433 tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
434 tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
435 tcg_temp_free(t);
438 static void dec_msr(DisasContext *dc)
440 TCGv t0, t1;
441 unsigned int sr, to, rn;
442 int mem_index = cpu_mmu_index(dc->env);
444 sr = dc->imm & ((1 << 14) - 1);
445 to = dc->imm & (1 << 14);
446 dc->type_b = 1;
447 if (to)
448 dc->cpustate_changed = 1;
450 /* msrclr and msrset. */
451 if (!(dc->imm & (1 << 15))) {
452 unsigned int clr = dc->ir & (1 << 16);
454 LOG_DIS("msr%s r%d imm=%x\n", clr ? "clr" : "set",
455 dc->rd, dc->imm);
457 if (!(dc->env->pvr.regs[2] & PVR2_USE_MSR_INSTR)) {
458 /* nop??? */
459 return;
462 if ((dc->tb_flags & MSR_EE_FLAG)
463 && mem_index == MMU_USER_IDX && (dc->imm != 4 && dc->imm != 0)) {
464 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
465 t_gen_raise_exception(dc, EXCP_HW_EXCP);
466 return;
469 if (dc->rd)
470 msr_read(dc, cpu_R[dc->rd]);
472 t0 = tcg_temp_new();
473 t1 = tcg_temp_new();
474 msr_read(dc, t0);
475 tcg_gen_mov_tl(t1, *(dec_alu_op_b(dc)));
477 if (clr) {
478 tcg_gen_not_tl(t1, t1);
479 tcg_gen_and_tl(t0, t0, t1);
480 } else
481 tcg_gen_or_tl(t0, t0, t1);
482 msr_write(dc, t0);
483 tcg_temp_free(t0);
484 tcg_temp_free(t1);
485 tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc + 4);
486 dc->is_jmp = DISAS_UPDATE;
487 return;
490 if (to) {
491 if ((dc->tb_flags & MSR_EE_FLAG)
492 && mem_index == MMU_USER_IDX) {
493 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
494 t_gen_raise_exception(dc, EXCP_HW_EXCP);
495 return;
499 #if !defined(CONFIG_USER_ONLY)
500 /* Catch read/writes to the mmu block. */
501 if ((sr & ~0xff) == 0x1000) {
502 sr &= 7;
503 LOG_DIS("m%ss sr%d r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm);
504 if (to)
505 gen_helper_mmu_write(tcg_const_tl(sr), cpu_R[dc->ra]);
506 else
507 gen_helper_mmu_read(cpu_R[dc->rd], tcg_const_tl(sr));
508 return;
510 #endif
512 if (to) {
513 LOG_DIS("m%ss sr%x r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm);
514 switch (sr) {
515 case 0:
516 break;
517 case 1:
518 msr_write(dc, cpu_R[dc->ra]);
519 break;
520 case 0x3:
521 tcg_gen_mov_tl(cpu_SR[SR_EAR], cpu_R[dc->ra]);
522 break;
523 case 0x5:
524 tcg_gen_mov_tl(cpu_SR[SR_ESR], cpu_R[dc->ra]);
525 break;
526 case 0x7:
527 tcg_gen_andi_tl(cpu_SR[SR_FSR], cpu_R[dc->ra], 31);
528 break;
529 case 0x800:
530 tcg_gen_st_tl(cpu_R[dc->ra], cpu_env, offsetof(CPUState, slr));
531 break;
532 case 0x802:
533 tcg_gen_st_tl(cpu_R[dc->ra], cpu_env, offsetof(CPUState, shr));
534 break;
535 default:
536 cpu_abort(dc->env, "unknown mts reg %x\n", sr);
537 break;
539 } else {
540 LOG_DIS("m%ss r%d sr%x imm=%x\n", to ? "t" : "f", dc->rd, sr, dc->imm);
542 switch (sr) {
543 case 0:
544 tcg_gen_movi_tl(cpu_R[dc->rd], dc->pc);
545 break;
546 case 1:
547 msr_read(dc, cpu_R[dc->rd]);
548 break;
549 case 0x3:
550 tcg_gen_mov_tl(cpu_R[dc->rd], cpu_SR[SR_EAR]);
551 break;
552 case 0x5:
553 tcg_gen_mov_tl(cpu_R[dc->rd], cpu_SR[SR_ESR]);
554 break;
555 case 0x7:
556 tcg_gen_mov_tl(cpu_R[dc->rd], cpu_SR[SR_FSR]);
557 break;
558 case 0xb:
559 tcg_gen_mov_tl(cpu_R[dc->rd], cpu_SR[SR_BTR]);
560 break;
561 case 0x800:
562 tcg_gen_ld_tl(cpu_R[dc->rd], cpu_env, offsetof(CPUState, slr));
563 break;
564 case 0x802:
565 tcg_gen_ld_tl(cpu_R[dc->rd], cpu_env, offsetof(CPUState, shr));
566 break;
567 case 0x2000:
568 case 0x2001:
569 case 0x2002:
570 case 0x2003:
571 case 0x2004:
572 case 0x2005:
573 case 0x2006:
574 case 0x2007:
575 case 0x2008:
576 case 0x2009:
577 case 0x200a:
578 case 0x200b:
579 case 0x200c:
580 rn = sr & 0xf;
581 tcg_gen_ld_tl(cpu_R[dc->rd],
582 cpu_env, offsetof(CPUState, pvr.regs[rn]));
583 break;
584 default:
585 cpu_abort(dc->env, "unknown mfs reg %x\n", sr);
586 break;
590 if (dc->rd == 0) {
591 tcg_gen_movi_tl(cpu_R[0], 0);
595 /* 64-bit signed mul, lower result in d and upper in d2. */
596 static void t_gen_muls(TCGv d, TCGv d2, TCGv a, TCGv b)
598 TCGv_i64 t0, t1;
600 t0 = tcg_temp_new_i64();
601 t1 = tcg_temp_new_i64();
603 tcg_gen_ext_i32_i64(t0, a);
604 tcg_gen_ext_i32_i64(t1, b);
605 tcg_gen_mul_i64(t0, t0, t1);
607 tcg_gen_trunc_i64_i32(d, t0);
608 tcg_gen_shri_i64(t0, t0, 32);
609 tcg_gen_trunc_i64_i32(d2, t0);
611 tcg_temp_free_i64(t0);
612 tcg_temp_free_i64(t1);
615 /* 64-bit unsigned muls, lower result in d and upper in d2. */
616 static void t_gen_mulu(TCGv d, TCGv d2, TCGv a, TCGv b)
618 TCGv_i64 t0, t1;
620 t0 = tcg_temp_new_i64();
621 t1 = tcg_temp_new_i64();
623 tcg_gen_extu_i32_i64(t0, a);
624 tcg_gen_extu_i32_i64(t1, b);
625 tcg_gen_mul_i64(t0, t0, t1);
627 tcg_gen_trunc_i64_i32(d, t0);
628 tcg_gen_shri_i64(t0, t0, 32);
629 tcg_gen_trunc_i64_i32(d2, t0);
631 tcg_temp_free_i64(t0);
632 tcg_temp_free_i64(t1);
635 /* Multiplier unit. */
636 static void dec_mul(DisasContext *dc)
638 TCGv d[2];
639 unsigned int subcode;
641 if ((dc->tb_flags & MSR_EE_FLAG)
642 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
643 && !(dc->env->pvr.regs[0] & PVR0_USE_HW_MUL_MASK)) {
644 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
645 t_gen_raise_exception(dc, EXCP_HW_EXCP);
646 return;
649 subcode = dc->imm & 3;
650 d[0] = tcg_temp_new();
651 d[1] = tcg_temp_new();
653 if (dc->type_b) {
654 LOG_DIS("muli r%d r%d %x\n", dc->rd, dc->ra, dc->imm);
655 t_gen_mulu(cpu_R[dc->rd], d[1], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
656 goto done;
659 /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */
660 if (subcode >= 1 && subcode <= 3
661 && !((dc->env->pvr.regs[2] & PVR2_USE_MUL64_MASK))) {
662 /* nop??? */
665 switch (subcode) {
666 case 0:
667 LOG_DIS("mul r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
668 t_gen_mulu(cpu_R[dc->rd], d[1], cpu_R[dc->ra], cpu_R[dc->rb]);
669 break;
670 case 1:
671 LOG_DIS("mulh r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
672 t_gen_muls(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
673 break;
674 case 2:
675 LOG_DIS("mulhsu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
676 t_gen_muls(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
677 break;
678 case 3:
679 LOG_DIS("mulhu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
680 t_gen_mulu(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
681 break;
682 default:
683 cpu_abort(dc->env, "unknown MUL insn %x\n", subcode);
684 break;
686 done:
687 tcg_temp_free(d[0]);
688 tcg_temp_free(d[1]);
691 /* Div unit. */
692 static void dec_div(DisasContext *dc)
694 unsigned int u;
696 u = dc->imm & 2;
697 LOG_DIS("div\n");
699 if ((dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
700 && !((dc->env->pvr.regs[0] & PVR0_USE_DIV_MASK))) {
701 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
702 t_gen_raise_exception(dc, EXCP_HW_EXCP);
705 if (u)
706 gen_helper_divu(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
707 else
708 gen_helper_divs(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
709 if (!dc->rd)
710 tcg_gen_movi_tl(cpu_R[dc->rd], 0);
713 static void dec_barrel(DisasContext *dc)
715 TCGv t0;
716 unsigned int s, t;
718 if ((dc->tb_flags & MSR_EE_FLAG)
719 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
720 && !(dc->env->pvr.regs[0] & PVR0_USE_BARREL_MASK)) {
721 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
722 t_gen_raise_exception(dc, EXCP_HW_EXCP);
723 return;
726 s = dc->imm & (1 << 10);
727 t = dc->imm & (1 << 9);
729 LOG_DIS("bs%s%s r%d r%d r%d\n",
730 s ? "l" : "r", t ? "a" : "l", dc->rd, dc->ra, dc->rb);
732 t0 = tcg_temp_new();
734 tcg_gen_mov_tl(t0, *(dec_alu_op_b(dc)));
735 tcg_gen_andi_tl(t0, t0, 31);
737 if (s)
738 tcg_gen_shl_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
739 else {
740 if (t)
741 tcg_gen_sar_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
742 else
743 tcg_gen_shr_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
747 static void dec_bit(DisasContext *dc)
749 TCGv t0, t1;
750 unsigned int op;
751 int mem_index = cpu_mmu_index(dc->env);
753 op = dc->ir & ((1 << 8) - 1);
754 switch (op) {
755 case 0x21:
756 /* src. */
757 t0 = tcg_temp_new();
759 LOG_DIS("src r%d r%d\n", dc->rd, dc->ra);
760 tcg_gen_andi_tl(t0, cpu_R[dc->ra], 1);
761 if (dc->rd) {
762 t1 = tcg_temp_new();
763 read_carry(dc, t1);
764 tcg_gen_shli_tl(t1, t1, 31);
766 tcg_gen_shri_tl(cpu_R[dc->rd], cpu_R[dc->ra], 1);
767 tcg_gen_or_tl(cpu_R[dc->rd], cpu_R[dc->rd], t1);
768 tcg_temp_free(t1);
771 /* Update carry. */
772 write_carry(dc, t0);
773 tcg_temp_free(t0);
774 break;
776 case 0x1:
777 case 0x41:
778 /* srl. */
779 t0 = tcg_temp_new();
780 LOG_DIS("srl r%d r%d\n", dc->rd, dc->ra);
782 /* Update carry. */
783 tcg_gen_andi_tl(t0, cpu_R[dc->ra], 1);
784 write_carry(dc, t0);
785 tcg_temp_free(t0);
786 if (dc->rd) {
787 if (op == 0x41)
788 tcg_gen_shri_tl(cpu_R[dc->rd], cpu_R[dc->ra], 1);
789 else
790 tcg_gen_sari_tl(cpu_R[dc->rd], cpu_R[dc->ra], 1);
792 break;
793 case 0x60:
794 LOG_DIS("ext8s r%d r%d\n", dc->rd, dc->ra);
795 tcg_gen_ext8s_i32(cpu_R[dc->rd], cpu_R[dc->ra]);
796 break;
797 case 0x61:
798 LOG_DIS("ext16s r%d r%d\n", dc->rd, dc->ra);
799 tcg_gen_ext16s_i32(cpu_R[dc->rd], cpu_R[dc->ra]);
800 break;
801 case 0x64:
802 case 0x66:
803 case 0x74:
804 case 0x76:
805 /* wdc. */
806 LOG_DIS("wdc r%d\n", dc->ra);
807 if ((dc->tb_flags & MSR_EE_FLAG)
808 && mem_index == MMU_USER_IDX) {
809 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
810 t_gen_raise_exception(dc, EXCP_HW_EXCP);
811 return;
813 break;
814 case 0x68:
815 /* wic. */
816 LOG_DIS("wic r%d\n", dc->ra);
817 if ((dc->tb_flags & MSR_EE_FLAG)
818 && mem_index == MMU_USER_IDX) {
819 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
820 t_gen_raise_exception(dc, EXCP_HW_EXCP);
821 return;
823 break;
824 case 0xe0:
825 if ((dc->tb_flags & MSR_EE_FLAG)
826 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
827 && !((dc->env->pvr.regs[2] & PVR2_USE_PCMP_INSTR))) {
828 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
829 t_gen_raise_exception(dc, EXCP_HW_EXCP);
831 if (dc->env->pvr.regs[2] & PVR2_USE_PCMP_INSTR) {
832 gen_helper_clz(cpu_R[dc->rd], cpu_R[dc->ra]);
834 break;
835 default:
836 cpu_abort(dc->env, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n",
837 dc->pc, op, dc->rd, dc->ra, dc->rb);
838 break;
842 static inline void sync_jmpstate(DisasContext *dc)
844 if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) {
845 if (dc->jmp == JMP_DIRECT) {
846 tcg_gen_movi_tl(env_btaken, 1);
848 dc->jmp = JMP_INDIRECT;
849 tcg_gen_movi_tl(env_btarget, dc->jmp_pc);
853 static void dec_imm(DisasContext *dc)
855 LOG_DIS("imm %x\n", dc->imm << 16);
856 tcg_gen_movi_tl(env_imm, (dc->imm << 16));
857 dc->tb_flags |= IMM_FLAG;
858 dc->clear_imm = 0;
861 static inline void gen_load(DisasContext *dc, TCGv dst, TCGv addr,
862 unsigned int size)
864 int mem_index = cpu_mmu_index(dc->env);
866 if (size == 1) {
867 tcg_gen_qemu_ld8u(dst, addr, mem_index);
868 } else if (size == 2) {
869 tcg_gen_qemu_ld16u(dst, addr, mem_index);
870 } else if (size == 4) {
871 tcg_gen_qemu_ld32u(dst, addr, mem_index);
872 } else
873 cpu_abort(dc->env, "Incorrect load size %d\n", size);
876 static inline TCGv *compute_ldst_addr(DisasContext *dc, TCGv *t)
878 unsigned int extimm = dc->tb_flags & IMM_FLAG;
879 /* Should be set to one if r1 is used by loadstores. */
880 int stackprot = 0;
882 /* All load/stores use ra. */
883 if (dc->ra == 1) {
884 stackprot = 1;
887 /* Treat the common cases first. */
888 if (!dc->type_b) {
889 /* If any of the regs is r0, return a ptr to the other. */
890 if (dc->ra == 0) {
891 return &cpu_R[dc->rb];
892 } else if (dc->rb == 0) {
893 return &cpu_R[dc->ra];
896 if (dc->rb == 1) {
897 stackprot = 1;
900 *t = tcg_temp_new();
901 tcg_gen_add_tl(*t, cpu_R[dc->ra], cpu_R[dc->rb]);
903 if (stackprot) {
904 gen_helper_stackprot(*t);
906 return t;
908 /* Immediate. */
909 if (!extimm) {
910 if (dc->imm == 0) {
911 return &cpu_R[dc->ra];
913 *t = tcg_temp_new();
914 tcg_gen_movi_tl(*t, (int32_t)((int16_t)dc->imm));
915 tcg_gen_add_tl(*t, cpu_R[dc->ra], *t);
916 } else {
917 *t = tcg_temp_new();
918 tcg_gen_add_tl(*t, cpu_R[dc->ra], *(dec_alu_op_b(dc)));
921 if (stackprot) {
922 gen_helper_stackprot(*t);
924 return t;
927 static inline void dec_byteswap(DisasContext *dc, TCGv dst, TCGv src, int size)
929 if (size == 4) {
930 tcg_gen_bswap32_tl(dst, src);
931 } else if (size == 2) {
932 TCGv t = tcg_temp_new();
934 /* bswap16 assumes the high bits are zero. */
935 tcg_gen_andi_tl(t, src, 0xffff);
936 tcg_gen_bswap16_tl(dst, t);
937 tcg_temp_free(t);
938 } else {
939 /* Ignore.
940 cpu_abort(dc->env, "Invalid ldst byteswap size %d\n", size);
945 static void dec_load(DisasContext *dc)
947 TCGv t, *addr;
948 unsigned int size, rev = 0;
950 size = 1 << (dc->opcode & 3);
952 if (!dc->type_b) {
953 rev = (dc->ir >> 9) & 1;
956 if (size > 4 && (dc->tb_flags & MSR_EE_FLAG)
957 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) {
958 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
959 t_gen_raise_exception(dc, EXCP_HW_EXCP);
960 return;
963 LOG_DIS("l%d%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "");
965 t_sync_flags(dc);
966 addr = compute_ldst_addr(dc, &t);
969 * When doing reverse accesses we need to do two things.
971 * 1. Reverse the address wrt endianness.
972 * 2. Byteswap the data lanes on the way back into the CPU core.
974 if (rev && size != 4) {
975 /* Endian reverse the address. t is addr. */
976 switch (size) {
977 case 1:
979 /* 00 -> 11
980 01 -> 10
981 10 -> 10
982 11 -> 00 */
983 TCGv low = tcg_temp_new();
985 /* Force addr into the temp. */
986 if (addr != &t) {
987 t = tcg_temp_new();
988 tcg_gen_mov_tl(t, *addr);
989 addr = &t;
992 tcg_gen_andi_tl(low, t, 3);
993 tcg_gen_sub_tl(low, tcg_const_tl(3), low);
994 tcg_gen_andi_tl(t, t, ~3);
995 tcg_gen_or_tl(t, t, low);
996 tcg_gen_mov_tl(env_imm, t);
997 tcg_temp_free(low);
998 break;
1001 case 2:
1002 /* 00 -> 10
1003 10 -> 00. */
1004 /* Force addr into the temp. */
1005 if (addr != &t) {
1006 t = tcg_temp_new();
1007 tcg_gen_xori_tl(t, *addr, 2);
1008 addr = &t;
1009 } else {
1010 tcg_gen_xori_tl(t, t, 2);
1012 break;
1013 default:
1014 cpu_abort(dc->env, "Invalid reverse size\n");
1015 break;
1019 /* If we get a fault on a dslot, the jmpstate better be in sync. */
1020 sync_jmpstate(dc);
1022 /* Verify alignment if needed. */
1023 if ((dc->env->pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) {
1024 TCGv v = tcg_temp_new();
1027 * Microblaze gives MMU faults priority over faults due to
1028 * unaligned addresses. That's why we speculatively do the load
1029 * into v. If the load succeeds, we verify alignment of the
1030 * address and if that succeeds we write into the destination reg.
1032 gen_load(dc, v, *addr, size);
1034 tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
1035 gen_helper_memalign(*addr, tcg_const_tl(dc->rd),
1036 tcg_const_tl(0), tcg_const_tl(size - 1));
1037 if (dc->rd) {
1038 if (rev) {
1039 dec_byteswap(dc, cpu_R[dc->rd], v, size);
1040 } else {
1041 tcg_gen_mov_tl(cpu_R[dc->rd], v);
1044 tcg_temp_free(v);
1045 } else {
1046 if (dc->rd) {
1047 gen_load(dc, cpu_R[dc->rd], *addr, size);
1048 if (rev) {
1049 dec_byteswap(dc, cpu_R[dc->rd], cpu_R[dc->rd], size);
1051 } else {
1052 /* We are loading into r0, no need to reverse. */
1053 gen_load(dc, env_imm, *addr, size);
1057 if (addr == &t)
1058 tcg_temp_free(t);
1061 static void gen_store(DisasContext *dc, TCGv addr, TCGv val,
1062 unsigned int size)
1064 int mem_index = cpu_mmu_index(dc->env);
1066 if (size == 1)
1067 tcg_gen_qemu_st8(val, addr, mem_index);
1068 else if (size == 2) {
1069 tcg_gen_qemu_st16(val, addr, mem_index);
1070 } else if (size == 4) {
1071 tcg_gen_qemu_st32(val, addr, mem_index);
1072 } else
1073 cpu_abort(dc->env, "Incorrect store size %d\n", size);
1076 static void dec_store(DisasContext *dc)
1078 TCGv t, *addr;
1079 unsigned int size, rev = 0;
1081 size = 1 << (dc->opcode & 3);
1082 if (!dc->type_b) {
1083 rev = (dc->ir >> 9) & 1;
1086 if (size > 4 && (dc->tb_flags & MSR_EE_FLAG)
1087 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) {
1088 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
1089 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1090 return;
1093 LOG_DIS("s%d%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "");
1094 t_sync_flags(dc);
1095 /* If we get a fault on a dslot, the jmpstate better be in sync. */
1096 sync_jmpstate(dc);
1097 addr = compute_ldst_addr(dc, &t);
1099 if (rev && size != 4) {
1100 /* Endian reverse the address. t is addr. */
1101 switch (size) {
1102 case 1:
1104 /* 00 -> 11
1105 01 -> 10
1106 10 -> 10
1107 11 -> 00 */
1108 TCGv low = tcg_temp_new();
1110 /* Force addr into the temp. */
1111 if (addr != &t) {
1112 t = tcg_temp_new();
1113 tcg_gen_mov_tl(t, *addr);
1114 addr = &t;
1117 tcg_gen_andi_tl(low, t, 3);
1118 tcg_gen_sub_tl(low, tcg_const_tl(3), low);
1119 tcg_gen_andi_tl(t, t, ~3);
1120 tcg_gen_or_tl(t, t, low);
1121 tcg_gen_mov_tl(env_imm, t);
1122 tcg_temp_free(low);
1123 break;
1126 case 2:
1127 /* 00 -> 10
1128 10 -> 00. */
1129 /* Force addr into the temp. */
1130 if (addr != &t) {
1131 t = tcg_temp_new();
1132 tcg_gen_xori_tl(t, *addr, 2);
1133 addr = &t;
1134 } else {
1135 tcg_gen_xori_tl(t, t, 2);
1137 break;
1138 default:
1139 cpu_abort(dc->env, "Invalid reverse size\n");
1140 break;
1143 if (size != 1) {
1144 TCGv bs_data = tcg_temp_new();
1145 dec_byteswap(dc, bs_data, cpu_R[dc->rd], size);
1146 gen_store(dc, *addr, bs_data, size);
1147 tcg_temp_free(bs_data);
1148 } else {
1149 gen_store(dc, *addr, cpu_R[dc->rd], size);
1151 } else {
1152 if (rev) {
1153 TCGv bs_data = tcg_temp_new();
1154 dec_byteswap(dc, bs_data, cpu_R[dc->rd], size);
1155 gen_store(dc, *addr, bs_data, size);
1156 tcg_temp_free(bs_data);
1157 } else {
1158 gen_store(dc, *addr, cpu_R[dc->rd], size);
1162 /* Verify alignment if needed. */
1163 if ((dc->env->pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) {
1164 tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
1165 /* FIXME: if the alignment is wrong, we should restore the value
1166 * in memory. One possible way to achieve this is to probe
1167 * the MMU prior to the memaccess, thay way we could put
1168 * the alignment checks in between the probe and the mem
1169 * access.
1171 gen_helper_memalign(*addr, tcg_const_tl(dc->rd),
1172 tcg_const_tl(1), tcg_const_tl(size - 1));
1175 if (addr == &t)
1176 tcg_temp_free(t);
1179 static inline void eval_cc(DisasContext *dc, unsigned int cc,
1180 TCGv d, TCGv a, TCGv b)
1182 switch (cc) {
1183 case CC_EQ:
1184 tcg_gen_setcond_tl(TCG_COND_EQ, d, a, b);
1185 break;
1186 case CC_NE:
1187 tcg_gen_setcond_tl(TCG_COND_NE, d, a, b);
1188 break;
1189 case CC_LT:
1190 tcg_gen_setcond_tl(TCG_COND_LT, d, a, b);
1191 break;
1192 case CC_LE:
1193 tcg_gen_setcond_tl(TCG_COND_LE, d, a, b);
1194 break;
1195 case CC_GE:
1196 tcg_gen_setcond_tl(TCG_COND_GE, d, a, b);
1197 break;
1198 case CC_GT:
1199 tcg_gen_setcond_tl(TCG_COND_GT, d, a, b);
1200 break;
1201 default:
1202 cpu_abort(dc->env, "Unknown condition code %x.\n", cc);
1203 break;
1207 static void eval_cond_jmp(DisasContext *dc, TCGv pc_true, TCGv pc_false)
1209 int l1;
1211 l1 = gen_new_label();
1212 /* Conditional jmp. */
1213 tcg_gen_mov_tl(cpu_SR[SR_PC], pc_false);
1214 tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, l1);
1215 tcg_gen_mov_tl(cpu_SR[SR_PC], pc_true);
1216 gen_set_label(l1);
1219 static void dec_bcc(DisasContext *dc)
1221 unsigned int cc;
1222 unsigned int dslot;
1224 cc = EXTRACT_FIELD(dc->ir, 21, 23);
1225 dslot = dc->ir & (1 << 25);
1226 LOG_DIS("bcc%s r%d %x\n", dslot ? "d" : "", dc->ra, dc->imm);
1228 dc->delayed_branch = 1;
1229 if (dslot) {
1230 dc->delayed_branch = 2;
1231 dc->tb_flags |= D_FLAG;
1232 tcg_gen_st_tl(tcg_const_tl(dc->type_b && (dc->tb_flags & IMM_FLAG)),
1233 cpu_env, offsetof(CPUState, bimm));
1236 if (dec_alu_op_b_is_small_imm(dc)) {
1237 int32_t offset = (int32_t)((int16_t)dc->imm); /* sign-extend. */
1239 tcg_gen_movi_tl(env_btarget, dc->pc + offset);
1240 dc->jmp = JMP_DIRECT_CC;
1241 dc->jmp_pc = dc->pc + offset;
1242 } else {
1243 dc->jmp = JMP_INDIRECT;
1244 tcg_gen_movi_tl(env_btarget, dc->pc);
1245 tcg_gen_add_tl(env_btarget, env_btarget, *(dec_alu_op_b(dc)));
1247 eval_cc(dc, cc, env_btaken, cpu_R[dc->ra], tcg_const_tl(0));
1250 static void dec_br(DisasContext *dc)
1252 unsigned int dslot, link, abs, mbar;
1253 int mem_index = cpu_mmu_index(dc->env);
1255 dslot = dc->ir & (1 << 20);
1256 abs = dc->ir & (1 << 19);
1257 link = dc->ir & (1 << 18);
1259 /* Memory barrier. */
1260 mbar = (dc->ir >> 16) & 31;
1261 if (mbar == 2 && dc->imm == 4) {
1262 LOG_DIS("mbar %d\n", dc->rd);
1263 /* Break the TB. */
1264 dc->cpustate_changed = 1;
1265 return;
1268 LOG_DIS("br%s%s%s%s imm=%x\n",
1269 abs ? "a" : "", link ? "l" : "",
1270 dc->type_b ? "i" : "", dslot ? "d" : "",
1271 dc->imm);
1273 dc->delayed_branch = 1;
1274 if (dslot) {
1275 dc->delayed_branch = 2;
1276 dc->tb_flags |= D_FLAG;
1277 tcg_gen_st_tl(tcg_const_tl(dc->type_b && (dc->tb_flags & IMM_FLAG)),
1278 cpu_env, offsetof(CPUState, bimm));
1280 if (link && dc->rd)
1281 tcg_gen_movi_tl(cpu_R[dc->rd], dc->pc);
1283 dc->jmp = JMP_INDIRECT;
1284 if (abs) {
1285 tcg_gen_movi_tl(env_btaken, 1);
1286 tcg_gen_mov_tl(env_btarget, *(dec_alu_op_b(dc)));
1287 if (link && !dslot) {
1288 if (!(dc->tb_flags & IMM_FLAG) && (dc->imm == 8 || dc->imm == 0x18))
1289 t_gen_raise_exception(dc, EXCP_BREAK);
1290 if (dc->imm == 0) {
1291 if ((dc->tb_flags & MSR_EE_FLAG) && mem_index == MMU_USER_IDX) {
1292 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
1293 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1294 return;
1297 t_gen_raise_exception(dc, EXCP_DEBUG);
1300 } else {
1301 if (dec_alu_op_b_is_small_imm(dc)) {
1302 dc->jmp = JMP_DIRECT;
1303 dc->jmp_pc = dc->pc + (int32_t)((int16_t)dc->imm);
1304 } else {
1305 tcg_gen_movi_tl(env_btaken, 1);
1306 tcg_gen_movi_tl(env_btarget, dc->pc);
1307 tcg_gen_add_tl(env_btarget, env_btarget, *(dec_alu_op_b(dc)));
1312 static inline void do_rti(DisasContext *dc)
1314 TCGv t0, t1;
1315 t0 = tcg_temp_new();
1316 t1 = tcg_temp_new();
1317 tcg_gen_shri_tl(t0, cpu_SR[SR_MSR], 1);
1318 tcg_gen_ori_tl(t1, cpu_SR[SR_MSR], MSR_IE);
1319 tcg_gen_andi_tl(t0, t0, (MSR_VM | MSR_UM));
1321 tcg_gen_andi_tl(t1, t1, ~(MSR_VM | MSR_UM));
1322 tcg_gen_or_tl(t1, t1, t0);
1323 msr_write(dc, t1);
1324 tcg_temp_free(t1);
1325 tcg_temp_free(t0);
1326 dc->tb_flags &= ~DRTI_FLAG;
1329 static inline void do_rtb(DisasContext *dc)
1331 TCGv t0, t1;
1332 t0 = tcg_temp_new();
1333 t1 = tcg_temp_new();
1334 tcg_gen_andi_tl(t1, cpu_SR[SR_MSR], ~MSR_BIP);
1335 tcg_gen_shri_tl(t0, t1, 1);
1336 tcg_gen_andi_tl(t0, t0, (MSR_VM | MSR_UM));
1338 tcg_gen_andi_tl(t1, t1, ~(MSR_VM | MSR_UM));
1339 tcg_gen_or_tl(t1, t1, t0);
1340 msr_write(dc, t1);
1341 tcg_temp_free(t1);
1342 tcg_temp_free(t0);
1343 dc->tb_flags &= ~DRTB_FLAG;
1346 static inline void do_rte(DisasContext *dc)
1348 TCGv t0, t1;
1349 t0 = tcg_temp_new();
1350 t1 = tcg_temp_new();
1352 tcg_gen_ori_tl(t1, cpu_SR[SR_MSR], MSR_EE);
1353 tcg_gen_andi_tl(t1, t1, ~MSR_EIP);
1354 tcg_gen_shri_tl(t0, t1, 1);
1355 tcg_gen_andi_tl(t0, t0, (MSR_VM | MSR_UM));
1357 tcg_gen_andi_tl(t1, t1, ~(MSR_VM | MSR_UM));
1358 tcg_gen_or_tl(t1, t1, t0);
1359 msr_write(dc, t1);
1360 tcg_temp_free(t1);
1361 tcg_temp_free(t0);
1362 dc->tb_flags &= ~DRTE_FLAG;
1365 static void dec_rts(DisasContext *dc)
1367 unsigned int b_bit, i_bit, e_bit;
1368 int mem_index = cpu_mmu_index(dc->env);
1370 i_bit = dc->ir & (1 << 21);
1371 b_bit = dc->ir & (1 << 22);
1372 e_bit = dc->ir & (1 << 23);
1374 dc->delayed_branch = 2;
1375 dc->tb_flags |= D_FLAG;
1376 tcg_gen_st_tl(tcg_const_tl(dc->type_b && (dc->tb_flags & IMM_FLAG)),
1377 cpu_env, offsetof(CPUState, bimm));
1379 if (i_bit) {
1380 LOG_DIS("rtid ir=%x\n", dc->ir);
1381 if ((dc->tb_flags & MSR_EE_FLAG)
1382 && mem_index == MMU_USER_IDX) {
1383 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
1384 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1386 dc->tb_flags |= DRTI_FLAG;
1387 } else if (b_bit) {
1388 LOG_DIS("rtbd ir=%x\n", dc->ir);
1389 if ((dc->tb_flags & MSR_EE_FLAG)
1390 && mem_index == MMU_USER_IDX) {
1391 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
1392 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1394 dc->tb_flags |= DRTB_FLAG;
1395 } else if (e_bit) {
1396 LOG_DIS("rted ir=%x\n", dc->ir);
1397 if ((dc->tb_flags & MSR_EE_FLAG)
1398 && mem_index == MMU_USER_IDX) {
1399 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
1400 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1402 dc->tb_flags |= DRTE_FLAG;
1403 } else
1404 LOG_DIS("rts ir=%x\n", dc->ir);
1406 dc->jmp = JMP_INDIRECT;
1407 tcg_gen_movi_tl(env_btaken, 1);
1408 tcg_gen_add_tl(env_btarget, cpu_R[dc->ra], *(dec_alu_op_b(dc)));
1411 static int dec_check_fpuv2(DisasContext *dc)
1413 int r;
1415 r = dc->env->pvr.regs[2] & PVR2_USE_FPU2_MASK;
1417 if (!r && (dc->tb_flags & MSR_EE_FLAG)) {
1418 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_FPU);
1419 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1421 return r;
1424 static void dec_fpu(DisasContext *dc)
1426 unsigned int fpu_insn;
1428 if ((dc->tb_flags & MSR_EE_FLAG)
1429 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
1430 && !((dc->env->pvr.regs[2] & PVR2_USE_FPU_MASK))) {
1431 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
1432 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1433 return;
1436 fpu_insn = (dc->ir >> 7) & 7;
1438 switch (fpu_insn) {
1439 case 0:
1440 gen_helper_fadd(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
1441 break;
1443 case 1:
1444 gen_helper_frsub(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
1445 break;
1447 case 2:
1448 gen_helper_fmul(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
1449 break;
1451 case 3:
1452 gen_helper_fdiv(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
1453 break;
1455 case 4:
1456 switch ((dc->ir >> 4) & 7) {
1457 case 0:
1458 gen_helper_fcmp_un(cpu_R[dc->rd],
1459 cpu_R[dc->ra], cpu_R[dc->rb]);
1460 break;
1461 case 1:
1462 gen_helper_fcmp_lt(cpu_R[dc->rd],
1463 cpu_R[dc->ra], cpu_R[dc->rb]);
1464 break;
1465 case 2:
1466 gen_helper_fcmp_eq(cpu_R[dc->rd],
1467 cpu_R[dc->ra], cpu_R[dc->rb]);
1468 break;
1469 case 3:
1470 gen_helper_fcmp_le(cpu_R[dc->rd],
1471 cpu_R[dc->ra], cpu_R[dc->rb]);
1472 break;
1473 case 4:
1474 gen_helper_fcmp_gt(cpu_R[dc->rd],
1475 cpu_R[dc->ra], cpu_R[dc->rb]);
1476 break;
1477 case 5:
1478 gen_helper_fcmp_ne(cpu_R[dc->rd],
1479 cpu_R[dc->ra], cpu_R[dc->rb]);
1480 break;
1481 case 6:
1482 gen_helper_fcmp_ge(cpu_R[dc->rd],
1483 cpu_R[dc->ra], cpu_R[dc->rb]);
1484 break;
1485 default:
1486 qemu_log ("unimplemented fcmp fpu_insn=%x pc=%x opc=%x\n",
1487 fpu_insn, dc->pc, dc->opcode);
1488 dc->abort_at_next_insn = 1;
1489 break;
1491 break;
1493 case 5:
1494 if (!dec_check_fpuv2(dc)) {
1495 return;
1497 gen_helper_flt(cpu_R[dc->rd], cpu_R[dc->ra]);
1498 break;
1500 case 6:
1501 if (!dec_check_fpuv2(dc)) {
1502 return;
1504 gen_helper_fint(cpu_R[dc->rd], cpu_R[dc->ra]);
1505 break;
1507 case 7:
1508 if (!dec_check_fpuv2(dc)) {
1509 return;
1511 gen_helper_fsqrt(cpu_R[dc->rd], cpu_R[dc->ra]);
1512 break;
1514 default:
1515 qemu_log ("unimplemented FPU insn fpu_insn=%x pc=%x opc=%x\n",
1516 fpu_insn, dc->pc, dc->opcode);
1517 dc->abort_at_next_insn = 1;
1518 break;
1522 static void dec_null(DisasContext *dc)
1524 if ((dc->tb_flags & MSR_EE_FLAG)
1525 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) {
1526 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
1527 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1528 return;
1530 qemu_log ("unknown insn pc=%x opc=%x\n", dc->pc, dc->opcode);
1531 dc->abort_at_next_insn = 1;
1534 /* Insns connected to FSL or AXI stream attached devices. */
1535 static void dec_stream(DisasContext *dc)
1537 int mem_index = cpu_mmu_index(dc->env);
1538 TCGv_i32 t_id, t_ctrl;
1539 int ctrl;
1541 LOG_DIS("%s%s imm=%x\n", dc->rd ? "get" : "put",
1542 dc->type_b ? "" : "d", dc->imm);
1544 if ((dc->tb_flags & MSR_EE_FLAG) && (mem_index == MMU_USER_IDX)) {
1545 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
1546 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1547 return;
1550 t_id = tcg_temp_new();
1551 if (dc->type_b) {
1552 tcg_gen_movi_tl(t_id, dc->imm & 0xf);
1553 ctrl = dc->imm >> 10;
1554 } else {
1555 tcg_gen_andi_tl(t_id, cpu_R[dc->rb], 0xf);
1556 ctrl = dc->imm >> 5;
1559 t_ctrl = tcg_const_tl(ctrl);
1561 if (dc->rd == 0) {
1562 gen_helper_put(t_id, t_ctrl, cpu_R[dc->ra]);
1563 } else {
1564 gen_helper_get(cpu_R[dc->rd], t_id, t_ctrl);
1566 tcg_temp_free(t_id);
1567 tcg_temp_free(t_ctrl);
1570 static struct decoder_info {
1571 struct {
1572 uint32_t bits;
1573 uint32_t mask;
1575 void (*dec)(DisasContext *dc);
1576 } decinfo[] = {
1577 {DEC_ADD, dec_add},
1578 {DEC_SUB, dec_sub},
1579 {DEC_AND, dec_and},
1580 {DEC_XOR, dec_xor},
1581 {DEC_OR, dec_or},
1582 {DEC_BIT, dec_bit},
1583 {DEC_BARREL, dec_barrel},
1584 {DEC_LD, dec_load},
1585 {DEC_ST, dec_store},
1586 {DEC_IMM, dec_imm},
1587 {DEC_BR, dec_br},
1588 {DEC_BCC, dec_bcc},
1589 {DEC_RTS, dec_rts},
1590 {DEC_FPU, dec_fpu},
1591 {DEC_MUL, dec_mul},
1592 {DEC_DIV, dec_div},
1593 {DEC_MSR, dec_msr},
1594 {DEC_STREAM, dec_stream},
1595 {{0, 0}, dec_null}
1598 static inline void decode(DisasContext *dc)
1600 uint32_t ir;
1601 int i;
1603 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
1604 tcg_gen_debug_insn_start(dc->pc);
1606 dc->ir = ir = ldl_code(dc->pc);
1607 LOG_DIS("%8.8x\t", dc->ir);
1609 if (dc->ir)
1610 dc->nr_nops = 0;
1611 else {
1612 if ((dc->tb_flags & MSR_EE_FLAG)
1613 && (dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
1614 && (dc->env->pvr.regs[2] & PVR2_OPCODE_0x0_ILL_MASK)) {
1615 tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
1616 t_gen_raise_exception(dc, EXCP_HW_EXCP);
1617 return;
1620 LOG_DIS("nr_nops=%d\t", dc->nr_nops);
1621 dc->nr_nops++;
1622 if (dc->nr_nops > 4)
1623 cpu_abort(dc->env, "fetching nop sequence\n");
1625 /* bit 2 seems to indicate insn type. */
1626 dc->type_b = ir & (1 << 29);
1628 dc->opcode = EXTRACT_FIELD(ir, 26, 31);
1629 dc->rd = EXTRACT_FIELD(ir, 21, 25);
1630 dc->ra = EXTRACT_FIELD(ir, 16, 20);
1631 dc->rb = EXTRACT_FIELD(ir, 11, 15);
1632 dc->imm = EXTRACT_FIELD(ir, 0, 15);
1634 /* Large switch for all insns. */
1635 for (i = 0; i < ARRAY_SIZE(decinfo); i++) {
1636 if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits) {
1637 decinfo[i].dec(dc);
1638 break;
1643 static void check_breakpoint(CPUState *env, DisasContext *dc)
1645 CPUBreakpoint *bp;
1647 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
1648 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
1649 if (bp->pc == dc->pc) {
1650 t_gen_raise_exception(dc, EXCP_DEBUG);
1651 dc->is_jmp = DISAS_UPDATE;
1657 /* generate intermediate code for basic block 'tb'. */
1658 static void
1659 gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
1660 int search_pc)
1662 uint16_t *gen_opc_end;
1663 uint32_t pc_start;
1664 int j, lj;
1665 struct DisasContext ctx;
1666 struct DisasContext *dc = &ctx;
1667 uint32_t next_page_start, org_flags;
1668 target_ulong npc;
1669 int num_insns;
1670 int max_insns;
1672 qemu_log_try_set_file(stderr);
1674 pc_start = tb->pc;
1675 dc->env = env;
1676 dc->tb = tb;
1677 org_flags = dc->synced_flags = dc->tb_flags = tb->flags;
1679 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
1681 dc->is_jmp = DISAS_NEXT;
1682 dc->jmp = 0;
1683 dc->delayed_branch = !!(dc->tb_flags & D_FLAG);
1684 if (dc->delayed_branch) {
1685 dc->jmp = JMP_INDIRECT;
1687 dc->pc = pc_start;
1688 dc->singlestep_enabled = env->singlestep_enabled;
1689 dc->cpustate_changed = 0;
1690 dc->abort_at_next_insn = 0;
1691 dc->nr_nops = 0;
1693 if (pc_start & 3)
1694 cpu_abort(env, "Microblaze: unaligned PC=%x\n", pc_start);
1696 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1697 #if !SIM_COMPAT
1698 qemu_log("--------------\n");
1699 log_cpu_state(env, 0);
1700 #endif
1703 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
1704 lj = -1;
1705 num_insns = 0;
1706 max_insns = tb->cflags & CF_COUNT_MASK;
1707 if (max_insns == 0)
1708 max_insns = CF_COUNT_MASK;
1710 gen_icount_start();
1713 #if SIM_COMPAT
1714 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1715 tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
1716 gen_helper_debug();
1718 #endif
1719 check_breakpoint(env, dc);
1721 if (search_pc) {
1722 j = gen_opc_ptr - gen_opc_buf;
1723 if (lj < j) {
1724 lj++;
1725 while (lj < j)
1726 gen_opc_instr_start[lj++] = 0;
1728 gen_opc_pc[lj] = dc->pc;
1729 gen_opc_instr_start[lj] = 1;
1730 gen_opc_icount[lj] = num_insns;
1733 /* Pretty disas. */
1734 LOG_DIS("%8.8x:\t", dc->pc);
1736 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
1737 gen_io_start();
1739 dc->clear_imm = 1;
1740 decode(dc);
1741 if (dc->clear_imm)
1742 dc->tb_flags &= ~IMM_FLAG;
1743 dc->pc += 4;
1744 num_insns++;
1746 if (dc->delayed_branch) {
1747 dc->delayed_branch--;
1748 if (!dc->delayed_branch) {
1749 if (dc->tb_flags & DRTI_FLAG)
1750 do_rti(dc);
1751 if (dc->tb_flags & DRTB_FLAG)
1752 do_rtb(dc);
1753 if (dc->tb_flags & DRTE_FLAG)
1754 do_rte(dc);
1755 /* Clear the delay slot flag. */
1756 dc->tb_flags &= ~D_FLAG;
1757 /* If it is a direct jump, try direct chaining. */
1758 if (dc->jmp == JMP_INDIRECT) {
1759 eval_cond_jmp(dc, env_btarget, tcg_const_tl(dc->pc));
1760 dc->is_jmp = DISAS_JUMP;
1761 } else if (dc->jmp == JMP_DIRECT) {
1762 t_sync_flags(dc);
1763 gen_goto_tb(dc, 0, dc->jmp_pc);
1764 dc->is_jmp = DISAS_TB_JUMP;
1765 } else if (dc->jmp == JMP_DIRECT_CC) {
1766 int l1;
1768 t_sync_flags(dc);
1769 l1 = gen_new_label();
1770 /* Conditional jmp. */
1771 tcg_gen_brcondi_tl(TCG_COND_NE, env_btaken, 0, l1);
1772 gen_goto_tb(dc, 1, dc->pc);
1773 gen_set_label(l1);
1774 gen_goto_tb(dc, 0, dc->jmp_pc);
1776 dc->is_jmp = DISAS_TB_JUMP;
1778 break;
1781 if (env->singlestep_enabled)
1782 break;
1783 } while (!dc->is_jmp && !dc->cpustate_changed
1784 && gen_opc_ptr < gen_opc_end
1785 && !singlestep
1786 && (dc->pc < next_page_start)
1787 && num_insns < max_insns);
1789 npc = dc->pc;
1790 if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) {
1791 if (dc->tb_flags & D_FLAG) {
1792 dc->is_jmp = DISAS_UPDATE;
1793 tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
1794 sync_jmpstate(dc);
1795 } else
1796 npc = dc->jmp_pc;
1799 if (tb->cflags & CF_LAST_IO)
1800 gen_io_end();
1801 /* Force an update if the per-tb cpu state has changed. */
1802 if (dc->is_jmp == DISAS_NEXT
1803 && (dc->cpustate_changed || org_flags != dc->tb_flags)) {
1804 dc->is_jmp = DISAS_UPDATE;
1805 tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
1807 t_sync_flags(dc);
1809 if (unlikely(env->singlestep_enabled)) {
1810 TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG);
1812 if (dc->is_jmp != DISAS_JUMP) {
1813 tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
1815 gen_helper_raise_exception(tmp);
1816 tcg_temp_free_i32(tmp);
1817 } else {
1818 switch(dc->is_jmp) {
1819 case DISAS_NEXT:
1820 gen_goto_tb(dc, 1, npc);
1821 break;
1822 default:
1823 case DISAS_JUMP:
1824 case DISAS_UPDATE:
1825 /* indicate that the hash table must be used
1826 to find the next TB */
1827 tcg_gen_exit_tb(0);
1828 break;
1829 case DISAS_TB_JUMP:
1830 /* nothing more to generate */
1831 break;
1834 gen_icount_end(tb, num_insns);
1835 *gen_opc_ptr = INDEX_op_end;
1836 if (search_pc) {
1837 j = gen_opc_ptr - gen_opc_buf;
1838 lj++;
1839 while (lj <= j)
1840 gen_opc_instr_start[lj++] = 0;
1841 } else {
1842 tb->size = dc->pc - pc_start;
1843 tb->icount = num_insns;
1846 #ifdef DEBUG_DISAS
1847 #if !SIM_COMPAT
1848 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1849 qemu_log("\n");
1850 #if DISAS_GNU
1851 log_target_disas(pc_start, dc->pc - pc_start, 0);
1852 #endif
1853 qemu_log("\nisize=%d osize=%td\n",
1854 dc->pc - pc_start, gen_opc_ptr - gen_opc_buf);
1856 #endif
1857 #endif
1858 assert(!dc->abort_at_next_insn);
1861 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
1863 gen_intermediate_code_internal(env, tb, 0);
1866 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
1868 gen_intermediate_code_internal(env, tb, 1);
1871 void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
1872 int flags)
1874 int i;
1876 if (!env || !f)
1877 return;
1879 cpu_fprintf(f, "IN: PC=%x %s\n",
1880 env->sregs[SR_PC], lookup_symbol(env->sregs[SR_PC]));
1881 cpu_fprintf(f, "rmsr=%x resr=%x rear=%x debug=%x imm=%x iflags=%x fsr=%x\n",
1882 env->sregs[SR_MSR], env->sregs[SR_ESR], env->sregs[SR_EAR],
1883 env->debug, env->imm, env->iflags, env->sregs[SR_FSR]);
1884 cpu_fprintf(f, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
1885 env->btaken, env->btarget,
1886 (env->sregs[SR_MSR] & MSR_UM) ? "user" : "kernel",
1887 (env->sregs[SR_MSR] & MSR_UMS) ? "user" : "kernel",
1888 (env->sregs[SR_MSR] & MSR_EIP),
1889 (env->sregs[SR_MSR] & MSR_IE));
1891 for (i = 0; i < 32; i++) {
1892 cpu_fprintf(f, "r%2.2d=%8.8x ", i, env->regs[i]);
1893 if ((i + 1) % 4 == 0)
1894 cpu_fprintf(f, "\n");
1896 cpu_fprintf(f, "\n\n");
1899 CPUState *cpu_mb_init (const char *cpu_model)
1901 CPUState *env;
1902 static int tcg_initialized = 0;
1903 int i;
1905 env = g_malloc0(sizeof(CPUState));
1907 cpu_exec_init(env);
1908 cpu_reset(env);
1909 qemu_init_vcpu(env);
1910 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
1912 if (tcg_initialized)
1913 return env;
1915 tcg_initialized = 1;
1917 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
1919 env_debug = tcg_global_mem_new(TCG_AREG0,
1920 offsetof(CPUState, debug),
1921 "debug0");
1922 env_iflags = tcg_global_mem_new(TCG_AREG0,
1923 offsetof(CPUState, iflags),
1924 "iflags");
1925 env_imm = tcg_global_mem_new(TCG_AREG0,
1926 offsetof(CPUState, imm),
1927 "imm");
1928 env_btarget = tcg_global_mem_new(TCG_AREG0,
1929 offsetof(CPUState, btarget),
1930 "btarget");
1931 env_btaken = tcg_global_mem_new(TCG_AREG0,
1932 offsetof(CPUState, btaken),
1933 "btaken");
1934 for (i = 0; i < ARRAY_SIZE(cpu_R); i++) {
1935 cpu_R[i] = tcg_global_mem_new(TCG_AREG0,
1936 offsetof(CPUState, regs[i]),
1937 regnames[i]);
1939 for (i = 0; i < ARRAY_SIZE(cpu_SR); i++) {
1940 cpu_SR[i] = tcg_global_mem_new(TCG_AREG0,
1941 offsetof(CPUState, sregs[i]),
1942 special_regnames[i]);
1944 #define GEN_HELPER 2
1945 #include "helper.h"
1947 return env;
1950 void cpu_reset (CPUState *env)
1952 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
1953 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
1954 log_cpu_state(env, 0);
1957 memset(env, 0, offsetof(CPUMBState, breakpoints));
1958 tlb_flush(env, 1);
1960 /* Disable stack protector. */
1961 env->shr = ~0;
1963 env->pvr.regs[0] = PVR0_PVR_FULL_MASK \
1964 | PVR0_USE_BARREL_MASK \
1965 | PVR0_USE_DIV_MASK \
1966 | PVR0_USE_HW_MUL_MASK \
1967 | PVR0_USE_EXC_MASK \
1968 | PVR0_USE_ICACHE_MASK \
1969 | PVR0_USE_DCACHE_MASK \
1970 | PVR0_USE_MMU \
1971 | (0xb << 8);
1972 env->pvr.regs[2] = PVR2_D_OPB_MASK \
1973 | PVR2_D_LMB_MASK \
1974 | PVR2_I_OPB_MASK \
1975 | PVR2_I_LMB_MASK \
1976 | PVR2_USE_MSR_INSTR \
1977 | PVR2_USE_PCMP_INSTR \
1978 | PVR2_USE_BARREL_MASK \
1979 | PVR2_USE_DIV_MASK \
1980 | PVR2_USE_HW_MUL_MASK \
1981 | PVR2_USE_MUL64_MASK \
1982 | PVR2_USE_FPU_MASK \
1983 | PVR2_USE_FPU2_MASK \
1984 | PVR2_FPU_EXC_MASK \
1985 | 0;
1986 env->pvr.regs[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
1987 env->pvr.regs[11] = PVR11_USE_MMU | (16 << 17);
1989 #if defined(CONFIG_USER_ONLY)
1990 /* start in user mode with interrupts enabled. */
1991 env->sregs[SR_MSR] = MSR_EE | MSR_IE | MSR_VM | MSR_UM;
1992 env->pvr.regs[10] = 0x0c000000; /* Spartan 3a dsp. */
1993 #else
1994 env->sregs[SR_MSR] = 0;
1995 mmu_init(&env->mmu);
1996 env->mmu.c_mmu = 3;
1997 env->mmu.c_mmu_tlb_access = 3;
1998 env->mmu.c_mmu_zones = 16;
1999 #endif
2002 void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
2004 env->sregs[SR_PC] = gen_opc_pc[pc_pos];