2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// MIPS is really trivial :)
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
2013-04-13 19:51:38 +00:00
|
|
|
#include "math/math_util.h"
|
|
|
|
|
2013-03-21 19:52:33 +00:00
|
|
|
#include "Common/Common.h"
|
2014-01-26 19:53:29 +00:00
|
|
|
#include "Core/Config.h"
|
2013-11-02 19:53:44 +00:00
|
|
|
#include "Core/Core.h"
|
2014-01-26 19:53:29 +00:00
|
|
|
#include "Core/Host.h"
|
2014-03-15 18:22:19 +00:00
|
|
|
#include "Core/MemMap.h"
|
2013-11-02 19:53:44 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
#include "Core/MIPS/MIPSInt.h"
|
|
|
|
#include "Core/MIPS/MIPSTables.h"
|
2013-12-10 12:15:28 +00:00
|
|
|
#include "Core/MIPS/JitCommon/JitCommon.h"
|
2013-03-04 07:46:37 +00:00
|
|
|
#include "Core/Reporting.h"
|
2013-11-02 19:53:44 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
|
|
|
#include "Core/HLE/HLETables.h"
|
2013-11-30 19:57:44 +00:00
|
|
|
#include "Core/HLE/ReplaceTables.h"
|
2013-11-02 19:53:44 +00:00
|
|
|
#include "Core/System.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#define R(i) (currentMIPS->r[i])
|
|
|
|
#define F(i) (currentMIPS->f[i])
|
2013-06-11 19:36:59 +00:00
|
|
|
#define FI(i) (currentMIPS->fi[i])
|
|
|
|
#define FsI(i) (currentMIPS->fs[i])
|
2012-11-01 15:19:01 +00:00
|
|
|
#define PC (currentMIPS->pc)
|
|
|
|
|
2014-03-03 16:16:53 +00:00
|
|
|
#define _RS ((op>>21) & 0x1F)
|
|
|
|
#define _RT ((op>>16) & 0x1F)
|
|
|
|
#define _RD ((op>>11) & 0x1F)
|
|
|
|
#define _FS ((op>>11) & 0x1F)
|
|
|
|
#define _FT ((op>>16) & 0x1F)
|
|
|
|
#define _FD ((op>>6 ) & 0x1F)
|
|
|
|
#define _POS ((op>>6 ) & 0x1F)
|
|
|
|
#define _SIZE ((op>>11) & 0x1F)
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#define HI currentMIPS->hi
|
|
|
|
#define LO currentMIPS->lo
|
|
|
|
|
2012-11-23 11:42:35 +00:00
|
|
|
static inline void DelayBranchTo(u32 where)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
mipsr4k.nextPC = where;
|
|
|
|
mipsr4k.inDelaySlot = true;
|
|
|
|
}
|
|
|
|
|
2013-01-22 02:56:16 +00:00
|
|
|
static inline void SkipLikely()
|
|
|
|
{
|
|
|
|
PC += 8;
|
|
|
|
--mipsr4k.downcount;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
int MIPS_SingleStep()
|
|
|
|
{
|
2012-11-26 03:25:14 +00:00
|
|
|
#if defined(ARM)
|
2013-08-24 21:43:49 +00:00
|
|
|
MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(mipsr4k.pc));
|
2012-11-01 15:19:01 +00:00
|
|
|
#else
|
2013-08-24 21:43:49 +00:00
|
|
|
MIPSOpcode op = Memory::Read_Opcode_JIT(mipsr4k.pc);
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
// Choke on VFPU
|
2013-08-24 20:22:10 +00:00
|
|
|
MIPSInfo info = MIPSGetInfo(op);
|
2012-11-01 15:19:01 +00:00
|
|
|
if (info & IS_VFPU)
|
|
|
|
{
|
|
|
|
if (!Core_IsStepping() && !GetAsyncKeyState(VK_LSHIFT))
|
|
|
|
{
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
{
|
|
|
|
MIPSInterpret(op);
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
{
|
|
|
|
mipsr4k.pc = mipsr4k.nextPC;
|
|
|
|
mipsr4k.inDelaySlot = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MIPSInterpret(op);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MIPS_GetNextPC()
|
|
|
|
{
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
return mipsr4k.nextPC;
|
|
|
|
else
|
|
|
|
return mipsr4k.pc + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIPS_ClearDelaySlot()
|
|
|
|
{
|
|
|
|
mipsr4k.inDelaySlot = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MIPSInt
|
|
|
|
{
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Cache(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-01-22 19:30:49 +00:00
|
|
|
int imm = (s16)(op & 0xFFFF);
|
|
|
|
int rs = _RS;
|
|
|
|
int addr = R(rs) + imm;
|
|
|
|
int func = (op >> 16) & 0x1F;
|
|
|
|
|
2013-12-10 12:15:28 +00:00
|
|
|
// It appears that a cache line is 0x40 (64) bytes, loops in games
|
|
|
|
// issue the cache instruction at that interval.
|
|
|
|
|
|
|
|
// These codes might be PSP-specific, they don't match regular MIPS cache codes very well
|
2013-01-22 19:30:49 +00:00
|
|
|
switch (func) {
|
2013-12-10 12:15:28 +00:00
|
|
|
// Icache
|
|
|
|
case 8:
|
|
|
|
// Invalidate the instruction cache at this address
|
2013-12-10 19:34:07 +00:00
|
|
|
if (MIPSComp::jit) {
|
|
|
|
MIPSComp::jit->ClearCacheAt(addr, 0x40);
|
|
|
|
}
|
2013-12-10 12:15:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Dcache
|
2013-03-04 22:25:44 +00:00
|
|
|
case 24:
|
|
|
|
// "Create Dirty Exclusive" - for avoiding a cacheline fill before writing to it.
|
|
|
|
// Will cause garbage on the real machine so we just ignore it, the app will overwrite the cacheline.
|
|
|
|
break;
|
2013-01-22 19:30:49 +00:00
|
|
|
case 25: // Hit Invalidate - zaps the line if present in cache. Should not writeback???? scary.
|
|
|
|
// No need to do anything.
|
|
|
|
break;
|
2013-12-10 12:15:28 +00:00
|
|
|
case 27: // D-cube. Hit Writeback Invalidate. Tony Hawk Underground 2
|
2013-01-22 19:30:49 +00:00
|
|
|
break;
|
2013-12-10 12:15:28 +00:00
|
|
|
case 30: // GTA LCS, a lot. Fill (prefetch). Tony Hawk Underground 2
|
2013-04-27 18:06:31 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-22 19:30:49 +00:00
|
|
|
default:
|
2013-12-10 12:15:28 +00:00
|
|
|
DEBUG_LOG(CPU, "cache instruction affecting %08x : function %i", addr, func);
|
2013-01-22 19:30:49 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Syscall(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
// Need to pre-move PC, as CallSyscall may result in a rescheduling!
|
|
|
|
// To do this neater, we'll need a little generated kernel loop that syscall can jump to and then RFI from
|
|
|
|
// but I don't see a need to bother.
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
{
|
|
|
|
mipsr4k.pc = mipsr4k.nextPC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mipsr4k.pc += 4;
|
|
|
|
}
|
|
|
|
mipsr4k.inDelaySlot = false;
|
2013-11-02 20:15:44 +00:00
|
|
|
CallSyscall(op);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Sync(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-11-25 16:47:33 +00:00
|
|
|
//DEBUG_LOG(CPU, "sync");
|
2012-11-01 15:19:01 +00:00
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Break(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-03-04 07:46:37 +00:00
|
|
|
Reporting::ReportMessage("BREAK instruction hit");
|
2013-02-01 08:49:14 +00:00
|
|
|
ERROR_LOG(CPU, "BREAK!");
|
2014-01-26 19:53:29 +00:00
|
|
|
if (!g_Config.bIgnoreBadMemAccess) {
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_RelBranch(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int imm = (signed short)(op&0xFFFF)<<2;
|
|
|
|
int rs = _RS;
|
|
|
|
int rt = _RT;
|
|
|
|
u32 addr = PC + imm + 4;
|
|
|
|
|
|
|
|
switch (op >> 26)
|
|
|
|
{
|
2013-01-22 02:56:16 +00:00
|
|
|
case 4: if (R(rt) == R(rs)) DelayBranchTo(addr); else PC += 4; break; //beq
|
|
|
|
case 5: if (R(rt) != R(rs)) DelayBranchTo(addr); else PC += 4; break; //bne
|
|
|
|
case 6: if ((s32)R(rs) <= 0) DelayBranchTo(addr); else PC += 4; break; //blez
|
|
|
|
case 7: if ((s32)R(rs) > 0) DelayBranchTo(addr); else PC += 4; break; //bgtz
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-01-22 02:56:16 +00:00
|
|
|
case 20: if (R(rt) == R(rs)) DelayBranchTo(addr); else SkipLikely(); break; //beql
|
|
|
|
case 21: if (R(rt) != R(rs)) DelayBranchTo(addr); else SkipLikely(); break; //bnel
|
|
|
|
case 22: if ((s32)R(rs) <= 0) DelayBranchTo(addr); else SkipLikely(); break; //blezl
|
|
|
|
case 23: if ((s32)R(rs) > 0) DelayBranchTo(addr); else SkipLikely(); break; //bgtzl
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_RelBranchRI(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int imm = (signed short)(op&0xFFFF)<<2;
|
|
|
|
int rs = _RS;
|
|
|
|
u32 addr = PC + imm + 4;
|
|
|
|
|
|
|
|
switch ((op>>16) & 0x1F)
|
|
|
|
{
|
2012-11-06 14:46:21 +00:00
|
|
|
case 0: if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltz
|
2012-11-01 15:19:01 +00:00
|
|
|
case 1: if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgez
|
2013-01-22 02:56:16 +00:00
|
|
|
case 2: if ((s32)R(rs) < 0) DelayBranchTo(addr); else SkipLikely(); break;//bltzl
|
|
|
|
case 3: if ((s32)R(rs) >= 0) DelayBranchTo(addr); else SkipLikely(); break;//bgezl
|
2013-01-22 16:04:01 +00:00
|
|
|
case 16: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltzal
|
|
|
|
case 17: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgezal
|
|
|
|
case 18: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else SkipLikely(); break;//bltzall
|
|
|
|
case 19: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else SkipLikely(); break;//bgezall
|
2012-11-01 15:19:01 +00:00
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_VBranch(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int imm = (signed short)(op&0xFFFF)<<2;
|
|
|
|
u32 addr = PC + imm + 4;
|
|
|
|
|
2013-08-12 02:10:17 +00:00
|
|
|
// x, y, z, w, any, all, (invalid), (invalid)
|
2012-11-01 15:19:01 +00:00
|
|
|
int imm3 = (op>>18)&7;
|
|
|
|
int val = (currentMIPS->vfpuCtrl[VFPU_CTRL_CC] >> imm3) & 1;
|
|
|
|
|
|
|
|
switch ((op >> 16) & 3)
|
|
|
|
{
|
|
|
|
case 0: if (!val) DelayBranchTo(addr); else PC += 4; break; //bvf
|
|
|
|
case 1: if ( val) DelayBranchTo(addr); else PC += 4; break; //bvt
|
2013-01-22 02:56:16 +00:00
|
|
|
case 2: if (!val) DelayBranchTo(addr); else SkipLikely(); break; //bvfl
|
|
|
|
case 3: if ( val) DelayBranchTo(addr); else SkipLikely(); break; //bvtl
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_FPUBranch(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int imm = (signed short)(op&0xFFFF)<<2;
|
|
|
|
u32 addr = PC + imm + 4;
|
|
|
|
switch((op>>16)&0x1f)
|
|
|
|
{
|
2013-01-22 02:56:16 +00:00
|
|
|
case 0: if (!currentMIPS->fpcond) DelayBranchTo(addr); else PC += 4; break;//bc1f
|
2012-11-01 15:19:01 +00:00
|
|
|
case 1: if ( currentMIPS->fpcond) DelayBranchTo(addr); else PC += 4; break;//bc1t
|
2013-01-22 02:56:16 +00:00
|
|
|
case 2: if (!currentMIPS->fpcond) DelayBranchTo(addr); else SkipLikely(); break;//bc1fl
|
|
|
|
case 3: if ( currentMIPS->fpcond) DelayBranchTo(addr); else SkipLikely(); break;//bc1tl
|
2012-11-01 15:19:01 +00:00
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_JumpType(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
_dbg_assert_msg_(CPU,0,"Jump in delay slot :(");
|
|
|
|
|
2013-08-23 06:23:48 +00:00
|
|
|
u32 off = ((op & 0x03FFFFFF) << 2);
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 addr = (currentMIPS->pc & 0xF0000000) | off;
|
|
|
|
|
|
|
|
switch (op>>26)
|
|
|
|
{
|
|
|
|
case 2: DelayBranchTo(addr); break; //j
|
|
|
|
case 3: //jal
|
|
|
|
R(31) = PC + 8;
|
|
|
|
DelayBranchTo(addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_JumpRegType(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
if (mipsr4k.inDelaySlot)
|
|
|
|
{
|
|
|
|
// There's one of these in Star Soldier at 0881808c, which seems benign - it should probably be ignored.
|
|
|
|
if (op == 0x03e00008)
|
|
|
|
return;
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(CPU, "Jump in delay slot :(");
|
2012-11-01 15:19:01 +00:00
|
|
|
_dbg_assert_msg_(CPU,0,"Jump in delay slot :(");
|
|
|
|
}
|
|
|
|
|
2013-08-12 00:12:54 +00:00
|
|
|
int rs = _RS;
|
2013-10-17 14:39:33 +00:00
|
|
|
int rd = _RD;
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 addr = R(rs);
|
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 8: //jr
|
|
|
|
// LOG(CPU,"returning from: %08x",PC);
|
|
|
|
DelayBranchTo(addr);
|
|
|
|
break;
|
|
|
|
case 9: //jalr
|
2013-10-17 14:39:33 +00:00
|
|
|
R(rd) = PC + 8;
|
2012-11-01 15:19:01 +00:00
|
|
|
DelayBranchTo(addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_IType(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
s32 simm = (s32)(s16)(op & 0xFFFF);
|
|
|
|
u32 uimm = (u32)(u16)(op & 0xFFFF);
|
|
|
|
|
|
|
|
u32 suimm = (u32)simm;
|
|
|
|
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
|
2013-01-03 16:01:12 +00:00
|
|
|
if (rt == 0) { //destination register is zero register
|
|
|
|
PC += 4;
|
2012-11-01 15:19:01 +00:00
|
|
|
return; //nop
|
2013-01-03 16:01:12 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
switch (op>>26)
|
|
|
|
{
|
|
|
|
case 8: R(rt) = R(rs) + simm; break; //addi
|
|
|
|
case 9: R(rt) = R(rs) + simm; break; //addiu
|
|
|
|
case 10: R(rt) = (s32)R(rs) < simm; break; //slti
|
|
|
|
case 11: R(rt) = R(rs) < suimm; break; //sltiu
|
|
|
|
case 12: R(rt) = R(rs) & uimm; break; //andi
|
|
|
|
case 13: R(rt) = R(rs) | uimm; break; //ori
|
|
|
|
case 14: R(rt) = R(rs) ^ uimm; break; //xori
|
|
|
|
case 15: R(rt) = uimm << 16; break; //lui
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_StoreSync(MIPSOpcode op)
|
2012-11-07 16:34:25 +00:00
|
|
|
{
|
2013-08-12 00:12:54 +00:00
|
|
|
int imm = (signed short)(op&0xFFFF);
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
u32 addr = R(rs) + imm;
|
2012-11-07 16:34:25 +00:00
|
|
|
|
|
|
|
switch (op >> 26)
|
|
|
|
{
|
|
|
|
case 48: // ll
|
2013-02-17 01:56:27 +00:00
|
|
|
if (rt != 0) {
|
|
|
|
R(rt) = Memory::Read_U32(addr);
|
|
|
|
}
|
2012-11-07 16:34:25 +00:00
|
|
|
currentMIPS->llBit = 1;
|
|
|
|
break;
|
|
|
|
case 56: // sc
|
|
|
|
if (currentMIPS->llBit) {
|
|
|
|
Memory::Write_U32(R(rt), addr);
|
2013-02-17 01:56:27 +00:00
|
|
|
if (rt != 0) {
|
|
|
|
R(rt) = 1;
|
|
|
|
}
|
2013-02-18 18:27:15 +00:00
|
|
|
} else if (rt != 0) {
|
2012-11-07 16:34:25 +00:00
|
|
|
R(rt) = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-06 17:56:56 +00:00
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_RType3(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
int rd = _RD;
|
2012-11-06 17:56:56 +00:00
|
|
|
static bool has_warned = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-17 01:56:27 +00:00
|
|
|
// Don't change $zr.
|
|
|
|
if (rd == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op & 63)
|
|
|
|
{
|
|
|
|
case 10: if (R(rt) == 0) R(rd) = R(rs); break; //movz
|
|
|
|
case 11: if (R(rt) != 0) R(rd) = R(rs); break; //movn
|
|
|
|
case 32:
|
2012-11-06 17:56:56 +00:00
|
|
|
if (!has_warned) {
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(CPU,"WARNING : exception-causing add at %08x", PC);
|
2012-11-06 17:56:56 +00:00
|
|
|
has_warned = true;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
R(rd) = R(rs) + R(rt); break; //add
|
|
|
|
case 33: R(rd) = R(rs) + R(rt); break; //addu
|
|
|
|
case 34:
|
2012-11-06 17:56:56 +00:00
|
|
|
if (!has_warned) {
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(CPU,"WARNING : exception-causing sub at %08x", PC);
|
2012-11-06 17:56:56 +00:00
|
|
|
has_warned = true;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
R(rd) = R(rs) - R(rt); break; //sub
|
|
|
|
case 35: R(rd) = R(rs) - R(rt); break; //subu
|
|
|
|
case 36: R(rd) = R(rs) & R(rt); break; //and
|
|
|
|
case 37: R(rd) = R(rs) | R(rt); break; //or
|
|
|
|
case 38: R(rd) = R(rs) ^ R(rt); break; //xor
|
|
|
|
case 39: R(rd) = ~(R(rs) | R(rt)); break; //nor
|
|
|
|
case 42: R(rd) = (s32)R(rs) < (s32)R(rt); break; //slt
|
|
|
|
case 43: R(rd) = R(rs) < R(rt); break; //sltu
|
|
|
|
case 44: R(rd) = ((s32)R(rs) > (s32)R(rt)) ? R(rs) : R(rt); break; //max
|
|
|
|
case 45: R(rd) = ((s32)R(rs) < (s32)R(rt)) ? R(rs) : R(rt); break;//min
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_ITypeMem(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int imm = (signed short)(op&0xFFFF);
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
u32 addr = R(rs) + imm;
|
|
|
|
|
2013-01-03 15:14:16 +00:00
|
|
|
if (((op >> 29) & 1) == 0 && rt == 0) {
|
|
|
|
// Don't load anything into $zr
|
2013-01-03 16:01:12 +00:00
|
|
|
PC += 4;
|
2013-01-03 15:14:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op >> 26)
|
|
|
|
{
|
|
|
|
case 32: R(rt) = (u32)(s32)(s8) Memory::Read_U8(addr); break; //lb
|
|
|
|
case 33: R(rt) = (u32)(s32)(s16)Memory::Read_U16(addr); break; //lh
|
|
|
|
case 35: R(rt) = Memory::Read_U32(addr); break; //lw
|
|
|
|
case 36: R(rt) = Memory::Read_U8 (addr); break; //lbu
|
|
|
|
case 37: R(rt) = Memory::Read_U16(addr); break; //lhu
|
|
|
|
case 40: Memory::Write_U8(R(rt), addr); break; //sb
|
|
|
|
case 41: Memory::Write_U16(R(rt), addr); break; //sh
|
|
|
|
case 43: Memory::Write_U32(R(rt), addr); break; //sw
|
|
|
|
|
|
|
|
// When there's an LWL and an LWR together, we should be able to peephole optimize that
|
|
|
|
// into a single non-alignment-checking LW.
|
|
|
|
case 34: //lwl
|
|
|
|
{
|
|
|
|
u32 shift = (addr & 3) * 8;
|
|
|
|
u32 mem = Memory::Read_U32(addr & 0xfffffffc);
|
|
|
|
u32 result = ( u32(R(rt)) & (0x00ffffff >> shift) ) | ( mem << (24 - shift) );
|
|
|
|
R(rt) = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 38: //lwr
|
|
|
|
{
|
|
|
|
u32 shift = (addr & 3) * 8;
|
|
|
|
u32 mem = Memory::Read_U32(addr & 0xfffffffc);
|
|
|
|
u32 regval = R(rt);
|
|
|
|
u32 result = ( regval & (0xffffff00 << (24 - shift)) ) | ( mem >> shift );
|
|
|
|
R(rt) = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 42: //swl
|
|
|
|
{
|
|
|
|
u32 shift = (addr & 3) * 8;
|
|
|
|
u32 mem = Memory::Read_U32(addr & 0xfffffffc);
|
|
|
|
u32 result = ( ( u32(R(rt)) >> (24 - shift) ) ) | ( mem & (0xffffff00 << shift) );
|
|
|
|
Memory::Write_U32(result, (addr & 0xfffffffc));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 46: //swr
|
|
|
|
{
|
|
|
|
u32 shift = (addr & 3) << 3;
|
|
|
|
u32 mem = Memory::Read_U32(addr & 0xfffffffc);
|
|
|
|
u32 result = ( ( u32(R(rt)) << shift ) | (mem & (0x00ffffff >> (24 - shift)) ) );
|
|
|
|
Memory::Write_U32(result, (addr & 0xfffffffc));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret Mem instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_FPULS(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
s32 offset = (s16)(op&0xFFFF);
|
2013-02-13 20:07:06 +00:00
|
|
|
int ft = _FT;
|
2012-11-01 15:19:01 +00:00
|
|
|
int rs = _RS;
|
|
|
|
u32 addr = R(rs) + offset;
|
|
|
|
|
|
|
|
switch(op >> 26)
|
|
|
|
{
|
|
|
|
case 49: FI(ft) = Memory::Read_U32(addr); break; //lwc1
|
|
|
|
case 57: Memory::Write_U32(FI(ft), addr); break; //swc1
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret FPULS instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_mxc1(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int fs = _FS;
|
|
|
|
int rt = _RT;
|
|
|
|
|
|
|
|
switch((op>>21)&0x1f)
|
|
|
|
{
|
2013-02-14 07:56:10 +00:00
|
|
|
case 0: if (rt != 0) R(rt) = FI(fs); break; //mfc1
|
|
|
|
case 2: if (rt != 0) R(rt) = currentMIPS->ReadFCR(fs); break; //cfc1
|
2012-11-01 15:19:01 +00:00
|
|
|
case 4: FI(fs) = R(rt); break; //mtc1
|
|
|
|
case 6: currentMIPS->WriteFCR(fs, R(rt)); break; //ctc1
|
|
|
|
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_RType2(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rs = _RS;
|
|
|
|
int rd = _RD;
|
2013-02-17 01:56:27 +00:00
|
|
|
|
|
|
|
// Don't change $zr.
|
|
|
|
if (rd == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op & 63)
|
|
|
|
{
|
|
|
|
case 22: //clz
|
|
|
|
{ //TODO: verify
|
|
|
|
int x = 31;
|
|
|
|
int count=0;
|
|
|
|
while (!(R(rs) & (1<<x)) && x >= 0)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
R(rd) = count;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 23: //clo
|
|
|
|
{ //TODO: verify
|
|
|
|
int x = 31;
|
|
|
|
int count=0;
|
|
|
|
while ((R(rs) & (1<<x)) && x >= 0)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
R(rd) = count;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_MulDivType(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
int rd = _RD;
|
|
|
|
|
|
|
|
switch (op & 63)
|
|
|
|
{
|
|
|
|
case 24: //mult
|
|
|
|
{
|
|
|
|
s64 result = (s64)(s32)R(rs) * (s64)(s32)R(rt);
|
|
|
|
u64 resultBits = (u64)(result);
|
|
|
|
LO = (u32)(resultBits);
|
|
|
|
HI = (u32)(resultBits>>32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 25: //multu
|
|
|
|
{
|
|
|
|
u64 resultBits = (u64)R(rs) * (u64)R(rt);
|
|
|
|
LO = (u32)(resultBits);
|
|
|
|
HI = (u32)(resultBits>>32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 28: //madd
|
|
|
|
{
|
|
|
|
u32 a=R(rs),b=R(rt),hi=HI,lo=LO;
|
|
|
|
u64 origValBits = (u64)lo | ((u64)(hi)<<32);
|
|
|
|
s64 origVal = (s64)origValBits;
|
|
|
|
s64 result = origVal + (s64)(s32)a * (s64)(s32)b;
|
|
|
|
u64 resultBits = (u64)(result);
|
|
|
|
LO = (u32)(resultBits);
|
|
|
|
HI = (u32)(resultBits>>32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 29: //maddu
|
|
|
|
{
|
|
|
|
u32 a=R(rs),b=R(rt),hi=HI,lo=LO;
|
|
|
|
u64 origVal = (u64)lo | ((u64)(hi)<<32);
|
|
|
|
u64 result = origVal + (u64)a * (u64)b;
|
|
|
|
LO = (u32)(result);
|
|
|
|
HI = (u32)(result>>32);
|
|
|
|
}
|
|
|
|
break;
|
2012-11-07 15:18:37 +00:00
|
|
|
case 46: //msub
|
|
|
|
{
|
|
|
|
u32 a=R(rs),b=R(rt),hi=HI,lo=LO;
|
|
|
|
u64 origValBits = (u64)lo | ((u64)(hi)<<32);
|
|
|
|
s64 origVal = (s64)origValBits;
|
|
|
|
s64 result = origVal - (s64)(s32)a * (s64)(s32)b;
|
|
|
|
u64 resultBits = (u64)(result);
|
|
|
|
LO = (u32)(resultBits);
|
|
|
|
HI = (u32)(resultBits>>32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 47: //msubu
|
|
|
|
{
|
|
|
|
u32 a=R(rs),b=R(rt),hi=HI,lo=LO;
|
|
|
|
u64 origVal = (u64)lo | ((u64)(hi)<<32);
|
|
|
|
u64 result = origVal - (u64)a * (u64)b;
|
|
|
|
LO = (u32)(result);
|
|
|
|
HI = (u32)(result>>32);
|
|
|
|
}
|
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
case 16: R(rd) = HI; break; //mfhi
|
|
|
|
case 17: HI = R(rs); break; //mthi
|
|
|
|
case 18: R(rd) = LO; break; //mflo
|
|
|
|
case 19: LO = R(rs); break; //mtlo
|
|
|
|
case 26: //div
|
|
|
|
{
|
|
|
|
s32 a = (s32)R(rs);
|
|
|
|
s32 b = (s32)R(rt);
|
2012-11-18 22:35:02 +00:00
|
|
|
if (a == (s32)0x80000000 && b == -1) {
|
2012-11-11 21:38:19 +00:00
|
|
|
LO = 0x80000000;
|
|
|
|
} else if (b != 0) {
|
|
|
|
LO = (u32)(a / b);
|
|
|
|
HI = (u32)(a % b);
|
2012-11-01 15:19:01 +00:00
|
|
|
} else {
|
|
|
|
LO = HI = 0; // Not sure what the right thing to do is?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27: //divu
|
|
|
|
{
|
|
|
|
u32 a = R(rs);
|
|
|
|
u32 b = R(rt);
|
|
|
|
if (b != 0)
|
|
|
|
{
|
|
|
|
LO = (a/b);
|
|
|
|
HI = (a%b);
|
|
|
|
} else {
|
|
|
|
LO = HI = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_ShiftType(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rt = _RT;
|
|
|
|
int rs = _RS;
|
|
|
|
int rd = _RD;
|
|
|
|
int sa = _FD;
|
2013-02-17 01:56:27 +00:00
|
|
|
|
|
|
|
// Don't change $zr.
|
|
|
|
if (rd == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 0: R(rd) = R(rt) << sa; break; //sll
|
|
|
|
case 2:
|
|
|
|
if (_RS == 0) //srl
|
|
|
|
{
|
|
|
|
R(rd) = R(rt) >> sa;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (_RS == 1) //rotr
|
|
|
|
{
|
2013-04-04 17:16:15 +00:00
|
|
|
R(rd) = __rotr(R(rt), sa);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto wrong;
|
|
|
|
|
|
|
|
case 3: R(rd) = (u32)(((s32)R(rt)) >> sa); break; //sra
|
|
|
|
case 4: R(rd) = R(rt) << (R(rs)&0x1F); break; //sllv
|
|
|
|
case 6:
|
|
|
|
if (_FD == 0) //srlv
|
|
|
|
{
|
|
|
|
R(rd) = R(rt) >> (R(rs)&0x1F);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (_FD == 1) // rotrv
|
|
|
|
{
|
2013-04-04 17:16:15 +00:00
|
|
|
R(rd) = __rotr(R(rt), R(rs));
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else goto wrong;
|
|
|
|
case 7: R(rd) = (u32)(((s32)R(rt)) >> (R(rs)&0x1F)); break; //srav
|
|
|
|
default:
|
|
|
|
wrong:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Allegrex(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rt = _RT;
|
|
|
|
int rd = _RD;
|
2013-02-17 01:56:27 +00:00
|
|
|
|
|
|
|
// Don't change $zr.
|
|
|
|
if (rd == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch((op>>6)&31)
|
|
|
|
{
|
|
|
|
case 16: // seb
|
|
|
|
R(rd) = (u32)(s32)(s8)(u8)R(rt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 20: // bitrev
|
|
|
|
{
|
|
|
|
u32 tmp = 0;
|
|
|
|
for (int i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
if (R(rt) & (1 << i))
|
|
|
|
{
|
|
|
|
tmp |= (0x80000000 >> i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
R(rd) = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24: // seh
|
|
|
|
R(rd) = (u32)(s32)(s16)(u16)R(rt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret ALLEGREX instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Allegrex2(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rt = _RT;
|
|
|
|
int rd = _RD;
|
|
|
|
|
2013-02-17 01:56:27 +00:00
|
|
|
// Don't change $zr.
|
|
|
|
if (rd == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op & 0x3ff)
|
|
|
|
{
|
2012-11-29 13:35:44 +00:00
|
|
|
case 0xA0: //wsbh
|
2013-11-05 15:37:53 +00:00
|
|
|
R(rd) = ((R(rt) & 0xFF00FF00) >> 8) | ((R(rt) & 0x00FF00FF) << 8);
|
2012-11-29 13:35:44 +00:00
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
case 0xE0: //wsbw
|
2013-11-05 15:19:08 +00:00
|
|
|
R(rd) = swap32(R(rt));
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret ALLEGREX instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-25 20:28:19 +00:00
|
|
|
void Int_Special2(MIPSOpcode op)
|
|
|
|
{
|
|
|
|
static int reported = 0;
|
|
|
|
switch (op & 0x3F)
|
|
|
|
{
|
|
|
|
case 36:
|
|
|
|
if (!reported) {
|
|
|
|
Reporting::ReportMessage("MFIC instruction hit (%08x) at %08x", op, currentMIPS->pc);
|
|
|
|
WARN_LOG(CPU,"MFIC Disable/Enable Interrupt CPU instruction");
|
|
|
|
reported = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 38:
|
|
|
|
if (!reported) {
|
|
|
|
Reporting::ReportMessage("MTIC instruction hit (%08x) at %08x", op, currentMIPS->pc);
|
|
|
|
WARN_LOG(CPU,"MTIC Disable/Enable Interrupt CPU instruction");
|
|
|
|
reported = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Special3(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int rs = _RS;
|
|
|
|
int rt = _RT;
|
|
|
|
int pos = _POS;
|
|
|
|
|
2013-02-17 01:56:27 +00:00
|
|
|
// Don't change $zr.
|
|
|
|
if (rt == 0)
|
|
|
|
{
|
|
|
|
PC += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 0x0: //ext
|
|
|
|
{
|
|
|
|
int size = _SIZE + 1;
|
|
|
|
R(rt) = (R(rs) >> pos) & ((1<<size) - 1);
|
|
|
|
}
|
|
|
|
break;
|
2013-02-21 08:00:30 +00:00
|
|
|
case 0x4: //ins
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int size = (_SIZE + 1) - pos;
|
|
|
|
int sourcemask = (1 << size) - 1;
|
|
|
|
int destmask = sourcemask << pos;
|
|
|
|
R(rt) = (R(rt) & ~destmask) | ((R(rs)&sourcemask) << pos);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_FPU2op(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int fs = _FS;
|
|
|
|
int fd = _FD;
|
|
|
|
|
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 4: F(fd) = sqrtf(F(fs)); break; //sqrt
|
|
|
|
case 5: F(fd) = fabsf(F(fs)); break; //abs
|
|
|
|
case 6: F(fd) = F(fs); break; //mov
|
|
|
|
case 7: F(fd) = -F(fs); break; //neg
|
2013-09-14 04:26:46 +00:00
|
|
|
case 12:
|
|
|
|
case 13:
|
|
|
|
case 14:
|
|
|
|
case 15:
|
2013-11-12 13:07:48 +00:00
|
|
|
if (my_isnanorinf(F(fs)))
|
2013-09-14 04:26:46 +00:00
|
|
|
{
|
|
|
|
FsI(fd) = my_isinf(F(fs)) && F(fs) < 0.0f ? -2147483648LL : 2147483647LL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 12: FsI(fd) = (int)floorf(F(fs)+0.5f); break; //round.w.s
|
|
|
|
case 13: FsI(fd) = F(fs)>=0 ? (int)floorf(F(fs)) : (int)ceilf(F(fs)); break;//trunc.w.s
|
|
|
|
case 14: FsI(fd) = (int)ceilf (F(fs)); break; //ceil.w.s
|
|
|
|
case 15: FsI(fd) = (int)floorf(F(fs)); break; //floor.w.s
|
|
|
|
}
|
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
case 32: F(fd) = (float)FsI(fs); break; //cvt.s.w
|
2012-11-09 10:20:39 +00:00
|
|
|
|
|
|
|
case 36:
|
2013-11-12 13:07:48 +00:00
|
|
|
if (my_isnanorinf(F(fs)))
|
2013-09-14 04:26:46 +00:00
|
|
|
{
|
|
|
|
FsI(fd) = my_isinf(F(fs)) && F(fs) < 0.0f ? -2147483648LL : 2147483647LL;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-09 10:20:39 +00:00
|
|
|
switch (currentMIPS->fcr31 & 3)
|
|
|
|
{
|
2012-11-22 17:12:56 +00:00
|
|
|
case 0: FsI(fd) = (int)round_ieee_754(F(fs)); break; // RINT_0
|
2012-11-09 10:20:39 +00:00
|
|
|
case 1: FsI(fd) = (int)F(fs); break; // CAST_1
|
2012-11-18 22:35:02 +00:00
|
|
|
case 2: FsI(fd) = (int)ceilf(F(fs)); break; // CEIL_2
|
|
|
|
case 3: FsI(fd) = (int)floorf(F(fs)); break; // FLOOR_3
|
2012-11-09 10:20:39 +00:00
|
|
|
}
|
|
|
|
break; //cvt.w.s
|
2012-11-01 15:19:01 +00:00
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret FPU2Op instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_FPUComp(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int fs = _FS;
|
|
|
|
int ft = _FT;
|
|
|
|
bool cond;
|
|
|
|
switch (op & 0xf)
|
|
|
|
{
|
2012-11-22 17:12:56 +00:00
|
|
|
case 0: //f
|
|
|
|
case 8: //sf
|
|
|
|
cond = false;
|
|
|
|
break;
|
|
|
|
|
2013-02-13 09:51:49 +00:00
|
|
|
case 1: //un
|
|
|
|
case 9: //ngle
|
2013-04-13 19:51:38 +00:00
|
|
|
cond = my_isnan(F(fs)) || my_isnan(F(ft));
|
2013-02-13 09:51:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
case 2: //eq
|
2012-11-22 17:12:56 +00:00
|
|
|
case 10: //seq
|
2013-09-14 04:28:59 +00:00
|
|
|
cond = !my_isnan(F(fs)) && !my_isnan(F(ft)) && (F(fs) == F(ft));
|
2013-02-13 09:51:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-22 17:12:56 +00:00
|
|
|
case 3: //ueq
|
|
|
|
case 11: //ngl
|
2013-04-13 19:51:38 +00:00
|
|
|
cond = (F(fs) == F(ft)) || my_isnan(F(fs)) || my_isnan(F(ft));
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
2012-11-22 17:12:56 +00:00
|
|
|
|
|
|
|
case 4: //olt
|
2012-11-01 15:19:01 +00:00
|
|
|
case 12: //lt
|
|
|
|
cond = (F(fs) < F(ft));
|
|
|
|
break;
|
|
|
|
|
2013-02-13 09:51:49 +00:00
|
|
|
case 5: //ult
|
|
|
|
case 13: //nge
|
2013-04-13 19:51:38 +00:00
|
|
|
cond = (F(fs) < F(ft)) || my_isnan(F(fs)) || my_isnan(F(ft));
|
2013-02-13 09:51:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-22 17:12:56 +00:00
|
|
|
case 6: //ole
|
2012-11-01 15:19:01 +00:00
|
|
|
case 14: //le
|
|
|
|
cond = (F(fs) <= F(ft));
|
|
|
|
break;
|
|
|
|
|
2013-02-13 09:51:49 +00:00
|
|
|
case 7: //ule
|
|
|
|
case 15: //ngt
|
2013-04-13 19:51:38 +00:00
|
|
|
cond = (F(fs) <= F(ft)) || my_isnan(F(fs)) || my_isnan(F(ft));
|
2013-02-13 09:51:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret FPUComp instruction that can't be interpreted");
|
2012-11-18 22:35:02 +00:00
|
|
|
cond = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentMIPS->fpcond = cond;
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_FPU3op(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
int ft = _FT;
|
|
|
|
int fs = _FS;
|
|
|
|
int fd = _FD;
|
|
|
|
|
|
|
|
switch (op & 0x3f)
|
|
|
|
{
|
|
|
|
case 0: F(fd) = F(fs) + F(ft); break; //add
|
|
|
|
case 1: F(fd) = F(fs) - F(ft); break; //sub
|
|
|
|
case 2: F(fd) = F(fs) * F(ft); break; //mul
|
|
|
|
case 3: F(fd) = F(fs) / F(ft); break; //div
|
|
|
|
default:
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret FPU3Op instruction that can't be interpreted");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Interrupt(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-11-08 23:03:46 +00:00
|
|
|
static int reported = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
switch (op & 1)
|
|
|
|
{
|
|
|
|
case 0:
|
2012-11-08 23:03:46 +00:00
|
|
|
if (!reported) {
|
2013-08-12 02:33:52 +00:00
|
|
|
Reporting::ReportMessage("INTERRUPT instruction hit (%08x) at %08x", op, currentMIPS->pc);
|
2012-11-08 23:03:46 +00:00
|
|
|
WARN_LOG(CPU,"Disable/Enable Interrupt CPU instruction");
|
|
|
|
reported = 1;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
PC += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void Int_Emuhack(MIPSOpcode op)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-11-30 19:57:44 +00:00
|
|
|
if (((op >> 24) & 3) != 1) {
|
|
|
|
_dbg_assert_msg_(CPU,0,"Trying to interpret emuhack instruction that can't be interpreted");
|
|
|
|
}
|
|
|
|
// It's a replacement func!
|
|
|
|
int index = op.encoding & 0xFFFFFF;
|
|
|
|
const ReplacementTableEntry *entry = GetReplacementFunc(index);
|
|
|
|
if (entry) {
|
|
|
|
entry->replaceFunc();
|
|
|
|
} else {
|
|
|
|
ERROR_LOG(CPU, "Bad replacement function index %i", index);
|
|
|
|
}
|
|
|
|
|
|
|
|
PC = currentMIPS->r[MIPS_REG_RA];
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|