mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 12:12:06 +00:00
Move tricore from asm to anal ##arch
This commit is contained in:
parent
59a2453159
commit
cbd43edef5
1
dist/plugins-cfg/plugins.def.cfg
vendored
1
dist/plugins-cfg/plugins.def.cfg
vendored
@ -81,7 +81,6 @@ asm.i4004
|
||||
asm.i8080
|
||||
asm.java
|
||||
asm.lm32
|
||||
asm.tricore
|
||||
asm.m680x_cs
|
||||
asm.malbolge
|
||||
asm.mips_cs
|
||||
|
1
dist/plugins-cfg/plugins.mingw.cfg
vendored
1
dist/plugins-cfg/plugins.mingw.cfg
vendored
@ -75,7 +75,6 @@ asm.i4004
|
||||
asm.i8080
|
||||
asm.java
|
||||
asm.lm32
|
||||
asm.tricore
|
||||
asm.m680x_cs
|
||||
asm.malbolge
|
||||
asm.mips_cs
|
||||
|
1
dist/plugins-cfg/plugins.nocs.cfg
vendored
1
dist/plugins-cfg/plugins.nocs.cfg
vendored
@ -64,7 +64,6 @@ asm.i4004
|
||||
asm.i8080
|
||||
asm.java
|
||||
asm.lm32
|
||||
asm.tricore
|
||||
asm.malbolge
|
||||
asm.mips_gnu
|
||||
asm.nios2
|
||||
|
1
dist/plugins-cfg/plugins.static.cfg
vendored
1
dist/plugins-cfg/plugins.static.cfg
vendored
@ -52,7 +52,6 @@ asm.i4004
|
||||
asm.i8080
|
||||
asm.java
|
||||
asm.lm32
|
||||
asm.tricore
|
||||
asm.m680x_cs
|
||||
asm.malbolge
|
||||
asm.mips_cs
|
||||
|
1
dist/plugins-cfg/plugins.static.nogpl.cfg
vendored
1
dist/plugins-cfg/plugins.static.nogpl.cfg
vendored
@ -37,7 +37,6 @@ asm.i4004
|
||||
asm.i8080
|
||||
asm.java
|
||||
asm.lm32
|
||||
asm.tricore
|
||||
asm.malbolge
|
||||
asm.mips_cs
|
||||
asm.nios2
|
||||
|
@ -133,6 +133,9 @@ r_anal_sources = [
|
||||
join_paths('..','asm','arch','tms320','c55x_plus','decode_funcs.c'),
|
||||
join_paths('..','asm','arch','tms320','c55x_plus','hashtable.c'),
|
||||
join_paths('..','asm','arch','tms320','c55x_plus','utils.c'),
|
||||
join_paths('../asm/arch','tricore','gnu','cpu-tricore.c'),
|
||||
join_paths('../asm/arch','tricore','gnu','tricore-dis.c'),
|
||||
join_paths('../asm/arch','tricore','gnu','tricore-opc.c'),
|
||||
join_paths('..','asm','arch','v810','v810_disas.c'),
|
||||
join_paths('..','asm','arch','xtensa','gnu','xtensa-dis.c'),
|
||||
join_paths('..','asm','arch','xtensa','gnu','elf32-xtensa.c'),
|
||||
|
@ -5,7 +5,99 @@
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
#include <r_anal.h>
|
||||
// DISASM BEGIN
|
||||
|
||||
#include "disas-asm.h"
|
||||
|
||||
static unsigned long Offset = 0;
|
||||
static RStrBuf *buf_global = NULL;
|
||||
static ut8 bytes[128];
|
||||
enum {
|
||||
TRICORE_GENERIC = 0x00000000,
|
||||
TRICORE_RIDER_A = 0x00000001,
|
||||
TRICORE_RIDER_B = 0x00000002,
|
||||
TRICORE_RIDER_D = TRICORE_RIDER_B,
|
||||
TRICORE_V2 = 0x00000004,
|
||||
TRICORE_PCP = 0x00000010,
|
||||
TRICORE_PCP2 = 0x00000020
|
||||
};
|
||||
|
||||
static int cpu_to_mach(char *cpu_type) {
|
||||
if (cpu_type && *cpu_type) {
|
||||
if (!strcmp (cpu_type, "generic")) {
|
||||
return TRICORE_GENERIC;
|
||||
}
|
||||
if (!strcmp (cpu_type, "rider-a")) {
|
||||
return TRICORE_RIDER_A;
|
||||
}
|
||||
if ((!strcmp (cpu_type, "rider-b")) || (!strcmp (cpu_type, "rider-d"))) {
|
||||
return TRICORE_RIDER_B;
|
||||
}
|
||||
if (!strcmp (cpu_type, "v2")) {
|
||||
return TRICORE_V2;
|
||||
}
|
||||
if (!strcmp (cpu_type, "pcp")) {
|
||||
return TRICORE_PCP;
|
||||
}
|
||||
if (!strcmp (cpu_type, "pcp2")) {
|
||||
return TRICORE_PCP2;
|
||||
}
|
||||
}
|
||||
return TRICORE_RIDER_B;
|
||||
}
|
||||
|
||||
static int tricore_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
|
||||
int delta = memaddr - Offset;
|
||||
if (delta >= 0 && length + delta < sizeof(bytes)) {
|
||||
memcpy (myaddr, bytes + delta, length);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
|
||||
//--
|
||||
}
|
||||
|
||||
DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
|
||||
DECLARE_GENERIC_FPRINTF_FUNC()
|
||||
|
||||
static int disassemble(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
buf_global = sb;
|
||||
Offset = addr;
|
||||
memcpy (bytes, buf, R_MIN (len, 8)); // TODO handle thumb
|
||||
|
||||
/* prepare disassembler */
|
||||
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
|
||||
disasm_obj.disassembler_options = (a->config->bits == 64)?"64":"";
|
||||
disasm_obj.buffer = bytes;
|
||||
disasm_obj.read_memory_func = &tricore_buffer_read_memory;
|
||||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &generic_print_address_func;
|
||||
disasm_obj.endian = BFD_ENDIAN_LITTLE;
|
||||
disasm_obj.fprintf_func = &generic_fprintf_func;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
// cpu type
|
||||
disasm_obj.mach = cpu_to_mach (a->config->cpu);
|
||||
|
||||
int ret = print_insn_tricore ((bfd_vma)Offset, &disasm_obj);
|
||||
op->size = ret;
|
||||
if (op->size == -1) {
|
||||
r_strbuf_set (sb, "(data)");
|
||||
op->size = 2;
|
||||
}
|
||||
op->mnemonic = r_strbuf_drain (sb);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
// DISASM END
|
||||
static bool set_reg_profile(RAnal *anal) {
|
||||
const char *p =
|
||||
"=PC pc\n"
|
||||
@ -72,12 +164,38 @@ static bool set_reg_profile(RAnal *anal) {
|
||||
return r_reg_set_profile_string (anal->reg, p);
|
||||
}
|
||||
|
||||
static int archinfo(RAnal *anal, int q) {
|
||||
if (q == R_ANAL_ARCHINFO_DATA_ALIGN) {
|
||||
return 2;
|
||||
}
|
||||
if (q == R_ANAL_ARCHINFO_ALIGN) {
|
||||
return 2;
|
||||
}
|
||||
if (q == R_ANAL_ARCHINFO_INV_OP_SIZE) {
|
||||
return 2;
|
||||
}
|
||||
if (q == R_ANAL_ARCHINFO_MAX_OP_SIZE) {
|
||||
return 4;
|
||||
}
|
||||
if (q == R_ANAL_ARCHINFO_MIN_OP_SIZE) {
|
||||
return 2;
|
||||
}
|
||||
return 4; // XXX
|
||||
}
|
||||
|
||||
static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
|
||||
return disassemble (a, op, addr, buf, len);
|
||||
}
|
||||
|
||||
RAnalPlugin r_anal_plugin_tricore = {
|
||||
.name = "tricore",
|
||||
.desc = "TRICORE analysis plugin",
|
||||
.license = "LGPL3",
|
||||
.arch = "tricore",
|
||||
.bits = 32,
|
||||
.archinfo = archinfo,
|
||||
.op = &analop,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.set_reg_profile = set_reg_profile,
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
OBJ_TRICORE=anal_tricore.o
|
||||
OBJ_TRICORE+=../../asm/arch/tricore/gnu/tricore-dis.o
|
||||
OBJ_TRICORE+=../../asm/arch/tricore/gnu/tricore-opc.o
|
||||
OBJ_TRICORE+=../../asm/arch/tricore/gnu/cpu-tricore.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_TRICORE}
|
||||
TARGET_TRICORE=anal_tricore.${EXT_SO}
|
||||
@ -7,4 +10,4 @@ ALL_TARGETS+=${TARGET_TRICORE}
|
||||
|
||||
${TARGET_TRICORE}: ${OBJ_TRICORE}
|
||||
${CC} $(call libname,anal_tricore) ${LDFLAGS} ${CFLAGS} \
|
||||
-o $(TARGET_TRICORE) $(OBJ_TRICORE)
|
||||
-o $(TARGET_TRICORE) $(OBJ_TRICORE)
|
||||
|
@ -63,6 +63,7 @@ OBJS+=d/lm32.o
|
||||
OBJS+=d/m68k.o
|
||||
OBJS+=d/malbolge.o
|
||||
OBJS+=d/mips.o
|
||||
OBJS+=d/tricore.o
|
||||
OBJS+=d/s390.o
|
||||
OBJS+=d/msp430.o
|
||||
OBJS+=d/pic18c.o
|
||||
|
@ -21,6 +21,7 @@ extern SdbGperf gperf_ppc;
|
||||
extern SdbGperf gperf_riscv;
|
||||
extern SdbGperf gperf_sh;
|
||||
extern SdbGperf gperf_sparc;
|
||||
extern SdbGperf gperf_tricore;
|
||||
extern SdbGperf gperf_x86;
|
||||
extern SdbGperf gperf_v810;
|
||||
extern SdbGperf gperf_s390;
|
||||
@ -46,6 +47,7 @@ static const SdbGperf *gperfs[] = {
|
||||
&gperf_m68k,
|
||||
&gperf_malbolge,
|
||||
&gperf_mips,
|
||||
&gperf_tricore,
|
||||
&gperf_ppc,
|
||||
&gperf_riscv,
|
||||
&gperf_sh,
|
||||
|
@ -419,9 +419,11 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
|
||||
eprintf ("Cannot find arch plugin with this name. See rasm2 -L and rasm2 -LL\n");
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// check if its a valid analysis plugin
|
||||
sdb_free (a->pair);
|
||||
a->pair = NULL;
|
||||
#endif
|
||||
if (strcmp (name, "null")) {
|
||||
return r_asm_use (a, "null");
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ r_asm_sources = [
|
||||
join_paths('p','asm_sparc_cs.c'),
|
||||
join_paths('p','asm_sparc_gnu.c'),
|
||||
join_paths('p','asm_tms320.c'),
|
||||
join_paths('p','asm_tricore.c'),
|
||||
join_paths('p','asm_v810.c'),
|
||||
join_paths('p','asm_v850.c'),
|
||||
join_paths('p','asm_v850_gnu.c'),
|
||||
@ -144,9 +143,6 @@ r_asm_sources = [
|
||||
join_paths('arch','tms320','c55x_plus','ins.c'),
|
||||
join_paths('arch','tms320','c55x_plus','utils.c'),
|
||||
join_paths('arch','tms320','tms320_dasm.c'),
|
||||
join_paths('arch','tricore','gnu','cpu-tricore.c'),
|
||||
join_paths('arch','tricore','gnu','tricore-dis.c'),
|
||||
join_paths('arch','tricore','gnu','tricore-opc.c'),
|
||||
join_paths('arch','v810','v810_disas.c'),
|
||||
join_paths('arch','v850','v850_disas.c'),
|
||||
join_paths('arch','vax','vax-dis.c'),
|
||||
|
@ -1,115 +0,0 @@
|
||||
/* radare2 - LGPL - Copyright 2016 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include "disas-asm.h"
|
||||
|
||||
|
||||
static unsigned long Offset = 0;
|
||||
static RStrBuf *buf_global = NULL;
|
||||
static ut8 bytes[128];
|
||||
enum {
|
||||
TRICORE_GENERIC = 0x00000000,
|
||||
TRICORE_RIDER_A = 0x00000001,
|
||||
TRICORE_RIDER_B = 0x00000002,
|
||||
TRICORE_RIDER_D = TRICORE_RIDER_B,
|
||||
TRICORE_V2 = 0x00000004,
|
||||
TRICORE_PCP = 0x00000010,
|
||||
TRICORE_PCP2 = 0x00000020
|
||||
};
|
||||
|
||||
static int cpu_to_mach(char *cpu_type) {
|
||||
if (cpu_type && *cpu_type) {
|
||||
if (!strcmp (cpu_type, "generic")) {
|
||||
return TRICORE_GENERIC;
|
||||
}
|
||||
if (!strcmp (cpu_type, "rider-a")) {
|
||||
return TRICORE_RIDER_A;
|
||||
}
|
||||
if ((!strcmp (cpu_type, "rider-b")) || (!strcmp (cpu_type, "rider-d"))) {
|
||||
return TRICORE_RIDER_B;
|
||||
}
|
||||
if (!strcmp (cpu_type, "v2")) {
|
||||
return TRICORE_V2;
|
||||
}
|
||||
if (!strcmp (cpu_type, "pcp")) {
|
||||
return TRICORE_PCP;
|
||||
}
|
||||
if (!strcmp (cpu_type, "pcp2")) {
|
||||
return TRICORE_PCP2;
|
||||
}
|
||||
}
|
||||
return TRICORE_RIDER_B;
|
||||
}
|
||||
|
||||
static int tricore_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
|
||||
int delta = memaddr - Offset;
|
||||
if (delta >= 0 && length + delta < sizeof(bytes)) {
|
||||
memcpy (myaddr, bytes + delta, length);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
|
||||
//--
|
||||
}
|
||||
|
||||
DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
|
||||
DECLARE_GENERIC_FPRINTF_FUNC()
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
buf_global = &op->buf_asm;
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, R_MIN (len, 8)); // TODO handle thumb
|
||||
|
||||
/* prepare disassembler */
|
||||
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
|
||||
disasm_obj.disassembler_options = (a->config->bits == 64)?"64":"";
|
||||
disasm_obj.buffer = bytes;
|
||||
disasm_obj.read_memory_func = &tricore_buffer_read_memory;
|
||||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
disasm_obj.memory_error_func = &memory_error_func;
|
||||
disasm_obj.print_address_func = &generic_print_address_func;
|
||||
disasm_obj.endian = BFD_ENDIAN_LITTLE;
|
||||
disasm_obj.fprintf_func = &generic_fprintf_func;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
// cpu type
|
||||
disasm_obj.mach = cpu_to_mach (a->config->cpu);
|
||||
|
||||
op->size = print_insn_tricore ((bfd_vma)Offset, &disasm_obj);
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, " (data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_tricore = {
|
||||
.name = "tricore",
|
||||
.arch = "tricore",
|
||||
.license = "GPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Siemens TriCore CPU",
|
||||
.disassemble = &disassemble,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_tricore,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
OBJ_TRICORE=asm_tricore.o
|
||||
OBJ_TRICORE+=../arch/tricore/gnu/tricore-dis.o
|
||||
OBJ_TRICORE+=../arch/tricore/gnu/tricore-opc.o
|
||||
OBJ_TRICORE+=../arch/tricore/gnu/cpu-tricore.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_TRICORE}
|
||||
TARGET_TRICORE=asm_tricore.${EXT_SO}
|
||||
|
||||
ifeq ($(WITHPIC),1)
|
||||
ALL_TARGETS+=${TARGET_TRICORE}
|
||||
|
||||
${TARGET_TRICORE}: ${OBJ_TRICORE}
|
||||
${CC} $(call libname,asm_tricore) ${LDFLAGS} ${CFLAGS} -o asm_tricore.${EXT_SO} ${OBJ_TRICORE}
|
||||
endif
|
@ -214,7 +214,6 @@ asm_plugins += [
|
||||
'snes',
|
||||
'sparc_cs',
|
||||
'tms320',
|
||||
'tricore',
|
||||
'v810',
|
||||
'v850',
|
||||
'vax',
|
||||
|
@ -178,5 +178,7 @@ CMDS=<<EOF
|
||||
aod
|
||||
aod zap
|
||||
EOF
|
||||
EXPECT=
|
||||
EXPECT=<<EOF
|
||||
Zero and Add
|
||||
EOF
|
||||
RUN
|
||||
|
@ -135,7 +135,7 @@ EXPECT=<<EOF
|
||||
0x80000018 6f010400 jz.t d1, 0, 0x80000020 ; jump if zero bit
|
||||
0x8000001c 5d006800 jl 0x800000ec ; jump and link
|
||||
0x80000020 910000ad movh.a sp, 53248 ; move high to address
|
||||
0x80000024 d9aa6000 lea sp, [sp]1056 <0xd0000420> ; load effective address
|
||||
0x80000024 d9aa6000 lea sp, [sp]1056 ; load effective address
|
||||
0x80000028 7b00000d movh d0, 53248 ; move high
|
||||
0x8000002c 1b008200 addi d0, d0, 2080 ; add immediate
|
||||
0x80000030 cd80e20f mtcr #0xfe28, d0 ; move to core register
|
||||
|
Loading…
x
Reference in New Issue
Block a user