summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-10-07 22:07:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-10-07 22:07:27 (GMT)
commita5e162d47a574f334b172dfee3128a40e8d52fb3 (patch)
tree5816a46365d196f40ac39fed884a9ee20fb44194 /src
parent1d5f7f28f92251dc4d3bff8d87b3e3052ab9cab2 (diff)
Created a compiler for architecture instruction definitions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@410 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r--src/analysis/disass/fetch.c4
-rw-r--r--src/arch/arm/instruction.c8
-rw-r--r--src/arch/arm/instruction.h4
-rw-r--r--src/arch/arm/v7/Makefile.am6
-rw-r--r--src/arch/arm/v7/arm.c3
-rw-r--r--src/arch/arm/v7/helpers.c58
-rw-r--r--src/arch/arm/v7/helpers.h40
-rw-r--r--src/arch/arm/v7/instruction.c10
-rw-r--r--src/arch/arm/v7/instruction.h7
-rw-r--r--src/arch/arm/v7/opcodes/Makefile.am15
-rw-r--r--src/arch/arm/v7/opdefs/Makefile.am37
-rw-r--r--src/arch/arm/v7/opdefs/mov_A88104.d47
-rw-r--r--src/arch/arm/v7/opdefs/subs_B9320.d44
-rw-r--r--src/arch/arm/v7/processor.c12
-rw-r--r--src/arch/register-int.h29
-rw-r--r--src/arch/register.c202
-rw-r--r--src/arch/register.h39
17 files changed, 550 insertions, 15 deletions
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
index 97cad33..eee2eb6 100644
--- a/src/analysis/disass/fetch.c
+++ b/src/analysis/disass/fetch.c
@@ -159,6 +159,8 @@ static GArchInstruction *load_code_binary(const GLoadedBinary *binary, const vmp
{
instr = g_arch_processor_disassemble(proc, NULL, bin_data, &pos, end);
+ if (!G_IS_RAW_INSTRUCTION(instr)) printf("GOT %p\n", instr);
+
if (instr == NULL)
instr = g_raw_instruction_new_array(bin_data, MDS_32_BITS, 1, &pos, end,
g_arch_processor_get_endianness(proc));
@@ -294,7 +296,7 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt
/* Traiter la diff */
- if (cmp_vmpa_by_phy(last, border) < 0)
+ if (0 && cmp_vmpa_by_phy(last, border) < 0)
{
joint = load_raw_binary(binary, last,
get_phy_addr(last) + compute_vmpa_diff(border, last),
diff --git a/src/arch/arm/instruction.c b/src/arch/arm/instruction.c
index c315bae..b46cab0 100644
--- a/src/arch/arm/instruction.c
+++ b/src/arch/arm/instruction.c
@@ -46,7 +46,7 @@ static const char *g_arm_instruction_get_keyword(const GArmInstruction *, AsmSyn
/* Indique le type défini pour une représentation d'une instruction ARM. */
-G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARM_INSTRUCTION);
+G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARCH_INSTRUCTION);
/******************************************************************************
@@ -160,16 +160,18 @@ static const char *g_arm_instruction_get_keyword(const GArmInstruction *instr, A
* *
* Description : Définit les conditions d'exécution d'une instruction ARM. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_arm_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond)
+bool g_arm_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond)
{
instr->cond = cond;
+ return true;
+
}
diff --git a/src/arch/arm/instruction.h b/src/arch/arm/instruction.h
index ecd9919..3211766 100644
--- a/src/arch/arm/instruction.h
+++ b/src/arch/arm/instruction.h
@@ -26,10 +26,12 @@
#include <glib-object.h>
+#include <stdbool.h>
#include <stdint.h>
#include "cond.h"
+#include "../instruction.h"
@@ -52,7 +54,7 @@ typedef struct _GArmInstructionClass GArmInstructionClass;
GType g_arm_instruction_get_type(void);
/* Définit les conditions d'exécution d'une instruction ARM. */
-void g_arm_instruction_set_cond(GArmInstruction *, ArmCondCode);
+bool g_arm_instruction_set_cond(GArmInstruction *, ArmCondCode);
/* Indique les conditions d'exécution d'une instruction ARM. */
ArmCondCode g_arm_instruction_get_cond(const GArmInstruction *);
diff --git a/src/arch/arm/v7/Makefile.am b/src/arch/arm/v7/Makefile.am
index dc095ed..3fe1394 100644
--- a/src/arch/arm/v7/Makefile.am
+++ b/src/arch/arm/v7/Makefile.am
@@ -3,10 +3,14 @@ noinst_LTLIBRARIES = libarcharmv7.la
libarcharmv7_la_SOURCES = \
arm.h arm.c \
+ helpers.h helpers.c \
instruction.h instruction.c \
processor.h processor.c \
register.h register.c
+libarcharmv7_la_LIBADD = \
+ opcodes/libarcharmv7opcodes.la
+
libarcharmv7_la_CFLAGS = $(AM_CFLAGS)
@@ -15,4 +19,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = #opdefs
+SUBDIRS = opdefs opcodes
diff --git a/src/arch/arm/v7/arm.c b/src/arch/arm/v7/arm.c
index 4953b6b..bd1beb8 100644
--- a/src/arch/arm/v7/arm.c
+++ b/src/arch/arm/v7/arm.c
@@ -27,6 +27,7 @@
#include <stdint.h>
+#include "opcodes/opcodes.h"
#include "../../../common/bconst.h"
@@ -82,7 +83,7 @@ static GArchInstruction *process_armv7_data_processing_register(uint32_t);
#define armv7_read_instr_cmp_register(raw) NULL
#define armv7_read_instr_cmn_register(raw) NULL
#define armv7_read_instr_orr_register(raw) NULL
-#define armv7_read_instr_mov_register_arm(raw) NULL
+//#define armv7_read_instr_mov_register_arm(raw) NULL
#define armv7_read_instr_lsl_immediate(raw) NULL
#define armv7_read_instr_lsr_immediate(raw) NULL
#define armv7_read_instr_asr_immediate(raw) NULL
diff --git a/src/arch/arm/v7/helpers.c b/src/arch/arm/v7/helpers.c
new file mode 100644
index 0000000..632c1b7
--- /dev/null
+++ b/src/arch/arm/v7/helpers.c
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * helpers.c - aide à la mise en place des opérandes ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "helpers.h"
+
+
+#include "register.h"
+#include "../../register.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : index = indice du registre correspondant. *
+* *
+* Description : Crée un opérande représentant un registre ARMv7. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *translate_armv7_register(uint8_t index)
+{
+ GArchOperand *result; /* Opérande à faire remonter */
+ GArmV7Register *reg; /* Register à représenter */
+
+ reg = g_armv7_register_new(index);
+
+ if (reg == NULL)
+ result = NULL;
+ else
+ result = g_register_operand_new(G_ARCH_REGISTER(reg));
+
+ return result;
+
+}
diff --git a/src/arch/arm/v7/helpers.h b/src/arch/arm/v7/helpers.h
new file mode 100644
index 0000000..9ea0d74
--- /dev/null
+++ b/src/arch/arm/v7/helpers.h
@@ -0,0 +1,40 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * helpers.h - prototypes pour l'aide à la mise en place des opérandes ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_ARM_V7_HELPERS_H
+#define _ARCH_ARM_V7_HELPERS_H
+
+
+#include <stdint.h>
+
+
+#include "../../operand.h"
+
+
+
+/* Crée un opérande représentant un registre ARMv7. */
+GArchOperand *translate_armv7_register(uint8_t);
+
+
+
+#endif /* _ARCH_ARM_V7_HELPERS_H */
diff --git a/src/arch/arm/v7/instruction.c b/src/arch/arm/v7/instruction.c
index 24135f3..de81056 100644
--- a/src/arch/arm/v7/instruction.c
+++ b/src/arch/arm/v7/instruction.c
@@ -156,9 +156,9 @@ static void g_armv7_instruction_finalize(GArmV7Instruction *instr)
* *
******************************************************************************/
-GArmV7Instruction *g_armv7_instruction_new(const char *keyword)
+GArchInstruction *g_armv7_instruction_new(const char *keyword)
{
- GArmV7Instruction *result; /* Structure à retourner */
+ GArchInstruction *result; /* Structure à retourner */
result = g_object_new(G_TYPE_ARMV7_INSTRUCTION, NULL);
@@ -176,16 +176,18 @@ GArmV7Instruction *g_armv7_instruction_new(const char *keyword)
* *
* Description : Définit si une instruction ARMv7 met à jour les drapeaux. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_armv7_instruction_define_setflags(GArmV7Instruction *instr, bool set)
+bool g_armv7_instruction_define_setflags(GArmV7Instruction *instr, bool set)
{
instr->setflags = set;
+ return true;
+
}
diff --git a/src/arch/arm/v7/instruction.h b/src/arch/arm/v7/instruction.h
index 97ee31a..291f2c9 100644
--- a/src/arch/arm/v7/instruction.h
+++ b/src/arch/arm/v7/instruction.h
@@ -30,6 +30,9 @@
#include <stdint.h>
+#include "../../instruction.h"
+
+
#define G_TYPE_ARMV7_INSTRUCTION g_armv7_instruction_get_type()
#define G_ARMV7_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_instruction_get_type(), GArmV7Instruction))
@@ -50,10 +53,10 @@ typedef struct _GArmV7InstructionClass GArmV7InstructionClass;
GType g_armv7_instruction_get_type(void);
/* Crée une instruction pour l'architecture ARMv7. */
-GArmV7Instruction *g_armv7_instruction_new(const char *);
+GArchInstruction *g_armv7_instruction_new(const char *);
/* Définit si une instruction ARMv7 met à jour les drapeaux. */
-void g_armv7_instruction_define_setflags(GArmV7Instruction *, bool);
+bool g_armv7_instruction_define_setflags(GArmV7Instruction *, bool);
/* Indique si une instruction ARMv7 met à jour les drapeaux. */
bool g_armv7_instruction_get_setflags(const GArmV7Instruction *);
diff --git a/src/arch/arm/v7/opcodes/Makefile.am b/src/arch/arm/v7/opcodes/Makefile.am
new file mode 100644
index 0000000..e77b7e8
--- /dev/null
+++ b/src/arch/arm/v7/opcodes/Makefile.am
@@ -0,0 +1,15 @@
+
+noinst_LTLIBRARIES = libarcharmv7opcodes.la
+
+libarcharmv7opcodes_la_SOURCES = \
+ mov.c \
+ subs.c
+
+libarcharmv7opcodes_la_LIBADD =
+
+libarcharmv7opcodes_la_CFLAGS = $(AM_CFLAGS)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/arch/arm/v7/opdefs/Makefile.am b/src/arch/arm/v7/opdefs/Makefile.am
new file mode 100644
index 0000000..8a799b1
--- /dev/null
+++ b/src/arch/arm/v7/opdefs/Makefile.am
@@ -0,0 +1,37 @@
+
+include ../../../../../tools/d2c.mk
+
+
+D2C_BIN = ../../../../../tools/d2c
+
+D2C_OUTDIR = $(PWD)/..
+
+D2C_ARCH = armv7
+D2C_HEADER = _ARCH_ARM_V7
+
+D2C_ENCODINGS = \
+ -e a= \
+ -e t=thumb_
+
+D2C_MACROS = \
+ -M SetFlags=g_armv7_instruction_define_setflags \
+ -M Condition=g_arm_instruction_set_cond \
+ -M Register=translate_armv7_register \
+ -M "ExpandImmC32=g_imm_operand_new_from_value(MDS_32_BITS_UNSIGNED, "
+
+ARMV7_DEFS = \
+ mov_A88104.d \
+ subs_B9320.d
+
+
+all: $(ARMV7_DEFS:.d=.g) untabify_disass fix_includes_in_c finish_disass
+
+fix_includes_in_c:
+ find ../opcodes -name '*c' -exec sed -i 's/##INCLUDES##/\n#include "..\/instruction.h"\n#include "..\/..\/instruction.h"\n#include "..\/helpers.h"\n#include "..\/..\/..\/..\/common\/bconst.h"\n\n/' {} \;
+
+finish_disass: $(D2C_OUTDIR)/opcodes/opcodes.h
+ sed -i 's/##INCLUDES##/#include\ <stdint.h>\n\n#include "..\/..\/..\/instruction.h"/' $<
+ if ! grep -q 'endif' $<; then echo -en "\n\n#endif /* _ARCH_ARM_V7_OPCODES_OPCODES_H */\n" >> $< ; fi
+
+clean:
+ rm -f $(ARMV7_DEFS:.d=.g) $(D2C_OUTDIR)/opcodes/*c $(D2C_OUTDIR)/opcodes/opcodes.h
diff --git a/src/arch/arm/v7/opdefs/mov_A88104.d b/src/arch/arm/v7/opdefs/mov_A88104.d
new file mode 100644
index 0000000..1efebd3
--- /dev/null
+++ b/src/arch/arm/v7/opdefs/mov_A88104.d
@@ -0,0 +1,47 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * ##FILE## - traduction d'instructions ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+@title MOV (register, ARM)
+
+@encoding(A1) {
+
+ @word cond(4) 0 0 0 1 1 0 1 S(1) 0 0 0 0 Rd(4) 0 0 0 0 0 0 0 0 Rm(4)
+
+ @syntax {S} {c} <Rd> <Rm>
+
+ @conv {
+
+ S = SetFlags(S)
+ c = Condition(cond)
+ Rd = Register(Rd)
+ Rm = Register(Rm)
+
+ }
+
+ @rules {
+
+ if ((Rd == '1111') && (S == '1')) ; see SUBS PC, LR and related instructions (ARM)
+
+ }
+
+}
diff --git a/src/arch/arm/v7/opdefs/subs_B9320.d b/src/arch/arm/v7/opdefs/subs_B9320.d
new file mode 100644
index 0000000..335e614
--- /dev/null
+++ b/src/arch/arm/v7/opdefs/subs_B9320.d
@@ -0,0 +1,44 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * ##FILE## - traduction d'instructions ARMv7
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+@title SUBS PC, LR and related instructions (ARM)
+
+@encoding(A1) {
+
+ @word cond(4) 0 0 1 opcode(4) 1 Rn(4) 1 1 1 1 imm12(12)
+
+ @syntax {c} <Rn> <#const>
+
+ @conv {
+
+ c = Condition(cond)
+ Rn = Register(Rn)
+ const = ExpandImmC32(imm12)
+
+ }
+
+ @rules {
+
+ }
+
+}
diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c
index 3ce1623..dd2f39f 100644
--- a/src/arch/arm/v7/processor.c
+++ b/src/arch/arm/v7/processor.c
@@ -218,7 +218,7 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
//exit(1);
- raw = 0xe1a0000a;
+
start = get_phy_addr(pos);
@@ -226,16 +226,24 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr
if (!read_u32(&raw, data, &start, end, G_ARCH_PROCESSOR(proc)->endianness))
return NULL;
+ if (raw == 0xe1a0000a)
+ printf("process @ 0x%x :: 0x%08x\n", start, raw);
+ /*
if (raw == 0xe1a0000a)
printf("read !!!!!!!\n");
-
+ */
/* TODO : thumb... */
result = process_armv7_instruction_set_encoding(raw);
+ if (raw == 0xe1a0000a)
+ printf(" --> %p\n", result);
+
+
+
if (result != NULL)
advance_vmpa(pos, 4);
diff --git a/src/arch/register-int.h b/src/arch/register-int.h
index fe9db8c..bf2ad75 100644
--- a/src/arch/register-int.h
+++ b/src/arch/register-int.h
@@ -28,6 +28,12 @@
#include "register.h"
+#include "operand-int.h"
+
+
+
+/* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */
+
/* Produit une empreinte à partir d'un registre. */
typedef guint (* reg_hash_fc) (const GArchRegister *);
@@ -69,4 +75,27 @@ struct _GArchRegisterClass
+/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+
+
+/* Définition d'un opérande visant un registre (instance) */
+struct _GRegisterOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GArchRegister *reg; /* Registre représenté */
+ bool is_written; /* Changement de contenu */
+
+};
+
+
+/* Définition d'un opérande visant un registre (classe) */
+struct _GRegisterOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+
#endif /* _ARCH_REGISTER_INT_H */
diff --git a/src/arch/register.c b/src/arch/register.c
index 389e71a..706fcd4 100644
--- a/src/arch/register.c
+++ b/src/arch/register.c
@@ -28,6 +28,9 @@
+/* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */
+
+
/* Initialise la classe des registres. */
static void g_arch_register_class_init(GArchRegisterClass *);
@@ -36,6 +39,28 @@ static void g_arch_register_init(GArchRegister *);
+/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+
+
+/* Initialise la classe des opérandes de registre. */
+static void g_register_operand_class_init(GRegisterOperandClass *);
+
+/* Initialise une instance d'opérande de registre. */
+static void g_register_operand_init(GRegisterOperand *);
+
+/* Compare un opérande avec un autre. */
+static bool g_register_operand_compare(const GRegisterOperand *, const GRegisterOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_register_operand_print(const GRegisterOperand *, GBufferLine *, AsmSyntax);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PUR REGISTRE DU MATERIEL */
+/* ---------------------------------------------------------------------------------- */
+
+
/* Indique le type défini pour une représentation d'un registre. */
G_DEFINE_TYPE(GArchRegister, g_arch_register, G_TYPE_OBJECT);
@@ -210,3 +235,180 @@ bool g_arch_register_is_stack_pointer(const GArchRegister *reg)
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REGISTRE SOUS FORME D'OPERANDE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */
+G_DEFINE_TYPE(GRegisterOperand, g_register_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes de registre Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_class_init(GRegisterOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de registre Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_init(GRegisterOperand *operand)
+{
+ GArchOperand *parent; /* Instance parente */
+
+ parent = G_ARCH_OPERAND(operand);
+
+ parent->compare = (operand_compare_fc)g_register_operand_compare;
+ parent->print = (operand_print_fc)g_register_operand_print;
+
+ operand->is_written = false;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = registre déjà en place. *
+* *
+* Description : Crée un opérande visant un registre. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_register_operand_new(GArchRegister *reg)
+{
+ GRegisterOperand *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_REGISTER_OPERAND, NULL);
+
+ result->reg = reg;
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande représentant un registre. *
+* *
+* Description : Fournit le registre Dalvik associé à l'opérande. *
+* *
+* Retour : Représentation interne du registre. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand)
+{
+ return operand->reg;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : a = premier opérande à consulter. *
+* b = second opérande à consulter. *
+* *
+* Description : Compare un opérande avec un autre. *
+* *
+* Retour : Bilan de la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_register_operand_compare(const GRegisterOperand *a, const GRegisterOperand *b)
+{
+ return (g_arch_register_compare(a->reg, b->reg) == 0);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* line = ligne tampon où imprimer l'opérande donné. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_print(const GRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ g_arch_register_print(operand->reg, line, syntax);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande représentant un registre à mettre à jour. *
+* *
+* Description : Marque l'opérande comme étant écrit plutôt que consulté. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_register_operand_mark_as_written(GRegisterOperand *operand)
+{
+ operand->is_written = true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande représentant un registre à consulter. *
+* *
+* Description : Indique le type d'accès réalisé sur l'opérande. *
+* *
+* Retour : Type d'accès : true en cas d'écriture, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_register_operand_is_written(const GRegisterOperand *operand)
+{
+ return operand->is_written;
+
+}
diff --git a/src/arch/register.h b/src/arch/register.h
index 4e9d447..f5841f7 100644
--- a/src/arch/register.h
+++ b/src/arch/register.h
@@ -30,10 +30,14 @@
#include "archbase.h"
+#include "operand.h"
#include "../glibext/gbufferline.h"
+/* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */
+
+
#define G_TYPE_ARCH_REGISTER g_arch_register_get_type()
#define G_ARCH_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arch_register_get_type(), GArchRegister))
#define G_IS_ARCH_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arch_register_get_type()))
@@ -72,4 +76,39 @@ bool g_arch_register_is_stack_pointer(const GArchRegister *);
+/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+
+
+#define G_TYPE_REGISTER_OPERAND g_register_operand_get_type()
+#define G_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_register_operand_get_type(), GRegisterOperand))
+#define G_IS_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_register_operand_get_type()))
+#define G_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_REGISTER_OPERAND, GRegisterOperandClass))
+#define G_IS_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_REGISTER_OPERAND))
+#define G_REGISTER_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_REGISTER_OPERAND, GRegisterOperandClass))
+
+
+/* Définition d'un opérande visant un registre (instance) */
+typedef struct _GRegisterOperand GRegisterOperand;
+
+/* Définition d'un opérande visant un registre (classe) */
+typedef struct _GRegisterOperandClass GRegisterOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande de registre. */
+GType g_register_operand_get_type(void);
+
+/* Crée un opérande visant un registre. */
+GArchOperand *g_register_operand_new(GArchRegister *);
+
+/* Fournit le registre associé à l'opérande. */
+GArchRegister *g_register_operand_get_register(const GRegisterOperand *);
+
+/* Marque l'opérande comme étant écrit plutôt que consulté. */
+void g_register_operand_mark_as_written(GRegisterOperand *);
+
+/* Indique le type d'accès réalisé sur l'opérande. */
+bool g_register_operand_is_written(const GRegisterOperand *);
+
+
+
#endif /* _ARCH_ARCH_REGISTER_H */