From b8f37cb0c3ba53a4ad3d330d1ac0eeb967abd19d Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 25 Nov 2020 16:31:10 +0100 Subject: [PATCH] Add few tests for v850.gnu and fix instruction bounds ##disasm --- libr/anal/p/Makefile | 2 +- libr/anal/p/anal_v850.c | 2 +- libr/asm/meson.build | 3 +++ libr/asm/p/asm_v850_gnu.c | 9 +++------ libr/include/r_types_base.h | 16 ++++++++++++++++ libr/meson.build | 1 + test/db/anal/v850 | 4 ---- test/db/asm/v850.gnu_32 | 7 +++++++ test/db/formats/elf/v850 | 3 +++ 9 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 test/db/asm/v850.gnu_32 diff --git a/libr/anal/p/Makefile b/libr/anal/p/Makefile index 9104c6b9d5..7f1fbe4c88 100644 --- a/libr/anal/p/Makefile +++ b/libr/anal/p/Makefile @@ -12,7 +12,7 @@ all: ${ALL_TARGETS} ALL_TARGETS= # TODO: rename to enabled plugins -ARCHS=null.mk ppc_gnu.mk ppc_cs.mk arm_gnu.mk avr.mk xap.mk dalvik.mk sh.mk ebc.mk gb.mk malbolge.mk ws.mk h8300.mk cr16.mk v850.mk msp430.mk sparc_gnu.mk sparc_cs.mk x86_cs.mk cris.mk 6502.mk snes.mk riscv.mk vax.mk xtensa.mk rsp.mk mcore.mk tricore.mk +ARCHS=null.mk ppc_gnu.mk ppc_cs.mk arm_gnu.mk avr.mk xap.mk dalvik.mk sh.mk ebc.mk gb.mk malbolge.mk ws.mk h8300.mk cr16.mk v850.mk v850_gnu.mk msp430.mk sparc_gnu.mk sparc_cs.mk x86_cs.mk cris.mk 6502.mk snes.mk riscv.mk vax.mk xtensa.mk rsp.mk mcore.mk tricore.mk include $(ARCHS) clean: diff --git a/libr/anal/p/anal_v850.c b/libr/anal/p/anal_v850.c index 70f439fd07..d803cae483 100644 --- a/libr/anal/p/anal_v850.c +++ b/libr/anal/p/anal_v850.c @@ -562,7 +562,7 @@ static int archinfo(RAnal *anal, int q) { case R_ANAL_ARCHINFO_ALIGN: return 2; case R_ANAL_ARCHINFO_MAX_OP_SIZE: - return 6; + return 8; case R_ANAL_ARCHINFO_MIN_OP_SIZE: return 2; } diff --git a/libr/asm/meson.build b/libr/asm/meson.build index fa23f6a2dc..f60e0803b4 100644 --- a/libr/asm/meson.build +++ b/libr/asm/meson.build @@ -60,6 +60,7 @@ r_asm_sources = [ 'p/asm_tricore.c', 'p/asm_v810.c', 'p/asm_v850.c', + 'p/asm_v850_gnu.c', 'p/asm_vax.c', 'p/asm_wasm.c', 'p/asm_ws.c', @@ -76,6 +77,8 @@ r_asm_sources = [ 'arch/amd29k/amd29k.c', #'arch/8051/8051_disas.c', 'arch/8051/8051_ass.c', + 'arch/v850/gnu/v850-dis.c', + 'arch/v850/gnu/v850-opc.c', 'arch/arc/gnu/arc-dis.c', 'arch/arc/gnu/arc-ext.c', 'arch/arc/gnu/arc-opc.c', diff --git a/libr/asm/p/asm_v850_gnu.c b/libr/asm/p/asm_v850_gnu.c index 8f8678782e..c2f69b0254 100644 --- a/libr/asm/p/asm_v850_gnu.c +++ b/libr/asm/p/asm_v850_gnu.c @@ -33,12 +33,9 @@ DECLARE_GENERIC_FPRINTF_FUNC() static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; - if (len < 6) { - return -1; - } buf_global = &op->buf_asm; Offset = a->pc; - memcpy (bytes, buf, 6); + memcpy (bytes, buf, R_MIN (len, 8)); /* prepare disassembler */ memset (&disasm_obj, '\0', sizeof (struct disassemble_info)); @@ -69,9 +66,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (op->size == -1) { r_strbuf_set (&op->buf_asm, "(data)"); } - if (!memcmp (buf, "\xff\xff\xff\xff\xff\xff", op->size)) { + if (!memcmp (buf, "\xff\xff\xff\xff\xff\xff\xff\xff", op->size)) { r_strbuf_set (&op->buf_asm, "breakpoint"); - return 2; + return 4; } return op->size; } diff --git a/libr/include/r_types_base.h b/libr/include/r_types_base.h index 03a6c538bf..9408a7a360 100644 --- a/libr/include/r_types_base.h +++ b/libr/include/r_types_base.h @@ -144,6 +144,22 @@ typedef struct _utX { #define B_UNSET(x, n) ((x) &= ~(1ULL << (n))) #define B_TOGGLE(x, n) ((x) ^= (1ULL << (n))) +#define B11111 31 +#define B11110 30 +#define B11101 29 +#define B11100 28 +#define B11011 27 +#define B11010 26 +#define B11001 25 +#define B11000 24 +#define B10111 23 +#define B10110 22 +#define B10101 21 +#define B10100 20 +#define B10011 19 +#define B10010 18 +#define B10001 17 +#define B10000 16 #define B1111 15 #define B1110 14 #define B1101 13 diff --git a/libr/meson.build b/libr/meson.build index 5478f0fa7b..8249db8ad2 100644 --- a/libr/meson.build +++ b/libr/meson.build @@ -109,6 +109,7 @@ asm_plugins = [ 'tricore', 'v810', 'v850', + 'v850_gnu', 'vax', 'wasm', 'ws', diff --git a/test/db/anal/v850 b/test/db/anal/v850 index 0c7810fd18..3fad76c822 100644 --- a/test/db/anal/v850 +++ b/test/db/anal/v850 @@ -11,7 +11,6 @@ EXPECT=< 648 sym.___udivdi3 -0x001051e7 1 14 fcn.001051e7 0x001052d8 5 74 sym.___main 0x00105322 3 34 sym._exit 0x00105344 19 186 sym.__fclose_r @@ -201,7 +199,6 @@ EXPECT=<