summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/register.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-05-11 14:10:49 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-05-11 14:10:49 (GMT)
commiteaf46c79d5b1db06f1f1f7da17a37ec007af2d92 (patch)
tree63126e13d1524cac5259d02a5df281c6055075dd /plugins/arm/v7/register.c
parentb24aca86f0a096730fa8df440f7493556b39ae46 (diff)
Implemented a singleton system for ARMv7 registers.
Diffstat (limited to 'plugins/arm/v7/register.c')
-rw-r--r--plugins/arm/v7/register.c136
1 files changed, 135 insertions, 1 deletions
diff --git a/plugins/arm/v7/register.c b/plugins/arm/v7/register.c
index 1b17062..c2e15b0 100644
--- a/plugins/arm/v7/register.c
+++ b/plugins/arm/v7/register.c
@@ -31,6 +31,9 @@
+/* ------------------------- GESTION UNITAIRE DES REGISTRES ------------------------- */
+
+
/* Représentation d'un registre ARMv7 (instance) */
struct _GArmV7Register
{
@@ -65,6 +68,29 @@ static void g_armv7_register_finalize(GArmV7Register *);
/* Traduit un registre en version humainement lisible. */
static void g_armv7_register_print(const GArmV7Register *, GBufferLine *, AsmSyntax);
+/* Crée une réprésentation de registre ARMv7. */
+static GArmV7Register *_g_armv7_register_new(uint8_t);
+
+
+
+/* ------------------------ GESTION SOUS FORME DE SINGLETONS ------------------------ */
+
+
+/* Conservation des registres utilisés */
+static GArmV7Register **_armv7_registers = NULL;
+static size_t _av7reg_count = 0;
+G_LOCK_DEFINE_STATIC(_av7reg_mutex);
+
+
+/* Fournit le singleton associé à un registre ARMv7. */
+static GArmV7Register *get_armv7_register(uint8_t);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GESTION UNITAIRE DES REGISTRES */
+/* ---------------------------------------------------------------------------------- */
+
/* Indique le type défini pour une représentation d'un registre ARMv7. */
@@ -216,7 +242,7 @@ static void g_armv7_register_print(const GArmV7Register *reg, GBufferLine *line,
* *
******************************************************************************/
-GArmV7Register *g_armv7_register_new(uint8_t index)
+static GArmV7Register *_g_armv7_register_new(uint8_t index)
{
GArmV7Register *result; /* Structure à retourner */
@@ -227,3 +253,111 @@ GArmV7Register *g_armv7_register_new(uint8_t index)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : index = indice du registre correspondant. *
+* *
+* Description : Crée une réprésentation de registre ARMv7. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArmV7Register *g_armv7_register_new(uint8_t index)
+{
+ GArmV7Register *result; /* Structure à retourner */
+
+ result = get_armv7_register(index);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GESTION SOUS FORME DE SINGLETONS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : index = indice du registre correspondant. *
+* *
+* Description : Fournit le singleton associé à un registre ARMv7. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GArmV7Register *get_armv7_register(uint8_t index)
+{
+ GArmV7Register *result; /* Structure à retourner */
+ size_t new_count; /* Nouvelle taille à considérer*/
+ size_t i; /* Boucle de parcours */
+
+ G_LOCK(_av7reg_mutex);
+
+ if (index >= _av7reg_count)
+ {
+ new_count = index + 1;
+
+ _armv7_registers = realloc(_armv7_registers, new_count * sizeof(GArmV7Register *));
+
+ for (i = _av7reg_count; i < new_count; i++)
+ _armv7_registers[i] = NULL;
+
+ _av7reg_count = new_count;
+
+ }
+
+ if (_armv7_registers[index] == NULL)
+ _armv7_registers[index] = _g_armv7_register_new(index);
+
+ result = _armv7_registers[index];
+
+ G_UNLOCK(_av7reg_mutex);
+
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Vide totalement le cache des registres ARMv7. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void clean_armv7_register_cache(void)
+{
+ size_t i; /* Boucle de parcours */
+
+ G_LOCK(_av7reg_mutex);
+
+ for (i = 0; i < _av7reg_count; i++)
+ g_object_unref(G_OBJECT(_armv7_registers[i]));
+
+ if (_armv7_registers != NULL)
+ free(_armv7_registers);
+
+ _armv7_registers = NULL;
+ _av7reg_count = 0;
+
+ G_UNLOCK(_av7reg_mutex);
+
+}