diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-06-18 21:53:43 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-06-18 21:53:43 (GMT) |
commit | 2bf52fcc65f066186b2b5ada7bad4d41770caf01 (patch) | |
tree | 86f04041e08416dcae9238eda47f089fc1bd1420 /src/arch/arm/v7/arm.c | |
parent | c987ca944052019957d3f31d69c679ed5ad994f2 (diff) |
Fixed and extended the support for ARM v7 instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@542 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/arm/v7/arm.c')
-rw-r--r-- | src/arch/arm/v7/arm.c | 346 |
1 files changed, 334 insertions, 12 deletions
diff --git a/src/arch/arm/v7/arm.c b/src/arch/arm/v7/arm.c index 2c0cabb..176d171 100644 --- a/src/arch/arm/v7/arm.c +++ b/src/arch/arm/v7/arm.c @@ -52,6 +52,23 @@ static GArchInstruction *process_armv7_arm_multiply_and_multiply_accumulate(uint static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uint32_t); + +/* Désassemble une instruction ARMv7 de données ou autre. */ +static GArchInstruction *process_armv7_arm_media_instructions(uint32_t); + + + +#define process_armv7_arm_parallel_addition_and_subtraction_signed(raw) NULL +#define process_armv7_arm_parallel_addition_and_subtraction_unsigned(raw) NULL +#define process_armv7_arm_signed_multiply_signed_and_unsigned_divide(raw) NULL + + + +/* Désassemble une instruction ARMv7 de données ou autre. */ +static GArchInstruction *process_armv7_arm_packing_unpacking_saturation_and_reversal(uint32_t); + + + /* Désassemble une instruction ARMv7 de données ou autre. */ static GArchInstruction *process_armv7_arm_branch_branch_with_link_and_block_data_transfer(uint32_t); @@ -61,7 +78,7 @@ static GArchInstruction *process_armv7_arm_branch_branch_with_link_and_block_dat //#define process_armv7_arm_load_store_word_and_unsigned_byte(raw) NULL //#define process_armv7_arm_load_store_word_and_unsigned_byte(raw) NULL -#define process_armv7_arm_media_instructions(raw) NULL +//#define process_armv7_arm_media_instructions(raw) NULL //#define process_armv7_arm_branch_branch_with_link_and_block_data_transfer(raw) NULL #define process_armv7_arm_coprocessor_instructions_and_Supervisor_call(raw) NULL #define process_armv7_arm_unconditional_instructions(raw) NULL @@ -531,10 +548,10 @@ static GArchInstruction *process_armv7_arm_multiply_and_multiply_accumulate(uint result = NULL; - if ((raw & 0x0f0000f0) == 0x00000090) + if ((raw & 0x0f0000f0) != 0x00000090) return NULL; - op = (raw >> 20) & 0x1f; + op = (raw >> 20) & 0xf; if ((op & b1110) == b0000) result = armv7_read_arm_instr_mul(raw); @@ -637,7 +654,7 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin { if (a == b0) { - result = armv7_read_arm_instr_strt(raw); + result = armv7_read_arm_instr_ldrt(raw); goto a53_done; } else if (/*a == b1 && */b == b0) @@ -657,7 +674,7 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin } else if (/*a == b1 && */b == b0) { - result = armv7_read_arm_instr_str_register(raw); + result = armv7_read_arm_instr_ldr_register(raw); goto a53_done; } } @@ -666,7 +683,7 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin { if (a == b0) { - result = armv7_read_arm_instr_strt(raw); + result = armv7_read_arm_instr_strbt(raw); goto a53_done; } else if (/*a == b1 && */b == b0) @@ -676,12 +693,12 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin { if (a == b0) { - result = armv7_read_arm_instr_str_immediate_arm(raw); + result = armv7_read_arm_instr_strb_immediate_arm(raw); goto a53_done; } else if (/*a == b1 && */b == b0) { - result = armv7_read_arm_instr_str_register(raw); + result = armv7_read_arm_instr_strb_register(raw); goto a53_done; } } @@ -690,7 +707,7 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin { if (a == b0) { - result = armv7_read_arm_instr_strt(raw); + result = armv7_read_arm_instr_ldrbt(raw); goto a53_done; } else if (/*a == b1 && */b == b0) @@ -701,16 +718,16 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin if (a == b0) { if (rn == b1111) - result = armv7_read_arm_instr_ldr_literal(raw); + result = armv7_read_arm_instr_ldrb_literal(raw); else - result = armv7_read_arm_instr_ldr_immediate_arm(raw); + result = armv7_read_arm_instr_ldrb_immediate_arm(raw); goto a53_done; } else if (/*a == b1 && */b == b0) { - result = armv7_read_arm_instr_str_register(raw); + result = armv7_read_arm_instr_ldrb_register(raw); goto a53_done; } } @@ -730,6 +747,311 @@ static GArchInstruction *process_armv7_arm_load_store_word_and_unsigned_byte(uin + +/****************************************************************************** +* * +* Paramètres : raw = donnée brute de 32 bits à désassembler. * +* * +* Description : Désassemble une instruction ARMv7 de données ou autre. * +* * +* Retour : Instruction mise en place ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArchInstruction *process_armv7_arm_media_instructions(uint32_t raw) +{ + GArchInstruction *result; /* Instruction à retourner */ + uint32_t cond; /* Champ 'cond' à retrouver */ + uint32_t op1; /* Champ 'op1' à retrouver */ + uint32_t rd; /* Champ 'rd' à retrouver */ + uint32_t op2; /* Champ 'op2' à retrouver */ + uint32_t rn; /* Champ 'rn' à retrouver */ + + /** + * Suit les directives de : + * § A5.4 Media instructions + */ + + result = NULL; + + if ((raw & 0x0e000010) != 0x06000010) + return NULL; + + cond = (raw >> 28) & 0xf; + op1 = (raw >> 20) & 0x1f; + rd = (raw >> 12) & 0xf; + op2 = (raw >> 5) & 0x7; + rn = (raw >> 0) & 0xf; + + if ((op1 & b11100) == b00000) + result = process_armv7_arm_parallel_addition_and_subtraction_signed(raw); + + else if ((op1 & b11100) == b00100) + result = process_armv7_arm_parallel_addition_and_subtraction_unsigned(raw); + + else if ((op1 & b11000) == b01000) + result = process_armv7_arm_packing_unpacking_saturation_and_reversal(raw); + + else if ((op1 & b11000) == b10000) + result = process_armv7_arm_signed_multiply_signed_and_unsigned_divide(raw); + + else if (op1 == b11000) + { + if (op2 == b000) + { + if (rd == b1111) + result = armv7_read_arm_instr_usad8(raw); + else + result = armv7_read_arm_instr_usada8(raw); + } + + goto a54_done; + + } + + else if ((op1 & b11110) == b11010) + { + if ((op2 & b011) == b010) + result = armv7_read_arm_instr_sbfx(raw); + + goto a54_done; + + } + + else if ((op1 & b11110) == b11100) + { + if ((op2 & b011) == b000) + { + if (rn == b1111) + result = armv7_read_arm_instr_bfc(raw); + else + result = armv7_read_arm_instr_bfi(raw); + } + + goto a54_done; + + } + + else if ((op1 & b11110) == b11110) + { + if ((op2 & b011) == b010) + result = armv7_read_arm_instr_ubfx(raw); + + goto a54_done; + + } + + else if (op1 == b11111 && op2 == b111 && cond == b1110) + result = armv7_read_arm_instr_ubfx(raw); + + a54_done: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : raw = donnée brute de 32 bits à désassembler. * +* * +* Description : Désassemble une instruction ARMv7 de données ou autre. * +* * +* Retour : Instruction mise en place ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArchInstruction *process_armv7_arm_packing_unpacking_saturation_and_reversal(uint32_t raw) +{ + GArchInstruction *result; /* Instruction à retourner */ + uint32_t op1; /* Champ 'op1' à retrouver */ + uint32_t a; /* Champ 'a' à retrouver */ + uint32_t op2; /* Champ 'op2' à retrouver */ + + /** + * Suit les directives de : + * § A5.4.3 Packing, unpacking, saturation, and reversal + */ + + result = NULL; + + if ((raw & 0x0f800010) != 0x06800010) + return NULL; + + op1 = (raw >> 20) & 0x7; + a = (raw >> 16) & 0xf; + op2 = (raw >> 5) & 0x7; + + if ((op1 & b111) == b000) + { + if ((op2 & b001) == b000) + { + result = armv7_read_arm_instr_pkh(raw); + goto a543_done; + } + else if (op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_sxtb16(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_sxtab16(raw); + goto a543_done; + } + } + else if (op2 == b101) + { + result = armv7_read_arm_instr_sel(raw); + goto a543_done; + } + } + + else if ((op1 & b110) == b010 && (op2 & b001) == b000) + { + result = armv7_read_arm_instr_ssat(raw); + goto a543_done; + } + + else if (op1 == b010) + { + if (op2 == b001) + { + result = armv7_read_arm_instr_ssat16(raw); + goto a543_done; + } + else if (op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_sxtb(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_sxtab(raw); + goto a543_done; + } + } + } + + else if (op1 == b011) + { + if (op2 == b001) + { + result = armv7_read_arm_instr_rev(raw); + goto a543_done; + } + else if (op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_sxth(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_sxtah(raw); + goto a543_done; + } + } + else if (op2 == b101) + { + result = armv7_read_arm_instr_rev16(raw); + goto a543_done; + } + } + + else if (op1 == b100 && op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_uxtb16(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_uxtab16(raw); + goto a543_done; + } + } + + else if ((op1 & b110) == b110 && (op2 & b001) == b000) + { + result = armv7_read_arm_instr_usat(raw); + goto a543_done; + } + + else if (op1 == b110) + { + if (op2 == b001) + { + result = armv7_read_arm_instr_usat16(raw); + goto a543_done; + } + else if (op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_uxtb(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_uxtab(raw); + goto a543_done; + } + } + } + + else if (op1 == b111) + { + if (op2 == b001) + { + result = armv7_read_arm_instr_rbit(raw); + goto a543_done; + } + else if (op2 == b011) + { + if (a == b1111) + { + result = armv7_read_arm_instr_uxth(raw); + goto a543_done; + } + else + { + result = armv7_read_arm_instr_uxtah(raw); + goto a543_done; + } + } + else if (op2 == b101) + { + result = armv7_read_arm_instr_revsh(raw); + goto a543_done; + } + } + + a543_done: + + return result; + +} + + + + + + + + + + /****************************************************************************** * * * Paramètres : raw = donnée brute de 32 bits à désassembler. * |