TMS320: move c55plus under the TMS320 namespace

Sorry for the huge patch, but there is nothing special. We just move
asm/arch/c55plus into the asm/arch/tms320 and add some wrappers to use
existing code base under the new namespace.

Also, we've implement TMS320 anal module that supports now c55+ only. To
be continued...
This commit is contained in:
Ilya V. Matveychikov 2014-02-06 00:33:49 +04:00 committed by Anton Kochkov
parent 64aa3b37f2
commit 969ea9b7c2
33 changed files with 113 additions and 111 deletions

View File

@ -90,9 +90,9 @@ ANAL_OBJS += p/anal_java.c
../../shlr/java/ops.c
;
# C55PLUS
ANAL_OBJS += p/anal_c55plus.c
../asm/arch/c55plus/ins.c
# TMS320
ANAL_OBJS += p/anal_tms320.c
../asm/arch/tms320/tms320_dasm.c
;
# DALVIK

59
libr/anal/p/anal_tms320.c Normal file
View File

@ -0,0 +1,59 @@
/*
* TMS320 disassembly analizer
*
* Written by Ilya V. Matveychikov <i.matveychikov@milabs.ru>
*
* Distributed under LGPL
*/
#include <r_anal.h>
#include "../../asm/arch/tms320/tms320_dasm.h"
typedef int (* anal_op_t)(RAnal *, RAnalOp *, ut64, ut8 *, int);
int tms320_c54x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len);
int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len);
int tms320_c55plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len);
int tms320_c54x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
{
// TODO: add the implementation
return 0;
}
int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
{
// TODO: add the implementation
return 0;
}
int tms320_op(RAnal * anal, RAnalOp * op, ut64 addr, const ut8 * buf, int len)
{
anal_op_t aop = tms320_c55x_op;
if (anal->cpu && strcasecmp(anal->cpu, "C54X") == 0)
aop = tms320_c54x_op;
if (anal->cpu && strcasecmp(anal->cpu, "C55X") == 0)
aop = tms320_c55x_op;
if (anal->cpu && strcasecmp(anal->cpu, "C55PLUS") == 0)
aop = tms320_c55plus_op;
return aop(anal, op, addr, buf, len);
}
struct r_anal_plugin_t r_anal_plugin_tms320 = {
.name = "tms320",
.arch = R_SYS_ARCH_TMS320,
.bits = 32,
.desc = "TMS320 DSP family code analisys plugin",
.license = "LGPLv3",
.op = &tms320_op,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_tms320,
};
#endif

View File

@ -8,7 +8,7 @@
ut32 get_ins_len(ut8 opcode);
static int c55plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
int tms320_c55plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
ut16 *ins = (ut16*)buf;
ut32 ins_len;
@ -89,27 +89,3 @@ static int c55plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int l
return op->size;
}
struct r_anal_plugin_t r_anal_plugin_c55plus = {
.name = "c55+",
.desc = "C55+ code analysis plugin",
.arch = R_SYS_ARCH_C55PLUS,
.license = "LGPL3",
.bits = 32 | 40,
.init = NULL,
.fini = NULL,
.op = &c55plus_op,
.set_reg_profile = NULL,
.fingerprint_bb = NULL,
.fingerprint_fcn = NULL,
.diff_bb = NULL,
.diff_fcn = NULL,
.diff_eval = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_c55plus
};
#endif

View File

@ -1,11 +0,0 @@
OBJ_C55PLUS=anal_c55plus.o
SHARED_C55PLUS=../../asm/arch/c55plus/ins.o
STATIC_OBJ+=${OBJ_C55PLUS}
STATIC_OBJ+=${SHARED_C55PLUS}
TARGET_C55PLUS=anal_c55plus.${EXT_SO}
ALL_TARGETS+=${TARGET_C55PLUS}
${TARGET_C55PLUS}: ${OBJ_C55PLUS}
${CC} $(call libname,anal_c55plus) ${CFLAGS} -o anal_c55plus.${EXT_SO} ${OBJ_C55PLUS} ${SHARED_C55PLUS}

