2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
7 use work.wishbone_types.all;
14 stall_in : in std_ulogic;
15 flush_in : in std_ulogic;
17 -- Results from icache
18 i_in : in IcacheToFetch2Type;
21 f_out : out Fetch2ToDecode1Type
25 architecture behaviour of fetch2 is
27 -- The icache cannot stall, so we need to stash a cycle
28 -- of output from it when we stall.
29 type reg_internal_type is record
30 stash : IcacheToFetch2Type;
31 stash_valid : std_ulogic;
35 signal r_int, rin_int : reg_internal_type;
36 signal r, rin : Fetch2ToDecode1Type;
41 if rising_edge(clk) then
44 report "fetch2 rst:" & std_ulogic'image(rst) &
45 " S:" & std_ulogic'image(stall_in) &
46 " F:" & std_ulogic'image(flush_in) &
47 " T:" & std_ulogic'image(rin.stop_mark) &
48 " V:" & std_ulogic'image(rin.valid) &
49 " FF:" & std_ulogic'image(rin.fetch_failed) &
50 " nia:" & to_hstring(rin.nia);
53 -- Output state remains unchanged on stall, unless we are flushing
54 if rst = '1' or flush_in = '1' or stall_in = '0' then
58 -- Internal state is updated on every clock
64 variable v : Fetch2ToDecode1Type;
65 variable v_int : reg_internal_type;
66 variable v_i_in : IcacheToFetch2Type;
71 -- If stalling, stash away the current input from the icache
72 if stall_in = '1' and v_int.stash_valid = '0' then
74 v_int.stash_valid := '1';
77 -- If unstalling, source input from the stash and invalidate it,
78 -- otherwise source normally from the icache.
81 if v_int.stash_valid = '1' and stall_in = '0' then
82 v_i_in := v_int.stash;
83 v_int.stash_valid := '0';
86 v.valid := v_i_in.valid;
87 v.stop_mark := v_i_in.stop_mark;
88 v.fetch_failed := v_i_in.fetch_failed;
90 v.insn := v_i_in.insn;
92 -- Clear stash internal valid bit on flush. We still mark
93 -- the stash itself as valid since we still want to override
94 -- whatever comes form icache when unstalling, but we'll
95 -- override it with something invalid.
97 if flush_in = '1' then
98 v_int.stash.valid := '0';
99 v_int.stash.fetch_failed := '0';
102 -- If we are flushing or the instruction comes with a stop mark
103 -- we tag it as invalid so it doesn't get decoded and executed
104 if flush_in = '1' or v.stop_mark = '1' then
106 v.fetch_failed := '0';
109 -- Clear stash on reset
111 v_int.stash_valid := '0';
123 end architecture behaviour;