summaryrefslogtreecommitdiff
path: root/src/arch/arm/v7/processor.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-01-09 22:30:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-01-09 22:30:16 (GMT)
commitcc3e31eecd90766ae4f0bb391428c5c59567ef4c (patch)
treee442bbaf401855f7bac411ac45e3545aa96ba661 /src/arch/arm/v7/processor.c
parent50a4c165df49b04fe55278d5dcfa6b56d3cc1125 (diff)
Chosen the right encoding to use when disassembling ARM binary.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@452 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/arm/v7/processor.c')
-rw-r--r--src/arch/arm/v7/processor.c117
1 files changed, 87 insertions, 30 deletions
diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c
index 4ae933b..45b53ae 100644
--- a/src/arch/arm/v7/processor.c
+++ b/src/arch/arm/v7/processor.c
@@ -24,10 +24,13 @@
#include "processor.h"
+#include <assert.h>
+
+
#include "arm.h"
+#include "context.h"
#include "thumb_16.h"
#include "thumb_32.h"
-#include "../context.h"
#include "../processor-int.h"
#include "../../raw.h"
@@ -61,8 +64,11 @@ static void g_armv7_processor_dispose(GArmV7Processor *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_processor_finalize(GArmV7Processor *);
+/* Fournit un contexte pour l'exécution du processeur ARM. */
+static GArmV7Context *g_armv7_processor_get_context(const GArmV7Processor *);
+
/* Décode une instruction dans un flux de données. */
-static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *, GArmContext *, const bin_t *, vmpa2t *, phys_t);
+static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *, GArmV7Context *, const bin_t *, vmpa2t *, phys_t);
@@ -121,6 +127,12 @@ static void g_armv7_processor_init(GArmV7Processor *proc)
parent->memsize = MDS_32_BITS;
parent->inssize = MDS_32_BITS;
+
+
+
+ parent->get_ctx = (get_processor_context_fc)g_armv7_processor_get_context;
+
+
}
@@ -187,6 +199,25 @@ GArmV7Processor *g_armv7_processor_new(void)
/******************************************************************************
* *
+* Paramètres : proc = architecture, spectatrice ici. *
+* *
+* Description : Fournit un contexte pour l'exécution du processeur Arm. *
+* *
+* Retour : Contexte mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArmV7Context *g_armv7_processor_get_context(const GArmV7Processor *proc)
+{
+ return g_armv7_context_new();
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : proc = architecture visée par la procédure. *
* ctx = contexte lié à l'exécution du processeur. *
* data = flux de données à analyser. *
@@ -202,7 +233,7 @@ GArmV7Processor *g_armv7_processor_new(void)
******************************************************************************/
#include "link.h"
#include "post.h"
-static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *proc, GArmContext *ctx, const bin_t *data, vmpa2t *pos, phys_t end)
+static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *proc, GArmV7Context *ctx, const bin_t *data, vmpa2t *pos, phys_t end)
{
GArchInstruction *result; /* Instruction à renvoyer */
phys_t start; /* Point de départ de lecture */
@@ -213,45 +244,71 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
+
+
+
+ ArmV7InstrSet iset;
+
+
+
+ iset = g_armv7_context_find_encoding(ctx, get_virt_addr(pos));
+
+
+
+ printf(" --decoding-- 0x%08x -> %u\n",
+ (unsigned int)get_virt_addr(pos),
+ (unsigned int)iset);
+
+
start = get_phy_addr(pos);
diff = 4;
- if (1/*Thumb*/)
+
+ switch (iset)
{
- if (!read_u16(&raw16, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
- return NULL;
+ case AV7IS_ARM:
- switch (raw16 >> 11)
- {
- case 0b11101:
- case 0b11110:
- case 0b11111:
+ if (!read_u32(&raw32, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
+ return NULL;
- raw32 = raw16 << 16;
+ result = process_armv7_arm_instruction_set_encoding(raw32);
- if (!read_u16(&raw16, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
- return NULL;
+ break;
- raw32 |= raw16;
+ case AV7IS_THUMB:
- result = process_armv7_thumb_32_instruction_set_encoding(raw32);
- break;
+ if (!read_u16(&raw16, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
+ return NULL;
- default:
- diff = 2;
- result = process_armv7_thumb_16_instruction_set_encoding(raw16);
- break;
+ switch (raw16 >> 11)
+ {
+ case 0b11101:
+ case 0b11110:
+ case 0b11111:
- }
+ raw32 = raw16 << 16;
- }
- else
- {
- if (!read_u32(&raw32, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
- return NULL;
+ if (!read_u16(&raw16, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
+ return NULL;
+
+ raw32 |= raw16;
+
+ result = process_armv7_thumb_32_instruction_set_encoding(raw32);
+ break;
+
+ default:
+ diff = 2;
+ result = process_armv7_thumb_16_instruction_set_encoding(raw16);
+ break;
+
+ }
+
+ break;
- result = process_armv7_arm_instruction_set_encoding(raw32);
+ default:
+ assert(0);
+ break;
}
@@ -270,7 +327,7 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
{
- g_arch_instruction_set_hook(result, IPH_LINK, handle_links_with_thumb_instruction_bl);
+ g_arch_instruction_set_hook(result, IPH_LINK, (instr_hook_fc)handle_links_with_thumb_instruction_bl);
g_arch_instruction_set_hook(result, IPH_POST, post_process_branch_instructions);
@@ -280,7 +337,7 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
if (strcmp(g_arch_instruction_get_keyword(result, 0), "blx") == 0/* && pc == 0x000085b2*/)
{
- g_arch_instruction_set_hook(result, IPH_LINK, handle_links_with_thumb_instruction_blx);
+ g_arch_instruction_set_hook(result, IPH_LINK, (instr_hook_fc)handle_links_with_thumb_instruction_blx);
g_arch_instruction_set_hook(result, IPH_POST, post_process_branch_instructions);