[Project64] Fix CArmOps::SetJump20 for negative

This commit is contained in:
zilmar 2016-11-22 21:07:44 +11:00
parent a5a1547131
commit 4053bc2286
3 changed files with 23 additions and 16 deletions

View File

@ -266,9 +266,9 @@ void CArmOps::BranchLabel20(ArmCompareType CompareType, const char * Label)
op.Branch20.S = 0;
op.Branch20.Opcode = 0x1E;
op.Branch20.imm11 = 0;
op.Branch20.J2 = CompareType == ArmBranch_Always ? 1 : 0;
op.Branch20.J2 = 0;
op.Branch20.val12 = CompareType == ArmBranch_Always ? 1 : 0;
op.Branch20.J1 = CompareType == ArmBranch_Always ? 1 : 0;
op.Branch20.J1 = 0;
op.Branch20.val14 = 0x2;
AddCode32(op.Hex);
}
@ -1415,25 +1415,18 @@ void CArmOps::SetJump20(uint32_t * Loc, uint32_t * JumpLoc)
g_Notify->BreakPoint(__FILE__, __LINE__);
return;
}
uint32_t pc = ((uint32_t)Loc) + 4;
uint32_t target = ((uint32_t)JumpLoc);
uint32_t immediate = (target - pc) >> 1;
uint32_t immediate_check = immediate & ~0xFFFFF;
int32_t pc = ((int32_t)Loc) + 4;
int32_t target = ((int32_t)JumpLoc);
int32_t immediate = (target - pc) >> 1;
int32_t immediate_check = immediate & ~0xFFFFF;
if (immediate_check != 0 && immediate_check != ~0xFFFFF)
{
CPU_Message("%s: target %X pc %X immediate: %X", __FUNCTION__, target,pc, immediate );
g_Notify->BreakPoint(__FILE__, __LINE__);
}
Arm32Opcode op = {0};
op.Hex = *Loc;
if (op.Branch20.val12 == 0)
{
op.Branch20.imm11 = (immediate & 0x7FF);
op.Branch20.imm6 = (immediate >> 11) & 0x37;
op.Branch20.J1 = (immediate >> 17) & 0x1;
op.Branch20.J2 = (immediate >> 18) & 0x1;
op.Branch20.S = (immediate >> 19) & 0x1;
}
else
{
if (immediate < 0)
{
@ -1442,8 +1435,21 @@ void CArmOps::SetJump20(uint32_t * Loc, uint32_t * JumpLoc)
else
{
op.Branch20.imm11 = (immediate & 0x7FF);
op.Branch20.imm6 = (immediate >> 11) & 0x37;
op.Branch20.J1 = (immediate >> 17) & 0x1;
op.Branch20.J2 = (immediate >> 18) & 0x1;
op.Branch20.S = (immediate >> 19) & 0x1;
}
}
else
{
op.Branch20.S = (immediate >> 23) & 0x1;
op.Branch20.J1 = op.Branch20.S == 1 ? (immediate >> 22) & 0x1 : !((immediate >> 22) & 0x1);
op.Branch20.J2 = op.Branch20.S == 1 ? (immediate >> 21) & 0x1 : !((immediate >> 21) & 0x1);
op.Branch20.cond = (immediate >> 17) & 0xF;
op.Branch20.imm6 = (immediate >> 11) & 0x3F;
op.Branch20.imm11 = (immediate & 0x7FF);
}
uint32_t OriginalValue = *Loc;
*Loc = op.Hex;

View File

@ -217,6 +217,9 @@ protected:
protected:
static const char * ArmRegName(ArmReg Reg);
private:
friend CArmRegInfo;
static void BreakPointNotification(const char * FileName, uint32_t LineNumber);
static bool ArmCompareInverse(ArmCompareType CompareType);
static ArmCompareType ArmCompareInverseType(ArmCompareType CompareType);

View File

@ -13,11 +13,9 @@
#include <Project64-core/N64System/Recompiler/RegBase.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Mips/RegisterClass.h>
#include <Project64-core/Settings/DebugSettings.h>
class CArmRegInfo :
public CRegBase,
private CDebugSettings,
public CArmOps,
private CSystemRegisters
{