diff options
Diffstat (limited to 'src/arch/instruction.c')
-rw-r--r-- | src/arch/instruction.c | 117 |
1 files changed, 73 insertions, 44 deletions
diff --git a/src/arch/instruction.c b/src/arch/instruction.c index 72911bf..3a62a90 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -39,6 +39,12 @@ static void g_arch_instruction_class_init(GArchInstructionClass *); /* Initialise une instance d'opérande d'architecture. */ static void g_arch_instruction_init(GArchInstruction *); +/* Supprime toutes les références externes. */ +static void g_arch_instruction_dispose(GArchInstruction *); + +/* Procède à la libération totale de la mémoire. */ +static void g_arch_instruction_finalize(GArchInstruction *); + /* --------------------- CONVERSIONS DU FORMAT DES INSTRUCTIONS --------------------- */ @@ -67,6 +73,17 @@ G_DEFINE_TYPE(GArchInstruction, g_arch_instruction, G_TYPE_OBJECT); static void g_arch_instruction_class_init(GArchInstructionClass *klass) { + GObjectClass *object; /* Autre version de la classe */ + GArchInstructionClass *instr; /* Encore une autre vision... */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_arch_instruction_dispose; + object->finalize = (GObjectFinalizeFunc)g_arch_instruction_finalize; + + instr = G_ARCH_INSTRUCTION_CLASS(klass); + + instr->print = (print_instruction_fc)_g_arch_instruction_print; } @@ -92,10 +109,47 @@ static void g_arch_instruction_init(GArchInstruction *instr) /****************************************************************************** * * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_instruction_dispose(GArchInstruction *instr) +{ + G_OBJECT_CLASS(g_arch_instruction_parent_class)->dispose(G_OBJECT(instr)); + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_instruction_finalize(GArchInstruction *instr) +{ + G_OBJECT_CLASS(g_arch_instruction_parent_class)->finalize(G_OBJECT(instr)); + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction quelconque à modifier. * -* offset = position physique dans le code binaire. * +* address = adresse virtuelle et/ou position physique. * * length = taille de l'instruction. * -* address = adresse virtuelle ou position physique. * * * * Description : Définit la localisation d'une instruction. * * * @@ -105,12 +159,15 @@ static void g_arch_instruction_init(GArchInstruction *instr) * * ******************************************************************************/ -void g_arch_instruction_set_location(GArchInstruction *instr, off_t offset, off_t length, vmpa_t address) +void g_arch_instruction_set_location(GArchInstruction *instr, const vmpa2t *address, off_t length) { - instr->offset = offset; - instr->length = length; + copy_vmpa(&instr->address2, address); + + /* FIXME */ + instr->offset = get_phy_addr(address); + instr->address = get_virt_addr(address); - instr->address = address; + instr->length = length; } @@ -578,6 +635,7 @@ size_t g_arch_instruction_compute_group_index(GArchInstruction **iter, GArchInst /****************************************************************************** * * * Paramètres : instr = instruction d'assemblage à consulter. * +* syntax = type de représentation demandée. * * * * Description : Fournit le nom humain de l'instruction manipulée. * * * @@ -587,9 +645,9 @@ size_t g_arch_instruction_compute_group_index(GArchInstruction **iter, GArchInst * * ******************************************************************************/ -const char *g_arch_instruction_get_keyword(const GArchInstruction *instr) +const char *g_arch_instruction_get_keyword(const GArchInstruction *instr, AsmSyntax syntax) { - return instr->get_text(instr, NULL/* FIXME */, 0/* FIXME */); + G_ARCH_INSTRUCTION_GET_CLASS(instr)->get_key(instr, syntax); } @@ -611,42 +669,17 @@ const char *g_arch_instruction_get_keyword(const GArchInstruction *instr) static void _g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) { GBufferLine *line; /* Ligne de destination */ - char address[VMPA_MAX_SIZE]; /* Adresse au format texte */ - size_t len; /* Taille de l'élément inséré */ - char *bin_code; /* Tampon du code binaire */ - off_t i; /* Boucle de parcours #1 */ const char *key; /* Mot clef principal */ size_t klen; /* Taille de ce mot clef */ - size_t j; /* Boucle de parcours #2 */ - - line = g_code_buffer_append_new_line(buffer, instr->address); - - /* Adresse virtuelle ou physique */ - - len = vmpa_to_string(instr->address, msize, address); - - g_buffer_line_insert_text(line, BLC_ADDRESS, address, len, RTT_RAW); - - /* Code brut */ - - bin_code = (char *)calloc(instr->length * 3, sizeof(char)); - - for (i = 0; i < instr->length; i++) - { - if ((i + 1) < instr->length) - snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[instr->offset + i]); - else - snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[instr->offset + i]); - } + size_t i; /* Boucle de parcours */ - g_buffer_line_insert_text(line, BLC_BINARY, - bin_code, instr->length * 3 - 1, RTT_RAW_CODE); + line = g_code_buffer_append_new_line(buffer, &instr->address2); - free(bin_code); + g_buffer_line_fill_for_instr(line, msize/* TODO ! */, msize, content, instr->length, true); /* Instruction proprement dite */ - key = instr->get_text(instr, NULL/* FIXME */, 0/* FIXME */); + key = g_arch_instruction_get_keyword(instr, syntax); klen = strlen(key); g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, key, klen, RTT_INSTRUCTION); @@ -655,12 +688,12 @@ static void _g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer { g_arch_operand_print(instr->operands[0], line, syntax); - for (j = 1; j < instr->operands_count; j++) + for (i = 1; i < instr->operands_count; i++) { g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT); g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_RAW); - g_arch_operand_print(instr->operands[j], line, syntax); + g_arch_operand_print(instr->operands[i], line, syntax); } @@ -685,11 +718,7 @@ static void _g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer void g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) { - if (instr->print != NULL) - instr->print(instr, buffer, msize, content, syntax); - - else - _g_arch_instruction_print(instr, buffer, msize, content, syntax); + G_ARCH_INSTRUCTION_GET_CLASS(instr)->print(instr, buffer, msize, content, syntax); } |