Line 204... |
Line 204... |
|
|
byte_we : in std_logic_vector(3 downto 0);
|
byte_we : in std_logic_vector(3 downto 0);
|
data_wr : in std_logic_vector(31 downto 0);
|
data_wr : in std_logic_vector(31 downto 0);
|
|
|
mem_wait : out std_logic;
|
mem_wait : out std_logic;
|
|
cache_ready : out std_logic;
|
cache_enable : in std_logic;
|
cache_enable : in std_logic;
|
ic_invalidate : in std_logic;
|
ic_invalidate : in std_logic;
|
unmapped : out std_logic;
|
unmapped : out std_logic;
|
|
|
-- interface to FPGA i/o devices
|
-- interface to FPGA i/o devices
|
Line 258... |
Line 259... |
subtype t_wait_state_counter is std_logic_vector(2 downto 0);
|
subtype t_wait_state_counter is std_logic_vector(2 downto 0);
|
|
|
-- State machine ----------------------------------------------------
|
-- State machine ----------------------------------------------------
|
|
|
type t_cache_state is (
|
type t_cache_state is (
|
|
cache_reset, -- Between reset and 1st code refill,
|
idle, -- Cache is hitting, control machine idle
|
idle, -- Cache is hitting, control machine idle
|
|
|
-- Code refill --------------------------------------------------
|
-- Code refill --------------------------------------------------
|
code_refill_bram_0, -- pc in bram_rd_addr
|
code_refill_bram_0, -- pc in bram_rd_addr
|
code_refill_bram_1, -- op in bram_rd
|
code_refill_bram_1, -- op in bram_rd
|
Line 387... |
Line 389... |
-- code_miss for accesses to UNCACHED areas OR with cache disabled
|
-- code_miss for accesses to UNCACHED areas OR with cache disabled
|
signal code_miss_uncached : std_logic;
|
signal code_miss_uncached : std_logic;
|
-- '1' when the I-cache state machine stalls the pipeline (mem_wait)
|
-- '1' when the I-cache state machine stalls the pipeline (mem_wait)
|
signal code_wait : std_logic;
|
signal code_wait : std_logic;
|
|
|
|
|
-- D-cache ----------------------------------------------------------
|
-- D-cache ----------------------------------------------------------
|
|
|
subtype t_data_tag is std_logic_vector(DATA_TAG_SIZE+1-1 downto 0);
|
subtype t_data_tag is std_logic_vector(DATA_TAG_SIZE+1-1 downto 0);
|
type t_data_tag_table is array(CACHE_SIZE-1 downto 0) of t_data_tag;
|
type t_data_tag_table is array(CACHE_SIZE-1 downto 0) of t_data_tag;
|
type t_data_line_table is array((CACHE_SIZE*LINE_SIZE)-1 downto 0) of t_word;
|
type t_data_line_table is array((CACHE_SIZE*LINE_SIZE)-1 downto 0) of t_word;
|
Line 466... |
Line 469... |
cache_state_machine_reg:
|
cache_state_machine_reg:
|
process(clk)
|
process(clk)
|
begin
|
begin
|
if clk'event and clk='1' then
|
if clk'event and clk='1' then
|
if reset='1' then
|
if reset='1' then
|
ps <= idle;
|
ps <= cache_reset;
|
else
|
else
|
ps <= ns;
|
ps <= ns;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process cache_state_machine_reg;
|
end process cache_state_machine_reg;
|
Line 483... |
Line 486... |
data_wr_attr.mem_type, data_rd_attr.mem_type, code_rd_attr.mem_type,
|
data_wr_attr.mem_type, data_rd_attr.mem_type, code_rd_attr.mem_type,
|
ws_wait_done, code_refill_ctr, data_refill_ctr,
|
ws_wait_done, code_refill_ctr, data_refill_ctr,
|
write_pending, read_pending)
|
write_pending, read_pending)
|
begin
|
begin
|
case ps is
|
case ps is
|
when idle =>
|
|
|
-- The cache will remain in 'cache_reset' state until the first code miss,
|
|
-- at which time the state machine proceeds as usual.
|
|
-- The only difference between states idle and cache_reset is that in
|
|
-- cache_reset the output cache_ready is '0', which will prevent the CPU
|
|
-- from loading its IR with the cache output -- which is known invalid.
|
|
when idle | cache_reset =>
|
if code_miss='1' then
|
if code_miss='1' then
|
case code_rd_attr.mem_type is
|
case code_rd_attr.mem_type is
|
when MT_BRAM => ns <= code_refill_bram_0;
|
when MT_BRAM => ns <= code_refill_bram_0;
|
when MT_SRAM_16B => ns <= code_refill_sram_0;
|
when MT_SRAM_16B => ns <= code_refill_sram_0;
|
when MT_SRAM_8B => ns <= code_refill_sram8_0;
|
when MT_SRAM_8B => ns <= code_refill_sram8_0;
|
Line 1416... |
Line 1425... |
'1' when data_read_io_0,
|
'1' when data_read_io_0,
|
-- In any other state, stall CPU only if there's a RD/WR pending.
|
-- In any other state, stall CPU only if there's a RD/WR pending.
|
read_pending or write_pending when others;
|
read_pending or write_pending when others;
|
|
|
|
|
|
-- The cache will be ready only after the first code refill.
|
|
-- This will prevent the CPU from loading junk into the IR.
|
|
with ps select cache_ready <=
|
|
'0' when cache_reset,
|
|
'1' when others;
|
|
|
|
|
end architecture direct;
|
end architecture direct;
|
|
|
No newline at end of file
|
No newline at end of file
|