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.vhd 16KB

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