Rizin
unix-like reverse engineering framework and cli tools
cstool_tms320c64x.c
Go to the documentation of this file.
1 /* Capstone Disassembler Engine */
2 /* By Fotis Loukos <me@fotisl.com>, 2017 */
3 
4 #include <stdio.h>
5 #include <capstone/capstone.h>
6 
7 void print_string_hex(const char *comment, unsigned char *str, size_t len);
8 
10 {
11  cs_tms320c64x *tms320c64x;
12  int i;
13 
14  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
15  if (ins->detail == NULL)
16  return;
17 
18  tms320c64x = &(ins->detail->tms320c64x);
19  if (tms320c64x->op_count)
20  printf("\top_count: %u\n", tms320c64x->op_count);
21 
22  for (i = 0; i < tms320c64x->op_count; i++) {
23  cs_tms320c64x_op *op = &(tms320c64x->operands[i]);
24  switch((int)op->type) {
25  default:
26  break;
27  case TMS320C64X_OP_REG:
28  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
29  break;
30  case TMS320C64X_OP_IMM:
31  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
32  break;
33  case TMS320C64X_OP_MEM:
34  printf("\t\toperands[%u].type: MEM\n", i);
35  if (op->mem.base != TMS320C64X_REG_INVALID)
36  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
37  i, cs_reg_name(handle, op->mem.base));
38  printf("\t\t\toperands[%u].mem.disptype: ", i);
39  if(op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) {
40  printf("Invalid\n");
41  printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
42  }
43  if(op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) {
44  printf("Constant\n");
45  printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
46  }
47  if(op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) {
48  printf("Register\n");
49  printf("\t\t\toperands[%u].mem.disp: %s\n", i, cs_reg_name(handle, op->mem.disp));
50  }
51  printf("\t\t\toperands[%u].mem.unit: %u\n", i, op->mem.unit);
52  printf("\t\t\toperands[%u].mem.direction: ", i);
53  if(op->mem.direction == TMS320C64X_MEM_DIR_INVALID)
54  printf("Invalid\n");
55  if(op->mem.direction == TMS320C64X_MEM_DIR_FW)
56  printf("Forward\n");
57  if(op->mem.direction == TMS320C64X_MEM_DIR_BW)
58  printf("Backward\n");
59  printf("\t\t\toperands[%u].mem.modify: ", i);
60  if(op->mem.modify == TMS320C64X_MEM_MOD_INVALID)
61  printf("Invalid\n");
62  if(op->mem.modify == TMS320C64X_MEM_MOD_NO)
63  printf("No\n");
64  if(op->mem.modify == TMS320C64X_MEM_MOD_PRE)
65  printf("Pre\n");
66  if(op->mem.modify == TMS320C64X_MEM_MOD_POST)
67  printf("Post\n");
68  printf("\t\t\toperands[%u].mem.scaled: %u\n", i, op->mem.scaled);
69 
70  break;
72  printf("\t\toperands[%u].type: REGPAIR = %s:%s\n", i, cs_reg_name(handle, op->reg + 1), cs_reg_name(handle, op->reg));
73  break;
74  }
75  }
76 
77  printf("\tFunctional unit: ");
78  switch(tms320c64x->funit.unit) {
79  case TMS320C64X_FUNIT_D:
80  printf("D%u\n", tms320c64x->funit.side);
81  break;
82  case TMS320C64X_FUNIT_L:
83  printf("L%u\n", tms320c64x->funit.side);
84  break;
85  case TMS320C64X_FUNIT_M:
86  printf("M%u\n", tms320c64x->funit.side);
87  break;
88  case TMS320C64X_FUNIT_S:
89  printf("S%u\n", tms320c64x->funit.side);
90  break;
92  printf("No Functional Unit\n");
93  break;
94  default:
95  printf("Unknown (Unit %u, Side %u)\n", tms320c64x->funit.unit, tms320c64x->funit.side);
96  break;
97  }
98  if(tms320c64x->funit.crosspath == 1)
99  printf("\tCrosspath: 1\n");
100 
101  if(tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
102  printf("\tCondition: [%c%s]\n", (tms320c64x->condition.zero == 1) ? '!' : ' ', cs_reg_name(handle, tms320c64x->condition.reg));
103  printf("\tParallel: %s\n", (tms320c64x->parallel == 1) ? "true" : "false");
104 
105  printf("\n");
106 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
static mcore_handle handle
Definition: asm_mcore.c:8
size_t csh
Definition: capstone.h:71
#define NULL
Definition: cris-opc.c:27
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
void print_string_hex(const char *comment, unsigned char *str, size_t len)
Definition: cstool.c:91
void print_insn_detail_tms320c64x(csh handle, cs_insn *ins)
cs_tms320c64x_op operands[8]
operands for this instruction.
Definition: tms320c64x.h:66
struct cs_tms320c64x::@364 funit
unsigned int unit
Definition: tms320c64x.h:72
unsigned int parallel
Definition: tms320c64x.h:76
unsigned int crosspath
Definition: tms320c64x.h:74
unsigned int reg
Definition: tms320c64x.h:68
uint8_t op_count
Definition: tms320c64x.h:65
struct cs_tms320c64x::@363 condition
unsigned int zero
Definition: tms320c64x.h:69
unsigned int side
Definition: tms320c64x.h:73
@ TMS320C64X_FUNIT_NO
Definition: tms320c64x.h:351
@ TMS320C64X_FUNIT_L
Definition: tms320c64x.h:348
@ TMS320C64X_FUNIT_D
Definition: tms320c64x.h:347
@ TMS320C64X_FUNIT_S
Definition: tms320c64x.h:350
@ TMS320C64X_FUNIT_M
Definition: tms320c64x.h:349
@ TMS320C64X_MEM_DISP_INVALID
Definition: tms320c64x.h:27
@ TMS320C64X_MEM_DISP_CONSTANT
Definition: tms320c64x.h:28
@ TMS320C64X_MEM_DISP_REGISTER
Definition: tms320c64x.h:29
@ TMS320C64X_REG_INVALID
Definition: tms320c64x.h:80
@ TMS320C64X_MEM_DIR_FW
Definition: tms320c64x.h:34
@ TMS320C64X_MEM_DIR_BW
Definition: tms320c64x.h:35
@ TMS320C64X_MEM_DIR_INVALID
Definition: tms320c64x.h:33
@ TMS320C64X_MEM_MOD_POST
Definition: tms320c64x.h:42
@ TMS320C64X_MEM_MOD_INVALID
Definition: tms320c64x.h:39
@ TMS320C64X_MEM_MOD_NO
Definition: tms320c64x.h:40
@ TMS320C64X_MEM_MOD_PRE
Definition: tms320c64x.h:41
@ TMS320C64X_OP_REG
= CS_OP_REG (Register operand).
Definition: tms320c64x.h:20
@ TMS320C64X_OP_REGPAIR
Register pair for double word ops.
Definition: tms320c64x.h:23
@ TMS320C64X_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: tms320c64x.h:21
@ TMS320C64X_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: tms320c64x.h:22
Definition: dis.c:32