-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fetch.vhd
94 lines (75 loc) · 1.93 KB
/
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
--new fetch --47221757
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Fetch is
port(
clk:in std_logic;
--inputs
PCBranchD: in std_logic_vector(31 downto 0);
Jump: in std_logic;
StallF:in std_logic;
StallD:in std_logic;
PCSrcD:in std_logic;
--outputs
InstrD:out std_logic_vector(31 downto 0);
PCPlus4D:out std_logic_vector(31 downto 0) --PCtoIMEM+4
);
end entity Fetch;
architecture fetch_logic of Fetch is
--signals
signal InstrF:std_logic_vector(31 downto 0);
signal PCtoIMEM:std_logic_vector(31 downto 0);
signal PCtoJMUX:std_logic_vector(31 downto 0);
signal JMUXOut:std_logic_vector(31 downto 0);
signal PCPlus4F:std_logic_vector(31 downto 0):=(others=>'0');
--components
component imem
port(
pc: in std_logic_vector(31 downto 0);
instr: out std_logic_vector(31 downto 0)
);
end component;
begin
imem_unit: imem port map( pc=>PCtoIMEM,instr=>InstrF);
PCMUX: process(PCSrcD,PCPlus4F,PCBranchD) is --not sure about this
begin
if (PCSrcD = '0') then
PCtoJMUX <= PCPlus4F;
else
PCtoJMUX <= PCBranchD;
end if;
end process;
JMUX: process(Jump,PCPlus4F,InstrF,PCtoJMUX) is
begin
if (Jump = '1') then
JMUXOut <= PCPlus4F(31 downto 28) & InstrF(25 downto 0) & "00";
else
JMUXOut <= PCtoJMUX;
end if;
end process;
stallF_FF: process(clk,StallF) is
begin
if StallF = '0' then
if rising_edge(clk) then
PCtoIMEM <= JMUXOut;
end if;
end if;
end process;
stallD_FF: process(clk,PCSrcD,StallD) is
begin
if (PCSrcD='1') then
PCPlus4D<= x"00000000";
InstrD<= x"00000000";
else
if StallD = '0' then
if rising_edge(clk) then
InstrD <= InstrF;
PCPlus4D <= PCPlus4F;
end if;
end if;
end if;
end process;
PCPlus4F <= conv_std_logic_vector((conv_integer(PCtoIMEM) + 4),32);
end architecture;