diff options
Diffstat (limited to 'plugins/arm/v7/operands/limitation.c')
-rw-r--r-- | plugins/arm/v7/operands/limitation.c | 263 |
1 files changed, 180 insertions, 83 deletions
diff --git a/plugins/arm/v7/operands/limitation.c b/plugins/arm/v7/operands/limitation.c index 0d29545..5d22681 100644 --- a/plugins/arm/v7/operands/limitation.c +++ b/plugins/arm/v7/operands/limitation.c @@ -30,13 +30,24 @@ +/* -------------------------- DEFINITION D'UN NOUVEAU TYPE -------------------------- */ + + +/* Informations glissées dans la structure GObject de GArchOperand */ +typedef struct _a7limop_extra_data_t +{ + operand_extra_data_t parent; /* A laisser en premier */ + + BarrierLimitationType type; /* Type de limitation */ + +} a7limop_extra_data_t; + + /* Définition d'un opérande déterminant une limitation de domaine et d'accès (instance) */ struct _GArmV7LimitationOperand { GArchOperand parent; /* Instance parente */ - BarrierLimitationType type; /* Type de limitation */ - }; @@ -48,6 +59,21 @@ struct _GArmV7LimitationOperandClass }; +/** + * Accès aux informations éventuellement déportées. + */ + +#if __SIZEOF_INT__ == __SIZEOF_LONG__ + +# define GET_ARMV7_LIMITATION_OP_EXTRA(op) (a7limop_extra_data_t *)&op->extra + +#else + +# define GET_ARMV7_LIMITATION_OP_EXTRA(op) GET_GOBJECT_EXTRA(G_OBJECT(op), a7limop_extra_data_t) + +#endif + + /* Initialise la classe des co-processeurs ARM. */ static void g_armv7_limitation_operand_class_init(GArmV7LimitationOperandClass *); @@ -60,23 +86,28 @@ static void g_armv7_limitation_operand_dispose(GArmV7LimitationOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_limitation_operand_finalize(GArmV7LimitationOperand *); + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + /* Compare un opérande avec un autre. */ -static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *, const GArmV7LimitationOperand *); +static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *, const GArmV7LimitationOperand *, bool); /* Traduit un opérande en version humainement lisible. */ static void g_armv7_limitation_operand_print(const GArmV7LimitationOperand *, GBufferLine *); +/* Charge un contenu depuis une mémoire tampon. */ +static bool g_armv7_limitation_operand_load(GArmV7LimitationOperand *, GObjectStorage *, packed_buffer_t *); - -/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ +/* Sauvegarde un contenu dans une mémoire tampon. */ +static bool g_armv7_limitation_operand_store(GArmV7LimitationOperand *, GObjectStorage *, packed_buffer_t *); -/* Charge un opérande depuis une mémoire tampon. */ -static bool g_armv7_limitation_operand_unserialize(GArmV7LimitationOperand *, GAsmStorage *, GBinFormat *, packed_buffer_t *); - -/* Sauvegarde un opérande dans une mémoire tampon. */ -static bool g_armv7_limitation_operand_serialize(const GArmV7LimitationOperand *, GAsmStorage *, packed_buffer_t *); +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UN NOUVEAU TYPE */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini par la GLib pour une limitation de domaine et d'accès. */ @@ -109,8 +140,8 @@ static void g_armv7_limitation_operand_class_init(GArmV7LimitationOperandClass * operand->compare = (operand_compare_fc)g_armv7_limitation_operand_compare; operand->print = (operand_print_fc)g_armv7_limitation_operand_print; - operand->unserialize = (unserialize_operand_fc)g_armv7_limitation_operand_unserialize; - operand->serialize = (serialize_operand_fc)g_armv7_limitation_operand_serialize; + operand->load = (load_operand_fc)g_armv7_limitation_operand_load; + operand->store = (store_operand_fc)g_armv7_limitation_operand_store; } @@ -173,8 +204,77 @@ static void g_armv7_limitation_operand_finalize(GArmV7LimitationOperand *operand /****************************************************************************** * * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * +* Paramètres : raw = valeur brute de la limitation à considérer. * +* * +* Description : Crée une représentation d'une limitation pour barrière. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_limitation_operand_new(uint8_t raw) +{ + GArmV7LimitationOperand *result; /* Structure à retourner */ + a7limop_extra_data_t *extra; /* Données insérées à modifier */ + + result = g_object_new(G_TYPE_ARMV7_LIMITATION_OPERAND, NULL); + + extra = GET_ARMV7_LIMITATION_OP_EXTRA(result); + + if (raw < 0b0010 || raw > 0b1111) + extra->type = BLT_RESERVED; + + else + extra->type = raw; + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à consulter. * +* * +* Description : Indique le type de limitation représentée. * +* * +* Retour : Type de limitation d'accès et de domaine. * +* * +* Remarques : - * +* * +******************************************************************************/ + +BarrierLimitationType g_armv7_limitation_operand_get_value(const GArmV7LimitationOperand *operand) +{ + BarrierLimitationType result; /* Type à retourner */ + a7limop_extra_data_t *extra; /* Données insérées à consulter*/ + + extra = GET_ARMV7_LIMITATION_OP_EXTRA(operand); + + LOCK_GOBJECT_EXTRA(extra); + + result = extra->type; + + UNLOCK_GOBJECT_EXTRA(extra); + + 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. * * * @@ -184,11 +284,35 @@ static void g_armv7_limitation_operand_finalize(GArmV7LimitationOperand *operand * * ******************************************************************************/ -static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *a, const GArmV7LimitationOperand *b) +static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *a, const GArmV7LimitationOperand *b, bool lock) { int result; /* Bilan à faire remonter */ + a7limop_extra_data_t *ea; /* Données insérées à consulter*/ + a7limop_extra_data_t *eb; /* Données insérées à consulter*/ + GArchOperandClass *class; /* Classe parente normalisée */ + + ea = GET_ARMV7_LIMITATION_OP_EXTRA(a); + eb = GET_ARMV7_LIMITATION_OP_EXTRA(b); + + if (lock) + { + LOCK_GOBJECT_EXTRA(ea); + LOCK_GOBJECT_EXTRA(eb); + } + + result = sort_unsigned_long(ea->type, eb->type); - result = sort_unsigned_long(a->type, b->type); + if (result == 0) + { + class = G_ARCH_OPERAND_CLASS(g_armv7_limitation_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; @@ -210,7 +334,11 @@ static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *a, static void g_armv7_limitation_operand_print(const GArmV7LimitationOperand *operand, GBufferLine *line) { - switch (operand->type) + BarrierLimitationType type; /* Type porté par l'opérande */ + + type = g_armv7_limitation_operand_get_value(operand); + + switch (type) { case BLT_SY: g_buffer_line_append_text(line, DLC_ASSEMBLY, "SY", 2, RTT_KEY_WORD, NULL); @@ -255,66 +383,56 @@ static void g_armv7_limitation_operand_print(const GArmV7LimitationOperand *oper /****************************************************************************** * * -* Paramètres : raw = valeur brute de la limitation à considérer. * +* Paramètres : operand = élément GLib à constuire. * +* storage = conservateur de données à manipuler ou NULL. * +* pbuf = zone tampon à lire. * * * -* Description : Crée une représentation d'une limitation pour barrière. * +* 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_limitation_operand_new(uint8_t raw) +static bool g_armv7_limitation_operand_load(GArmV7LimitationOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) { - GArmV7LimitationOperand *result; /* Structure à retourner */ + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + a7limop_extra_data_t *extra; /* Données insérées à modifier */ + uleb128_t value; /* Valeur ULEB128 à charger */ - result = g_object_new(G_TYPE_ARMV7_LIMITATION_OPERAND, NULL); + parent = G_ARCH_OPERAND_CLASS(g_armv7_limitation_operand_parent_class); - if (raw < 0b0010 || raw > 0b1111) - result->type = BLT_RESERVED; + result = parent->load(G_ARCH_OPERAND(operand), storage, pbuf); - else - result->type = raw; + if (result) + { + extra = GET_ARMV7_LIMITATION_OP_EXTRA(operand); - return G_ARCH_OPERAND(result); + LOCK_GOBJECT_EXTRA(extra); -} + result = unpack_uleb128(&value, pbuf); + if (result) + extra->type = value; -/****************************************************************************** -* * -* Paramètres : operand = opérande à consulter. * -* * -* Description : Indique le type de limitation représentée. * -* * -* Retour : Type de limitation d'accès et de domaine. * -* * -* Remarques : - * -* * -******************************************************************************/ - -BarrierLimitationType g_armv7_limitation_operand_get_value(const GArmV7LimitationOperand *operand) -{ - return operand->type; - -} + UNLOCK_GOBJECT_EXTRA(extra); + } + 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. * * * @@ -322,48 +440,27 @@ BarrierLimitationType g_armv7_limitation_operand_get_value(const GArmV7Limitatio * * ******************************************************************************/ -static bool g_armv7_limitation_operand_unserialize(GArmV7LimitationOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer_t *pbuf) +static bool g_armv7_limitation_operand_store(GArmV7LimitationOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ GArchOperandClass *parent; /* Classe parente à consulter */ + a7limop_extra_data_t *extra; /* Données insérées à modifier */ parent = G_ARCH_OPERAND_CLASS(g_armv7_limitation_operand_parent_class); - result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); + result = parent->store(G_ARCH_OPERAND(operand), storage, pbuf); if (result) - result = extract_packed_buffer(pbuf, &operand->type, sizeof(BarrierLimitationType), true); - - return result; - -} - - -/****************************************************************************** -* * -* 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 : - * -* * -******************************************************************************/ + { + extra = GET_ARMV7_LIMITATION_OP_EXTRA(operand); -static bool g_armv7_limitation_operand_serialize(const GArmV7LimitationOperand *operand, GAsmStorage *storage, packed_buffer_t *pbuf) -{ - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ + LOCK_GOBJECT_EXTRA(extra); - parent = G_ARCH_OPERAND_CLASS(g_armv7_limitation_operand_parent_class); + result = pack_uleb128((uleb128_t []){ extra->type }, pbuf); - result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + UNLOCK_GOBJECT_EXTRA(extra); - if (result) - result = extend_packed_buffer(pbuf, &operand->type, sizeof(BarrierLimitationType), true); + } return result; |