----------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------
|
--
|
--
|
-- Input file : fetch.vhd
|
-- Input file : fetch.vhd
|
-- Design name : fetch
|
-- Design name : fetch
|
-- Author : Tamar Kranenburg
|
-- Author : Tamar Kranenburg
|
-- Company : Delft University of Technology
|
-- Company : Delft University of Technology
|
-- : Faculty EEMCS, Department ME&CE
|
-- : Faculty EEMCS, Department ME&CE
|
-- : Systems and Circuits group
|
-- : Systems and Circuits group
|
--
|
--
|
-- Description : Instruction Fetch Stage inserts instruction into the pipeline. It
|
-- Description : Instruction Fetch Stage inserts instruction into the pipeline. It
|
-- uses a single port Random Access Memory component which holds
|
-- uses a single port Random Access Memory component which holds
|
-- the instructions. The next instruction is computed in the decode
|
-- the instructions. The next instruction is computed in the decode
|
-- stage.
|
-- stage.
|
--
|
--
|
----------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
|
|
library mblite;
|
library mblite;
|
use mblite.config_Pkg.all;
|
use mblite.config_Pkg.all;
|
use mblite.core_Pkg.all;
|
use mblite.core_Pkg.all;
|
use mblite.std_Pkg.all;
|
use mblite.std_Pkg.all;
|
|
|
entity fetch is port
|
entity fetch is port
|
(
|
(
|
fetch_o : out fetch_out_type;
|
fetch_o : out fetch_out_type;
|
imem_o : out imem_out_type;
|
imem_o : out imem_out_type;
|
fetch_i : in fetch_in_type;
|
fetch_i : in fetch_in_type;
|
rst_i : in std_logic;
|
rst_i : in std_logic;
|
ena_i : in std_logic;
|
ena_i : in std_logic;
|
clk_i : in std_logic
|
clk_i : in std_logic
|
);
|
);
|
end fetch;
|
end fetch;
|
|
|
architecture arch of fetch is
|
architecture arch of fetch is
|
signal r, rin : fetch_out_type;
|
signal r, rin : fetch_out_type;
|
begin
|
begin
|
|
|
fetch_o.program_counter <= r.program_counter;
|
fetch_o.program_counter <= r.program_counter;
|
imem_o.adr_o <= rin.program_counter;
|
imem_o.adr_o <= rin.program_counter;
|
imem_o.ena_o <= ena_i;
|
imem_o.ena_o <= ena_i;
|
|
|
fetch_comb: process(fetch_i, r, rst_i)
|
fetch_comb: process(fetch_i, r, rst_i)
|
variable v : fetch_out_type;
|
variable v : fetch_out_type;
|
begin
|
begin
|
v := r;
|
v := r;
|
if rst_i = '1' then
|
if rst_i = '1' then
|
v.program_counter := (OTHERS => '0');
|
v.program_counter := (OTHERS => '0');
|
elsif fetch_i.hazard = '1' then
|
elsif fetch_i.hazard = '1' then
|
v.program_counter := r.program_counter;
|
v.program_counter := r.program_counter;
|
elsif fetch_i.branch = '1' then
|
elsif fetch_i.branch = '1' then
|
v.program_counter := fetch_i.branch_target;
|
v.program_counter := fetch_i.branch_target;
|
else
|
else
|
v.program_counter := increment(r.program_counter(CFG_IMEM_SIZE - 1 downto 2)) & "00";
|
v.program_counter := increment(r.program_counter(CFG_IMEM_SIZE - 1 downto 2)) & "00";
|
end if;
|
end if;
|
rin <= v;
|
rin <= v;
|
end process;
|
end process;
|
|
|
fetch_seq: process(clk_i)
|
fetch_seq: process(clk_i)
|
begin
|
begin
|
if rising_edge(clk_i) then
|
if rising_edge(clk_i) then
|
if rst_i = '1' then
|
if rst_i = '1' then
|
r.program_counter <= (others => '0');
|
r.program_counter <= (others => '0');
|
elsif ena_i = '1' then
|
elsif ena_i = '1' then
|
r <= rin;
|
r <= rin;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
end arch;
|
end arch;
|
|
|