|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NO_LEGACY_MEMORY_HANDLERS 1
|
|
|
|
|
#include "debugger.h"
|
|
|
|
|
#include "r3000.h"
|
|
|
|
|
|
|
|
|
@ -80,33 +81,31 @@
|
|
|
|
|
#define RDREG ((op >> 11) & 31)
|
|
|
|
|
#define SHIFT ((op >> 6) & 31)
|
|
|
|
|
|
|
|
|
|
#define RSVAL (r3000->r[RSREG])
|
|
|
|
|
#define RTVAL (r3000->r[RTREG])
|
|
|
|
|
#define RDVAL (r3000->r[RDREG])
|
|
|
|
|
#define RSVAL r[RSREG]
|
|
|
|
|
#define RTVAL r[RTREG]
|
|
|
|
|
#define RDVAL r[RDREG]
|
|
|
|
|
|
|
|
|
|
#define SIMMVAL ((INT16)op)
|
|
|
|
|
#define UIMMVAL ((UINT16)op)
|
|
|
|
|
#define LIMMVAL (op & 0x03ffffff)
|
|
|
|
|
|
|
|
|
|
#define ADDPC(x) r3000->nextpc = r3000->pc + ((x) << 2)
|
|
|
|
|
#define ADDPCL(x,l) { r3000->nextpc = r3000->pc + ((x) << 2); r3000->r[l] = r3000->pc + 4; }
|
|
|
|
|
#define ABSPC(x) r3000->nextpc = (r3000->pc & 0xf0000000) | ((x) << 2)
|
|
|
|
|
#define ABSPCL(x,l) { r3000->nextpc = (r3000->pc & 0xf0000000) | ((x) << 2); r3000->r[l] = r3000->pc + 4; }
|
|
|
|
|
#define SETPC(x) r3000->nextpc = (x)
|
|
|
|
|
#define SETPCL(x,l) { r3000->nextpc = (x); r3000->r[l] = r3000->pc + 4; }
|
|
|
|
|
#define ADDPC(R,x) do { (R)->nextpc = (R)->pc + ((x) << 2); } while (0)
|
|
|
|
|
#define ADDPCL(R,x,l) do { (R)->nextpc = (R)->pc + ((x) << 2); (R)->r[l] = (R)->pc + 4; } while (0)
|
|
|
|
|
#define ABSPC(R,x) do { (R)->nextpc = ((R)->pc & 0xf0000000) | ((x) << 2); } while (0)
|
|
|
|
|
#define ABSPCL(R,x,l) do { (R)->nextpc = ((R)->pc & 0xf0000000) | ((x) << 2); (R)->r[l] = (R)->pc + 4; } while (0)
|
|
|
|
|
#define SETPC(R,x) do { (R)->nextpc = (x); } while (0)
|
|
|
|
|
#define SETPCL(R,x,l) do { (R)->nextpc = (x); (R)->r[l] = (R)->pc + 4; } while (0)
|
|
|
|
|
|
|
|
|
|
#define RBYTE(x) (*r3000->cur.readbyte)(x)
|
|
|
|
|
#define RWORD(x) (*r3000->cur.readword)(x)
|
|
|
|
|
#define RLONG(x) (*r3000->cur.readlong)(x)
|
|
|
|
|
#define RBYTE(R,x) (*(R)->cur.read_byte)((R)->program, x)
|
|
|
|
|
#define RWORD(R,x) (*(R)->cur.read_word)((R)->program, x)
|
|
|
|
|
#define RLONG(R,x) (*(R)->cur.read_dword)((R)->program, x)
|
|
|
|
|
|
|
|
|
|
#define WBYTE(x,v) (*r3000->cur.writebyte)(x,v)
|
|
|
|
|
#define WWORD(x,v) (*r3000->cur.writeword)(x,v)
|
|
|
|
|
#define WLONG(x,v) (*r3000->cur.writelong)(x,v)
|
|
|
|
|
#define WBYTE(R,x,v) (*(R)->cur.write_byte)((R)->program, x, v)
|
|
|
|
|
#define WWORD(R,x,v) (*(R)->cur.write_word)((R)->program, x, v)
|
|
|
|
|
#define WLONG(R,x,v) (*(R)->cur.write_dword)((R)->program, x, v)
|
|
|
|
|
|
|
|
|
|
#define HIVAL r3000->hi
|
|
|
|
|
#define LOVAL r3000->lo
|
|
|
|
|
#define SR r3000->cpr[0][COP0_Status]
|
|
|
|
|
#define CAUSE r3000->cpr[0][COP0_Cause]
|
|
|
|
|
#define SR cpr[0][COP0_Status]
|
|
|
|
|
#define CAUSE cpr[0][COP0_Cause]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -114,17 +113,6 @@
|
|
|
|
|
STRUCTURES & TYPEDEFS
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* memory access function table */
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
UINT8 (*readbyte)(offs_t);
|
|
|
|
|
UINT16 (*readword)(offs_t);
|
|
|
|
|
UINT32 (*readlong)(offs_t);
|
|
|
|
|
void (*writebyte)(offs_t, UINT8);
|
|
|
|
|
void (*writeword)(offs_t, UINT16);
|
|
|
|
|
void (*writelong)(offs_t, UINT32);
|
|
|
|
|
} memory_accessors;
|
|
|
|
|
|
|
|
|
|
/* R3000 Registers */
|
|
|
|
|
typedef struct _r3000_state r3000_state;
|
|
|
|
|
struct _r3000_state
|
|
|
|
@ -149,6 +137,7 @@ struct _r3000_state
|
|
|
|
|
int hasfpu;
|
|
|
|
|
cpu_irq_callback irq_callback;
|
|
|
|
|
const device_config *device;
|
|
|
|
|
const address_space *program;
|
|
|
|
|
|
|
|
|
|
/* endian-dependent load/store */
|
|
|
|
|
void (*lwl)(r3000_state *r3000, UINT32 op);
|
|
|
|
@ -158,9 +147,9 @@ struct _r3000_state
|
|
|
|
|
|
|
|
|
|
/* memory accesses */
|
|
|
|
|
UINT8 bigendian;
|
|
|
|
|
memory_accessors cur;
|
|
|
|
|
const memory_accessors *memory_hand;
|
|
|
|
|
const memory_accessors *cache_hand;
|
|
|
|
|
data_accessors cur;
|
|
|
|
|
const data_accessors *memory_hand;
|
|
|
|
|
const data_accessors *cache_hand;
|
|
|
|
|
|
|
|
|
|
/* cache memory */
|
|
|
|
|
UINT32 * cache;
|
|
|
|
@ -187,49 +176,36 @@ static void lwr_le(r3000_state *r3000, UINT32 op);
|
|
|
|
|
static void swl_le(r3000_state *r3000, UINT32 op);
|
|
|
|
|
static void swr_le(r3000_state *r3000, UINT32 op);
|
|
|
|
|
|
|
|
|
|
static UINT8 readcache_be(offs_t offset);
|
|
|
|
|
static UINT16 readcache_be_word(offs_t offset);
|
|
|
|
|
static UINT32 readcache_be_dword(offs_t offset);
|
|
|
|
|
static void writecache_be(offs_t offset, UINT8 data);
|
|
|
|
|
static void writecache_be_word(offs_t offset, UINT16 data);
|
|
|
|
|
static void writecache_be_dword(offs_t offset, UINT32 data);
|
|
|
|
|
static UINT8 readcache_be(const address_space *space, offs_t offset);
|
|
|
|
|
static UINT16 readcache_be_word(const address_space *space, offs_t offset);
|
|
|
|
|
static UINT32 readcache_be_dword(const address_space *space, offs_t offset);
|
|
|
|
|
static void writecache_be(const address_space *space, offs_t offset, UINT8 data);
|
|
|
|
|
static void writecache_be_word(const address_space *space, offs_t offset, UINT16 data);
|
|
|
|
|
static void writecache_be_dword(const address_space *space, offs_t offset, UINT32 data);
|
|
|
|
|
|
|
|
|
|
static UINT8 readcache_le(const address_space *space, offs_t offset);
|
|
|
|
|
static UINT16 readcache_le_word(const address_space *space, offs_t offset);
|
|
|
|
|
static UINT32 readcache_le_dword(const address_space *space, offs_t offset);
|
|
|
|
|
static void writecache_le(const address_space *space, offs_t offset, UINT8 data);
|
|
|
|
|
static void writecache_le_word(const address_space *space, offs_t offset, UINT16 data);
|
|
|
|
|
static void writecache_le_dword(const address_space *space, offs_t offset, UINT32 data);
|
|
|
|
|
|
|
|
|
|
static UINT8 readcache_le(offs_t offset);
|
|
|
|
|
static UINT16 readcache_le_word(offs_t offset);
|
|
|
|
|
static UINT32 readcache_le_dword(offs_t offset);
|
|
|
|
|
static void writecache_le(offs_t offset, UINT8 data);
|
|
|
|
|
static void writecache_le_word(offs_t offset, UINT16 data);
|
|
|
|
|
static void writecache_le_dword(offs_t offset, UINT32 data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
PRIVATE GLOBAL VARIABLES
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void *token;
|
|
|
|
|
|
|
|
|
|
static const memory_accessors be_memory =
|
|
|
|
|
static const data_accessors be_cache =
|
|
|
|
|
{
|
|
|
|
|
program_read_byte_32be, program_read_word_32be, program_read_dword_32be,
|
|
|
|
|
program_write_byte_32be, program_write_word_32be, program_write_dword_32be
|
|
|
|
|
readcache_be, readcache_be_word, NULL, readcache_be_dword, NULL, NULL, NULL,
|
|
|
|
|
writecache_be, writecache_be_word, NULL, writecache_be_dword, NULL, NULL, NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const memory_accessors le_memory =
|
|
|
|
|
static const data_accessors le_cache =
|
|
|
|
|
{
|
|
|
|
|
program_read_byte_32le, program_read_word_32le, program_read_dword_32le,
|
|
|
|
|
program_write_byte_32le, program_write_word_32le, program_write_dword_32le
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const memory_accessors be_cache =
|
|
|
|
|
{
|
|
|
|
|
readcache_be, readcache_be_word, readcache_be_dword,
|
|
|
|
|
writecache_be, writecache_be_word, writecache_be_dword
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const memory_accessors le_cache =
|
|
|
|
|
{
|
|
|
|
|
readcache_le, readcache_le_word, readcache_le_dword,
|
|
|
|
|
writecache_le, writecache_le_word, writecache_le_dword
|
|
|
|
|
readcache_le, readcache_le_word, NULL, readcache_le_dword, NULL, NULL, NULL,
|
|
|
|
|
writecache_le, writecache_le_word, NULL, writecache_le_dword, NULL, NULL, NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -238,7 +214,7 @@ static const memory_accessors le_cache =
|
|
|
|
|
MEMORY ACCESSORS
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define ROPCODE(pc) program_decrypted_read_dword(pc)
|
|
|
|
|
#define ROPCODE(R,pc) memory_decrypted_read_dword((R)->program, pc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -252,21 +228,21 @@ INLINE void generate_exception(r3000_state *r3000, int exception)
|
|
|
|
|
r3000->cpr[0][COP0_EPC] = r3000->pc;
|
|
|
|
|
|
|
|
|
|
/* put the cause in the low 8 bits and clear the branch delay flag */
|
|
|
|
|
CAUSE = (CAUSE & ~0x800000ff) | (exception << 2);
|
|
|
|
|
r3000->CAUSE = (r3000->CAUSE & ~0x800000ff) | (exception << 2);
|
|
|
|
|
|
|
|
|
|
/* if we were in a branch delay slot, adjust */
|
|
|
|
|
if (r3000->nextpc != ~0)
|
|
|
|
|
{
|
|
|
|
|
r3000->nextpc = ~0;
|
|
|
|
|
r3000->cpr[0][COP0_EPC] -= 4;
|
|
|
|
|
CAUSE |= 0x80000000;
|
|
|
|
|
r3000->CAUSE |= 0x80000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* shift the exception bits */
|
|
|
|
|
SR = (SR & 0xffffffc0) | ((SR << 2) & 0x3c);
|
|
|
|
|
r3000->SR = (r3000->SR & 0xffffffc0) | ((r3000->SR << 2) & 0x3c);
|
|
|
|
|
|
|
|
|
|
/* based on the BEV bit, we either go to ROM or RAM */
|
|
|
|
|
r3000->pc = (SR & SR_BEV) ? 0xbfc00000 : 0x80000000;
|
|
|
|
|
r3000->pc = (r3000->SR & SR_BEV) ? 0xbfc00000 : 0x80000000;
|
|
|
|
|
|
|
|
|
|
/* most exceptions go to offset 0x180, except for TLB stuff */
|
|
|
|
|
if (exception >= EXCEPTION_TLBMOD && exception <= EXCEPTION_TLBSTORE)
|
|
|
|
@ -292,7 +268,7 @@ INLINE void invalid_instruction(r3000_state *r3000, UINT32 op)
|
|
|
|
|
|
|
|
|
|
static void check_irqs(r3000_state *r3000)
|
|
|
|
|
{
|
|
|
|
|
if ((CAUSE & SR & 0xff00) && (SR & SR_IEc))
|
|
|
|
|
if ((r3000->CAUSE & r3000->SR & 0xff00) && (r3000->SR & SR_IEc))
|
|
|
|
|
generate_exception(r3000, EXCEPTION_INTERRUPT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -300,9 +276,9 @@ static void check_irqs(r3000_state *r3000)
|
|
|
|
|
static void set_irq_line(r3000_state *r3000, int irqline, int state)
|
|
|
|
|
{
|
|
|
|
|
if (state != CLEAR_LINE)
|
|
|
|
|
CAUSE |= 0x400 << irqline;
|
|
|
|
|
r3000->CAUSE |= 0x400 << irqline;
|
|
|
|
|
else
|
|
|
|
|
CAUSE &= ~(0x400 << irqline);
|
|
|
|
|
r3000->CAUSE &= ~(0x400 << irqline);
|
|
|
|
|
check_irqs(r3000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -332,8 +308,6 @@ static CPU_INIT( r3000 )
|
|
|
|
|
const r3000_cpu_core *configdata = device->static_config;
|
|
|
|
|
r3000_state *r3000 = device->token;
|
|
|
|
|
|
|
|
|
|
token = device->token; // temporary
|
|
|
|
|
|
|
|
|
|
/* allocate memory */
|
|
|
|
|
r3000->icache = auto_malloc(configdata->icache);
|
|
|
|
|
r3000->dcache = auto_malloc(configdata->dcache);
|
|
|
|
@ -344,6 +318,7 @@ static CPU_INIT( r3000 )
|
|
|
|
|
|
|
|
|
|
r3000->irq_callback = irqcallback;
|
|
|
|
|
r3000->device = device;
|
|
|
|
|
r3000->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +328,7 @@ static void r3000_reset(r3000_state *r3000, int bigendian)
|
|
|
|
|
r3000->bigendian = bigendian;
|
|
|
|
|
if (r3000->bigendian)
|
|
|
|
|
{
|
|
|
|
|
r3000->memory_hand = &be_memory;
|
|
|
|
|
r3000->memory_hand = &r3000->program->accessors;
|
|
|
|
|
r3000->cache_hand = &be_cache;
|
|
|
|
|
r3000->lwl = lwl_be;
|
|
|
|
|
r3000->lwr = lwr_be;
|
|
|
|
@ -362,7 +337,7 @@ static void r3000_reset(r3000_state *r3000, int bigendian)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
r3000->memory_hand = &le_memory;
|
|
|
|
|
r3000->memory_hand = &r3000->program->accessors;
|
|
|
|
|
r3000->cache_hand = &le_cache;
|
|
|
|
|
r3000->lwl = lwl_le;
|
|
|
|
|
r3000->lwr = lwr_le;
|
|
|
|
@ -413,7 +388,7 @@ INLINE void set_cop0_reg(r3000_state *r3000, int idx, UINT32 val)
|
|
|
|
|
{
|
|
|
|
|
if (idx == COP0_Cause)
|
|
|
|
|
{
|
|
|
|
|
CAUSE = (CAUSE & 0xfc00) | (val & ~0xfc00);
|
|
|
|
|
r3000->CAUSE = (r3000->CAUSE & 0xfc00) | (val & ~0xfc00);
|
|
|
|
|
|
|
|
|
|
/* update interrupts -- software ints can occur this way */
|
|
|
|
|
check_irqs(r3000);
|
|
|
|
@ -461,20 +436,20 @@ INLINE void set_cop0_creg(r3000_state *r3000, int idx, UINT32 val)
|
|
|
|
|
|
|
|
|
|
INLINE void handle_cop0(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
if (!(SR & SR_COP0) && (SR & SR_KUc))
|
|
|
|
|
if (!(r3000->SR & SR_COP0) && (r3000->SR & SR_KUc))
|
|
|
|
|
generate_exception(r3000, EXCEPTION_BADCOP);
|
|
|
|
|
|
|
|
|
|
switch (RSREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) RTVAL = get_cop0_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) RTVAL = get_cop0_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop0_reg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop0_creg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) r3000->RTVAL = get_cop0_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) r3000->RTVAL = get_cop0_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop0_reg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop0_creg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x08: /* BC */
|
|
|
|
|
switch (RTREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[0]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[0]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[0]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[0]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x02: /* BCzFL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x03: /* BCzTL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: invalid_instruction(r3000, op); break;
|
|
|
|
@ -502,7 +477,7 @@ INLINE void handle_cop0(r3000_state *r3000, UINT32 op)
|
|
|
|
|
case 0x02: /* TLBWI */ break;
|
|
|
|
|
case 0x06: /* TLBWR */ break;
|
|
|
|
|
case 0x08: /* TLBP */ break;
|
|
|
|
|
case 0x10: /* RFE */ SR = (SR & 0xfffffff0) | ((SR >> 2) & 0x0f); break;
|
|
|
|
|
case 0x10: /* RFE */ r3000->SR = (r3000->SR & 0xfffffff0) | ((r3000->SR >> 2) & 0x0f); break;
|
|
|
|
|
case 0x18: /* ERET */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: invalid_instruction(r3000, op); break;
|
|
|
|
|
}
|
|
|
|
@ -539,22 +514,22 @@ INLINE void set_cop1_creg(r3000_state *r3000, int idx, UINT32 val)
|
|
|
|
|
|
|
|
|
|
INLINE void handle_cop1(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
if (!(SR & SR_COP1))
|
|
|
|
|
if (!(r3000->SR & SR_COP1))
|
|
|
|
|
generate_exception(r3000, EXCEPTION_BADCOP);
|
|
|
|
|
if (!r3000->hasfpu)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (RSREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) RTVAL = get_cop1_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) RTVAL = get_cop1_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop1_reg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop1_creg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) r3000->RTVAL = get_cop1_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) r3000->RTVAL = get_cop1_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop1_reg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop1_creg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x08: /* BC */
|
|
|
|
|
switch (RTREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[1]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[1]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[1]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[1]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x02: /* BCzFL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x03: /* BCzTL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: invalid_instruction(r3000, op); break;
|
|
|
|
@ -608,20 +583,20 @@ INLINE void set_cop2_creg(r3000_state *r3000, int idx, UINT32 val)
|
|
|
|
|
|
|
|
|
|
INLINE void handle_cop2(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
if (!(SR & SR_COP2))
|
|
|
|
|
if (!(r3000->SR & SR_COP2))
|
|
|
|
|
generate_exception(r3000, EXCEPTION_BADCOP);
|
|
|
|
|
|
|
|
|
|
switch (RSREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) RTVAL = get_cop2_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) RTVAL = get_cop2_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop2_reg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop2_creg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) r3000->RTVAL = get_cop2_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) r3000->RTVAL = get_cop2_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop2_reg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop2_creg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x08: /* BC */
|
|
|
|
|
switch (RTREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[2]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[2]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[2]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[2]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x02: /* BCzFL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x03: /* BCzTL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: invalid_instruction(r3000, op); break;
|
|
|
|
@ -675,20 +650,20 @@ INLINE void set_cop3_creg(r3000_state *r3000, int idx, UINT32 val)
|
|
|
|
|
|
|
|
|
|
INLINE void handle_cop3(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
if (!(SR & SR_COP3))
|
|
|
|
|
if (!(r3000->SR & SR_COP3))
|
|
|
|
|
generate_exception(r3000, EXCEPTION_BADCOP);
|
|
|
|
|
|
|
|
|
|
switch (RSREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) RTVAL = get_cop3_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) RTVAL = get_cop3_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop3_reg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop3_creg(r3000, RDREG, RTVAL); break;
|
|
|
|
|
case 0x00: /* MFCz */ if (RTREG) r3000->RTVAL = get_cop3_reg(r3000, RDREG); break;
|
|
|
|
|
case 0x02: /* CFCz */ if (RTREG) r3000->RTVAL = get_cop3_creg(r3000, RDREG); break;
|
|
|
|
|
case 0x04: /* MTCz */ set_cop3_reg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x06: /* CTCz */ set_cop3_creg(r3000, RDREG, r3000->RTVAL); break;
|
|
|
|
|
case 0x08: /* BC */
|
|
|
|
|
switch (RTREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[3]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[3]) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x00: /* BCzF */ if (!r3000->cf[3]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BCzF */ if (r3000->cf[3]) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x02: /* BCzFL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x03: /* BCzTL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: invalid_instruction(r3000, op); break;
|
|
|
|
@ -724,8 +699,6 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = device->token;
|
|
|
|
|
|
|
|
|
|
token = device->token;
|
|
|
|
|
|
|
|
|
|
/* count cycles and interrupt cycles */
|
|
|
|
|
r3000->icount = cycles;
|
|
|
|
|
r3000->icount -= r3000->interrupt_cycles;
|
|
|
|
@ -747,7 +720,7 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
debugger_instruction_hook(device, r3000->pc);
|
|
|
|
|
|
|
|
|
|
/* instruction fetch */
|
|
|
|
|
op = ROPCODE(r3000->pc);
|
|
|
|
|
op = ROPCODE(r3000, r3000->pc);
|
|
|
|
|
|
|
|
|
|
/* adjust for next PC */
|
|
|
|
|
if (r3000->nextpc != ~0)
|
|
|
|
@ -765,65 +738,65 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
case 0x00: /* SPECIAL */
|
|
|
|
|
switch (op & 63)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* SLL */ if (RDREG) RDVAL = RTVAL << SHIFT; break;
|
|
|
|
|
case 0x02: /* SRL */ if (RDREG) RDVAL = RTVAL >> SHIFT; break;
|
|
|
|
|
case 0x03: /* SRA */ if (RDREG) RDVAL = (INT32)RTVAL >> SHIFT; break;
|
|
|
|
|
case 0x04: /* SLLV */ if (RDREG) RDVAL = RTVAL << (RSVAL & 31); break;
|
|
|
|
|
case 0x06: /* SRLV */ if (RDREG) RDVAL = RTVAL >> (RSVAL & 31); break;
|
|
|
|
|
case 0x07: /* SRAV */ if (RDREG) RDVAL = (INT32)RTVAL >> (RSVAL & 31); break;
|
|
|
|
|
case 0x08: /* JR */ SETPC(RSVAL); break;
|
|
|
|
|
case 0x09: /* JALR */ SETPCL(RSVAL,RDREG); break;
|
|
|
|
|
case 0x00: /* SLL */ if (RDREG) r3000->RDVAL = r3000->RTVAL << SHIFT; break;
|
|
|
|
|
case 0x02: /* SRL */ if (RDREG) r3000->RDVAL = r3000->RTVAL >> SHIFT; break;
|
|
|
|
|
case 0x03: /* SRA */ if (RDREG) r3000->RDVAL = (INT32)r3000->RTVAL >> SHIFT; break;
|
|
|
|
|
case 0x04: /* SLLV */ if (RDREG) r3000->RDVAL = r3000->RTVAL << (r3000->RSVAL & 31); break;
|
|
|
|
|
case 0x06: /* SRLV */ if (RDREG) r3000->RDVAL = r3000->RTVAL >> (r3000->RSVAL & 31); break;
|
|
|
|
|
case 0x07: /* SRAV */ if (RDREG) r3000->RDVAL = (INT32)r3000->RTVAL >> (r3000->RSVAL & 31); break;
|
|
|
|
|
case 0x08: /* JR */ SETPC(r3000, r3000->RSVAL); break;
|
|
|
|
|
case 0x09: /* JALR */ SETPCL(r3000, r3000->RSVAL, RDREG); break;
|
|
|
|
|
case 0x0c: /* SYSCALL */ generate_exception(r3000, EXCEPTION_SYSCALL); break;
|
|
|
|
|
case 0x0d: /* BREAK */ generate_exception(r3000, EXCEPTION_BREAK); break;
|
|
|
|
|
case 0x0f: /* SYNC */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x10: /* MFHI */ if (RDREG) RDVAL = HIVAL; break;
|
|
|
|
|
case 0x11: /* MTHI */ HIVAL = RSVAL; break;
|
|
|
|
|
case 0x12: /* MFLO */ if (RDREG) RDVAL = LOVAL; break;
|
|
|
|
|
case 0x13: /* MTLO */ LOVAL = RSVAL; break;
|
|
|
|
|
case 0x10: /* MFHI */ if (RDREG) r3000->RDVAL = r3000->hi; break;
|
|
|
|
|
case 0x11: /* MTHI */ r3000->hi = r3000->RSVAL; break;
|
|
|
|
|
case 0x12: /* MFLO */ if (RDREG) r3000->RDVAL = r3000->lo; break;
|
|
|
|
|
case 0x13: /* MTLO */ r3000->lo = r3000->RSVAL; break;
|
|
|
|
|
case 0x18: /* MULT */
|
|
|
|
|
temp64 = (INT64)(INT32)RSVAL * (INT64)(INT32)RTVAL;
|
|
|
|
|
LOVAL = (UINT32)temp64;
|
|
|
|
|
HIVAL = (UINT32)(temp64 >> 32);
|
|
|
|
|
temp64 = (INT64)(INT32)r3000->RSVAL * (INT64)(INT32)r3000->RTVAL;
|
|
|
|
|
r3000->lo = (UINT32)temp64;
|
|
|
|
|
r3000->hi = (UINT32)(temp64 >> 32);
|
|
|
|
|
r3000->icount -= 11;
|
|
|
|
|
break;
|
|
|
|
|
case 0x19: /* MULTU */
|
|
|
|
|
temp64 = (UINT64)RSVAL * (UINT64)RTVAL;
|
|
|
|
|
LOVAL = (UINT32)temp64;
|
|
|
|
|
HIVAL = (UINT32)(temp64 >> 32);
|
|
|
|
|
temp64 = (UINT64)r3000->RSVAL * (UINT64)r3000->RTVAL;
|
|
|
|
|
r3000->lo = (UINT32)temp64;
|
|
|
|
|
r3000->hi = (UINT32)(temp64 >> 32);
|
|
|
|
|
r3000->icount -= 11;
|
|
|
|
|
break;
|
|
|
|
|
case 0x1a: /* DIV */
|
|
|
|
|
if (RTVAL)
|
|
|
|
|
if (r3000->RTVAL)
|
|
|
|
|
{
|
|
|
|
|
LOVAL = (INT32)RSVAL / (INT32)RTVAL;
|
|
|
|
|
HIVAL = (INT32)RSVAL % (INT32)RTVAL;
|
|
|
|
|
r3000->lo = (INT32)r3000->RSVAL / (INT32)r3000->RTVAL;
|
|
|
|
|
r3000->hi = (INT32)r3000->RSVAL % (INT32)r3000->RTVAL;
|
|
|
|
|
}
|
|
|
|
|
r3000->icount -= 34;
|
|
|
|
|
break;
|
|
|
|
|
case 0x1b: /* DIVU */
|
|
|
|
|
if (RTVAL)
|
|
|
|
|
if (r3000->RTVAL)
|
|
|
|
|
{
|
|
|
|
|
LOVAL = RSVAL / RTVAL;
|
|
|
|
|
HIVAL = RSVAL % RTVAL;
|
|
|
|
|
r3000->lo = r3000->RSVAL / r3000->RTVAL;
|
|
|
|
|
r3000->hi = r3000->RSVAL % r3000->RTVAL;
|
|
|
|
|
}
|
|
|
|
|
r3000->icount -= 34;
|
|
|
|
|
break;
|
|
|
|
|
case 0x20: /* ADD */
|
|
|
|
|
if (ENABLE_OVERFLOWS && RSVAL > ~RTVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else RDVAL = RSVAL + RTVAL;
|
|
|
|
|
if (ENABLE_OVERFLOWS && r3000->RSVAL > ~r3000->RTVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else r3000->RDVAL = r3000->RSVAL + r3000->RTVAL;
|
|
|
|
|
break;
|
|
|
|
|
case 0x21: /* ADDU */ if (RDREG) RDVAL = RSVAL + RTVAL; break;
|
|
|
|
|
case 0x21: /* ADDU */ if (RDREG) r3000->RDVAL = r3000->RSVAL + r3000->RTVAL; break;
|
|
|
|
|
case 0x22: /* SUB */
|
|
|
|
|
if (ENABLE_OVERFLOWS && RSVAL < RTVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else RDVAL = RSVAL - RTVAL;
|
|
|
|
|
if (ENABLE_OVERFLOWS && r3000->RSVAL < r3000->RTVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else r3000->RDVAL = r3000->RSVAL - r3000->RTVAL;
|
|
|
|
|
break;
|
|
|
|
|
case 0x23: /* SUBU */ if (RDREG) RDVAL = RSVAL - RTVAL; break;
|
|
|
|
|
case 0x24: /* AND */ if (RDREG) RDVAL = RSVAL & RTVAL; break;
|
|
|
|
|
case 0x25: /* OR */ if (RDREG) RDVAL = RSVAL | RTVAL; break;
|
|
|
|
|
case 0x26: /* XOR */ if (RDREG) RDVAL = RSVAL ^ RTVAL; break;
|
|
|
|
|
case 0x27: /* NOR */ if (RDREG) RDVAL = ~(RSVAL | RTVAL); break;
|
|
|
|
|
case 0x2a: /* SLT */ if (RDREG) RDVAL = (INT32)RSVAL < (INT32)RTVAL; break;
|
|
|
|
|
case 0x2b: /* SLTU */ if (RDREG) RDVAL = (UINT32)RSVAL < (UINT32)RTVAL; break;
|
|
|
|
|
case 0x23: /* SUBU */ if (RDREG) r3000->RDVAL = r3000->RSVAL - r3000->RTVAL; break;
|
|
|
|
|
case 0x24: /* AND */ if (RDREG) r3000->RDVAL = r3000->RSVAL & r3000->RTVAL; break;
|
|
|
|
|
case 0x25: /* OR */ if (RDREG) r3000->RDVAL = r3000->RSVAL | r3000->RTVAL; break;
|
|
|
|
|
case 0x26: /* XOR */ if (RDREG) r3000->RDVAL = r3000->RSVAL ^ r3000->RTVAL; break;
|
|
|
|
|
case 0x27: /* NOR */ if (RDREG) r3000->RDVAL = ~(r3000->RSVAL | r3000->RTVAL); break;
|
|
|
|
|
case 0x2a: /* SLT */ if (RDREG) r3000->RDVAL = (INT32)r3000->RSVAL < (INT32)r3000->RTVAL; break;
|
|
|
|
|
case 0x2b: /* SLTU */ if (RDREG) r3000->RDVAL = (UINT32)r3000->RSVAL < (UINT32)r3000->RTVAL; break;
|
|
|
|
|
case 0x30: /* TEQ */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x31: /* TGEU */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x32: /* TLT */ invalid_instruction(r3000, op); break;
|
|
|
|
@ -837,8 +810,8 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
case 0x01: /* REGIMM */
|
|
|
|
|
switch (RTREG)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: /* BLTZ */ if ((INT32)RSVAL < 0) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BGEZ */ if ((INT32)RSVAL >= 0) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x00: /* BLTZ */ if ((INT32)r3000->RSVAL < 0) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x01: /* BGEZ */ if ((INT32)r3000->RSVAL >= 0) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x02: /* BLTZL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x03: /* BGEZL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x08: /* TGEI */ invalid_instruction(r3000, op); break;
|
|
|
|
@ -847,31 +820,31 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
case 0x0b: /* TLTIU */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x0c: /* TEQI */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x0e: /* TNEI */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x10: /* BLTZAL */ if ((INT32)RSVAL < 0) ADDPCL(SIMMVAL,31); break;
|
|
|
|
|
case 0x11: /* BGEZAL */ if ((INT32)RSVAL >= 0) ADDPCL(SIMMVAL,31); break;
|
|
|
|
|
case 0x10: /* BLTZAL */ if ((INT32)r3000->RSVAL < 0) ADDPCL(r3000,SIMMVAL,31); break;
|
|
|
|
|
case 0x11: /* BGEZAL */ if ((INT32)r3000->RSVAL >= 0) ADDPCL(r3000,SIMMVAL,31); break;
|
|
|
|
|
case 0x12: /* BLTZALL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x13: /* BGEZALL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
default: /* ??? */ invalid_instruction(r3000, op); break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x02: /* J */ ABSPC(LIMMVAL); break;
|
|
|
|
|
case 0x03: /* JAL */ ABSPCL(LIMMVAL,31); break;
|
|
|
|
|
case 0x04: /* BEQ */ if (RSVAL == RTVAL) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x05: /* BNE */ if (RSVAL != RTVAL) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x06: /* BLEZ */ if ((INT32)RSVAL <= 0) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x07: /* BGTZ */ if ((INT32)RSVAL > 0) ADDPC(SIMMVAL); break;
|
|
|
|
|
case 0x02: /* J */ ABSPC(r3000, LIMMVAL); break;
|
|
|
|
|
case 0x03: /* JAL */ ABSPCL(r3000, LIMMVAL,31); break;
|
|
|
|
|
case 0x04: /* BEQ */ if (r3000->RSVAL == r3000->RTVAL) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x05: /* BNE */ if (r3000->RSVAL != r3000->RTVAL) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x06: /* BLEZ */ if ((INT32)r3000->RSVAL <= 0) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x07: /* BGTZ */ if ((INT32)r3000->RSVAL > 0) ADDPC(r3000, SIMMVAL); break;
|
|
|
|
|
case 0x08: /* ADDI */
|
|
|
|
|
if (ENABLE_OVERFLOWS && RSVAL > ~SIMMVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else if (RTREG) RTVAL = RSVAL + SIMMVAL;
|
|
|
|
|
if (ENABLE_OVERFLOWS && r3000->RSVAL > ~SIMMVAL) generate_exception(r3000, EXCEPTION_OVERFLOW);
|
|
|
|
|
else if (RTREG) r3000->RTVAL = r3000->RSVAL + SIMMVAL;
|
|
|
|
|
break;
|
|
|
|
|
case 0x09: /* ADDIU */ if (RTREG) RTVAL = RSVAL + SIMMVAL; break;
|
|
|
|
|
case 0x0a: /* SLTI */ if (RTREG) RTVAL = (INT32)RSVAL < (INT32)SIMMVAL; break;
|
|
|
|
|
case 0x0b: /* SLTIU */ if (RTREG) RTVAL = (UINT32)RSVAL < (UINT32)SIMMVAL; break;
|
|
|
|
|
case 0x0c: /* ANDI */ if (RTREG) RTVAL = RSVAL & UIMMVAL; break;
|
|
|
|
|
case 0x0d: /* ORI */ if (RTREG) RTVAL = RSVAL | UIMMVAL; break;
|
|
|
|
|
case 0x0e: /* XORI */ if (RTREG) RTVAL = RSVAL ^ UIMMVAL; break;
|
|
|
|
|
case 0x0f: /* LUI */ if (RTREG) RTVAL = UIMMVAL << 16; break;
|
|
|
|
|
case 0x09: /* ADDIU */ if (RTREG) r3000->RTVAL = r3000->RSVAL + SIMMVAL; break;
|
|
|
|
|
case 0x0a: /* SLTI */ if (RTREG) r3000->RTVAL = (INT32)r3000->RSVAL < (INT32)SIMMVAL; break;
|
|
|
|
|
case 0x0b: /* SLTIU */ if (RTREG) r3000->RTVAL = (UINT32)r3000->RSVAL < (UINT32)SIMMVAL; break;
|
|
|
|
|
case 0x0c: /* ANDI */ if (RTREG) r3000->RTVAL = r3000->RSVAL & UIMMVAL; break;
|
|
|
|
|
case 0x0d: /* ORI */ if (RTREG) r3000->RTVAL = r3000->RSVAL | UIMMVAL; break;
|
|
|
|
|
case 0x0e: /* XORI */ if (RTREG) r3000->RTVAL = r3000->RSVAL ^ UIMMVAL; break;
|
|
|
|
|
case 0x0f: /* LUI */ if (RTREG) r3000->RTVAL = UIMMVAL << 16; break;
|
|
|
|
|
case 0x10: /* COP0 */ handle_cop0(r3000, op); break;
|
|
|
|
|
case 0x11: /* COP1 */ handle_cop1(r3000, op); break;
|
|
|
|
|
case 0x12: /* COP2 */ handle_cop2(r3000, op); break;
|
|
|
|
@ -880,31 +853,31 @@ static CPU_EXECUTE( r3000 )
|
|
|
|
|
case 0x15: /* BNEL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x16: /* BLEZL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x17: /* BGTZL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x20: /* LB */ temp = RBYTE(SIMMVAL+RSVAL); if (RTREG) RTVAL = (INT8)temp; break;
|
|
|
|
|
case 0x21: /* LH */ temp = RWORD(SIMMVAL+RSVAL); if (RTREG) RTVAL = (INT16)temp; break;
|
|
|
|
|
case 0x20: /* LB */ temp = RBYTE(r3000, SIMMVAL+r3000->RSVAL); if (RTREG) r3000->RTVAL = (INT8)temp; break;
|
|
|
|
|
case 0x21: /* LH */ temp = RWORD(r3000, SIMMVAL+r3000->RSVAL); if (RTREG) r3000->RTVAL = (INT16)temp; break;
|
|
|
|
|
case 0x22: /* LWL */ (*r3000->lwl)(r3000, op); break;
|
|
|
|
|
case 0x23: /* LW */ temp = RLONG(SIMMVAL+RSVAL); if (RTREG) RTVAL = temp; break;
|
|
|
|
|
case 0x24: /* LBU */ temp = RBYTE(SIMMVAL+RSVAL); if (RTREG) RTVAL = (UINT8)temp; break;
|
|
|
|
|
case 0x25: /* LHU */ temp = RWORD(SIMMVAL+RSVAL); if (RTREG) RTVAL = (UINT16)temp; break;
|
|
|
|
|
case 0x23: /* LW */ temp = RLONG(r3000, SIMMVAL+r3000->RSVAL); if (RTREG) r3000->RTVAL = temp; break;
|
|
|
|
|
case 0x24: /* LBU */ temp = RBYTE(r3000, SIMMVAL+r3000->RSVAL); if (RTREG) r3000->RTVAL = (UINT8)temp; break;
|
|
|
|
|
case 0x25: /* LHU */ temp = RWORD(r3000, SIMMVAL+r3000->RSVAL); if (RTREG) r3000->RTVAL = (UINT16)temp; break;
|
|
|
|
|
case 0x26: /* LWR */ (*r3000->lwr)(r3000, op); break;
|
|
|
|
|
case 0x28: /* SB */ WBYTE(SIMMVAL+RSVAL, RTVAL); break;
|
|
|
|
|
case 0x29: /* SH */ WWORD(SIMMVAL+RSVAL, RTVAL); break;
|
|
|
|
|
case 0x28: /* SB */ WBYTE(r3000, SIMMVAL+r3000->RSVAL, r3000->RTVAL); break;
|
|
|
|
|
case 0x29: /* SH */ WWORD(r3000, SIMMVAL+r3000->RSVAL, r3000->RTVAL); break;
|
|
|
|
|
case 0x2a: /* SWL */ (*r3000->swl)(r3000, op); break;
|
|
|
|
|
case 0x2b: /* SW */ WLONG(SIMMVAL+RSVAL, RTVAL); break;
|
|
|
|
|
case 0x2b: /* SW */ WLONG(r3000, SIMMVAL+r3000->RSVAL, r3000->RTVAL); break;
|
|
|
|
|
case 0x2e: /* SWR */ (*r3000->swr)(r3000, op); break;
|
|
|
|
|
case 0x2f: /* CACHE */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x30: /* LL */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x31: /* LWC1 */ set_cop1_reg(r3000, RTREG, RLONG(SIMMVAL+RSVAL)); break;
|
|
|
|
|
case 0x32: /* LWC2 */ set_cop2_reg(r3000, RTREG, RLONG(SIMMVAL+RSVAL)); break;
|
|
|
|
|
case 0x33: /* LWC3 */ set_cop3_reg(r3000, RTREG, RLONG(SIMMVAL+RSVAL)); break;
|
|
|
|
|
case 0x31: /* LWC1 */ set_cop1_reg(r3000, RTREG, RLONG(r3000, SIMMVAL+r3000->RSVAL)); break;
|
|
|
|
|
case 0x32: /* LWC2 */ set_cop2_reg(r3000, RTREG, RLONG(r3000, SIMMVAL+r3000->RSVAL)); break;
|
|
|
|
|
case 0x33: /* LWC3 */ set_cop3_reg(r3000, RTREG, RLONG(r3000, SIMMVAL+r3000->RSVAL)); break;
|
|
|
|
|
case 0x34: /* LDC0 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x35: /* LDC1 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x36: /* LDC2 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x37: /* LDC3 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x38: /* SC */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x39: /* LWC1 */ WLONG(SIMMVAL+RSVAL, get_cop1_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x3a: /* LWC2 */ WLONG(SIMMVAL+RSVAL, get_cop2_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x3b: /* LWC3 */ WLONG(SIMMVAL+RSVAL, get_cop3_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x39: /* LWC1 */ WLONG(r3000, SIMMVAL+r3000->RSVAL, get_cop1_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x3a: /* LWC2 */ WLONG(r3000, SIMMVAL+r3000->RSVAL, get_cop2_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x3b: /* LWC3 */ WLONG(r3000, SIMMVAL+r3000->RSVAL, get_cop3_reg(r3000, RTREG)); break;
|
|
|
|
|
case 0x3c: /* SDC0 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x3d: /* SDC1 */ invalid_instruction(r3000, op); break;
|
|
|
|
|
case 0x3e: /* SDC2 */ invalid_instruction(r3000, op); break;
|
|
|
|
@ -949,86 +922,86 @@ static CPU_DISASSEMBLE( r3000le )
|
|
|
|
|
CACHE I/O
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
static UINT8 readcache_be(offs_t offset)
|
|
|
|
|
static UINT8 readcache_be(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? r3000->cache[BYTE4_XOR_BE(offset)] : 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UINT16 readcache_be_word(offs_t offset)
|
|
|
|
|
static UINT16 readcache_be_word(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? *(UINT16 *)&r3000->cache[WORD_XOR_BE(offset)] : 0xffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UINT32 readcache_be_dword(offs_t offset)
|
|
|
|
|
static UINT32 readcache_be_dword(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? *(UINT32 *)&r3000->cache[offset] : 0xffffffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_be(offs_t offset, UINT8 data)
|
|
|
|
|
static void writecache_be(const address_space *space, offs_t offset, UINT8 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) r3000->cache[BYTE4_XOR_BE(offset)] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_be_word(offs_t offset, UINT16 data)
|
|
|
|
|
static void writecache_be_word(const address_space *space, offs_t offset, UINT16 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) *(UINT16 *)&r3000->cache[WORD_XOR_BE(offset)] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_be_dword(offs_t offset, UINT32 data)
|
|
|
|
|
static void writecache_be_dword(const address_space *space, offs_t offset, UINT32 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) *(UINT32 *)&r3000->cache[offset] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UINT8 readcache_le(offs_t offset)
|
|
|
|
|
static UINT8 readcache_le(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? r3000->cache[BYTE4_XOR_LE(offset)] : 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UINT16 readcache_le_word(offs_t offset)
|
|
|
|
|
static UINT16 readcache_le_word(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? *(UINT16 *)&r3000->cache[WORD_XOR_LE(offset)] : 0xffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UINT32 readcache_le_dword(offs_t offset)
|
|
|
|
|
static UINT32 readcache_le_dword(const address_space *space, offs_t offset)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
return (offset * 4 < r3000->cache_size) ? *(UINT32 *)&r3000->cache[offset] : 0xffffffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_le(offs_t offset, UINT8 data)
|
|
|
|
|
static void writecache_le(const address_space *space, offs_t offset, UINT8 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) r3000->cache[BYTE4_XOR_LE(offset)] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_le_word(offs_t offset, UINT16 data)
|
|
|
|
|
static void writecache_le_word(const address_space *space, offs_t offset, UINT16 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) *(UINT16 *)&r3000->cache[WORD_XOR_LE(offset)] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writecache_le_dword(offs_t offset, UINT32 data)
|
|
|
|
|
static void writecache_le_dword(const address_space *space, offs_t offset, UINT32 data)
|
|
|
|
|
{
|
|
|
|
|
r3000_state *r3000 = token; /* fixme */
|
|
|
|
|
r3000_state *r3000 = space->cpu->token;
|
|
|
|
|
offset &= 0x1fffffff;
|
|
|
|
|
if (offset * 4 < r3000->cache_size) *(UINT32 *)&r3000->cache[offset] = data;
|
|
|
|
|
}
|
|
|
|
@ -1041,56 +1014,56 @@ static void writecache_le_dword(offs_t offset, UINT32 data)
|
|
|
|
|
|
|
|
|
|
static void lwl_be(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
if (RTREG)
|
|
|
|
|
{
|
|
|
|
|
if (!(offs & 3)) RTVAL = temp;
|
|
|
|
|
if (!(offs & 3)) r3000->RTVAL = temp;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
RTVAL = (RTVAL & (0x00ffffff >> (24 - shift))) | (temp << shift);
|
|
|
|
|
r3000->RTVAL = (r3000->RTVAL & (0x00ffffff >> (24 - shift))) | (temp << shift);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lwr_be(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
if (RTREG)
|
|
|
|
|
{
|
|
|
|
|
if ((offs & 3) == 3) RTVAL = temp;
|
|
|
|
|
if ((offs & 3) == 3) r3000->RTVAL = temp;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
RTVAL = (RTVAL & (0xffffff00 << shift)) | (temp >> (24 - shift));
|
|
|
|
|
r3000->RTVAL = (r3000->RTVAL & (0xffffff00 << shift)) | (temp >> (24 - shift));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void swl_be(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
if (!(offs & 3)) WLONG(offs, RTVAL);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
if (!(offs & 3)) WLONG(r3000, offs, r3000->RTVAL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
WLONG(offs & ~3, (temp & (0xffffff00 << (24 - shift))) | (RTVAL >> shift));
|
|
|
|
|
WLONG(r3000, offs & ~3, (temp & (0xffffff00 << (24 - shift))) | (r3000->RTVAL >> shift));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void swr_be(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
if ((offs & 3) == 3) WLONG(offs & ~3, RTVAL);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
if ((offs & 3) == 3) WLONG(r3000, offs & ~3, r3000->RTVAL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
WLONG(offs & ~3, (temp & (0x00ffffff >> shift)) | (RTVAL << (24 - shift)));
|
|
|
|
|
WLONG(r3000, offs & ~3, (temp & (0x00ffffff >> shift)) | (r3000->RTVAL << (24 - shift)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1098,55 +1071,55 @@ static void swr_be(r3000_state *r3000, UINT32 op)
|
|
|
|
|
|
|
|
|
|
static void lwl_le(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
if (RTREG)
|
|
|
|
|
{
|
|
|
|
|
if (!(offs & 3)) RTVAL = temp;
|
|
|
|
|
if (!(offs & 3)) r3000->RTVAL = temp;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
RTVAL = (RTVAL & (0xffffff00 << (24 - shift))) | (temp >> shift);
|
|
|
|
|
r3000->RTVAL = (r3000->RTVAL & (0xffffff00 << (24 - shift))) | (temp >> shift);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lwr_le(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
if (RTREG)
|
|
|
|
|
{
|
|
|
|
|
if ((offs & 3) == 3) RTVAL = temp;
|
|
|
|
|
if ((offs & 3) == 3) r3000->RTVAL = temp;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
RTVAL = (RTVAL & (0x00ffffff >> shift)) | (temp << (24 - shift));
|
|
|
|
|
r3000->RTVAL = (r3000->RTVAL & (0x00ffffff >> shift)) | (temp << (24 - shift));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void swl_le(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
if (!(offs & 3)) WLONG(offs, RTVAL);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
if (!(offs & 3)) WLONG(r3000, offs, r3000->RTVAL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
WLONG(offs & ~3, (temp & (0x00ffffff >> (24 - shift))) | (RTVAL << shift));
|
|
|
|
|
WLONG(r3000, offs & ~3, (temp & (0x00ffffff >> (24 - shift))) | (r3000->RTVAL << shift));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void swr_le(r3000_state *r3000, UINT32 op)
|
|
|
|
|
{
|
|
|
|
|
offs_t offs = SIMMVAL + RSVAL;
|
|
|
|
|
if ((offs & 3) == 3) WLONG(offs & ~3, RTVAL);
|
|
|
|
|
offs_t offs = SIMMVAL + r3000->RSVAL;
|
|
|
|
|
if ((offs & 3) == 3) WLONG(r3000, offs & ~3, r3000->RTVAL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UINT32 temp = RLONG(offs & ~3);
|
|
|
|
|
UINT32 temp = RLONG(r3000, offs & ~3);
|
|
|
|
|
int shift = 8 * (offs & 3);
|
|
|
|
|
WLONG(offs & ~3, (temp & (0xffffff00 << shift)) | (RTVAL >> (24 - shift)));
|
|
|
|
|
WLONG(r3000, offs & ~3, (temp & (0xffffff00 << shift)) | (r3000->RTVAL >> (24 - shift)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1171,7 +1144,7 @@ static CPU_SET_INFO( r3000 )
|
|
|
|
|
|
|
|
|
|
case CPUINFO_INT_PC:
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_PC: r3000->pc = info->i; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_SR: SR = info->i; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_SR: r3000->SR = info->i; break;
|
|
|
|
|
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_R0: r3000->r[0] = info->i; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_R1: r3000->r[1] = info->i; break;
|
|
|
|
@ -1253,7 +1226,7 @@ static CPU_GET_INFO( r3000 )
|
|
|
|
|
|
|
|
|
|
case CPUINFO_INT_PC: info->i = r3000->pc & 0x1fffffff; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_PC: info->i = r3000->pc; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_SR: info->i = SR; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_SR: info->i = r3000->SR; break;
|
|
|
|
|
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_R0: info->i = r3000->r[0]; break;
|
|
|
|
|
case CPUINFO_INT_REGISTER + R3000_R1: info->i = r3000->r[1]; break;
|
|
|
|
@ -1311,7 +1284,7 @@ static CPU_GET_INFO( r3000 )
|
|
|
|
|
case CPUINFO_STR_FLAGS: strcpy(info->s, " "); break;
|
|
|
|
|
|
|
|
|
|
case CPUINFO_STR_REGISTER + R3000_PC: sprintf(info->s, "PC: %08X", r3000->pc); break;
|
|
|
|
|
case CPUINFO_STR_REGISTER + R3000_SR: sprintf(info->s, "SR: %08X", r3000->cpr[0][COP0_Status]); break;
|
|
|
|
|
case CPUINFO_STR_REGISTER + R3000_SR: sprintf(info->s, "SR: %08X", r3000->SR); break;
|
|
|
|
|
|
|
|
|
|
case CPUINFO_STR_REGISTER + R3000_R0: sprintf(info->s, "R0: %08X", r3000->r[0]); break;
|
|
|
|
|
case CPUINFO_STR_REGISTER + R3000_R1: sprintf(info->s, "R1: %08X", r3000->r[1]); break;
|
|
|
|
|