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.

processeur.vhd 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 12:52:06 05/04/2021
  6. -- Design Name:
  7. -- Module Name: processeur - 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. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23. use IEEE.NUMERIC_STD.ALL;
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31. entity processeur is
  32. Port ( CLK: in STD_LOGIC ;
  33. RST : in STD_LOGIC);
  34. end processeur;
  35. architecture Behavioral of processeur is
  36. COMPONENT bm_instr
  37. PORT(
  38. IN_addr : IN std_logic_vector(7 downto 0);
  39. OUT_data : OUT std_logic_vector(31 downto 0);
  40. CLK : IN std_logic
  41. );
  42. END COMPONENT;
  43. COMPONENT pipeline
  44. PORT( OP_IN : in STD_LOGIC_VECTOR (7 downto 0);
  45. A_IN : in STD_LOGIC_VECTOR (7 downto 0);
  46. B_IN : in STD_LOGIC_VECTOR (7 downto 0);
  47. C_IN : in STD_LOGIC_VECTOR (7 downto 0);
  48. CLK : IN std_logic;
  49. EN : in STD_LOGIC;
  50. OP_OUT : out STD_LOGIC_VECTOR (7 downto 0);
  51. A_OUT : out STD_LOGIC_VECTOR (7 downto 0);
  52. B_OUT : out STD_LOGIC_VECTOR (7 downto 0);
  53. C_OUT : out STD_LOGIC_VECTOR (7 downto 0)
  54. );
  55. END COMPONENT;
  56. COMPONENT br
  57. PORT(
  58. A_addr : IN std_logic_vector(3 downto 0);
  59. B_addr : IN std_logic_vector(3 downto 0);
  60. W_addr : IN std_logic_vector(3 downto 0);
  61. W : IN std_logic;
  62. Data : IN std_logic_vector(7 downto 0);
  63. RST : IN std_logic;
  64. CLK : IN std_logic;
  65. QA : OUT std_logic_vector(7 downto 0);
  66. QB : OUT std_logic_vector(7 downto 0)
  67. );
  68. END COMPONENT;
  69. COMPONENT alu
  70. PORT(
  71. A : IN std_logic_vector(7 downto 0);
  72. B : IN std_logic_vector(7 downto 0);
  73. Ctrl_Alu : IN std_logic_vector(2 downto 0);
  74. N : OUT std_logic;
  75. O : OUT std_logic;
  76. Z : OUT std_logic;
  77. C : OUT std_logic;
  78. S : OUT std_logic_vector(7 downto 0)
  79. );
  80. END COMPONENT;
  81. COMPONENT bm_data
  82. PORT(
  83. IN_addr : IN std_logic_vector(7 downto 0);
  84. IN_data : IN std_logic_vector(7 downto 0);
  85. RW : IN std_logic;
  86. RST : IN std_logic;
  87. CLK : IN std_logic;
  88. OUT_data : OUT std_logic_vector(7 downto 0)
  89. );
  90. END COMPONENT;
  91. --Inputs
  92. signal IP : std_logic_vector(7 downto 0) := (others => '0');
  93. signal QA_IN_MUX : std_logic_vector(7 downto 0) := (others => '0');
  94. signal B_DIEX_IN : std_logic_vector(7 downto 0) := (others => '0');
  95. signal C_DIEX_IN : std_logic_vector(7 downto 0) := (others => '0');
  96. --Outputs
  97. signal OUT_data : std_logic_vector(31 downto 0);
  98. signal OP_LIDI_OUT : std_logic_vector(7 downto 0);
  99. signal A_LIDI_OUT : std_logic_vector(7 downto 0);
  100. signal B_LIDI_OUT : std_logic_vector(7 downto 0);
  101. signal C_LIDI_OUT : std_logic_vector(7 downto 0);
  102. signal OP_DIEX_OUT : std_logic_vector(7 downto 0);
  103. signal A_DIEX_OUT : std_logic_vector(7 downto 0);
  104. signal B_DIEX_OUT : std_logic_vector(7 downto 0);
  105. signal C_DIEX_OUT : std_logic_vector(7 downto 0);
  106. signal O_ALU_OUT : std_logic;
  107. signal N_ALU_OUT : std_logic;
  108. signal Z_ALU_OUT : std_logic;
  109. signal C_ALU_OUT : std_logic;
  110. signal A_EXMem_OUT : std_logic_vector(7 downto 0);
  111. signal B_EXMem_OUT : std_logic_vector(7 downto 0);
  112. signal OP_EXMem_OUT : std_logic_vector(7 downto 0);
  113. signal A_MemRE_OUT : std_logic_vector(7 downto 0);
  114. signal B_MemRE_OUT : std_logic_vector(7 downto 0);
  115. signal OP_MemRE_OUT : std_logic_vector(7 downto 0);
  116. --AUX
  117. signal Ctr_ALU_LC : std_logic_vector(2 downto 0);
  118. signal RW_LC : std_logic;
  119. signal addr_dm_MUX : std_logic_vector(7 downto 0);
  120. signal in_dm_MUX : std_logic_vector(7 downto 0);
  121. signal out_dm_MUX : std_logic_vector(7 downto 0);
  122. signal B_EXMem_IN : std_logic_vector(7 downto 0);
  123. signal W_br_LC : std_logic;
  124. signal S_IN_MUX : std_logic_vector(7 downto 0);
  125. signal B_MemRE_IN : std_logic_vector(7 downto 0);
  126. --alea
  127. signal li_di_r_b : std_logic;
  128. signal li_di_r_c : std_logic;
  129. signal di_ex_w_a : std_logic;
  130. signal ex_mem_w_a : std_logic;
  131. signal alea : std_logic;
  132. begin
  133. -- Instantiate adresse des instructions
  134. addr_instructions: bm_instr PORT MAP (
  135. IN_addr => IP,
  136. OUT_data => OUT_data,
  137. CLK => CLK
  138. );
  139. -- Instantiate pipeline LI_LD
  140. LI_LD : pipeline PORT MAP (
  141. OP_IN => OUT_data(31 downto 24),
  142. A_IN => OUT_data(23 downto 16),
  143. B_IN => OUT_data(15 downto 8),
  144. C_IN => OUT_data(7 downto 0),
  145. CLK => CLK,
  146. EN => alea,
  147. A_OUT => A_LIDI_OUT,
  148. B_OUT => B_LIDI_OUT,
  149. C_OUT => C_LIDI_OUT,
  150. OP_OUT => OP_LIDI_OUT
  151. );
  152. W_br_LC <= '1' when OP_MemRE_OUT = x"07" or OP_MemRE_OUT = x"05" or OP_MemRE_OUT = x"06" or OP_MemRE_OUT = x"01" or OP_MemRE_OUT = x"02" or OP_MemRE_OUT = x"03" or OP_MemRE_OUT = x"04" else
  153. '0';
  154. --alea LI_DI
  155. li_di_r_b <= '1' when OUT_data(31 downto 24) = x"05" or OUT_data(31 downto 24) = x"01" or OUT_data(31 downto 24) = x"02" or OUT_data(31 downto 24) = x"03" or OUT_data(31 downto 24) = x"04" or OUT_data(31 downto 24) = x"08"
  156. else '0';
  157. li_di_r_c <= '1' when OUT_data(31 downto 24) = x"01" or OUT_data(31 downto 24) = x"02" or OUT_data(31 downto 24) = x"03" or OUT_data(31 downto 24) = x"04"
  158. else '0';
  159. -- Instanciate banc de registre
  160. banc_registres : br PORT MAP (
  161. A_addr => B_LIDI_OUT(3 downto 0),
  162. B_addr => C_LIDI_OUT(3 downto 0),
  163. W_addr => A_MemRE_OUT(3 downto 0),
  164. W => W_br_LC, --ATTENTION LC
  165. Data => B_MemRE_OUT,
  166. RST => RST,
  167. CLK => CLK,
  168. QA => QA_IN_MUX,
  169. QB => C_DIEX_IN
  170. );
  171. B_DIEX_IN <= QA_IN_MUX when OP_LIDI_OUT = x"05" or OP_LIDI_OUT = x"01" or OP_LIDI_OUT = x"02" or OP_LIDI_OUT = x"03" or OP_LIDI_OUT = x"04" or OP_LIDI_OUT = x"08" else B_LIDI_OUT ;
  172. -- Instantiate pipeline DI_EX
  173. DI_EX : pipeline PORT MAP (
  174. OP_IN => OP_LIDI_OUT,
  175. A_IN => A_LIDI_OUT,
  176. B_IN => B_DIEX_IN,
  177. C_IN => C_DIEX_IN,
  178. CLK => CLK,
  179. EN => '1',
  180. A_OUT => A_DIEX_OUT,
  181. B_OUT => B_DIEX_OUT,
  182. C_OUT => C_DIEX_OUT,
  183. OP_OUT => OP_DIEX_OUT
  184. );
  185. Ctr_ALU_LC <= "001" when OP_DIEX_OUT = x"01" else
  186. "010" when OP_DIEX_OUT = x"03" else
  187. "011" when OP_DIEX_OUT = x"02" else
  188. "000";
  189. -- alea DI_EX
  190. di_ex_w_a <= '0' when OP_LIDI_OUT = x"08" or OP_LIDI_OUT = x"00"
  191. else '1';
  192. -- Instantiate alu
  193. UAL : alu PORT MAP (
  194. A => B_DIEX_OUT,
  195. B => C_DIEX_OUT,
  196. Ctrl_Alu =>Ctr_AlU_LC,
  197. N => N_ALU_OUT,
  198. O => O_ALU_OUT,
  199. Z => Z_ALU_OUT,
  200. C => C_ALU_OUT,
  201. S => S_IN_MUX
  202. );
  203. B_EXMem_IN <= S_IN_MUX when OP_DIEX_OUT = x"01" or OP_DIEX_OUT = x"02" or OP_DIEX_OUT = x"03" else
  204. B_DIEX_OUT ;
  205. -- Instantiate pipeline EX_Mem
  206. EX_Mem : pipeline PORT MAP (
  207. OP_IN => OP_DIEX_OUT,
  208. A_IN => A_DIEX_OUT,
  209. B_IN => B_EXMem_IN,
  210. C_IN => x"00",
  211. CLK => CLK,
  212. EN => '1',
  213. A_OUT => A_EXMem_OUT,
  214. B_OUT => B_EXMem_OUT,
  215. C_OUT => open,
  216. OP_OUT => OP_EXMem_OUT
  217. );
  218. RW_LC <= '0' when OP_EXMem_OUT = x"08" else
  219. '1';
  220. addr_dm_MUX <= B_EXMem_OUT when OP_EXMem_OUT = x"07" else
  221. A_EXMem_OUT;
  222. in_dm_MUX <= B_EXMem_OUT when OP_EXMem_OUT = x"08";
  223. B_MemRE_IN <= out_dm_MUX when OP_EXMem_OUT = x"08" or OP_EXMem_OUT = x"07" else
  224. B_EXMem_OUT;
  225. -- alea ex_mem
  226. ex_mem_w_a <= '0' when OP_DIEX_OUT = x"08" or OP_DIEX_OUT = x"00"
  227. else '1';
  228. -- Instantiate banc de données
  229. data_memory: bm_data PORT MAP (
  230. IN_addr => addr_dm_MUX,
  231. IN_data => in_dm_MUX,
  232. RW => RW_LC,
  233. RST => RST,
  234. CLK => CLK,
  235. OUT_data => out_dm_MUX
  236. );
  237. -- Instantiate pipeline Mem_RE
  238. Mem_RE : pipeline PORT MAP (
  239. OP_IN => OP_EXMem_OUT,
  240. A_IN => A_EXMem_OUT,
  241. B_IN => B_MemRE_IN,
  242. C_IN => x"00",
  243. CLK => CLK,
  244. EN => '1',
  245. A_OUT => A_MemRE_OUT,
  246. B_OUT => B_MemRE_OUT,
  247. C_OUT => open,
  248. OP_OUT => OP_MemRE_OUT
  249. );
  250. alea <= '0' when (li_di_r_b = '1' and di_ex_w_a = '1' and OUT_data(15 downto 8) = A_LIDI_OUT) or
  251. (li_di_r_c = '1' and di_ex_w_a = '1' and OUT_data(7 downto 0) = A_LIDI_OUT) or
  252. (li_di_r_b = '1' and ex_mem_w_a = '1' and OUT_data(15 downto 8) = A_DIEX_OUT) or
  253. (li_di_r_c = '1' and ex_mem_w_a = '1' and OUT_data(7 downto 0) = A_DIEX_OUT) else
  254. '1';
  255. process
  256. begin
  257. wait until rising_edge(CLK);
  258. if rst = '0' then
  259. IP <= x"00";
  260. else
  261. if alea = '1' then
  262. IP <= IP + "00000001";
  263. end if;
  264. end if;
  265. end process;
  266. end Behavioral;