Rizin
unix-like reverse engineering framework and cli tools
tms320_dasm.h File Reference

Go to the source code of this file.

Classes

struct  tms320_instruction
 
struct  tms320_instruction_mask
 
struct  tms320_instruction_flag
 
struct  tms320_instruction_head
 
struct  tms320_dasm_t
 

Macros

#define IDA_COMPATIBLE_MODE   1
 
#define i_list_last(x)   !(((x)->i_list || (x)->m_list || (x)->f_list || (x)->syntax))
 
#define m_list_last(x)   !(((x)->f || (x)->n || (x)->v))
 
#define f_list_last(x)   !(((x)->f || (x)->v))
 
#define TMS320_S_INVAL   0x01
 
#define def_field(name, size)
 
#define TMS320_F_CPU_C54X   0x0000001
 
#define TMS320_F_CPU_C55X   0x0000002
 
#define TMS320_F_CPU_C55X_PLUS   0x0000003
 
#define TMS320_F_CPU_MASK   0x00000FF
 
#define tms320_f_get_cpu(d)   ((d)->features & TMS320_F_CPU_MASK)
 
#define tms320_f_set_cpu(d, v)   ((d)->features = ((d)->features & ~TMS320_F_CPU_MASK) | (v))
 
#define field_valid(d, name)    (d)->f.bf_##name##_valid
 
#define field_value(d, name)    (d)->f.bf_##name##_value
 
#define set_field_value(d, name, value)
 
#define LIST_END    { 0 }
 
#define INSN_MASK(af, an, av)    { .f = af, .n = an, .v = av }
 
#define INSN_FLAG(af, av)    { .f = af, .v = TMS320_FLAG_##av }
 
#define INSN_SYNTAX(...)   (char *)#__VA_ARGS__
 

Typedefs

typedef struct tms320_instruction insn_item_t
 
typedef struct tms320_instruction_mask insn_mask_t
 
typedef struct tms320_instruction_flag insn_flag_t
 
typedef struct tms320_instruction_head insn_head_t
 

Enumerations

enum  insn_flag_e {
  TMS320_FLAG_E = 0x10 , TMS320_FLAG_R , TMS320_FLAG_U , TMS320_FLAG_u ,
  TMS320_FLAG_g , TMS320_FLAG_r , TMS320_FLAG_t , TMS320_FLAG_uu ,
  TMS320_FLAG_mm , TMS320_FLAG_cc , TMS320_FLAG_tt , TMS320_FLAG_vv ,
  TMS320_FLAG_ss , TMS320_FLAG_dd , TMS320_FLAG_SS , TMS320_FLAG_DD ,
  TMS320_FLAG_k3 , TMS320_FLAG_k4 , TMS320_FLAG_k5 , TMS320_FLAG_k6 ,
  TMS320_FLAG_k8 , TMS320_FLAG_k12 , TMS320_FLAG_k16 , TMS320_FLAG_K8 ,
  TMS320_FLAG_K16 , TMS320_FLAG_l1 , TMS320_FLAG_l3 , TMS320_FLAG_l7 ,
  TMS320_FLAG_l16 , TMS320_FLAG_L7 , TMS320_FLAG_L8 , TMS320_FLAG_L16 ,
  TMS320_FLAG_P8 , TMS320_FLAG_P24 , TMS320_FLAG_D16 , TMS320_FLAG_SHFT ,
  TMS320_FLAG_SHIFTW , TMS320_FLAG_CCCCCCC , TMS320_FLAG_AAAAAAAI , TMS320_FLAG_FSSS ,
  TMS320_FLAG_FDDD , TMS320_FLAG_XSSS , TMS320_FLAG_XDDD , TMS320_FLAG_XACS ,
  TMS320_FLAG_XACD , TMS320_FLAG_XXX , TMS320_FLAG_MMM , TMS320_FLAG_Y ,
  TMS320_FLAG_YY
}
 

Functions

int tms320_dasm (tms320_dasm_t *, const ut8 *, int)
 
int tms320_dasm_init (tms320_dasm_t *)
 
int tms320_dasm_fini (tms320_dasm_t *)
 

Macro Definition Documentation

◆ def_field

#define def_field (   name,
  size 
)
Value:
unsigned int bf_##name##_valid : 1; \
unsigned int bf_##name##_value : size
voidpf void uLong size
Definition: ioapi.h:138
Definition: z80asm.h:102

Definition at line 129 of file tms320_dasm.h.

◆ f_list_last

#define f_list_last (   x)    !(((x)->f || (x)->v))

