diff --git a/arch/TriCore/TriCoreDisassembler.c b/arch/TriCore/TriCoreDisassembler.c index bc07be5b4..7a3bf25f1 100644 --- a/arch/TriCore/TriCoreDisassembler.c +++ b/arch/TriCore/TriCoreDisassembler.c @@ -12,7 +12,7 @@ #ifdef CAPSTONE_HAS_TRICORE -#include // DEBUG +#include // DEBUG #include #include @@ -26,25 +26,22 @@ #include "../../MCDisassembler.h" #include "../../MathExtras.h" -static uint64_t getFeatureBits(int mode) -{ +static uint64_t getFeatureBits(int mode) { // support everything - return (uint64_t)-1; + return (uint64_t) -1; } -static bool readInstruction16(const uint8_t *code, size_t code_len, uint16_t *insn) -{ +static bool readInstruction16(const uint8_t *code, size_t code_len, uint16_t *insn) { if (code_len < 2) // insufficient data return false; // Encoded as a little-endian 16-bit word in the stream. - *insn = (code[0] << 0) | (code[1] << 8); + *insn = (code[0] << 0) | (code[1] << 8); return true; } -static bool readInstruction32(const uint8_t *code, size_t code_len, uint32_t *insn) -{ +static bool readInstruction32(const uint8_t *code, size_t code_len, uint32_t *insn) { if (code_len < 4) // insufficient data return false; @@ -54,105 +51,126 @@ static bool readInstruction32(const uint8_t *code, size_t code_len, uint32_t *in return true; } -static unsigned getReg(MCRegisterInfo *MRI, unsigned RC, unsigned RegNo) -{ +static unsigned getReg(MCRegisterInfo *MRI, unsigned RC, unsigned RegNo) { const MCRegisterClass *rc = MCRegisterInfo_getRegClass(MRI, RC); return rc->RegsBegin[RegNo]; } static DecodeStatus DecodeDataRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeExtRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodePairAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSBInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSBRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSRCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeBInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder); + uint64_t Address, void *Decoder); static DecodeStatus DecodeSLRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSLROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSRRSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSBCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSSRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeSYSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRRR2Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeBITInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRCRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRRRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRCRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeBRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeBRCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeABSBInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeRCRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); + static DecodeStatus DecodeBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder); #include "TriCoreGenDisassemblerTables.inc" #define GET_REGINFO_ENUM #define GET_REGINFO_MC_DESC + #include "TriCoreGenRegisterInfo.inc" static DecodeStatus DecodeDataRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned Reg; if (RegNo > 15) @@ -165,8 +183,7 @@ static DecodeStatus DecodeDataRegsRegisterClass(MCInst *Inst, unsigned RegNo, } static DecodeStatus DecodeAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned Reg; if (RegNo > 15) @@ -179,8 +196,7 @@ static DecodeStatus DecodeAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo, } static DecodeStatus DecodeExtRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned Reg; unsigned RegHalfNo = RegNo / 2; @@ -194,8 +210,7 @@ static DecodeStatus DecodeExtRegsRegisterClass(MCInst *Inst, unsigned RegNo, } static DecodeStatus DecodePairAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned Reg; unsigned RegHalfNo = RegNo / 2; @@ -209,15 +224,15 @@ static DecodeStatus DecodePairAddrRegsRegisterClass(MCInst *Inst, unsigned RegNo } #define GET_INSTRINFO_ENUM + #include "TriCoreGenInstrInfo.inc" static DecodeStatus DecodeSBInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned disp8 = fieldFromInstruction_4(Insn, 8, 8); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode disp8. @@ -227,14 +242,13 @@ static DecodeStatus DecodeSBInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeSBRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); unsigned disp4 = fieldFromInstruction_4(Insn, 8, 4); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode s2. @@ -249,12 +263,11 @@ static DecodeStatus DecodeSBRInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeSCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned const8 = fieldFromInstruction_4(Insn, 8, 8); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode const8. @@ -264,13 +277,12 @@ static DecodeStatus DecodeSCInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeSRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode s1/d. @@ -285,18 +297,17 @@ static DecodeStatus DecodeSRInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeSRCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned const4 = fieldFromInstruction_4(Insn, 12, 4); unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode s1/d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_ADD_src: status = DecodeDataRegsRegisterClass(Inst, s1_d, Address, Decoder); if (status == MCDisassembler_Success) @@ -316,18 +327,17 @@ static DecodeStatus DecodeSRCInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(is32Bit) // This instruction is 16-bit + if (is32Bit) // This instruction is 16-bit return MCDisassembler_Fail; // Decode s1/d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_MOV_AA_srr: status = DecodeAddrRegsRegisterClass(Inst, s1_d, Address, Decoder); break; @@ -349,7 +359,7 @@ static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn, // Decode s2. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_MOV_AA_srr: status = DecodeAddrRegsRegisterClass(Inst, s2, Address, Decoder); break; @@ -364,8 +374,7 @@ static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned off18_0 = fieldFromInstruction_4(Insn, 16, 6); @@ -373,12 +382,12 @@ static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn, unsigned off18_2 = fieldFromInstruction_4(Insn, 22, 4); unsigned off18_3 = fieldFromInstruction_4(Insn, 12, 4); unsigned off18 = (off18_0 << 0) | (off18_1 << 6) | - (off18_2 << 10) | (off18_3 << 14); + (off18_2 << 10) | (off18_3 << 14); unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode s1_d. @@ -409,15 +418,14 @@ static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeBInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { unsigned disp24_0 = fieldFromInstruction_4(Insn, 16, 16); unsigned disp24_1 = fieldFromInstruction_4(Insn, 8, 8); unsigned disp24 = (disp24_0 << 0) | (disp24_1 << 16); unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode disp24. @@ -427,8 +435,7 @@ static DecodeStatus DecodeBInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned off10_0 = fieldFromInstruction_4(Insn, 16, 6); unsigned off10_1 = fieldFromInstruction_4(Insn, 28, 4); @@ -439,11 +446,11 @@ static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode s1_d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_LD_A_bo_bso: case TriCore_LD_A_bo_pre: case TriCore_LD_A_bo_pos: @@ -488,7 +495,7 @@ static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn, return status; // Decode s2. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_LD_B_bo_c: case TriCore_LD_BU_bo_c: case TriCore_LD_H_bo_c: @@ -535,8 +542,7 @@ static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned off16_0 = fieldFromInstruction_4(Insn, 16, 6); unsigned off16_1 = fieldFromInstruction_4(Insn, 22, 6); @@ -548,11 +554,11 @@ static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode s1_d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_LD_A_bol: status = DecodeAddrRegsRegisterClass(Inst, s1_d, Address, Decoder); break; @@ -575,8 +581,7 @@ static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned const9 = fieldFromInstruction_4(Insn, 12, 9); @@ -584,11 +589,11 @@ static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit - return MCDisassembler_Fail; + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; // Decode d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_AND_EQ_rc: case TriCore_AND_NE_rc: case TriCore_AND_LT_rc: @@ -630,8 +635,7 @@ static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned pos = fieldFromInstruction_4(Insn, 23, 5); @@ -641,7 +645,7 @@ static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode d. @@ -667,8 +671,7 @@ static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned const16 = fieldFromInstruction_4(Insn, 12, 16); @@ -676,7 +679,7 @@ static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode d. @@ -685,7 +688,7 @@ static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn, return status; // Decode s1. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { default: status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); break; @@ -705,8 +708,7 @@ static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned n = fieldFromInstruction_4(Insn, 16, 2); @@ -715,11 +717,11 @@ static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode d. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_ADD_A_rr: case TriCore_SUB_A_rr: case TriCore_MOV_A_rr: @@ -756,7 +758,7 @@ static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, return status; // Decode s1. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_ADD_A_rr: case TriCore_SUB_A_rr: status = DecodeAddrRegsRegisterClass(Inst, s1, Address, Decoder); @@ -769,7 +771,7 @@ static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, return status; // Decode s2. - switch(MCInst_getOpcode(Inst)) { + switch (MCInst_getOpcode(Inst)) { case TriCore_ADD_A_rr: case TriCore_SUB_A_rr: case TriCore_MOV_D_rr: @@ -790,8 +792,7 @@ static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); @@ -799,7 +800,7 @@ static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode d. @@ -821,8 +822,7 @@ static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn, } static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn, - uint64_t Address, void *Decoder) -{ + uint64_t Address, void *Decoder) { DecodeStatus status; unsigned d = fieldFromInstruction_4(Insn, 28, 4); unsigned pos = fieldFromInstruction_4(Insn, 23, 5); @@ -832,7 +832,7 @@ static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn, unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); - if(!is32Bit) // This instruction is 32-bit + if (!is32Bit) // This instruction is 32-bit return MCDisassembler_Fail; // Decode d. @@ -859,104 +859,645 @@ static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn, return MCDisassembler_Success; } -static DecodeStatus DecodeSLRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; +static DecodeStatus DecodeSLRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned d = fieldFromInstruction_2(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeSLROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSLROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned d = fieldFromInstruction_2(Insn, 8, 4); + unsigned off4 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode off4. + MCOperand_CreateImm0(Inst, off4); + + return MCDisassembler_Success; } -static DecodeStatus DecodeSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned off4 = fieldFromInstruction_2(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode off4. + MCOperand_CreateImm0(Inst, off4); + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeSRRSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSRRSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned n = fieldFromInstruction_2(Insn, 6, 2); + unsigned s1_d = fieldFromInstruction_2(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + // Decode s1_d. + status = DecodeDataRegsRegisterClass(Inst, s1_d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + return MCDisassembler_Success; } -static DecodeStatus DecodeSBCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSBCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned disp4 = fieldFromInstruction_2(Insn, 8, 4); + unsigned const4 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode disp4. + MCOperand_CreateImm0(Inst, disp4); + + // Decode const4. + MCOperand_CreateImm0(Inst, const4); + + return MCDisassembler_Success; } -static DecodeStatus DecodeSBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned disp4 = fieldFromInstruction_2(Insn, 8, 4); + unsigned n = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode disp4. + MCOperand_CreateImm0(Inst, disp4); + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + return MCDisassembler_Success; } -static DecodeStatus DecodeSSRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSSRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_2(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeSSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeSSROInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_2(Insn, 8, 4); + unsigned off4 = fieldFromInstruction_2(Insn, 12, 4); + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (is32Bit) // This instruction is 16-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode off4. + MCOperand_CreateImm0(Inst, off4); + + return MCDisassembler_Success; } -static DecodeStatus DecodeSYSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +/// 32-bit Opcode Format + +static DecodeStatus DecodeSYSInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1_d. + status = DecodeDataRegsRegisterClass(Inst, s1_d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRRR2Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRRR2Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned n = fieldFromInstruction_4(Insn, 16, 2); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeBITInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeBITInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned pos1 = fieldFromInstruction_4(Insn, 16, 5); + unsigned pos2 = fieldFromInstruction_4(Insn, 23, 5); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode pos1. + MCOperand_CreateImm0(Inst, pos1); + + // Decode pos2. + MCOperand_CreateImm0(Inst, pos2); + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRR1Instruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned n = fieldFromInstruction_4(Insn, 16, 2); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRCRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRCRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned const9 = fieldFromInstruction_4(Insn, 12, 9); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode const9. + MCOperand_CreateImm0(Inst, const9); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRRRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRRRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned width = fieldFromInstruction_4(Insn, 16, 5); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode width. + MCOperand_CreateImm0(Inst, width); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRCRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRCRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned const4 = fieldFromInstruction_4(Insn, 12, 4); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode const4. + MCOperand_CreateImm0(Inst, const4); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeRRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeBRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeBRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode disp15. + MCOperand_CreateImm0(Inst, disp15); + + return MCDisassembler_Success; } -static DecodeStatus DecodeBRCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeBRCInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned const4 = fieldFromInstruction_4(Insn, 12, 4); + unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode const4. + MCOperand_CreateImm0(Inst, const4); + + // Decode disp15. + MCOperand_CreateImm0(Inst, disp15); + + return MCDisassembler_Success; } -static DecodeStatus DecodeRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRRRInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned s2 = fieldFromInstruction_4(Insn, 12, 4); + unsigned n = fieldFromInstruction_4(Insn, 16, 2); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode s2. + status = DecodeDataRegsRegisterClass(Inst, s2, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeABSBInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeABSBInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4); + + unsigned off18_0_5 = fieldFromInstruction_4(Insn, 16, 6); + unsigned off18_6_9 = fieldFromInstruction_4(Insn, 28, 4); + unsigned off18_10_13 = fieldFromInstruction_4(Insn, 22, 4); + unsigned off18_14_17 = fieldFromInstruction_4(Insn, 12, 4); + unsigned off18 = (off18_0_5 << 0) | (off18_6_9 << 6) | + (off18_10_13 << 10) | (off18_14_17 << 14); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1_d. + status = DecodeDataRegsRegisterClass(Inst, s1_d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode off18. + MCOperand_CreateImm0(Inst, off18); + + return MCDisassembler_Success; } -static DecodeStatus DecodeRCRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeRCRWInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + unsigned const4 = fieldFromInstruction_4(Insn, 12, 4); + unsigned width = fieldFromInstruction_4(Insn, 16, 5); + unsigned s3 = fieldFromInstruction_4(Insn, 24, 4); + unsigned d = fieldFromInstruction_4(Insn, 28, 4); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode const4. + MCOperand_CreateImm0(Inst, const4); + + // Decode width. + MCOperand_CreateImm0(Inst, width); + + // Decode s3. + status = DecodeDataRegsRegisterClass(Inst, s3, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode d. + status = DecodeDataRegsRegisterClass(Inst, d, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + return MCDisassembler_Success; } -static DecodeStatus DecodeBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder){ - // TODO: DecodeBRNInstruction - return MCDisassembler_Fail; + +static DecodeStatus DecodeBRNInstruction(MCInst *Inst, unsigned Insn, uint64_t Address, void *Decoder) { + DecodeStatus status = MCDisassembler_Fail; + unsigned s1 = fieldFromInstruction_4(Insn, 8, 4); + + unsigned n_0_3 = fieldFromInstruction_4(Insn, 12, 4); + unsigned n_4 = fieldFromInstruction_4(Insn, 7, 1); + unsigned n = (n_0_3 << 0) | (n_4 << 4); + + unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15); + + unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1); + if (!is32Bit) // This instruction is 32-bit + return MCDisassembler_Fail; + + // Decode s1. + status = DecodeDataRegsRegisterClass(Inst, s1, Address, Decoder); + if (status != MCDisassembler_Success) + return status; + + // Decode n. + MCOperand_CreateImm0(Inst, n); + + // Decode disp15. + MCOperand_CreateImm0(Inst, disp15); + + return MCDisassembler_Success; } #define GET_SUBTARGETINFO_ENUM + #include "TriCoreGenInstrInfo.inc" + bool TriCore_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *MI, - uint16_t *size, uint64_t address, void *info) -{ + uint16_t *size, uint64_t address, void *info) { uint16_t insn16; uint32_t insn32; DecodeStatus Result; @@ -990,8 +1531,7 @@ bool TriCore_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst return false; } -void TriCore_init(MCRegisterInfo *MRI) -{ +void TriCore_init(MCRegisterInfo *MRI) { /* InitMCRegisterInfo(TriCoreRegDesc, 45, RA, PC, TriCoreMCRegisterClasses, 4, @@ -1007,13 +1547,13 @@ void TriCore_init(MCRegisterInfo *MRI) MCRegisterInfo_InitMCRegisterInfo(MRI, TriCoreRegDesc, 53, - 0, 0, - TriCoreMCRegisterClasses, 5, - 0, 0, - TriCoreRegDiffLists, - 0, - TriCoreSubRegIdxLists, 1, - 0); + 0, 0, + TriCoreMCRegisterClasses, 5, + 0, 0, + TriCoreRegDiffLists, + 0, + TriCoreSubRegIdxLists, 1, + 0); } #endif