12
libr/anal/p/tms320.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_TMS320=anal_tms320.o
OBJ_TMS320+=anal_tms320_c55plus.o
STATIC_OBJ+=${OBJ_TMS320}
OBJ_TMS320+=../../../../../../../../../../../${LTOP}/asm/arch/tms320/tms320_dasm.o
TARGET_TMS320=anal_tms320.${EXT_SO}
ALL_TARGETS+=${TARGET_TMS320}
${TARGET_TMS320}: ${OBJ_TMS320} ${SHARED_OBJ}
${CC} $(call libname,anal_tms320) ${CFLAGS} \
-I../../include/ -o ${TARGET_TMS320} ${OBJ_TMS320}

View File

@ -3,10 +3,6 @@ ASM_OBJS = asm.c code.c ;
# X86 OLLY
ASM_OBJS += arch/x86/ollyasm/asmserv.c arch/x86/ollyasm/assembl.c arch/x86/ollyasm/disasm.c ;
# C55plus
ASM_OBJS += arch/c55plus/c55plus.c arch/c55plus/decode.c arch/c55plus/decode_funcs.c ;
ASM_OBJS += arch/c55plus/hashtable.c arch/c55plus/hashvector.c arch/c55plus/ins.c arch/c55plus/utils.c ;
# TMS320
ASM_OBJS += arch/tms320/tms320_dasm.c ;
@ -38,7 +34,7 @@ ASM_OBJS += arch/arm/aarch64/aarch64-opc-2.c ;
ASM_OBJS += arch/arm/aarch64/aarch64-opc.c ;
ASM_EXTRA += <include>arch/arm/aarch64/ ;
ASM_OBJS += p/asm_8051.c p/asm_c55plus.c p/asm_gb.c p/asm_ppc.c p/asm_x86.c ;
ASM_OBJS += p/asm_8051.c p/asm_tms320.c p/asm_gb.c p/asm_ppc.c p/asm_x86.c ;
ASM_OBJS += p/asm_arc.c p/asm_csr.c p/asm_i8080.c p/asm_x86_as.c ;
ASM_OBJS += p/asm_arm.c p/asm_dalvik.c p/asm_java.c p/asm_rar.c p/asm_x86_nasm.c ;
ASM_OBJS += p/asm_arm_winedbg.c p/asm_dcpu16.c p/asm_m68k.c p/asm_sh.c p/asm_x86_nz.c ;

View File