Definition at line 100 of file tms320_dasm.h.

◆ field_valid

#define field_valid (   d,
  name 
)     (d)->f.bf_##name##_valid

Definition at line 218 of file tms320_dasm.h.

◆ field_value

#define field_value (   d,
  name 
)     (d)->f.bf_##name##_value

Definition at line 220 of file tms320_dasm.h.

◆ i_list_last

#define i_list_last (   x)    !(((x)->i_list || (x)->m_list || (x)->f_list || (x)->syntax))

Definition at line 85 of file tms320_dasm.h.

◆ IDA_COMPATIBLE_MODE

#define IDA_COMPATIBLE_MODE   1

Definition at line 7 of file tms320_dasm.h.

◆ INSN_FLAG

#define INSN_FLAG (   af,
  av 
)     { .f = af, .v = TMS320_FLAG_##av }

Definition at line 242 of file tms320_dasm.h.

◆ INSN_MASK

#define INSN_MASK (   af,
  an,
  av 
)     { .f = af, .n = an, .v = av }

Definition at line 240 of file tms320_dasm.h.

◆ INSN_SYNTAX

#define INSN_SYNTAX (   ...)    (char *)#__VA_ARGS__

Definition at line 244 of file tms320_dasm.h.

◆ LIST_END

#define LIST_END    { 0 }

Definition at line 237 of file tms320_dasm.h.

◆ m_list_last

#define m_list_last (   x)    !(((x)->f || (x)->n || (x)->v))

Definition at line 95 of file tms320_dasm.h.

◆ set_field_value

#define set_field_value (   d,
  name,
  value 
)
Value:
({ \
field_valid(d, name) = 1; \
field_value(d, name) = value; \
})
static int value
Definition: cmd_api.c:93
#define d(i)
Definition: sha256.c:44

Definition at line 230 of file tms320_dasm.h.

◆ TMS320_F_CPU_C54X

#define TMS320_F_CPU_C54X   0x0000001

Definition at line 209 of file tms320_dasm.h.

◆ TMS320_F_CPU_C55X

#define TMS320_F_CPU_C55X   0x0000002

Definition at line 210 of file tms320_dasm.h.

◆ TMS320_F_CPU_C55X_PLUS

#define TMS320_F_CPU_C55X_PLUS   0x0000003

Definition at line 211 of file tms320_dasm.h.

◆ TMS320_F_CPU_MASK

#define TMS320_F_CPU_MASK   0x00000FF

Definition at line 212 of file tms320_dasm.h.

◆ tms320_f_get_cpu

#define tms320_f_get_cpu (   d)    ((d)->features & TMS320_F_CPU_MASK)

Definition at line 214 of file tms320_dasm.h.

◆ tms320_f_set_cpu

#define tms320_f_set_cpu (   d,
  v 
)    ((d)->features = ((d)->features & ~TMS320_F_CPU_MASK) | (v))

Definition at line 215 of file tms320_dasm.h.

◆ TMS320_S_INVAL

#define TMS320_S_INVAL   0x01

Definition at line 124 of file tms320_dasm.h.

Typedef Documentation

◆ insn_flag_t

Definition at line 1 of file tms320_dasm.h.

◆ insn_head_t

Definition at line 1 of file tms320_dasm.h.

◆ insn_item_t

Definition at line 1 of file tms320_dasm.h.

◆ insn_mask_t

Definition at line 1 of file tms320_dasm.h.

Enumeration Type Documentation

◆ insn_flag_e

Enumerator
TMS320_FLAG_E 
TMS320_FLAG_R 
TMS320_FLAG_U 
TMS320_FLAG_u 
TMS320_FLAG_g 
TMS320_FLAG_r 
TMS320_FLAG_t 
TMS320_FLAG_uu 
TMS320_FLAG_mm 
TMS320_FLAG_cc 
TMS320_FLAG_tt 
TMS320_FLAG_vv 
TMS320_FLAG_ss 
TMS320_FLAG_dd 
TMS320_FLAG_SS 
TMS320_FLAG_DD 
TMS320_FLAG_k3 
TMS320_FLAG_k4 
TMS320_FLAG_k5 
TMS320_FLAG_k6 
TMS320_FLAG_k8 
TMS320_FLAG_k12 
TMS320_FLAG_k16 
TMS320_FLAG_K8 
TMS320_FLAG_K16 
TMS320_FLAG_l1 
TMS320_FLAG_l3 
TMS320_FLAG_l7 
TMS320_FLAG_l16 
TMS320_FLAG_L7 
TMS320_FLAG_L8 
TMS320_FLAG_L16 
TMS320_FLAG_P8 
TMS320_FLAG_P24 
TMS320_FLAG_D16 
TMS320_FLAG_SHFT 
TMS320_FLAG_SHIFTW 
TMS320_FLAG_CCCCCCC 
TMS320_FLAG_AAAAAAAI 
TMS320_FLAG_FSSS 
TMS320_FLAG_FDDD 
TMS320_FLAG_XSSS 
TMS320_FLAG_XDDD 
TMS320_FLAG_XACS 
TMS320_FLAG_XACD 
TMS320_FLAG_XXX 
TMS320_FLAG_MMM 
TMS320_FLAG_Y 
TMS320_FLAG_YY 

