dcache_tb.vhdl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. library work;
  4. use work.common.all;
  5. use work.wishbone_types.all;
  6. entity dcache_tb is
  7. end dcache_tb;
  8. architecture behave of dcache_tb is
  9. signal clk : std_ulogic;
  10. signal rst : std_ulogic;
  11. signal d_in : Loadstore1ToDcacheType;
  12. signal d_out : DcacheToLoadstore1Type;
  13. signal m_in : MmuToDcacheType;
  14. signal m_out : DcacheToMmuType;
  15. signal wb_bram_in : wishbone_master_out;
  16. signal wb_bram_out : wishbone_slave_out;
  17. constant clk_period : time := 10 ns;
  18. begin
  19. dcache0: entity work.dcache
  20. generic map(
  21. LINE_SIZE => 64,
  22. NUM_LINES => 4
  23. )
  24. port map(
  25. clk => clk,
  26. rst => rst,
  27. d_in => d_in,
  28. d_out => d_out,
  29. m_in => m_in,
  30. m_out => m_out,
  31. wishbone_out => wb_bram_in,
  32. wishbone_in => wb_bram_out
  33. );
  34. -- BRAM Memory slave
  35. bram0: entity work.wishbone_bram_wrapper
  36. generic map(
  37. MEMORY_SIZE => 1024,
  38. RAM_INIT_FILE => "icache_test.bin"
  39. )
  40. port map(
  41. clk => clk,
  42. rst => rst,
  43. wishbone_in => wb_bram_in,
  44. wishbone_out => wb_bram_out
  45. );
  46. clk_process: process
  47. begin
  48. clk <= '0';
  49. wait for clk_period/2;
  50. clk <= '1';
  51. wait for clk_period/2;
  52. end process;
  53. rst_process: process
  54. begin
  55. rst <= '1';
  56. wait for 2*clk_period;
  57. rst <= '0';
  58. wait;
  59. end process;
  60. stim: process
  61. begin
  62. -- Clear stuff
  63. d_in.valid <= '0';
  64. d_in.load <= '0';
  65. d_in.nc <= '0';
  66. d_in.addr <= (others => '0');
  67. d_in.data <= (others => '0');
  68. m_in.valid <= '0';
  69. m_in.addr <= (others => '0');
  70. m_in.pte <= (others => '0');
  71. wait for 4*clk_period;
  72. wait until rising_edge(clk);
  73. -- Cacheable read of address 4
  74. d_in.load <= '1';
  75. d_in.nc <= '0';
  76. d_in.addr <= x"0000000000000004";
  77. d_in.valid <= '1';
  78. wait until rising_edge(clk);
  79. d_in.valid <= '0';
  80. wait until rising_edge(clk) and d_out.valid = '1';
  81. assert d_out.data = x"0000000100000000"
  82. report "data @" & to_hstring(d_in.addr) &
  83. "=" & to_hstring(d_out.data) &
  84. " expected 0000000100000000"
  85. severity failure;
  86. -- wait for clk_period;
  87. -- Cacheable read of address 30
  88. d_in.load <= '1';
  89. d_in.nc <= '0';
  90. d_in.addr <= x"0000000000000030";
  91. d_in.valid <= '1';
  92. wait until rising_edge(clk);
  93. d_in.valid <= '0';
  94. wait until rising_edge(clk) and d_out.valid = '1';
  95. assert d_out.data = x"0000000D0000000C"
  96. report "data @" & to_hstring(d_in.addr) &
  97. "=" & to_hstring(d_out.data) &
  98. " expected 0000000D0000000C"
  99. severity failure;
  100. -- Non-cacheable read of address 100
  101. d_in.load <= '1';
  102. d_in.nc <= '1';
  103. d_in.addr <= x"0000000000000100";
  104. d_in.valid <= '1';
  105. wait until rising_edge(clk);
  106. d_in.valid <= '0';
  107. wait until rising_edge(clk) and d_out.valid = '1';
  108. assert d_out.data = x"0000004100000040"
  109. report "data @" & to_hstring(d_in.addr) &
  110. "=" & to_hstring(d_out.data) &
  111. " expected 0000004100000040"
  112. severity failure;
  113. wait until rising_edge(clk);
  114. wait until rising_edge(clk);
  115. wait until rising_edge(clk);
  116. wait until rising_edge(clk);
  117. std.env.finish;
  118. end process;
  119. end;