summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/operands/maccess.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/arm/v7/operands/maccess.c')
-rw-r--r--plugins/arm/v7/operands/maccess.c441
1 files changed, 174 insertions, 267 deletions
diff --git a/plugins/arm/v7/operands/maccess.c b/plugins/arm/v7/operands/maccess.c
index 07f38a6..0b0d0b4 100644
--- a/plugins/arm/v7/operands/maccess.c
+++ b/plugins/arm/v7/operands/maccess.c
@@ -31,12 +31,14 @@
#include <arch/operand-int.h>
#include <common/cpp.h>
-#include <common/sort.h>
#include <core/logs.h>
#include <gtkext/gtkblockdisplay.h>
+/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */
+
+
/* Définition d'un opérande offrant un accès à la mémoire depuis une base (instance) */
struct _GArmV7MAccessOperand
{
@@ -45,8 +47,6 @@ struct _GArmV7MAccessOperand
GArchOperand *base; /* Base de l'accès en mémoire */
GArchOperand *offset; /* Décalage pour l'adresse */
GArchOperand *shift; /* Décalage supplémentaire ? */
- bool post_indexed; /* Position du décalage */
- bool write_back; /* Mise à jour de la base */
};
@@ -71,8 +71,13 @@ static void g_armv7_maccess_operand_dispose(GArmV7MAccessOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_armv7_maccess_operand_finalize(GArmV7MAccessOperand *);
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
/* Compare un opérande avec un autre. */
-static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *, const GArmV7MAccessOperand *);
+static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *, const GArmV7MAccessOperand *, bool);
/* Détermine le chemin conduisant à un opérande interne. */
static char *g_armv7_maccess_operand_find_inner_operand_path(const GArmV7MAccessOperand *, const GArchOperand *);
@@ -83,17 +88,17 @@ static GArchOperand *g_armv7_maccess_operand_get_inner_operand_from_path(const G
/* Traduit un opérande en version humainement lisible. */
static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *, GBufferLine *);
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_armv7_maccess_operand_load(GArmV7MAccessOperand *, GObjectStorage *, packed_buffer_t *);
-
-/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_armv7_maccess_operand_store(GArmV7MAccessOperand *, GObjectStorage *, packed_buffer_t *);
-/* Charge un opérande depuis une mémoire tampon. */
-static bool g_armv7_maccess_operand_unserialize(GArmV7MAccessOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *);
-
-/* Sauvegarde un opérande dans une mémoire tampon. */
-static bool g_armv7_maccess_operand_serialize(const GArmV7MAccessOperand *, GAsmStorage *, packed_buffer_t *);
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN NOUVEAU TYPE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini par la GLib pour un accès à la mémoire depuis une base. */
@@ -130,8 +135,8 @@ static void g_armv7_maccess_operand_class_init(GArmV7MAccessOperandClass *klass)
operand->print = (operand_print_fc)g_armv7_maccess_operand_print;
- operand->unserialize = (unserialize_operand_fc)g_armv7_maccess_operand_unserialize;
- operand->serialize = (serialize_operand_fc)g_armv7_maccess_operand_serialize;
+ operand->load = (load_operand_fc)g_armv7_maccess_operand_load;
+ operand->store = (store_operand_fc)g_armv7_maccess_operand_store;
}
@@ -171,14 +176,9 @@ static void g_armv7_maccess_operand_init(GArmV7MAccessOperand *operand)
static void g_armv7_maccess_operand_dispose(GArmV7MAccessOperand *operand)
{
- if (operand->base != NULL)
- g_object_unref(G_OBJECT(operand->base));
-
- if (operand->offset != NULL)
- g_object_unref(G_OBJECT(operand->offset));
-
- if (operand->shift != NULL)
- g_object_unref(G_OBJECT(operand->shift));
+ g_clear_object(&operand->base);
+ g_clear_object(&operand->offset);
+ g_clear_object(&operand->shift);
G_OBJECT_CLASS(g_armv7_maccess_operand_parent_class)->dispose(G_OBJECT(operand));
@@ -206,8 +206,109 @@ static void g_armv7_maccess_operand_finalize(GArmV7MAccessOperand *operand)
/******************************************************************************
* *
-* Paramètres : a = premier opérande à consulter. *
-* b = second opérande à consulter. *
+* Paramètres : base = représente le registre de la base d'accès. *
+* offset = détermine le décalage entre l'adresse et la base. *
+* shift = opération de décalage pour jouer sur le décalage. *
+* post = précise la forme donnée au décalage à appliquer. *
+* wback = indique une mise à jour de la base après usage. *
+* *
+* Description : Crée un accès à la mémoire depuis une base et un décalage. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_maccess_operand_new(GArchOperand *base, GArchOperand *offset, GArchOperand *shift, bool post, bool wback)
+{
+ GArmV7MAccessOperand *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ARMV7_MACCESS_OPERAND, NULL);
+
+ result->base = base;
+ result->offset = offset;
+ result->shift = shift;
+
+ if (post)
+ g_arch_operand_set_flag(G_ARCH_OPERAND(result), A7MAOF_POST_INDEXED);
+
+ if (wback)
+ g_arch_operand_set_flag(G_ARCH_OPERAND(result), A7MAOF_WRITE_BACK);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Founit la base d'un accès à la mémoire. *
+* *
+* Retour : Opérande en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_maccess_operand_get_base(const GArmV7MAccessOperand *operand)
+{
+ return operand->base;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Founit le décalage d'un accès à la mémoire depuis la base. *
+* *
+* Retour : Opérande en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_maccess_operand_get_offset(const GArmV7MAccessOperand *operand)
+{
+ return operand->offset;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Founit le décalage d'un décalage pour un accès mémoire. *
+* *
+* Retour : Opérande en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_armv7_maccess_operand_get_shift(const GArmV7MAccessOperand *operand)
+{
+ return operand->shift;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* 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. *
* *
@@ -217,25 +318,24 @@ static void g_armv7_maccess_operand_finalize(GArmV7MAccessOperand *operand)
* *
******************************************************************************/
-static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *a, const GArmV7MAccessOperand *b)
+static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *a, const GArmV7MAccessOperand *b, bool lock)
{
int result; /* Bilan à faire remonter */
+ GArchOperandClass *class; /* Classe parente normalisée */
result = g_arch_operand_compare(a->base, b->base);
- if (result != 0) goto gamoc_done;
-
- result = sort_pointer(a->offset, b->offset, (__compar_fn_t)g_arch_operand_compare);
- if (result != 0) goto gamoc_done;
- result = sort_pointer(a->shift, b->shift, (__compar_fn_t)g_arch_operand_compare);
- if (result != 0) goto gamoc_done;
-
- result = sort_boolean(a->post_indexed, b->post_indexed);
- if (result != 0) goto gamoc_done;
+ if (result)
+ result = g_arch_operand_compare(a->offset, b->offset);
- result = sort_boolean(a->write_back, b->write_back);
+ if (result)
+ result = g_arch_operand_compare(a->shift, b->shift);
- gamoc_done:
+ if (result == 0)
+ {
+ class = G_ARCH_OPERAND_CLASS(g_armv7_maccess_operand_parent_class);
+ result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b), false);
+ }
return result;
@@ -392,11 +492,17 @@ static GArchOperand *g_armv7_maccess_operand_get_inner_operand_from_path(const G
static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *operand, GBufferLine *line)
{
+ bool post; /* Forme post-indexée ? */
+ bool wback; /* Ecriture après coup ? */
+
+ post = g_arch_operand_has_flag(G_ARCH_OPERAND(operand), A7MAOF_POST_INDEXED);
+ wback = g_arch_operand_has_flag(G_ARCH_OPERAND(operand), A7MAOF_WRITE_BACK);
+
g_buffer_line_append_text(line, DLC_ASSEMBLY, "[", 1, RTT_HOOK, NULL);
g_arch_operand_print(operand->base, line);
- if (operand->post_indexed)
+ if (post)
g_buffer_line_append_text(line, DLC_ASSEMBLY, "]", 1, RTT_HOOK, NULL);
if (operand->offset != NULL)
@@ -417,10 +523,10 @@ static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *operand, G
}
- if (!operand->post_indexed)
+ if (!post)
g_buffer_line_append_text(line, DLC_ASSEMBLY, "]", 1, RTT_HOOK, NULL);
- if (operand->post_indexed && operand->write_back)
+ if (post && wback)
g_buffer_line_append_text(line, DLC_ASSEMBLY, "!", 1, RTT_PUNCT, NULL);
}
@@ -428,147 +534,11 @@ static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *operand, G
/******************************************************************************
* *
-* Paramètres : base = représente le registre de la base d'accès. *
-* offset = détermine le décalage entre l'adresse et la base. *
-* shift = opération de décalage pour jouer sur le décalage. *
-* post = précise la forme donnée au décalage à appliquer. *
-* wback = indique une mise à jour de la base après usage. *
-* *
-* Description : Crée un accès à la mémoire depuis une base et un décalage. *
+* Paramètres : operand = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
* *
-* Retour : Opérande mis en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_maccess_operand_new(GArchOperand *base, GArchOperand *offset, GArchOperand *shift, bool post, bool wback)
-{
- GArmV7MAccessOperand *result; /* Structure à retourner */
-
- result = g_object_new(G_TYPE_ARMV7_MACCESS_OPERAND, NULL);
-
- result->base = base;
- result->offset = offset;
- result->shift = shift;
-
- result->post_indexed = post;
- result->write_back = wback;
-
- return G_ARCH_OPERAND(result);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Founit la base d'un accès à la mémoire. *
-* *
-* Retour : Opérande en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_maccess_operand_get_base(const GArmV7MAccessOperand *operand)
-{
- return operand->base;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Founit le décalage d'un accès à la mémoire depuis la base. *
-* *
-* Retour : Opérande en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_maccess_operand_get_offset(const GArmV7MAccessOperand *operand)
-{
- return operand->offset;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Founit le décalage d'un décalage pour un accès mémoire. *
-* *
-* Retour : Opérande en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GArchOperand *g_armv7_maccess_operand_get_shift(const GArmV7MAccessOperand *operand)
-{
- return operand->shift;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Indique si le décalage est post-indexé. *
-* *
-* Retour : Statut des opérations menées. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_armv7_maccess_operand_is_post_indexed(const GArmV7MAccessOperand *operand)
-{
- return operand->post_indexed;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* *
-* Description : Indique si la base est mise à jour après usage. *
-* *
-* Retour : Statut des opérations menées. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_armv7_maccess_operand_has_to_write_back(const GArmV7MAccessOperand *operand)
-{
- return operand->write_back;
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* 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. *
* *
@@ -576,80 +546,46 @@ bool g_armv7_maccess_operand_has_to_write_back(const GArmV7MAccessOperand *opera
* *
******************************************************************************/
-static bool g_armv7_maccess_operand_unserialize(GArmV7MAccessOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf)
+static bool g_armv7_maccess_operand_load(GArmV7MAccessOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
- GArchOperand *subop; /* Sous-opérande à intégrer */
- uint8_t boolean; /* Valeur booléenne */
+ GSerializableObject *obj; /* Instance à manipuler */
parent = G_ARCH_OPERAND_CLASS(g_armv7_maccess_operand_parent_class);
- result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
-
- if (result)
- {
- subop = g_arch_operand_load(storage, format, pbuf);
-
- if (subop == NULL)
- result = false;
-
- else
- operand->base = subop;
-
- }
+ result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
{
- result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
-
- if (result && boolean == 1)
- {
- subop = g_arch_operand_load(storage, format, pbuf);
+ obj = g_object_storage_unpack_object(storage, "operands", pbuf);
- if (subop == NULL)
- result = false;
+ result = (obj != NULL);
- else
- operand->offset = subop;
-
- }
+ if (result)
+ operand->base = G_ARCH_OPERAND(obj);
}
if (result)
{
- result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
-
- if (result && boolean == 1)
- {
- subop = g_arch_operand_load(storage, format, pbuf);
-
- if (subop == NULL)
- result = false;
+ obj = g_object_storage_unpack_object(storage, "operands", pbuf);
- else
- operand->shift = subop;
-
- }
-
- }
-
- if (result)
- {
- result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+ result = (obj != NULL);
if (result)
- operand->post_indexed = (boolean == 1 ? true : false);
+ operand->offset = G_ARCH_OPERAND(obj);
}
if (result)
{
- result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+ obj = g_object_storage_unpack_object(storage, "operands", pbuf);
+
+ result = (obj != NULL);
if (result)
- operand->write_back = (boolean == 1 ? true : false);
+ operand->shift = G_ARCH_OPERAND(obj);
}
@@ -660,11 +596,11 @@ static bool g_armv7_maccess_operand_unserialize(GArmV7MAccessOperand *operand, G
/******************************************************************************
* *
-* 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. *
* *
@@ -672,61 +608,32 @@ static bool g_armv7_maccess_operand_unserialize(GArmV7MAccessOperand *operand, G
* *
******************************************************************************/
-static bool g_armv7_maccess_operand_serialize(const GArmV7MAccessOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf)
+static bool g_armv7_maccess_operand_store(GArmV7MAccessOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
GArchOperandClass *parent; /* Classe parente à consulter */
- uint8_t boolean; /* Valeur booléenne */
+ GSerializableObject *obj; /* Instance à manipuler */
parent = G_ARCH_OPERAND_CLASS(g_armv7_maccess_operand_parent_class);
- result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
-
- if (result)
- result = g_arch_operand_store(operand->base, storage, pbuf);
+ result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf);
if (result)
{
- if (operand->offset == NULL)
- result = extend_packed_buffer(pbuf, (uint8_t []) { 0 }, sizeof(uint8_t), false);
-
- else
- {
- result = extend_packed_buffer(pbuf, (uint8_t []) { 1 }, sizeof(uint8_t), false);
-
- if (result)
- result = g_arch_operand_store(operand->offset, storage, pbuf);
-
- }
-
- }
-
- if (result)
- {
- if (operand->shift == NULL)
- result = extend_packed_buffer(pbuf, (uint8_t []) { 0 }, sizeof(uint8_t), false);
-
- else
- {
- result = extend_packed_buffer(pbuf, (uint8_t []) { 1 }, sizeof(uint8_t), false);
-
- if (result)
- result = g_arch_operand_store(operand->shift, storage, pbuf);
-
- }
-
+ obj = G_SERIALIZABLE_OBJECT(operand->base);
+ result = g_object_storage_pack_object(storage, "operands", obj, pbuf);
}
if (result)
{
- boolean = (operand->post_indexed ? 1 : 0);
- result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+ obj = G_SERIALIZABLE_OBJECT(operand->offset);
+ result = g_object_storage_pack_object(storage, "operands", obj, pbuf);
}
if (result)
{
- boolean = (operand->write_back ? 1 : 0);
- result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+ obj = G_SERIALIZABLE_OBJECT(operand->shift);
+ result = g_object_storage_pack_object(storage, "operands", obj, pbuf);
}
return result;