4 * Copyright (c) 2005 Samuel Tardieu
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define SH4_DEBUG_DISAS
29 //#define SH4_SINGLE_STEP
35 #include "qemu-common.h"
37 typedef struct DisasContext
{
38 struct TranslationBlock
*tb
;
47 int singlestep_enabled
;
51 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
54 BS_STOP
= 1, /* We want to stop translation for any reason */
55 BS_BRANCH
= 2, /* We reached a branch condition */
56 BS_EXCP
= 3, /* We reached an exception condition */
59 #ifdef CONFIG_USER_ONLY
61 #define GEN_OP_LD(width, reg) \
62 void gen_op_ld##width##_T0_##reg (DisasContext *ctx) { \
63 gen_op_ld##width##_T0_##reg##_raw(); \
65 #define GEN_OP_ST(width, reg) \
66 void gen_op_st##width##_##reg##_T1 (DisasContext *ctx) { \
67 gen_op_st##width##_##reg##_T1_raw(); \
72 #define GEN_OP_LD(width, reg) \
73 void gen_op_ld##width##_T0_##reg (DisasContext *ctx) { \
74 if (ctx->memidx) gen_op_ld##width##_T0_##reg##_kernel(); \
75 else gen_op_ld##width##_T0_##reg##_user();\
77 #define GEN_OP_ST(width, reg) \
78 void gen_op_st##width##_##reg##_T1 (DisasContext *ctx) { \
79 if (ctx->memidx) gen_op_st##width##_##reg##_T1_kernel(); \
80 else gen_op_st##width##_##reg##_T1_user();\
98 void cpu_dump_state(CPUState
* env
, FILE * f
,
99 int (*cpu_fprintf
) (FILE * f
, const char *fmt
, ...),
103 cpu_fprintf(f
, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n",
104 env
->pc
, env
->sr
, env
->pr
, env
->fpscr
);
105 for (i
= 0; i
< 24; i
+= 4) {
106 cpu_fprintf(f
, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
107 i
, env
->gregs
[i
], i
+ 1, env
->gregs
[i
+ 1],
108 i
+ 2, env
->gregs
[i
+ 2], i
+ 3, env
->gregs
[i
+ 3]);
110 if (env
->flags
& DELAY_SLOT
) {
111 cpu_fprintf(f
, "in delay slot (delayed_pc=0x%08x)\n",
113 } else if (env
->flags
& DELAY_SLOT_CONDITIONAL
) {
114 cpu_fprintf(f
, "in conditional delay slot (delayed_pc=0x%08x)\n",
119 void cpu_sh4_reset(CPUSH4State
* env
)
121 #if defined(CONFIG_USER_ONLY)
122 env
->sr
= SR_FD
; /* FD - kernel does lazy fpu context switch */
124 env
->sr
= 0x700000F0; /* MD, RB, BL, I3-I0 */
127 env
->pc
= 0xA0000000;
128 #if defined(CONFIG_USER_ONLY)
129 env
->fpscr
= FPSCR_PR
; /* value for userspace according to the kernel */
130 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
); /* ?! */
132 env
->fpscr
= 0x00040001; /* CPU reset value according to SH4 manual */
133 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
138 CPUSH4State
*cpu_sh4_init(const char *cpu_model
)
142 env
= qemu_mallocz(sizeof(CPUSH4State
));
151 static void gen_goto_tb(DisasContext
* ctx
, int n
, target_ulong dest
)
153 TranslationBlock
*tb
;
156 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
157 !ctx
->singlestep_enabled
) {
158 /* Use a direct jump if in same page and singlestep not enabled */
160 gen_op_movl_imm_PC(dest
);
161 tcg_gen_exit_tb((long) tb
+ n
);
163 gen_op_movl_imm_PC(dest
);
164 if (ctx
->singlestep_enabled
)
170 static void gen_jump(DisasContext
* ctx
)
172 if (ctx
->delayed_pc
== (uint32_t) - 1) {
173 /* Target is not statically known, it comes necessarily from a
174 delayed jump as immediate jump are conditinal jumps */
175 gen_op_movl_delayed_pc_PC();
176 if (ctx
->singlestep_enabled
)
180 gen_goto_tb(ctx
, 0, ctx
->delayed_pc
);
184 /* Immediate conditional jump (bt or bf) */
185 static void gen_conditional_jump(DisasContext
* ctx
,
186 target_ulong ift
, target_ulong ifnott
)
190 l1
= gen_new_label();
192 gen_goto_tb(ctx
, 0, ifnott
);
194 gen_goto_tb(ctx
, 1, ift
);
197 /* Delayed conditional jump (bt or bf) */
198 static void gen_delayed_conditional_jump(DisasContext
* ctx
)
202 l1
= gen_new_label();
204 gen_goto_tb(ctx
, 1, ctx
->pc
+ 2);
209 #define B3_0 (ctx->opcode & 0xf)
210 #define B6_4 ((ctx->opcode >> 4) & 0x7)
211 #define B7_4 ((ctx->opcode >> 4) & 0xf)
212 #define B7_0 (ctx->opcode & 0xff)
213 #define B7_0s ((int32_t) (int8_t) (ctx->opcode & 0xff))
214 #define B11_0s (ctx->opcode & 0x800 ? 0xfffff000 | (ctx->opcode & 0xfff) : \
215 (ctx->opcode & 0xfff))
216 #define B11_8 ((ctx->opcode >> 8) & 0xf)
217 #define B15_12 ((ctx->opcode >> 12) & 0xf)
219 #define REG(x) ((x) < 8 && (ctx->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB) ? \
222 #define ALTREG(x) ((x) < 8 && (ctx->sr & (SR_MD | SR_RB)) != (SR_MD | SR_RB) \
225 #define FREG(x) (ctx->fpscr & FPSCR_FR ? (x) ^ 0x10 : (x))
226 #define XHACK(x) ((((x) & 1 ) << 4) | ((x) & 0xe))
227 #define XREG(x) (ctx->fpscr & FPSCR_FR ? XHACK(x) ^ 0x10 : XHACK(x))
228 #define DREG(x) FREG(x) /* Assumes lsb of (x) is always 0 */
230 #define CHECK_NOT_DELAY_SLOT \
231 if (ctx->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) \
232 {gen_op_raise_slot_illegal_instruction (); ctx->bstate = BS_EXCP; \
235 void _decode_opc(DisasContext
* ctx
)
238 fprintf(stderr
, "Translating opcode 0x%04x\n", ctx
->opcode
);
240 switch (ctx
->opcode
) {
241 case 0x0019: /* div0u */
244 case 0x000b: /* rts */
245 CHECK_NOT_DELAY_SLOT
gen_op_rts();
246 ctx
->flags
|= DELAY_SLOT
;
247 ctx
->delayed_pc
= (uint32_t) - 1;
249 case 0x0028: /* clrmac */
252 case 0x0048: /* clrs */
255 case 0x0008: /* clrt */
258 case 0x0038: /* ldtlb */
259 assert(0); /* XXXXX */
261 case 0x002b: /* rte */
262 CHECK_NOT_DELAY_SLOT
gen_op_rte();
263 ctx
->flags
|= DELAY_SLOT
;
264 ctx
->delayed_pc
= (uint32_t) - 1;
266 case 0x0058: /* sets */
269 case 0x0018: /* sett */
272 case 0xfbfd: /* frchg */
274 ctx
->bstate
= BS_STOP
;
276 case 0xf3fd: /* fschg */
278 ctx
->bstate
= BS_STOP
;
280 case 0x0009: /* nop */
282 case 0x001b: /* sleep */
283 assert(0); /* XXXXX */
287 switch (ctx
->opcode
& 0xf000) {
288 case 0x1000: /* mov.l Rm,@(disp,Rn) */
289 gen_op_movl_rN_T0(REG(B7_4
));
290 gen_op_movl_rN_T1(REG(B11_8
));
291 gen_op_addl_imm_T1(B3_0
* 4);
292 gen_op_stl_T0_T1(ctx
);
294 case 0x5000: /* mov.l @(disp,Rm),Rn */
295 gen_op_movl_rN_T0(REG(B7_4
));
296 gen_op_addl_imm_T0(B3_0
* 4);
297 gen_op_ldl_T0_T0(ctx
);
298 gen_op_movl_T0_rN(REG(B11_8
));
300 case 0xe000: /* mov #imm,Rn */
301 gen_op_movl_imm_rN(B7_0s
, REG(B11_8
));
303 case 0x9000: /* mov.w @(disp,PC),Rn */
304 gen_op_movl_imm_T0(ctx
->pc
+ 4 + B7_0
* 2);
305 gen_op_ldw_T0_T0(ctx
);
306 gen_op_movl_T0_rN(REG(B11_8
));
308 case 0xd000: /* mov.l @(disp,PC),Rn */
309 gen_op_movl_imm_T0((ctx
->pc
+ 4 + B7_0
* 4) & ~3);
310 gen_op_ldl_T0_T0(ctx
);
311 gen_op_movl_T0_rN(REG(B11_8
));
313 case 0x7000: /* add #imm,Rn */
314 gen_op_add_imm_rN(B7_0s
, REG(B11_8
));
316 case 0xa000: /* bra disp */
318 gen_op_bra(ctx
->delayed_pc
= ctx
->pc
+ 4 + B11_0s
* 2);
319 ctx
->flags
|= DELAY_SLOT
;
321 case 0xb000: /* bsr disp */
323 gen_op_bsr(ctx
->pc
+ 4, ctx
->delayed_pc
=
324 ctx
->pc
+ 4 + B11_0s
* 2);
325 ctx
->flags
|= DELAY_SLOT
;
329 switch (ctx
->opcode
& 0xf00f) {
330 case 0x6003: /* mov Rm,Rn */
331 gen_op_movl_rN_T0(REG(B7_4
));
332 gen_op_movl_T0_rN(REG(B11_8
));
334 case 0x2000: /* mov.b Rm,@Rn */
335 gen_op_movl_rN_T0(REG(B7_4
));
336 gen_op_movl_rN_T1(REG(B11_8
));
337 gen_op_stb_T0_T1(ctx
);
339 case 0x2001: /* mov.w Rm,@Rn */
340 gen_op_movl_rN_T0(REG(B7_4
));
341 gen_op_movl_rN_T1(REG(B11_8
));
342 gen_op_stw_T0_T1(ctx
);
344 case 0x2002: /* mov.l Rm,@Rn */
345 gen_op_movl_rN_T0(REG(B7_4
));
346 gen_op_movl_rN_T1(REG(B11_8
));
347 gen_op_stl_T0_T1(ctx
);
349 case 0x6000: /* mov.b @Rm,Rn */
350 gen_op_movl_rN_T0(REG(B7_4
));
351 gen_op_ldb_T0_T0(ctx
);
352 gen_op_movl_T0_rN(REG(B11_8
));
354 case 0x6001: /* mov.w @Rm,Rn */
355 gen_op_movl_rN_T0(REG(B7_4
));
356 gen_op_ldw_T0_T0(ctx
);
357 gen_op_movl_T0_rN(REG(B11_8
));
359 case 0x6002: /* mov.l @Rm,Rn */
360 gen_op_movl_rN_T0(REG(B7_4
));
361 gen_op_ldl_T0_T0(ctx
);
362 gen_op_movl_T0_rN(REG(B11_8
));
364 case 0x2004: /* mov.b Rm,@-Rn */
365 gen_op_movl_rN_T0(REG(B7_4
));
366 gen_op_dec1_rN(REG(B11_8
));
367 gen_op_movl_rN_T1(REG(B11_8
));
368 gen_op_stb_T0_T1(ctx
);
370 case 0x2005: /* mov.w Rm,@-Rn */
371 gen_op_movl_rN_T0(REG(B7_4
));
372 gen_op_dec2_rN(REG(B11_8
));
373 gen_op_movl_rN_T1(REG(B11_8
));
374 gen_op_stw_T0_T1(ctx
);
376 case 0x2006: /* mov.l Rm,@-Rn */
377 gen_op_movl_rN_T0(REG(B7_4
));
378 gen_op_dec4_rN(REG(B11_8
));
379 gen_op_movl_rN_T1(REG(B11_8
));
380 gen_op_stl_T0_T1(ctx
);
382 case 0x6004: /* mov.b @Rm+,Rn */
383 gen_op_movl_rN_T0(REG(B7_4
));
384 gen_op_ldb_T0_T0(ctx
);
385 gen_op_movl_T0_rN(REG(B11_8
));
387 gen_op_inc1_rN(REG(B7_4
));
389 case 0x6005: /* mov.w @Rm+,Rn */
390 gen_op_movl_rN_T0(REG(B7_4
));
391 gen_op_ldw_T0_T0(ctx
);
392 gen_op_movl_T0_rN(REG(B11_8
));
394 gen_op_inc2_rN(REG(B7_4
));
396 case 0x6006: /* mov.l @Rm+,Rn */
397 gen_op_movl_rN_T0(REG(B7_4
));
398 gen_op_ldl_T0_T0(ctx
);
399 gen_op_movl_T0_rN(REG(B11_8
));
401 gen_op_inc4_rN(REG(B7_4
));
403 case 0x0004: /* mov.b Rm,@(R0,Rn) */
404 gen_op_movl_rN_T0(REG(B7_4
));
405 gen_op_movl_rN_T1(REG(B11_8
));
406 gen_op_add_rN_T1(REG(0));
407 gen_op_stb_T0_T1(ctx
);
409 case 0x0005: /* mov.w Rm,@(R0,Rn) */
410 gen_op_movl_rN_T0(REG(B7_4
));
411 gen_op_movl_rN_T1(REG(B11_8
));
412 gen_op_add_rN_T1(REG(0));
413 gen_op_stw_T0_T1(ctx
);
415 case 0x0006: /* mov.l Rm,@(R0,Rn) */
416 gen_op_movl_rN_T0(REG(B7_4
));
417 gen_op_movl_rN_T1(REG(B11_8
));
418 gen_op_add_rN_T1(REG(0));
419 gen_op_stl_T0_T1(ctx
);
421 case 0x000c: /* mov.b @(R0,Rm),Rn */
422 gen_op_movl_rN_T0(REG(B7_4
));
423 gen_op_add_rN_T0(REG(0));
424 gen_op_ldb_T0_T0(ctx
);
425 gen_op_movl_T0_rN(REG(B11_8
));
427 case 0x000d: /* mov.w @(R0,Rm),Rn */
428 gen_op_movl_rN_T0(REG(B7_4
));
429 gen_op_add_rN_T0(REG(0));
430 gen_op_ldw_T0_T0(ctx
);
431 gen_op_movl_T0_rN(REG(B11_8
));
433 case 0x000e: /* mov.l @(R0,Rm),Rn */
434 gen_op_movl_rN_T0(REG(B7_4
));
435 gen_op_add_rN_T0(REG(0));
436 gen_op_ldl_T0_T0(ctx
);
437 gen_op_movl_T0_rN(REG(B11_8
));
439 case 0x6008: /* swap.b Rm,Rn */
440 gen_op_movl_rN_T0(REG(B7_4
));
442 gen_op_movl_T0_rN(REG(B11_8
));
444 case 0x6009: /* swap.w Rm,Rn */
445 gen_op_movl_rN_T0(REG(B7_4
));
447 gen_op_movl_T0_rN(REG(B11_8
));
449 case 0x200d: /* xtrct Rm,Rn */
450 gen_op_movl_rN_T0(REG(B7_4
));
451 gen_op_movl_rN_T1(REG(B11_8
));
452 gen_op_xtrct_T0_T1();
453 gen_op_movl_T1_rN(REG(B11_8
));
455 case 0x300c: /* add Rm,Rn */
456 gen_op_movl_rN_T0(REG(B7_4
));
457 gen_op_add_T0_rN(REG(B11_8
));
459 case 0x300e: /* addc Rm,Rn */
460 gen_op_movl_rN_T0(REG(B7_4
));
461 gen_op_movl_rN_T1(REG(B11_8
));
463 gen_op_movl_T1_rN(REG(B11_8
));
465 case 0x300f: /* addv Rm,Rn */
466 gen_op_movl_rN_T0(REG(B7_4
));
467 gen_op_movl_rN_T1(REG(B11_8
));
469 gen_op_movl_T1_rN(REG(B11_8
));
471 case 0x2009: /* and Rm,Rn */
472 gen_op_movl_rN_T0(REG(B7_4
));
473 gen_op_and_T0_rN(REG(B11_8
));
475 case 0x3000: /* cmp/eq Rm,Rn */
476 gen_op_movl_rN_T0(REG(B7_4
));
477 gen_op_movl_rN_T1(REG(B11_8
));
478 gen_op_cmp_eq_T0_T1();
480 case 0x3003: /* cmp/ge Rm,Rn */
481 gen_op_movl_rN_T0(REG(B7_4
));
482 gen_op_movl_rN_T1(REG(B11_8
));
483 gen_op_cmp_ge_T0_T1();
485 case 0x3007: /* cmp/gt Rm,Rn */
486 gen_op_movl_rN_T0(REG(B7_4
));
487 gen_op_movl_rN_T1(REG(B11_8
));
488 gen_op_cmp_gt_T0_T1();
490 case 0x3006: /* cmp/hi Rm,Rn */
491 gen_op_movl_rN_T0(REG(B7_4
));
492 gen_op_movl_rN_T1(REG(B11_8
));
493 gen_op_cmp_hi_T0_T1();
495 case 0x3002: /* cmp/hs Rm,Rn */
496 gen_op_movl_rN_T0(REG(B7_4
));
497 gen_op_movl_rN_T1(REG(B11_8
));
498 gen_op_cmp_hs_T0_T1();
500 case 0x200c: /* cmp/str Rm,Rn */
501 gen_op_movl_rN_T0(REG(B7_4
));
502 gen_op_movl_rN_T1(REG(B11_8
));
503 gen_op_cmp_str_T0_T1();
505 case 0x2007: /* div0s Rm,Rn */
506 gen_op_movl_rN_T0(REG(B7_4
));
507 gen_op_movl_rN_T1(REG(B11_8
));
508 gen_op_div0s_T0_T1();
510 case 0x3004: /* div1 Rm,Rn */
511 gen_op_movl_rN_T0(REG(B7_4
));
512 gen_op_movl_rN_T1(REG(B11_8
));
514 gen_op_movl_T1_rN(REG(B11_8
));
516 case 0x300d: /* dmuls.l Rm,Rn */
517 gen_op_movl_rN_T0(REG(B7_4
));
518 gen_op_movl_rN_T1(REG(B11_8
));
519 gen_op_dmulsl_T0_T1();
521 case 0x3005: /* dmulu.l Rm,Rn */
522 gen_op_movl_rN_T0(REG(B7_4
));
523 gen_op_movl_rN_T1(REG(B11_8
));
524 gen_op_dmulul_T0_T1();
526 case 0x600e: /* exts.b Rm,Rn */
527 gen_op_movb_rN_T0(REG(B7_4
));
528 gen_op_movl_T0_rN(REG(B11_8
));
530 case 0x600f: /* exts.w Rm,Rn */
531 gen_op_movw_rN_T0(REG(B7_4
));
532 gen_op_movl_T0_rN(REG(B11_8
));
534 case 0x600c: /* extu.b Rm,Rn */
535 gen_op_movub_rN_T0(REG(B7_4
));
536 gen_op_movl_T0_rN(REG(B11_8
));
538 case 0x600d: /* extu.w Rm,Rn */
539 gen_op_movuw_rN_T0(REG(B7_4
));
540 gen_op_movl_T0_rN(REG(B11_8
));
542 case 0x000f: /* mac.l @Rm+,@Rn+ */
543 gen_op_movl_rN_T0(REG(B11_8
));
544 gen_op_ldl_T0_T0(ctx
);
546 gen_op_inc4_rN(REG(B11_8
));
547 gen_op_movl_rN_T0(REG(B7_4
));
548 gen_op_ldl_T0_T0(ctx
);
550 gen_op_inc4_rN(REG(B7_4
));
552 case 0x400f: /* mac.w @Rm+,@Rn+ */
553 gen_op_movl_rN_T0(REG(B11_8
));
554 gen_op_ldl_T0_T0(ctx
);
556 gen_op_inc2_rN(REG(B11_8
));
557 gen_op_movl_rN_T0(REG(B7_4
));
558 gen_op_ldl_T0_T0(ctx
);
560 gen_op_inc2_rN(REG(B7_4
));
562 case 0x0007: /* mul.l Rm,Rn */
563 gen_op_movl_rN_T0(REG(B7_4
));
564 gen_op_movl_rN_T1(REG(B11_8
));
567 case 0x200f: /* muls.w Rm,Rn */
568 gen_op_movw_rN_T0(REG(B7_4
));
569 gen_op_movw_rN_T1(REG(B11_8
));
570 gen_op_mulsw_T0_T1();
572 case 0x200e: /* mulu.w Rm,Rn */
573 gen_op_movuw_rN_T0(REG(B7_4
));
574 gen_op_movuw_rN_T1(REG(B11_8
));
575 gen_op_muluw_T0_T1();
577 case 0x600b: /* neg Rm,Rn */
578 gen_op_movl_rN_T0(REG(B7_4
));
580 gen_op_movl_T0_rN(REG(B11_8
));
582 case 0x600a: /* negc Rm,Rn */
583 gen_op_movl_rN_T0(REG(B7_4
));
585 gen_op_movl_T0_rN(REG(B11_8
));
587 case 0x6007: /* not Rm,Rn */
588 gen_op_movl_rN_T0(REG(B7_4
));
590 gen_op_movl_T0_rN(REG(B11_8
));
592 case 0x200b: /* or Rm,Rn */
593 gen_op_movl_rN_T0(REG(B7_4
));
594 gen_op_or_T0_rN(REG(B11_8
));
596 case 0x400c: /* shad Rm,Rn */
597 gen_op_movl_rN_T0(REG(B7_4
));
598 gen_op_movl_rN_T1(REG(B11_8
));
600 gen_op_movl_T1_rN(REG(B11_8
));
602 case 0x400d: /* shld Rm,Rn */
603 gen_op_movl_rN_T0(REG(B7_4
));
604 gen_op_movl_rN_T1(REG(B11_8
));
606 gen_op_movl_T1_rN(REG(B11_8
));
608 case 0x3008: /* sub Rm,Rn */
609 gen_op_movl_rN_T0(REG(B7_4
));
610 gen_op_sub_T0_rN(REG(B11_8
));
612 case 0x300a: /* subc Rm,Rn */
613 gen_op_movl_rN_T0(REG(B7_4
));
614 gen_op_movl_rN_T1(REG(B11_8
));
616 gen_op_movl_T1_rN(REG(B11_8
));
618 case 0x300b: /* subv Rm,Rn */
619 gen_op_movl_rN_T0(REG(B7_4
));
620 gen_op_movl_rN_T1(REG(B11_8
));
622 gen_op_movl_T1_rN(REG(B11_8
));
624 case 0x2008: /* tst Rm,Rn */
625 gen_op_movl_rN_T0(REG(B7_4
));
626 gen_op_movl_rN_T1(REG(B11_8
));
629 case 0x200a: /* xor Rm,Rn */
630 gen_op_movl_rN_T0(REG(B7_4
));
631 gen_op_xor_T0_rN(REG(B11_8
));
633 case 0xf00c: /* fmov {F,D,X}Rm,{F,D,X}Rn - FPSCR: Nothing */
634 if (ctx
->fpscr
& FPSCR_SZ
) {
635 gen_op_fmov_drN_DT0(XREG(B7_4
));
636 gen_op_fmov_DT0_drN(XREG(B11_8
));
638 gen_op_fmov_frN_FT0(FREG(B7_4
));
639 gen_op_fmov_FT0_frN(FREG(B11_8
));
642 case 0xf00a: /* fmov {F,D,X}Rm,@Rn - FPSCR: Nothing */
643 if (ctx
->fpscr
& FPSCR_SZ
) {
644 gen_op_fmov_drN_DT0(XREG(B7_4
));
645 gen_op_movl_rN_T1(REG(B11_8
));
646 gen_op_stfq_DT0_T1(ctx
);
648 gen_op_fmov_frN_FT0(FREG(B7_4
));
649 gen_op_movl_rN_T1(REG(B11_8
));
650 gen_op_stfl_FT0_T1(ctx
);
653 case 0xf008: /* fmov @Rm,{F,D,X}Rn - FPSCR: Nothing */
654 if (ctx
->fpscr
& FPSCR_SZ
) {
655 gen_op_movl_rN_T0(REG(B7_4
));
656 gen_op_ldfq_T0_DT0(ctx
);
657 gen_op_fmov_DT0_drN(XREG(B11_8
));
659 gen_op_movl_rN_T0(REG(B7_4
));
660 gen_op_ldfl_T0_FT0(ctx
);
661 gen_op_fmov_FT0_frN(FREG(B11_8
));
664 case 0xf009: /* fmov @Rm+,{F,D,X}Rn - FPSCR: Nothing */
665 if (ctx
->fpscr
& FPSCR_SZ
) {
666 gen_op_movl_rN_T0(REG(B7_4
));
667 gen_op_ldfq_T0_DT0(ctx
);
668 gen_op_fmov_DT0_drN(XREG(B11_8
));
669 gen_op_inc8_rN(REG(B7_4
));
671 gen_op_movl_rN_T0(REG(B7_4
));
672 gen_op_ldfl_T0_FT0(ctx
);
673 gen_op_fmov_FT0_frN(FREG(B11_8
));
674 gen_op_inc4_rN(REG(B7_4
));
677 case 0xf00b: /* fmov {F,D,X}Rm,@-Rn - FPSCR: Nothing */
678 if (ctx
->fpscr
& FPSCR_SZ
) {
679 gen_op_dec8_rN(REG(B11_8
));
680 gen_op_fmov_drN_DT0(XREG(B7_4
));
681 gen_op_movl_rN_T1(REG(B11_8
));
682 gen_op_stfq_DT0_T1(ctx
);
684 gen_op_dec4_rN(REG(B11_8
));
685 gen_op_fmov_frN_FT0(FREG(B7_4
));
686 gen_op_movl_rN_T1(REG(B11_8
));
687 gen_op_stfl_FT0_T1(ctx
);
690 case 0xf006: /* fmov @(R0,Rm),{F,D,X}Rm - FPSCR: Nothing */
691 if (ctx
->fpscr
& FPSCR_SZ
) {
692 gen_op_movl_rN_T0(REG(B7_4
));
693 gen_op_add_rN_T0(REG(0));
694 gen_op_ldfq_T0_DT0(ctx
);
695 gen_op_fmov_DT0_drN(XREG(B11_8
));
697 gen_op_movl_rN_T0(REG(B7_4
));
698 gen_op_add_rN_T0(REG(0));
699 gen_op_ldfl_T0_FT0(ctx
);
700 gen_op_fmov_FT0_frN(FREG(B11_8
));
703 case 0xf007: /* fmov {F,D,X}Rn,@(R0,Rn) - FPSCR: Nothing */
704 if (ctx
->fpscr
& FPSCR_SZ
) {
705 gen_op_fmov_drN_DT0(XREG(B7_4
));
706 gen_op_movl_rN_T1(REG(B11_8
));
707 gen_op_add_rN_T1(REG(0));
708 gen_op_stfq_DT0_T1(ctx
);
710 gen_op_fmov_frN_FT0(FREG(B7_4
));
711 gen_op_movl_rN_T1(REG(B11_8
));
712 gen_op_add_rN_T1(REG(0));
713 gen_op_stfl_FT0_T1(ctx
);
716 case 0xf000: /* fadd Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */
717 case 0xf001: /* fsub Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */
718 case 0xf002: /* fmul Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */
719 case 0xf003: /* fdiv Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */
720 case 0xf004: /* fcmp/eq Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */
721 case 0xf005: /* fcmp/gt Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */
722 if (ctx
->fpscr
& FPSCR_PR
) {
723 if (ctx
->opcode
& 0x0110)
724 break; /* illegal instruction */
725 gen_op_fmov_drN_DT1(DREG(B7_4
));
726 gen_op_fmov_drN_DT0(DREG(B11_8
));
729 gen_op_fmov_frN_FT1(FREG(B7_4
));
730 gen_op_fmov_frN_FT0(FREG(B11_8
));
733 switch (ctx
->opcode
& 0xf00f) {
734 case 0xf000: /* fadd Rm,Rn */
735 ctx
->fpscr
& FPSCR_PR
? gen_op_fadd_DT() : gen_op_fadd_FT();
737 case 0xf001: /* fsub Rm,Rn */
738 ctx
->fpscr
& FPSCR_PR
? gen_op_fsub_DT() : gen_op_fsub_FT();
740 case 0xf002: /* fmul Rm,Rn */
741 ctx
->fpscr
& FPSCR_PR
? gen_op_fmul_DT() : gen_op_fmul_FT();
743 case 0xf003: /* fdiv Rm,Rn */
744 ctx
->fpscr
& FPSCR_PR
? gen_op_fdiv_DT() : gen_op_fdiv_FT();
746 case 0xf004: /* fcmp/eq Rm,Rn */
747 ctx
->fpscr
& FPSCR_PR
? gen_op_fcmp_eq_DT() : gen_op_fcmp_eq_FT();
749 case 0xf005: /* fcmp/gt Rm,Rn */
750 ctx
->fpscr
& FPSCR_PR
? gen_op_fcmp_gt_DT() : gen_op_fcmp_gt_FT();
754 if (ctx
->fpscr
& FPSCR_PR
) {
755 gen_op_fmov_DT0_drN(DREG(B11_8
));
758 gen_op_fmov_FT0_frN(FREG(B11_8
));
763 switch (ctx
->opcode
& 0xff00) {
764 case 0xc900: /* and #imm,R0 */
765 gen_op_and_imm_rN(B7_0
, REG(0));
767 case 0xcd00: /* and.b #imm,@(R0,GBR) */
768 gen_op_movl_rN_T0(REG(0));
769 gen_op_addl_GBR_T0();
771 gen_op_ldub_T0_T0(ctx
);
772 gen_op_and_imm_T0(B7_0
);
773 gen_op_stb_T0_T1(ctx
);
775 case 0x8b00: /* bf label */
777 gen_conditional_jump(ctx
, ctx
->pc
+ 2,
778 ctx
->pc
+ 4 + B7_0s
* 2);
779 ctx
->bstate
= BS_BRANCH
;
781 case 0x8f00: /* bf/s label */
783 gen_op_bf_s(ctx
->delayed_pc
= ctx
->pc
+ 4 + B7_0s
* 2);
784 ctx
->flags
|= DELAY_SLOT_CONDITIONAL
;
786 case 0x8900: /* bt label */
788 gen_conditional_jump(ctx
, ctx
->pc
+ 4 + B7_0s
* 2,
790 ctx
->bstate
= BS_BRANCH
;
792 case 0x8d00: /* bt/s label */
794 gen_op_bt_s(ctx
->delayed_pc
= ctx
->pc
+ 4 + B7_0s
* 2);
795 ctx
->flags
|= DELAY_SLOT_CONDITIONAL
;
797 case 0x8800: /* cmp/eq #imm,R0 */
798 gen_op_movl_rN_T0(REG(0));
799 gen_op_cmp_eq_imm_T0(B7_0s
);
801 case 0xc400: /* mov.b @(disp,GBR),R0 */
803 gen_op_addl_imm_T0(B7_0
);
804 gen_op_ldb_T0_T0(ctx
);
805 gen_op_movl_T0_rN(REG(0));
807 case 0xc500: /* mov.w @(disp,GBR),R0 */
809 gen_op_addl_imm_T0(B7_0
* 2);
810 gen_op_ldw_T0_T0(ctx
);
811 gen_op_movl_T0_rN(REG(0));
813 case 0xc600: /* mov.l @(disp,GBR),R0 */
815 gen_op_addl_imm_T0(B7_0
* 4);
816 gen_op_ldl_T0_T0(ctx
);
817 gen_op_movl_T0_rN(REG(0));
819 case 0xc000: /* mov.b R0,@(disp,GBR) */
821 gen_op_addl_imm_T0(B7_0
);
823 gen_op_movl_rN_T0(REG(0));
824 gen_op_stb_T0_T1(ctx
);
826 case 0xc100: /* mov.w R0,@(disp,GBR) */
828 gen_op_addl_imm_T0(B7_0
* 2);
830 gen_op_movl_rN_T0(REG(0));
831 gen_op_stw_T0_T1(ctx
);
833 case 0xc200: /* mov.l R0,@(disp,GBR) */
835 gen_op_addl_imm_T0(B7_0
* 4);
837 gen_op_movl_rN_T0(REG(0));
838 gen_op_stl_T0_T1(ctx
);
840 case 0x8000: /* mov.b R0,@(disp,Rn) */
841 gen_op_movl_rN_T0(REG(0));
842 gen_op_movl_rN_T1(REG(B7_4
));
843 gen_op_addl_imm_T1(B3_0
);
844 gen_op_stb_T0_T1(ctx
);
846 case 0x8100: /* mov.w R0,@(disp,Rn) */
847 gen_op_movl_rN_T0(REG(0));
848 gen_op_movl_rN_T1(REG(B7_4
));
849 gen_op_addl_imm_T1(B3_0
* 2);
850 gen_op_stw_T0_T1(ctx
);
852 case 0x8400: /* mov.b @(disp,Rn),R0 */
853 gen_op_movl_rN_T0(REG(B7_4
));
854 gen_op_addl_imm_T0(B3_0
);
855 gen_op_ldb_T0_T0(ctx
);
856 gen_op_movl_T0_rN(REG(0));
858 case 0x8500: /* mov.w @(disp,Rn),R0 */
859 gen_op_movl_rN_T0(REG(B7_4
));
860 gen_op_addl_imm_T0(B3_0
* 2);
861 gen_op_ldw_T0_T0(ctx
);
862 gen_op_movl_T0_rN(REG(0));
864 case 0xc700: /* mova @(disp,PC),R0 */
865 gen_op_movl_imm_rN(((ctx
->pc
& 0xfffffffc) + 4 + B7_0
* 4) & ~3,
868 case 0xcb00: /* or #imm,R0 */
869 gen_op_or_imm_rN(B7_0
, REG(0));
871 case 0xcf00: /* or.b #imm,@(R0,GBR) */
872 gen_op_movl_rN_T0(REG(0));
873 gen_op_addl_GBR_T0();
875 gen_op_ldub_T0_T0(ctx
);
876 gen_op_or_imm_T0(B7_0
);
877 gen_op_stb_T0_T1(ctx
);
879 case 0xc300: /* trapa #imm */
880 CHECK_NOT_DELAY_SLOT
gen_op_movl_imm_PC(ctx
->pc
);
882 ctx
->bstate
= BS_BRANCH
;
884 case 0xc800: /* tst #imm,R0 */
885 gen_op_tst_imm_rN(B7_0
, REG(0));
887 case 0xcc00: /* tst.b #imm,@(R0,GBR) */
888 gen_op_movl_rN_T0(REG(0));
889 gen_op_addl_GBR_T0();
890 gen_op_ldub_T0_T0(ctx
);
891 gen_op_tst_imm_T0(B7_0
);
893 case 0xca00: /* xor #imm,R0 */
894 gen_op_xor_imm_rN(B7_0
, REG(0));
896 case 0xce00: /* xor.b #imm,@(R0,GBR) */
897 gen_op_movl_rN_T0(REG(0));
898 gen_op_addl_GBR_T0();
900 gen_op_ldub_T0_T0(ctx
);
901 gen_op_xor_imm_T0(B7_0
);
902 gen_op_stb_T0_T1(ctx
);
906 switch (ctx
->opcode
& 0xf08f) {
907 case 0x408e: /* ldc Rm,Rn_BANK */
908 gen_op_movl_rN_rN(REG(B11_8
), ALTREG(B6_4
));
910 case 0x4087: /* ldc.l @Rm+,Rn_BANK */
911 gen_op_movl_rN_T0(REG(B11_8
));
912 gen_op_ldl_T0_T0(ctx
);
913 gen_op_movl_T0_rN(ALTREG(B6_4
));
914 gen_op_inc4_rN(REG(B11_8
));
916 case 0x0082: /* stc Rm_BANK,Rn */
917 gen_op_movl_rN_rN(ALTREG(B6_4
), REG(B11_8
));
919 case 0x4083: /* stc.l Rm_BANK,@-Rn */
920 gen_op_dec4_rN(REG(B11_8
));
921 gen_op_movl_rN_T1(REG(B11_8
));
922 gen_op_movl_rN_T0(ALTREG(B6_4
));
923 gen_op_stl_T0_T1(ctx
);
927 switch (ctx
->opcode
& 0xf0ff) {
928 case 0x0023: /* braf Rn */
929 CHECK_NOT_DELAY_SLOT
gen_op_movl_rN_T0(REG(B11_8
));
930 gen_op_braf_T0(ctx
->pc
+ 4);
931 ctx
->flags
|= DELAY_SLOT
;
932 ctx
->delayed_pc
= (uint32_t) - 1;
934 case 0x0003: /* bsrf Rn */
935 CHECK_NOT_DELAY_SLOT
gen_op_movl_rN_T0(REG(B11_8
));
936 gen_op_bsrf_T0(ctx
->pc
+ 4);
937 ctx
->flags
|= DELAY_SLOT
;
938 ctx
->delayed_pc
= (uint32_t) - 1;
940 case 0x4015: /* cmp/pl Rn */
941 gen_op_movl_rN_T0(REG(B11_8
));
944 case 0x4011: /* cmp/pz Rn */
945 gen_op_movl_rN_T0(REG(B11_8
));
948 case 0x4010: /* dt Rn */
949 gen_op_dt_rN(REG(B11_8
));
951 case 0x402b: /* jmp @Rn */
952 CHECK_NOT_DELAY_SLOT
gen_op_movl_rN_T0(REG(B11_8
));
954 ctx
->flags
|= DELAY_SLOT
;
955 ctx
->delayed_pc
= (uint32_t) - 1;
957 case 0x400b: /* jsr @Rn */
958 CHECK_NOT_DELAY_SLOT
gen_op_movl_rN_T0(REG(B11_8
));
959 gen_op_jsr_T0(ctx
->pc
+ 4);
960 ctx
->flags
|= DELAY_SLOT
;
961 ctx
->delayed_pc
= (uint32_t) - 1;
963 #define LDST(reg,ldnum,ldpnum,ldop,stnum,stpnum,stop,extrald) \
965 gen_op_movl_rN_T0 (REG(B11_8)); \
966 gen_op_##ldop##_T0_##reg (); \
970 gen_op_movl_rN_T0 (REG(B11_8)); \
971 gen_op_ldl_T0_T0 (ctx); \
972 gen_op_inc4_rN (REG(B11_8)); \
973 gen_op_##ldop##_T0_##reg (); \
977 gen_op_##stop##_##reg##_T0 (); \
978 gen_op_movl_T0_rN (REG(B11_8)); \
981 gen_op_##stop##_##reg##_T0 (); \
982 gen_op_dec4_rN (REG(B11_8)); \
983 gen_op_movl_rN_T1 (REG(B11_8)); \
984 gen_op_stl_T0_T1 (ctx); \
986 LDST(sr
, 0x400e, 0x4007, ldc
, 0x0002, 0x4003, stc
, ctx
->bstate
=
988 LDST(gbr
, 0x401e, 0x4017, ldc
, 0x0012, 0x4013, stc
,)
989 LDST(vbr
, 0x402e, 0x4027, ldc
, 0x0022, 0x4023, stc
,)
990 LDST(ssr
, 0x403e, 0x4037, ldc
, 0x0032, 0x4033, stc
,)
991 LDST(spc
, 0x404e, 0x4047, ldc
, 0x0042, 0x4043, stc
,)
992 LDST(dbr
, 0x40fa, 0x40f6, ldc
, 0x00fa, 0x40f2, stc
,)
993 LDST(mach
, 0x400a, 0x4006, lds
, 0x000a, 0x4002, sts
,)
994 LDST(macl
, 0x401a, 0x4016, lds
, 0x001a, 0x4012, sts
,)
995 LDST(pr
, 0x402a, 0x4026, lds
, 0x002a, 0x4022, sts
,)
996 LDST(fpul
, 0x405a, 0x4056, lds
, 0x005a, 0x4052, sts
,)
997 LDST(fpscr
, 0x406a, 0x4066, lds
, 0x006a, 0x4062, sts
, ctx
->bstate
=
999 case 0x00c3: /* movca.l R0,@Rm */
1000 gen_op_movl_rN_T0(REG(0));
1001 gen_op_movl_rN_T1(REG(B11_8
));
1002 gen_op_stl_T0_T1(ctx
);
1004 case 0x0029: /* movt Rn */
1005 gen_op_movt_rN(REG(B11_8
));
1007 case 0x0093: /* ocbi @Rn */
1008 gen_op_movl_rN_T0(REG(B11_8
));
1009 gen_op_ldl_T0_T0(ctx
);
1011 case 0x00a3: /* ocbp @Rn */
1012 gen_op_movl_rN_T0(REG(B11_8
));
1013 gen_op_ldl_T0_T0(ctx
);
1015 case 0x00b3: /* ocbwb @Rn */
1016 gen_op_movl_rN_T0(REG(B11_8
));
1017 gen_op_ldl_T0_T0(ctx
);
1019 case 0x0083: /* pref @Rn */
1021 case 0x4024: /* rotcl Rn */
1022 gen_op_rotcl_Rn(REG(B11_8
));
1024 case 0x4025: /* rotcr Rn */
1025 gen_op_rotcr_Rn(REG(B11_8
));
1027 case 0x4004: /* rotl Rn */
1028 gen_op_rotl_Rn(REG(B11_8
));
1030 case 0x4005: /* rotr Rn */
1031 gen_op_rotr_Rn(REG(B11_8
));
1033 case 0x4000: /* shll Rn */
1034 case 0x4020: /* shal Rn */
1035 gen_op_shal_Rn(REG(B11_8
));
1037 case 0x4021: /* shar Rn */
1038 gen_op_shar_Rn(REG(B11_8
));
1040 case 0x4001: /* shlr Rn */
1041 gen_op_shlr_Rn(REG(B11_8
));
1043 case 0x4008: /* shll2 Rn */
1044 gen_op_shll2_Rn(REG(B11_8
));
1046 case 0x4018: /* shll8 Rn */
1047 gen_op_shll8_Rn(REG(B11_8
));
1049 case 0x4028: /* shll16 Rn */
1050 gen_op_shll16_Rn(REG(B11_8
));
1052 case 0x4009: /* shlr2 Rn */
1053 gen_op_shlr2_Rn(REG(B11_8
));
1055 case 0x4019: /* shlr8 Rn */
1056 gen_op_shlr8_Rn(REG(B11_8
));
1058 case 0x4029: /* shlr16 Rn */
1059 gen_op_shlr16_Rn(REG(B11_8
));
1061 case 0x401b: /* tas.b @Rn */
1062 gen_op_tasb_rN(REG(B11_8
));
1064 case 0xf00d: /* fsts FPUL,FRn - FPSCR: Nothing */
1065 gen_op_movl_fpul_FT0();
1066 gen_op_fmov_FT0_frN(FREG(B11_8
));
1068 case 0xf01d: /* flds FRm,FPUL - FPSCR: Nothing */
1069 gen_op_fmov_frN_FT0(FREG(B11_8
));
1070 gen_op_movl_FT0_fpul();
1072 case 0xf02d: /* float FPUL,FRn/DRn - FPSCR: R[PR,Enable.I]/W[Cause,Flag] */
1073 if (ctx
->fpscr
& FPSCR_PR
) {
1074 if (ctx
->opcode
& 0x0100)
1075 break; /* illegal instruction */
1077 gen_op_fmov_DT0_drN(DREG(B11_8
));
1081 gen_op_fmov_FT0_frN(FREG(B11_8
));
1084 case 0xf03d: /* ftrc FRm/DRm,FPUL - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */
1085 if (ctx
->fpscr
& FPSCR_PR
) {
1086 if (ctx
->opcode
& 0x0100)
1087 break; /* illegal instruction */
1088 gen_op_fmov_drN_DT0(DREG(B11_8
));
1092 gen_op_fmov_frN_FT0(FREG(B11_8
));
1096 case 0xf04d: /* fneg FRn/DRn - FPSCR: Nothing */
1097 gen_op_fneg_frN(FREG(B11_8
));
1099 case 0xf05d: /* fabs FRn/DRn */
1100 if (ctx
->fpscr
& FPSCR_PR
) {
1101 if (ctx
->opcode
& 0x0100)
1102 break; /* illegal instruction */
1103 gen_op_fmov_drN_DT0(DREG(B11_8
));
1105 gen_op_fmov_DT0_drN(DREG(B11_8
));
1107 gen_op_fmov_frN_FT0(FREG(B11_8
));
1109 gen_op_fmov_FT0_frN(FREG(B11_8
));
1112 case 0xf06d: /* fsqrt FRn */
1113 if (ctx
->fpscr
& FPSCR_PR
) {
1114 if (ctx
->opcode
& 0x0100)
1115 break; /* illegal instruction */
1116 gen_op_fmov_drN_DT0(FREG(B11_8
));
1118 gen_op_fmov_DT0_drN(FREG(B11_8
));
1120 gen_op_fmov_frN_FT0(FREG(B11_8
));
1122 gen_op_fmov_FT0_frN(FREG(B11_8
));
1125 case 0xf07d: /* fsrra FRn */
1127 case 0xf08d: /* fldi0 FRn - FPSCR: R[PR] */
1128 if (!(ctx
->fpscr
& FPSCR_PR
)) {
1129 gen_op_movl_imm_T0(0);
1130 gen_op_fmov_T0_frN(FREG(B11_8
));
1134 case 0xf09d: /* fldi1 FRn - FPSCR: R[PR] */
1135 if (!(ctx
->fpscr
& FPSCR_PR
)) {
1136 gen_op_movl_imm_T0(0x3f800000);
1137 gen_op_fmov_T0_frN(FREG(B11_8
));
1141 case 0xf0ad: /* fcnvsd FPUL,DRn */
1142 gen_op_movl_fpul_FT0();
1143 gen_op_fcnvsd_FT_DT();
1144 gen_op_fmov_DT0_drN(DREG(B11_8
));
1146 case 0xf0bd: /* fcnvds DRn,FPUL */
1147 gen_op_fmov_drN_DT0(DREG(B11_8
));
1148 gen_op_fcnvds_DT_FT();
1149 gen_op_movl_FT0_fpul();
1153 fprintf(stderr
, "unknown instruction 0x%04x at pc 0x%08x\n",
1154 ctx
->opcode
, ctx
->pc
);
1155 gen_op_raise_illegal_instruction();
1156 ctx
->bstate
= BS_EXCP
;
1159 void decode_opc(DisasContext
* ctx
)
1161 uint32_t old_flags
= ctx
->flags
;
1165 if (old_flags
& (DELAY_SLOT
| DELAY_SLOT_CONDITIONAL
)) {
1166 if (ctx
->flags
& DELAY_SLOT_CLEARME
) {
1167 gen_op_store_flags(0);
1170 ctx
->bstate
= BS_BRANCH
;
1171 if (old_flags
& DELAY_SLOT_CONDITIONAL
) {
1172 gen_delayed_conditional_jump(ctx
);
1173 } else if (old_flags
& DELAY_SLOT
) {
1181 gen_intermediate_code_internal(CPUState
* env
, TranslationBlock
* tb
,
1185 target_ulong pc_start
;
1186 static uint16_t *gen_opc_end
;
1190 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1192 ctx
.flags
= (uint32_t)tb
->flags
;
1193 ctx
.bstate
= BS_NONE
;
1195 ctx
.fpscr
= env
->fpscr
;
1196 ctx
.memidx
= (env
->sr
& SR_MD
) ? 1 : 0;
1197 /* We don't know if the delayed pc came from a dynamic or static branch,
1198 so assume it is a dynamic branch. */
1199 ctx
.delayed_pc
= -1; /* use delayed pc from env pointer */
1201 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
1204 if (loglevel
& CPU_LOG_TB_CPU
) {
1206 "------------------------------------------------\n");
1207 cpu_dump_state(env
, logfile
, fprintf
, 0);
1212 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
1213 if (env
->nb_breakpoints
> 0) {
1214 for (i
= 0; i
< env
->nb_breakpoints
; i
++) {
1215 if (ctx
.pc
== env
->breakpoints
[i
]) {
1216 /* We have hit a breakpoint - make sure PC is up-to-date */
1217 gen_op_movl_imm_PC(ctx
.pc
);
1219 ctx
.bstate
= BS_EXCP
;
1225 i
= gen_opc_ptr
- gen_opc_buf
;
1229 gen_opc_instr_start
[ii
++] = 0;
1231 gen_opc_pc
[ii
] = ctx
.pc
;
1232 gen_opc_hflags
[ii
] = ctx
.flags
;
1233 gen_opc_instr_start
[ii
] = 1;
1236 fprintf(stderr
, "Loading opcode at address 0x%08x\n", ctx
.pc
);
1239 ctx
.opcode
= lduw_code(ctx
.pc
);
1242 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
1244 if (env
->singlestep_enabled
)
1246 #ifdef SH4_SINGLE_STEP
1250 if (env
->singlestep_enabled
) {
1253 switch (ctx
.bstate
) {
1255 /* gen_op_interrupt_restart(); */
1259 gen_op_store_flags(ctx
.flags
| DELAY_SLOT_CLEARME
);
1261 gen_goto_tb(&ctx
, 0, ctx
.pc
);
1264 /* gen_op_interrupt_restart(); */
1273 *gen_opc_ptr
= INDEX_op_end
;
1275 i
= gen_opc_ptr
- gen_opc_buf
;
1278 gen_opc_instr_start
[ii
++] = 0;
1280 tb
->size
= ctx
.pc
- pc_start
;
1284 #ifdef SH4_DEBUG_DISAS
1285 if (loglevel
& CPU_LOG_TB_IN_ASM
)
1286 fprintf(logfile
, "\n");
1288 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1289 fprintf(logfile
, "IN:\n"); /* , lookup_symbol(pc_start)); */
1290 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
1291 fprintf(logfile
, "\n");
1297 int gen_intermediate_code(CPUState
* env
, struct TranslationBlock
*tb
)
1299 return gen_intermediate_code_internal(env
, tb
, 0);
1302 int gen_intermediate_code_pc(CPUState
* env
, struct TranslationBlock
*tb
)
1304 return gen_intermediate_code_internal(env
, tb
, 1);
1307 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
1308 unsigned long searched_pc
, int pc_pos
, void *puc
)
1310 env
->pc
= gen_opc_pc
[pc_pos
];
1311 env
->flags
= gen_opc_hflags
[pc_pos
];