summaryrefslogtreecommitdiff
path: root/lib/registre.c
blob: 82ecfdd2bd96e350c36153c83a0b7dc7a7f92ef6 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "registre.h"
#include "interne.h"
#include "simulator.h"
#include "exceptions.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define _(x) x
#endif

Uint32 registre[64];

/*****************************************/
/**                                     **/
/**         GESTION DES REGISTRES       **/
/**                                     **/
/*****************************************/

Uint32 LireRegistreRG(void)
{
    return (registre[REG_RG]);
}

Uint32 LireRegistreRD(void)
{
    return (registre[REG_RD]);
}

Uint32 LireRegistrePC(void)
{
    return (registre[REG_PC]);
}

Uint32 LireRegistreFLAG(void)
{
    return (registre[REG_FLAG]);
}

Uint32 LireRegistreSP(void)
{
    return (registre[REG_STACKPTR]);
}

void EcrireRegistreRG(Uint32 val)
{
    registre[REG_RG] = val;
}

void EcrireRegistreRD(Uint32 val)
{
    registre[REG_RD] = val;
}

void EcrireRegistrePC(Uint32 val)
{
    registre[REG_PC] = val;
}

void EcrireRegistreFLAG(Uint32 val)
{
    registre[REG_FLAG] = val;
}

void EcrireRegistreSP(Uint32 val)
{
    registre[REG_STACKPTR] = val;
}

/* Lit le mot qui se trouve dans le registre 'numero_registre' */
Uint32 LireRegistre(Uint32 champ_registre)
{
    Uint32 i;

    if (ValeurBit(champ_registre, 5) == 0) {	/* Test du bit S */
	Reset(&i);
	if (champ_registre < 0 || champ_registre >= NB_REGISTRES_UTILISABLES) {	/* Si on voudrait diminuer le nombre de registres */
	    exception(1, _("Invalid Register Descriptor"));	/* Il n'y a que 32 registres */
	    return (i);
	}
	i = registre[champ_registre];	/* Registre classique */
	return (i);
    } else			/* Registre spécial */
	switch (champ(champ_registre, 4)) {
	case 0:
	    return (LireRegistreRG());
	case 1:
	    return (LireRegistreRD());
	case 2:
	    return (LireRegistrePC());
	case 3:
	    return (LireRegistreFLAG());
	default:{
		exception(1, _("Invalid Register Descriptor"));
		return (0);
	    }
	}
}

/* Ecrit le mot 'valeur' dans le registre 'numero_registre' */
void EcrireRegistre(Uint32 champ_registre, Uint32 valeur)
{
    Uint32 i;

    if (ValeurBit(champ_registre, 5) == 0) {	/* Test du bit S */
	Reset(&i);
	if (champ_registre < 0 || champ_registre >= NB_REGISTRES_UTILISABLES)
	    exception(1, _("Invalid Register Descriptor"));	/* Il n'y a que 32 registres */
	else
	    registre[champ_registre] = valeur;	/* Registre classique */
    } else			/* Registre spécial */
	switch (champ(champ_registre, 4)) {
	case 0:
	    EcrireRegistreRG(valeur);
	case 1:
	    EcrireRegistreRD(valeur);
	case 2:
	    EcrireRegistrePC(valeur);
	case 3:
	    EcrireRegistreFLAG(valeur);
	default:
	    exception(1, _("Invalid Register Descriptor"));
	}
}

int Overflow(void)
{
    return (ValeurBit(LireRegistreFLAG(), 0));
}
int Zero(void)
{
    return (ValeurBit(LireRegistreFLAG(), 1));
}
int Sign(void)
{
    return (ValeurBit(LireRegistreFLAG(), 2));
}
int Parity(void)
{
    return (ValeurBit(LireRegistreFLAG(), 3));
}

void SetOverflow(void)
{
    registre[REG_FLAG] |= 1;
}
void SetZero(void)
{
    registre[REG_FLAG] |= 2;
}
void SetSign(void)
{
    registre[REG_FLAG] |= 4;
}
void SetParity(void)
{
    registre[REG_FLAG] |= 8;
}

void ResetOverflow(void)
{
    registre[REG_FLAG] &= (VAL_MAX - 1);
}
void ResetZero(void)
{
    registre[REG_FLAG] &= (VAL_MAX - 2);
}
void ResetSign(void)
{
    registre[REG_FLAG] &= (VAL_MAX - 4);
}
void ResetParity(void)
{
    registre[REG_FLAG] &= (VAL_MAX - 8);
}


void ResetRegistres(void)
{
    int i;

    for (i = 0; i < NB_REGISTRES_PHYSIQUES; i++)
	registre[i] = 0;
}