-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_fetch.vhd
103 lines (85 loc) · 3.16 KB
/
d_fetch.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 19:10:14 04/23/2013
-- Design Name:
-- Module Name: i_fetch - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
use work.octagon_types.all;
use work.octagon_funcs.all;
entity d_fetch is
Port (
clk : in std_logic;
dcin : in dcmemin_type;
dout : out std_logic_vector(31 downto 0);
idx : in std_logic_vector(1 downto 0);
idxi : in std_logic_vector(1 downto 0);
way : in std_logic;
dirt : out std_logic;
cout : out std_logic_vector(31 downto 0)
);
end d_fetch;
architecture Behavioral of d_fetch is
--Must use ramb18's on dcache or true dual port won't work
type dtype is array(0 to 511) of std_logic_vector(31 downto 0);
signal dram : dtype := (others => (others => '0'));
signal dirty : std_logic_vector(31 downto 0) := (others => '0');
attribute ram_style: string;
attribute ram_style of dirty : signal is "distributed";
begin
process(clk)
variable wren : std_logic;
begin
if clk='1' and clk'Event then
dout <= dram(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 2))));
wren := to_std_logic(dcin.alu2out.dcwren='1' and
dcin.dcout.owns(to_integer(unsigned(idx & way)))='1' and
dcin.dcout.nc='0');
if wren = '1' then
dirty(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 6)))) <= '1';
end if;
if wren = '1' and dcin.alu2out.be(0) = '1' then
dram(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 2))))(7 downto 0) <= dcin.alu2out.store_data(7 downto 0);
end if;
if wren = '1' and dcin.alu2out.be(1) = '1' then
dram(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 2))))(15 downto 8) <= dcin.alu2out.store_data(15 downto 8);
end if;
if wren = '1' and dcin.alu2out.be(2) = '1' then
dram(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 2))))(23 downto 16) <= dcin.alu2out.store_data(23 downto 16);
end if;
if wren = '1' and dcin.alu2out.be(3) = '1' then
dram(to_integer(unsigned(way & dcin.alu2out.dcwradr(9 downto 2))))(31 downto 24) <= dcin.alu2out.store_data(31 downto 24);
end if;
--Second port stuffs
if dcin.dmemwe = '1' and dcin.dmemidx(2 downto 1) = idx then
dram(to_integer(unsigned(dcin.dmemidx(0) & dcin.dmemadr))) <= dcin.dmemval;
end if;
if dcin.dclean = '1' and dcin.dmemidx(2 downto 1) = idx then
dirty(to_integer(unsigned(dcin.dmemidx(0) & dcin.dmemadr(7 downto 4)))) <= '0';
end if;
dirt <= dirty(to_integer(unsigned(dcin.dmemidx(0) & dcin.dmemadr(7 downto 4))));
cout <= dram(to_integer(unsigned(dcin.dmemidx(0) & dcin.dmemadr)));
end if;
end process;
end Behavioral;