1 |
2 |
tarookumic |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
----------------------------------------------------------------------------
|
6 |
|
|
-- This file is a part of the LEON VHDL model
|
7 |
|
|
-- Copyright (C) 1999 European Space Agency (ESA)
|
8 |
|
|
--
|
9 |
|
|
-- This library is free software; you can redistribute it and/or
|
10 |
|
|
-- modify it under the terms of the GNU Lesser General Public
|
11 |
|
|
-- License as published by the Free Software Foundation; either
|
12 |
|
|
-- version 2 of the License, or (at your option) any later version.
|
13 |
|
|
--
|
14 |
|
|
-- See the file COPYING.LGPL for the full details of the license.
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
-----------------------------------------------------------------------------
|
18 |
|
|
-- Entity: icache
|
19 |
|
|
-- File: icache.vhd
|
20 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
21 |
|
|
-- Description: This unit implements the instruction cache controller.
|
22 |
|
|
------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
library IEEE;
|
25 |
|
|
use IEEE.std_logic_1164.all;
|
26 |
|
|
use IEEE.std_logic_unsigned."+";
|
27 |
|
|
use IEEE.std_logic_unsigned.conv_integer;
|
28 |
|
|
use IEEE.std_logic_arith.conv_unsigned;
|
29 |
|
|
use work.leon_config.all;
|
30 |
|
|
use work.sparcv8.all; -- ASI declarations
|
31 |
|
|
use work.leon_iface.all;
|
32 |
|
|
use work.macro.all; -- xorv()
|
33 |
|
|
use work.amba.all;
|
34 |
|
|
use work.leon_target.all;
|
35 |
|
|
|
36 |
|
|
entity icache is
|
37 |
|
|
port (
|
38 |
|
|
rst : in std_logic;
|
39 |
|
|
clk : in clk_type;
|
40 |
|
|
ici : in icache_in_type;
|
41 |
|
|
ico : out icache_out_type;
|
42 |
|
|
dci : in dcache_in_type;
|
43 |
|
|
dco : in dcache_out_type;
|
44 |
|
|
mcii : out memory_ic_in_type;
|
45 |
|
|
mcio : in memory_ic_out_type;
|
46 |
|
|
icrami : out icram_in_type;
|
47 |
|
|
icramo : in icram_out_type;
|
48 |
|
|
fpuholdn : in std_logic
|
49 |
|
|
);
|
50 |
|
|
end;
|
51 |
|
|
|
52 |
|
|
architecture rtl of icache is
|
53 |
|
|
|
54 |
|
|
constant TAG_HIGH : integer := ITAG_HIGH;
|
55 |
|
|
constant TAG_LOW : integer := IOFFSET_BITS + ILINE_BITS + 2;
|
56 |
|
|
constant OFFSET_HIGH: integer := TAG_LOW - 1;
|
57 |
|
|
constant OFFSET_LOW : integer := ILINE_BITS + 2;
|
58 |
|
|
constant LINE_HIGH : integer := OFFSET_LOW - 1;
|
59 |
|
|
constant LINE_LOW : integer := 2;
|
60 |
|
|
constant LRR_BIT : integer := TAG_HIGH + 1;
|
61 |
|
|
|
62 |
|
|
constant lline : std_logic_vector((ILINE_BITS -1) downto 0) := (others=>'1');
|
63 |
|
|
|
64 |
|
|
constant SETBITS : integer := log2x(ISETS);
|
65 |
|
|
subtype lru_type is std_logic_vector(ILRUBITS-1 downto 0);
|
66 |
|
|
type lru_array is array (0 to 2**IOFFSET_BITS-1) of lru_type; -- lru registers
|
67 |
|
|
type rdatatype is (itag, idata, memory); -- sources during cache read
|
68 |
|
|
|
69 |
|
|
type lru_table_vector_type is array(0 to 3) of std_logic_vector(4 downto 0);
|
70 |
|
|
type lru_table_type is array (0 to 2**IOFFSET_BITS-1) of lru_table_vector_type;
|
71 |
|
|
|
72 |
|
|
subtype lock_type is std_logic_vector(0 to ISETS-1);
|
73 |
|
|
type par_type is array (0 to ISETS-1) of std_logic_vector(1 downto 0);
|
74 |
|
|
|
75 |
|
|
function lru_set (lru : lru_type; lock : lock_type) return std_logic_vector is
|
76 |
|
|
variable xlru : std_logic_vector(4 downto 0);
|
77 |
|
|
variable set : std_logic_vector(SETBITS-1 downto 0);
|
78 |
|
|
variable xset : std_logic_vector(1 downto 0);
|
79 |
|
|
variable unlocked : integer range 0 to ISETS-1;
|
80 |
|
|
begin
|
81 |
|
|
|
82 |
|
|
set := (others => '0'); xlru := (others => '0'); xset := (others => '0');
|
83 |
|
|
xlru(ILRUBITS-1 downto 0) := lru;
|
84 |
|
|
|
85 |
|
|
if ICLOCK_BIT = 1 then
|
86 |
|
|
unlocked := ISETS-1;
|
87 |
|
|
for i in ISETS-1 downto 0 loop
|
88 |
|
|
if lock(i) = '0' then unlocked := i; end if;
|
89 |
|
|
end loop;
|
90 |
|
|
end if;
|
91 |
|
|
|
92 |
|
|
case ISETS is
|
93 |
|
|
when 2 =>
|
94 |
|
|
if ICLOCK_BIT = 1 then
|
95 |
|
|
if lock(0) = '1' then xset(0) := '1'; else xset(0) := xlru(0); end if;
|
96 |
|
|
else xset(0) := xlru(0); end if;
|
97 |
|
|
when 3 =>
|
98 |
|
|
if ICLOCK_BIT = 1 then
|
99 |
|
|
xset := std_logic_vector(conv_unsigned(lru3_repl_table(conv_integer(xlru)) (unlocked), 2));
|
100 |
|
|
else
|
101 |
|
|
xset := std_logic_vector(conv_unsigned(lru3_repl_table(conv_integer(xlru)) (0), 2));
|
102 |
|
|
end if;
|
103 |
|
|
when 4 =>
|
104 |
|
|
if ICLOCK_BIT = 1 then
|
105 |
|
|
xset := std_logic_vector(conv_unsigned(lru4_repl_table(conv_integer(xlru)) (unlocked), 2));
|
106 |
|
|
else
|
107 |
|
|
xset := std_logic_vector(conv_unsigned(lru4_repl_table(conv_integer(xlru)) (0), 2));
|
108 |
|
|
end if;
|
109 |
|
|
when others =>
|
110 |
|
|
end case;
|
111 |
|
|
set := xset(SETBITS-1 downto 0);
|
112 |
|
|
return(set);
|
113 |
|
|
end;
|
114 |
|
|
|
115 |
|
|
function lru_calc (lru : lru_type; set : integer) return lru_type is
|
116 |
|
|
variable new_lru : lru_type;
|
117 |
|
|
variable xnew_lru: std_logic_vector(4 downto 0);
|
118 |
|
|
variable xlru : std_logic_vector(4 downto 0);
|
119 |
|
|
begin
|
120 |
|
|
new_lru := (others => '0'); xnew_lru := (others => '0');
|
121 |
|
|
xlru := (others => '0'); xlru(ILRUBITS-1 downto 0) := lru;
|
122 |
|
|
case ISETS is
|
123 |
|
|
when 2 =>
|
124 |
|
|
if set = 0 then xnew_lru(0) := '1'; else xnew_lru(0) := '0'; end if;
|
125 |
|
|
when 3 =>
|
126 |
|
|
xnew_lru(2 downto 0) := lru_3set_table(conv_integer(lru))(set);
|
127 |
|
|
when 4 =>
|
128 |
|
|
xnew_lru(4 downto 0) := lru_4set_table(conv_integer(lru))(set);
|
129 |
|
|
when others =>
|
130 |
|
|
end case;
|
131 |
|
|
new_lru := xnew_lru(ILRUBITS-1 downto 0);
|
132 |
|
|
return(new_lru);
|
133 |
|
|
end;
|
134 |
|
|
|
135 |
|
|
type icache_control_type is record -- all registers
|
136 |
|
|
req, burst, holdn : std_logic;
|
137 |
|
|
overrun : std_logic; --
|
138 |
|
|
underrun : std_logic; --
|
139 |
|
|
istate : std_logic_vector(1 downto 0); -- FSM vector
|
140 |
|
|
waddress : std_logic_vector(31 downto PCLOW); -- write address buffer
|
141 |
|
|
valid : std_logic_vector(ILINE_SIZE-1 downto 0); -- valid bits
|
142 |
|
|
hit : std_logic;
|
143 |
|
|
su : std_logic;
|
144 |
|
|
flush : std_logic; -- flush in progress
|
145 |
|
|
flush2 : std_logic; -- flush in progress
|
146 |
|
|
faddr : std_logic_vector(IOFFSET_BITS - 1 downto 0); -- flush address
|
147 |
|
|
diagrdy : std_logic;
|
148 |
|
|
rndcnt : std_logic_vector(log2x(ISETS)-1 downto 0); -- replace counter
|
149 |
|
|
lrr : std_logic;
|
150 |
|
|
setrepl : std_logic_vector(log2x(ISETS)-1 downto 0); -- set to replace
|
151 |
|
|
diagset : std_logic_vector(log2x(ISETS)-1 downto 0);
|
152 |
|
|
lock : std_logic;
|
153 |
|
|
|
154 |
|
|
end record;
|
155 |
|
|
|
156 |
|
|
type lru_reg_type is record
|
157 |
|
|
write : std_logic;
|
158 |
|
|
waddr : std_logic_vector(IOFFSET_BITS-1 downto 0);
|
159 |
|
|
set : std_logic_vector(SETBITS-1 downto 0); --integer range 0 to ISETS-1;
|
160 |
|
|
lru : lru_array;
|
161 |
|
|
end record;
|
162 |
|
|
|
163 |
|
|
signal r, c : icache_control_type; -- r is registers, c is combinational
|
164 |
|
|
signal rl, cl : lru_reg_type; -- rl is registers, cl is combinational
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
begin
|
168 |
|
|
|
169 |
|
|
ictrl : process(rst, r, rl, mcio, ici, dci, dco, icramo, fpuholdn)
|
170 |
|
|
variable rdatasel : rdatatype;
|
171 |
|
|
variable twrite, diagen, dwrite : std_logic;
|
172 |
|
|
variable taddr : std_logic_vector(TAG_HIGH downto LINE_LOW); -- tag address
|
173 |
|
|
variable wtag : std_logic_vector(TAG_HIGH downto TAG_LOW); -- write tag value
|
174 |
|
|
variable ddatain : std_logic_vector(31 downto 0);
|
175 |
|
|
variable rdata : std_logic_vector(31 downto 0);
|
176 |
|
|
variable diagdata : std_logic_vector(31 downto 0);
|
177 |
|
|
variable vmaskraw, vmask : std_logic_vector((ILINE_SIZE -1) downto 0);
|
178 |
|
|
variable xaddr_inc : std_logic_vector((ILINE_BITS -1) downto 0);
|
179 |
|
|
variable lastline, nlastline, nnlastline : std_logic;
|
180 |
|
|
variable enable : std_logic;
|
181 |
|
|
variable error : std_logic;
|
182 |
|
|
variable whit, hit, valid : std_logic;
|
183 |
|
|
variable cacheon : std_logic;
|
184 |
|
|
variable v : icache_control_type;
|
185 |
|
|
variable branch : std_logic;
|
186 |
|
|
variable eholdn : std_logic;
|
187 |
|
|
variable mds, write : std_logic;
|
188 |
|
|
variable memaddr : std_logic_vector(31 downto PCLOW);
|
189 |
|
|
variable set : integer range 0 to MAXSETS-1;
|
190 |
|
|
variable setrepl : std_logic_vector(log2x(ISETS)-1 downto 0); -- set to replace
|
191 |
|
|
variable ctwrite, cdwrite, validv : std_logic_vector(0 to MAXSETS-1);
|
192 |
|
|
variable wlrr : std_logic;
|
193 |
|
|
variable vl : lru_reg_type;
|
194 |
|
|
variable vdiagset, rdiagset : integer range 0 to ISETS-1;
|
195 |
|
|
variable lock : std_logic_vector(0 to ISETS-1);
|
196 |
|
|
variable wlock : std_logic;
|
197 |
|
|
|
198 |
|
|
begin
|
199 |
|
|
|
200 |
|
|
-- init local variables
|
201 |
|
|
|
202 |
|
|
v := r; vl := rl; vl.write := '0'; vl.set := r.setrepl;
|
203 |
|
|
vl.waddr := r.waddress(OFFSET_HIGH downto OFFSET_LOW);
|
204 |
|
|
|
205 |
|
|
mds := '1'; dwrite := '0'; twrite := '0'; diagen := '0'; error := '0';
|
206 |
|
|
write := mcio.ready; v.diagrdy := '0'; v.holdn := '1';
|
207 |
|
|
|
208 |
|
|
cacheon := mcio.ics(0) and not r.flush;
|
209 |
|
|
enable := '1'; branch := '0';
|
210 |
|
|
eholdn := dco.hold and fpuholdn;
|
211 |
|
|
|
212 |
|
|
rdatasel := idata; -- read data from cache as default
|
213 |
|
|
ddatain := mcio.data; -- load full word from memory
|
214 |
|
|
wtag(TAG_HIGH downto TAG_LOW) := r.waddress(TAG_HIGH downto TAG_LOW);
|
215 |
|
|
wlrr := r.lrr; wlock := r.lock;
|
216 |
|
|
|
217 |
|
|
set := 0; ctwrite := (others => '0'); cdwrite := (others => '0');
|
218 |
|
|
vdiagset := 0; rdiagset := 0; lock := (others => '0');
|
219 |
|
|
|
220 |
|
|
-- random replacement counter
|
221 |
|
|
if ISETS > 1 then
|
222 |
|
|
-- pragma translate_off
|
223 |
|
|
if not is_x(r.rndcnt) then
|
224 |
|
|
-- pragma translate_on
|
225 |
|
|
if conv_integer(r.rndcnt) = (ISETS - 1) then v.rndcnt := (others => '0');
|
226 |
|
|
else v.rndcnt := r.rndcnt + 1; end if;
|
227 |
|
|
-- pragma translate_off
|
228 |
|
|
end if;
|
229 |
|
|
-- pragma translate_on
|
230 |
|
|
end if;
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
-- generate lock bits
|
234 |
|
|
if ICLOCK_BIT = 1 then
|
235 |
|
|
for i in 0 to ISETS-1 loop lock(i) := icramo.itramout(i).lock; end loop;
|
236 |
|
|
end if;
|
237 |
|
|
|
238 |
|
|
-- generate cache hit and valid bits
|
239 |
|
|
hit := '0';
|
240 |
|
|
for i in ISETS-1 downto 0 loop
|
241 |
|
|
if (icramo.itramout(i).tag = ici.fpc(TAG_HIGH downto TAG_LOW))
|
242 |
|
|
then hit := not r.flush; set := i; end if;
|
243 |
|
|
validv(i) := genmux(ici.fpc(LINE_HIGH downto LINE_LOW),
|
244 |
|
|
icramo.itramout(i).valid);
|
245 |
|
|
end loop;
|
246 |
|
|
|
247 |
|
|
if ici.fpc(LINE_HIGH downto LINE_LOW) = lline then lastline := '1';
|
248 |
|
|
else lastline := '0'; end if;
|
249 |
|
|
|
250 |
|
|
if r.waddress(LINE_HIGH downto LINE_LOW) = lline((ILINE_BITS -1) downto 0) then
|
251 |
|
|
nlastline := '1';
|
252 |
|
|
else nlastline := '0'; end if;
|
253 |
|
|
|
254 |
|
|
if r.waddress(LINE_HIGH downto LINE_LOW+1) = lline((ILINE_BITS -1) downto 1) then
|
255 |
|
|
nnlastline := '1';
|
256 |
|
|
else nnlastline := '0'; end if;
|
257 |
|
|
|
258 |
|
|
-- pragma translate_off
|
259 |
|
|
if not is_x(ici.fpc(LINE_HIGH downto LINE_LOW)) then
|
260 |
|
|
-- pragma translate_on
|
261 |
|
|
valid := validv(set);
|
262 |
|
|
-- pragma translate_off
|
263 |
|
|
end if;
|
264 |
|
|
-- pragma translate_on
|
265 |
|
|
|
266 |
|
|
-- pragma translate_off
|
267 |
|
|
if not is_x(r.waddress) then
|
268 |
|
|
-- pragma translate_on
|
269 |
|
|
xaddr_inc := r.waddress(LINE_HIGH downto LINE_LOW) + 1;
|
270 |
|
|
-- pragma translate_off
|
271 |
|
|
end if;
|
272 |
|
|
-- pragma translate_on
|
273 |
|
|
|
274 |
|
|
if mcio.ready = '1' then
|
275 |
|
|
v.waddress(LINE_HIGH downto LINE_LOW) := xaddr_inc;
|
276 |
|
|
end if;
|
277 |
|
|
|
278 |
|
|
taddr := ici.rpc(TAG_HIGH downto LINE_LOW);
|
279 |
|
|
|
280 |
|
|
-- main Icache state machine
|
281 |
|
|
|
282 |
|
|
case r.istate is
|
283 |
|
|
when "00" => -- main state and cache hit
|
284 |
|
|
v.valid := icramo.itramout(set).valid;
|
285 |
|
|
v.hit := hit; v.su := ici.su;
|
286 |
|
|
|
287 |
|
|
if (ici.nullify or eholdn) = '0' then
|
288 |
|
|
taddr := ici.fpc(TAG_HIGH downto LINE_LOW);
|
289 |
|
|
else taddr := ici.rpc(TAG_HIGH downto LINE_LOW); end if;
|
290 |
|
|
v.burst := mcio.burst and not lastline;
|
291 |
|
|
if (eholdn and not ici.nullify ) = '1' then
|
292 |
|
|
if not (cacheon and hit and valid) = '1' then
|
293 |
|
|
v.istate := "01"; v.req := '1';
|
294 |
|
|
v.holdn := '0'; v.overrun := '1';
|
295 |
|
|
else
|
296 |
|
|
if (ISETS > 1) and (ICREPLACE = lru) then vl.write := '1'; end if;
|
297 |
|
|
end if;
|
298 |
|
|
v.waddress := ici.fpc(31 downto PCLOW);
|
299 |
|
|
|
300 |
|
|
end if;
|
301 |
|
|
if dco.icdiag.enable = '1' then
|
302 |
|
|
diagen := '1';
|
303 |
|
|
end if;
|
304 |
|
|
ddatain := dci.maddress;
|
305 |
|
|
if (ISETS > 1) then
|
306 |
|
|
if (ICREPLACE = lru) then
|
307 |
|
|
vl.set := std_logic_vector(conv_unsigned(set, SETBITS));
|
308 |
|
|
vl.waddr := ici.fpc(OFFSET_HIGH downto OFFSET_LOW);
|
309 |
|
|
end if;
|
310 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(set, SETBITS));
|
311 |
|
|
if (((not hit) and (not r.flush)) = '1') then
|
312 |
|
|
case ICREPLACE is
|
313 |
|
|
when rnd =>
|
314 |
|
|
if ICLOCK_BIT = 1 then
|
315 |
|
|
if lock(conv_integer(r.rndcnt)) = '0' then v.setrepl := r.rndcnt;
|
316 |
|
|
else
|
317 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(ISETS-1, SETBITS));
|
318 |
|
|
for i in ISETS-1 downto 0 loop
|
319 |
|
|
if (lock(i) = '0') and (i>conv_integer(r.rndcnt)) then
|
320 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(i, SETBITS));
|
321 |
|
|
end if;
|
322 |
|
|
end loop;
|
323 |
|
|
end if;
|
324 |
|
|
else
|
325 |
|
|
v.setrepl := r.rndcnt;
|
326 |
|
|
end if;
|
327 |
|
|
when lru =>
|
328 |
|
|
-- pragma translate_off
|
329 |
|
|
if not is_x(ici.fpc) then
|
330 |
|
|
-- pragma translate_on
|
331 |
|
|
v.setrepl := lru_set(rl.lru(conv_integer(ici.fpc(OFFSET_HIGH downto OFFSET_LOW))), lock(0 to ISETS-1));
|
332 |
|
|
-- pragma translate_off
|
333 |
|
|
end if;
|
334 |
|
|
-- pragma translate_on
|
335 |
|
|
when lrr =>
|
336 |
|
|
v.setrepl := (others => '0');
|
337 |
|
|
if ICLOCK_BIT = 1 then
|
338 |
|
|
if lock(0) = '1' then v.setrepl(0) := '1';
|
339 |
|
|
else
|
340 |
|
|
v.setrepl(0) := icramo.itramout(0).lrr xor icramo.itramout(1).lrr;
|
341 |
|
|
end if;
|
342 |
|
|
else
|
343 |
|
|
v.setrepl(0) := icramo.itramout(0).lrr xor icramo.itramout(1).lrr;
|
344 |
|
|
end if;
|
345 |
|
|
if v.setrepl(0) = '0' then v.lrr := not icramo.itramout(0).lrr;
|
346 |
|
|
else v.lrr := icramo.itramout(0).lrr; end if;
|
347 |
|
|
end case;
|
348 |
|
|
end if;
|
349 |
|
|
if (ICLOCK_BIT = 1) then
|
350 |
|
|
if (hit and lock(set)) = '1' then v.lock := '1';
|
351 |
|
|
else v.lock := '0'; end if;
|
352 |
|
|
end if;
|
353 |
|
|
end if;
|
354 |
|
|
when "01" => -- streaming: update cache and send data to IU
|
355 |
|
|
rdatasel := memory;
|
356 |
|
|
taddr(TAG_HIGH downto LINE_LOW) := r.waddress(TAG_HIGH downto LINE_LOW);
|
357 |
|
|
branch := (ici.fbranch and r.overrun) or
|
358 |
|
|
(ici.rbranch and (not r.overrun));
|
359 |
|
|
v.underrun := r.underrun or
|
360 |
|
|
(write and ((ici.nullify or not eholdn) and (mcio.ready and not (r.overrun and not r.underrun))));
|
361 |
|
|
v.overrun := (r.overrun or (eholdn and not ici.nullify)) and
|
362 |
|
|
not (write or r.underrun);
|
363 |
|
|
if mcio.ready = '1' then
|
364 |
|
|
-- mds := not (v.overrun and not r.underrun);
|
365 |
|
|
mds := not (r.overrun and not r.underrun);
|
366 |
|
|
-- v.req := r.burst;
|
367 |
|
|
v.burst := v.req and not nnlastline;
|
368 |
|
|
end if;
|
369 |
|
|
if mcio.grant = '1' then
|
370 |
|
|
v.req := mcio.burst and r.burst and
|
371 |
|
|
(not (nnlastline and mcio.ready)) and (mcio.burst or (not branch)) and
|
372 |
|
|
not (v.underrun and not cacheon);
|
373 |
|
|
v.burst := v.req and not nnlastline;
|
374 |
|
|
end if;
|
375 |
|
|
v.underrun := (v.underrun or branch) and not v.overrun;
|
376 |
|
|
v.holdn := not (v.overrun or v.underrun);
|
377 |
|
|
if (mcio.ready = '1') and (r.req = '0') then --(v.burst = '0') then
|
378 |
|
|
v.underrun := '0'; v.overrun := '0';
|
379 |
|
|
if (mcio.ics(0) and not r.flush2) = '1' then
|
380 |
|
|
v.istate := "10"; v.holdn := '0';
|
381 |
|
|
else
|
382 |
|
|
v.istate := "00"; v.flush := r.flush2; v.holdn := '1';
|
383 |
|
|
if r.overrun = '1' then taddr := ici.fpc(TAG_HIGH downto LINE_LOW);
|
384 |
|
|
else taddr := ici.rpc(TAG_HIGH downto LINE_LOW); end if;
|
385 |
|
|
end if;
|
386 |
|
|
end if;
|
387 |
|
|
when "10" => -- return to main
|
388 |
|
|
taddr := ici.fpc(TAG_HIGH downto LINE_LOW);
|
389 |
|
|
v.istate := "00"; v.flush := r.flush2;
|
390 |
|
|
when others => v.istate := "00";
|
391 |
|
|
end case;
|
392 |
|
|
|
393 |
|
|
if mcio.retry = '1' then v.req := '1'; end if;
|
394 |
|
|
|
395 |
|
|
-- Generate new valid bits write strobe
|
396 |
|
|
|
397 |
|
|
vmaskraw := decode(r.waddress(LINE_HIGH downto LINE_LOW));
|
398 |
|
|
twrite := write;
|
399 |
|
|
if cacheon = '0' then
|
400 |
|
|
twrite := '0'; vmask := (others => '0');
|
401 |
|
|
elsif (mcio.ics = "01") then
|
402 |
|
|
twrite := twrite and r.hit;
|
403 |
|
|
vmask := icramo.itramout(set).valid or vmaskraw;
|
404 |
|
|
else
|
405 |
|
|
if r.hit = '1' then vmask := r.valid or vmaskraw;
|
406 |
|
|
else vmask := vmaskraw; end if;
|
407 |
|
|
end if;
|
408 |
|
|
if (mcio.mexc or not mcio.cache) = '1' then
|
409 |
|
|
twrite := '0'; dwrite := '0';
|
410 |
|
|
else dwrite := twrite; end if;
|
411 |
|
|
if twrite = '1' then
|
412 |
|
|
v.valid := vmask; v.hit := '1';
|
413 |
|
|
if (ISETS > 1) and (ICREPLACE = lru) then vl.write := '1'; end if;
|
414 |
|
|
end if;
|
415 |
|
|
|
416 |
|
|
if (ISETS > 1) and (ICREPLACE = lru) and (rl.write = '1') then
|
417 |
|
|
vl.lru(conv_integer(rl.waddr)) :=
|
418 |
|
|
lru_calc(rl.lru(conv_integer(rl.waddr)), conv_integer(rl.set));
|
419 |
|
|
end if;
|
420 |
|
|
|
421 |
|
|
-- cache write signals
|
422 |
|
|
|
423 |
|
|
if ISETS > 1 then setrepl := r.setrepl; else setrepl := (others => '0'); end if;
|
424 |
|
|
-- pragma translate_off
|
425 |
|
|
if not is_x(setrepl) then
|
426 |
|
|
-- pragma translate_on
|
427 |
|
|
if twrite = '1' then ctwrite(conv_integer(setrepl)) := '1'; end if;
|
428 |
|
|
if dwrite = '1' then cdwrite(conv_integer(setrepl)) := '1'; end if;
|
429 |
|
|
-- pragma translate_off
|
430 |
|
|
end if;
|
431 |
|
|
-- pragma translate_on
|
432 |
|
|
|
433 |
|
|
-- diagnostic cache access
|
434 |
|
|
|
435 |
|
|
if diagen = '1' then
|
436 |
|
|
if (ISETS /= 1) then
|
437 |
|
|
v.diagset := dco.icdiag.addr(SETBITS -1 + TAG_LOW downto TAG_LOW);
|
438 |
|
|
end if;
|
439 |
|
|
end if;
|
440 |
|
|
|
441 |
|
|
if (ISETS /= 1) then
|
442 |
|
|
-- pragma translate_off
|
443 |
|
|
if not is_x(r.diagset) then
|
444 |
|
|
-- pragma translate_on
|
445 |
|
|
rdiagset := conv_integer(r.diagset);
|
446 |
|
|
-- pragma translate_off
|
447 |
|
|
end if;
|
448 |
|
|
-- pragma translate_on
|
449 |
|
|
-- pragma translate_off
|
450 |
|
|
if not is_x(v.diagset) then
|
451 |
|
|
-- pragma translate_on
|
452 |
|
|
vdiagset := conv_integer(v.diagset);
|
453 |
|
|
-- pragma translate_off
|
454 |
|
|
end if;
|
455 |
|
|
-- pragma translate_on
|
456 |
|
|
end if;
|
457 |
|
|
|
458 |
|
|
diagdata := icramo.idramout(rdiagset).data;
|
459 |
|
|
if diagen = '1' then -- diagnostic access
|
460 |
|
|
taddr(OFFSET_HIGH downto LINE_LOW) := dco.icdiag.addr(OFFSET_HIGH downto LINE_LOW);
|
461 |
|
|
wtag(TAG_HIGH downto TAG_LOW) := dci.maddress(TAG_HIGH downto TAG_LOW);
|
462 |
|
|
wlrr := dci.maddress(ICTAG_LRRPOS);
|
463 |
|
|
wlock := dci.maddress(ICTAG_LOCKPOS);
|
464 |
|
|
if dco.icdiag.tag = '1' then
|
465 |
|
|
twrite := not dco.icdiag.read; dwrite := '0';
|
466 |
|
|
ctwrite := (others => '0'); cdwrite := (others => '0');
|
467 |
|
|
ctwrite(vdiagset) := not dco.icdiag.read;
|
468 |
|
|
diagdata := (others => '0');
|
469 |
|
|
diagdata(TAG_HIGH downto TAG_LOW) := icramo.itramout(rdiagset).tag(ITAG_BITS - ILINE_SIZE - 1 downto 0);
|
470 |
|
|
diagdata(ILINE_SIZE -1 downto 0) := icramo.itramout(rdiagset).valid;
|
471 |
|
|
diagdata(ICTAG_LRRPOS) := icramo.itramout(rdiagset).lrr;
|
472 |
|
|
diagdata(ICTAG_LOCKPOS) := icramo.itramout(rdiagset).lock;
|
473 |
|
|
else
|
474 |
|
|
dwrite := not dco.icdiag.read; twrite := '0';
|
475 |
|
|
cdwrite := (others => '0'); cdwrite(vdiagset) := not dco.icdiag.read;
|
476 |
|
|
ctwrite := (others => '0');
|
477 |
|
|
end if;
|
478 |
|
|
vmask := dci.maddress(ILINE_SIZE -1 downto 0);
|
479 |
|
|
v.diagrdy := '1';
|
480 |
|
|
end if;
|
481 |
|
|
|
482 |
|
|
-- select data to return on read access
|
483 |
|
|
|
484 |
|
|
case rdatasel is
|
485 |
|
|
when memory => rdata := mcio.data;
|
486 |
|
|
when others => rdata := icramo.idramout(set).data;
|
487 |
|
|
end case;
|
488 |
|
|
|
489 |
|
|
-- cache flush
|
490 |
|
|
|
491 |
|
|
if (ici.flush or dco.icdiag.flush) = '1' then
|
492 |
|
|
v.flush := '1'; v.flush2 := '1'; v.faddr := (others => '0');
|
493 |
|
|
end if;
|
494 |
|
|
|
495 |
|
|
if r.flush2 = '1' then
|
496 |
|
|
twrite := '1'; ctwrite := (others => '1'); vmask := (others => '0');
|
497 |
|
|
v.faddr := r.faddr +1; taddr(OFFSET_HIGH downto OFFSET_LOW) := r.faddr;
|
498 |
|
|
wlrr := '0'; wlock := '0'; wtag := (others => '0');
|
499 |
|
|
if (r.faddr(IOFFSET_BITS -1) and not v.faddr(IOFFSET_BITS -1)) = '1' then
|
500 |
|
|
v.flush2 := '0';
|
501 |
|
|
end if;
|
502 |
|
|
end if;
|
503 |
|
|
|
504 |
|
|
-- reset
|
505 |
|
|
|
506 |
|
|
if rst = '0' then
|
507 |
|
|
v.istate := "00"; v.req := '0'; v.burst := '0'; v.holdn := '1';
|
508 |
|
|
v.flush := '0'; v.flush2 := '0'; v.overrun := '0'; v.underrun := '0';
|
509 |
|
|
v.rndcnt := (others => '0'); v.lrr := '0'; v.setrepl := (others => '0');
|
510 |
|
|
v.diagset := (others => '0'); v.lock := '0';
|
511 |
|
|
end if;
|
512 |
|
|
|
513 |
|
|
if (not rst or r.flush) = '1' then
|
514 |
|
|
vl.lru := (others => (others => '0'));
|
515 |
|
|
end if;
|
516 |
|
|
|
517 |
|
|
-- Drive signals
|
518 |
|
|
|
519 |
|
|
c <= v; -- register inputs
|
520 |
|
|
cl <= vl; -- lru register inputs
|
521 |
|
|
|
522 |
|
|
-- tag ram inputs
|
523 |
|
|
icrami.itramin.valid <= vmask;
|
524 |
|
|
icrami.itramin.tag <= wtag;
|
525 |
|
|
icrami.itramin.lrr <= wlrr;
|
526 |
|
|
icrami.itramin.lock <= wlock;
|
527 |
|
|
icrami.itramin.enable <= enable;
|
528 |
|
|
icrami.itramin.write <= ctwrite;
|
529 |
|
|
icrami.itramin.flush <= r.flush2;
|
530 |
|
|
|
531 |
|
|
-- data ram inputs
|
532 |
|
|
icrami.idramin.enable <= enable;
|
533 |
|
|
icrami.idramin.address <= taddr(OFFSET_HIGH downto LINE_LOW);
|
534 |
|
|
icrami.idramin.data <= ddatain;
|
535 |
|
|
icrami.idramin.write <= cdwrite;
|
536 |
|
|
|
537 |
|
|
-- memory controller inputs
|
538 |
|
|
mcii.address(31 downto 2) <= r.waddress(31 downto 2);
|
539 |
|
|
mcii.address(1 downto 0) <= "00";
|
540 |
|
|
mcii.su <= r.su;
|
541 |
|
|
mcii.burst <= r.burst;
|
542 |
|
|
mcii.req <= r.req;
|
543 |
|
|
mcii.flush <= r.flush;
|
544 |
|
|
|
545 |
|
|
-- IU data cache inputs
|
546 |
|
|
ico.data <= rdata;
|
547 |
|
|
ico.exception <= mcio.mexc or error;
|
548 |
|
|
ico.hold <= r.holdn;
|
549 |
|
|
ico.mds <= mds;
|
550 |
|
|
ico.flush <= r.flush;
|
551 |
|
|
ico.diagdata <= diagdata;
|
552 |
|
|
ico.diagrdy <= r.diagrdy;
|
553 |
|
|
|
554 |
|
|
end process;
|
555 |
|
|
|
556 |
|
|
-- Local registers
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
regs1 : process(clk)
|
560 |
|
|
begin if rising_edge(clk) then r <= c; end if; end process;
|
561 |
|
|
|
562 |
|
|
regs2gen : if (ISETS > 1) and (ICREPLACE = lru) generate
|
563 |
|
|
regs2 : process(clk)
|
564 |
|
|
begin if rising_edge(clk) then rl <= cl; end if; end process;
|
565 |
|
|
end generate;
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
-- pragma translate_off
|
569 |
|
|
chk : process
|
570 |
|
|
begin
|
571 |
|
|
assert not ((ISETS > 2) and (ICREPLACE = lrr)) report
|
572 |
|
|
"Wrong instruction cache configuration detected: LRR replacement requires 2 sets"
|
573 |
|
|
severity failure;
|
574 |
|
|
wait;
|
575 |
|
|
end process;
|
576 |
|
|
-- pragma translate_on
|
577 |
|
|
|
578 |
|
|
end ;
|
579 |
|
|
|