summaryrefslogtreecommitdiff
path: root/src/arch/instructions
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/instructions')
-rw-r--r--src/arch/instructions/raw.c62
-rw-r--r--src/arch/instructions/undefined-int.h56
-rw-r--r--src/arch/instructions/undefined.c30
3 files changed, 82 insertions, 66 deletions
diff --git a/src/arch/instructions/raw.c b/src/arch/instructions/raw.c
index 481dd1c..6340e46 100644
--- a/src/arch/instructions/raw.c
+++ b/src/arch/instructions/raw.c
@@ -213,17 +213,17 @@ static void g_raw_instruction_finalize(GRawInstruction *instr)
GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDataSize size, uint64_t value)
{
GArchInstruction *result; /* Instruction à retourner */
- GImmOperand *operand; /* Octet non décodé à afficher */
+ GArchOperand *operand; /* Octet non décodé à afficher */
mrange_t range; /* Couverture de l'instruction */
result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL);
- operand = G_IMM_OPERAND(g_imm_operand_new_from_value(size, value));
- if (operand == NULL) goto grinfv_error;
+ operand = g_imm_operand_new_from_value(size, value);
+ if (operand == NULL) goto error;
- g_imm_operand_pad(operand, true);
+ g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING);
- g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand));
+ g_arch_instruction_attach_extra_operand(result, operand);
switch (size)
{
@@ -249,7 +249,7 @@ GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDat
default:
assert(false);
- goto grinfv_error;
+ goto error;
break;
}
@@ -258,7 +258,7 @@ GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDat
return result;
- grinfv_error:
+ error:
g_object_unref(G_OBJECT(result));
@@ -287,13 +287,15 @@ GArchInstruction *g_raw_instruction_new_uleb128(const GBinContent *content, vmpa
uleb128_t value; /* Valeur uleb128 à représenter*/
phys_t diff; /* Couverture de la lecture */
MemoryDataSize leb_size; /* Taille de la valeur */
- GImmOperand *operand; /* Octet non décodé à afficher */
+ GArchOperand *operand; /* Octet non décodé à afficher */
mrange_t range; /* Couverture de l'instruction */
+ result = NULL;
+
copy_vmpa(&start, addr);
if (!g_binary_content_read_uleb128(content, addr, &value))
- goto grinu_error;
+ goto error;
diff = compute_vmpa_diff(&start, addr);
@@ -305,16 +307,18 @@ GArchInstruction *g_raw_instruction_new_uleb128(const GBinContent *content, vmpa
init_mrange(&range, &start, diff);
g_arch_instruction_set_range(result, &range);
- operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value));
- if (operand == NULL) goto grinu_error;
+ operand = g_imm_operand_new_from_value(leb_size, (uint64_t)value);
+ if (operand == NULL) goto error;
- g_imm_operand_pad(operand, true);
+ g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING);
- g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand));
+ g_arch_instruction_attach_extra_operand(result, operand);
return result;
- grinu_error:
+ error:
+
+ g_clear_object(&result);
return NULL;
@@ -341,13 +345,15 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa
uleb128_t value; /* Valeur uleb128 à représenter*/
phys_t diff; /* Couverture de la lecture */
MemoryDataSize leb_size; /* Taille de la valeur */
- GImmOperand *operand; /* Octet non décodé à afficher */
+ GArchOperand *operand; /* Octet non décodé à afficher */
mrange_t range; /* Couverture de l'instruction */
+ result = NULL;
+
copy_vmpa(&start, addr);
if (!g_binary_content_read_uleb128(content, addr, &value))
- goto grins_error;
+ goto error;
diff = compute_vmpa_diff(&start, addr);
@@ -359,16 +365,18 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa
init_mrange(&range, &start, diff);
g_arch_instruction_set_range(result, &range);
- operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value));
- if (operand == NULL) goto grins_error;
+ operand = g_imm_operand_new_from_value(leb_size, (uint64_t)value);
+ if (operand == NULL) goto error;
- g_imm_operand_pad(operand, true);
+ g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING);
- g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand));
+ g_arch_instruction_attach_extra_operand(result, operand);
return result;
- grins_error:
+ error:
+
+ g_clear_object(&result);
return NULL;
@@ -396,7 +404,7 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory
GArchInstruction *result; /* Instruction à retourner */
vmpa2t old; /* Sauvegarde de la position */
size_t i; /* Boucle de parcours */
- GImmOperand *operand; /* Octet non décodé à afficher */
+ GArchOperand *operand; /* Octet non décodé à afficher */
mrange_t range; /* Couverture de l'instruction */
/* Par soucis de cohérence */
@@ -408,12 +416,12 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory
for (i = 0; i < count; i++)
{
- operand = G_IMM_OPERAND(g_imm_operand_new_from_data(size, content, addr, endian));
- if (operand == NULL) goto grina_error;
+ operand = g_imm_operand_new_from_data(size, content, addr, endian);
+ if (operand == NULL) goto error;
- g_imm_operand_pad(operand, true);
+ g_arch_operand_set_flag(operand, IOF_ZERO_PADDING_BY_DEFAULT | IOF_ZERO_PADDING);
- g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand));
+ g_arch_instruction_attach_extra_operand(result, operand);
}
@@ -423,7 +431,7 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory
return result;
- grina_error:
+ error:
g_object_unref(G_OBJECT(result));
diff --git a/src/arch/instructions/undefined-int.h b/src/arch/instructions/undefined-int.h
index 8a648cf..491ec31 100644
--- a/src/arch/instructions/undefined-int.h
+++ b/src/arch/instructions/undefined-int.h
@@ -32,63 +32,57 @@
/* Informations glissées dans la structure GObject de GArchInstruction */
-typedef union _undef_obj_extra
+typedef struct _undef_extra_data_t
{
- struct
- {
- InstrExpectedBehavior behavior; /* Conséquences réelles */
+ /**
+ * Le champ uid de la structure parente attendue conduit à une taille
+ * alignée sur 2 octets, donc à une taille totale de 4 octets ce qui
+ * représente la limite maximale de taille supportée.
+ *
+ * Pour 3 octets à la base, qui devraient laisser 8 - 1 octets disponbibles
+ * en incluant le bit de verrouillage.
+ *
+ * On reproduit donc la structure instr_extra_data_t ici, en basculant
+ * l'énumération InstrExpectedBehavior en champ de bits.
+ */
- };
+ itid_t uid; /* Identifiant unique du type */
+ ArchInstrFlag flags; /* Informations complémentaires*/
- gint lock; /* Gestion d'accès aux fanions */
+ unsigned int behavior : 2; /* Conséquences réelles */
+
+} undef_extra_data_t;
-} undef_obj_extra;
/* Définition générique d'une instruction au comportement non défini (instance) */
struct _GUndefInstruction
{
GArchInstruction parent; /* A laisser en premier */
-#if __SIZEOF_INT__ == __SIZEOF_LONG__
-
- /**
- * L'inclusion des informations suivantes dépend de l'architecture.
- *
- * Si la structure GObject possède un trou, on remplit de préférence
- * ce dernier.
- */
-
- undef_obj_extra extra; /* Externalisation embarquée */
+};
-#endif
+/* Définition générique d'une instruction au comportement non défini (classe) */
+struct _GUndefInstructionClass
+{
+ GArchInstructionClass parent; /* A laisser en premier */
};
+
/**
* Accès aux informations éventuellement déportées.
*/
#if __SIZEOF_INT__ == __SIZEOF_LONG__
-# define INIT_UNDEF_INSTR_EXTRA(ins) ins->extra.lock = 0
-
-# define GET_UNDEF_INSTR_EXTRA(ins) &ins->extra
+# define GET_UNDEF_INSTR_EXTRA(ins) (undef_extra_data_t *)&ins->extra
#else
-# define INIT_UNDEF_INSTR_EXTRA(ins) INIT_GOBJECT_EXTRA(G_OBJECT(ins))
-
-# define GET_UNDEF_INSTR_EXTRA(ins) GET_GOBJECT_EXTRA(G_OBJECT(ins), undef_obj_extra)
+# define GET_UNDEF_INSTR_EXTRA(ins) GET_GOBJECT_EXTRA(G_OBJECT(ins), undef_extra_data_t)
#endif
-/* Définition générique d'une instruction au comportement non défini (classe) */
-struct _GUndefInstructionClass
-{
- GArchInstructionClass parent; /* A laisser en premier */
-
-};
-
#endif /* _ARCH_INSTRUCTIONS_UNDEFINED_INT_H */
diff --git a/src/arch/instructions/undefined.c b/src/arch/instructions/undefined.c
index 880e338..663a9eb 100644
--- a/src/arch/instructions/undefined.c
+++ b/src/arch/instructions/undefined.c
@@ -132,7 +132,7 @@ static void g_undef_instruction_class_init(GUndefInstructionClass *klass)
static void g_undef_instruction_init(GUndefInstruction *instr)
{
- INIT_ARCH_INSTR_EXTRA(instr);
+ GET_UNDEF_INSTR_EXTRA(instr)->behavior = IEB_UNDEFINED;
}
@@ -190,7 +190,7 @@ static void g_undef_instruction_finalize(GUndefInstruction *instr)
GArchInstruction *g_undef_instruction_new(InstrExpectedBehavior behavior)
{
GArchInstruction *result; /* Instruction à retourner */
- undef_obj_extra *extra; /* Données insérées à modifier */
+ undef_extra_data_t *extra; /* Données insérées à modifier */
result = g_object_new(G_TYPE_UNDEF_INSTRUCTION, NULL);
@@ -241,7 +241,7 @@ static const char *g_undef_instruction_get_encoding(const GUndefInstruction *ins
const char *g_undef_instruction_get_keyword(const GUndefInstruction *instr)
{
const char *result; /* Désignation à retourner */
- undef_obj_extra *extra; /* Données insérées à consulter*/
+ undef_extra_data_t *extra; /* Données insérées à consulter*/
extra = GET_UNDEF_INSTR_EXTRA(instr);
@@ -300,7 +300,8 @@ static bool g_undef_instruction_unserialize(GUndefInstruction *instr, GAsmStorag
{
bool result; /* Bilan à retourner */
GArchInstructionClass *parent; /* Classe parente à consulter */
- undef_obj_extra *extra; /* Données insérées à modifier */
+ undef_extra_data_t *extra; /* Données insérées à consulter*/
+ uint8_t val; /* Champ de bits manipulé */
parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class);
@@ -310,7 +311,12 @@ static bool g_undef_instruction_unserialize(GUndefInstruction *instr, GAsmStorag
{
extra = GET_UNDEF_INSTR_EXTRA(instr);
- result = extract_packed_buffer(pbuf, &extra->behavior, sizeof(InstrExpectedBehavior), true);
+ LOCK_GOBJECT_EXTRA(extra);
+
+ result = extract_packed_buffer(pbuf, &val, sizeof(uint8_t), false);
+ extra->behavior = val;
+
+ UNLOCK_GOBJECT_EXTRA(extra);
}
@@ -337,7 +343,7 @@ static bool g_undef_instruction_serialize(GUndefInstruction *instr, GAsmStorage
{
bool result; /* Bilan à retourner */
GArchInstructionClass *parent; /* Classe parente à consulter */
- undef_obj_extra *extra; /* Données insérées à consulter*/
+ undef_extra_data_t *extra; /* Données insérées à consulter*/
parent = G_ARCH_INSTRUCTION_CLASS(g_undef_instruction_parent_class);
@@ -347,7 +353,11 @@ static bool g_undef_instruction_serialize(GUndefInstruction *instr, GAsmStorage
{
extra = GET_UNDEF_INSTR_EXTRA(instr);
- result = extend_packed_buffer(pbuf, &extra->behavior, sizeof(InstrExpectedBehavior), true);
+ LOCK_GOBJECT_EXTRA(extra);
+
+ result = extend_packed_buffer(pbuf, (uint8_t []){ extra->behavior }, sizeof(uint8_t), false);
+
+ UNLOCK_GOBJECT_EXTRA(extra);
}
@@ -417,12 +427,16 @@ static void g_undef_instruction_print(GUndefInstruction *instr, GBufferLine *lin
InstrExpectedBehavior g_undef_instruction_get_behavior(const GUndefInstruction *instr)
{
InstrExpectedBehavior result; /* Comportement à retourner */
- undef_obj_extra *extra; /* Données insérées à consulter*/
+ undef_extra_data_t *extra; /* Données insérées à consulter*/
extra = GET_UNDEF_INSTR_EXTRA(instr);
+ LOCK_GOBJECT_EXTRA(extra);
+
result = extra->behavior;
+ UNLOCK_GOBJECT_EXTRA(extra);
+
return result;
}