summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/operands/offset.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/arm/v7/operands/offset.c')
-rw-r--r--plugins/arm/v7/operands/offset.c240
1 files changed, 108 insertions, 132 deletions
diff --git a/plugins/arm/v7/operands/offset.c b/plugins/arm/v7/operands/offset.c
index 615e296..fc68638 100644
--- a/plugins/arm/v7/operands/offset.c
+++ b/plugins/arm/v7/operands/offset.c
@@ -29,17 +29,18 @@
#include <arch/operand-int.h>
-#include <common/sort.h>
#include <gtkext/gtkblockdisplay.h>
+/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */
+
+
/* Définition d'un opérande visant à constituer un décalage relatif ARMv7 (instance) */
struct _GArmV7OffsetOperand
{
GArchOperand parent; /* Instance parente */
- bool positive; /* Sens du décalage */
GArchOperand *value; /* Valeur du décalage */
};
@@ -65,8 +66,13 @@ static void g_armv7_offset_operand_dispose(GArmV7OffsetOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *);
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
/* Compare un opérande avec un autre. */
-static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *, const GArmV7OffsetOperand *);
+static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *, const GArmV7OffsetOperand *, bool);
/* Détermine le chemin conduisant à un opérande interne. */
static char *g_armv7_offset_operand_find_inner_operand_path(const GArmV7OffsetOperand *, const GArchOperand *);
@@ -77,17 +83,17 @@ static GArchOperand *g_armv7_offset_operand_get_inner_operand_from_path(const GA
/* Traduit un opérande en version humainement lisible. */
static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *, GBufferLine *);
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_armv7_offset_operand_load(GArmV7OffsetOperand *, GObjectStorage *, packed_buffer_t *);
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_armv7_offset_operand_store(GArmV7OffsetOperand *, GObjectStorage *, packed_buffer_t *);
-/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
-
-
-/* Charge un opérande depuis une mémoire tampon. */
-static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *);
-/* Sauvegarde un opérande dans une mémoire tampon. */
-static bool g_armv7_offset_operand_serialize(const GArmV7OffsetOperand *, GAsmStorage *, packed_buffer_t *);
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN NOUVEAU TYPE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini par la GLib pour un décalage relatif ARMv7. */
@@ -124,8 +130,8 @@ static void g_armv7_offset_operand_class_init(GArmV7OffsetOperandClass *klass)
operand->print = (operand_print_fc)g_armv7_offset_operand_print;
- operand->unserialize = (unserialize_operand_fc)g_armv7_offset_operand_unserialize;
- operand->serialize = (serialize_operand_fc)g_armv7_offset_operand_serialize;
+ operand->load = (load_operand_fc)g_armv7_offset_operand_load;
+ operand->store = (store_operand_fc)g_armv7_offset_operand_store;
}
@@ -163,8 +169,7 @@ static void g_armv7_offset_operand_init(GArmV7OffsetOperand *operand)
static void g_armv7_offset_operand_dispose(GArmV7OffsetOperand *operand)
{
- if (operand->value != NULL)
- g_object_unref(G_OBJECT(operand->value));
+ g_clear_object(&operand->value);
G_OBJECT_CLASS(g_armv7_offset_operand_parent_class)->dispose(G_OBJECT(operand));
@@ -192,8 +197,69 @@ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *operand)
/******************************************************************************
* *
-* Paramètres : a = premier opérande à consulter. *
-* b = second opérande à consulter. *
+* Paramètres : positive = indique si la quantité doit être ajoutée ou non. *
+* value = valeur du décalage à appliquer. *
+* *
+* Description : Crée un décalage selon un sens et une valeur donnés. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value)
+{
+ GArmV7OffsetOperand *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ARMV7_OFFSET_OPERAND, NULL);
+
+ if (positive)
+ g_arch_operand_set_flag(G_ARCH_OPERAND(result), A7OOF_POSITIVE);
+
+ result->value = value;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Founit la valeur utilisée pour un décalage. *
+* *
+* Retour : Opérande en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operand)
+{
+ GArchOperand *result; /* Instance à retourner */
+
+ result = operand->value;
+
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : a = premier opérande à consulter. *
+* b = second opérande à consulter. *
+* lock = précise le besoin en verrouillage. *
* *
* Description : Compare un opérande avec un autre. *
* *
@@ -203,16 +269,18 @@ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *operand)
* *
******************************************************************************/
-static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *a, const GArmV7OffsetOperand *b)
+static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *a, const GArmV7OffsetOperand *b, bool lock)
{
int result; /* Bilan à faire remonter */
-
- result = sort_boolean(a->positive, b->positive);
- if (result != 0) goto gaooc_done;
+ GArchOperandClass *class; /* Classe parente normalisée */
result = g_arch_operand_compare(a->value, b->value);
- gaooc_done:
+ if (result == 0)
+ {
+ class = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class);
+ result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false);
+ }
return result;
@@ -299,7 +367,7 @@ static GArchOperand *g_armv7_offset_operand_get_inner_operand_from_path(const GA
static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *operand, GBufferLine *line)
{
- if (!operand->positive)
+ if (!g_arch_operand_has_flag(G_ARCH_OPERAND(operand), A7OOF_POSITIVE))
g_buffer_line_append_text(line, DLC_ASSEMBLY, "-", 1, RTT_KEY_WORD, NULL);
g_arch_operand_print(operand->value, line);
@@ -309,89 +377,11 @@ static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *operand, GBu
/******************************************************************************
* *
-* Paramètres : positive = indique si la quantité doit être ajoutée ou non. *
-* value = valeur du décalage à appliquer. *
-* *
-* Description : Crée un décalage selon un sens et une valeur donnés. *
-* *
-* Retour : Opérande mis en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value)
-{
- GArmV7OffsetOperand *result; /* Structure à retourner */
-
- result = g_object_new(G_TYPE_ARMV7_OFFSET_OPERAND, NULL);
-
- result->positive = positive;
- result->value = value;
-
- return G_ARCH_OPERAND(result);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Indique le sens du décalage représenté. *
-* *
-* Retour : Indication d'ajout ou de retrait. *
+* Paramètres : operand = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_armv7_offset_operand_is_positive(const GArmV7OffsetOperand *operand)
-{
- return operand->positive;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Founit la valeur utilisée pour un décalage. *
-* *
-* Retour : Opérande en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operand)
-{
- GArchOperand *result; /* Instance à retourner */
-
- result = operand->value;
-
- g_object_ref(G_OBJECT(result));
-
- return result;
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* TRANSPOSITIONS VIA CACHE DES OPERANDES */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* 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. *
-* *
-* Description : Charge un opérande depuis une mémoire tampon. *
+* Description : Charge un contenu depuis une mémoire tampon. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -399,35 +389,24 @@ GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operan
* *
******************************************************************************/
-static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf)
+static bool g_armv7_offset_operand_load(GArmV7OffsetOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
- GArchOperand *value; /* Valeur à intégrer */
- uint8_t positive; /* Sens du décalage */
+ GSerializableObject *value; /* Valeur du décalage */
parent = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class);
- result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
+ result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
{
- value = g_arch_operand_load(storage, format, pbuf);
-
- if (value == NULL)
- result = false;
+ value = g_object_storage_unpack_object(storage, "operands", pbuf);
- else
- operand->value = value;
-
- }
-
- if (result)
- {
- result = extract_packed_buffer(pbuf, &positive, sizeof(uint8_t), false);
+ result = (value != NULL);
if (result)
- operand->positive = (positive == 1 ? true : false);
+ operand->value = G_ARCH_OPERAND(value);
}
@@ -438,11 +417,11 @@ static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *operand, GAs
/******************************************************************************
* *
-* Paramètres : operand = opérande d'assemblage à consulter. *
-* storage = mécanisme de sauvegarde à manipuler. *
+* Paramètres : operand = élément GLib à consulter. *
+* storage = conservateur de données à manipuler ou NULL. *
* pbuf = zone tampon à remplir. *
* *
-* Description : Sauvegarde un opérande dans une mémoire tampon. *
+* Description : Sauvegarde un contenu dans une mémoire tampon. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -450,25 +429,22 @@ static bool g_armv7_offset_operand_unserialize(GArmV7OffsetOperand *operand, GAs
* *
******************************************************************************/
-static bool g_armv7_offset_operand_serialize(const GArmV7OffsetOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf)
+static bool g_armv7_offset_operand_store(GArmV7OffsetOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
- uint8_t positive; /* Sens du décalage */
+ GSerializableObject *value; /* Valeur du décalage */
parent = G_ARCH_OPERAND_CLASS(g_armv7_offset_operand_parent_class);
- result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
+ result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
{
- positive = (operand->positive ? 1 : 0);
- result = extend_packed_buffer(pbuf, &positive, sizeof(uint8_t), false);
+ value = G_SERIALIZABLE_OBJECT(operand->value);
+ result = g_object_storage_pack_object(storage, "operands", value, pbuf);
}
- if (result)
- result = g_arch_operand_store(operand->value, storage, pbuf);
-
return result;
}