From 5233a3bc84c4d92cb228e5b9037b06ae5a01423b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 9 Apr 2023 10:36:20 -0700 Subject: [PATCH] Debugger: Cleanup some sign extends in disassembly. --- Core/MIPS/MIPSDis.cpp | 16 ++++++++-------- Core/MIPS/MIPSDisVFPU.cpp | 12 +++++------- Core/MIPS/MIPSIntVFPU.cpp | 7 ++++--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Core/MIPS/MIPSDis.cpp b/Core/MIPS/MIPSDis.cpp index d62d67dd34..81eac961fe 100644 --- a/Core/MIPS/MIPSDis.cpp +++ b/Core/MIPS/MIPSDis.cpp @@ -97,7 +97,7 @@ namespace MIPSDis void Dis_FPULS(MIPSOpcode op, char *out) { - int offset = (signed short)(op&0xFFFF); + int offset = SignExtend16ToS32(op & 0xFFFF); int ft = _FT; int rs = _RS; const char *name = MIPSGetName(op); @@ -114,7 +114,7 @@ namespace MIPSDis void Dis_FPUBranch(MIPSOpcode op, char *out) { u32 off = disPC; - int imm = (signed short)(op&0xFFFF)<<2; + int imm = SignExtend16ToS32(op & 0xFFFF) << 2; off += imm + 4; const char *name = MIPSGetName(op); sprintf(out, "%s\t->$%08x",name,off); @@ -123,7 +123,7 @@ namespace MIPSDis void Dis_RelBranch(MIPSOpcode op, char *out) { u32 off = disPC; - int imm = (signed short)(op&0xFFFF)<<2; + int imm = SignExtend16ToS32(op & 0xFFFF) << 2; int rs = _RS; off += imm + 4; @@ -155,7 +155,7 @@ namespace MIPSDis void Dis_RelBranch2(MIPSOpcode op, char *out) { u32 off = disPC; - int imm = (signed short)(op&0xFFFF)<<2; + int imm = SignExtend16ToS32(op & 0xFFFF) << 2; int rt = _RT; int rs = _RS; off += imm + 4; @@ -196,7 +196,7 @@ namespace MIPSDis } void Dis_ori(MIPSOpcode op, char *out) { - u32 uimm = (u32)(u16)(op & 0xFFFF); + u32 uimm = op & 0xFFFF; int rt = _RT; int rs = _RS; const char *name = MIPSGetName(op); @@ -208,7 +208,7 @@ namespace MIPSDis void Dis_IType1(MIPSOpcode op, char *out) { - u32 uimm = (u32)(u16)(op & 0xFFFF); + u32 uimm = op & 0xFFFF; int rt = _RT; const char *name = MIPSGetName(op); sprintf(out, "%s\t%s, 0x%X",name,RN(rt),uimm); @@ -216,7 +216,7 @@ namespace MIPSDis void Dis_addi(MIPSOpcode op, char *out) { - int imm = (signed short)(op&0xFFFF); + int imm = SignExtend16ToS32(op & 0xFFFF); int rt = _RT; int rs = _RS; if (rs == 0) @@ -227,7 +227,7 @@ namespace MIPSDis void Dis_ITypeMem(MIPSOpcode op, char *out) { - int imm = (signed short)(op&0xFFFF); + int imm = SignExtend16ToS32(op & 0xFFFF); int rt = _RT; int rs = _RS; const char *name = MIPSGetName(op); diff --git a/Core/MIPS/MIPSDisVFPU.cpp b/Core/MIPS/MIPSDisVFPU.cpp index 7efe6a7dd9..c37f919b5d 100644 --- a/Core/MIPS/MIPSDisVFPU.cpp +++ b/Core/MIPS/MIPSDisVFPU.cpp @@ -16,13 +16,11 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include -#include "Core/HLE/HLE.h" - +#include "Common/Data/Convert/SmallDataConvert.h" #include "Core/MIPS/MIPS.h" #include "Core/MIPS/MIPSDis.h" #include "Core/MIPS/MIPSTables.h" #include "Core/MIPS/MIPSDebugInterface.h" - #include "Core/MIPS/MIPSVFPUUtils.h" #define _RS ((op>>21) & 0x1F) @@ -102,7 +100,7 @@ namespace MIPSDis { void Dis_SV(MIPSOpcode op, char *out) { - int offset = (signed short)(op&0xFFFC); + int offset = SignExtend16ToS32(op & 0xFFFC); int vt = ((op>>16)&0x1f)|((op&3)<<5); int rs = (op>>21) & 0x1f; const char *name = MIPSGetName(op); @@ -111,7 +109,7 @@ namespace MIPSDis void Dis_SVQ(MIPSOpcode op, char *out) { - int offset = (signed short)(op&0xFFFC); + int offset = SignExtend16ToS32(op & 0xFFFC); int vt = (((op>>16)&0x1f))|((op&1)<<5); int rs = (op>>21) & 0x1f; const char *name = MIPSGetName(op); @@ -122,7 +120,7 @@ namespace MIPSDis void Dis_SVLRQ(MIPSOpcode op, char *out) { - int offset = (signed short)(op&0xFFFC); + int offset = SignExtend16ToS32(op & 0xFFFC); int vt = (((op>>16)&0x1f))|((op&1)<<5); int rs = (op>>21) & 0x1f; int lr = (op>>1)&1; @@ -603,7 +601,7 @@ namespace MIPSDis void Dis_VBranch(MIPSOpcode op, char *out) { u32 off = disPC; - int imm = (signed short)(op&0xFFFF)<<2; + int imm = SignExtend16ToS32(op&0xFFFF) << 2; int imm3 = (op>>18)&7; off += imm + 4; const char *name = MIPSGetName(op); diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index b8bbe25caf..53ead7dcac 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -21,6 +21,7 @@ #include #include +#include "Common/Data/Convert/SmallDataConvert.h" #include "Common/Math/math_util.h" #include "Core/Compatibility.h" @@ -201,7 +202,7 @@ namespace MIPSInt void Int_SVQ(MIPSOpcode op) { - int imm = (signed short)(op&0xFFFC); + int imm = SignExtend16ToS32(op & 0xFFFC); int rs = _RS; int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); @@ -419,7 +420,7 @@ namespace MIPSInt void Int_Viim(MIPSOpcode op) { int vt = _VT; - s32 imm = (s16)(op&0xFFFF); + s32 imm = SignExtend16ToS32(op & 0xFFFF); u16 uimm16 = (op&0xFFFF); float f[1]; int type = (op >> 23) & 7; @@ -1736,7 +1737,7 @@ namespace MIPSInt void Int_SV(MIPSOpcode op) { - s32 imm = (signed short)(op&0xFFFC); + s32 imm = SignExtend16ToS32(op & 0xFFFC); int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); int rs = _RS; u32 addr = R(rs) + imm;