Browse Source

Fusion des deux versions en cours

Paul Faure 2 years ago
parent
commit
1c8364b30d

+ 289
- 0
Processeur.srcs/sources_1/new/Etage1_LectureInstruction.vhd View File

@@ -0,0 +1,289 @@
1
+    ----------------------------------------------------------------------------------
2
+    -- Company:  INSA-Toulouse
3
+    -- Engineer: Paul Faure
4
+    -- 
5
+    -- Create Date: 18.04.2021 21:19:41
6
+    -- Module Name: Etage1_LectureInstruction - Behavioral
7
+    -- Project Name: Processeur sécurisé
8
+    -- Target Devices: Basys 3 ARTIX7
9
+    -- Tool Versions: Vivado 2016.4
10
+    -- Description: Etage 1 du processeur
11
+    --     - Gestion des instructions, lecture en mémoire
12
+    --     - Gestion des aléas sur les registres
13
+    --     - Gestion des sauts et appels de fonction
14
+    -- 
15
+    -- Dependencies: 
16
+    --    - MemoireInstruction
17
+    --    - MemoireAdressesRetour
18
+    ----------------------------------------------------------------------------------
19
+
20
+
21
+    library IEEE;
22
+    use IEEE.STD_LOGIC_1164.ALL;
23
+    use IEEE.STD_LOGIC_UNSIGNED.ALL;
24
+    use IEEE.NUMERIC_STD.ALL;
25
+
26
+
27
+    entity Etage1_LectureInstruction is
28
+        Generic (Instruction_size_in_memory : Natural; -- Taille d'une instruction en mémoire (Taille d'un code instruction + 3*Taille d'un mot binaire)
29
+                 Addr_size_mem_instruction : Natural; -- Nombre de bits pour adresser la mémoire d'instruction
30
+                 Mem_instruction_size : Natural; -- Taille de la mémoire d'instruction (nombre d'instructions stockées)
31
+                 Nb_bits : Natural; -- Taille d'un mot binaire
32
+                 Instruction_bus_size : Natural; -- Nombre de bits du bus d'instruction (Taille d'un code instruction)
33
+                 Nb_registres : Natural; -- Nombre de registres du processeurs
34
+                 Mem_adresse_retour_size : Natural; -- Taille de la mémoire des adresses de retour (nombre d'adresse maximum) (profondeur d'appel maximale)
35
+                 Adresse_size_mem_adresse_retour : Natural; -- Nombre de bits pour adresser la mémoire des adresses de retour
36
+                 Instructions_critiques_lecture_A : STD_LOGIC_VECTOR; -- Vecteur de bit représentant les instruction critiques sur l'opérande A (si le bit i est a un, l'instruction i lit une valeur dans le registre n°opérandeA)
37
+                 Instructions_critiques_lecture_B : STD_LOGIC_VECTOR; -- Vecteur de bit représentant les instruction critiques sur l'opérande B (si le bit i est a un, l'instruction i lit une valeur dans le registre n°opérandeB)
38
+                 Instructions_critiques_lecture_C : STD_LOGIC_VECTOR; -- Vecteur de bit représentant les instruction critiques sur l'opérande C (si le bit i est a un, l'instruction i lit une valeur dans le registre n°opérandeC)
39
+                 Instructions_critiques_ecriture : STD_LOGIC_VECTOR; -- Vecteur de bit représentant les instruction critiques en écriture (toujours sur l'opérande A) (si le bit i est a un, l'instruction i ecrit une valeur dans le registre n°opérandeA)
40
+                 
41
+                 -- Exemple 1 : Soit MUL i j k avec pour numéro d'instruction 7 avec le comportement Ri <- Rj*Rk
42
+                 --                Instructions_critiques_lecture_A(7) = '0'  --> MUL ne lit pas dans le registre de l'opérande A
43
+                 --                Instructions_critiques_lecture_B(7) = '1'  --> MUL lit dans le registre de l'opérande B
44
+                 --                Instructions_critiques_lecture_C(7) = '1'  --> MUL lit dans le registre de l'opérande C
45
+                 --                Instructions_critiques_ecriture(7) = '1'  --> MUL ecrit dans le registre de l'opérande A
46
+                 
47
+                 -- Exemple 2 : Soit AFC i val avec pour numéro d'instruction 5 avec le comportement Ri <- val
48
+                 --                Instructions_critiques_lecture_A(5) = '0'  --> AFC ne lit pas dans le registre de l'opérande A
49
+                 --                Instructions_critiques_lecture_B(5) = '0'  --> AFC ne lit pas dans le registre de l'opérande B (pour AFC, B est directement la valeur, pas un numero de registre, il n'y a donc pas de lecture)
50
+                 --                Instructions_critiques_lecture_C(5) = '0'  --> AFC ne lit pas dans le registre de l'opérande C
51
+                 --                Instructions_critiques_ecriture(5) = '1'  --> AFC ecrit dans le registre de l'opérande A
52
+                 
53
+                 Code_Instruction_JMP : STD_LOGIC_VECTOR;   -- Numéro de l'instruction JMP
54
+                 Code_Instruction_JMZ : STD_LOGIC_VECTOR;   -- Numéro de l'instruction JMZ
55
+                 Code_Instruction_CALL : STD_LOGIC_VECTOR;  -- Numéro de l'instruction CALL
56
+                 Code_Instruction_RET : STD_LOGIC_VECTOR;   -- Numéro de l'instruction RET
57
+                 Code_Instruction_STOP : STD_LOGIC_VECTOR); -- Numéro de l'instruction STOP
58
+        Port ( CLK : in STD_LOGIC; -- Clock
59
+               RST : in STD_LOGIC; -- Reset
60
+               Z : in STD_LOGIC;   -- Flag Zero de l'ALU (utile pour le JMZ)
61
+               A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande A
62
+               B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande B
63
+               C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande C
64
+               Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0)); -- Sortie du code de l'instruction
65
+    end Etage1_LectureInstruction;
66
+
67
+
68
+
69
+    architecture Behavioral of Etage1_LectureInstruction is
70
+        component MemoireInstructions is
71
+        Generic (Nb_bits : Natural;
72
+                 Addr_size : Natural;
73
+                 Mem_size : Natural);
74
+        Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0);
75
+               D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'));
76
+        end component;
77
+        
78
+        component MemoireAdressesRetour is
79
+            Generic (Nb_bits : Natural;
80
+                     Addr_size : Natural;
81
+                     Mem_size : Natural);
82
+            Port ( R : in STD_LOGIC;
83
+                   W : in STD_LOGIC;
84
+                   D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
85
+                   RST : in STD_LOGIC;
86
+                   CLK : in STD_LOGIC;
87
+                   D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0');
88
+                   E : out STD_LOGIC;
89
+                   F : out STD_LOGIC);
90
+        end component;
91
+        
92
+        -- Signaux pour récuperer l'instruction de la mémoire
93
+        signal Pointeur_instruction : STD_LOGIC_VECTOR (Addr_size_mem_instruction - 1 downto 0) := (others => '0');
94
+        signal Pointeur_instruction_next : STD_LOGIC_VECTOR (Addr_size_mem_instruction - 1 downto 0) := (0 => '1', others => '0');
95
+        signal Instruction_courante : STD_LOGIC_VECTOR (Instruction_size_in_memory - 1 downto 0) := (others => '0');
96
+        
97
+        
98
+        -- Tableau pour gérer les aléas des registres (lecture en étage 2 avant écriture en étage 5)
99
+        subtype Registre is integer range -1 to Nb_registres - 1;
100
+        type Tab_registres is array (1 to 3) of Registre;
101
+        signal Tableau : Tab_registres := (others => - 1);
102
+        
103
+        -- Signaux de gestion pour la mémoire des adresses de retour
104
+        signal Adresse_Retour : STD_LOGIC_VECTOR (Addr_size_mem_instruction - 1 downto 0) := (others => '0');
105
+        signal E : STD_LOGIC;
106
+        signal F : STD_LOGIC;
107
+        signal R_Aux : STD_LOGIC := '0';
108
+        signal W_Aux : STD_LOGIC := '0';
109
+
110
+        -- constantes pour injecter des bulles dans le pipeline
111
+        constant Instruction_nulle : STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0) := (others => '0');
112
+        constant Argument_nul : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
113
+        
114
+        -- condition pour detecter si une bulle doit être injectée 
115
+        signal bulles : boolean := false;
116
+        
117
+        -- Compteur pour attendre lors d'un JMZ que l'instruction d'avant soit a l'ALU, ou lors d'un STOP k
118
+        signal compteur : integer := 0;
119
+        
120
+        -- Signal d'arret (STOP 0)
121
+        signal locked : boolean := false;
122
+        
123
+    begin
124
+        instance : MemoireInstructions
125
+        generic map (Nb_bits => Instruction_size_in_memory,
126
+                     Addr_size => Addr_size_mem_instruction,
127
+                     Mem_size => Mem_instruction_size)
128
+        port map (Addr => Pointeur_Instruction,
129
+                  D_OUT => Instruction_courante);
130
+                  
131
+        instance_MemoireAdressesRetour : MemoireAdressesRetour
132
+        generic map (Nb_bits => Addr_size_mem_instruction,
133
+                     Addr_size => Adresse_size_mem_adresse_retour,
134
+                     Mem_size => Mem_adresse_retour_size
135
+        )
136
+        port map ( R => R_Aux,
137
+                   W => W_Aux,
138
+                   D_IN => Pointeur_instruction_next,
139
+                   RST => RST,
140
+                   CLK => CLK,
141
+                   D_OUT => Adresse_Retour,
142
+                   E => E,
143
+                   F => F
144
+        );
145
+
146
+                  
147
+        process 
148
+        begin
149
+        -- Synchronisation
150
+            wait until CLK'event and CLK = '1';
151
+            if (RST = '0') then
152
+                -- Reset de l'étage
153
+                Tableau <= (others => -1);
154
+                Pointeur_Instruction <= (others => '0');
155
+                compteur <= 0;
156
+                locked <= false;
157
+                C <= Argument_nul;
158
+                B <= Argument_nul;
159
+                A <= Argument_nul;
160
+                Instruction <= Instruction_nulle;
161
+            else
162
+                -- Avancement des instructions en écritures dans le pipeline
163
+                Tableau(3) <= Tableau(2);
164
+                Tableau(2) <= Tableau(1);
165
+                Tableau(1) <= -1;
166
+                if (not bulles) then
167
+                    -- S'il ne faut pas injecter de bulles ont traite l'instruction (Possible code factorisable sur ce if)
168
+                    if ((Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_CALL) or (Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_JMP)) then
169
+                        -- CAS PARTICULIER : CALL ou JMP, on transmet et on saute
170
+                        C <= Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits);
171
+                        B <= Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits);
172
+                        A <= Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits);
173
+                        Instruction <= Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits);
174
+                        Pointeur_Instruction <= Instruction_courante (2 * Nb_bits + Addr_size_mem_instruction - 1 downto 2 * Nb_bits);
175
+                    elsif (Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_RET) then
176
+                        -- CAS PARTICULIER : RET, on transmet et on revient 
177
+                        C <= Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits);
178
+                        B <= Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits);
179
+                        A <= Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits);
180
+                        Instruction <= Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits);
181
+                        Pointeur_Instruction <= Adresse_Retour;
182
+                    elsif (Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_JMZ) then
183
+                        -- CAS PARTICULIER : JMZ, on attends que l'instruction précedente arrive sur l'ALU, si le flag Zero est a un on saute, sinon on continue normalement
184
+                        compteur <= compteur + 1;
185
+                        C <= Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits);
186
+                        B <= Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits);
187
+                        A <= Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits);
188
+                        Instruction <= Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits);
189
+                        if (compteur = 2) then
190
+                            if (Z = '1') then
191
+                                Pointeur_Instruction <= Instruction_courante (2 * Nb_bits + Addr_size_mem_instruction - 1 downto 2 * Nb_bits);
192
+                            else 
193
+                                Pointeur_Instruction <= Pointeur_Instruction + 1;
194
+                            end if;
195
+                            compteur <= 0;
196
+                        end if;
197
+                    elsif (Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_STOP) then
198
+                        -- CAS PARTICULIER : STOP, si on est bloqué, on ne fait rien, programme arrété
199
+                        --                         sinon, on regarde si l'on doit se bloquer
200
+                        --                         sinon, on incremente le compteur et on attends
201
+                        if (not locked) then
202
+                            if (Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits) = Argument_nul) then
203
+                                locked <= true;
204
+                            end if;
205
+                            compteur <= compteur + 1;
206
+                            if (compteur + 1 = to_integer(unsigned(Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits))) * 1000) then
207
+                                Pointeur_Instruction <= Pointeur_Instruction + 1;
208
+                                compteur <= 0;
209
+                            end if;
210
+                        end if;
211
+                        C <= Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits);
212
+                        B <= Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits);
213
+                        A <= Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits);
214
+                        Instruction <= Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits);
215
+                    else
216
+                        -- CAS GENERAL : On transmet l'instruction et les opérandes, si elle est critique en ecriture, on enregistre le registre associé dans le tableau
217
+                        C <= Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits);
218
+                        B <= Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits);
219
+                        A <= Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits);
220
+                        Instruction <= Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits);
221
+                        if (Instructions_critiques_ecriture(to_integer(unsigned(Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits)))) = '1') then
222
+                            Tableau(1) <= to_integer(unsigned(Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits)));
223
+                        end if;
224
+                        Pointeur_Instruction <= Pointeur_Instruction + 1;
225
+                    end if;
226
+                else 
227
+                    -- Si besoin de bulle, on l'injecte
228
+                    C <= Argument_nul;
229
+                    B <= Argument_nul;
230
+                    A <= Argument_nul;
231
+                    Instruction <= Instruction_nulle;
232
+                end if;
233
+            end if;
234
+        end process;
235
+        
236
+        
237
+        -- Condition horrible -> Instruction critique en lecture sur A qui lit dans A=i et Ri dans tableau ou instruction critique en lecture sur B qui lit dans B=j et Rj dans tableau ou instruction critique en lecture sur C qui lit dans C=k et Rk dans tableau 
238
+        bulles <= 
239
+        (
240
+            (
241
+                Instructions_critiques_lecture_A(to_integer(unsigned(Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits)))) = '1' -- Intruction critique sur A
242
+            )
243
+            and 
244
+            (
245
+                (to_integer(unsigned(Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits))) = Tableau(1)) -- A est
246
+                or 
247
+                (to_integer(unsigned(Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits))) = Tableau(2)) --        dans le 
248
+                or 
249
+                (to_integer(unsigned(Instruction_courante (3 * Nb_bits - 1 downto 2 * Nb_bits))) = Tableau(3)) --                  tableau
250
+            )
251
+        ) 
252
+        or 
253
+        (
254
+            (
255
+                Instructions_critiques_lecture_B(to_integer(unsigned(Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits)))) = '1'
256
+            )
257
+            and 
258
+            (
259
+                (to_integer(unsigned(Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits))) = Tableau(1))
260
+                or 
261
+                (to_integer(unsigned(Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits))) = Tableau(2))
262
+                or 
263
+                (to_integer(unsigned(Instruction_courante (2 * Nb_bits - 1 downto 1 * Nb_bits))) = Tableau(3))
264
+            )
265
+        ) 
266
+        or
267
+        (
268
+            (
269
+                Instructions_critiques_lecture_C(to_integer(unsigned(Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits)))) = '1'
270
+            )
271
+            and 
272
+            (
273
+                (to_integer(unsigned(Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits))) = Tableau(1))
274
+                or
275
+                (to_integer(unsigned(Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits))) = Tableau(2))
276
+                or 
277
+                (to_integer(unsigned(Instruction_courante (1 * Nb_bits - 1 downto 0 * Nb_bits))) = Tableau(3))
278
+            )
279
+        );
280
+        
281
+        -- Gestion de l'écriture/lecture dans la mémoire des adresses de retour
282
+        R_Aux <= '1' when Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_Instruction_RET else
283
+                 '0';
284
+        W_Aux <= '1' when Instruction_courante (Instruction_bus_size + 3 * Nb_bits - 1 downto 3 * Nb_bits) = Code_instruction_CALL else
285
+                 '0';
286
+                 
287
+                 
288
+        Pointeur_instruction_next <= Pointeur_instruction + 1;
289
+    end Behavioral;