@ -11,10 +11,13 @@
#define USE_DECODE
#include "decode.h"
#include "../tms320_p.h"
#include "../tms320_dasm.h"
extern ut8 *ins_buff;
extern ut32 ins_buff_len;
int c55plus_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int c55plus_disassemble(tms320_dasm_t *dasm, const ut8 *buf, int len) {
unsigned int next_ins_pos;
char *ins_decoded;
size_t i, ins_decoded_len;
@ -26,17 +29,17 @@ int c55plus_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
// decode instruction
ins_decoded = decode(0, &next_ins_pos);
dasm->length = next_ins_pos;
if (!ins_decoded) {
op->size = 0;
return 0;
}
// opcode length
op->size = next_ins_pos;
dasm->length = next_ins_pos;
ins_decoded_len = strlen(ins_decoded);
for (i = 0; i < ins_decoded_len; i++)
ins_decoded[i] = tolower(ins_decoded[i]);
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s", ins_decoded);
snprintf (dasm->syntax, sizeof(dasm->syntax), "%s", ins_decoded);
free (ins_decoded);
return next_ins_pos;

View File

@ -7,6 +7,9 @@
#include <r_types.h>
#include <r_lib.h>
int c55plus_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
#include "../tms320_p.h"
#include "../tms320_dasm.h"
extern int c55plus_disassemble(tms320_dasm_t *dasm, const ut8 *buf, int len);
#endif

View File

@ -20,6 +20,8 @@
#include "tms320_p.h"
#include "tms320_dasm.h"
#include "c55plus/c55plus.h"
/*
* TMS320 disassembly engine implementation
*/
@ -1001,11 +1003,13 @@ int tms320_dasm(tms320_dasm_t * dasm, const ut8 * stream, int len)
{
init_dasm(dasm, stream, len);
if (lookup_insn_head(dasm)) {
if (decode_insn_head(dasm)) {
if (tms320_f_get_cpu(dasm) != TMS320_F_CPU_C55PLUS) {
if (lookup_insn_head(dasm) && decode_insn_head(dasm)) {
if (dasm->length > len)
dasm->status |= TMS320_S_INVAL;
}
} else {
c55plus_disassemble(dasm, stream, len);
}
return dasm->status & TMS320_S_INVAL ? 0 : dasm->length;

View File

@ -204,6 +204,7 @@ typedef struct {
#define TMS320_F_CPU_C54X 0x0000001
#define TMS320_F_CPU_C55X 0x0000002
#define TMS320_F_CPU_C55PLUS 0x0000003
#define TMS320_F_CPU_MASK 0x00000FF
ut32 features;
#define tms320_f_get_cpu(d) ((d)->features & TMS320_F_CPU_MASK)

View File

@ -13,7 +13,7 @@ ALL_TARGETS=
# TODO: rename to enabled plugins
ARCHS=mips.mk sparc.mk java.mk bf.mk arm.mk dalvik.mk x86_as.mk x86_nz.mk
ARCHS+=ppc.mk x86_olly.mk x86.mk csr.mk x86_nasm.mk psosvm.mk avr.mk
ARCHS+=msil.mk sh.mk arm_winedbg.mk c55plus.mk tms320.mk gb.mk snes.mk ebc.mk malbolge.mk ws.mk
ARCHS+=msil.mk sh.mk arm_winedbg.mk tms320.mk gb.mk snes.mk ebc.mk malbolge.mk ws.mk
include $(ARCHS)
all: ${ALL_TARGETS}

View File

@ -1,35 +0,0 @@
/* radare - LGPL - Copyright 2009-2013 - th0rpe, pancake */
#include <stdio.h>
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include "dis-asm.h"
int c55plus_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
return c55plus_disassemble (a, op, buf, len);
}
RAsmPlugin r_asm_plugin_c55plus = {
.name = "c55+",
.license = "LGPL3",
.desc = "c55+ disassembly plugin",
.arch = "c55+",
.bits = 32|40,
.init = NULL,
.fini = NULL,
.disassemble = &disassemble,
.modify = NULL,
.assemble = NULL,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_c55plus
};
#endif

View File

@ -22,6 +22,8 @@ static int tms320_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
tms320_f_set_cpu(&engine, TMS320_F_CPU_C54X);
if (a->cpu && strcasecmp(a->cpu, "C55X") == 0)
tms320_f_set_cpu(&engine, TMS320_F_CPU_C55X);
if (a->cpu && strcasecmp(a->cpu, "C55PLUS") == 0)
tms320_f_set_cpu(&engine, TMS320_F_CPU_C55PLUS);
op->size = tms320_dasm(&engine, buf, len);
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s", op->size ? engine.syntax : "invalid");

View File

@ -1,16 +0,0 @@
# depends
OBJ_C55PLUS=asm_c55plus.o
OBJ_C55PLUS+=../arch/c55plus/c55plus.o
OBJ_C55PLUS+=../arch/c55plus/decode.o
OBJ_C55PLUS+=../arch/c55plus/decode_funcs.o
OBJ_C55PLUS+=../arch/c55plus/hashtable.o
OBJ_C55PLUS+=../arch/c55plus/hashvector.o
OBJ_C55PLUS+=../arch/c55plus/ins.o
OBJ_C55PLUS+=../arch/c55plus/utils.o
TARGET_C55PLUS=asm_c55plus.${EXT_SO}
ALL_TARGETS+=${TARGET_C55PLUS}
STATIC_OBJ+=${OBJ_C55PLUS}
${TARGET_C55PLUS}: ${OBJ_C55PLUS}
${CC} $(call libname,asm_c55plus) ${LDFLAGS} ${CFLAGS} ${OBJ_C55PLUS}

View File

@ -1,6 +1,16 @@
OBJ_TMS320=asm_tms320.o
OBJ_TMS320+=../arch/tms320/tms320_dasm.o
# looks ugly as radare2 build system is terrible
OBJ_TMS320+=../arch/tms320/c55plus/c55plus.o \
../arch/tms320/c55plus/decode.o \
../arch/tms320/c55plus/decode_funcs.o \
../arch/tms320/c55plus/hashtable.o \
../arch/tms320/c55plus/hashvector.o \
../arch/tms320/c55plus/ins.o \
../arch/tms320/c55plus/utils.o
STATIC_OBJ+=${OBJ_TMS320}
TARGET_TMS320=asm_tms320.${EXT_SO}

View File

@ -1095,7 +1095,7 @@ R_API void r_anal_state_set_depth(RAnalState *state, ut32 depth);
/* plugin pointers */
extern RAnalPlugin r_anal_plugin_csr;
extern RAnalPlugin r_anal_plugin_c55plus;
extern RAnalPlugin r_anal_plugin_tms320;
extern RAnalPlugin r_anal_plugin_avr;
extern RAnalPlugin r_anal_plugin_arm;
extern RAnalPlugin r_anal_plugin_x86;

View File

@ -181,7 +181,6 @@ extern RAsmPlugin r_asm_plugin_arc;
extern RAsmPlugin r_asm_plugin_rar;
extern RAsmPlugin r_asm_plugin_dcpu16;
extern RAsmPlugin r_asm_plugin_8051;
extern RAsmPlugin r_asm_plugin_c55plus;
extern RAsmPlugin r_asm_plugin_tms320;
extern RAsmPlugin r_asm_plugin_gb;
extern RAsmPlugin r_asm_plugin_snes;

View File

@ -255,7 +255,7 @@ enum {
R_SYS_ARCH_I8080 = 0x10000,
R_SYS_ARCH_RAR = 0x20000,
R_SYS_ARCH_8051 = 0x40000,
R_SYS_ARCH_C55PLUS = 0x80000,
R_SYS_ARCH_TMS320 = 0x80000,
R_SYS_ARCH_EBC = 0x100000,
};

View File

@ -40,7 +40,7 @@ struct {const char* name; ut64 bit;} const static arch_bit_array[] = {
{"mips", R_SYS_ARCH_MIPS},
{"sparc", R_SYS_ARCH_SPARC},
{"csr", R_SYS_ARCH_CSR},
{"c55+", R_SYS_ARCH_C55PLUS},
{"tms320", R_SYS_ARCH_TMS320},
{"msil", R_SYS_ARCH_MSIL},
{"objd", R_SYS_ARCH_OBJD},
{"bf", R_SYS_ARCH_BF},

View File

@ -29,7 +29,6 @@ asm.z80
asm.i8080
asm.8051
asm.msil
asm.c55plus
asm.tms320
asm.gb
asm.snes
@ -49,7 +48,7 @@ anal.java
anal.dalvik
anal.csr
anal.nios2
anal.c55plus
anal.tms320
anal.avr
anal.m68k
anal.ppc

View File

@ -77,7 +77,7 @@ asm.z80
asm.i8080
asm.8051
asm.msil
asm.c55plus
asm.tms320
asm.sh
asm.csr
asm.avr
@ -91,7 +91,7 @@ anal.arc
anal.bf
anal.z80
anal.csr
anal.c55plus
anal.tms320
anal.avr
anal.m68k
anal.sh