| 1 | /* Capstone Disassembler Engine */ |
| 2 | /* By Fotis Loukos <[email protected]>, 2017 */ |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <capstone/capstone.h> |
| 6 | #include "cstool.h" |
| 7 | |
| 8 | void print_insn_detail_tms320c64x(csh handle, cs_insn *ins) |
| 9 | { |
| 10 | cs_tms320c64x *tms320c64x; |
| 11 | int i; |
| 12 | |
| 13 | // detail can be NULL on "data" instruction if SKIPDATA option is turned ON |
| 14 | if (ins->detail == NULL) |
| 15 | return; |
| 16 | |
| 17 | tms320c64x = &(ins->detail->tms320c64x); |
| 18 | if (tms320c64x->op_count) |
| 19 | printf("\top_count: %u\n", tms320c64x->op_count); |
| 20 | |
| 21 | for (i = 0; i < tms320c64x->op_count; i++) { |
| 22 | cs_tms320c64x_op *op = &(tms320c64x->operands[i]); |
| 23 | switch((int)op->type) { |
| 24 | default: |
| 25 | break; |
| 26 | case TMS320C64X_OP_REG: |
| 27 | printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg)); |
| 28 | break; |
| 29 | case TMS320C64X_OP_IMM: |
| 30 | printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm); |
| 31 | break; |
| 32 | case TMS320C64X_OP_MEM: |
| 33 | printf("\t\toperands[%u].type: MEM\n", i); |
| 34 | if (op->mem.base != TMS320C64X_REG_INVALID) |
| 35 | printf("\t\t\toperands[%u].mem.base: REG = %s\n", |
| 36 | i, cs_reg_name(handle, op->mem.base)); |
| 37 | printf("\t\t\toperands[%u].mem.disptype: ", i); |
| 38 | if(op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) { |
| 39 | printf("Invalid\n"); |
| 40 | printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp); |
| 41 | } |
| 42 | if(op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) { |
| 43 | printf("Constant\n"); |
| 44 | printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp); |
| 45 | } |
| 46 | if(op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) { |
| 47 | printf("Register\n"); |
| 48 | printf("\t\t\toperands[%u].mem.disp: %s\n", i, cs_reg_name(handle, op->mem.disp)); |
| 49 | } |
| 50 | printf("\t\t\toperands[%u].mem.unit: %u\n", i, op->mem.unit); |
| 51 | printf("\t\t\toperands[%u].mem.direction: ", i); |
| 52 | if(op->mem.direction == TMS320C64X_MEM_DIR_INVALID) |
| 53 | printf("Invalid\n"); |
| 54 | if(op->mem.direction == TMS320C64X_MEM_DIR_FW) |
| 55 | printf("Forward\n"); |
| 56 | if(op->mem.direction == TMS320C64X_MEM_DIR_BW) |
| 57 | printf("Backward\n"); |
| 58 | printf("\t\t\toperands[%u].mem.modify: ", i); |
| 59 | if(op->mem.modify == TMS320C64X_MEM_MOD_INVALID) |
| 60 | printf("Invalid\n"); |
| 61 | if(op->mem.modify == TMS320C64X_MEM_MOD_NO) |
| 62 | printf("No\n"); |
| 63 | if(op->mem.modify == TMS320C64X_MEM_MOD_PRE) |
| 64 | printf("Pre\n"); |
| 65 | if(op->mem.modify == TMS320C64X_MEM_MOD_POST) |
| 66 | printf("Post\n"); |
| 67 | printf("\t\t\toperands[%u].mem.scaled: %u\n", i, op->mem.scaled); |
| 68 | |
| 69 | break; |
| 70 | case TMS320C64X_OP_REGPAIR: |
| 71 | printf("\t\toperands[%u].type: REGPAIR = %s:%s\n", i, cs_reg_name(handle, op->reg + 1), cs_reg_name(handle, op->reg)); |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | printf("\tFunctional unit: "); |
| 77 | switch(tms320c64x->funit.unit) { |
| 78 | case TMS320C64X_FUNIT_D: |
| 79 | printf("D%u\n", tms320c64x->funit.side); |
| 80 | break; |
| 81 | case TMS320C64X_FUNIT_L: |
| 82 | printf("L%u\n", tms320c64x->funit.side); |
| 83 | break; |
| 84 | case TMS320C64X_FUNIT_M: |
| 85 | printf("M%u\n", tms320c64x->funit.side); |
| 86 | break; |
| 87 | case TMS320C64X_FUNIT_S: |
| 88 | printf("S%u\n", tms320c64x->funit.side); |
| 89 | break; |
| 90 | case TMS320C64X_FUNIT_NO: |
| 91 | printf("No Functional Unit\n"); |
| 92 | break; |
| 93 | default: |
| 94 | printf("Unknown (Unit %u, Side %u)\n", tms320c64x->funit.unit, tms320c64x->funit.side); |
| 95 | break; |
| 96 | } |
| 97 | if(tms320c64x->funit.crosspath == 1) |
| 98 | printf("\tCrosspath: 1\n"); |
| 99 | |
| 100 | if(tms320c64x->condition.reg != TMS320C64X_REG_INVALID) |
| 101 | printf("\tCondition: [%c%s]\n", (tms320c64x->condition.zero == 1) ? '!' : ' ', cs_reg_name(handle, tms320c64x->condition.reg)); |
| 102 | printf("\tParallel: %s\n", (tms320c64x->parallel == 1) ? "true" : "false"); |
| 103 | |
| 104 | printf("\n"); |
| 105 | } |