+ 192
- 0
Processeur.srcs/sources_1/new/Etage4_Memoire.vhd View File

@@ -0,0 +1,192 @@
1
+    ----------------------------------------------------------------------------------
2
+    -- Company:  INSA-Toulouse
3
+    -- Engineer: Paul Faure
4
+    -- 
5
+    -- Create Date: 18.04.2021 21:19:41
6
+    -- Module Name: Etage4_Memoire - Structural
7
+    -- Project Name: Processeur sécurisé
8
+    -- Target Devices: Basys 3 ARTIX7
9
+    -- Tool Versions: Vivado 2016.4
10
+    --
11
+    -- Description: Etage 4 du processeur
12
+    --     - Gestion de la mémoire
13
+    --     - Gestion de la sauvegarde du contexte lors des appels de fonction
14
+    -- 
15
+    -- Dependencies: 
16
+    --    - MemoireDonnees
17
+    --    - MemoireAdressesRetour
18
+    --    - LC
19
+    --    - MUX
20
+    ----------------------------------------------------------------------------------
21
+
22
+
23
+    library IEEE;
24
+    use IEEE.STD_LOGIC_1164.ALL;
25
+    use IEEE.STD_LOGIC_UNSIGNED.ALL;
26
+
27
+    entity Etage4_Memoire is
28
+        Generic ( Nb_bits : Natural; -- Taille d'un mot binaire
29
+                  Mem_size : Natural; -- Taille de la mémoire de donnees (nombre de mots binaires stockables)
30
+                  Adresse_mem_size : Natural; -- Nombre de bits pour adresser la mémoire de donnees
31
+                  Instruction_bus_size : Natural; -- Nombre de bits du bus d'instruction (Taille d'un code instruction)
32
+                  Mem_EBP_size : Natural; -- Taille de la mémoire du contexte (profondeur d'appel maximale)
33
+                  Adresse_size_mem_EBP : Natural; -- Nombre de bits pour adresser la mémoire de contexte
34
+                  Bits_Controle_LC : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le Link Controler (cf LC.vhd)
35
+                  Bits_Controle_MUX_IN : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant A ou B comme adresse (cf MUX.vhd)
36
+                  Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant si on doit ajouter ou non EBP à l'adresse (cf MUX.vhd)
37
+                  Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer de sortie (cf MUX.vhd)
38
+                  Code_Instruction_CALL : STD_LOGIC_VECTOR; -- Numéro de l'instruction CALL
39
+                  Code_Instruction_RET : STD_LOGIC_VECTOR); -- Numéro de l'instruction RET
40
+        Port ( CLK : in STD_LOGIC; -- Clock
41
+               RST : in STD_LOGIC; -- Reset
42
+               IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande A
43
+               IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande B
44
+               IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Entrée de l'instruction
45
+               OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande A
46
+               OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande B
47
+               OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0)); -- Sortie de l'instruction
48
+    end Etage4_Memoire;
49
+
50
+    architecture Structural of Etage4_Memoire is
51
+        component MemoireDonnees is
52
+        Generic (Nb_bits : Natural;
53
+                 Addr_size : Natural;
54
+                 Mem_size : Natural);
55
+        Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0);
56
+               RW : in STD_LOGIC;
57
+               D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
58
+               RST : in STD_LOGIC;
59
+               CLK : in STD_LOGIC;
60
+               D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'));
61
+        end component;
62
+        
63
+        component MemoireAdressesRetour is
64
+            Generic (Nb_bits : Natural;
65
+                     Addr_size : Natural;
66
+                     Mem_size : Natural);
67
+            Port ( R : in STD_LOGIC;
68
+                   W : in STD_LOGIC;
69
+                   D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
70
+                   RST : in STD_LOGIC;
71
+                   CLK : in STD_LOGIC;
72
+                   D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0');
73
+                   E : out STD_LOGIC;
74
+                   F : out STD_LOGIC);
75
+        end component;
76
+        
77
+        component LC is
78
+            Generic (Instruction_Vector_Size : Natural;
79
+                    Command_size : Natural;
80
+                    Bits_Controle : STD_LOGIC_VECTOR);
81
+            Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
82
+                   Commande : out STD_LOGIC_VECTOR (Command_size - 1 downto 0));
83
+        end component;
84
+        
85
+        component MUX is
86
+            Generic (Nb_bits : Natural;
87
+                    Instruction_Vector_Size : Natural;
88
+                    Bits_Controle : STD_LOGIC_VECTOR);
89
+            Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
90
+                   IN1 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
91
+                   IN2 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
92
+                   OUTPUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
93
+        end component;
94
+        
95
+        
96
+        signal EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- EBP (offset à ajouter à l'adresse)
97
+        signal New_EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Nouvelle valeur d'EBP, a stocker lors d'un CALL (Cf fonctionnement MemoireAdressesRetour.vhd)
98
+        
99
+        signal Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse entrante dans le composant de mémoire de donnees
100
+        signal IN_Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Sortie du mux de choix d'adresse entre A et B
101
+        signal Addr_MemoireDonnees_EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse avec EBP ajouté (IN_Addr_MemoireDonnees + BP)
102
+        
103
+        signal Commande_MemoireDonnees : STD_LOGIC_VECTOR (0 downto 0) := "0"; -- Sortie du Link Controler, signal de commande de la mémoire
104
+        
105
+        signal Sortie_MemoireDonnees : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Sortie de la mémoire (a multiplexer)
106
+        
107
+        signal intern_OUT_B : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Signal interne
108
+        
109
+        -- Signaux de la memoire de contexte
110
+        signal R_Aux : STD_LOGIC := '0';
111
+        signal W_Aux : STD_LOGIC := '0';
112
+        signal E : STD_LOGIC;
113
+        signal F : STD_LOGIC;
114
+        
115
+        
116
+    begin
117
+        instance_LC : LC -- Link controleur sur la mémoire de donnees
118
+        generic map (Instruction_Vector_Size => Instruction_bus_size,
119
+                     Command_size => 1,
120
+                     Bits_Controle => Bits_Controle_LC)
121
+        port map (   Instruction => IN_Instruction,
122
+                     Commande => Commande_MemoireDonnees);
123
+                     
124
+        instance_MUX_IN : MUX -- Multiplexeur selectionnant A ou B pour adresse
125
+        generic map (Nb_bits => Adresse_mem_size,
126
+                     Instruction_Vector_Size => Instruction_bus_size,
127
+                     Bits_Controle => Bits_Controle_MUX_IN)
128
+        port map (   Instruction => IN_Instruction,
129
+                     IN1 => IN_A (Adresse_mem_size - 1 downto 0),
130
+                     IN2 => IN_B (Adresse_mem_size - 1 downto 0),
131
+                     OUTPUT => IN_Addr_MemoireDonnees);
132
+                     
133
+        instance_MUX_IN_EBP : MUX -- Multiplexeur selectionnant l'adresse plus EBP ou l'adresse de base
134
+        generic map (Nb_bits => Adresse_mem_size,
135
+                     Instruction_Vector_Size => Instruction_bus_size,
136
+                     Bits_Controle => Bits_Controle_MUX_IN_EBP)
137
+        port map (   Instruction => IN_Instruction,
138
+                     IN1 => IN_Addr_MemoireDonnees,
139
+                     IN2 => Addr_MemoireDonnees_EBP,
140
+                     OUTPUT => Addr_MemoireDonnees);
141
+                     
142
+        instance_MUX_OUT : MUX -- Multiplexeur selectionnant la sortie de l'étage (sur B)
143
+        generic map (Nb_bits => Nb_bits,
144
+                     Instruction_Vector_Size => Instruction_bus_size,
145
+                     Bits_Controle => Bits_Controle_MUX_OUT)
146
+        port map (   Instruction => IN_Instruction,
147
+                     IN1 => Sortie_MemoireDonnees,
148
+                     IN2 => IN_B,
149
+                     OUTPUT => intern_OUT_B);
150
+
151
+        instance_MemoireDonnees : MemoireDonnees
152
+        generic map (Nb_bits => Nb_bits,
153
+                     Addr_size => Adresse_mem_size,
154
+                     Mem_size => Mem_size)
155
+        port map ( Addr => Addr_MemoireDonnees,
156
+                   RW => Commande_MemoireDonnees(0),
157
+                   D_IN => IN_B,
158
+                   RST => RST,
159
+                   CLK => CLK,
160
+                   D_OUT => Sortie_MemoireDonnees);
161
+                   
162
+        instance_MemoireEBP : MemoireAdressesRetour
163
+        generic map (Nb_bits => Adresse_mem_size,
164
+                     Addr_size => Adresse_size_mem_EBP,
165
+                     Mem_size => Mem_EBP_size
166
+        )
167
+        port map ( R => R_Aux,
168
+                   W => W_Aux,
169
+                   D_IN => New_EBP,
170
+                   RST => RST,
171
+                   CLK => CLK,
172
+                   D_OUT => EBP,
173
+                   E => E,
174
+                   F => F
175
+        );
176
+                     
177
+        OUT_A <= (others => '0') when RST = '0' else
178
+                 IN_A;
179
+        OUT_B <= (others => '0') when RST = '0' else
180
+                 intern_OUT_B;
181
+        OUT_Instruction <= (others => '0') when RST = '0' else
182
+                 IN_Instruction;
183
+                 
184
+        -- Controle de la mémoire de contexte (ici aussi un LC aurait été disproportionné)
185
+        R_Aux <= '1' when IN_Instruction = Code_Instruction_RET else
186
+                 '0';
187
+        W_Aux <= '1' when IN_Instruction = Code_Instruction_CALL else
188
+                 '0';
189
+                 
190
+        Addr_MemoireDonnees_EBP <= IN_Addr_MemoireDonnees + EBP;
191
+        New_EBP <= EBP + IN_B (Adresse_mem_size - 1 downto 0);
192
+    end Structural;

+ 328
- 0
Processeur.srcs/sources_1/new/Pipeline.vhd View File

@@ -0,0 +1,328 @@
1
+----------------------------------------------------------------------------------
2
+-- Company: 
3
+-- Engineer: 
4
+-- 
5
+-- Create Date: 19.04.2021 16:57:41
6
+-- Design Name: 
7
+-- Module Name: Pipeline - Behavioral
8
+-- Project Name: 
9
+-- Target Devices: 
10
+-- Tool Versions: 
11
+-- Description: 
12
+-- 
13
+-- Dependencies: 
14
+-- 
15
+-- Revision:
16
+-- Revision 0.01 - File Created
17
+-- Additional Comments:
18
+-- 
19
+----------------------------------------------------------------------------------
20
+
21
+
22
+library IEEE;
23
+use IEEE.STD_LOGIC_1164.ALL;
24
+
25
+-- Uncomment the following library declaration if using
26
+-- arithmetic functions with Signed or Unsigned values
27
+--use IEEE.NUMERIC_STD.ALL;
28
+
29
+-- Uncomment the following library declaration if instantiating
30
+-- any Xilinx leaf cells in this code.
31
+--library UNISIM;
32
+--use UNISIM.VComponents.all;
33
+
34
+entity Pipeline is
35
+    Generic (Nb_bits : Natural := 8;
36
+             Instruction_En_Memoire_Size : Natural := 29;
37
+             Addr_Memoire_Instruction_Size : Natural := 3;
38
+             Memoire_Instruction_Size : Natural := 8;
39
+             Instruction_Bus_Size : Natural := 5;
40
+             Nb_Instructions : Natural := 32;
41
+             Nb_Registres : Natural := 16;
42
+             Addr_registres_size : Natural := 4;
43
+             Memoire_Size : Natural := 32;
44
+             Adresse_mem_size : Natural := 5;
45
+             Memoire_Adresses_Retour_Size : Natural := 16;
46
+             Adresse_Memoire_Adresses_Retour_Size : Natural := 4);
47
+    Port (CLK : STD_LOGIC;
48
+          RST : STD_LOGIC;
49
+          STD_IN : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
50
+          STD_OUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
51
+end Pipeline;
52
+
53
+architecture Behavioral of Pipeline is
54
+    
55
+    component Etage1_LectureInstruction is
56
+    Generic (Instruction_size_in_memory : Natural;
57
+             Addr_size_mem_instruction : Natural;
58
+             Mem_instruction_size : Natural;
59
+             Nb_bits : Natural;
60
+             Instruction_bus_size : Natural;
61
+             Nb_registres : Natural;
62
+             Mem_adresse_retour_size : Natural;
63
+             Adresse_size_mem_adresse_retour : Natural;
64
+             Instructions_critiques_lecture_A : STD_LOGIC_VECTOR;
65
+             Instructions_critiques_lecture_B : STD_LOGIC_VECTOR;
66
+             Instructions_critiques_lecture_C : STD_LOGIC_VECTOR;
67
+             Instructions_critiques_ecriture : STD_LOGIC_VECTOR;
68
+             Code_Instruction_JMP : STD_LOGIC_VECTOR;
69
+             Code_Instruction_JMZ : STD_LOGIC_VECTOR;
70
+             Code_Instruction_CALL : STD_LOGIC_VECTOR;
71
+             Code_Instruction_RET : STD_LOGIC_VECTOR;
72
+             Code_Instruction_STOP : STD_LOGIC_VECTOR);
73
+    Port ( CLK : in STD_LOGIC;
74
+           RST : in STD_LOGIC;
75
+           Z : in STD_LOGIC;
76
+           A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
77
+           B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
78
+           C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
79
+           Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
80
+    end component;
81
+    
82
+    component Etage2_5_Registres is
83
+    Generic ( Nb_bits : Natural;
84
+              Nb_registres : Natural;
85
+              Addr_registres_size : Natural;
86
+              Instruction_bus_size : Natural;
87
+              Bits_Controle_LC_5 : STD_LOGIC_VECTOR;
88
+              Bits_Controle_MUX_2_A : STD_LOGIC_VECTOR;
89
+              Bits_Controle_MUX_2_B : STD_LOGIC_VECTOR;
90
+              Code_Instruction_PRI : STD_LOGIC_VECTOR;
91
+              Code_Instruction_GET : STD_LOGIC_VECTOR);
92
+    Port ( CLK : in STD_LOGIC;
93
+           RST : in STD_LOGIC;
94
+           STD_IN : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
95
+           STD_OUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
96
+           IN_2_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
97
+           IN_2_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
98
+           IN_2_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
99
+           IN_2_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
100
+           OUT_2_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
101
+           OUT_2_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
102
+           OUT_2_C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
103
+           OUT_2_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
104
+           IN_5_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
105
+           IN_5_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
106
+           IN_5_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
107
+    end component;
108
+    
109
+    component Etage3_Calcul is
110
+    Generic ( Nb_bits : Natural;
111
+              Instruction_bus_size : Natural;
112
+              Bits_Controle_LC : STD_LOGIC_VECTOR;
113
+              Bits_Controle_MUX : STD_LOGIC_VECTOR);
114
+    Port ( RST : in STD_LOGIC;
115
+           IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
116
+           IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
117
+           IN_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
118
+           IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
119
+           OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
120
+           OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
121
+           OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
122
+           N : out STD_LOGIC;
123
+           O : out STD_LOGIC;
124
+           Z : out STD_LOGIC;
125
+           C : out STD_LOGIC);
126
+    end component;
127
+        
128
+    component Etage4_Memoire is
129
+        Generic ( Nb_bits : Natural;
130
+                  Mem_size : Natural;
131
+                  Adresse_mem_size : Natural;
132
+                  Instruction_bus_size : Natural;
133
+                  Mem_EBP_size : Natural;
134
+                  Adresse_size_mem_EBP : Natural;
135
+                  Bits_Controle_LC : STD_LOGIC_VECTOR;
136
+                  Bits_Controle_MUX_IN : STD_LOGIC_VECTOR;
137
+                  Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR;
138
+                  Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR;
139
+                  Code_Instruction_CALL : STD_LOGIC_VECTOR;
140
+                  Code_Instruction_RET : STD_LOGIC_VECTOR);
141
+        Port ( CLK : in STD_LOGIC;
142
+               RST : in STD_LOGIC;
143
+               IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
144
+               IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
145
+               IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
146
+               OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
147
+               OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
148
+               OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
149
+    end component;
150
+    
151
+    signal A_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
152
+    signal A_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
153
+    signal A_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
154
+    signal A_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
155
+    signal A_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
156
+    signal A_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
157
+    signal A_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
158
+    signal A_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
159
+    signal B_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
160
+    signal B_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
161
+    signal B_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
162
+    signal B_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
163
+    signal B_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
164
+    signal B_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
165
+    signal B_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
166
+    signal B_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
167
+    signal C_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
168
+    signal C_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
169
+    signal C_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
170
+    signal C_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
171
+    signal Instruction_from_1 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
172
+    signal Instruction_from_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
173
+    signal Instruction_from_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
174
+    signal Instruction_from_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
175
+    signal Instruction_to_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
176
+    signal Instruction_to_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
177
+    signal Instruction_to_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
178
+    signal Instruction_to_5 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
179
+    signal N : STD_LOGIC := '0';
180
+    signal Z : STD_LOGIC := '0';
181
+    signal O : STD_LOGIC := '0';
182
+    signal C : STD_LOGIC := '0';
183
+    
184
+    constant Bits_Controle_MUX_2_A      : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111011101111111111111";
185
+    constant Bits_Controle_MUX_2_B      : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111111000011000000001";
186
+    constant Bits_Controle_LC_3         : STD_LOGIC_VECTOR (Nb_Instructions * 3 - 1 downto 0) := "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "111" & "110" & "101" & "100" & "010" & "011" & "001" & "000";
187
+    constant Bits_Controle_MUX_3        : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111111111111100000001";
188
+    constant Bits_Controle_LC_4         : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111111001011111111111";
189
+    constant Bits_Controle_MUX_4_IN     : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111111110101111111111";
190
+    constant Bits_Controle_MUX_4_IN_EBP : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "1111111011001111111111";
191
+    constant Bits_Controle_MUX_4_OUT    : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0000000001010000000000";
192
+    constant Bits_Controle_LC_5         : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0001000001011111111110";
193
+    constant Code_Instruction_JMP  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "01111";
194
+    constant Code_Instruction_JMZ  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10000";
195
+    constant Code_Instruction_PRI  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10001";
196
+    constant Code_Instruction_GET  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10010";
197
+    constant Code_Instruction_CALL : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10011";
198
+    constant Code_Instruction_RET  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10100";
199
+    constant Code_Instruction_STOP  : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10101";
200
+    
201
+    constant Instructions_critiques_lecture_A : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0000100010000000000000";
202
+    constant Instructions_critiques_lecture_B : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0000000111100111111110";
203
+    constant Instructions_critiques_lecture_C : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0000000000000011111110";
204
+    constant Instructions_critiques_ecriture  : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111111" & "0001000001011111111110";
205
+begin
206
+    instance_Etage1 : Etage1_LectureInstruction
207
+    generic map (Instruction_size_in_memory => Instruction_En_Memoire_Size,
208
+                 Addr_size_mem_instruction => Addr_Memoire_Instruction_Size,
209
+                 Mem_instruction_size => Memoire_Instruction_Size,
210
+                 Nb_bits => Nb_bits,
211
+                 Instruction_bus_size => Instruction_Bus_Size,
212
+                 Nb_registres => Nb_Registres,
213
+                 Mem_adresse_retour_size => Memoire_Adresses_Retour_Size,
214
+                 Adresse_size_mem_adresse_retour => Adresse_Memoire_Adresses_Retour_Size,
215
+                 Instructions_critiques_lecture_A => Instructions_critiques_lecture_A,
216
+                 Instructions_critiques_lecture_B => Instructions_critiques_lecture_B,
217
+                 Instructions_critiques_lecture_C => Instructions_critiques_lecture_C,
218
+                 Instructions_critiques_ecriture => Instructions_critiques_ecriture,
219
+                 Code_Instruction_JMP => Code_Instruction_JMP,
220
+                 Code_Instruction_JMZ => Code_Instruction_JMZ,
221
+                 Code_Instruction_CALL => Code_Instruction_CALL,
222
+                 Code_Instruction_RET => Code_Instruction_RET,
223
+                 Code_Instruction_STOP => Code_Instruction_STOP
224
+    )
225
+    port map (
226
+        CLK => CLK,
227
+        RST => RST,
228
+        Z => Z,
229
+        A => A_from_1,
230
+        B => B_from_1,
231
+        C => C_from_1,
232
+        Instruction => Instruction_from_1
233
+    );
234
+    
235
+    instance_Etage2_5 : Etage2_5_Registres
236
+    generic map( Nb_bits => Nb_bits,
237
+                 Nb_Registres => Nb_Registres,
238
+                 Addr_registres_size => Addr_registres_size,
239
+                 Instruction_bus_size => Instruction_Bus_Size,
240
+                 Bits_Controle_LC_5 => Bits_Controle_LC_5,
241
+                 Bits_Controle_MUX_2_A => Bits_Controle_MUX_2_A,
242
+                 Bits_Controle_MUX_2_B => Bits_Controle_MUX_2_B,
243
+                 Code_Instruction_PRI => Code_Instruction_PRI,
244
+                 Code_Instruction_GET => Code_Instruction_GET
245
+    )
246
+    port map(    CLK => CLK,
247
+                 RST => RST,
248
+                 STD_IN => STD_IN,
249
+                 STD_OUT => STD_OUT,
250
+                 IN_2_A => A_to_2,
251
+                 IN_2_B => B_to_2,
252
+                 IN_2_C => C_to_2,
253
+                 IN_2_Instruction => Instruction_to_2,
254
+                 OUT_2_A => A_from_2,
255
+                 OUT_2_B => B_from_2,
256
+                 OUT_2_C => C_from_2,
257
+                 OUT_2_Instruction => Instruction_from_2,
258
+                 IN_5_A => A_to_5,
259
+                 IN_5_B => B_to_5,
260
+                 IN_5_Instruction => Instruction_to_5
261
+    );
262
+    
263
+    instance_Etage3 : Etage3_Calcul
264
+    generic map( Nb_bits => Nb_bits,
265
+                 Instruction_bus_size => Instruction_Bus_Size,
266
+                 Bits_Controle_LC => Bits_Controle_LC_3,
267
+                 Bits_Controle_MUX => Bits_Controle_MUX_3
268
+    )
269
+    port map(    RST => RST,
270
+                 IN_A => A_to_3,
271
+                 IN_B => B_to_3,
272
+                 IN_C => C_to_3,
273
+                 IN_Instruction => Instruction_to_3,
274
+                 OUT_A => A_from_3,
275
+                 OUT_B => B_from_3,
276
+                 OUT_Instruction => Instruction_from_3,
277
+                 N => N,
278
+                 O => O,
279
+                 Z => Z,
280
+                 C => C
281
+    );
282
+                      
283
+    instance_Etage4 : Etage4_Memoire
284
+    generic map( Nb_bits => Nb_bits,
285
+                 Mem_size => Memoire_Size,
286
+                 Adresse_mem_size => Adresse_mem_size,
287
+                 Instruction_bus_size => Instruction_Bus_Size,
288
+                 Mem_EBP_size => Memoire_Adresses_Retour_Size,
289
+                 Adresse_size_mem_EBP => Adresse_Memoire_Adresses_Retour_Size,
290
+                 Bits_Controle_LC => Bits_Controle_LC_4,
291
+                 Bits_Controle_MUX_IN => Bits_Controle_MUX_4_IN,
292
+                 Bits_Controle_MUX_IN_EBP => Bits_Controle_MUX_4_IN_EBP,
293
+                 Bits_Controle_MUX_OUT => Bits_Controle_MUX_4_OUT,
294
+                 Code_Instruction_CALL => Code_Instruction_CALL,
295
+                 Code_Instruction_RET => Code_Instruction_RET
296
+    )
297
+    port map(    CLK => CLK,
298
+                 RST => RST,
299
+                 IN_A => A_to_4,
300
+                 IN_B => B_to_4,
301
+                 IN_Instruction => Instruction_to_4,
302
+                 OUT_A => A_from_4,
303
+                 OUT_B => B_from_4,
304
+                 OUT_Instruction => Instruction_from_4
305
+    );
306
+
307
+    process
308
+    begin
309
+        wait until CLK'event and CLK = '1';
310
+        A_to_2 <= A_from_1;
311
+        B_to_2 <= B_from_1;
312
+        C_to_2 <= C_from_1;
313
+        Instruction_to_2 <= Instruction_from_1;
314
+        
315
+        A_to_3 <= A_from_2;
316
+        B_to_3 <= B_from_2;
317
+        C_to_3 <= C_from_2;
318
+        Instruction_to_3 <= Instruction_from_2;
319
+
320
+        A_to_4 <= A_from_3;
321
+        B_to_4 <= B_from_3;
322
+        Instruction_to_4 <= Instruction_from_3;
323
+
324
+        A_to_5 <= A_from_4;
325
+        B_to_5 <= B_from_4;
326
+        Instruction_to_5 <= Instruction_from_4;
327
+    end process;        
328
+end Behavioral;

+ 43
- 8
Processeur.srcs/sources_1/new/System.vhd View File

@@ -31,6 +31,26 @@ entity System is
31 31
 end System;
32 32
 
33 33
 architecture Structural of System is
34
+
35
+    component Pipeline is
36
+    Generic (Nb_bits : Natural := 8;
37
+             Instruction_En_Memoire_Size : Natural := 29;
38
+             Addr_Memoire_Instruction_Size : Natural := 3;
39
+             Memoire_Instruction_Size : Natural := 8;
40
+             Instruction_Bus_Size : Natural := 5;
41
+             Nb_Instructions : Natural := 32;
42
+             Nb_Registres : Natural := 16;
43
+             Addr_registres_size : Natural := 4;
44
+             Memoire_Size : Natural := 32;
45
+             Adresse_mem_size : Natural := 5;
46
+             Memoire_Adresses_Retour_Size : Natural := 16;
47
+             Adresse_Memoire_Adresses_Retour_Size : Natural := 4);
48
+    Port (CLK : STD_LOGIC;
49
+          RST : STD_LOGIC;
50
+          STD_IN : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
51
+          STD_OUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
52
+    end component;
53
+
34 54
     component Pipeline_NS is
35 55
     Generic (Nb_bits : Natural := 8;
36 56
              Instruction_En_Memoire_Size : Natural := 29;
@@ -54,21 +74,36 @@ architecture Structural of System is
54 74
     -- signaux auxiliaires
55 75
     signal my_RST : STD_LOGIC;
56 76
     signal my_CLK : STD_LOGIC;
77
+    
78
+    constant SECURISED : boolean := true;
57 79
         
58 80
 begin     
81
+           
59 82
     -- Diviseur de clock
60 83
     clk_div : Clock_Divider
61 84
     port map (CLK_IN => CLK,
62 85
               CLK_OUT => my_CLK);
63 86
               
64
-    -- Le processeur, augmentation de la taille de la mémoire d'instruction
65
-    instance : Pipeline_NS
66
-    generic map (Addr_Memoire_Instruction_Size => 8,
67
-                 Memoire_Instruction_Size => 256)
68
-    port map (CLK => my_CLK,
69
-              RST => my_RST,
70
-              STD_IN => sw,
71
-              STD_OUT => led);
87
+              
88
+    -- Generation du processeur en fonction de la condition sécurisé ou non       
89
+    instance: if (SECURISED) generate
90
+        instance_securisee : entity work.Pipeline
91
+            generic map (Addr_Memoire_Instruction_Size => 8,
92
+                         Memoire_Instruction_Size => 256)
93
+            port map (CLK => my_CLK,
94
+                      RST => my_RST,
95
+                      STD_IN => sw,
96
+                      STD_OUT => led);
97
+    else generate
98
+        instance_non_securisee : entity work.Pipeline_NS
99
+            generic map (Addr_Memoire_Instruction_Size => 8,
100
+                         Memoire_Instruction_Size => 256)
101
+            port map (CLK => my_CLK,
102
+                      RST => my_RST,
103
+                      STD_IN => sw,
104
+                      STD_OUT => led);
105
+    end generate;  
106
+          
72 107
               
73 108
     -- Gestion du RST (inversion d'état)
74 109
     my_RST <= '1' when btnC = '0' else

+ 19
- 1
Processeur.xpr View File

@@ -62,7 +62,7 @@
62 62
         </FileInfo>
63 63
       </File>
64 64
       <File Path="$PSRCDIR/sources_1/new/System.vhd">
65
-        <FileInfo>
65
+        <FileInfo SFType="VHDL2008">
66 66
           <Attr Name="UsedIn" Val="synthesis"/>
67 67
           <Attr Name="UsedIn" Val="simulation"/>
68 68
         </FileInfo>
@@ -139,6 +139,24 @@
139 139
           <Attr Name="UsedIn" Val="simulation"/>
140 140
         </FileInfo>
141 141
       </File>
142
+      <File Path="$PSRCDIR/sources_1/new/Pipeline.vhd">
143
+        <FileInfo>
144
+          <Attr Name="UsedIn" Val="synthesis"/>
145
+          <Attr Name="UsedIn" Val="simulation"/>
146
+        </FileInfo>
147
+      </File>
148
+      <File Path="$PSRCDIR/sources_1/new/Etage4_Memoire.vhd">
149
+        <FileInfo>
150
+          <Attr Name="UsedIn" Val="synthesis"/>
151
+          <Attr Name="UsedIn" Val="simulation"/>
152
+        </FileInfo>
153
+      </File>
154
+      <File Path="$PSRCDIR/sources_1/new/Etage1_LectureInstruction.vhd">
155
+        <FileInfo>
156
+          <Attr Name="UsedIn" Val="synthesis"/>
157
+          <Attr Name="UsedIn" Val="simulation"/>
158
+        </FileInfo>
159
+      </File>
142 160
       <Config>
143 161
         <Option Name="DesignMode" Val="RTL"/>
144 162
         <Option Name="TopModule" Val="System"/>

Loading…
Cancel
Save