Migrate cris from anal to ##arch

This commit is contained in:
Murphy 2023-03-12 18:15:06 +01:00 committed by pancake
parent b9356ead0e
commit 4e43e320cd
15 changed files with 62 additions and 130 deletions

View File

@ -13,7 +13,7 @@ arch.bpf
arch.bpf_cs arch.bpf_cs
anal.chip8 anal.chip8
anal.cr16 anal.cr16
anal.cris arch.cris
anal.dalvik anal.dalvik
anal.ebc anal.ebc
arch.dis arch.dis

View File

@ -9,7 +9,7 @@ anal.bf
anal.chip8 anal.chip8
arch.lanai arch.lanai
anal.cr16 anal.cr16
anal.cris arch.cris
anal.hppa_gnu anal.hppa_gnu
anal.dalvik anal.dalvik
anal.gb anal.gb

View File

@ -6,7 +6,7 @@ anal.avr
anal.bf anal.bf
anal.chip8 anal.chip8
anal.cr16 anal.cr16
anal.cris arch.cris
anal.dalvik anal.dalvik
anal.ebc anal.ebc
anal.gb anal.gb

View File

@ -6,7 +6,7 @@ anal.arm_cs
anal.arm_gnu anal.arm_gnu
anal.bf anal.bf
anal.chip8 anal.chip8
anal.cris arch.cris
anal.dalvik anal.dalvik
anal.gb anal.gb
arch.mcs96 arch.mcs96

View File

@ -3,7 +3,7 @@ anal.arc
anal.arm_cs anal.arm_cs
anal.bf anal.bf
anal.chip8 anal.chip8
anal.cris arch.cris
anal.dalvik anal.dalvik
anal.gb anal.gb
arch.lm32 arch.lm32

View File

@ -54,9 +54,6 @@ r_anal_sources = [
'p/anal_bf.c', 'p/anal_bf.c',
'p/anal_chip8.c', 'p/anal_chip8.c',
'p/anal_cr16.c', 'p/anal_cr16.c',
'p/anal_cris.c',
'../asm/arch/cris/gnu/cris-dis.c',
'../asm/arch/cris/gnu/cris-opc.c',
'p/anal_dalvik.c', 'p/anal_dalvik.c',
'p/anal_ebc.c', 'p/anal_ebc.c',
'p/anal_gb.c', 'p/anal_gb.c',

View File

@ -1,11 +0,0 @@
OBJ_CRIS=anal_cris.o
OBJ_CRIS+=../../asm/arch/cris/gnu/cris-dis.o
OBJ_CRIS+=../../asm/arch/cris/gnu/cris-opc.o
STATIC_OBJ+=$(OBJ_CRIS)
TARGET_CRIS=anal_cris.$(EXT_SO)
ALL_TARGETS+=$(TARGET_CRIS)
$(TARGET_CRIS): $(OBJ_CRIS)
$(CC) $(CFLAGS) $(call libname,anal_cris) -o anal_cris.$(EXT_SO) $(OBJ_CRIS)

View File

@ -72,6 +72,9 @@ r_arch_sources = [
'p/tricore/gnu/cpu-tricore.c', 'p/tricore/gnu/cpu-tricore.c',
'p/tricore/gnu/tricore-dis.c', 'p/tricore/gnu/tricore-dis.c',
'p/tricore/gnu/tricore-opc.c', 'p/tricore/gnu/tricore-opc.c',
'p/cris/cris.c',
'p/cris/gnu/cris-dis.c',
'p/cris/gnu/cris-opc.c',
] ]
if arch_plugins.contains('x86_nz') if arch_plugins.contains('x86_nz')

11
libr/arch/p/cris.mk Normal file
View File

@ -0,0 +1,11 @@
OBJ_CRIS=p/cris/cris.o
OBJ_CRIS+=p/cris/gnu/cris-dis.o
OBJ_CRIS+=p/cris/gnu/cris-opc.o
STATIC_OBJ+=$(OBJ_CRIS)
TARGET_CRIS=cris.$(EXT_SO)
ALL_TARGETS+=$(TARGET_CRIS)
$(TARGET_CRIS): $(OBJ_CRIS)
$(CC) $(CFLAGS) $(call libname,cris) -o cris.$(EXT_SO) $(OBJ_CRIS)

