From b0cef1b14390bfc80d51f9040dcfcb1a796344cd Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 19 Aug 2014 14:58:00 +0200 Subject: [PATCH 1/5] Add a couple of pseudo instructions to the R5900 disassembler and display signed immediates as signed --- pcsx2/DebugTools/DisR5900asm.cpp | 132 +++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 32 deletions(-) diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index e968d5f75f..9b0b456652 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -691,6 +691,18 @@ void COP1_Unknown( std::string& output ) // the copy-paste marathon of code below more readable! #define _sap( str ) ssappendf( output, str, +const char* signedImmediate(s16 imm, int len = 0) +{ + static char buffer[32]; + + if (imm >= 0) + sprintf(buffer,"0x%*X",len,imm); + else + sprintf(buffer,"-0x%*X",len,-imm); + + return buffer; +} + //********************* Standard Opcodes*********************** void J( std::string& output ) { output += "j\t"; jump_decode(output);} void JAL( std::string& output ) { output += "jal\t"; jump_decode(output);} @@ -699,11 +711,36 @@ void BNE( std::string& output ) { _sap("bne\t%s, %s, ") GPR_REG[DECO void BLEZ( std::string& output ) { _sap("blez\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void BGTZ( std::string& output ) { _sap("bgtz\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void ADDI( std::string& output ) { _sap("addi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED);} -void ADDIU( std::string& output ) { _sap("addiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED);} + +void ADDIU( std::string& output ) +{ + int rt = DECODE_RT; + int rs = DECODE_RS; + s16 imm = DECODE_IMMED; + + if (rs == 0) + ssappendf(output, "li\t%s, %s",GPR_REG[rt],signedImmediate(imm)); + else + ssappendf(output, "addiu\t%s, %s, %s",GPR_REG[rt],GPR_REG[rs],signedImmediate(imm)); +} + void SLTI( std::string& output ) { _sap("slti\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void SLTIU( std::string& output ) { _sap("sltiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void ANDI( std::string& output ) { _sap("andi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED);} -void ORI( std::string& output ) { _sap("ori\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } + +void ORI( std::string& output ) +{ + int rt = DECODE_RT; + int rs = DECODE_RS; + + u32 unsignedImm = (u16) DECODE_IMMED; + + if (rs == 0) + ssappendf(output, "li\t%s, 0x%X",GPR_REG[rt],unsignedImm); + else + ssappendf(output, "ori\t%s, %s, 0x%X",GPR_REG[rt],GPR_REG[rs],unsignedImm); +} + void XORI( std::string& output ) { _sap("xori\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void LUI( std::string& output ) { _sap("lui\t%s, 0x%04X") GPR_REG[DECODE_RT], DECODE_IMMED); } void BEQL( std::string& output ) { _sap("beql\t%s, %s, ") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); offset_decode(output); } @@ -712,32 +749,32 @@ void BLEZL( std::string& output ) { _sap("blezl\t%s, ") GPR_REG[DECO void BGTZL( std::string& output ) { _sap("bgtzl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void DADDI( std::string& output ) { _sap("daddi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void DADDIU( std::string& output ) { _sap("daddiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } -void LDL( std::string& output ) { _sap("ldl\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LDR( std::string& output ) { _sap("ldr\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LB( std::string& output ) { _sap("lb\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LH( std::string& output ) { _sap("lh\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LWL( std::string& output ) { _sap("lwl\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LW( std::string& output ) { _sap("lw\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LBU( std::string& output ) { _sap("lbu\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LHU( std::string& output ) { _sap("lhu\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LWR( std::string& output ) { _sap("lwr\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LWU( std::string& output ) { _sap("lwu\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SB( std::string& output ) { _sap("sb\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SH( std::string& output ) { _sap("sh\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SWL( std::string& output ) { _sap("swl\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SW( std::string& output ) { _sap("sw\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SDL( std::string& output ) { _sap("sdl\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SDR( std::string& output ) { _sap("sdr\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SWR( std::string& output ) { _sap("swr\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LD( std::string& output ) { _sap("ld\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SD( std::string& output ) { _sap("sd\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LQ( std::string& output ) { _sap("lq\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SQ( std::string& output ) { _sap("sq\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SWC1( std::string& output ) { _sap("swc1\t%s, 0x%04X(%s)") COP1_REG_FP[DECODE_FT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void SQC2( std::string& output ) { _sap("sqc2\t%s, 0x%04X(%s)") COP2_REG_FP[DECODE_FT], DECODE_IMMED, GPR_REG[DECODE_RS]); } +void LDL( std::string& output ) { _sap("ldl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LDR( std::string& output ) { _sap("ldr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LB( std::string& output ) { _sap("lb\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LH( std::string& output ) { _sap("lh\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LWL( std::string& output ) { _sap("lwl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LW( std::string& output ) { _sap("lw\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LBU( std::string& output ) { _sap("lbu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LHU( std::string& output ) { _sap("lhu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LWR( std::string& output ) { _sap("lwr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LWU( std::string& output ) { _sap("lwu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SB( std::string& output ) { _sap("sb\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SH( std::string& output ) { _sap("sh\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SWL( std::string& output ) { _sap("swl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SW( std::string& output ) { _sap("sw\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SDL( std::string& output ) { _sap("sdl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SDR( std::string& output ) { _sap("sdr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SWR( std::string& output ) { _sap("swr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LD( std::string& output ) { _sap("ld\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SD( std::string& output ) { _sap("sd\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LQ( std::string& output ) { _sap("lq\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SQ( std::string& output ) { _sap("sq\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SWC1( std::string& output ) { _sap("swc1\t%s, %s(%s)") COP1_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void SQC2( std::string& output ) { _sap("sqc2\t%s, %s(%s)") COP2_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } void PREF( std::string& output ) { output += "pref ---"; /*_sap("PREF\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[RS]); */} -void LWC1( std::string& output ) { _sap("lwc1\t%s, 0x%04X(%s)") COP1_REG_FP[DECODE_FT], DECODE_IMMED, GPR_REG[DECODE_RS]); } -void LQC2( std::string& output ) { _sap("lqc2\t%s, 0x%04X(%s)") COP2_REG_FP[DECODE_FT], DECODE_IMMED, GPR_REG[DECODE_RS]); } +void LWC1( std::string& output ) { _sap("lwc1\t%s, %s(%s)") COP1_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LQC2( std::string& output ) { _sap("lqc2\t%s, %s(%s)") COP2_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } //********************END OF STANDARD OPCODES************************* void SLL( std::string& output ) @@ -765,7 +802,6 @@ void JALR( std::string& output ) _sap("jalr\t%s, ->%s") GPR_REG[rd], GPR_REG[DECODE_RS]); } - void SYNC( std::string& output ) { output += "SYNC"; } void MFHI( std::string& output ) { _sap("mfhi\t%s") GPR_REG[DECODE_RD]); } void MTHI( std::string& output ) { _sap("mthi\t%s") GPR_REG[DECODE_RS]); } @@ -778,8 +814,24 @@ void MULT( std::string& output ) { _sap("mult\t%s, %s, %s") GPR_REG[DECODE_R void MULTU( std::string& output ) { _sap("multu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]);} void DIV( std::string& output ) { _sap("div\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void DIVU( std::string& output ) { _sap("divu\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void ADD( std::string& output ) { _sap("add\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void ADDU( std::string& output ) { _sap("addu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } + +void disAddAddu( std::string& output, const char* name ) +{ + int rd = DECODE_RD; + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == 0) + ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rt]); + else if (rt == 0) + ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rs]); + else + ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[rd], GPR_REG[rs], GPR_REG[rt]); +} + +void ADD( std::string& output ) { disAddAddu(output,"add"); } +void ADDU( std::string& output ) { disAddAddu(output,"addu"); } + void SUB( std::string& output ) { _sap("sub\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void SUBU( std::string& output ) { _sap("subu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void AND( std::string& output ) { _sap("and\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } @@ -788,8 +840,24 @@ void XOR( std::string& output ) { _sap("xor\t%s, %s, %s") GPR_REG[DECODE_R void NOR( std::string& output ) { _sap("nor\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void SLT( std::string& output ) { _sap("slt\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void SLTU( std::string& output ) { _sap("sltu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void DADD( std::string& output ) { _sap("dadd\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void DADDU( std::string& output ) { _sap("daddu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } + +void disDaddDaddu( std::string& output, const char* name ) +{ + int rd = DECODE_RD; + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == 0) + ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RT]); + else if (rt == 0) + ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RS]); + else + ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); +} + +void DADD( std::string& output ) { disDaddDaddu(output,"dadd"); } +void DADDU( std::string& output ) { disDaddDaddu(output,"daddu"); } + void DSUB( std::string& output ) { _sap("dsub\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void DSUBU( std::string& output ) { _sap("dsubu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TGE( std::string& output ) { _sap("tge\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } From a696bf0d0210931a4ccf2e93d8f317793913f039 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 19 Aug 2014 13:22:04 +0200 Subject: [PATCH 2/5] Add branch pseudo opcodes to R5900 disassembler --- pcsx2/DebugTools/DisR5900asm.cpp | 70 ++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index 9b0b456652..e01dc2edb5 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -706,8 +706,39 @@ const char* signedImmediate(s16 imm, int len = 0) //********************* Standard Opcodes*********************** void J( std::string& output ) { output += "j\t"; jump_decode(output);} void JAL( std::string& output ) { output += "jal\t"; jump_decode(output);} -void BEQ( std::string& output ) { _sap("beq\t%s, %s, ") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); offset_decode(output); } -void BNE( std::string& output ) { _sap("bne\t%s, %s, ") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); offset_decode(output); } + +void BEQ( std::string& output ) +{ + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == rt) + ssappendf(output, "b\t"); + else if (rs == 0 && rt != 0) + ssappendf(output, "beqz\t%s, ",GPR_REG[rt]); + else if (rs != 0 && rt == 0) + ssappendf(output, "beqz\t%s, ",GPR_REG[rs]); + else + ssappendf(output, "beq\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); + + offset_decode(output); +} + +void BNE( std::string& output ) +{ + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == 0 && rt != 0) + ssappendf(output, "bnez\t%s, ",GPR_REG[rt]); + else if (rs != 0 && rt == 0) + ssappendf(output, "bnez\t%s, ",GPR_REG[rs]); + else + ssappendf(output, "bne\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); + + offset_decode(output); +} + void BLEZ( std::string& output ) { _sap("blez\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void BGTZ( std::string& output ) { _sap("bgtz\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void ADDI( std::string& output ) { _sap("addi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED);} @@ -743,8 +774,39 @@ void ORI( std::string& output ) void XORI( std::string& output ) { _sap("xori\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void LUI( std::string& output ) { _sap("lui\t%s, 0x%04X") GPR_REG[DECODE_RT], DECODE_IMMED); } -void BEQL( std::string& output ) { _sap("beql\t%s, %s, ") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); offset_decode(output); } -void BNEL( std::string& output ) { _sap("bnel\t%s, %s, ") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); offset_decode(output); } + +void BEQL( std::string& output ) +{ + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == rt) + ssappendf(output, "b\t"); + else if (rs == 0 && rt != 0) + ssappendf(output, "beqzl\t%s, ",GPR_REG[rt]); + else if (rs != 0 && rt == 0) + ssappendf(output, "beqzl\t%s, ",GPR_REG[rs]); + else + ssappendf(output, "beql\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); + + offset_decode(output); +} + +void BNEL( std::string& output ) +{ + int rs = DECODE_RS; + int rt = DECODE_RT; + + if (rs == 0 && rt != 0) + ssappendf(output, "bnezl\t%s, ",GPR_REG[rt]); + else if (rs != 0 && rt == 0) + ssappendf(output, "bnezl\t%s, ",GPR_REG[rs]); + else + ssappendf(output, "bnel\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); + + offset_decode(output); +} + void BLEZL( std::string& output ) { _sap("blezl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void BGTZL( std::string& output ) { _sap("bgtzl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void DADDI( std::string& output ) { _sap("daddi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } From b72963ee5fb2118b2f65cb3f8e0fec7d7445b36c Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 19 Aug 2014 15:43:38 +0200 Subject: [PATCH 3/5] Make simplifcations in the disassembler optional --- pcsx2/DebugTools/Debug.h | 2 +- pcsx2/DebugTools/DebugInterface.cpp | 8 ++--- pcsx2/DebugTools/DebugInterface.h | 6 ++-- pcsx2/DebugTools/DisR5900asm.cpp | 43 +++++++++++++++---------- pcsx2/DebugTools/DisassemblyManager.cpp | 2 +- pcsx2/Dump.cpp | 2 +- pcsx2/x86/ix86-32/iR5900-32.cpp | 2 +- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/pcsx2/DebugTools/Debug.h b/pcsx2/DebugTools/Debug.h index a421440139..e5b1950287 100644 --- a/pcsx2/DebugTools/Debug.h +++ b/pcsx2/DebugTools/Debug.h @@ -28,7 +28,7 @@ extern char* disVU1MicroLF(u32 code, u32 pc); namespace R5900 { - void disR5900Fasm( std::string& output, u32 code, u32 pc); + void disR5900Fasm( std::string& output, u32 code, u32 pc, bool simplify); extern const char * const GPR_REG[32]; extern const char * const COP0_REG[32]; diff --git a/pcsx2/DebugTools/DebugInterface.cpp b/pcsx2/DebugTools/DebugInterface.cpp index 8d40606792..bd32077467 100644 --- a/pcsx2/DebugTools/DebugInterface.cpp +++ b/pcsx2/DebugTools/DebugInterface.cpp @@ -487,12 +487,12 @@ void R5900DebugInterface::setRegister(int cat, int num, u128 newValue) } } -std::string R5900DebugInterface::disasm(u32 address) +std::string R5900DebugInterface::disasm(u32 address, bool simplify) { std::string out; u32 op = read32(address); - R5900::disR5900Fasm(out,op,address); + R5900::disR5900Fasm(out,op,address,simplify); return out; } @@ -739,12 +739,12 @@ void R3000DebugInterface::setRegister(int cat, int num, u128 newValue) } } -std::string R3000DebugInterface::disasm(u32 address) +std::string R3000DebugInterface::disasm(u32 address, bool simplify) { std::string out; u32 op = read32(address); - R5900::disR5900Fasm(out,op,address); + R5900::disR5900Fasm(out,op,address,simplify); return out; } diff --git a/pcsx2/DebugTools/DebugInterface.h b/pcsx2/DebugTools/DebugInterface.h index 28ffdd3d11..59da9a6753 100644 --- a/pcsx2/DebugTools/DebugInterface.h +++ b/pcsx2/DebugTools/DebugInterface.h @@ -45,7 +45,7 @@ public: virtual void setPc(u32 newPc) = 0; virtual void setRegister(int cat, int num, u128 newValue) = 0; - virtual std::string disasm(u32 address) = 0; + virtual std::string disasm(u32 address, bool simplify) = 0; virtual bool isValidAddress(u32 address) = 0; virtual u32 getCycles() = 0; @@ -83,7 +83,7 @@ public: virtual void setPc(u32 newPc); virtual void setRegister(int cat, int num, u128 newValue); - virtual std::string disasm(u32 address); + virtual std::string disasm(u32 address, bool simplify); virtual bool isValidAddress(u32 address); virtual u32 getCycles(); }; @@ -115,7 +115,7 @@ public: virtual void setPc(u32 newPc); virtual void setRegister(int cat, int num, u128 newValue); - virtual std::string disasm(u32 address); + virtual std::string disasm(u32 address, bool simplify); virtual bool isValidAddress(u32 address); virtual u32 getCycles(); }; diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index e01dc2edb5..4310355e98 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -27,6 +27,7 @@ unsigned long opcode_addr; u32 disasmOpcode; +bool disSimplify; namespace R5900 { @@ -605,10 +606,11 @@ void (*COP2SPECIAL2PrintTable[128])( std::string& output ) = //**************************TABLES CALLS*********************** -void disR5900Fasm( std::string& output, u32 code, u32 pc ) +void disR5900Fasm( std::string& output, u32 code, u32 pc, bool simplify ) { opcode_addr = pc; disasmOpcode = code; + disSimplify = simplify; GetInstruction(code).disasm( output ); } @@ -695,6 +697,13 @@ const char* signedImmediate(s16 imm, int len = 0) { static char buffer[32]; + if (!disSimplify) + { + u16 uimm = imm; + sprintf(buffer,"0x%*X",len,uimm); + return buffer; + } + if (imm >= 0) sprintf(buffer,"0x%*X",len,imm); else @@ -712,11 +721,11 @@ void BEQ( std::string& output ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == rt) + if (disSimplify && rs == rt) ssappendf(output, "b\t"); - else if (rs == 0 && rt != 0) + else if (disSimplify && rs == 0 && rt != 0) ssappendf(output, "beqz\t%s, ",GPR_REG[rt]); - else if (rs != 0 && rt == 0) + else if (disSimplify && rs != 0 && rt == 0) ssappendf(output, "beqz\t%s, ",GPR_REG[rs]); else ssappendf(output, "beq\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); @@ -729,9 +738,9 @@ void BNE( std::string& output ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == 0 && rt != 0) + if (disSimplify && rs == 0 && rt != 0) ssappendf(output, "bnez\t%s, ",GPR_REG[rt]); - else if (rs != 0 && rt == 0) + else if (disSimplify && rs != 0 && rt == 0) ssappendf(output, "bnez\t%s, ",GPR_REG[rs]); else ssappendf(output, "bne\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); @@ -749,7 +758,7 @@ void ADDIU( std::string& output ) int rs = DECODE_RS; s16 imm = DECODE_IMMED; - if (rs == 0) + if (disSimplify && rs == 0) ssappendf(output, "li\t%s, %s",GPR_REG[rt],signedImmediate(imm)); else ssappendf(output, "addiu\t%s, %s, %s",GPR_REG[rt],GPR_REG[rs],signedImmediate(imm)); @@ -766,7 +775,7 @@ void ORI( std::string& output ) u32 unsignedImm = (u16) DECODE_IMMED; - if (rs == 0) + if (disSimplify && rs == 0) ssappendf(output, "li\t%s, 0x%X",GPR_REG[rt],unsignedImm); else ssappendf(output, "ori\t%s, %s, 0x%X",GPR_REG[rt],GPR_REG[rs],unsignedImm); @@ -780,11 +789,11 @@ void BEQL( std::string& output ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == rt) + if (disSimplify && rs == rt) ssappendf(output, "b\t"); - else if (rs == 0 && rt != 0) + else if (disSimplify && rs == 0 && rt != 0) ssappendf(output, "beqzl\t%s, ",GPR_REG[rt]); - else if (rs != 0 && rt == 0) + else if (disSimplify && rs != 0 && rt == 0) ssappendf(output, "beqzl\t%s, ",GPR_REG[rs]); else ssappendf(output, "beql\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); @@ -797,9 +806,9 @@ void BNEL( std::string& output ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == 0 && rt != 0) + if (disSimplify && rs == 0 && rt != 0) ssappendf(output, "bnezl\t%s, ",GPR_REG[rt]); - else if (rs != 0 && rt == 0) + else if (disSimplify && rs != 0 && rt == 0) ssappendf(output, "bnezl\t%s, ",GPR_REG[rs]); else ssappendf(output, "bnel\t%s, %s, ",GPR_REG[rs], GPR_REG[rt]); @@ -883,9 +892,9 @@ void disAddAddu( std::string& output, const char* name ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == 0) + if (disSimplify && rs == 0) ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rt]); - else if (rt == 0) + else if (disSimplify && rt == 0) ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rs]); else ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[rd], GPR_REG[rs], GPR_REG[rt]); @@ -909,9 +918,9 @@ void disDaddDaddu( std::string& output, const char* name ) int rs = DECODE_RS; int rt = DECODE_RT; - if (rs == 0) + if (disSimplify && rs == 0) ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RT]); - else if (rt == 0) + else if (disSimplify && rt == 0) ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RS]); else ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); diff --git a/pcsx2/DebugTools/DisassemblyManager.cpp b/pcsx2/DebugTools/DisassemblyManager.cpp index efa33aa96d..1e8ca71513 100644 --- a/pcsx2/DebugTools/DisassemblyManager.cpp +++ b/pcsx2/DebugTools/DisassemblyManager.cpp @@ -691,7 +691,7 @@ bool DisassemblyOpcode::disassemble(u32 address, DisassemblyLineInfo& dest, bool { char opcode[64],arguments[256]; - std::string dis = cpu->disasm(address); + std::string dis = cpu->disasm(address,insertSymbols); parseDisasm(dis.c_str(),opcode,arguments,insertSymbols); dest.type = DISTYPE_OPCODE; dest.name = opcode; diff --git a/pcsx2/Dump.cpp b/pcsx2/Dump.cpp index e868d7b441..28aff30d98 100644 --- a/pcsx2/Dump.cpp +++ b/pcsx2/Dump.cpp @@ -219,7 +219,7 @@ void iDumpBlock( int startpc, u8 * ptr ) for ( uint i = startpc; i < s_nEndBlock; i += 4 ) { std::string output; - disR5900Fasm( output, memRead32( i ), i ); + disR5900Fasm( output, memRead32( i ), i, false ); eff.Printf( "%s\n", output.c_str() ); } diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index 50f9cd462d..475fe2ccf9 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -1678,7 +1678,7 @@ void recompileNextInstruction(int delayslot) DevCon.Warning("Possible old value used in COP2 code"); for (u32 i = s_pCurBlockEx->startpc; i < s_nEndBlock; i += 4) { - disR5900Fasm(disasm, memRead32(i), i); + disR5900Fasm(disasm, memRead32(i), i,false); DevCon.Warning("%s%08X %s", i == pc - 4 ? "*" : i == p ? "=" : " ", memRead32(i), disasm.c_str()); } break; From d1619af18ccbdfa709feea58b7ebeae3c7f59c15 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 22 Aug 2014 23:28:28 +0200 Subject: [PATCH 4/5] Simplify disassembly of memory access with zero offset --- pcsx2/DebugTools/DisR5900asm.cpp | 76 +++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index 4310355e98..c60b8130a8 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -820,32 +820,58 @@ void BLEZL( std::string& output ) { _sap("blezl\t%s, ") GPR_REG[DECO void BGTZL( std::string& output ) { _sap("bgtzl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void DADDI( std::string& output ) { _sap("daddi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } void DADDIU( std::string& output ) { _sap("daddiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } -void LDL( std::string& output ) { _sap("ldl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LDR( std::string& output ) { _sap("ldr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LB( std::string& output ) { _sap("lb\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LH( std::string& output ) { _sap("lh\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LWL( std::string& output ) { _sap("lwl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LW( std::string& output ) { _sap("lw\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LBU( std::string& output ) { _sap("lbu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LHU( std::string& output ) { _sap("lhu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LWR( std::string& output ) { _sap("lwr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LWU( std::string& output ) { _sap("lwu\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SB( std::string& output ) { _sap("sb\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SH( std::string& output ) { _sap("sh\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SWL( std::string& output ) { _sap("swl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SW( std::string& output ) { _sap("sw\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SDL( std::string& output ) { _sap("sdl\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SDR( std::string& output ) { _sap("sdr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SWR( std::string& output ) { _sap("swr\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LD( std::string& output ) { _sap("ld\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SD( std::string& output ) { _sap("sd\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LQ( std::string& output ) { _sap("lq\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SQ( std::string& output ) { _sap("sq\t%s, %s(%s)") GPR_REG[DECODE_RT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SWC1( std::string& output ) { _sap("swc1\t%s, %s(%s)") COP1_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void SQC2( std::string& output ) { _sap("sqc2\t%s, %s(%s)") COP2_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } + +void disMemAccess( std::string& output, const char* name, int cop = 0) +{ + const char* rt; + switch (cop) + { + case 0: + rt = GPR_REG[DECODE_RT]; + break; + case 1: + rt = COP1_REG_FP[DECODE_FT]; + break; + case 2: + rt = COP2_REG_FP[DECODE_FT]; + break; + } + + const char* rs = GPR_REG[DECODE_RS]; + s16 imm = DECODE_IMMED; + + if (disSimplify && imm == 0) + ssappendf(output, "%s\t%s,(%s)",name,rt,rs); + else + ssappendf(output, "%s\t%s, %s(%s)",name,rt,signedImmediate(imm,4),rs); +} + +void LDL( std::string& output ) { disMemAccess(output,"ldl"); } +void LDR( std::string& output ) { disMemAccess(output,"ldr"); } +void LB( std::string& output ) { disMemAccess(output,"lb"); } +void LH( std::string& output ) { disMemAccess(output,"lh"); } +void LWL( std::string& output ) { disMemAccess(output,"lwl"); } +void LW( std::string& output ) { disMemAccess(output,"lw"); } +void LBU( std::string& output ) { disMemAccess(output,"lbu"); } +void LHU( std::string& output ) { disMemAccess(output,"lhu"); } +void LWR( std::string& output ) { disMemAccess(output,"lwr"); } +void LWU( std::string& output ) { disMemAccess(output,"lwu"); } +void SB( std::string& output ) { disMemAccess(output,"sb"); } +void SH( std::string& output ) { disMemAccess(output,"sh"); } +void SWL( std::string& output ) { disMemAccess(output,"swl"); } +void SW( std::string& output ) { disMemAccess(output,"sw"); } +void SDL( std::string& output ) { disMemAccess(output,"sdl"); } +void SDR( std::string& output ) { disMemAccess(output,"sdr"); } +void SWR( std::string& output ) { disMemAccess(output,"swr"); } +void LD( std::string& output ) { disMemAccess(output,"ld"); } +void SD( std::string& output ) { disMemAccess(output,"sd"); } +void LQ( std::string& output ) { disMemAccess(output,"lq"); } +void SQ( std::string& output ) { disMemAccess(output,"sq"); } +void SWC1( std::string& output ) { disMemAccess(output,"swc1",1); } +void SQC2( std::string& output ) { disMemAccess(output,"sqc2",2); } void PREF( std::string& output ) { output += "pref ---"; /*_sap("PREF\t%s, 0x%04X(%s)") GPR_REG[DECODE_RT], DECODE_IMMED, GPR_REG[RS]); */} -void LWC1( std::string& output ) { _sap("lwc1\t%s, %s(%s)") COP1_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } -void LQC2( std::string& output ) { _sap("lqc2\t%s, %s(%s)") COP2_REG_FP[DECODE_FT], signedImmediate(DECODE_IMMED,4), GPR_REG[DECODE_RS]); } +void LWC1( std::string& output ) { disMemAccess(output,"lwc1",1); } +void LQC2( std::string& output ) { disMemAccess(output,"lqc2",2); } //********************END OF STANDARD OPCODES************************* void SLL( std::string& output ) From 259a6996137cceb2fe4e4f9e8bb40dcfdf728ec1 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 22 Aug 2014 23:28:32 +0200 Subject: [PATCH 5/5] Add shared source and dest register simplifications --- pcsx2/DebugTools/DisR5900asm.cpp | 93 ++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index c60b8130a8..0fb17687a9 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -693,17 +693,10 @@ void COP1_Unknown( std::string& output ) // the copy-paste marathon of code below more readable! #define _sap( str ) ssappendf( output, str, -const char* signedImmediate(s16 imm, int len = 0) +const char* signedImmediate(s32 imm, int len = 0) { static char buffer[32]; - if (!disSimplify) - { - u16 uimm = imm; - sprintf(buffer,"0x%*X",len,uimm); - return buffer; - } - if (imm >= 0) sprintf(buffer,"0x%*X",len,imm); else @@ -712,6 +705,18 @@ const char* signedImmediate(s16 imm, int len = 0) return buffer; } +const char* disDestSource(int dest, int source) +{ + static char buffer[32]; + + if (disSimplify && dest == source) + sprintf(buffer,"%s",GPR_REG[dest]); + else + sprintf(buffer,"%s,%s",GPR_REG[dest],GPR_REG[source]); + + return buffer; +} + //********************* Standard Opcodes*********************** void J( std::string& output ) { output += "j\t"; jump_decode(output);} void JAL( std::string& output ) { output += "jal\t"; jump_decode(output);} @@ -761,12 +766,12 @@ void ADDIU( std::string& output ) if (disSimplify && rs == 0) ssappendf(output, "li\t%s, %s",GPR_REG[rt],signedImmediate(imm)); else - ssappendf(output, "addiu\t%s, %s, %s",GPR_REG[rt],GPR_REG[rs],signedImmediate(imm)); + ssappendf(output, "addiu\t%s, %s",disDestSource(rt,rs),signedImmediate(imm)); } -void SLTI( std::string& output ) { _sap("slti\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } -void SLTIU( std::string& output ) { _sap("sltiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } -void ANDI( std::string& output ) { _sap("andi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED);} +void SLTI( std::string& output ) { _sap("slti\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED); } +void SLTIU( std::string& output ) { _sap("sltiu\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED); } +void ANDI( std::string& output ) { _sap("andi\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED);} void ORI( std::string& output ) { @@ -778,10 +783,10 @@ void ORI( std::string& output ) if (disSimplify && rs == 0) ssappendf(output, "li\t%s, 0x%X",GPR_REG[rt],unsignedImm); else - ssappendf(output, "ori\t%s, %s, 0x%X",GPR_REG[rt],GPR_REG[rs],unsignedImm); + ssappendf(output, "ori\t%s, 0x%X",disDestSource(DECODE_RT, DECODE_RS),unsignedImm); } -void XORI( std::string& output ) { _sap("xori\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } +void XORI( std::string& output ) { _sap("xori\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED); } void LUI( std::string& output ) { _sap("lui\t%s, 0x%04X") GPR_REG[DECODE_RT], DECODE_IMMED); } void BEQL( std::string& output ) @@ -818,8 +823,8 @@ void BNEL( std::string& output ) void BLEZL( std::string& output ) { _sap("blezl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } void BGTZL( std::string& output ) { _sap("bgtzl\t%s, ") GPR_REG[DECODE_RS]); offset_decode(output); } -void DADDI( std::string& output ) { _sap("daddi\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } -void DADDIU( std::string& output ) { _sap("daddiu\t%s, %s, 0x%04X") GPR_REG[DECODE_RT], GPR_REG[DECODE_RS], DECODE_IMMED); } +void DADDI( std::string& output ) { _sap("daddi\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED); } +void DADDIU( std::string& output ) { _sap("daddiu\t%s, 0x%04X") disDestSource(DECODE_RT, DECODE_RS), DECODE_IMMED); } void disMemAccess( std::string& output, const char* name, int cop = 0) { @@ -882,11 +887,11 @@ void SLL( std::string& output ) _sap("sll\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void SRL( std::string& output ) { _sap("srl\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void SRA( std::string& output ) { _sap("sra\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void SLLV( std::string& output ) { _sap("sllv\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]); } -void SRLV( std::string& output ) { _sap("srlv\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]);} -void SRAV( std::string& output ) { _sap("srav\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]); } +void SRL( std::string& output ) { _sap("srl\t%s, 0x%02X") disDestSource(DECODE_RD, DECODE_RT), DECODE_SA); } +void SRA( std::string& output ) { _sap("sra\t%s, 0x%02X") disDestSource(DECODE_RD, DECODE_RT), DECODE_SA); } +void SLLV( std::string& output ) { _sap("sllv\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]); } +void SRLV( std::string& output ) { _sap("srlv\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]);} +void SRAV( std::string& output ) { _sap("srav\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]); } void JR( std::string& output ) { _sap("jr\t->%s") GPR_REG[DECODE_RS]); } void JALR( std::string& output ) @@ -904,9 +909,9 @@ void MFHI( std::string& output ) { _sap("mfhi\t%s") GPR_REG[DECODE_R void MTHI( std::string& output ) { _sap("mthi\t%s") GPR_REG[DECODE_RS]); } void MFLO( std::string& output ) { _sap("mflo\t%s") GPR_REG[DECODE_RD]); } void MTLO( std::string& output ) { _sap("mtlo\t%s") GPR_REG[DECODE_RS]); } -void DSLLV( std::string& output ) { _sap("dsllv\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]); } -void DSRLV( std::string& output ) { _sap("dsrlv\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]); } -void DSRAV( std::string& output ) { _sap("dsrav\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], GPR_REG[DECODE_RS]); } +void DSLLV( std::string& output ) { _sap("dsllv\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]); } +void DSRLV( std::string& output ) { _sap("dsrlv\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]); } +void DSRAV( std::string& output ) { _sap("dsrav\t%s, %s") disDestSource(DECODE_RD, DECODE_RT), GPR_REG[DECODE_RS]); } void MULT( std::string& output ) { _sap("mult\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]);} void MULTU( std::string& output ) { _sap("multu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]);} void DIV( std::string& output ) { _sap("div\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } @@ -922,6 +927,10 @@ void disAddAddu( std::string& output, const char* name ) ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rt]); else if (disSimplify && rt == 0) ssappendf(output,"move\t%s, %s",GPR_REG[rd],GPR_REG[rs]); + else if (disSimplify && rd == rs) + ssappendf(output, "%s\t%s, %s",name,GPR_REG[rd],GPR_REG[rt]); + else if (disSimplify && rd == rt) + ssappendf(output, "%s\t%s, %s",name,GPR_REG[rd],GPR_REG[rs]); else ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[rd], GPR_REG[rs], GPR_REG[rt]); } @@ -929,14 +938,14 @@ void disAddAddu( std::string& output, const char* name ) void ADD( std::string& output ) { disAddAddu(output,"add"); } void ADDU( std::string& output ) { disAddAddu(output,"addu"); } -void SUB( std::string& output ) { _sap("sub\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void SUBU( std::string& output ) { _sap("subu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void AND( std::string& output ) { _sap("and\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void OR( std::string& output ) { _sap("or\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void XOR( std::string& output ) { _sap("xor\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void NOR( std::string& output ) { _sap("nor\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void SLT( std::string& output ) { _sap("slt\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void SLTU( std::string& output ) { _sap("sltu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } +void SUB( std::string& output ) { _sap("sub\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void SUBU( std::string& output ) { _sap("subu\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void AND( std::string& output ) { _sap("and\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void OR( std::string& output ) { _sap("or\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void XOR( std::string& output ) { _sap("xor\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void NOR( std::string& output ) { _sap("nor\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void SLT( std::string& output ) { _sap("slt\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void SLTU( std::string& output ) { _sap("sltu\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } void disDaddDaddu( std::string& output, const char* name ) { @@ -948,6 +957,10 @@ void disDaddDaddu( std::string& output, const char* name ) ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RT]); else if (disSimplify && rt == 0) ssappendf(output,"dmove\t%s, %s",GPR_REG[DECODE_RD],GPR_REG[DECODE_RS]); + else if (disSimplify && rd == rs) + ssappendf(output, "%s\t%s, %s",name,GPR_REG[rd],GPR_REG[rt]); + else if (disSimplify && rd == rt) + ssappendf(output, "%s\t%s, %s",name,GPR_REG[rd],GPR_REG[rs]); else ssappendf(output, "%s\t%s, %s, %s",name,GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } @@ -955,20 +968,20 @@ void disDaddDaddu( std::string& output, const char* name ) void DADD( std::string& output ) { disDaddDaddu(output,"dadd"); } void DADDU( std::string& output ) { disDaddDaddu(output,"daddu"); } -void DSUB( std::string& output ) { _sap("dsub\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void DSUBU( std::string& output ) { _sap("dsubu\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } +void DSUB( std::string& output ) { _sap("dsub\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } +void DSUBU( std::string& output ) { _sap("dsubu\t%s, %s") disDestSource(DECODE_RD,DECODE_RS), GPR_REG[DECODE_RT]); } void TGE( std::string& output ) { _sap("tge\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TGEU( std::string& output ) { _sap("tgeu\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TLT( std::string& output ) { _sap("tlt\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TLTU( std::string& output ) { _sap("tltu\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TEQ( std::string& output ) { _sap("teq\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void TNE( std::string& output ) { _sap("tne\t%s, %s") GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } -void DSLL( std::string& output ) { _sap("dsll\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void DSRL( std::string& output ) { _sap("dsrl\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void DSRA( std::string& output ) { _sap("dsra\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void DSLL32( std::string& output ) { _sap("dsll32\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void DSRL32( std::string& output ) { _sap("dsrl32\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } -void DSRA32( std::string& output ) { _sap("dsra32\t%s, %s, 0x%02X") GPR_REG[DECODE_RD], GPR_REG[DECODE_RT], DECODE_SA); } +void DSLL( std::string& output ) { _sap("dsll\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } +void DSRL( std::string& output ) { _sap("dsrl\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } +void DSRA( std::string& output ) { _sap("dsra\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } +void DSLL32( std::string& output ) { _sap("dsll32\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } +void DSRL32( std::string& output ) { _sap("dsrl32\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } +void DSRA32( std::string& output ) { _sap("dsra32\t%s, 0x%02X") disDestSource(DECODE_RD,DECODE_RT), DECODE_SA); } void MOVZ( std::string& output ) { _sap("movz\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void MOVN( std::string& output ) { _sap("movn\t%s, %s, %s") GPR_REG[DECODE_RD], GPR_REG[DECODE_RS], GPR_REG[DECODE_RT]); } void MFSA( std::string& output ) { _sap("mfsa\t%s") GPR_REG[DECODE_RD]);}