summaryrefslogtreecommitdiff
path: root/src/arch/processor.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-03-31 23:20:33 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-03-31 23:20:33 (GMT)
commit5cc7bd39ae41af40a0c939acf98f90bf1375effd (patch)
tree4f7140e2c5a8d939c672fb941e66903300229e82 /src/arch/processor.c
parent52e036040b5e0ad8acde3d467ac8d9ca43ed414c (diff)
Saved some progress in the definition of basic blocks.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@497 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/processor.c')
-rw-r--r--src/arch/processor.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 0b33552..c2d190b 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -24,12 +24,16 @@
#include "processor.h"
+#include <malloc.h>
+#include <stdlib.h>
+
#include "instruction-int.h"
#include "processor-int.h"
+#include "raw.h"
@@ -294,3 +298,146 @@ GArchInstruction *g_arch_processor_disassemble(const GArchProcessor *proc, GProc
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : proc = architecture visée par la procédure. *
+* list = liste des instructions désassemblées. *
+* *
+* Description : Note les instructions désassemblées avec une architecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_arch_processor_set_disassembled_instructions(GArchProcessor *proc, GArchInstruction *list)
+{
+ GArchInstruction *iter; /* Boucle de parcours */
+
+ ainstr_list_for_each(iter, list)
+ {
+ /* Mise à disposition de d'avantage d'espace */
+ if (proc->instr_allocated == proc->instr_count)
+ {
+ proc->instr_allocated += INSTR_ALLOC_BLOCK;
+
+ proc->instructions = (GArchInstruction **)realloc(proc->instructions,
+ proc->instr_allocated * sizeof(GArchInstruction *));
+
+ }
+
+ proc->instructions[proc->instr_count++] = iter;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : proc = architecture visée par la procédure. *
+* *
+* Description : Fournit les instructions désassemblées pour une architecture.*
+* *
+* Retour : Liste des instructions désassemblées ou NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_arch_processor_get_disassembled_instructions(const GArchProcessor *proc)
+{
+ return (proc->instr_count > 0 ? proc->instructions[0] : NULL);
+
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : proc = processeur recensant diverses instructions. *
+* addr = position en mémoire ou physique à chercher. *
+* *
+* Description : Recherche une instruction d'après son adresse. *
+* *
+* Retour : Instruction trouvée à l'adresse donnée, NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_arch_processor_find_instr_by_address(const GArchProcessor *proc, const vmpa2t *addr)
+{
+ GArchInstruction *result; /* Trouvaille à retourner */
+ GArchInstruction *fake; /* Coquille vide à comparer */
+ void *ptr; /* Résultat des recherches */
+ size_t i; /* Boucle de parcours */
+ const mrange_t *range; /* Emplacement d'instruction */
+
+ if (has_phys_addr(addr))
+ {
+ fake = g_raw_instruction_new_from_value(addr, MDS_8_BITS_UNSIGNED, 0);
+
+ int search_for_instr_by_addr(const GArchInstruction **a, const GArchInstruction **b)
+ {
+ const mrange_t *range_a; /* Emplacement pour l'instr. A */
+ const mrange_t *range_b; /* Emplacement pour l'instr. B */
+
+ range_a = g_arch_instruction_get_range(*a);
+ range_b = g_arch_instruction_get_range(*b);
+
+ /*
+ printf(" -- cmp -- 0x%08x vs 0x%08x => %d\n",
+ (unsigned int)range_a->addr.virtual,
+ (unsigned int)range_b->addr.virtual,
+ cmp_vmpa(get_mrange_addr(range_a), get_mrange_addr(range_b)));
+ */
+
+ return cmp_vmpa(get_mrange_addr(range_a), get_mrange_addr(range_b));
+
+ }
+
+ ptr = bsearch(&fake, proc->instructions, proc->instr_count,
+ sizeof(GArchInstruction *), (__compar_fn_t)search_for_instr_by_addr);
+
+ g_object_unref(G_OBJECT(fake));
+
+ result = (ptr != NULL ? *((GArchInstruction **)ptr) : NULL);
+
+ }
+
+ else
+ {
+ result = NULL;
+
+ for (i = 0; i < proc->instr_count && result == NULL; i++)
+ {
+ range = g_arch_instruction_get_range(proc->instructions[i]);
+
+ if (cmp_vmpa(addr, get_mrange_addr(range)) == 0)
+ result = proc->instructions[i];
+
+ }
+
+ /*
+ for (i = 0; i < proc->instr_count; i++)
+ printf(" # %04zu 0x%08x\n", i, proc->instructions[i]->range.addr.virtual);
+ */
+
+ }
+
+ return result;
+
+}