summaryrefslogtreecommitdiff
path: root/src/arch/mips/operand.h
blob: 5147be40489cfd6105f0675c714e7b6ebefa234b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

/* Chrysalide - Outil d'analyse de fichiers binaires
 * operand.h - prototypes pour la gestion des operandes de l'architecture MIPS
 *
 * Copyright (C) 2009-2017 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/>.
 */


#ifndef _ARCH_MIPS_OPERAND_H
#define _ARCH_MIPS_OPERAND_H


#include <stdbool.h>


#include "registers.h"
#include "../instruction.h"



/* ------------------------ COQUILLE VIDE POUR OPERANDE MIPS ------------------------ */


#define G_TYPE_MIPS_OPERAND                  g_mips_operand_get_type()
#define G_MIPS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_mips_operand_get_type(), GMipsOperand))
#define G_IS_MIPS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_mips_operand_get_type()))
#define G_MIPS_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_mips_operand_get_type(), GMipsOperandIface))


/* Définition d'un opérande de MIPS (instance) */
typedef struct _GMipsOperand GMipsOperand;

/* Définition d'un opérande de MIPS (classe) */
typedef struct _GMipsOperandClass GMipsOperandClass;


/* Indique le type défini par la GLib pour un opérande de MIPS. */
GType g_mips_operand_get_type(void);



/* ----------------------- OPERANDES OFFRANT UN REGISTRE MIPS ----------------------- */


#define G_TYPE_MIPS_REGISTER_OPERAND                  g_mips_register_operand_get_type()
#define G_MIPS_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_mips_register_operand_get_type(), GMipsRegisterOperand))
#define G_IS_MIPS_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_mips_register_operand_get_type()))
#define G_MIPS_REGISTER_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_mips_register_operand_get_type(), GMipsRegisterOperandIface))


/* Définition d'un opérande visant un registre MIPS (instance) */
typedef struct _GMipsRegisterOperand GMipsRegisterOperand;

/* Définition d'un opérande visant un registre MIPS (classe) */
typedef struct _GMipsRegisterOperandClass GMipsRegisterOperandClass;


/* Indique le type défini par la GLib pour un opérande de registre MIPS. */
GType g_mips_register_operand_get_type(void);

/* Crée un opérande visant un registre MIPS. */
GArchOperand *g_mips_register_operand_new(bin_t);

/* Fournit le registre MIPS représenté. */
const mips_register *g_mips_register_operand_get_register(const GMipsRegisterOperand *);



/* -------------------------- OPERANDES DE CONTENU MEMOIRE -------------------------- */


#define G_TYPE_MIPS_MEM_CONTENT_OPERAND                  g_mips_mem_content_operand_get_type()
#define G_MIPS_MEM_CONTENT_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_mips_mem_content_operand_get_type(), GMipsMemContentOperand))
#define G_IS_MIPS_MEM_CONTENT_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_mips_mem_content_operand_get_type()))
#define G_MIPS_MEM_CONTENT_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_mips_mem_content_operand_get_type(), GMipsMemContentOperandIface))


/* Définition d'un opérande MIPS pointeur un contenu mémoire (instance) */
typedef struct _GMipsMemContentOperand GMipsMemContentOperand;

/* Définition d'un opérande MIPS pointeur un contenu mémoire (classe) */
typedef struct _GMipsMemContentOperandClass GMipsMemContentOperandClass;


/* Indique le type défini par la GLib pour un opérande MIPS de contenu mémoire. */
GType g_mips_mem_content_operand_get_type(void);

/* Crée un opérande MIPS de contenu mémoire. */
GArchOperand *g_mips_mem_content_operand_new(bin_t, int16_t);



/* ----------------------------- OPERANDES DE DECALLAGE ----------------------------- */


#define G_TYPE_MIPS_OFFSET_OPERAND                  g_mips_offset_operand_get_type()
#define G_MIPS_OFFSET_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_mips_offset_operand_get_type(), GMipsOffsetOperand))
#define G_IS_MIPS_OFFSET_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_mips_offset_operand_get_type()))
#define G_MIPS_OFFSET_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_mips_offset_operand_get_type(), GMipsOffsetOperandIface))


/* Définition d'un opérande MIPS de décallage (instance) */
typedef struct _GMipsOffsetOperand GMipsOffsetOperand;

/* Définition d'un opérande MIPS de décallage (classe) */
typedef struct _GMipsOffsetOperandClass GMipsOffsetOperandClass;


/* Indique le type défini par la GLib pour un opérande MIPS de décallage. */
GType g_mips_offset_operand_get_type(void);

/* Crée un opérande MIPS de décallage. */
GArchOperand *g_mips_offset_operand_new(int16_t);



/* ------------------------- AIDE A LA CREATION D'OPERANDES ------------------------- */


/* Types d'opérandes supportés */
typedef enum _MIPSOperandType
{
    MIPS_OTP_RS,                            /* Registre rs (bits 21 -> 25) */
    MIPS_OTP_RT,                            /* Registre rs (bits 16 -> 20) */
    MIPS_OTP_RD,                            /* Registre rs (bits 11 -> 15) */
    MIPS_OTP_IMMEDIATE,                     /* Valeur imm. (bits 0 -> 15)  */
    MIPS_OTP_TARGET_ADDRESS,                /* Adresse (bits 0 -> 25)      */

    MIPS_OTP_MEM_CONTENT,                   /* Contenu mémoire [base+off]  */
    MIPS_OTP_OFFSET,                        /* Décallage                   */
    MIPS_OTP_SA                             /* Valeur arithmétique         */

} MipsOperandType;


/* Procède à la lecture de n opérandes donnés. */
bool mips_read_n_operands(GArchInstruction *, const bin_t *data, off_t *pos, off_t, unsigned int, ...);



#endif  /* _ARCH_MIPS_OPERAND_H */