Definition at line 23 of file tms320_dasm.h.

23  {
24  TMS320_FLAG_E = 0x10,
31 
41 
49 
52 
57 
61 
65 
70 
77 
82 } insn_flag_e;
insn_flag_e
Definition: tms320_dasm.h:23
@ TMS320_FLAG_l3
Definition: tms320_dasm.h:54
@ TMS320_FLAG_k4
Definition: tms320_dasm.h:43
@ TMS320_FLAG_SS
Definition: tms320_dasm.h:39
@ TMS320_FLAG_XSSS
Definition: tms320_dasm.h:73
@ TMS320_FLAG_XDDD
Definition: tms320_dasm.h:74
@ TMS320_FLAG_l7
Definition: tms320_dasm.h:55
@ TMS320_FLAG_FSSS
Definition: tms320_dasm.h:71
@ TMS320_FLAG_YY
Definition: tms320_dasm.h:81
@ TMS320_FLAG_FDDD
Definition: tms320_dasm.h:72
@ TMS320_FLAG_uu
Definition: tms320_dasm.h:32
@ TMS320_FLAG_k16
Definition: tms320_dasm.h:48
@ TMS320_FLAG_k12
Definition: tms320_dasm.h:47
@ TMS320_FLAG_r
Definition: tms320_dasm.h:29
@ TMS320_FLAG_E
Definition: tms320_dasm.h:24
@ TMS320_FLAG_SHIFTW
Definition: tms320_dasm.h:67
@ TMS320_FLAG_vv
Definition: tms320_dasm.h:36
@ TMS320_FLAG_mm
Definition: tms320_dasm.h:33
@ TMS320_FLAG_l16
Definition: tms320_dasm.h:56
@ TMS320_FLAG_DD
Definition: tms320_dasm.h:40
@ TMS320_FLAG_g
Definition: tms320_dasm.h:28
@ TMS320_FLAG_XXX
Definition: tms320_dasm.h:78
@ TMS320_FLAG_K8
Definition: tms320_dasm.h:50
@ TMS320_FLAG_XACD
Definition: tms320_dasm.h:76
@ TMS320_FLAG_P24
Definition: tms320_dasm.h:63
@ TMS320_FLAG_t
Definition: tms320_dasm.h:30
@ TMS320_FLAG_dd
Definition: tms320_dasm.h:38
@ TMS320_FLAG_K16
Definition: tms320_dasm.h:51
@ TMS320_FLAG_k8
Definition: tms320_dasm.h:46
@ TMS320_FLAG_cc
Definition: tms320_dasm.h:34
@ TMS320_FLAG_ss
Definition: tms320_dasm.h:37
@ TMS320_FLAG_u
Definition: tms320_dasm.h:27
@ TMS320_FLAG_L8
Definition: tms320_dasm.h:59
@ TMS320_FLAG_Y
Definition: tms320_dasm.h:80
@ TMS320_FLAG_AAAAAAAI
Definition: tms320_dasm.h:69
@ TMS320_FLAG_XACS
Definition: tms320_dasm.h:75
@ TMS320_FLAG_tt
Definition: tms320_dasm.h:35
@ TMS320_FLAG_MMM
Definition: tms320_dasm.h:79
@ TMS320_FLAG_k6
Definition: tms320_dasm.h:45
@ TMS320_FLAG_L7
Definition: tms320_dasm.h:58
@ TMS320_FLAG_k3
Definition: tms320_dasm.h:42
@ TMS320_FLAG_L16
Definition: tms320_dasm.h:60
@ TMS320_FLAG_U
Definition: tms320_dasm.h:26
@ TMS320_FLAG_D16
Definition: tms320_dasm.h:64
@ TMS320_FLAG_l1
Definition: tms320_dasm.h:53
@ TMS320_FLAG_SHFT
Definition: tms320_dasm.h:66
@ TMS320_FLAG_R
Definition: tms320_dasm.h:25
@ TMS320_FLAG_CCCCCCC
Definition: tms320_dasm.h:68
@ TMS320_FLAG_k5
Definition: tms320_dasm.h:44
@ TMS320_FLAG_P8
Definition: tms320_dasm.h:62

Function Documentation

◆ tms320_dasm()

int tms320_dasm ( tms320_dasm_t dasm,
const ut8 stream,
int  len 
)

Definition at line 1154 of file tms320_dasm.c.

1154  {
1155  init_dasm(dasm, stream, len);
1156 
1158  if (lookup_insn_head(dasm) && decode_insn_head(dasm)) {
1159  if (dasm->length > len) {
1160  dasm->status |= TMS320_S_INVAL;
1161  }
1162  }
1163  } else {
1165  }
1166 
1167  if (strstr(dasm->syntax, "invalid")) {
1168  dasm->status |= TMS320_S_INVAL;
1169  }
1170 
1171  if (dasm->status & TMS320_S_INVAL) {
1172  strcpy(dasm->syntax, "invalid"), dasm->length = 1;
1173  }
1174 
1175  return full_insn_size(dasm);
1176 }
size_t len
Definition: 6502dis.c:15
int c55x_plus_disassemble(tms320_dasm_t *dasm, const ut8 *buf, int len)
Definition: c55plus.c:21
voidpf stream
Definition: ioapi.h:138
char syntax[1024]
Definition: tms320_dasm.h:127
static void init_dasm(tms320_dasm_t *dasm, const ut8 *stream, int len)
Definition: tms320_dasm.c:1124
insn_item_t * decode_insn_head(tms320_dasm_t *dasm)
Definition: tms320_dasm.c:1065
insn_head_t * lookup_insn_head(tms320_dasm_t *dasm)
Definition: tms320_dasm.c:1100
static int full_insn_size(tms320_dasm_t *dasm)
Definition: tms320_dasm.c:1137
#define TMS320_F_CPU_C55X_PLUS
Definition: tms320_dasm.h:211
#define tms320_f_get_cpu(d)
Definition: tms320_dasm.h:214
#define TMS320_S_INVAL
Definition: tms320_dasm.h:124

References c55x_plus_disassemble(), decode_insn_head(), full_insn_size(), init_dasm(), len, tms320_dasm_t::length, lookup_insn_head(), tms320_dasm_t::status, tms320_dasm_t::syntax, TMS320_F_CPU_C55X_PLUS, tms320_f_get_cpu, and TMS320_S_INVAL.

Referenced by tms320_c55x_op(), and tms320_disassemble().

◆ tms320_dasm_fini()

int tms320_dasm_fini ( tms320_dasm_t dasm)

Definition at line 1202 of file tms320_dasm.c.

1202  {
1203  if (dasm) {
1204  if (dasm->map) {
1205  ht_up_free(dasm->map);
1206  }
1207  /* avoid double free */
1208  memset(dasm, 0, sizeof(tms320_dasm_t));
1209  }
1210  return 0;
1211 }
return memset(p, 0, total)

References tms320_dasm_t::map, and memset().

Referenced by tms320_fini().

◆ tms320_dasm_init()

int tms320_dasm_init ( tms320_dasm_t dasm)

Definition at line 1181 of file tms320_dasm.c.

1181  {
1182  int i = 0;
1183 
1184  if (dasm->map) {
1185  /* already initialized */
1186  return 0;
1187  }
1188 
1189  dasm->map = ht_up_new0();
1190  if (!dasm->map) {
1191  return 0;
1192  }
1193  for (i = 0; i < RZ_ARRAY_SIZE(c55x_list); i++) {
1194  ht_up_insert(dasm->map, c55x_list[i].byte, &c55x_list[i]);
1195  }
1196 
1198 
1199  return 0;
1200 }
lzma_index ** i
Definition: index.h:629
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
static insn_head_t c55x_list[]
Definition: table.h:4
#define tms320_f_set_cpu(d, v)
Definition: tms320_dasm.h:215
#define TMS320_F_CPU_C55X
Definition: tms320_dasm.h:210

References tms320_instruction_head::byte, c55x_list, i, tms320_dasm_t::map, RZ_ARRAY_SIZE, TMS320_F_CPU_C55X, and tms320_f_set_cpu.

Referenced by tms320_init().