diff options
Diffstat (limited to 'plugins/arm/v7/cregister.c')
-rw-r--r-- | plugins/arm/v7/cregister.c | 162 |
1 files changed, 145 insertions, 17 deletions
diff --git a/plugins/arm/v7/cregister.c b/plugins/arm/v7/cregister.c index 03607e2..7b39e02 100644 --- a/plugins/arm/v7/cregister.c +++ b/plugins/arm/v7/cregister.c @@ -31,6 +31,9 @@ +/* ------------------------- GESTION UNITAIRE DES REGISTRES ------------------------- */ + + /* Représentation d'un registre de co-processeur ARMv7 (instance) */ struct _GArmV7CRegister { @@ -63,6 +66,23 @@ static void g_armv7_cregister_finalize(GArmV7CRegister *); /* Traduit un registre en version humainement lisible. */ static void g_armv7_cregister_print(const GArmV7CRegister *, GBufferLine *, AsmSyntax); +/* Crée une réprésentation de registre de co-processeur ARMv7. */ +static GArmV7CRegister *_g_armv7_cregister_new(uint8_t); + + + +/* ------------------------ GESTION SOUS FORME DE SINGLETONS ------------------------ */ + + +/* Conservation des registres utilisés */ +static GArmV7CRegister **_armv7_cregisters = NULL; +static size_t _av7creg_count = 0; +G_LOCK_DEFINE_STATIC(_av7creg_mutex); + + +/* Fournit le singleton associé à un registre de co-proc. ARMv7. */ +static GArmV7CRegister *get_armv7_cregister(uint8_t); + /* Indique le type défini pour une représentation d'un registre de co-processeur ARMv7. */ @@ -155,6 +175,40 @@ static void g_armv7_cregister_finalize(GArmV7CRegister *reg) /****************************************************************************** * * +* Paramètres : reg = registre à transcrire. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un registre en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_cregister_print(const GArmV7CRegister *reg, GBufferLine *line, AsmSyntax syntax) +{ + char key[MAX_REGNAME_LEN]; /* Mot clef principal */ + size_t klen; /* Taille de ce mot clef */ + + switch (G_ARM_REGISTER(reg)->index) + { + case 0 ... 15: + klen = snprintf(key, MAX_REGNAME_LEN, "c%hhu", G_ARM_REGISTER(reg)->index); + break; + default: + klen = snprintf(key, MAX_REGNAME_LEN, "c??"); + break; + } + + g_buffer_line_append_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER, NULL); + +} + + +/****************************************************************************** +* * * Paramètres : index = indice du registre correspondant. * * * * Description : Crée une réprésentation de registre de co-processeur ARMv7. * @@ -165,7 +219,7 @@ static void g_armv7_cregister_finalize(GArmV7CRegister *reg) * * ******************************************************************************/ -GArmV7CRegister *g_armv7_cregister_new(uint8_t index) +static GArmV7CRegister *_g_armv7_cregister_new(uint8_t index) { GArmV7CRegister *result; /* Structure à retourner */ @@ -180,33 +234,107 @@ GArmV7CRegister *g_armv7_cregister_new(uint8_t index) /****************************************************************************** * * -* Paramètres : reg = registre à transcrire. * -* line = ligne tampon où imprimer l'opérande donné. * -* syntax = type de représentation demandée. * +* Paramètres : index = indice du registre correspondant. * * * -* Description : Traduit un registre en version humainement lisible. * +* Description : Crée une réprésentation de registre de co-processeur ARMv7. * * * -* Retour : - * +* Retour : Adresse de la structure mise en place. * * * * Remarques : - * * * ******************************************************************************/ -static void g_armv7_cregister_print(const GArmV7CRegister *reg, GBufferLine *line, AsmSyntax syntax) +GArmV7CRegister *g_armv7_cregister_new(uint8_t index) { - char key[MAX_REGNAME_LEN]; /* Mot clef principal */ - size_t klen; /* Taille de ce mot clef */ + GArmV7CRegister *result; /* Structure à retourner */ - switch (G_ARM_REGISTER(reg)->index) + result = get_armv7_cregister(index); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* GESTION SOUS FORME DE SINGLETONS */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : index = indice du registre correspondant. * +* * +* Description : Fournit le singleton associé à un registre de co-proc. ARMv7.* +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArmV7CRegister *get_armv7_cregister(uint8_t index) +{ + GArmV7CRegister *result; /* Structure à retourner */ + size_t new_count; /* Nouvelle taille à considérer*/ + size_t i; /* Boucle de parcours */ + + G_LOCK(_av7creg_mutex); + + if (index >= _av7creg_count) { - case 0 ... 15: - klen = snprintf(key, MAX_REGNAME_LEN, "c%hhu", G_ARM_REGISTER(reg)->index); - break; - default: - klen = snprintf(key, MAX_REGNAME_LEN, "c??"); - break; + new_count = index + 1; + + _armv7_cregisters = realloc(_armv7_cregisters, new_count * sizeof(GArmV7CRegister *)); + + for (i = _av7creg_count; i < new_count; i++) + _armv7_cregisters[i] = NULL; + + _av7creg_count = new_count; + } - g_buffer_line_append_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER, NULL); + if (_armv7_cregisters[index] == NULL) + _armv7_cregisters[index] = _g_armv7_cregister_new(index); + + result = _armv7_cregisters[index]; + + G_UNLOCK(_av7creg_mutex); + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Vide totalement le cache des registres ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void clean_armv7_cregister_cache(void) +{ + size_t i; /* Boucle de parcours */ + + G_LOCK(_av7creg_mutex); + + for (i = 0; i < _av7creg_count; i++) + g_object_unref(G_OBJECT(_armv7_cregisters[i])); + + if (_armv7_cregisters != NULL) + free(_armv7_cregisters); + + _armv7_cregisters = NULL; + _av7creg_count = 0; + + G_UNLOCK(_av7creg_mutex); } |