Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. -- ===================================================================
  2. -- (C)opyright 2001, 2002, 2012
  3. --
  4. -- Lehrstuhl Entwurf Mikroelektronischer Systeme
  5. -- Prof. Wehn
  6. -- Universitaet Kaiserslautern
  7. --
  8. -- ===================================================================
  9. --
  10. -- Autoren: Frank Gilbert
  11. -- Christian Neeb
  12. -- Timo Vogt
  13. -- Stefan Weithoffer
  14. --
  15. -- ===================================================================
  16. --
  17. -- Modul:
  18. -- Data Cache Modul for 16-Bit RAM-Adresses.
  19. -- Cacheline 128 Bit (4 Words a 32Bit)
  20. -- 2x32 Lines 2-way associative Cache.
  21. -- ^^^^ ^^^^^^^^^^^^^^^^^
  22. --
  23. -- Addr-Bits: 111111
  24. -- 5432109876543210
  25. -- ----------------
  26. -- _______
  27. -- Tag _____
  28. -- Offset__
  29. -- Word
  30. -- __
  31. -- Byte
  32. -- ===================================================================
  33.  
  34.  
  35. library ieee;
  36. use ieee.std_logic_1164.all;
  37. use ieee.numeric_std.all;
  38. use work.cache_support.all;
  39.  
  40.  
  41. entity dcache is
  42. port(
  43. clk : in std_logic;
  44. rst : in std_logic;
  45.  
  46. dc_addr : in address;
  47. dc_rdata : out word;
  48. dc_wdata : in word;
  49. dc_enable : in std_logic;
  50. dc_write : in std_logic;
  51. dc_width : in Mem_width;
  52. dc_ready : out std_logic;
  53.  
  54. cache_line : in std_logic_vector( 0 to bw_cacheline-1 );
  55. dc_update : in std_logic;
  56. memctrl_busy : in std_logic
  57. );
  58. end dcache;
  59.  
  60.  
  61. -- ===================================================================
  62. architecture behavior of dcache is
  63.  
  64.  
  65. -- Component Deklarationen
  66. -- =======================
  67. component cache_memory
  68. generic(
  69. bit_width : natural;
  70. addr_width : natural
  71. );
  72. port(
  73. clk : in std_logic;
  74. addr : in std_logic_vector(addr_width-1 downto 0);
  75. write : in std_logic;
  76. data_out : out std_logic_vector(0 to bit_width-1);
  77. data_in : in std_logic_vector(0 to bit_width-1)
  78. );
  79. end component;
  80.  
  81.  
  82. -- Signale zur Ansteuerung der Cache RAMs-------------------------------------
  83. signal setX_in : std_logic_vector( 0 to bw_cacheline + bw_dc_tag );
  84. signal set0_out : std_logic_vector( 0 to bw_cacheline + bw_dc_tag );
  85. signal set1_out : std_logic_vector( 0 to bw_cacheline + bw_dc_tag );
  86. signal set0_write : std_logic := '0';
  87. signal set1_write : std_logic := '0';
  88.  
  89. -- Signale zur Aufsplittung der Cache-RAM-Ausgänge ---------------------------
  90. signal set0_tag : std_logic_vector( bw_dc_tag - 1 downto 0 );
  91. signal set0_line : std_logic_vector( 0 to bw_cacheline - 1 );
  92. signal set0_valid : std_logic;
  93. signal set1_tag : std_logic_vector( bw_dc_tag-1 downto 0 );
  94. signal set1_line : std_logic_vector( 0 to bw_cacheline - 1 );
  95. signal set1_valid : std_logic;
  96.  
  97. -- Signale zur Aufsplittung der Daten-Adresse --------------------------------
  98. signal addr_tag : std_logic_vector( bw_dc_tag - 1 downto 0 );
  99. signal addr_offset : std_logic_vector( bw_dc_offset - 1 downto 0 );
  100. signal addr_word : std_logic_vector( 1 downto 0 );
  101. signal addr_byte : std_logic_vector( 1 downto 0 );
  102.  
  103. -- algemeine Signale ---------------------------------------------------------
  104. signal set0_hit : std_logic;
  105. signal set1_hit : std_logic;
  106.  
  107. -- LFSR for random-Bit Generation --------------------------------------------
  108. signal lfsr : std_logic_vector( 7 downto 0 );
  109. signal rand_bit : std_logic := '0';
  110.  
  111. begin
  112.  
  113.  
  114. -- =================================================================
  115. -- Instanziierung der Cache-RAMs (fuer Tag, Cache-Line u. Vaild-Bit)
  116. -- =================================================================
  117.  
  118.  
  119. set0_ram : cache_memory
  120. generic map(
  121. bit_width => bw_cacheline+bw_dc_tag+1,
  122. addr_width => bw_dc_offset
  123. )
  124. port map(
  125. clk => clk,
  126. addr => addr_offset,
  127. data_out => set0_out,
  128. write => set0_write,
  129. data_in => setX_in
  130. );
  131.  
  132. set1_ram : cache_memory
  133. generic map(
  134. bit_width => bw_cacheline+bw_dc_tag+1,
  135. addr_width => bw_dc_offset
  136. )
  137. port map(
  138. clk => clk,
  139. addr => addr_offset,
  140. data_out => set1_out,
  141. write => set1_write,
  142. data_in => setX_in
  143. );
  144.  
  145.  
  146. -- =================================================================
  147. -- Aufsplittung der Cache-RAM-Ausgänge (Tag, Line u. Vaild-Bit)
  148. -- =================================================================
  149.  
  150.  
  151. set0_valid <= set0_out( 0 );
  152. set0_tag <= set0_out( 1 to bw_dc_tag );
  153. set0_line <= set0_out( bw_dc_tag + 1 to bw_cacheline + bw_dc_tag );
  154. set1_valid <= set1_out( 0 );
  155. set1_tag <= set1_out( 1 to bw_dc_tag );
  156. set1_line <= set1_out( bw_dc_tag + 1 to bw_cacheline + bw_dc_tag );
  157.  
  158.  
  159. -- =================================================================
  160. -- Aufsplittung der Daten-Adresse (Tag, Offset, Word, Byte)
  161. -- =================================================================
  162.  
  163.  
  164. addr_tag <= dc_addr( address_width - 1 downto address_width - bw_dc_tag );
  165. addr_offset <= dc_addr( address_width - bw_dc_tag - 1 downto 4 );
  166. addr_word <= dc_addr( 3 downto 2 );
  167. addr_byte <= dc_addr( 1 downto 0 );
  168.  
  169.  
  170. -- =================================================================
  171. -- Cache-Read-Access (nicht getaktet!)
  172. -- =================================================================
  173.  
  174.  
  175. cache_read : process( set0_valid, set1_valid, set0_tag, set1_tag, set0_line,
  176. set1_line, addr_tag, addr_word, addr_byte, dc_width )
  177. begin
  178.  
  179. -- Insert your code here:
  180.  
  181. if((set0_tag=addr_tag) and (set0_valid='1')) then
  182.  
  183. dc_rdata <= align(set0_line,addr_word,addr_byte,dc_width);
  184. set0_hit <= '1';
  185. set1_hit <= '0';
  186.  
  187. elsif((set1_tag=addr_tag )and (set1_valid='1')) then
  188.  
  189. dc_rdata <= align(set1_line,addr_word,addr_byte,dc_width);
  190. set0_hit <= '0';
  191. set1_hit <= '1';
  192.  
  193. else
  194. set0_hit <= '0';
  195. set1_hit <= '0';
  196. end if;
  197.  
  198. end process cache_read;
  199.  
  200.  
  201. -- =================================================================
  202. -- Cache-Update-Access (nicht getaktet!)
  203. -- =================================================================
  204.  
  205.  
  206. cache_update : process( set0_valid, set1_valid, set0_tag, set1_tag,
  207. set0_line, set1_line, set0_hit, set1_hit,
  208. addr_tag, addr_word, addr_byte, cache_line,
  209. dc_update, dc_enable, dc_write, dc_width )
  210. begin
  211.  
  212. -- Insert your code here:
  213. set1_write <= '0';
  214. set0_write <= '0';
  215. if ((dc_write = '1') and (dc_update = '0')) then
  216. if (set0_hit = '1') then
  217. setX_in <= '1' & addr_tag & update(set0_line, dc_wdata, addr_word, addr_byte, dc_width);
  218. set0_write <= '1';
  219. elsif (set1_hit = '1') then
  220. setX_in <= '1' & addr_tag & update(set1_line, dc_wdata, addr_word, addr_byte, dc_width);
  221. set1_write <= '1';
  222. end if;
  223. elsif (dc_update = '1') then
  224. if (dc_write = '1') then
  225. setX_in <= '1' & addr_tag & update(cache_line, dc_wdata, addr_word, addr_byte, dc_width);
  226. else setX_in <= '1' & addr_tag & cache_line;
  227. end if;
  228.  
  229. if (rand_bit = '0') then
  230. set0_write <= '1';
  231. else set1_write <= '1';
  232. end if;
  233. end if;
  234. end process cache_update;
  235.  
  236.  
  237. -- =================================================================
  238. -- Cache-Read/Write-Access completed (nicht getaktet!)
  239. -- =================================================================
  240.  
  241.  
  242. completed : process( dc_write, memctrl_busy, set0_hit, set1_hit )
  243. begin
  244. -- Cache Access Completed
  245. if (dc_write='1' and memctrl_busy ='0')
  246. or (dc_write='0' and (set0_hit='1' or set1_hit='1'))
  247. then
  248. dc_ready <= '1';
  249. else
  250. dc_ready <= '0';
  251. end if;
  252. end process completed;
  253.  
  254.  
  255. -- =================================================================
  256. -- Linear Feedback Shift Register, LFSR (getaktet!)
  257. -- =================================================================
  258. rand_bit <= lfsr(0);
  259.  
  260. lfsr_reg : process( clk )
  261. begin
  262.  
  263. -- Insert your code here:
  264.  
  265. if (rst = '1') then lfsr(7 downto 0) <= "00000001";
  266. else lfsr(7 downto 1) <= lfsr (6 downto 0);
  267. lfsr(0) <= (lfsr(7)) xor (lfsr(6)) xor (lfsr(1)) xor ('1');
  268. end if;
  269.  
  270. end process lfsr_reg;
  271.  
  272.  
  273. end behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement