Rizin
unix-like reverse engineering framework and cli tools
analysis_tms320_c55x_plus.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 montekki <i.matveychikov@milabs.ru>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <string.h>
5 #include <rz_types.h>
6 #include <rz_lib.h>
7 #include <rz_asm.h>
8 #include <rz_analysis.h>
9 
10 ut32 get_ins_len(ut8 opcode);
11 
12 int tms320_c55x_plus_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len) {
13  ut16 *ins = (ut16 *)buf;
14  ut32 ins_len;
15 
16  if (!buf || len <= 0) {
17  return 0;
18  }
19 
20  ins_len = get_ins_len(buf[0]);
21  if (ins_len == 0) {
22  return 0;
23  }
24 
25  op->addr = addr;
26  op->size = ins_len;
27 
28  if (ins_len == 1) {
29  if (*ins == 0x20) {
31  } else if (*ins == 0x21) {
33  }
34  } else if (ins_len >= 4 && buf[0] == 0xD8) {
35  // BCC conditional absolute jump
37  op->jump = (buf[1] << 16) | (buf[2] << 8) | buf[3];
38  } else if (ins_len >= 2 && buf[0] == 0x6A) {
39  // BCC conditional relative jump
41  op->jump = addr + ((st8)buf[1]) + ins_len;
42  } else if (ins_len >= 3 && buf[0] == 0x9A) {
43  // BCC conditional relative jump
45  op->jump = addr + (st16)((buf[1] << 8) | buf[2]) + ins_len;
46  } else if (ins_len >= 4 && buf[0] == 0x9C) {
47  // B unconditional absolute jump
49  op->jump = (buf[1] << 16) | (buf[2] << 8) | buf[3];
50  } else if (ins_len >= 3 && buf[0] == 0x68) {
51  // B unconditional relative jump
53  op->jump = addr + (st16)((buf[1] << 8) | buf[2]) + ins_len;
54  } else if (ins_len == 2 && buf[0] == 0x02) {
55  // CALL unconditional absolute call with acumulator register ACx
56 
58  op->fail = addr + ins_len;
59  } else if (ins_len >= 3 && buf[0] == 0x69) {
60  // CALL unconditional relative call
62  op->jump = addr + (st16)((buf[1] << 8) | buf[2]) + ins_len;
63  } else if (ins_len >= 3 && buf[0] == 0x9D) {
64  // CALL unconditional absolute call
66  op->jump = (buf[1] << 16) | (buf[2] << 8) | buf[3];
67  } else if (ins_len >= 3 && buf[0] == 0x9B) {
68  // CALLCC conditional relative call
70  op->jump = addr + (st16)((buf[1] << 8) | buf[2]) + ins_len;
71  } else if (ins_len >= 4 && buf[0] == 0xD9) {
72  // CALLCC conditional absolute call
74  op->jump = (buf[1] << 16) | (buf[2] << 8) | buf[3];
75  } else {
77  }
78  return op->size;
79 }
size_t len
Definition: 6502dis.c:15
int tms320_c55x_plus_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len)
ut32 get_ins_len(ut8 opcode)
Definition: ins.c:11
uint16_t ut16
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
#define st8
Definition: rz_types_base.h:16
#define st16
Definition: rz_types_base.h:14
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58