diff --git a/cstool/cstool.c b/cstool/cstool.c index 7e6347d99..9cd948171 100644 --- a/cstool/cstool.c +++ b/cstool/cstool.c @@ -105,6 +105,7 @@ static struct { { "sh4abe", CS_ARCH_SH, CS_MODE_BIG_ENDIAN | CS_MODE_SH4A | CS_MODE_SHFPU }, { "sh4al-dsp", CS_ARCH_SH, CS_MODE_LITTLE_ENDIAN | CS_MODE_SH4A | CS_MODE_SHDSP | CS_MODE_SHFPU }, { "sh4al-dspbe", CS_ARCH_SH, CS_MODE_BIG_ENDIAN | CS_MODE_SH4A | CS_MODE_SHDSP | CS_MODE_SHFPU}, + {"tricore", CS_ARCH_TRICORE, CS_MODE_TRICORE}, { NULL } }; @@ -126,6 +127,7 @@ void print_insn_detail_wasm(csh handle, cs_insn *ins); void print_insn_detail_mos65xx(csh handle, cs_insn *ins); void print_insn_detail_bpf(csh handle, cs_insn *ins); void print_insn_detail_sh(csh handle, cs_insn *ins); +void print_insn_detail_tricore(csh handle, cs_insn *ins); static void print_details(csh handle, cs_arch arch, cs_mode md, cs_insn *ins); @@ -319,6 +321,10 @@ static void usage(char *prog) printf(" sh4al-dspbe superh SH4AL-DSP big endian\n"); } + if (cs_support(CS_ARCH_TRICORE)) { + printf(" tricore tricore\n"); + } + printf("\nExtra options:\n"); printf(" -d show detailed information of the instructions\n"); printf(" -s decode in SKIPDATA mode\n"); @@ -506,6 +512,10 @@ int main(int argc, char **argv) printf("x86_reduce=1 "); } + if (cs_support(CS_ARCH_TRICORE)) { + printf("tricore=1 "); + } + printf("\n"); return 0; case 'h': diff --git a/cstool/cstool_tricore.c b/cstool/cstool_tricore.c new file mode 100644 index 000000000..282fa0636 --- /dev/null +++ b/cstool/cstool_tricore.c @@ -0,0 +1,65 @@ +#include +#include + +#include + +void print_insn_detail_tricore(csh handle, cs_insn *ins) +{ + cs_tricore *tricore; + int i; + cs_regs regs_read, regs_write; + uint8_t regs_read_count, regs_write_count; + + // detail can be NULL on "data" instruction if SKIPDATA option is turned ON + if (ins->detail == NULL) + return; + + tricore = &(ins->detail->tricore); + + if (tricore->op_count) + printf("\top_count: %u\n", tricore->op_count); + + for (i = 0; i < tricore->op_count; i++) { + cs_tricore_op *op = &(tricore->operands[i]); + switch ((int)op->type) { + default: + break; + case TRICORE_OP_REG: + printf("\t\toperands[%u].type: REG = %s\n", i, + cs_reg_name(handle, op->reg)); + break; + case TRICORE_OP_IMM: + printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm); + break; + case TRICORE_OP_MEM: + printf("\t\toperands[%u].type: MEM\n", i); + if (op->mem.base != TriCore_REG_INVALID) + printf("\t\t\toperands[%u].mem.base: REG = %s\n", i, + cs_reg_name(handle, op->mem.base)); + if (op->mem.disp != 0) + printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp); + break; + } + + // Print out all registers accessed by this instruction (either implicit or + // explicit) + if (!cs_regs_access(handle, ins, regs_read, ®s_read_count, regs_write, + ®s_write_count)) { + if (regs_read_count) { + printf("\tRegisters read:"); + for (i = 0; i < regs_read_count; i++) { + printf(" %s", cs_reg_name(handle, regs_read[i])); + } + printf("\n"); + } + + if (regs_write_count) { + printf("\tRegisters modified:"); + for (i = 0; i < regs_write_count; i++) { + printf(" %s", cs_reg_name(handle, regs_write[i])); + } + printf("\n"); + } + } + } +} \ No newline at end of file