From 4d313d845a60e908b9e2723cc1fe2bdbbdded315 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 15 Dec 2015 23:08:44 +0100 Subject: Stored and provided the encoding used by an instruction. --- ChangeLog | 16 ++++++++++++++++ src/arch/arm/v7/instruction.c | 35 +++++++++++++++++++++++++++++++++++ src/arch/instruction-int.h | 7 +++++++ src/arch/instruction.c | 39 +++++++++++++++++++++++++++++++++++++++ src/arch/instruction.h | 6 ++++++ src/arch/raw.c | 33 +++++++++++++++++++++++++++++++++ tools/d2c/spec.c | 4 ++++ 7 files changed, 140 insertions(+) diff --git a/ChangeLog b/ChangeLog index fae9a9b..bb9f0d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +15-12-15 Cyrille Bagard + + * src/arch/arm/v7/instruction.c: + Update code. + + * src/arch/instruction-int.h: + * src/arch/instruction.c: + * src/arch/instruction.h: + Store and provide the encoding used by an instruction. + + * src/arch/raw.c: + Update code. + + * tools/d2c/spec.c: + Update the generated code. + 15-12-12 Cyrille Bagard * src/analysis/disass/area.c: diff --git a/src/arch/arm/v7/instruction.c b/src/arch/arm/v7/instruction.c index de81056..d485dbc 100644 --- a/src/arch/arm/v7/instruction.c +++ b/src/arch/arm/v7/instruction.c @@ -58,6 +58,8 @@ static void g_armv7_instruction_dispose(GArmV7Instruction *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_instruction_finalize(GArmV7Instruction *); +/* Indique l'encodage d'une instruction de façon détaillée. */ +static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *); /* Indique le type défini pour une représentation d'une instruction ARMv7. */ @@ -79,12 +81,16 @@ G_DEFINE_TYPE(GArmV7Instruction, g_armv7_instruction, G_TYPE_ARM_INSTRUCTION); static void g_armv7_instruction_class_init(GArmV7InstructionClass *klass) { GObjectClass *object_class; /* Autre version de la classe */ + GArchInstructionClass *instr; /* Encore une autre vision... */ object_class = G_OBJECT_CLASS(klass); + instr = G_ARCH_INSTRUCTION_CLASS(klass); object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_instruction_dispose; object_class->finalize = (GObjectFinalizeFunc)g_armv7_instruction_finalize; + instr->get_encoding = (get_instruction_encoding_fc)g_armv7_instruction_get_encoding; + } @@ -171,6 +177,35 @@ GArchInstruction *g_armv7_instruction_new(const char *keyword) /****************************************************************************** * * +* Paramètres : instr = instruction quelconque à consulter. * +* * +* Description : Indique l'encodage d'une instruction de façon détaillée. * +* * +* Retour : Description humaine de l'encodage utilisé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *instr) +{ + const char *result; /* Description à retourner */ + const char *raw; /* Description brute d'origine */ + + raw = G_ARCH_INSTRUCTION(instr)->encoding; + + if (raw[0] == 'T' || raw[0] == 't') + result = "Thumb"; + else + result = "ARM"; + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction ARMv7 à mettre à jour. * * set = statut à enregistrer. * * * diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index 6b2b5c7..2d3a6a6 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -35,6 +35,9 @@ /* Liste les registres lus et écrits par l'instruction. */ typedef void (* get_instruction_rw_regs_fc) (const GArchInstruction *, GArchRegister ***, size_t *, GArchRegister ***, size_t *); +/* Indique l'encodage d'une instruction de façon détaillée. */ +typedef const char * (* get_instruction_encoding_fc) (const GArchInstruction *); + /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ typedef GBufferLine * (* print_instruction_fc) (const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); @@ -52,6 +55,8 @@ struct _GArchInstruction DL_LIST_ITEM(flow); /* Maillon de liste chaînée */ + const char *encoding; /* Encodage de l'instruction */ + const char *suffix; /* Complément au nom affiché */ char *cached_keyword; /* Désignation complète */ @@ -97,6 +102,8 @@ struct _GArchInstructionClass { GObjectClass parent; /* A laisser en premier */ + get_instruction_encoding_fc get_encoding; /* Obtention de l'encodage */ + print_instruction_fc print; /* Imprime l'ensemble */ build_instruction_keyword_fc build_key; /* Texte humain équivalent */ diff --git a/src/arch/instruction.c b/src/arch/instruction.c index c3c32dc..184d98c 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -150,6 +150,45 @@ static void g_arch_instruction_finalize(GArchInstruction *instr) /****************************************************************************** * * +* Paramètres : instr = instruction quelconque à consulter. * +* * +* Description : Indique l'encodage d'une instruction de façon détaillée. * +* * +* Retour : Description humaine de l'encodage utilisé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_arch_instruction_get_encoding(const GArchInstruction *instr) +{ + return G_ARCH_INSTRUCTION_GET_CLASS(instr)->get_encoding(instr); + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction quelconque à modifier. * +* encoding = encodage de l'instruction. * +* * +* Description : Précise l'encodage d'une instruction de façon détaillée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_arch_instruction_set_encoding(GArchInstruction *instr, const char *encoding) +{ + instr->encoding = encoding; + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction quelconque à modifier. * * suffix = chaîne de caractères fournie en complément. * * * diff --git a/src/arch/instruction.h b/src/arch/instruction.h index baeee2e..0db68c7 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -59,6 +59,12 @@ typedef struct _GArchInstructionClass GArchInstructionClass; /* Indique le type défini pour une instruction d'architecture. */ GType g_arch_instruction_get_type(void); +/* Indique l'encodage d'une instruction de façon détaillée. */ +const char *g_arch_instruction_get_encoding(const GArchInstruction *); + +/* Précise l'encodage d'une instruction de façon détaillée. */ +void g_arch_instruction_set_encoding(GArchInstruction *, const char *); + /* Etend la désignation d'un nom d'instruction. */ void g_arch_instruction_append_suffix(GArchInstruction *, const char *); diff --git a/src/arch/raw.c b/src/arch/raw.c index a9fc3df..57860c0 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -29,6 +29,9 @@ #include +#include + + #include "immediate.h" #include "instruction-int.h" #include "target.h" @@ -68,6 +71,9 @@ static void g_raw_instruction_dispose(GRawInstruction *); /* Procède à la libération totale de la mémoire. */ static void g_raw_instruction_finalize(GRawInstruction *); +/* Indique l'encodage d'une instruction de façon détaillée. */ +static const char *g_raw_instruction_get_encoding(const GRawInstruction *); + /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ static GBufferLine *g_raw_instruction_print(const GRawInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); @@ -109,6 +115,7 @@ static void g_raw_instruction_class_init(GRawInstructionClass *klass) instr = G_ARCH_INSTRUCTION_CLASS(klass); + instr->get_encoding = (get_instruction_encoding_fc)g_raw_instruction_get_encoding; instr->print = (print_instruction_fc)g_raw_instruction_print; instr->build_key = (build_instruction_keyword_fc)g_raw_instruction_build_keyword; @@ -299,6 +306,32 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory /****************************************************************************** * * +* Paramètres : instr = instruction quelconque à consulter. * +* * +* Description : Indique l'encodage d'une instruction de façon détaillée. * +* * +* Retour : Description humaine de l'encodage utilisé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const char *g_raw_instruction_get_encoding(const GRawInstruction *instr) +{ + const char *result; /* Description à retourner */ + + if (instr->is_string) + result = _("String"); + else + result = _("Raw"); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction d'assemblage à représenter. * * buffer = espace où placer ledit contenu. * * msize = taille idéale des positions et adresses; * diff --git a/tools/d2c/spec.c b/tools/d2c/spec.c index cf1a066..30a412a 100644 --- a/tools/d2c/spec.c +++ b/tools/d2c/spec.c @@ -345,6 +345,10 @@ bool write_encoding_spec_disass(const encoding_spec *spec, int fd, const char *a dprintf(fd, "\n"); } + dprintf(fd, "\t\tg_arch_instruction_set_encoding(instr, \"%s\");\n", spec->prefix); + + dprintf(fd, "\n"); + dprintf(fd, "\t\treturn instr;\n"); dprintf(fd, "\n"); -- cgit v0.11.2-87-g4458