View File

@ -46,7 +46,7 @@ int print_insn_cris_without_register_prefix(bfd_vma vma, disassemble_info *info)
int print_insn_crisv32_with_register_prefix(bfd_vma vma, disassemble_info *info); int print_insn_crisv32_with_register_prefix(bfd_vma vma, disassemble_info *info);
int print_insn_crisv32_without_register_prefix(bfd_vma vma, disassemble_info *info); int print_insn_crisv32_without_register_prefix(bfd_vma vma, disassemble_info *info);
static char *disassemble(RAnal *a, RAnalOp *op, const ut8 *buf, int len) { static char *disassemble(RArchSession *as, RAnalOp *op, const ut8 *buf, int len) {
ut8 bytes[8] = { 0 }; ut8 bytes[8] = { 0 };
struct disassemble_info disasm_obj; struct disassemble_info disasm_obj;
int mode = 2; int mode = 2;
@ -59,18 +59,18 @@ static char *disassemble(RAnal *a, RAnalOp *op, const ut8 *buf, int len) {
/* prepare disassembler */ /* prepare disassembler */
memset (&disasm_obj, '\0', sizeof (struct disassemble_info)); memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
disasm_obj.disassembler_options = (a->config->bits == 64)?"64":""; disasm_obj.disassembler_options = (as->config->bits == 64)?"64":"";
disasm_obj.buffer = bytes; disasm_obj.buffer = bytes;
disasm_obj.read_memory_func = &cris_buffer_read_memory; disasm_obj.read_memory_func = &cris_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address; disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func; disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &generic_print_address_func; disasm_obj.print_address_func = &generic_print_address_func;
disasm_obj.endian = !R_ARCH_CONFIG_IS_BIG_ENDIAN (a->config); disasm_obj.endian = !R_ARCH_CONFIG_IS_BIG_ENDIAN (as->config);
disasm_obj.fprintf_func = &generic_fprintf_func; disasm_obj.fprintf_func = &generic_fprintf_func;
disasm_obj.stream = sb; disasm_obj.stream = sb;
disasm_obj.buffer_vma = op->addr; disasm_obj.buffer_vma = op->addr;
const char *cpu = a->config->cpu; const char *cpu = as->config->cpu;
if (R_STR_ISNOTEMPTY (cpu)) { if (R_STR_ISNOTEMPTY (cpu)) {
// enum cris_disass_family { cris_dis_v0_v10, cris_dis_common_v10_v32, cris_dis_v32 }; // enum cris_disass_family { cris_dis_v0_v10, cris_dis_common_v10_v32, cris_dis_v32 };
// 0: v0-v10 // 0: v0-v10
@ -87,7 +87,7 @@ static char *disassemble(RAnal *a, RAnalOp *op, const ut8 *buf, int len) {
mode = 2; mode = 2;
} }
(void)cris_parse_disassembler_options (&disasm_obj, mode); (void)cris_parse_disassembler_options (&disasm_obj, mode);
if (a->config->syntax == R_ARCH_SYNTAX_ATT) { if (as->config->syntax == R_ARCH_SYNTAX_ATT) {
switch (mode) { switch (mode) {
case 0: case 0:
op->size = print_insn_cris_with_register_prefix ((bfd_vma)addr, &disasm_obj); op->size = print_insn_cris_with_register_prefix ((bfd_vma)addr, &disasm_obj);
@ -118,16 +118,17 @@ static char *disassemble(RAnal *a, RAnalOp *op, const ut8 *buf, int len) {
return r_strbuf_drain (sb); return r_strbuf_drain (sb);
} }
static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { static bool decode(RArchSession *as, RAnalOp *op, RArchDecodeMask mask) {
int opsize = -1; const int len = op->size;
const ut8 *buf = op->bytes;
const ut64 addr = op->addr;
op->size = 2;
op->type = -1; op->type = -1;
opsize = 2;
if (len < 1) { if (len < 1) {
return -1; return -1;
} }
if (mask & R_ARCH_OP_MASK_DISASM) { if (mask & R_ARCH_OP_MASK_DISASM) {
op->addr = addr; op->mnemonic = disassemble (as, op, buf, len);
op->mnemonic = disassemble (a, op, buf, len);
if (!op->mnemonic) { if (!op->mnemonic) {
op->mnemonic = strdup ("invalid"); op->mnemonic = strdup ("invalid");
} }
@ -136,11 +137,11 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
case 0x3f: case 0x3f:
case 0x4f: case 0x4f:
op->type = R_ANAL_OP_TYPE_MOV; op->type = R_ANAL_OP_TYPE_MOV;
opsize = 4; op->size = 4;
break; break;
case 0x6f: case 0x6f:
op->type = R_ANAL_OP_TYPE_MOV; op->type = R_ANAL_OP_TYPE_MOV;
opsize = 6; op->size = 6;
break; break;
case 0x7f: case 0x7f:
op->type = R_ANAL_OP_TYPE_LEA; op->type = R_ANAL_OP_TYPE_LEA;
@ -150,7 +151,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
op->ptr |= buf[4] << 16; op->ptr |= buf[4] << 16;
op->ptr |= ((ut32)(0xff & buf[5])) << 24; op->ptr |= ((ut32)(0xff & buf[5])) << 24;
op->ptr += addr; op->ptr += addr;
opsize = 6; op->size = 6;
} else { } else {
// error // error
op->ptr = UT64_MAX; op->ptr = UT64_MAX;
@ -168,7 +169,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
op->jump = UT64_MAX; op->jump = UT64_MAX;
} }
op->fail = addr + 6; op->fail = addr + 6;
opsize = 6; op->size = 6;
break; break;
case 0x00: case 0x00:
if (len < 2) { if (len < 2) {
@ -282,96 +283,11 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
break; break;
} }
} }
#if 0
switch (*buf) {
case 0x3f: // adds.w N, R
opsize = 4;
case 0x01:
case 0x53: // addi, acr.w, r3, acr
case 0x04:
case 0x61:
case 0x62:
case 0x63:
op->type = R_ANAL_OP_TYPE_ADD;
break;
case 0x88:
case 0x84:
case 0x81:
case 0x8c:
case 0xad:
op->type = R_ANAL_OP_TYPE_SUB;
break;
case 0x7f: // lapc <addr>, <reg>
op->type = R_ANAL_OP_TYPE_LEA;
break;
case 0xcf:
case 0xbe:
case 0x60:
case 0x6f:
case 0x6a: // move.d reg, reg
case 0x7e:
case 0xfe:
op->type = R_ANAL_OP_TYPE_MOV;
break;
case 0x00:
op->type = R_ANAL_OP_TYPE_JMP;
// jsr acr
break;
case 0xff:
opsize = 6;
case 0x14:
case 0x0e:
case 0x1a:
case 0x9c:
case 0x6d: // bne
op->type = R_ANAL_OP_TYPE_CJMP;
// jsr acr
break;
case 0xbf:
opsize = 6;
case 0xb1:
case 0xb2:
case 0xb3:
case 0xb4:
case 0xb5:
case 0xb6:
case 0xb7:
case 0xb8:
case 0xb9:
op->type = R_ANAL_OP_TYPE_UJMP;
// jsr acr
break;
case 0x8f: // test.b [acr]
case 0xc0:
case 0xe1:
case 0xaa:
op->type = R_ANAL_OP_TYPE_CMP;
break;
default:
switch (*w) {
case 0xb0b9: //// jsr r0
op->type = R_ANAL_OP_TYPE_CJMP;
break;
case 0xb005:
case 0x05b0:
op->type = R_ANAL_OP_TYPE_NOP;
break;
case 0xf0b9:
case 0xb9f0:
op->type = R_ANAL_OP_TYPE_RET;
break;
default:
op->type = R_ANAL_OP_TYPE_MOV;
break;
}
}
#endif
op->size = opsize;
//op->delay = 1; //op->delay = 1;
return opsize; return op->size;
} }
static bool set_reg_profile(RAnal *anal) { static char *get_reg_profile(RArchSession *as) {
const char *p = const char *p =
"=PC pc\n" "=PC pc\n"
"=SP r14\n" // XXX "=SP r14\n" // XXX
@ -406,24 +322,40 @@ static bool set_reg_profile(RAnal *anal) {
"gpr r15 .32 60 0\n" "gpr r15 .32 60 0\n"
// ADD P REGISTERS // ADD P REGISTERS
; ;
return r_reg_set_profile_string (anal->reg, p); return strdup (p);
} }
RAnalPlugin r_anal_plugin_cris = { static int archinfo(RArchSession *as, ut32 q) {
switch (q) {
case R_ANAL_ARCHINFO_ALIGN:
return 1;
case R_ANAL_ARCHINFO_DATA_ALIGN:
return 1;
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
return 8;
case R_ANAL_ARCHINFO_INV_OP_SIZE:
return 4;
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
return 2;
}
return 4;
}
RArchPlugin r_arch_plugin_cris = {
.name = "cris", .name = "cris",
.desc = "Axis Communications 32-bit embedded processor", .desc = "Axis Communications 32-bit embedded processor",
.license = "LGPL3", .license = "LGPL3",
.esil = false,
.arch = "cris", .arch = "cris",
.set_reg_profile = set_reg_profile, .bits = R_SYS_BITS_PACK1 (32),
.bits = 32, .info = archinfo,
.op = &analop, .regs = get_reg_profile,
.decode = &decode,
}; };
#ifndef R2_PLUGIN_INCORE #ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = { R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL, .type = R_LIB_TYPE_ARCH,
.data = &r_anal_plugin_cris, .data = &r_arch_plugin_cris,
.version = R2_VERSION .version = R2_VERSION
}; };
#endif #endif

View File

@ -1571,7 +1571,6 @@ extern RAnalPlugin r_anal_plugin_avr;
extern RAnalPlugin r_anal_plugin_bf; extern RAnalPlugin r_anal_plugin_bf;
extern RAnalPlugin r_anal_plugin_chip8; extern RAnalPlugin r_anal_plugin_chip8;
extern RAnalPlugin r_anal_plugin_cr16; extern RAnalPlugin r_anal_plugin_cr16;
extern RAnalPlugin r_anal_plugin_cris;
extern RAnalPlugin r_anal_plugin_dalvik; extern RAnalPlugin r_anal_plugin_dalvik;
extern RAnalPlugin r_anal_plugin_ebc; extern RAnalPlugin r_anal_plugin_ebc;
extern RAnalPlugin r_anal_plugin_gb; extern RAnalPlugin r_anal_plugin_gb;

View File

@ -311,6 +311,7 @@ extern RArchPlugin r_arch_plugin_alpha;
extern RArchPlugin r_arch_plugin_vax; extern RArchPlugin r_arch_plugin_vax;
extern RArchPlugin r_arch_plugin_tricore; extern RArchPlugin r_arch_plugin_tricore;
extern RArchPlugin r_arch_plugin_pic; extern RArchPlugin r_arch_plugin_pic;
extern RArchPlugin r_arch_plugin_cris;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -38,6 +38,7 @@ arch_plugins = [ 'null',
'amd29k', 'amd29k',
'vax', 'vax',
'tricore', 'tricore',
'cris',
] ]
bin_plugins = [ 'any' ] bin_plugins = [ 'any' ]
bin_ldr_plugins = [ 'ldr_linux' ] bin_ldr_plugins = [ 'ldr_linux' ]
@ -156,7 +157,6 @@ anal_plugins += [
'bf', 'bf',
'chip8', 'chip8',
'cr16', 'cr16',
'cris',
'dalvik', 'dalvik',
'ebc', 'ebc',
'gb', 'gb',