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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 := 28;
  32. Addr_Memoire_Instruction_Size : Natural := 3;
  33. Memoire_Instruction_Size : Natural := 8;
  34. Instruction_Bus_Size : Natural := 4;
  35. Nb_Instructions : Natural := 16;
  36. Nb_Registres : Natural := 16;
  37. Memoire_Size : Natural := 8;
  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. end Pipeline;
  43. architecture Behavioral of Pipeline is
  44. component Etage1_LectureInstruction is
  45. Generic (Instruction_size_in_memory : Natural;
  46. Addr_size_mem_instruction : Natural;
  47. Mem_instruction_size : Natural;
  48. Nb_bits : Natural;
  49. Instruction_bus_size : Natural;
  50. Nb_registres : Natural;
  51. Mem_adresse_retour_size : Natural;
  52. Adresse_size_mem_adresse_retour : Natural;
  53. Instructions_critiques_lecture : STD_LOGIC_VECTOR;
  54. Instructions_critiques_lecture_double : STD_LOGIC_VECTOR;
  55. Instructions_critiques_ecriture : STD_LOGIC_VECTOR;
  56. Code_Instruction_JMP : STD_LOGIC_VECTOR;
  57. Code_Instruction_JMZ : STD_LOGIC_VECTOR;
  58. Code_Instruction_CALL : STD_LOGIC_VECTOR;
  59. Code_Instruction_RET : STD_LOGIC_VECTOR);
  60. Port ( CLK : in STD_LOGIC;
  61. RST : in STD_LOGIC;
  62. Z : in STD_LOGIC;
  63. A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  64. B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  65. C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  66. Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
  67. end component;
  68. component Etage2_5_Registres is
  69. Generic ( Nb_bits : Natural;
  70. Nb_registres : Natural;
  71. Instruction_bus_size : Natural;
  72. Bits_Controle_LC_5 : STD_LOGIC_VECTOR;
  73. Bits_Controle_MUX_2 : STD_LOGIC_VECTOR);
  74. Port ( CLK : in STD_LOGIC;
  75. RST : in STD_LOGIC;
  76. IN_2_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  77. IN_2_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  78. IN_2_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  79. IN_2_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  80. OUT_2_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  81. OUT_2_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  82. OUT_2_C : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  83. OUT_2_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  84. IN_5_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  85. IN_5_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  86. IN_5_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
  87. end component;
  88. component Etage3_Calcul is
  89. Generic ( Nb_bits : Natural;
  90. Instruction_bus_size : Natural;
  91. Bits_Controle_LC : STD_LOGIC_VECTOR;
  92. Bits_Controle_MUX : STD_LOGIC_VECTOR);
  93. Port ( RST : in STD_LOGIC;
  94. IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  95. IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  96. IN_C : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  97. IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  98. OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  99. OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  100. OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  101. N : out STD_LOGIC;
  102. O : out STD_LOGIC;
  103. Z : out STD_LOGIC;
  104. C : out STD_LOGIC);
  105. end component;
  106. component Etage4_Memoire is
  107. Generic ( Nb_bits : Natural;
  108. Mem_size : Natural;
  109. Instruction_bus_size : Natural;
  110. Bits_Controle_LC : STD_LOGIC_VECTOR;
  111. Bits_Controle_MUX_IN : STD_LOGIC_VECTOR;
  112. Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR);
  113. Port ( CLK : in STD_LOGIC;
  114. 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_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0);
  118. OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  119. OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  120. OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0));
  121. end component;
  122. signal A_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  123. signal A_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  124. signal A_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  125. signal A_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  126. signal A_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  127. signal A_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  128. signal A_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  129. signal A_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  130. signal B_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  131. signal B_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  132. signal B_from_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  133. signal B_from_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  134. signal B_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  135. signal B_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  136. signal B_to_4 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  137. signal B_to_5 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  138. signal C_from_1 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  139. signal C_from_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  140. signal C_to_2 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  141. signal C_to_3 : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0');
  142. signal Instruction_from_1 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  143. signal Instruction_from_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  144. signal Instruction_from_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  145. signal Instruction_from_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  146. signal Instruction_to_2 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  147. signal Instruction_to_3 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  148. signal Instruction_to_4 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  149. signal Instruction_to_5 : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := (others => '0');
  150. signal N : STD_LOGIC := '0';
  151. signal Z : STD_LOGIC := '0';
  152. signal O : STD_LOGIC := '0';
  153. signal C : STD_LOGIC := '0';
  154. constant Bits_Controle_MUX_2 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1101011000000001";
  155. constant Bits_Controle_LC_3 : STD_LOGIC_VECTOR (Nb_Instructions * 3 - 1 downto 0) := "000" & "000" & "000" & "000" & "000" & "000" & "000" & "000" & "111" & "110" & "101" & "100" & "010" & "011" & "001" & "000";
  156. constant Bits_Controle_MUX_3 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111111100000001";
  157. constant Bits_Controle_LC_4 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111011111111111";
  158. constant Bits_Controle_MUX_4_IN : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "1111101111111111";
  159. constant Bits_Controle_MUX_4_OUT : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "0000010000000000";
  160. constant Bits_Controle_LC_5 : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "0000011111111110";
  161. constant Code_Instruction_JMP : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "1100";
  162. constant Code_Instruction_JMZ : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "1101";
  163. constant Code_Instruction_CALL : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "1110";
  164. constant Code_Instruction_RET : STD_LOGIC_VECTOR (Instruction_Bus_Size - 1 downto 0) := "1111";
  165. constant Instructions_critiques_lecture : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "0000100111111110";
  166. constant Instructions_critiques_lecture_double : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "0000000011111110";
  167. constant Instructions_critiques_ecriture : STD_LOGIC_VECTOR (Nb_Instructions - 1 downto 0) := "0000011111111110";
  168. begin
  169. instance_Etage1 : Etage1_LectureInstruction
  170. generic map (Instruction_size_in_memory => Instruction_En_Memoire_Size,
  171. Addr_size_mem_instruction => Addr_Memoire_Instruction_Size,
  172. Mem_instruction_size => Memoire_Instruction_Size,
  173. Nb_bits => Nb_bits,
  174. Instruction_bus_size => Instruction_Bus_Size,
  175. Nb_registres => Nb_Registres,
  176. Mem_adresse_retour_size => Memoire_Adresses_Retour_Size,
  177. Adresse_size_mem_adresse_retour => Adresse_Memoire_Adresses_Retour_Size,
  178. Instructions_critiques_lecture => Instructions_critiques_lecture,
  179. Instructions_critiques_lecture_double => Instructions_critiques_lecture_double,
  180. Instructions_critiques_ecriture => Instructions_critiques_ecriture,
  181. Code_Instruction_JMP => Code_Instruction_JMP,
  182. Code_Instruction_JMZ => Code_Instruction_JMZ,
  183. Code_Instruction_CALL => Code_Instruction_CALL,
  184. Code_Instruction_RET => Code_Instruction_RET
  185. )
  186. port map (
  187. CLK => CLK,
  188. RST => RST,
  189. Z => Z,
  190. A => A_from_1,
  191. B => B_from_1,
  192. C => C_from_1,
  193. Instruction => Instruction_from_1
  194. );
  195. instance_Etage2_5 : Etage2_5_Registres
  196. generic map( Nb_bits => Nb_bits,
  197. Nb_Registres => Nb_Registres,
  198. Instruction_bus_size => Instruction_Bus_Size,
  199. Bits_Controle_LC_5 => Bits_Controle_LC_5,
  200. Bits_Controle_MUX_2 => Bits_Controle_MUX_2
  201. )
  202. port map( CLK => CLK,
  203. RST => RST,
  204. IN_2_A => A_to_2,
  205. IN_2_B => B_to_2,
  206. IN_2_C => C_to_2,
  207. IN_2_Instruction => Instruction_to_2,
  208. OUT_2_A => A_from_2,
  209. OUT_2_B => B_from_2,
  210. OUT_2_C => C_from_2,
  211. OUT_2_Instruction => Instruction_from_2,
  212. IN_5_A => A_to_5,
  213. IN_5_B => B_to_5,
  214. IN_5_Instruction => Instruction_to_5
  215. );
  216. instance_Etage3 : Etage3_Calcul
  217. generic map( Nb_bits => Nb_bits,
  218. Instruction_bus_size => Instruction_Bus_Size,
  219. Bits_Controle_LC => Bits_Controle_LC_3,
  220. Bits_Controle_MUX => Bits_Controle_MUX_3
  221. )
  222. port map( RST => RST,
  223. IN_A => A_to_3,
  224. IN_B => B_to_3,
  225. IN_C => C_to_3,
  226. IN_Instruction => Instruction_to_3,
  227. OUT_A => A_from_3,
  228. OUT_B => B_from_3,
  229. OUT_Instruction => Instruction_from_3,
  230. N => N,
  231. O => O,
  232. Z => Z,
  233. C => C
  234. );
  235. instance_Etage4 : Etage4_Memoire
  236. generic map( Nb_bits => Nb_bits,
  237. Mem_size => Memoire_Size,
  238. Instruction_bus_size => Instruction_Bus_Size,
  239. Bits_Controle_LC => Bits_Controle_LC_4,
  240. Bits_Controle_MUX_IN => Bits_Controle_MUX_4_IN,
  241. Bits_Controle_MUX_OUT => Bits_Controle_MUX_4_OUT
  242. )
  243. port map( CLK => CLK,
  244. RST => RST,
  245. IN_A => A_to_4,
  246. IN_B => B_to_4,
  247. IN_Instruction => Instruction_to_4,
  248. OUT_A => A_from_4,
  249. OUT_B => B_from_4,
  250. OUT_Instruction => Instruction_from_4
  251. );
  252. process
  253. begin
  254. wait until CLK'event and CLK = '1';
  255. A_to_2 <= A_from_1;
  256. B_to_2 <= B_from_1;
  257. C_to_2 <= C_from_1;
  258. Instruction_to_2 <= Instruction_from_1;
  259. A_to_3 <= A_from_2;
  260. B_to_3 <= B_from_2;
  261. C_to_3 <= C_from_2;
  262. Instruction_to_3 <= Instruction_from_2;
  263. A_to_4 <= A_from_3;
  264. B_to_4 <= B_from_3;
  265. Instruction_to_4 <= Instruction_from_3;
  266. A_to_5 <= A_from_4;
  267. B_to_5 <= B_from_4;
  268. Instruction_to_5 <= Instruction_from_4;
  269. end process;
  270. end Behavioral;