summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/operands/reglist.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/arm/v7/operands/reglist.c')
-rw-r--r--plugins/arm/v7/operands/reglist.c279
1 files changed, 130 insertions, 149 deletions
diff --git a/plugins/arm/v7/operands/reglist.c b/plugins/arm/v7/operands/reglist.c
index 2b2ee10..21407a4 100644
--- a/plugins/arm/v7/operands/reglist.c
+++ b/plugins/arm/v7/operands/reglist.c
@@ -39,6 +39,9 @@
+/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */
+
+
/* Définition d'un opérande listant une série de registres ARM (instance) */
struct _GArmV7RegListOperand
{
@@ -70,23 +73,28 @@ static void g_armv7_reglist_operand_dispose(GArmV7RegListOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_reglist_operand_finalize(GArmV7RegListOperand *);
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
/* Compare un opérande avec un autre. */
-static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *, const GArmV7RegListOperand *);
+static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *, const GArmV7RegListOperand *, bool);
/* Traduit un opérande en version humainement lisible. */
static void g_armv7_reglist_operand_print(const GArmV7RegListOperand *, GBufferLine *);
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_armv7_reglist_operand_load(GArmV7RegListOperand *, GObjectStorage *, packed_buffer_t *);
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_armv7_reglist_operand_store(GArmV7RegListOperand *, GObjectStorage *, packed_buffer_t *);
-/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
-/* Charge un opérande depuis une mémoire tampon. */
-static bool g_armv7_reglist_operand_unserialize(GArmV7RegListOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *);
-
-/* Sauvegarde un opérande dans une mémoire tampon. */
-static bool g_armv7_reglist_operand_serialize(const GArmV7RegListOperand *, GAsmStorage *, packed_buffer_t *);
-
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN NOUVEAU TYPE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini par la GLib pour une liste de registres ARM. */
@@ -119,8 +127,8 @@ static void g_armv7_reglist_operand_class_init(GArmV7RegListOperandClass *klass)
operand->compare = (operand_compare_fc)g_armv7_reglist_operand_compare;
operand->print = (operand_print_fc)g_armv7_reglist_operand_print;
- operand->unserialize = (unserialize_operand_fc)g_armv7_reglist_operand_unserialize;
- operand->serialize = (serialize_operand_fc)g_armv7_reglist_operand_serialize;
+ operand->load = (load_operand_fc)g_armv7_reglist_operand_load;
+ operand->store = (store_operand_fc)g_armv7_reglist_operand_store;
}
@@ -162,7 +170,7 @@ static void g_armv7_reglist_operand_dispose(GArmV7RegListOperand *operand)
size_t i; /* Boucle de parcours */
for (i = 0; i < operand->count; i++)
- g_object_unref(G_OBJECT(operand->registers[i]));
+ g_clear_object(&operand->registers[i]);
G_OBJECT_CLASS(g_armv7_reglist_operand_parent_class)->dispose(G_OBJECT(operand));
@@ -193,88 +201,6 @@ static void g_armv7_reglist_operand_finalize(GArmV7RegListOperand *operand)
/******************************************************************************
* *
-* Paramètres : a = premier opérande à consulter. *
-* b = second opérande à consulter. *
-* *
-* Description : Compare un opérande avec un autre. *
-* *
-* Retour : Bilan de la comparaison. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *a, const GArmV7RegListOperand *b)
-{
- int result; /* Bilan à faire remonter */
- size_t i; /* Boucle de parcours */
- GArchRegister *ra; /* Registre de la liste A */
- GArchRegister *rb; /* Registre de la liste B */
-
- /* Création de l'objet... */
- if (b == NULL)
- {
- result = 1;
- goto garoc_done;
- }
-
- result = sort_unsigned_long(a->count, b->count);
- if (result != 0) goto garoc_done;
-
- for (i = 0; i < a->count && result == 0; i++)
- {
- ra = G_ARCH_REGISTER(a->registers[i]);
- rb = G_ARCH_REGISTER(b->registers[i]);
-
- result = g_arch_register_compare(ra, rb);
-
- }
-
- garoc_done:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
-* line = ligne tampon où imprimer l'opérande donné. *
-* *
-* Description : Traduit un opérande en version humainement lisible. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_armv7_reglist_operand_print(const GArmV7RegListOperand *operand, GBufferLine *line)
-{
- size_t i; /* Boucle de parcours */
-
- g_buffer_line_append_text(line, DLC_ASSEMBLY, "{", 1, RTT_HOOK, NULL);
-
- for (i = 0; i < operand->count; i++)
- {
- if (i > 0)
- {
- g_buffer_line_append_text(line, DLC_ASSEMBLY, ",", 1, RTT_PUNCT, NULL);
- g_buffer_line_append_text(line, DLC_ASSEMBLY, " ", 1, RTT_RAW, NULL);
- }
-
- g_arch_register_print(G_ARCH_REGISTER(operand->registers[i]), line);
-
- }
-
- g_buffer_line_append_text(line, DLC_ASSEMBLY, "}", 1, RTT_HOOK, NULL);
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : selected = masque de bits pour les registres à intégrer. *
* *
* Description : Crée une liste vierge de registres ARM. *
@@ -322,8 +248,7 @@ GArchOperand *g_armv7_reglist_operand_new(uint16_t selected)
void g_armv7_reglist_add_register(GArmV7RegListOperand *operand, GArmV7Register *reg)
{
- operand->registers = (GArmV7Register **)realloc(operand->registers,
- ++operand->count * sizeof(GArmV7Register *));
+ operand->registers = realloc(operand->registers, ++operand->count * sizeof(GArmV7Register *));
operand->registers[operand->count - 1] = reg;
@@ -408,80 +333,106 @@ bool g_armv7_reglist_operand_has_register(const GArmV7RegListOperand *operand, c
/* ---------------------------------------------------------------------------------- */
-/* TRANSPOSITIONS VIA CACHE DES OPERANDES */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
/* ---------------------------------------------------------------------------------- */
/******************************************************************************
* *
-* Paramètres : operand = opérande d'assemblage à constituer. *
-* storage = mécanisme de sauvegarde à manipuler. *
-* format = format binaire chargé associé à l'architecture. *
-* pbuf = zone tampon à remplir. *
+* Paramètres : a = premier opérande à consulter. *
+* b = second opérande à consulter. *
+* lock = précise le besoin en verrouillage. *
* *
-* Description : Charge un opérande depuis une mémoire tampon. *
+* Description : Compare un opérande avec un autre. *
* *
-* Retour : Bilan de l'opération. *
+* Retour : Bilan de la comparaison. *
* *
* Remarques : - *
* *
******************************************************************************/
-static bool g_armv7_reglist_operand_unserialize(GArmV7RegListOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf)
+static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *a, const GArmV7RegListOperand *b, bool lock)
{
- bool result; /* Bilan à retourner */
- GArchOperandClass *parent; /* Classe parente à consulter */
- size_t count; /* Quantité de registres */
- packed_buffer_t reg_pbuf; /* Tampon des données à écrire */
+ int result; /* Bilan à faire remonter */
size_t i; /* Boucle de parcours */
- off64_t pos; /* Position dans le flux */
- GArchRegister *reg; /* Registre restauré */
+ GArchRegister *ra; /* Registre de la liste A */
+ GArchRegister *rb; /* Registre de la liste B */
+ GArchOperandClass *class; /* Classe parente normalisée */
- parent = G_ARCH_OPERAND_CLASS(g_armv7_reglist_operand_parent_class);
+ /* Création de l'objet... */
+ if (b == NULL)
+ {
+ result = 1;
+ goto done;
+ }
- result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
+ result = sort_unsigned_long(a->count, b->count);
- if (result)
- result = extract_packed_buffer(pbuf, &count, sizeof(size_t), true);
+ for (i = 0; i < a->count && result == 0; i++)
+ {
+ ra = G_ARCH_REGISTER(a->registers[i]);
+ rb = G_ARCH_REGISTER(b->registers[i]);
- if (result)
+ result = g_arch_register_compare(ra, rb);
+
+ }
+
+ if (result == 0)
{
- init_packed_buffer(&reg_pbuf);
+ class = G_ARCH_OPERAND_CLASS(g_armv7_reglist_operand_parent_class);
+ result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false);
+ }
- for (i = 0; i < count && result; i++)
- {
- result = extract_packed_buffer(pbuf, &pos, sizeof(off64_t), true);
+ done:
- if (result)
- result = g_asm_storage_load_register_data(storage, &reg_pbuf, pos);
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* line = ligne tampon où imprimer l'opérande donné. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- if (result)
- {
- reg = NULL;//g_arch_register_load(storage, &reg_pbuf);
- result = (reg != NULL);
- }
+static void g_armv7_reglist_operand_print(const GArmV7RegListOperand *operand, GBufferLine *line)
+{
+ size_t i; /* Boucle de parcours */
- if (result)
- g_armv7_reglist_add_register(operand, G_ARMV7_REGISTER(reg));
+ g_buffer_line_append_text(line, DLC_ASSEMBLY, "{", 1, RTT_HOOK, NULL);
+ for (i = 0; i < operand->count; i++)
+ {
+ if (i > 0)
+ {
+ g_buffer_line_append_text(line, DLC_ASSEMBLY, ",", 1, RTT_PUNCT, NULL);
+ g_buffer_line_append_text(line, DLC_ASSEMBLY, " ", 1, RTT_RAW, NULL);
}
- exit_packed_buffer(&reg_pbuf);
+ g_arch_register_print(G_ARCH_REGISTER(operand->registers[i]), line);
}
- return result;
+ g_buffer_line_append_text(line, DLC_ASSEMBLY, "}", 1, RTT_HOOK, NULL);
}
/******************************************************************************
* *
-* Paramètres : operand = opérande d'assemblage à consulter. *
-* storage = mécanisme de sauvegarde à manipuler. *
-* pbuf = zone tampon à remplir. *
+* Paramètres : operand = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
* *
-* Description : Sauvegarde un opérande dans une mémoire tampon. *
+* Description : Charge un contenu depuis une mémoire tampon. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -489,39 +440,69 @@ static bool g_armv7_reglist_operand_unserialize(GArmV7RegListOperand *operand, G
* *
******************************************************************************/
-static bool g_armv7_reglist_operand_serialize(const GArmV7RegListOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf)
+static bool g_armv7_reglist_operand_load(GArmV7RegListOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
+ size_t count; /* Quantité de registres */
size_t i; /* Boucle de parcours */
- off64_t pos; /* Position dans le flux */
- packed_buffer_t reg_pbuf; /* Tampon des données à écrire */
+ GSerializableObject *reg; /* Registre de la liste */
parent = G_ARCH_OPERAND_CLASS(g_armv7_reglist_operand_parent_class);
- result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
+ result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
- result = extend_packed_buffer(pbuf, &operand->count, sizeof(size_t), true);
+ result = extract_packed_buffer(pbuf, &count, sizeof(size_t), true);
- if (result)
+ for (i = 0; i < count && result; i++)
{
- init_packed_buffer(&reg_pbuf);
+ reg = g_object_storage_unpack_object(storage, "registers", pbuf);
- for (i = 0; i < operand->count && result; i++)
- {
- result = false;//g_arch_register_store(G_ARCH_REGISTER(operand->registers[i]), storage, &reg_pbuf);
+ result = (reg != NULL);
- if (result)
- result = g_asm_storage_store_register_data(storage, &reg_pbuf, &pos);
+ if (result)
+ g_armv7_reglist_add_register(operand, G_ARMV7_REGISTER(reg));
- if (result)
- result = extend_packed_buffer(pbuf, &pos, sizeof(off64_t), true);
+ }
- }
+ return result;
- exit_packed_buffer(&reg_pbuf);
+}
+
+/******************************************************************************
+* *
+* Paramètres : operand = élément GLib à consulter. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Sauvegarde un contenu dans une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_armv7_reglist_operand_store(GArmV7RegListOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ size_t i; /* Boucle de parcours */
+ GSerializableObject *reg; /* Registre de la liste */
+
+ parent = G_ARCH_OPERAND_CLASS(g_armv7_reglist_operand_parent_class);
+
+ result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf);
+
+ if (result)
+ result = extend_packed_buffer(pbuf, &operand->count, sizeof(size_t), true);
+
+ for (i = 0; i < operand->count && result; i++)
+ {
+ reg = G_SERIALIZABLE_OBJECT(operand->registers[i]);
+ result = g_object_storage_pack_object(storage, "registers", reg, pbuf);
}
return result;