10 SH2 *sh2; // active sh2
12 int sh2_init(SH2 *sh2, int is_slave)
16 memset(sh2, 0, sizeof(*sh2));
17 sh2->is_slave = is_slave;
18 pdb_register_cpu(sh2, PDBCT_SH2, is_slave ? "ssh2" : "msh2");
20 ret = sh2_drc_init(sh2);
25 void sh2_finish(SH2 *sh2)
32 void sh2_reset(SH2 *sh2)
34 sh2->pc = p32x_sh2_read32(0, sh2);
35 sh2->r[15] = p32x_sh2_read32(4, sh2);
38 sh2->pending_int_irq = 0;
41 void sh2_do_irq(SH2 *sh2, int level, int vector)
44 p32x_sh2_write32(sh2->r[15], sh2->sr, sh2); /* push SR onto stack */
46 p32x_sh2_write32(sh2->r[15], sh2->pc, sh2); /* push PC onto stack */
48 /* set I flags in SR */
49 sh2->sr = (sh2->sr & ~I) | (level << 4);
52 sh2->pc = p32x_sh2_read32(sh2->vbr + vector * 4, sh2);
54 /* 13 cycles at best */
55 sh2->cycles_done += 13;
59 void sh2_irl_irq(SH2 *sh2, int level, int nested_call)
61 sh2->pending_irl = level;
62 if (level < sh2->pending_int_irq)
63 level = sh2->pending_int_irq;
64 sh2->pending_level = level;
67 // not in memhandler, so handle this now (recompiler friendly)
68 // do this to avoid missing irqs that other SH2 might clear
69 if (level > ((sh2->sr >> 4) & 0x0f)) {
70 int vector = sh2->irq_callback(sh2, level);
71 sh2_do_irq(sh2, level, vector);
78 void sh2_internal_irq(SH2 *sh2, int level, int vector)
80 // FIXME: multiple internal irqs not handled..
81 // assuming internal irqs never clear until accepted
82 sh2->pending_int_irq = level;
83 sh2->pending_int_vector = vector;
84 if (level > sh2->pending_level)
85 sh2->pending_level = level;
90 #define SH2_REG_SIZE (offsetof(SH2, macl) + sizeof(sh2->macl))
92 void sh2_pack(const SH2 *sh2, unsigned char *buff)
96 memcpy(buff, sh2, SH2_REG_SIZE);
97 p = (void *)(buff + SH2_REG_SIZE);
99 p[0] = sh2->pending_int_irq;
100 p[1] = sh2->pending_int_vector;
101 p[2] = sh2->cycles_aim;
102 p[3] = sh2->cycles_done;
105 void sh2_unpack(SH2 *sh2, const unsigned char *buff)
109 memcpy(sh2, buff, SH2_REG_SIZE);
110 p = (void *)(buff + SH2_REG_SIZE);
112 sh2->pending_int_irq = p[0];
113 sh2->pending_int_vector = p[1];
114 sh2->cycles_aim = p[2];
115 sh2->cycles_done = p[3];