summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/operands/shift.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/arm/v7/operands/shift.c')
-rw-r--r--plugins/arm/v7/operands/shift.c331
1 files changed, 215 insertions, 116 deletions
diff --git a/plugins/arm/v7/operands/shift.c b/plugins/arm/v7/operands/shift.c
index 852e677..8c00753 100644
--- a/plugins/arm/v7/operands/shift.c
+++ b/plugins/arm/v7/operands/shift.c
@@ -34,12 +34,24 @@
+/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */
+
+
+/* Informations glissées dans la structure GObject de GArchOperand */
+typedef struct _a7shiftop_extra_data_t
+{
+ operand_extra_data_t parent; /* A laisser en premier */
+
+ SRType shift_type; /* Type de décalage */
+
+} a7shiftop_extra_data_t;
+
+
/* Définition d'un opérande visant une opérande de décalage ARMv7 (instance) */
struct _GArmV7ShiftOperand
{
GArchOperand parent; /* Instance parente */
- SRType shift_type; /* Type de décalage */
GArchOperand *shift_value; /* Valeur du décalage */
};
@@ -53,6 +65,21 @@ struct _GArmV7ShiftOperandClass
};
+/**
+ * Accès aux informations éventuellement déportées.
+ */
+
+#if __SIZEOF_INT__ == __SIZEOF_LONG__
+
+# define GET_ARMV7_SHIFT_OP_EXTRA(op) (a7shiftop_extra_data_t *)&op->extra
+
+#else
+
+# define GET_ARMV7_SHIFT_OP_EXTRA(op) GET_GOBJECT_EXTRA(G_OBJECT(op), a7shiftop_extra_data_t)
+
+#endif
+
+
/* Initialise la classe des opérandes de décalage ARMv7. */
static void g_armv7_shift_operand_class_init(GArmV7ShiftOperandClass *);
@@ -65,8 +92,13 @@ static void g_armv7_shift_operand_dispose(GArmV7ShiftOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_shift_operand_finalize(GArmV7ShiftOperand *);
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
/* Compare un opérande avec un autre. */
-static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *, const GArmV7ShiftOperand *);
+static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *, const GArmV7ShiftOperand *, bool);
/* Détermine le chemin conduisant à un opérande interne. */
static char *g_armv7_shift_operand_find_inner_operand_path(const GArmV7ShiftOperand *, const GArchOperand *);
@@ -77,17 +109,17 @@ static GArchOperand *g_armv7_shift_operand_get_inner_operand_from_path(const GAr
/* Traduit un opérande en version humainement lisible. */
static void g_armv7_shift_operand_print(const GArmV7ShiftOperand *, GBufferLine *);
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_armv7_shift_operand_load(GArmV7ShiftOperand *, GObjectStorage *, packed_buffer_t *);
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_armv7_shift_operand_store(GArmV7ShiftOperand *, GObjectStorage *, packed_buffer_t *);
-/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
-
-
-/* Charge un opérande depuis une mémoire tampon. */
-static bool g_armv7_shift_operand_unserialize(GArmV7ShiftOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *);
-/* Sauvegarde un opérande dans une mémoire tampon. */
-static bool g_armv7_shift_operand_serialize(const GArmV7ShiftOperand *, GAsmStorage *, packed_buffer_t *);
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN NOUVEAU TYPE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini par la GLib pour une opérande de décalage ARMv7. */
@@ -124,8 +156,8 @@ static void g_armv7_shift_operand_class_init(GArmV7ShiftOperandClass *klass)
operand->print = (operand_print_fc)g_armv7_shift_operand_print;
- operand->unserialize = (unserialize_operand_fc)g_armv7_shift_operand_unserialize;
- operand->serialize = (serialize_operand_fc)g_armv7_shift_operand_serialize;
+ operand->load = (load_operand_fc)g_armv7_shift_operand_load;
+ operand->store = (store_operand_fc)g_armv7_shift_operand_store;
}
@@ -163,8 +195,7 @@ static void g_armv7_shift_operand_init(GArmV7ShiftOperand *operand)
static void g_armv7_shift_operand_dispose(GArmV7ShiftOperand *operand)
{
- if (operand->shift_value != NULL)
- g_object_unref(G_OBJECT(operand->shift_value));
+ g_clear_object(&operand->shift_value);
G_OBJECT_CLASS(g_armv7_shift_operand_parent_class)->dispose(G_OBJECT(operand));
@@ -192,8 +223,100 @@ static void g_armv7_shift_operand_finalize(GArmV7ShiftOperand *operand)
/******************************************************************************
* *
-* Paramètres : a = premier opérande à consulter. *
-* b = second opérande à consulter. *
+* Paramètres : - *
+* *
+* Description : Crée un réceptacle pour opérande de décalage ARMv7. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_shift_operand_new(SRType type, GArchOperand *value)
+{
+ GArmV7ShiftOperand *result; /* Structure à retourner */
+ a7shiftop_extra_data_t *extra; /* Données insérées à modifier */
+
+ result = g_object_new(G_TYPE_ARMV7_SHIFT_OPERAND, NULL);
+
+ extra = GET_ARMV7_SHIFT_OP_EXTRA(result);
+
+ extra->shift_type = type;
+
+ result->shift_value = value;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Indique la forme de décalage représenté. *
+* *
+* Retour : Type de décalage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+SRType g_armv7_shift_operand_get_shift_type(const GArmV7ShiftOperand *operand)
+{
+ SRType result; /* Type à retourner */
+ a7shiftop_extra_data_t *extra; /* Données insérées à consulter*/
+
+ extra = GET_ARMV7_SHIFT_OP_EXTRA(operand);
+
+ LOCK_GOBJECT_EXTRA(extra);
+
+ result = extra->shift_type;
+
+ UNLOCK_GOBJECT_EXTRA(extra);
+
+ return 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_shift_operand_get_shift_value(const GArmV7ShiftOperand *operand)
+{
+ GArchOperand *result; /* Instance à retourner */
+
+ result = operand->shift_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 +326,38 @@ static void g_armv7_shift_operand_finalize(GArmV7ShiftOperand *operand)
* *
******************************************************************************/
-static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *a, const GArmV7ShiftOperand *b)
+static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *a, const GArmV7ShiftOperand *b, bool lock)
{
int result; /* Bilan à faire remonter */
+ a7shiftop_extra_data_t *ea; /* Données insérées à consulter*/
+ a7shiftop_extra_data_t *eb; /* Données insérées à consulter*/
+ GArchOperandClass *class; /* Classe parente normalisée */
- result = sort_unsigned_long(a->shift_type, b->shift_type);
- if (result != 0) goto gasoc_done;
+ ea = GET_ARMV7_SHIFT_OP_EXTRA(a);
+ eb = GET_ARMV7_SHIFT_OP_EXTRA(b);
- result = g_arch_operand_compare(a->shift_value, b->shift_value);
+ if (lock)
+ {
+ LOCK_GOBJECT_EXTRA(ea);
+ LOCK_GOBJECT_EXTRA(eb);
+ }
- gasoc_done:
+ result = sort_unsigned_long(ea->shift_type, eb->shift_type);
+
+ if (result == 0)
+ result = g_arch_operand_compare(a->shift_value, b->shift_value);
+
+ if (result == 0)
+ {
+ class = G_ARCH_OPERAND_CLASS(g_armv7_shift_operand_parent_class);
+ result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false);
+ }
+
+ if (lock)
+ {
+ UNLOCK_GOBJECT_EXTRA(eb);
+ UNLOCK_GOBJECT_EXTRA(ea);
+ }
return result;
@@ -299,7 +444,11 @@ static GArchOperand *g_armv7_shift_operand_get_inner_operand_from_path(const GAr
static void g_armv7_shift_operand_print(const GArmV7ShiftOperand *operand, GBufferLine *line)
{
- switch (operand->shift_type)
+ SRType shift_type; /* Type porté par l'opérande */
+
+ shift_type = g_armv7_shift_operand_get_shift_type(operand);
+
+ switch (shift_type)
{
case SRType_LSL:
g_buffer_line_append_text(line, DLC_ASSEMBLY, "lsl", 3, RTT_KEY_WORD, NULL);
@@ -327,88 +476,68 @@ static void g_armv7_shift_operand_print(const GArmV7ShiftOperand *operand, GBuff
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : operand = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
* *
-* Description : Crée un réceptacle pour opérande de décalage ARMv7. *
+* Description : Charge un contenu depuis une mémoire tampon. *
* *
-* Retour : Opérande mis en place. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-GArchOperand *g_armv7_shift_operand_new(SRType type, GArchOperand *value)
+static bool g_armv7_shift_operand_load(GArmV7ShiftOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
- GArmV7ShiftOperand *result; /* Structure à retourner */
-
- result = g_object_new(G_TYPE_ARMV7_SHIFT_OPERAND, NULL);
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ a7shiftop_extra_data_t *extra; /* Données insérées à modifier */
+ uleb128_t value; /* Valeur ULEB128 à charger */
+ GSerializableObject *shift_value; /* Valeur du décalage */
- result->shift_type = type;
- result->shift_value = value;
+ parent = G_ARCH_OPERAND_CLASS(g_armv7_shift_operand_parent_class);
- return G_ARCH_OPERAND(result);
+ result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf);
-}
+ if (result)
+ {
+ extra = GET_ARMV7_SHIFT_OP_EXTRA(operand);
+ LOCK_GOBJECT_EXTRA(extra);
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Indique la forme de décalage représenté. *
-* *
-* Retour : Type de décalage. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ result = unpack_uleb128(&value, pbuf);
-SRType g_armv7_shift_operand_get_shift_type(const GArmV7ShiftOperand *operand)
-{
- return operand->shift_type;
+ if (result)
+ extra->shift_type = value;
-}
+ UNLOCK_GOBJECT_EXTRA(extra);
+ }
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Founit la valeur utilisée pour un décalage. *
-* *
-* Retour : Opérande en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ if (result)
+ {
+ shift_value = g_object_storage_unpack_object(storage, "operands", pbuf);
-GArchOperand *g_armv7_shift_operand_get_shift_value(const GArmV7ShiftOperand *operand)
-{
- GArchOperand *result; /* Instance à retourner */
+ result = (shift_value != NULL);
- result = operand->shift_value;
+ if (result)
+ operand->shift_value = G_ARCH_OPERAND(shift_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. *
+* Paramètres : operand = élément GLib à consulter. *
+* storage = conservateur de données à manipuler ou NULL. *
* pbuf = zone tampon à remplir. *
* *
-* Description : Charge un opérande depuis une mémoire tampon. *
+* Description : Sauvegarde un contenu dans une mémoire tampon. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -416,64 +545,34 @@ GArchOperand *g_armv7_shift_operand_get_shift_value(const GArmV7ShiftOperand *op
* *
******************************************************************************/
-static bool g_armv7_shift_operand_unserialize(GArmV7ShiftOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf)
+static bool g_armv7_shift_operand_store(GArmV7ShiftOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
- GArchOperand *value; /* Valeur à intégrer */
+ a7shiftop_extra_data_t *extra; /* Données insérées à modifier */
+ GSerializableObject *shift_value; /* Valeur du décalage */
parent = G_ARCH_OPERAND_CLASS(g_armv7_shift_operand_parent_class);
- result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
-
- if (result)
- result = extract_packed_buffer(pbuf, &operand->shift_type, sizeof(SRType), true);
+ result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
{
- value = g_arch_operand_load(storage, format, pbuf);
-
- if (value == NULL)
- result = false;
-
- else
- operand->shift_value = value;
-
- }
+ extra = GET_ARMV7_SHIFT_OP_EXTRA(operand);
- return result;
+ LOCK_GOBJECT_EXTRA(extra);
-}
+ result = pack_uleb128((uleb128_t []){ extra->shift_type }, pbuf);
+ UNLOCK_GOBJECT_EXTRA(extra);
-/******************************************************************************
-* *
-* Paramètres : operand = opérande d'assemblage à consulter. *
-* storage = mécanisme de sauvegarde à manipuler. *
-* pbuf = zone tampon à remplir. *
-* *
-* Description : Sauvegarde un opérande dans une mémoire tampon. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_armv7_shift_operand_serialize(const GArmV7ShiftOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf)
-{
- bool result; /* Bilan à retourner */
- GArchOperandClass *parent; /* Classe parente à consulter */
-
- parent = G_ARCH_OPERAND_CLASS(g_armv7_shift_operand_parent_class);
-
- result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
-
- if (result)
- result = extend_packed_buffer(pbuf, &operand->shift_type, sizeof(SRType), true);
+ }
if (result)
- result = g_arch_operand_store(operand->shift_value, storage, pbuf);
+ {
+ shift_value = G_SERIALIZABLE_OBJECT(operand->shift_value);
+ result = g_object_storage_pack_object(storage, "operands", shift_value, pbuf);
+ }
return result;