No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Pipeline_NS.vhd 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. ----------------------------------------------------------------------------------
  2. -- Company: INSA-Toulouse
  3. -- Engineer: Paul Faure
  4. --
  5. -- Create Date: 19.04.2021 16:57:41
  6. -- Module Name: Pipeline_NS - Behavioral
  7. -- Project Name: Processeur sécurisé
  8. -- Target Devices: Basys 3 ARTIX7
  9. -- Tool Versions: Vivado 2016.4
  10. -- Description: Version non sécurisée du pipeline, connecte les étages et fait avancer les signaux sur le pipeline
  11. --
  12. -- Dependencies:
  13. -- - Etage1_LectureInstruction_NS
  14. -- - Etage2_5_Registres
  15. -- - Etage3_Calcul
  16. -- - Etage4_Memoire_NS
  17. ----------------------------------------------------------------------------------
  18. library IEEE;
  19. use IEEE.STD_LOGIC_1164.ALL;
  20. entity Pipeline_NS is
  21. Generic (Nb_bits : Natural := 8; -- Taille d'un mot binaire
  22. Instruction_En_Memoire_Size : Natural := 29; -- Taille d'une instruction en mémoire (Taille d'un code instruction + 3*Taille d'un mot binaire)
  23. Addr_Memoire_Instruction_Size : Natural := 3; -- Nombre de bits pour adresser la mémoire d'instruction
  24. Memoire_Instruction_Size : Natural := 8; -- Taille de la mémoire d'instruction (nombre d'instructions stockées)
  25. Instruction_Bus_Size : Natural := 5; -- Nombre de bits du bus d'instruction (Taille d'un code instruction)
  26. Nb_Instructions : Natural := 32; -- Nombre d'instructions dans le processeur
  27. Nb_Registres : Natural := 16; -- Nombre de registres du processeurs
  28. Addr_registres_size : Natural := 4; -- Nombre de bits pour adresser les registres
  29. Memoire_Size : Natural := 32; -- Taille de la mémoire de données
  30. Adresse_mem_size : Natural := 5); -- Nombre de bits pour adresser la mémoire
  31. Port (CLK : STD_LOGIC;
  32. RST : STD_LOGIC;
  33. STD_IN : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  34. STD_IN_Av : in STD_LOGIC;
  35. STD_IN_Request : out STD_LOGIC;
  36. STD_OUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  37. STD_OUT_Av : out STD_LOGIC;
  38. STD_OUT_Int : out STD_LOGIC);
  39. end Pipeline_NS;
  40. architecture Behavioral of Pipeline_NS is
  41. component Etage1_LectureInstruction_NS is
  42. Generic (Instruction_size_in_memory : Natural;
  43. Addr_size_mem_instruction : Natural;
  44. Mem_instruction_size : Natural;
  45. Nb_bits : Natural;
  46. Instruction_bus_size : Natural;
  47. Nb_registres : Natural;
  48. Instructions_critiques_lecture_A : STD_LOGIC_VECTOR;
  49. Instructions_critiques_lecture_B : STD_LOGIC_VECTOR;
  50. Instructions_critiques_lecture_C : STD_LOGIC_VECTOR;
  51. Instructions_critiques_ecriture : STD_LOGIC_VECTOR;
  52. Code_Instruction_JMP : STD_LOGIC_VECTOR;
  53. Code_Instruction_JMZ : STD_LOGIC_VECTOR;
  54. Code_Instruction_PRI : STD_LOGIC_VECTOR;
  55. Code_Instruction_PRIC : STD_LOGIC_VECTOR;
  56. Code_Instruction_CALL : STD_LOGIC_VECTOR;
  57. Code_Instruction_RET : STD_LOGIC_VECTOR;
  58. Code_Instruction_STOP : STD_LOGIC_VECTOR);
  59. Port ( CLK : in STD_LOGIC;
  60. RST : in STD_LOGIC;
  61. Z : in STD_LOGIC;
  62. STD_IN_Request : in STD_LOGIC;
  63. Addr_Retour : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'adresse de retour depuis l'étage 4
  64. A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  65. B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  66. C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  67. Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
  68. end component;
  69. component Etage2_5_Registres is
  70. Generic ( Nb_bits : Natural;
  71. Nb_registres : Natural;
  72. Addr_registres_size : Natural;
  73. Instruction_bus_size : Natural;
  74. Bits_Controle_LC_5 : STD_LOGIC_VECTOR;
  75. Bits_Controle_MUX_2_A : STD_LOGIC_VECTOR;
  76. Bits_Controle_MUX_2_B : STD_LOGIC_VECTOR;
  77. Code_Instruction_PRI : STD_LOGIC_VECTOR;
  78. Code_Instruction_PRIC : STD_LOGIC_VECTOR;
  79. Code_Instruction_GET : STD_LOGIC_VECTOR);
  80. Port ( CLK : in STD_LOGIC;
  81. RST : in STD_LOGIC;
  82. STD_IN : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de données depuis l'exterieur du processeur
  83. STD_IN_Av : in STD_LOGIC;
  84. STD_IN_Request : out STD_LOGIC;
  85. STD_OUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de données vers l'exterieur du processeur
  86. STD_OUT_Av : out STD_LOGIC;
  87. STD_OUT_Int : out STD_LOGIC;
  88. IN_2_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  89. IN_2_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  90. IN_2_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  91. IN_2_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  92. OUT_2_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  93. OUT_2_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  94. OUT_2_C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  95. OUT_2_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  96. IN_5_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  97. IN_5_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  98. IN_5_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
  99. end component;
  100. component Etage3_Calcul is
  101. Generic ( Nb_bits : Natural;
  102. Instruction_bus_size : Natural;
  103. Bits_Controle_LC : STD_LOGIC_VECTOR;
  104. Bits_Controle_MUX : STD_LOGIC_VECTOR);
  105. Port ( RST : in STD_LOGIC;
  106. IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  107. IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  108. IN_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  109. IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  110. OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  111. OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  112. OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  113. N : out STD_LOGIC;
  114. O : out STD_LOGIC;
  115. Z : out STD_LOGIC;
  116. C : out STD_LOGIC);
  117. end component;
  118. component Etage4_Memoire_NS is
  119. Generic ( Nb_bits : Natural;
  120. Mem_size : Natural;
  121. Adresse_mem_size : Natural;
  122. Instruction_bus_size : Natural;
  123. Bits_Controle_LC : STD_LOGIC_VECTOR;
  124. Bits_Controle_MUX_IN : STD_LOGIC_VECTOR;
  125. Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR;
  126. Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR;
  127. Code_Instruction_CALL : STD_LOGIC_VECTOR;
  128. Code_Instruction_RET : STD_LOGIC_VECTOR);
  129. Port ( CLK : in STD_LOGIC;
  130. RST : in STD_LOGIC;
  131. IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  132. IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  133. IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  134. OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  135. OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  136. OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  137. OUT_AddrRetour : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
  138. end component;
  139. -- Signaux reliant les étages
  140. signal A_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  141. signal A_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  142. signal A_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  143. signal A_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  144. signal A_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  145. signal A_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  146. signal A_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  147. signal A_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  148. signal B_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  149. signal B_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  150. signal B_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  151. signal B_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  152. signal B_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  153. signal B_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  154. signal B_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  155. signal B_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  156. signal C_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  157. signal C_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  158. signal C_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  159. signal C_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  160. signal Instruction_from_1 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  161. signal Instruction_from_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  162. signal Instruction_from_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  163. signal Instruction_from_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  164. signal Instruction_to_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  165. signal Instruction_to_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  166. signal Instruction_to_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  167. signal Instruction_to_5 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  168. -- Sorties de l'ALU
  169. signal N : STD_LOGIC := '0';
  170. signal Z : STD_LOGIC := '0';
  171. signal O : STD_LOGIC := '0';
  172. signal C : STD_LOGIC := '0';
  173. -- Sortie de l'adresse de retour de l'étage 4 vers le 1
  174. signal AdresseRetour : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  175. signal intern_STD_IN_Request : STD_LOGIC := '0';
  176. -- Constantes de contrôle des MUX et LC
  177. constant Bits_Controle_MUX_2_A : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "11110011101111111111111";
  178. constant Bits_Controle_MUX_2_B : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "11111111000011000000001";
  179. 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";
  180. constant Bits_Controle_MUX_3 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "11111111111111100000001";
  181. constant Bits_Controle_LC_4 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "11111111001011111111111";
  182. constant Bits_Controle_MUX_4_IN : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "11111111110101111111111";
  183. constant Bits_Controle_MUX_4_IN_EBP : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "10011111011001111111111";
  184. constant Bits_Controle_MUX_4_OUT : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00000000001010000000000";
  185. constant Bits_Controle_LC_5 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00010000001011111111110";
  186. constant Code_Instruction_JMP : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "01111";
  187. constant Code_Instruction_JMZ : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10000";
  188. constant Code_Instruction_PRI : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10001";
  189. constant Code_Instruction_PRIC : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10010";
  190. constant Code_Instruction_GET : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10011";
  191. constant Code_Instruction_CALL : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10100";
  192. constant Code_Instruction_RET : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10101";
  193. constant Code_Instruction_STOP : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "10110";
  194. -- Constantes de contrôle des bulles
  195. constant Instructions_critiques_lecture_A : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00001100010000000000000";
  196. constant Instructions_critiques_lecture_B : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00000000111100111111110";
  197. constant Instructions_critiques_lecture_C : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00000000000000011111110";
  198. constant Instructions_critiques_ecriture : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "111111111" & "00010000001011111111110";
  199. begin
  200. instance_Etage1 : Etage1_LectureInstruction_NS
  201. generic map (Instruction_size_in_memory => Instruction_En_Memoire_Size,
  202. Addr_size_mem_instruction => Addr_Memoire_Instruction_Size,
  203. Mem_instruction_size => Memoire_Instruction_Size,
  204. Nb_bits => Nb_bits,
  205. Instruction_bus_size => Instruction_Bus_Size,
  206. Nb_registres => Nb_Registres,
  207. Instructions_critiques_lecture_A => Instructions_critiques_lecture_A,
  208. Instructions_critiques_lecture_B => Instructions_critiques_lecture_B,
  209. Instructions_critiques_lecture_C => Instructions_critiques_lecture_C,
  210. Instructions_critiques_ecriture => Instructions_critiques_ecriture,
  211. Code_Instruction_JMP => Code_Instruction_JMP,
  212. Code_Instruction_JMZ => Code_Instruction_JMZ,
  213. Code_Instruction_PRI => Code_Instruction_PRI,
  214. Code_Instruction_PRIC => Code_Instruction_PRIC,
  215. Code_Instruction_CALL => Code_Instruction_CALL,
  216. Code_Instruction_RET => Code_Instruction_RET,
  217. Code_Instruction_STOP => Code_Instruction_STOP
  218. )
  219. port map (
  220. CLK => CLK,
  221. RST => RST,
  222. Z => Z,
  223. STD_IN_Request => intern_STD_IN_Request,
  224. Addr_Retour => AdresseRetour,
  225. A => A_from_1,
  226. B => B_from_1,
  227. C => C_from_1,
  228. Instruction => Instruction_from_1
  229. );
  230. instance_Etage2_5 : Etage2_5_Registres
  231. generic map( Nb_bits => Nb_bits,
  232. Nb_Registres => Nb_Registres,
  233. Addr_registres_size => Addr_registres_size,
  234. Instruction_bus_size => Instruction_Bus_Size,
  235. Bits_Controle_LC_5 => Bits_Controle_LC_5,
  236. Bits_Controle_MUX_2_A => Bits_Controle_MUX_2_A,
  237. Bits_Controle_MUX_2_B => Bits_Controle_MUX_2_B,
  238. Code_Instruction_PRI => Code_Instruction_PRI,
  239. Code_Instruction_PRIC => Code_Instruction_PRIC,
  240. Code_Instruction_GET => Code_Instruction_GET
  241. )
  242. port map( CLK => CLK,
  243. RST => RST,
  244. STD_IN => STD_IN,
  245. STD_IN_Av => STD_IN_Av,
  246. STD_IN_Request => intern_STD_IN_Request,
  247. STD_OUT => STD_OUT,
  248. STD_OUT_Av => STD_OUT_Av,
  249. STD_OUT_Int => STD_OUT_Int,
  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. instance_Etage3 : Etage3_Calcul
  263. generic map( Nb_bits => Nb_bits,
  264. Instruction_bus_size => Instruction_Bus_Size,
  265. Bits_Controle_LC => Bits_Controle_LC_3,
  266. Bits_Controle_MUX => Bits_Controle_MUX_3
  267. )
  268. port map( RST => RST,
  269. IN_A => A_to_3,
  270. IN_B => B_to_3,
  271. IN_C => C_to_3,
  272. IN_Instruction => Instruction_to_3,
  273. OUT_A => A_from_3,
  274. OUT_B => B_from_3,
  275. OUT_Instruction => Instruction_from_3,
  276. N => N,
  277. O => O,
  278. Z => Z,
  279. C => C
  280. );
  281. instance_Etage4 : Etage4_Memoire_NS
  282. generic map( Nb_bits => Nb_bits,
  283. Mem_size => Memoire_Size,
  284. Adresse_mem_size => Adresse_mem_size,
  285. Instruction_bus_size => Instruction_Bus_Size,
  286. Bits_Controle_LC => Bits_Controle_LC_4,
  287. Bits_Controle_MUX_IN => Bits_Controle_MUX_4_IN,
  288. Bits_Controle_MUX_IN_EBP => Bits_Controle_MUX_4_IN_EBP,
  289. Bits_Controle_MUX_OUT => Bits_Controle_MUX_4_OUT,
  290. Code_Instruction_CALL => Code_Instruction_CALL,
  291. Code_Instruction_RET => Code_Instruction_RET
  292. )
  293. port map( CLK => CLK,
  294. RST => RST,
  295. IN_A => A_to_4,
  296. IN_B => B_to_4,
  297. IN_Instruction => Instruction_to_4,
  298. OUT_A => A_from_4,
  299. OUT_B => B_from_4,
  300. OUT_Instruction => Instruction_from_4,
  301. OUT_AddrRetour => AdresseRetour
  302. );
  303. STD_IN_Request <= intern_STD_IN_Request;
  304. process
  305. begin
  306. wait until CLK'event and CLK = '1';
  307. if (intern_STD_IN_Request = '0') then
  308. A_to_2 <= A_from_1;
  309. B_to_2 <= B_from_1;
  310. C_to_2 <= C_from_1;
  311. Instruction_to_2 <= Instruction_from_1;
  312. A_to_3 <= A_from_2;
  313. B_to_3 <= B_from_2;
  314. C_to_3 <= C_from_2;
  315. Instruction_to_3 <= Instruction_from_2;
  316. A_to_4 <= A_from_3;
  317. B_to_4 <= B_from_3;
  318. Instruction_to_4 <= Instruction_from_3;
  319. A_to_5 <= A_from_4;
  320. B_to_5 <= B_from_4;
  321. Instruction_to_5 <= Instruction_from_4;
  322. end if;
  323. end process;
  324. end Behavioral;