From 096f123b87437cf25cd008a6dea710286fbefcf0 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 8 Dec 2014 08:27:56 +0000 Subject: Supported new ARMv7 instructions. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@437 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 39 ++++++++ src/arch/arm/v7/helpers.h | 26 ++++- src/arch/arm/v7/opcodes/Makefile.am | 9 ++ src/arch/arm/v7/opcodes/opcodes_tmp_arm.h | 2 - src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h | 6 -- src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h | 3 - src/arch/arm/v7/opdefs/Makefile.am | 5 + src/arch/arm/v7/opdefs/add_A886.d | 90 ++++++++++++++++++ src/arch/arm/v7/opdefs/b_A8818.d | 125 +++++++++++++++++++++++++ src/arch/arm/v7/opdefs/bx_A8827.d | 2 +- src/arch/arm/v7/opdefs/cbnz_A8829.d | 54 +++++++++++ src/arch/arm/v7/opdefs/ldr_A8865.d | 73 +++++++++++++++ src/arch/arm/v7/opdefs/lsl_A8894.d | 98 +++++++++++++++++++ src/arch/arm/v7/operands/maccess.c | 36 ++++++- src/arch/arm/v7/operands/maccess.h | 5 +- src/arch/arm/v7/thumb_16.c | 4 +- src/arch/arm/v7/thumb_32.c | 6 ++ tools/d2c/d2c_tok.l | 2 +- 18 files changed, 566 insertions(+), 19 deletions(-) create mode 100644 src/arch/arm/v7/opdefs/add_A886.d create mode 100644 src/arch/arm/v7/opdefs/b_A8818.d create mode 100644 src/arch/arm/v7/opdefs/cbnz_A8829.d create mode 100644 src/arch/arm/v7/opdefs/ldr_A8865.d create mode 100644 src/arch/arm/v7/opdefs/lsl_A8894.d diff --git a/ChangeLog b/ChangeLog index fabaa54..9157004 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +14-12-08 Cyrille Bagard + + * src/arch/arm/v7/helpers.h: + Create the 'DecodeImmShiftValue' macro and refine memory accesses. + + * src/arch/arm/v7/opcodes/Makefile.am: + Update libarcharmv7opcodes_la_SOURCES. + + * src/arch/arm/v7/opcodes/opcodes_tmp_arm.h: + * src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h: + * src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h: + Update missing prototypes. + + * src/arch/arm/v7/opdefs/add_A886.d: + * src/arch/arm/v7/opdefs/b_A8818.d: + New entries: support new ARMv7 instructions. + + * src/arch/arm/v7/opdefs/bx_A8827.d: + Fix the lower case for Thumb16 processing. + + * src/arch/arm/v7/opdefs/cbnz_A8829.d: + * src/arch/arm/v7/opdefs/ldr_A8865.d: + * src/arch/arm/v7/opdefs/lsl_A8894.d: + New entries: support new ARMv7 instructions. + + * src/arch/arm/v7/opdefs/Makefile.am: + Add new definitions to ARMV7_DEFS. + + * src/arch/arm/v7/operands/maccess.c: + * src/arch/arm/v7/operands/maccess.h: + Add an extra shift value for some accesses. + + * src/arch/arm/v7/thumb_16.c: + * src/arch/arm/v7/thumb_32.c: + Fix bugs in instruction decoding. + + * tools/d2c/d2c_tok.l: + Allow functions starting with an underscore. + 14-12-05 Cyrille Bagard * src/arch/arm/v7/helpers.h: diff --git a/src/arch/arm/v7/helpers.h b/src/arch/arm/v7/helpers.h index 4ef7087..fee5aea 100644 --- a/src/arch/arm/v7/helpers.h +++ b/src/arch/arm/v7/helpers.h @@ -88,6 +88,17 @@ +#define DecodeImmShiftValue(imm5) \ + ({ \ + GArchOperand *__result; \ + uint32_t __shift_n; \ + if (!armv7_decode_imm_shift(0, imm5, (SRType []) { 0 }, &__shift_n)) \ + __result = NULL; \ + else \ + __result = g_imm_operand_new_from_value(MDS_32_BITS_UNSIGNED, __shift_n); \ + __result; \ + }) + #define DecodeImmShift(type, imm5) \ ({ \ GArchOperand *__result; \ @@ -156,16 +167,27 @@ return shift_t; g_armv7_offset_operand_new(add, off) +#define MakeShiftedMemoryAccess(base, off, shift, wr) \ + g_armv7_maccess_operand_new(base, off, shift, wr) + + +#define _MakeMemoryAccess(base, off, wr) \ + MakeShiftedMemoryAccess(base, off, NULL, wr) + + #define MakeMemoryAccess(base, off, add, wr) \ ({ \ GArchOperand *__off; \ __off = MakeAccessOffset(add, off); \ - g_armv7_maccess_operand_new(base, __off, wr); \ + _MakeMemoryAccess(base, __off, wr); \ }) #define MakeMemoryNotIndexed(base, wr) \ - g_armv7_maccess_operand_new(base, NULL, wr) + _MakeMemoryAccess(base, NULL, wr) + + + diff --git a/src/arch/arm/v7/opcodes/Makefile.am b/src/arch/arm/v7/opcodes/Makefile.am index 30d0e16..be437b9 100644 --- a/src/arch/arm/v7/opcodes/Makefile.am +++ b/src/arch/arm/v7/opcodes/Makefile.am @@ -6,13 +6,16 @@ libarcharmv7opcodes_la_SOURCES = \ arm_adc.c \ arm_add.c \ arm_and.c \ + arm_b.c \ arm_bic.c \ arm_bl.c \ arm_bx.c \ + arm_cbnz.c \ arm_cmn.c \ arm_cmp.c \ arm_eor.c \ arm_ldr.c \ + arm_lsl.c \ arm_mla.c \ arm_mls.c \ arm_mov.c \ @@ -36,13 +39,16 @@ libarcharmv7opcodes_la_SOURCES = \ thumb_16_adc.c \ thumb_16_add.c \ thumb_16_and.c \ + thumb_16_b.c \ thumb_16_bic.c \ thumb_16_bl.c \ thumb_16_bx.c \ + thumb_16_cbnz.c \ thumb_16_cmn.c \ thumb_16_cmp.c \ thumb_16_eor.c \ thumb_16_ldr.c \ + thumb_16_lsl.c \ thumb_16_mla.c \ thumb_16_mls.c \ thumb_16_mov.c \ @@ -66,13 +72,16 @@ libarcharmv7opcodes_la_SOURCES = \ thumb_32_adc.c \ thumb_32_add.c \ thumb_32_and.c \ + thumb_32_b.c \ thumb_32_bic.c \ thumb_32_bl.c \ thumb_32_bx.c \ + thumb_32_cbnz.c \ thumb_32_cmn.c \ thumb_32_cmp.c \ thumb_32_eor.c \ thumb_32_ldr.c \ + thumb_32_lsl.c \ thumb_32_mla.c \ thumb_32_mls.c \ thumb_32_mov.c \ diff --git a/src/arch/arm/v7/opcodes/opcodes_tmp_arm.h b/src/arch/arm/v7/opcodes/opcodes_tmp_arm.h index 82590a4..1cd3e24 100644 --- a/src/arch/arm/v7/opcodes/opcodes_tmp_arm.h +++ b/src/arch/arm/v7/opcodes/opcodes_tmp_arm.h @@ -2,14 +2,12 @@ #define arm_def_tmp_h #define armv7_read_arm_instr_adr(r) NULL #define armv7_read_arm_instr_asr_immediate(r) NULL -#define armv7_read_arm_instr_b(r) NULL #define armv7_read_arm_instr_ldmda_ldmfa(r) NULL #define armv7_read_arm_instr_ldmdb_ldmea(r) NULL #define armv7_read_arm_instr_ldm_exception_return(r) NULL #define armv7_read_arm_instr_ldmib_ldmed(r) NULL #define armv7_read_arm_instr_ldm_ldmia_ldmfd_arm(r) NULL #define armv7_read_arm_instr_ldm_user_registers(r) NULL -#define armv7_read_arm_instr_lsl_immediate(r) NULL #define armv7_read_arm_instr_lsr_immediate(r) NULL #define armv7_read_arm_instr_movt(r) NULL #define armv7_read_arm_instr_pop_arm(r) NULL diff --git a/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h b/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h index 4620f83..f9ef7d9 100644 --- a/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h +++ b/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_16.h @@ -2,18 +2,14 @@ #define thumb_16_def_tmp_h #define armv7_read_thumb_16_instr_adc_register(r) NULL #define armv7_read_thumb_16_instr_add_immediate_thumb(r) NULL -#define armv7_read_thumb_16_instr_add_register_thumb(r) NULL #define armv7_read_thumb_16_instr_add_sp_plus_immediate(r) NULL #define armv7_read_thumb_16_instr_adr(r) NULL #define armv7_read_thumb_16_instr_and_register(r) NULL #define armv7_read_thumb_16_instr_asr_immediate(r) NULL #define armv7_read_thumb_16_instr_asr_register(r) NULL -#define armv7_read_thumb_16_instr_b(r) NULL #define armv7_read_thumb_16_instr_bic_register(r) NULL #define armv7_read_thumb_16_instr_bkpt(r) NULL #define armv7_read_thumb_16_instr_blx_register(r) NULL -#define armv7_read_thumb_16_instr_bx(r) NULL -#define armv7_read_thumb_16_instr_cbnz_cbz(r) NULL #define armv7_read_thumb_16_instr_cmn_register(r) NULL #define armv7_read_thumb_16_instr_cmp_immediate(r) NULL #define armv7_read_thumb_16_instr_cmp_register(r) NULL @@ -25,10 +21,8 @@ #define armv7_read_thumb_16_instr_ldrb_register(r) NULL #define armv7_read_thumb_16_instr_ldrh_immediate_thumb(r) NULL #define armv7_read_thumb_16_instr_ldrh_register(r) NULL -#define armv7_read_thumb_16_instr_ldr_register_thumb(r) NULL #define armv7_read_thumb_16_instr_ldrsb_register(r) NULL #define armv7_read_thumb_16_instr_ldrsh_register(r) NULL -#define armv7_read_thumb_16_instr_lsl_immediate(r) NULL #define armv7_read_thumb_16_instr_lsl_register(r) NULL #define armv7_read_thumb_16_instr_lsr_immediate(r) NULL #define armv7_read_thumb_16_instr_lsr_register(r) NULL diff --git a/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h b/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h index 999cd0d..966d6a2 100644 --- a/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h +++ b/src/arch/arm/v7/opcodes/opcodes_tmp_thumb_32.h @@ -1,10 +1,8 @@ #ifndef thumb_32_def_tmp_h #define thumb_32_def_tmp_h #define armv7_read_thumb_32_instr_add_immediate_thumb(r) NULL -#define armv7_read_thumb_32_instr_add_register_thumb(r) NULL #define armv7_read_thumb_32_instr_adr(r) NULL #define armv7_read_thumb_32_instr_asr_register(r) NULL -#define armv7_read_thumb_32_instr_b(r) NULL #define armv7_read_thumb_32_instr_bfc(r) NULL #define armv7_read_thumb_32_instr_bfi(r) NULL #define armv7_read_thumb_32_instr_b_mrs(r) NULL @@ -22,7 +20,6 @@ #define armv7_read_thumb_32_instr_isb(r) NULL #define armv7_read_thumb_32_instr_ldmdb_ldmea(r) NULL #define armv7_read_thumb_32_instr_ldm_ldmia_ldmfd_thumb(r) NULL -#define armv7_read_thumb_32_instr_ldr_register_thumb(r) NULL #define armv7_read_thumb_32_instr_ldrt(r) NULL #define armv7_read_thumb_32_instr_lsl_register(r) NULL #define armv7_read_thumb_32_instr_lsr_register(r) NULL diff --git a/src/arch/arm/v7/opdefs/Makefile.am b/src/arch/arm/v7/opdefs/Makefile.am index 348cbf6..948c9da 100644 --- a/src/arch/arm/v7/opdefs/Makefile.am +++ b/src/arch/arm/v7/opdefs/Makefile.am @@ -25,13 +25,16 @@ ARMV7_DEFS = \ adc_A881.d \ adc_A882.d \ add_A885.d \ + add_A886.d \ add_A887.d \ and_A8813.d \ and_A8814.d \ + b_A8818.d \ bic_A8821.d \ bic_A8822.d \ bl_A8825.d \ bx_A8827.d \ + cbnz_A8829.d \ cmn_A8834.d \ cmn_A8835.d \ cmp_A8837.d \ @@ -40,6 +43,8 @@ ARMV7_DEFS = \ eor_A8847.d \ ldr_A8862.d \ ldr_A8864.d \ + ldr_A8865.d \ + lsl_A8894.d \ mla_A88100.d \ mls_A88101.d \ mov_A88102.d \ diff --git a/src/arch/arm/v7/opdefs/add_A886.d b/src/arch/arm/v7/opdefs/add_A886.d new file mode 100644 index 0000000..fd8f7a4 --- /dev/null +++ b/src/arch/arm/v7/opdefs/add_A886.d @@ -0,0 +1,90 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * ##FILE## - traduction d'instructions ARMv7 + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see . + */ + + +@title ADD (register, Thumb) + +@encoding(t1) { + + @half 0 0 0 1 1 0 0 Rm(3) Rn(3) Rd(3) + + @syntax + + @conv { + + Rd = Register(Rd) + Rn = Register(Rn) + Rm = Register(Rm) + + } + +} + +@encoding(t2) { + + @half 0 1 0 0 0 1 0 0 DN(1) Rm(4) Rdn(3) + + @syntax + + @conv { + + Rdn = Register(DN:Rdn) + Rm = Register(Rm) + + } + + @rules { + + //if (DN:Rdn) == '1101' || Rm == '1101' then SEE ADD (SP plus register); + //if n == 15 && m == 15 then UNPREDICTABLE; + //if d == 15 && InITBlock() && !LastInITBlock() then UNPREDICTABLE; + + } + +} + +@encoding(T3) { + + @word 1 1 1 0 1 0 1 1 0 0 0 S(1) Rn(4) 0 imm3(3) Rd(4) imm2(2) type(2) Rm(4) + + @syntax {S} ".W" + + @conv { + + S = SetFlags(S) + Rd = Register(Rd) + Rn = Register(Rn) + Rm = Register(Rm) + shift = DecodeImmShift(type, imm3:imm2) + + } + + @rules { + + //if Rd == '1111' && S == '1' then SEE CMN (register); + //if Rn == '1101' then SEE ADD (SP plus register); + //if d == 13 || (d == 15 && S == '0') || n == 15 || m IN {13,15} then UNPREDICTABLE; + + + } + +} diff --git a/src/arch/arm/v7/opdefs/b_A8818.d b/src/arch/arm/v7/opdefs/b_A8818.d new file mode 100644 index 0000000..50600d4 --- /dev/null +++ b/src/arch/arm/v7/opdefs/b_A8818.d @@ -0,0 +1,125 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * ##FILE## - traduction d'instructions ARMv7 + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see . + */ + + +@title B + +@encoding(t1) { + + @half 1 1 0 1 cond(4) top(1) imm8(7) + + @syntax {c}