diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-05-14 19:40:07 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-05-14 19:40:07 (GMT) |
commit | 0286b53bad21abf91cbe17c4772ca9cde6a89cbc (patch) | |
tree | 3bec9dc7e118c00ce9c748576b01606a71880ad7 /src/arch/target.c | |
parent | 267b1ae8608ed4bf52de743798e8647c903ee1b4 (diff) |
Created an instruction database for Chrysalide.
Diffstat (limited to 'src/arch/target.c')
-rw-r--r-- | src/arch/target.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/arch/target.c b/src/arch/target.c index 3b5655e..a297a3c 100644 --- a/src/arch/target.c +++ b/src/arch/target.c @@ -47,6 +47,7 @@ struct _GTargetOperand MemoryDataSize size; /* Taille de l'opérande */ vmpa2t addr; /* Adresse de l'élément visé */ + bool strict; /* Résolution stricte */ GBinSymbol *symbol; /* Eventuel symbole associé */ phys_t diff; /* Position dans le symbole */ @@ -84,6 +85,17 @@ static char *g_target_operand_build_tooltip(const GTargetOperand *, const GLoade +/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ + + +/* Charge un opérande depuis une mémoire tampon. */ +static bool g_target_operand_unserialize(GTargetOperand *, GAsmStorage *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un opérande dans une mémoire tampon. */ +static bool g_target_operand_serialize(const GTargetOperand *, GAsmStorage *, packed_buffer *); + + + /* Indique le type défini pour un opérande de valeur numérique. */ G_DEFINE_TYPE(GTargetOperand, g_target_operand, G_TYPE_ARCH_OPERAND); @@ -116,6 +128,9 @@ static void g_target_operand_class_init(GTargetOperandClass *klass) operand->print = (operand_print_fc)g_target_operand_print; operand->build_tooltip = (operand_build_tooltip_fc)g_target_operand_build_tooltip; + operand->unserialize = (unserialize_operand_fc)g_target_operand_unserialize; + operand->serialize = (serialize_operand_fc)g_target_operand_serialize; + } @@ -136,6 +151,7 @@ static void g_target_operand_init(GTargetOperand *operand) operand->size = MDS_UNDEFINED; init_vmpa(&operand->addr, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); + operand->strict = true; operand->symbol = NULL; operand->diff = 0; @@ -324,6 +340,8 @@ GArchOperand *g_target_operand_new(MemoryDataSize size, const vmpa2t *addr) result = g_object_new(G_TYPE_TARGET_OPERAND, NULL); + assert(size != MDS_UNDEFINED); + result->size = size; copy_vmpa(&result->addr, addr); @@ -466,8 +484,12 @@ bool g_target_operand_resolve(GTargetOperand *operand, GBinFormat *format, bool if (operand->symbol != NULL) g_object_unref(G_OBJECT(operand->symbol)); + operand->strict = strict; + result = g_binary_format_resolve_symbol(format, &operand->addr, strict, &operand->symbol, &operand->diff); + assert(!result || !strict || (strict && operand->diff == 0)); + /** * Si plusieurs chaînes se suivent, la seconde et les suivantes bénéficient * d'une étiquette si et seulement si elles sont détachées des précédentes @@ -539,3 +561,85 @@ GBinSymbol *g_target_operand_get_symbol(const GTargetOperand *operand, phys_t *d 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. * +* pbuf = zone tampon à remplir. * +* * +* Description : Charge un opérande depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_target_operand_unserialize(GTargetOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + + assert(false); + + /** + * Comme ce type d'opérande peut générer de nouveaux symboles lorsque + * sa résolution échoue, il faut appeler ces résolutions dans les contextes + * d'origine. + * + * Ces contextes sont généralement le lieu de conversions de valeurs immédiates + * en valeurs de cibles, donc la sérialisation de l'opérande conduit à + * la sauvegarde d'un opérande de valeur immédiate de subsitution. + * + * La désérialisation est donc prise en compte par ce dernier type d'opérande. + */ + + 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 : - * +* * +******************************************************************************/ + +static bool g_target_operand_serialize(const GTargetOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchOperand *original; /* Opérande d'origine */ + + /** + * Pour les architectures sans mémoire virtuelle, la valeur est portée + * par la position physique. + */ + + if (has_virt_addr(&operand->addr)) + original = g_imm_operand_new_from_value(operand->size, get_virt_addr(&operand->addr)); + else + original = g_imm_operand_new_from_value(operand->size, get_phy_addr(&operand->addr)); + + result = g_arch_operand_store(original, storage, pbuf); + + g_object_unref(G_OBJECT(original)); + + return result; + +} |