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: dcache
|
19 |
|
|
-- File: dcache.vhd
|
20 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
21 |
|
|
-- Description: This unit implements the data 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.amba.all;
|
30 |
|
|
use work.leon_target.all;
|
31 |
|
|
use work.leon_config.all;
|
32 |
|
|
use work.sparcv8.all; -- ASI declarations
|
33 |
|
|
use work.leon_iface.all;
|
34 |
|
|
use work.macro.all; -- xorv()
|
35 |
|
|
|
36 |
|
|
entity dcache is
|
37 |
|
|
port (
|
38 |
|
|
rst : in std_logic;
|
39 |
|
|
clk : in clk_type;
|
40 |
|
|
dci : in dcache_in_type;
|
41 |
|
|
dco : out dcache_out_type;
|
42 |
|
|
ico : in icache_out_type;
|
43 |
|
|
mcdi : out memory_dc_in_type;
|
44 |
|
|
mcdo : in memory_dc_out_type;
|
45 |
|
|
ahbsi : in ahb_slv_in_type;
|
46 |
|
|
dcrami : out dcram_in_type;
|
47 |
|
|
dcramo : in dcram_out_type;
|
48 |
|
|
fpuholdn : in std_logic
|
49 |
|
|
);
|
50 |
|
|
end;
|
51 |
|
|
|
52 |
|
|
architecture rtl of dcache is
|
53 |
|
|
|
54 |
|
|
constant TAG_HIGH : integer := DTAG_HIGH;
|
55 |
|
|
constant TAG_LOW : integer := DOFFSET_BITS + DLINE_BITS + 2;
|
56 |
|
|
constant OFFSET_HIGH: integer := TAG_LOW - 1;
|
57 |
|
|
constant OFFSET_LOW : integer := DLINE_BITS + 2;
|
58 |
|
|
constant LINE_HIGH : integer := OFFSET_LOW - 1;
|
59 |
|
|
constant LINE_LOW : integer := 2;
|
60 |
|
|
constant LINE_ZERO : std_logic_vector(DLINE_BITS-1 downto 0) := (others => '0');
|
61 |
|
|
constant SETBITS : integer := log2x(DSETS);
|
62 |
|
|
|
63 |
|
|
type rdatatype is (dtag, ddata, dddata, icache, memory); -- sources during cache read
|
64 |
|
|
type vmasktype is (clearone, clearall, merge, tnew); -- valid bits operation
|
65 |
|
|
|
66 |
|
|
type write_buffer_type is record -- write buffer
|
67 |
|
|
addr, data1, data2 : std_logic_vector(31 downto 0);
|
68 |
|
|
size : std_logic_vector(1 downto 0);
|
69 |
|
|
asi : std_logic_vector(3 downto 0);
|
70 |
|
|
read : std_logic;
|
71 |
|
|
lock : std_logic;
|
72 |
|
|
end record;
|
73 |
|
|
|
74 |
|
|
type dcache_control_type is record -- all registers
|
75 |
|
|
read : std_logic; -- access direction
|
76 |
|
|
signed : std_logic; -- signed/unsigned read
|
77 |
|
|
size : std_logic_vector(1 downto 0); -- access size
|
78 |
|
|
req, burst, holdn, nomds, stpend : std_logic;
|
79 |
|
|
xaddress : std_logic_vector(31 downto 0); -- common address buffer
|
80 |
|
|
faddr : std_logic_vector(DOFFSET_BITS - 1 downto 0); -- flush address
|
81 |
|
|
valid : std_logic_vector(DLINE_SIZE - 1 downto 0); -- registered valid bits
|
82 |
|
|
dstate : std_logic_vector(2 downto 0); -- FSM vector
|
83 |
|
|
hit : std_logic;
|
84 |
|
|
flush : std_logic; -- flush in progress
|
85 |
|
|
mexc : std_logic; -- latched mexc
|
86 |
|
|
wb : write_buffer_type; -- write buffer
|
87 |
|
|
asi : std_logic_vector(3 downto 0);
|
88 |
|
|
icenable : std_logic; -- icache diag access
|
89 |
|
|
rndcnt : std_logic_vector(log2x(DSETS)-1 downto 0); -- replace counter
|
90 |
|
|
setrepl : std_logic_vector(log2x(DSETS)-1 downto 0); -- set to replace
|
91 |
|
|
lrr : std_logic;
|
92 |
|
|
dsuset : std_logic_vector(log2x(DSETS)-1 downto 0);
|
93 |
|
|
lock : std_logic;
|
94 |
|
|
lramrd : std_logic;
|
95 |
|
|
|
96 |
|
|
end record;
|
97 |
|
|
|
98 |
|
|
type snoop_reg_type is record -- snoop control registers
|
99 |
|
|
snoop : std_logic; -- snoop access to tags
|
100 |
|
|
writebp : std_logic_vector(0 to DSETS-1); -- snoop write bypass
|
101 |
|
|
addr : std_logic_vector(TAG_HIGH downto OFFSET_LOW);-- snoop tag
|
102 |
|
|
end record;
|
103 |
|
|
|
104 |
|
|
type snoop_hit_bits_type is array (0 to 2**DOFFSET_BITS-1) of std_logic_vector(0 to DSETS-1);
|
105 |
|
|
|
106 |
|
|
type snoop_hit_reg_type is record
|
107 |
|
|
hit : snoop_hit_bits_type; -- snoop hit bits
|
108 |
|
|
taddr : std_logic_vector(OFFSET_HIGH downto OFFSET_LOW); -- saved tag address
|
109 |
|
|
set : std_logic_vector(log2x(DSETS)-1 downto 0); -- saved set
|
110 |
|
|
end record;
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
subtype lru_type is std_logic_vector(DLRUBITS-1 downto 0);
|
114 |
|
|
type lru_array is array (0 to 2**DOFFSET_BITS-1) of lru_type; -- lru registers
|
115 |
|
|
type par_type is array (0 to DSETS-1) of std_logic_vector(1 downto 0);
|
116 |
|
|
|
117 |
|
|
type lru_reg_type is record
|
118 |
|
|
write : std_logic;
|
119 |
|
|
waddr : std_logic_vector(DOFFSET_BITS-1 downto 0);
|
120 |
|
|
set : std_logic_vector(SETBITS-1 downto 0); --integer range 0 to DSETS-1;
|
121 |
|
|
lru : lru_array;
|
122 |
|
|
end record;
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
subtype lock_type is std_logic_vector(0 to DSETS-1);
|
126 |
|
|
|
127 |
|
|
function lru_set (lru : lru_type; lock : lock_type) return std_logic_vector is
|
128 |
|
|
variable xlru : std_logic_vector(4 downto 0);
|
129 |
|
|
variable set : std_logic_vector(SETBITS-1 downto 0);
|
130 |
|
|
variable xset : std_logic_vector(1 downto 0);
|
131 |
|
|
variable unlocked : integer range 0 to DSETS-1;
|
132 |
|
|
begin
|
133 |
|
|
set := (others => '0'); xlru := (others => '0');
|
134 |
|
|
xlru(DLRUBITS-1 downto 0) := lru;
|
135 |
|
|
|
136 |
|
|
if DCLOCK_BIT = 1 then
|
137 |
|
|
unlocked := DSETS-1;
|
138 |
|
|
for i in DSETS-1 downto 0 loop
|
139 |
|
|
if lock(i) = '0' then unlocked := i; end if;
|
140 |
|
|
end loop;
|
141 |
|
|
end if;
|
142 |
|
|
|
143 |
|
|
case DSETS is
|
144 |
|
|
when 2 =>
|
145 |
|
|
if DCLOCK_BIT = 1 then
|
146 |
|
|
if lock(0) = '1' then xset(0) := '1'; else xset(0) := xlru(0); end if;
|
147 |
|
|
else xset(0) := xlru(0); end if;
|
148 |
|
|
when 3 =>
|
149 |
|
|
if DCLOCK_BIT = 1 then
|
150 |
|
|
xset := std_logic_vector(conv_unsigned(lru3_repl_table(conv_integer(xlru)) (unlocked), 2));
|
151 |
|
|
else
|
152 |
|
|
xset := std_logic_vector(conv_unsigned(lru3_repl_table(conv_integer(xlru)) (0), 2));
|
153 |
|
|
end if;
|
154 |
|
|
when 4 =>
|
155 |
|
|
if DCLOCK_BIT = 1 then
|
156 |
|
|
xset := std_logic_vector(conv_unsigned(lru4_repl_table(conv_integer(xlru)) (unlocked), 2));
|
157 |
|
|
else
|
158 |
|
|
xset := std_logic_vector(conv_unsigned(lru4_repl_table(conv_integer(xlru)) (0), 2));
|
159 |
|
|
end if;
|
160 |
|
|
when others =>
|
161 |
|
|
end case;
|
162 |
|
|
set := xset(SETBITS-1 downto 0);
|
163 |
|
|
return(set);
|
164 |
|
|
end;
|
165 |
|
|
|
166 |
|
|
function lru_calc (lru : lru_type; set : integer) return lru_type is
|
167 |
|
|
variable new_lru : lru_type;
|
168 |
|
|
variable xnew_lru: std_logic_vector(4 downto 0);
|
169 |
|
|
variable xlru : std_logic_vector(4 downto 0);
|
170 |
|
|
begin
|
171 |
|
|
new_lru := (others => '0'); xnew_lru := (others => '0');
|
172 |
|
|
xlru := (others => '0'); xlru(DLRUBITS-1 downto 0) := lru;
|
173 |
|
|
case DSETS is
|
174 |
|
|
when 2 =>
|
175 |
|
|
if set = 0 then xnew_lru(0) := '1'; else xnew_lru(0) := '0'; end if;
|
176 |
|
|
when 3 =>
|
177 |
|
|
xnew_lru(2 downto 0) := lru_3set_table(conv_integer(lru))(set);
|
178 |
|
|
when 4 =>
|
179 |
|
|
xnew_lru(4 downto 0) := lru_4set_table(conv_integer(lru))(set);
|
180 |
|
|
when others =>
|
181 |
|
|
end case;
|
182 |
|
|
new_lru := xnew_lru(DLRUBITS-1 downto 0);
|
183 |
|
|
return(new_lru);
|
184 |
|
|
end;
|
185 |
|
|
|
186 |
|
|
subtype word is std_logic_vector(31 downto 0);
|
187 |
|
|
|
188 |
|
|
signal r, c : dcache_control_type; -- r is registers, c is combinational
|
189 |
|
|
signal rs, cs : snoop_reg_type; -- rs is registers, cs is combinational
|
190 |
|
|
signal rh, ch : snoop_hit_reg_type; -- rs is registers, cs is combinational
|
191 |
|
|
signal rl, cl : lru_reg_type; -- rl is registers, cl is combinational
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
begin
|
195 |
|
|
|
196 |
|
|
dctrl : process(rst, r, rs, rh, rl, dci, mcdo, ico, dcramo, ahbsi, fpuholdn)
|
197 |
|
|
type ddtype is array (0 to DSETS-1) of word;
|
198 |
|
|
variable dcramov : dcram_out_type;
|
199 |
|
|
variable rdatasel : rdatatype;
|
200 |
|
|
variable maddress : std_logic_vector(31 downto 0);
|
201 |
|
|
variable maddrlow : std_logic_vector(1 downto 0);
|
202 |
|
|
variable edata : std_logic_vector(31 downto 0);
|
203 |
|
|
variable size : std_logic_vector(1 downto 0);
|
204 |
|
|
variable read : std_logic;
|
205 |
|
|
variable twrite, tdiagwrite, ddiagwrite, dwrite : std_logic;
|
206 |
|
|
variable taddr : std_logic_vector(OFFSET_HIGH downto LINE_LOW); -- tag address
|
207 |
|
|
variable newtag : std_logic_vector(TAG_HIGH downto TAG_LOW); -- new tag
|
208 |
|
|
variable align_data : std_logic_vector(31 downto 0); -- aligned data
|
209 |
|
|
variable ddatain : std_logic_vector(31 downto 0);
|
210 |
|
|
variable ddatainv, rdatav, align_datav : ddtype;
|
211 |
|
|
variable rdata : std_logic_vector(31 downto 0);
|
212 |
|
|
|
213 |
|
|
variable vmaskraw, vmask : std_logic_vector((DLINE_SIZE -1) downto 0);
|
214 |
|
|
variable ivalid : std_logic_vector((DLINE_SIZE -1) downto 0);
|
215 |
|
|
variable vmaskdbl : std_logic_vector((DLINE_SIZE/2 -1) downto 0);
|
216 |
|
|
variable enable : std_logic;
|
217 |
|
|
variable mds : std_logic;
|
218 |
|
|
variable mexc : std_logic;
|
219 |
|
|
variable hit, valid, validraw, forcemiss : std_logic;
|
220 |
|
|
variable signed : std_logic;
|
221 |
|
|
variable flush : std_logic;
|
222 |
|
|
variable iflush : std_logic;
|
223 |
|
|
variable v : dcache_control_type;
|
224 |
|
|
variable eholdn : std_logic; -- external hold
|
225 |
|
|
variable snoopwe : std_logic;
|
226 |
|
|
variable hcache : std_logic;
|
227 |
|
|
variable lramcs, lramen, lramrd, lramwr : std_logic;
|
228 |
|
|
variable snoopaddr: std_logic_vector(OFFSET_HIGH downto OFFSET_LOW);
|
229 |
|
|
variable vs : snoop_reg_type;
|
230 |
|
|
variable vh : snoop_hit_reg_type;
|
231 |
|
|
variable dsudata : std_logic_vector(31 downto 0);
|
232 |
|
|
variable set : integer range 0 to DSETS-1;
|
233 |
|
|
variable ddset : integer range 0 to MAXSETS-1;
|
234 |
|
|
variable snoopset : integer range 0 to DSETS-1;
|
235 |
|
|
variable validv, hitv, validrawv : std_logic_vector(0 to MAXSETS-1);
|
236 |
|
|
variable csnoopwe : std_logic_vector(0 to MAXSETS-1);
|
237 |
|
|
variable ctwrite, cdwrite : std_logic_vector(0 to MAXSETS-1);
|
238 |
|
|
variable vset, setrepl : std_logic_vector(log2x(DSETS)-1 downto 0);
|
239 |
|
|
variable wlrr : std_logic_vector(0 to MAXSETS-1);
|
240 |
|
|
variable vl : lru_reg_type;
|
241 |
|
|
variable diagset : std_logic_vector(TAG_LOW + SETBITS -1 downto TAG_LOW);
|
242 |
|
|
variable lock : std_logic_vector(0 to DSETS-1);
|
243 |
|
|
variable wlock : std_logic_vector(0 to MAXSETS-1);
|
244 |
|
|
variable snoophit : std_logic_vector(0 to DSETS-1);
|
245 |
|
|
variable snoopval : std_logic;
|
246 |
|
|
variable snoopset2, rdsuset : integer range 0 to DSETS-1;
|
247 |
|
|
variable laddr : std_logic_vector(31 downto 0); -- local ram addr
|
248 |
|
|
|
249 |
|
|
begin
|
250 |
|
|
|
251 |
|
|
-- init local variables
|
252 |
|
|
|
253 |
|
|
v := r; vs := rs; vh := rh; dcramov := dcramo; vl := rl;
|
254 |
|
|
vl.write := '0'; lramen := '0'; lramrd := '0'; lramwr := '0';
|
255 |
|
|
lramcs := '0'; laddr := (others => '0'); v.lramrd := '0';
|
256 |
|
|
|
257 |
|
|
mds := '1'; dwrite := '0'; twrite := '0';
|
258 |
|
|
ddiagwrite := '0'; tdiagwrite := '0'; v.holdn := '1'; mexc := '0';
|
259 |
|
|
flush := '0'; v.icenable := '0'; iflush := '0';
|
260 |
|
|
eholdn := ico.hold and fpuholdn; ddset := 0; vset := (others => '0');
|
261 |
|
|
vs.snoop := '0'; vs.writebp := (others => '0'); snoopwe := '0';
|
262 |
|
|
snoopaddr := ahbsi.haddr(OFFSET_HIGH downto OFFSET_LOW);
|
263 |
|
|
hcache := '0'; rdsuset := 0; enable := '1';
|
264 |
|
|
validv := (others => '0'); validrawv := (others => '0');
|
265 |
|
|
hitv := (others => '0'); ivalid := (others => '0');
|
266 |
|
|
|
267 |
|
|
rdatasel := ddata; -- read data from cache as default
|
268 |
|
|
|
269 |
|
|
set := 0; snoopset := 0; csnoopwe := (others => '0');
|
270 |
|
|
ctwrite := (others => '0'); cdwrite := (others => '0');
|
271 |
|
|
wlock := (others => '0');
|
272 |
|
|
for i in 0 to DSETS-1 loop wlock(i) := dcramov.dtramout(i).lock; end loop;
|
273 |
|
|
wlrr := (others => '0');
|
274 |
|
|
for i in 0 to 1 loop wlrr(i) := dcramov.dtramout(i).lrr; end loop;
|
275 |
|
|
|
276 |
|
|
if (DSETS > 1) then setrepl := r.setrepl; else setrepl := (others => '0'); end if;
|
277 |
|
|
|
278 |
|
|
-- random replacement counter
|
279 |
|
|
if DSETS > 1 then
|
280 |
|
|
-- pragma translate_off
|
281 |
|
|
if not is_x(r.rndcnt) then
|
282 |
|
|
-- pragma translate_on
|
283 |
|
|
if conv_integer(r.rndcnt) = (DSETS - 1) then v.rndcnt := (others => '0');
|
284 |
|
|
else v.rndcnt := r.rndcnt + 1; end if;
|
285 |
|
|
-- pragma translate_off
|
286 |
|
|
end if;
|
287 |
|
|
-- pragma translate_on
|
288 |
|
|
end if;
|
289 |
|
|
|
290 |
|
|
-- generate lock bits
|
291 |
|
|
lock := (others => '0');
|
292 |
|
|
if DCLOCK_BIT = 1 then
|
293 |
|
|
for i in 0 to DSETS-1 loop lock(i) := dcramov.dtramout(i).lock; end loop;
|
294 |
|
|
end if;
|
295 |
|
|
|
296 |
|
|
-- AHB snoop handling
|
297 |
|
|
|
298 |
|
|
if DSNOOP then
|
299 |
|
|
|
300 |
|
|
-- snoop only in cacheable areas
|
301 |
|
|
-- for i in PROC_CACHETABLE'range loop --'
|
302 |
|
|
-- if (ahbsi.haddr(31 downto 32-PROC_CACHE_ADDR_MSB) >= PROC_CACHETABLE(i).firstaddr) and
|
303 |
|
|
-- (ahbsi.haddr(31 downto 32-PROC_CACHE_ADDR_MSB) < PROC_CACHETABLE(i).lastaddr)
|
304 |
|
|
-- then hcache := '1'; end if;
|
305 |
|
|
-- end loop;
|
306 |
|
|
hcache := is_cacheable(ahbsi.haddr(31 downto 24));
|
307 |
|
|
-- snoop on NONSEQ or SEQ and first word in cache line
|
308 |
|
|
-- do not snoop during own transfers or during cache flush
|
309 |
|
|
if (ahbsi.hready and ahbsi.hwrite and not mcdo.bg) = '1' and
|
310 |
|
|
((ahbsi.htrans = HTRANS_NONSEQ) or
|
311 |
|
|
((ahbsi.htrans = HTRANS_SEQ) and
|
312 |
|
|
(ahbsi.haddr(LINE_HIGH downto LINE_LOW) = LINE_ZERO)))
|
313 |
|
|
then
|
314 |
|
|
vs.snoop := mcdo.dsnoop and hcache;
|
315 |
|
|
vs.addr := ahbsi.haddr(TAG_HIGH downto OFFSET_LOW);
|
316 |
|
|
end if;
|
317 |
|
|
-- clear valid bits on snoop hit (or set hit bits)
|
318 |
|
|
for i in DSETS-1 downto 0 loop
|
319 |
|
|
if ((rs.snoop and (not mcdo.ba) and not r.flush) = '1')
|
320 |
|
|
and (dcramov.dtramoutsn(i).tag = rs.addr(TAG_HIGH downto TAG_LOW))
|
321 |
|
|
then
|
322 |
|
|
if DSNOOP_FAST then
|
323 |
|
|
-- pragma translate_off
|
324 |
|
|
if not is_x(rs.addr(OFFSET_HIGH downto OFFSET_LOW)) then
|
325 |
|
|
-- pragma translate_on
|
326 |
|
|
vh.hit(conv_integer(rs.addr(OFFSET_HIGH downto OFFSET_LOW)))(i) := '1';
|
327 |
|
|
-- vh.set := std_logic_vector(conv_unsigned(i, SETBITS));
|
328 |
|
|
-- pragma translate_off
|
329 |
|
|
end if;
|
330 |
|
|
-- pragma translate_on
|
331 |
|
|
else
|
332 |
|
|
snoopaddr := rs.addr(OFFSET_HIGH downto OFFSET_LOW);
|
333 |
|
|
snoopwe := '1'; snoopset := i;
|
334 |
|
|
end if;
|
335 |
|
|
end if;
|
336 |
|
|
-- bypass tag data on read/write contention
|
337 |
|
|
if (not DSNOOP_FAST) and (rs.writebp(i) = '1') then
|
338 |
|
|
dcramov.dtramout(i).tag := rs.addr(TAG_HIGH downto TAG_LOW);
|
339 |
|
|
dcramov.dtramout(i).valid := (others => '0');
|
340 |
|
|
end if;
|
341 |
|
|
end loop;
|
342 |
|
|
end if;
|
343 |
|
|
|
344 |
|
|
-- generate access parameters during pipeline stall
|
345 |
|
|
|
346 |
|
|
if ((r.holdn) = '0') or (DEBUG_UNIT and (dci.dsuen = '1')) then
|
347 |
|
|
taddr := r.xaddress(OFFSET_HIGH downto LINE_LOW);
|
348 |
|
|
--if r.dsuwren = '0' then v.dsuwren := '1'; end if;
|
349 |
|
|
elsif ((dci.enaddr and not dci.read) = '1') or (eholdn = '0')
|
350 |
|
|
then
|
351 |
|
|
taddr := dci.maddress(OFFSET_HIGH downto LINE_LOW);
|
352 |
|
|
else
|
353 |
|
|
taddr := dci.eaddress(OFFSET_HIGH downto LINE_LOW);
|
354 |
|
|
end if;
|
355 |
|
|
|
356 |
|
|
if (dci.write or not r.holdn) = '1' then
|
357 |
|
|
maddress := r.xaddress(31 downto 0); signed := r.signed;
|
358 |
|
|
read := r.read; size := r.size; edata := dci.maddress;
|
359 |
|
|
else
|
360 |
|
|
maddress := dci.maddress(31 downto 0); signed := dci.signed;
|
361 |
|
|
read := dci.read; size := dci.size; edata := dci.edata;
|
362 |
|
|
end if;
|
363 |
|
|
|
364 |
|
|
newtag := dci.maddress(TAG_HIGH downto TAG_LOW);
|
365 |
|
|
vl.waddr := maddress(OFFSET_HIGH downto OFFSET_LOW); -- lru write address
|
366 |
|
|
|
367 |
|
|
-- generate cache hit and valid bits
|
368 |
|
|
|
369 |
|
|
forcemiss := not dci.asi(3); hit := '0'; set := 0; snoophit := (others => '0');
|
370 |
|
|
snoopval := '1';
|
371 |
|
|
for i in DSETS-1 downto 0 loop
|
372 |
|
|
if DSNOOP and DSNOOP_FAST then
|
373 |
|
|
-- pragma translate_off
|
374 |
|
|
if not is_x(rh.taddr) then
|
375 |
|
|
-- pragma translate_on
|
376 |
|
|
snoophit(i) := rh.hit(conv_integer(rh.taddr))(i);
|
377 |
|
|
-- pragma translate_off
|
378 |
|
|
end if;
|
379 |
|
|
-- pragma translate_on
|
380 |
|
|
end if;
|
381 |
|
|
if (dcramov.dtramout(i).tag = dci.maddress(TAG_HIGH downto TAG_LOW))
|
382 |
|
|
then hitv(i) := '1'; end if; -- not r.flush; set := i; end if;
|
383 |
|
|
validrawv(i) := hitv(i) and (not r.flush) and (not snoophit(i)) and
|
384 |
|
|
genmux(dci.maddress(LINE_HIGH downto LINE_LOW), dcramov.dtramout(i).valid);
|
385 |
|
|
validv(i) := validrawv(i);
|
386 |
|
|
if (hitv(i) and not snoophit(i)) = '1' then ivalid := ivalid or dcramov.dtramout(i).valid; end if;
|
387 |
|
|
snoopval := snoopval and not snoophit(i);
|
388 |
|
|
end loop;
|
389 |
|
|
|
390 |
|
|
hit := orv(hitv) and not r.flush; validraw := orv(validrawv);
|
391 |
|
|
valid := orv(validv);
|
392 |
|
|
if DSETS > 1 then
|
393 |
|
|
for i in DSETS-1 downto 0 loop
|
394 |
|
|
if (hitv(i) = '1') then
|
395 |
|
|
vset := vset or std_logic_vector(conv_unsigned(i, SETBITS));
|
396 |
|
|
end if;
|
397 |
|
|
end loop;
|
398 |
|
|
set := conv_integer(vset);
|
399 |
|
|
else set := 0; end if;
|
400 |
|
|
|
401 |
|
|
if (dci.dsuen and (not r.holdn)) = '1' then diagset := r.xaddress(TAG_LOW+SETBITS-1 downto TAG_LOW);
|
402 |
|
|
else diagset := maddress(TAG_LOW + SETBITS - 1 downto TAG_LOW); end if;
|
403 |
|
|
-- pragma translate_off
|
404 |
|
|
if not is_x(diagset) then
|
405 |
|
|
-- pragma translate_on
|
406 |
|
|
case DSETS is
|
407 |
|
|
when 1 => ddset := 0;
|
408 |
|
|
when 3 => if conv_integer(diagset) < 3 then ddset := conv_integer(diagset); end if;
|
409 |
|
|
when others => ddset := conv_integer(diagset);
|
410 |
|
|
end case;
|
411 |
|
|
-- pragma translate_off
|
412 |
|
|
end if;
|
413 |
|
|
--pragma translate_on
|
414 |
|
|
|
415 |
|
|
if ((r.holdn and dci.enaddr) = '1') and (r.dstate = "000") then
|
416 |
|
|
v.hit := hit; v.xaddress := dci.maddress;
|
417 |
|
|
v.read := dci.read; v.size := dci.size;
|
418 |
|
|
v.asi := dci.asi(3 downto 0);
|
419 |
|
|
v.signed := dci.signed;
|
420 |
|
|
end if;
|
421 |
|
|
|
422 |
|
|
-- Store buffer
|
423 |
|
|
|
424 |
|
|
-- wdata := r.wb.data1;
|
425 |
|
|
if mcdo.ready = '1' then
|
426 |
|
|
v.wb.addr(2) := r.wb.addr(2) or (r.wb.size(0) and r.wb.size(1));
|
427 |
|
|
if r.stpend = '1' then
|
428 |
|
|
v.stpend := r.req; v.wb.data1 := r.wb.data2;
|
429 |
|
|
v.wb.lock := r.wb.lock and r.req;
|
430 |
|
|
end if;
|
431 |
|
|
end if;
|
432 |
|
|
if mcdo.grant = '1' then v.req := r.burst; v.burst := '0'; end if;
|
433 |
|
|
|
434 |
|
|
if (LOCAL_RAM) then
|
435 |
|
|
if ((r.holdn) = '0') or (DEBUG_UNIT and (dci.dsuen = '1')) then
|
436 |
|
|
laddr := r.xaddress;
|
437 |
|
|
elsif ((dci.enaddr and not dci.read) = '1') or (eholdn = '0') then
|
438 |
|
|
laddr := dci.maddress;
|
439 |
|
|
else laddr := dci.eaddress; end if;
|
440 |
|
|
if (dci.enaddr = '1') and (dci.maddress(31 downto 24) = LOCAL_RAM_START)
|
441 |
|
|
then lramen := '1'; end if;
|
442 |
|
|
if ((dci.eenaddr or dci.enaddr) = '1') and (laddr(31 downto 24) = LOCAL_RAM_START)
|
443 |
|
|
then lramcs := '1'; end if;
|
444 |
|
|
end if;
|
445 |
|
|
|
446 |
|
|
-- main Dcache state machine
|
447 |
|
|
|
448 |
|
|
case r.dstate is
|
449 |
|
|
when "000" => -- Idle state
|
450 |
|
|
v.nomds := r.nomds and not eholdn;
|
451 |
|
|
if (snoopval = '1') then v.valid := dcramov.dtramout(set).valid;
|
452 |
|
|
else v.valid := (others => '0'); end if;
|
453 |
|
|
if (r.stpend = '0') or ((mcdo.ready and not r.req)= '1') then -- wait for store queue
|
454 |
|
|
v.wb.addr := dci.maddress; v.wb.size := dci.size;
|
455 |
|
|
v.wb.read := dci.read; v.wb.data1 := dci.edata; v.wb.lock := dci.lock;
|
456 |
|
|
v.wb.asi := dci.asi(3 downto 0);
|
457 |
|
|
end if;
|
458 |
|
|
if (eholdn and (not r.nomds)) = '1' then -- avoid false path through nullify
|
459 |
|
|
if dci.asi(3 downto 0) = LASI_DTAG then rdatasel := dtag; end if;
|
460 |
|
|
if dci.asi(3 downto 0) = LASI_DDATA then rdatasel := dddata; end if;
|
461 |
|
|
end if;
|
462 |
|
|
if (dci.enaddr and eholdn and (not r.nomds) and not dci.nullify) = '1' then
|
463 |
|
|
case dci.asi(3 downto 0) is
|
464 |
|
|
when LASI_ITAG | LASI_IDATA => -- Read/write Icache tags
|
465 |
|
|
if ico.flush = '1' then mexc := '1';
|
466 |
|
|
else v.dstate := "101"; v.holdn := '0'; end if;
|
467 |
|
|
when LASI_IFLUSH => -- flush instruction cache
|
468 |
|
|
if dci.read = '0' then iflush := '1'; end if;
|
469 |
|
|
when LASI_DFLUSH => -- flush data cache
|
470 |
|
|
if dci.read = '0' then flush := '1'; end if;
|
471 |
|
|
when LASI_DDATA => -- Read/write Dcache data
|
472 |
|
|
if (dci.size /= "10") or (r.flush = '1') then -- only word access is allowed
|
473 |
|
|
mexc := '1';
|
474 |
|
|
elsif (dci.read = '0') then
|
475 |
|
|
dwrite := '1'; ddiagwrite := '1';
|
476 |
|
|
end if;
|
477 |
|
|
when LASI_DTAG => -- Read/write Dcache tags
|
478 |
|
|
if (dci.size /= "10") or (r.flush = '1') then -- allow only word access
|
479 |
|
|
mexc := '1';
|
480 |
|
|
elsif (dci.read = '0') then
|
481 |
|
|
twrite := '1'; tdiagwrite := '1';
|
482 |
|
|
end if;
|
483 |
|
|
when others =>
|
484 |
|
|
-- setrepl := std_logic_vector(conv_unsigned(set, SETBITS));
|
485 |
|
|
if dci.read = '1' then -- read access
|
486 |
|
|
if LOCAL_RAM and (lramen = '1') then
|
487 |
|
|
lramrd := '1';
|
488 |
|
|
elsif (not ((mcdo.dcs(0) = '1')
|
489 |
|
|
and ((hit and valid and not forcemiss) = '1')))
|
490 |
|
|
|
491 |
|
|
then -- read miss
|
492 |
|
|
v.holdn := '0'; v.dstate := "001";
|
493 |
|
|
if ((r.stpend = '0') or ((mcdo.ready and not r.req) = '1'))
|
494 |
|
|
then -- wait for store queue
|
495 |
|
|
v.req := '1';
|
496 |
|
|
v.burst := dci.size(1) and dci.size(0) and not dci.maddress(2);
|
497 |
|
|
end if;
|
498 |
|
|
else -- read hit
|
499 |
|
|
if (DSETS > 1) and (DCREPLACE = lru) then vl.write := '1'; end if;
|
500 |
|
|
end if;
|
501 |
|
|
|
502 |
|
|
else -- write access
|
503 |
|
|
if LOCAL_RAM and (lramen = '1') then
|
504 |
|
|
lramwr := '1'; lramrd := '1';
|
505 |
|
|
if (dci.size = "11") then v.dstate := "100"; end if; -- double store
|
506 |
|
|
elsif (r.stpend = '0') or ((mcdo.ready and not r.req)= '1') then -- wait for store queue
|
507 |
|
|
|
508 |
|
|
v.req := '1'; v.stpend := '1';
|
509 |
|
|
v.burst := dci.size(1) and dci.size(0);
|
510 |
|
|
|
511 |
|
|
if (dci.size = "11") then v.dstate := "100"; end if; -- double store
|
512 |
|
|
else -- wait for store queue
|
513 |
|
|
v.dstate := "110"; v.holdn := '0';
|
514 |
|
|
end if;
|
515 |
|
|
if (mcdo.dcs(0) = '1') and ((hit and (dci.size(1) or validraw)) = '1')
|
516 |
|
|
then -- write hit
|
517 |
|
|
|
518 |
|
|
twrite := '1'; dwrite := '1';
|
519 |
|
|
if (DSETS > 1) and (DCREPLACE = lru) then vl.write := '1'; end if;
|
520 |
|
|
setrepl := std_logic_vector(conv_unsigned(set, SETBITS));
|
521 |
|
|
end if;
|
522 |
|
|
if (dci.size = "11") then v.xaddress(2) := '1'; end if;
|
523 |
|
|
end if;
|
524 |
|
|
|
525 |
|
|
if (DSETS > 1) then
|
526 |
|
|
vl.set := std_logic_vector(conv_unsigned(set, SETBITS));
|
527 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(set, SETBITS));
|
528 |
|
|
if ((not hit) and (not r.flush)) = '1' then
|
529 |
|
|
case DCREPLACE is
|
530 |
|
|
when rnd =>
|
531 |
|
|
if DCLOCK_BIT = 1 then
|
532 |
|
|
if lock(conv_integer(r.rndcnt)) = '0' then v.setrepl := r.rndcnt;
|
533 |
|
|
else
|
534 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(DSETS-1, SETBITS));
|
535 |
|
|
for i in DSETS-1 downto 0 loop
|
536 |
|
|
if (lock(i) = '0') and (i>conv_integer(r.rndcnt)) then
|
537 |
|
|
v.setrepl := std_logic_vector(conv_unsigned(i, SETBITS));
|
538 |
|
|
end if;
|
539 |
|
|
end loop;
|
540 |
|
|
end if;
|
541 |
|
|
else
|
542 |
|
|
v.setrepl := r.rndcnt;
|
543 |
|
|
end if;
|
544 |
|
|
when lru =>
|
545 |
|
|
-- pragma translate_off
|
546 |
|
|
if not is_x(dci.maddress(OFFSET_HIGH downto OFFSET_LOW)) then
|
547 |
|
|
-- pragma translate_on
|
548 |
|
|
v.setrepl := lru_set(rl.lru(conv_integer(dci.maddress(OFFSET_HIGH downto OFFSET_LOW))), lock(0 to DSETS-1));
|
549 |
|
|
-- pragma translate_off
|
550 |
|
|
end if;
|
551 |
|
|
-- pragma translate_on
|
552 |
|
|
when lrr =>
|
553 |
|
|
v.setrepl := (others => '0');
|
554 |
|
|
if DCLOCK_BIT = 1 then
|
555 |
|
|
if lock(0) = '1' then v.setrepl(0) := '1';
|
556 |
|
|
else
|
557 |
|
|
v.setrepl(0) := dcramov.dtramout(0).lrr xor dcramov.dtramout(1).lrr;
|
558 |
|
|
end if;
|
559 |
|
|
else
|
560 |
|
|
v.setrepl(0) := dcramov.dtramout(0).lrr xor dcramov.dtramout(1).lrr;
|
561 |
|
|
end if;
|
562 |
|
|
if v.setrepl(0) = '0' then
|
563 |
|
|
v.lrr := not dcramov.dtramout(0).lrr;
|
564 |
|
|
else
|
565 |
|
|
v.lrr := dcramov.dtramout(0).lrr;
|
566 |
|
|
end if;
|
567 |
|
|
end case;
|
568 |
|
|
end if;
|
569 |
|
|
|
570 |
|
|
if (DCLOCK_BIT = 1) then
|
571 |
|
|
if (hit and lock(set)) = '1' then v.lock := '1';
|
572 |
|
|
else v.lock := '0'; end if;
|
573 |
|
|
end if;
|
574 |
|
|
|
575 |
|
|
end if;
|
576 |
|
|
|
577 |
|
|
end case;
|
578 |
|
|
end if;
|
579 |
|
|
|
580 |
|
|
when "001" => -- read miss, wait for memory data
|
581 |
|
|
taddr := r.xaddress(OFFSET_HIGH downto LINE_LOW);
|
582 |
|
|
newtag := r.xaddress(TAG_HIGH downto TAG_LOW);
|
583 |
|
|
v.nomds := r.nomds and not eholdn;
|
584 |
|
|
v.holdn := v.nomds; rdatasel := memory;
|
585 |
|
|
for i in 0 to DSETS-1 loop wlock(i) := r.lock; end loop;
|
586 |
|
|
for i in 0 to 1 loop wlrr(i) := r.lrr; end loop;
|
587 |
|
|
if r.stpend = '0' then
|
588 |
|
|
|
589 |
|
|
if mcdo.ready = '1' then
|
590 |
|
|
mds := r.holdn or r.nomds; v.xaddress(2) := '1'; v.holdn := '1';
|
591 |
|
|
if (mcdo.dcs = "01") then
|
592 |
|
|
v.hit := mcdo.cache and r.hit; twrite := v.hit;
|
593 |
|
|
elsif (mcdo.dcs(1) = '1') then
|
594 |
|
|
v.hit := mcdo.cache and (r.hit or not r.asi(2)); twrite := v.hit;
|
595 |
|
|
end if;
|
596 |
|
|
dwrite := twrite; rdatasel := memory;
|
597 |
|
|
mexc := mcdo.mexc;
|
598 |
|
|
|
599 |
|
|
if r.req = '0' then
|
600 |
|
|
|
601 |
|
|
if (((dci.enaddr and not mds) = '1') or
|
602 |
|
|
((dci.eenaddr and mds and eholdn) = '1')) and (mcdo.dcs(0) = '1') then
|
603 |
|
|
v.dstate := "011"; v.holdn := '0';
|
604 |
|
|
else v.dstate := "000"; end if;
|
605 |
|
|
else v.nomds := '1'; end if;
|
606 |
|
|
end if;
|
607 |
|
|
v.mexc := mcdo.mexc; v.wb.data2 := mcdo.data;
|
608 |
|
|
else
|
609 |
|
|
if ((mcdo.ready and not r.req) = '1') then -- wait for store queue
|
610 |
|
|
v.burst := r.size(1) and r.size(0) and not r.xaddress(2);
|
611 |
|
|
v.wb.addr := r.xaddress; v.wb.size := r.size;
|
612 |
|
|
v.wb.read := r.read; v.wb.data1 := dci.maddress; v.req := '1';
|
613 |
|
|
v.wb.lock := dci.lock; v.wb.asi := r.asi;
|
614 |
|
|
end if;
|
615 |
|
|
end if;
|
616 |
|
|
when "011" => -- return from read miss with load pending
|
617 |
|
|
taddr := dci.maddress(OFFSET_HIGH downto LINE_LOW);
|
618 |
|
|
v.dstate := "000";
|
619 |
|
|
when "100" => -- second part of double store cycle
|
620 |
|
|
v.dstate := "000";
|
621 |
|
|
edata := dci.edata; -- needed for STD store hit
|
622 |
|
|
taddr := r.xaddress(OFFSET_HIGH downto LINE_LOW);
|
623 |
|
|
if LOCAL_RAM then laddr := r.xaddress; end if;
|
624 |
|
|
if LOCAL_RAM and (r.xaddress(31 downto 24) = LOCAL_RAM_START) then
|
625 |
|
|
lramwr := '1';
|
626 |
|
|
else
|
627 |
|
|
if (mcdo.dcs(0) = '1') and (r.hit = '1') then dwrite := '1'; end if;
|
628 |
|
|
v.wb.data2 := dci.edata;
|
629 |
|
|
end if;
|
630 |
|
|
|
631 |
|
|
when "101" => -- icache diag access
|
632 |
|
|
rdatasel := icache; v.icenable := '1'; v.holdn := '0';
|
633 |
|
|
if ico.diagrdy = '1' then
|
634 |
|
|
v.dstate := "011"; v.icenable := '0'; mds := not r.read;
|
635 |
|
|
end if;
|
636 |
|
|
|
637 |
|
|
when "110" => -- wait for store buffer to empty (store access)
|
638 |
|
|
edata := dci.edata; -- needed for STD store hit
|
639 |
|
|
|
640 |
|
|
if ((mcdo.ready and not r.req) = '1') then -- store queue emptied
|
641 |
|
|
|
642 |
|
|
if (mcdo.dcs(0) = '1') and (r.hit = '1') and (r.size = "11") then -- write hit
|
643 |
|
|
taddr := r.xaddress(OFFSET_HIGH downto LINE_LOW); dwrite := '1';
|
644 |
|
|
end if;
|
645 |
|
|
v.dstate := "000";
|
646 |
|
|
|
647 |
|
|
v.req := '1'; v.burst := r.size(1) and r.size(0); v.stpend := '1';
|
648 |
|
|
|
649 |
|
|
v.wb.addr := r.xaddress; v.wb.size := r.size;
|
650 |
|
|
v.wb.read := r.read; v.wb.data1 := dci.maddress;
|
651 |
|
|
v.wb.lock := dci.lock; v.wb.data2 := dci.edata;
|
652 |
|
|
v.wb.asi := r.asi;
|
653 |
|
|
if r.size = "11" then v.wb.addr(2) := '0'; end if;
|
654 |
|
|
else -- hold cpu until buffer empty
|
655 |
|
|
v.holdn := '0';
|
656 |
|
|
end if;
|
657 |
|
|
when others => v.dstate := "000";
|
658 |
|
|
end case;
|
659 |
|
|
|
660 |
|
|
dsudata := (others => '0');
|
661 |
|
|
if DEBUG_UNIT and dci.dsuen = '1' then
|
662 |
|
|
if (DSETS > 1) then
|
663 |
|
|
-- pragma translate_off
|
664 |
|
|
if not is_x(r.xaddress) then
|
665 |
|
|
-- pragma translate_on
|
666 |
|
|
v.dsuset := r.xaddress(TAG_LOW+SETBITS-1 downto TAG_LOW);
|
667 |
|
|
-- pragma translate_off
|
668 |
|
|
end if;
|
669 |
|
|
if not is_x(r.dsuset) then
|
670 |
|
|
-- pragma translate_on
|
671 |
|
|
rdsuset := conv_integer(r.dsuset);
|
672 |
|
|
-- pragma translate_off
|
673 |
|
|
end if;
|
674 |
|
|
-- pragma translate_on
|
675 |
|
|
|
676 |
|
|
end if;
|
677 |
|
|
case dci.asi(3 downto 0) is
|
678 |
|
|
when LASI_ITAG | LASI_IDATA => -- Read/write Icache tags
|
679 |
|
|
v.icenable := not ico.diagrdy;
|
680 |
|
|
dsudata := ico.diagdata;
|
681 |
|
|
when LASI_DTAG =>
|
682 |
|
|
if dci.write = '1' then
|
683 |
|
|
twrite := not dci.eenaddr; tdiagwrite := '1';
|
684 |
|
|
end if;
|
685 |
|
|
dsudata(TAG_HIGH downto TAG_LOW) := dcramov.dtramout(rdsuset).tag;
|
686 |
|
|
dsudata(DLINE_SIZE -1 downto 0) := dcramov.dtramout(rdsuset).valid;
|
687 |
|
|
dsudata(DCTAG_LRRPOS) := dcramov.dtramout(rdsuset).lrr;
|
688 |
|
|
dsudata(DCTAG_LOCKPOS) := dcramov.dtramout(rdsuset).lock;
|
689 |
|
|
when LASI_DDATA =>
|
690 |
|
|
--if (dci.write and r.dsuwren) = '1' then dwrite := '1'; ddiagwrite := '1'; end if;
|
691 |
|
|
if (LOCAL_RAM) and (laddr(19 downto 16) = "1111") then
|
692 |
|
|
lramwr := dci.write and not dci.eenaddr;
|
693 |
|
|
v.lramrd := not lramwr; lramcs := '1';
|
694 |
|
|
elsif dci.write = '1' then
|
695 |
|
|
dwrite := not dci.eenaddr; ddiagwrite := '1';
|
696 |
|
|
end if;
|
697 |
|
|
dsudata := dcramov.ddramout(rdsuset).data;
|
698 |
|
|
when others =>
|
699 |
|
|
end case;
|
700 |
|
|
end if;
|
701 |
|
|
|
702 |
|
|
-- select data to return on read access
|
703 |
|
|
-- align if byte/half word read from cache or memory.
|
704 |
|
|
|
705 |
|
|
rdata := (others => '0'); rdatav := (others => (others => '0'));
|
706 |
|
|
align_data := (others => '0'); align_datav := (others => (others => '0'));
|
707 |
|
|
maddrlow := maddress(1 downto 0); -- stupid Synopsys VSS bug ...
|
708 |
|
|
|
709 |
|
|
case rdatasel is
|
710 |
|
|
when dddata =>
|
711 |
|
|
rdata := dcramov.ddramout(ddset).data;
|
712 |
|
|
when dtag =>
|
713 |
|
|
rdata(TAG_HIGH downto TAG_LOW) := dcramov.dtramout(ddset).tag;
|
714 |
|
|
rdata(DLINE_SIZE -1 downto 0) := dcramov.dtramout(ddset).valid;
|
715 |
|
|
rdata(DCTAG_LRRPOS) := dcramov.dtramout(ddset).lrr;
|
716 |
|
|
rdata(DCTAG_LOCKPOS) := dcramov.dtramout(ddset).lock;
|
717 |
|
|
when icache => rdata := ico.diagdata;
|
718 |
|
|
when ddata | memory =>
|
719 |
|
|
if DREAD_FAST then
|
720 |
|
|
if rdatasel = memory then
|
721 |
|
|
case size is
|
722 |
|
|
when "00" => -- byte read
|
723 |
|
|
case maddrlow is
|
724 |
|
|
when "00" =>
|
725 |
|
|
rdata(7 downto 0) := mcdo.data(31 downto 24);
|
726 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => mcdo.data(31)); end if;
|
727 |
|
|
when "01" =>
|
728 |
|
|
rdata(7 downto 0) := mcdo.data(23 downto 16);
|
729 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => mcdo.data(23)); end if;
|
730 |
|
|
when "10" =>
|
731 |
|
|
rdata(7 downto 0) := mcdo.data(15 downto 8);
|
732 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => mcdo.data(15)); end if;
|
733 |
|
|
when others =>
|
734 |
|
|
rdata(7 downto 0) := mcdo.data(7 downto 0);
|
735 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => mcdo.data(7)); end if;
|
736 |
|
|
end case;
|
737 |
|
|
when "01" => -- half-word read
|
738 |
|
|
if maddress(1) = '1' then
|
739 |
|
|
rdata(15 downto 0) := mcdo.data(15 downto 0);
|
740 |
|
|
if signed = '1' then rdata(31 downto 15) := (others => mcdo.data(15)); end if;
|
741 |
|
|
else
|
742 |
|
|
rdata(15 downto 0) := mcdo.data(31 downto 16);
|
743 |
|
|
if signed = '1' then rdata(31 downto 15) := (others => mcdo.data(31)); end if;
|
744 |
|
|
end if;
|
745 |
|
|
when others => -- single and double word read
|
746 |
|
|
rdata := mcdo.data;
|
747 |
|
|
end case;
|
748 |
|
|
else
|
749 |
|
|
rdata := (others => '0');
|
750 |
|
|
for i in 0 to DSETS-1 loop
|
751 |
|
|
case size is
|
752 |
|
|
when "00" => -- byte read
|
753 |
|
|
case maddrlow is
|
754 |
|
|
when "00" =>
|
755 |
|
|
rdatav(i)(7 downto 0) := dcramov.ddramout(i).data(31 downto 24);
|
756 |
|
|
if signed = '1' then rdatav(i)(31 downto 8) := (others => dcramov.ddramout(i).data(31)); end if;
|
757 |
|
|
when "01" =>
|
758 |
|
|
rdatav(i)(7 downto 0) := dcramov.ddramout(i).data(23 downto 16);
|
759 |
|
|
if signed = '1' then rdatav(i)(31 downto 8) := (others => dcramov.ddramout(i).data(23)); end if;
|
760 |
|
|
when "10" =>
|
761 |
|
|
rdatav(i)(7 downto 0) := dcramov.ddramout(i).data(15 downto 8);
|
762 |
|
|
if signed = '1' then rdatav(i)(31 downto 8) := (others => dcramov.ddramout(i).data(15)); end if;
|
763 |
|
|
when others =>
|
764 |
|
|
rdatav(i)(7 downto 0) := dcramov.ddramout(i).data(7 downto 0);
|
765 |
|
|
if signed = '1' then rdatav(i)(31 downto 8) := (others => dcramov.ddramout(i).data(7)); end if;
|
766 |
|
|
end case;
|
767 |
|
|
when "01" => -- half-word read
|
768 |
|
|
if maddress(1) = '1' then
|
769 |
|
|
rdatav(i)(15 downto 0) := dcramov.ddramout(i).data(15 downto 0);
|
770 |
|
|
if signed = '1' then rdatav(i)(31 downto 15) := (others => dcramov.ddramout(i).data(15)); end if;
|
771 |
|
|
else
|
772 |
|
|
rdatav(i)(15 downto 0) := dcramov.ddramout(i).data(31 downto 16);
|
773 |
|
|
if signed = '1' then rdatav(i)(31 downto 15) := (others => dcramov.ddramout(i).data(31)); end if;
|
774 |
|
|
end if;
|
775 |
|
|
when others => -- single and double word read
|
776 |
|
|
rdatav(i) := dcramov.ddramout(i).data;
|
777 |
|
|
end case;
|
778 |
|
|
if validrawv(i) = '1' then rdata := rdata or rdatav(i); end if;
|
779 |
|
|
end loop;
|
780 |
|
|
end if;
|
781 |
|
|
else
|
782 |
|
|
if rdatasel = ddata then align_data := dcramov.ddramout(set).data;
|
783 |
|
|
else align_data := mcdo.data; end if;
|
784 |
|
|
case size is
|
785 |
|
|
when "00" => -- byte read
|
786 |
|
|
case maddrlow is
|
787 |
|
|
when "00" =>
|
788 |
|
|
rdata(7 downto 0) := align_data(31 downto 24);
|
789 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => align_data(31)); end if;
|
790 |
|
|
when "01" =>
|
791 |
|
|
rdata(7 downto 0) := align_data(23 downto 16);
|
792 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => align_data(23)); end if;
|
793 |
|
|
when "10" =>
|
794 |
|
|
rdata(7 downto 0) := align_data(15 downto 8);
|
795 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => align_data(15)); end if;
|
796 |
|
|
when others =>
|
797 |
|
|
rdata(7 downto 0) := align_data(7 downto 0);
|
798 |
|
|
if signed = '1' then rdata(31 downto 8) := (others => align_data(7)); end if;
|
799 |
|
|
end case;
|
800 |
|
|
when "01" => -- half-word read
|
801 |
|
|
if maddress(1) = '1' then
|
802 |
|
|
rdata(15 downto 0) := align_data(15 downto 0);
|
803 |
|
|
if signed = '1' then rdata(31 downto 15) := (others => align_data(15)); end if;
|
804 |
|
|
else
|
805 |
|
|
rdata(15 downto 0) := align_data(31 downto 16);
|
806 |
|
|
if signed = '1' then rdata(31 downto 15) := (others => align_data(31)); end if;
|
807 |
|
|
end if;
|
808 |
|
|
when others => -- single and double word read
|
809 |
|
|
rdata := align_data;
|
810 |
|
|
end case;
|
811 |
|
|
end if;
|
812 |
|
|
end case;
|
813 |
|
|
|
814 |
|
|
-- select which data to update the data cache with
|
815 |
|
|
|
816 |
|
|
if DWRITE_FAST then
|
817 |
|
|
for i in 0 to DSETS-1 loop
|
818 |
|
|
case size is -- merge data during partial write
|
819 |
|
|
when "00" =>
|
820 |
|
|
case maddrlow is
|
821 |
|
|
when "00" =>
|
822 |
|
|
ddatainv(i) := edata(7 downto 0) & dcramov.ddramout(i).data(23 downto 0);
|
823 |
|
|
when "01" =>
|
824 |
|
|
ddatainv(i) := dcramov.ddramout(i).data(31 downto 24) & edata(7 downto 0) &
|
825 |
|
|
dcramov.ddramout(i).data(15 downto 0);
|
826 |
|
|
when "10" =>
|
827 |
|
|
ddatainv(i) := dcramov.ddramout(i).data(31 downto 16) & edata(7 downto 0) &
|
828 |
|
|
dcramov.ddramout(i).data(7 downto 0);
|
829 |
|
|
when others =>
|
830 |
|
|
ddatainv(i) := dcramov.ddramout(i).data(31 downto 8) & edata(7 downto 0);
|
831 |
|
|
end case;
|
832 |
|
|
when "01" =>
|
833 |
|
|
if maddress(1) = '0' then
|
834 |
|
|
ddatainv(i) := edata(15 downto 0) & dcramov.ddramout(i).data(15 downto 0);
|
835 |
|
|
else
|
836 |
|
|
ddatainv(i) := dcramov.ddramout(i).data(31 downto 16) & edata(15 downto 0);
|
837 |
|
|
end if;
|
838 |
|
|
when others =>
|
839 |
|
|
ddatainv(i) := edata;
|
840 |
|
|
end case;
|
841 |
|
|
|
842 |
|
|
end loop;
|
843 |
|
|
ddatain := ddatainv(set);
|
844 |
|
|
|
845 |
|
|
else
|
846 |
|
|
case size is -- merge data during partial write
|
847 |
|
|
when "00" =>
|
848 |
|
|
case maddrlow is
|
849 |
|
|
when "00" =>
|
850 |
|
|
ddatain := edata(7 downto 0) & dcramov.ddramout(set).data(23 downto 0);
|
851 |
|
|
when "01" =>
|
852 |
|
|
ddatain := dcramov.ddramout(set).data(31 downto 24) & edata(7 downto 0) &
|
853 |
|
|
dcramov.ddramout(set).data(15 downto 0);
|
854 |
|
|
when "10" =>
|
855 |
|
|
ddatain := dcramov.ddramout(set).data(31 downto 16) & edata(7 downto 0) &
|
856 |
|
|
dcramov.ddramout(set).data(7 downto 0);
|
857 |
|
|
when others =>
|
858 |
|
|
ddatain := dcramov.ddramout(set).data(31 downto 8) & edata(7 downto 0);
|
859 |
|
|
end case;
|
860 |
|
|
when "01" =>
|
861 |
|
|
if maddress(1) = '0' then
|
862 |
|
|
ddatain := edata(15 downto 0) & dcramov.ddramout(set).data(15 downto 0);
|
863 |
|
|
else
|
864 |
|
|
ddatain := dcramov.ddramout(set).data(31 downto 16) & edata(15 downto 0);
|
865 |
|
|
end if;
|
866 |
|
|
when others =>
|
867 |
|
|
ddatain := edata;
|
868 |
|
|
end case;
|
869 |
|
|
|
870 |
|
|
end if;
|
871 |
|
|
|
872 |
|
|
-- handle double load with pipeline hold
|
873 |
|
|
|
874 |
|
|
if (r.dstate = "000") and (r.nomds = '1') then
|
875 |
|
|
rdata := r.wb.data2; mexc := r.mexc;
|
876 |
|
|
end if;
|
877 |
|
|
|
878 |
|
|
-- Handle AHB retry. Re-generate bus request and burst
|
879 |
|
|
|
880 |
|
|
if mcdo.retry = '1' then
|
881 |
|
|
v.req := '1';
|
882 |
|
|
v.burst := r.wb.size(0) and r.wb.size(1) and not r.wb.addr(2);
|
883 |
|
|
end if;
|
884 |
|
|
|
885 |
|
|
-- Generate new valid bits
|
886 |
|
|
|
887 |
|
|
vmaskdbl := decode(maddress(LINE_HIGH downto LINE_LOW+1));
|
888 |
|
|
if (size = "11") and (read = '0') then
|
889 |
|
|
for i in 0 to (DLINE_SIZE - 1) loop vmaskraw(i) := vmaskdbl(i/2); end loop;
|
890 |
|
|
else
|
891 |
|
|
vmaskraw := decode(maddress(LINE_HIGH downto LINE_LOW));
|
892 |
|
|
end if;
|
893 |
|
|
|
894 |
|
|
vmask := vmaskraw;
|
895 |
|
|
if r.hit = '1' then vmask := r.valid or vmaskraw; end if;
|
896 |
|
|
if r.dstate = "000" then
|
897 |
|
|
-- vmask := dcramov.dtramout(set).valid or vmaskraw;
|
898 |
|
|
vmask := ivalid or vmaskraw;
|
899 |
|
|
|
900 |
|
|
end if;
|
901 |
|
|
|
902 |
|
|
if (mcdo.mexc or r.flush) = '1' then twrite := '0'; dwrite := '0'; end if;
|
903 |
|
|
if twrite = '1' then
|
904 |
|
|
v.valid := vmask;
|
905 |
|
|
if (DSETS>1) and (DCREPLACE = lru) and (tdiagwrite = '0') then
|
906 |
|
|
vl.write := '1'; vl.set := setrepl;
|
907 |
|
|
end if;
|
908 |
|
|
end if;
|
909 |
|
|
|
910 |
|
|
if (DSETS>1) and (DCREPLACE = lru) and (rl.write = '1') then
|
911 |
|
|
vl.lru(conv_integer(rl.waddr)) :=
|
912 |
|
|
lru_calc(rl.lru(conv_integer(rl.waddr)), conv_integer(rl.set));
|
913 |
|
|
end if;
|
914 |
|
|
|
915 |
|
|
if tdiagwrite = '1' then -- diagnostic tag write
|
916 |
|
|
if DEBUG_UNIT and (dci.dsuen = '1') then
|
917 |
|
|
vmask := dci.maddress(DLINE_SIZE - 1 downto 0);
|
918 |
|
|
else
|
919 |
|
|
vmask := dci.edata(DLINE_SIZE - 1 downto 0);
|
920 |
|
|
newtag(TAG_HIGH downto TAG_LOW) := dci.edata(TAG_HIGH downto TAG_LOW);
|
921 |
|
|
for i in 0 to 1 loop wlrr(i) := dci.edata(DCTAG_LRRPOS); end loop;
|
922 |
|
|
for i in 0 to DSETS-1 loop wlock(i) := dci.edata(DCTAG_LOCKPOS); end loop;
|
923 |
|
|
end if;
|
924 |
|
|
end if;
|
925 |
|
|
|
926 |
|
|
-- cache flush
|
927 |
|
|
|
928 |
|
|
if (dci.flush or flush or mcdo.dflush) = '1' then
|
929 |
|
|
v.flush := '1'; v.faddr := (others => '0');
|
930 |
|
|
end if;
|
931 |
|
|
|
932 |
|
|
if r.flush = '1' then
|
933 |
|
|
twrite := '1'; vmask := (others => '0'); v.faddr := r.faddr +1;
|
934 |
|
|
newtag(TAG_HIGH downto TAG_LOW) := (others => '0');
|
935 |
|
|
taddr(OFFSET_HIGH downto OFFSET_LOW) := r.faddr;
|
936 |
|
|
wlrr := (others => '0');
|
937 |
|
|
if (r.faddr(DOFFSET_BITS -1) and not v.faddr(DOFFSET_BITS -1)) = '1' then
|
938 |
|
|
v.flush := '0';
|
939 |
|
|
end if;
|
940 |
|
|
end if;
|
941 |
|
|
|
942 |
|
|
-- AHB snoop handling (2), bypass write data on read/write contention
|
943 |
|
|
|
944 |
|
|
if DSNOOP then
|
945 |
|
|
-- pragma translate_off
|
946 |
|
|
if not is_x(setrepl) then
|
947 |
|
|
-- pragma translate_on
|
948 |
|
|
if tdiagwrite = '1' then snoopset2 := ddset;
|
949 |
|
|
else snoopset2 := conv_integer(setrepl); end if;
|
950 |
|
|
-- pragma translate_off
|
951 |
|
|
end if;
|
952 |
|
|
-- pragma translate_on
|
953 |
|
|
if DSNOOP_FAST then
|
954 |
|
|
vh.taddr := taddr(OFFSET_HIGH downto OFFSET_LOW);
|
955 |
|
|
vh.set := std_logic_vector(conv_unsigned(set, SETBITS));
|
956 |
|
|
if twrite = '1' then
|
957 |
|
|
-- pragma translate_off
|
958 |
|
|
if not is_x(taddr(OFFSET_HIGH downto OFFSET_LOW)) then
|
959 |
|
|
-- pragma translate_on
|
960 |
|
|
vh.hit(conv_integer(taddr(OFFSET_HIGH downto OFFSET_LOW)))(snoopset2) := '0';
|
961 |
|
|
-- pragma translate_off
|
962 |
|
|
end if;
|
963 |
|
|
-- pragma translate_on
|
964 |
|
|
end if;
|
965 |
|
|
else
|
966 |
|
|
if rs.addr(OFFSET_HIGH downto OFFSET_LOW) =
|
967 |
|
|
taddr(OFFSET_HIGH downto OFFSET_LOW)
|
968 |
|
|
then
|
969 |
|
|
if twrite = '0' then
|
970 |
|
|
if snoopwe = '1' then vs.writebp(snoopset) := '1'; end if;
|
971 |
|
|
else
|
972 |
|
|
if (snoopwe = '1') and (conv_integer(setrepl) = snoopset)
|
973 |
|
|
then twrite := '0'; end if; -- avoid write/write contention
|
974 |
|
|
end if;
|
975 |
|
|
end if;
|
976 |
|
|
end if;
|
977 |
|
|
end if;
|
978 |
|
|
|
979 |
|
|
-- update cache with memory data during read miss
|
980 |
|
|
|
981 |
|
|
if read = '1' then ddatain := mcdo.data; end if;
|
982 |
|
|
|
983 |
|
|
-- cache write signals
|
984 |
|
|
|
985 |
|
|
if twrite = '1' then
|
986 |
|
|
if tdiagwrite = '1' then ctwrite(ddset) := '1';
|
987 |
|
|
else ctwrite(conv_integer(setrepl)) := '1'; end if;
|
988 |
|
|
end if;
|
989 |
|
|
if dwrite = '1' then
|
990 |
|
|
if ddiagwrite = '1' then cdwrite(ddset) := '1';
|
991 |
|
|
else cdwrite(conv_integer(setrepl)) := '1'; end if;
|
992 |
|
|
end if;
|
993 |
|
|
|
994 |
|
|
csnoopwe := (others => '0'); if (snoopwe = '1') then csnoopwe(snoopset) := '1'; end if;
|
995 |
|
|
|
996 |
|
|
if (r.flush and twrite) = '1' then -- flush
|
997 |
|
|
ctwrite := (others => '1'); wlrr := (others => '0'); wlock := (others => '0');
|
998 |
|
|
end if;
|
999 |
|
|
|
1000 |
|
|
if (r.flush or (not rst)) = '1' then
|
1001 |
|
|
vl.lru := (others => (others => '0'));
|
1002 |
|
|
end if;
|
1003 |
|
|
|
1004 |
|
|
|
1005 |
|
|
-- reset
|
1006 |
|
|
|
1007 |
|
|
if rst = '0' then
|
1008 |
|
|
v.dstate := "000"; v.stpend := '0'; v.req := '0'; v.burst := '0';
|
1009 |
|
|
v.read := '0'; v.flush := '0'; v.nomds := '0';
|
1010 |
|
|
v.rndcnt := (others => '0'); v.setrepl := (others => '0');
|
1011 |
|
|
v.dsuset := (others => '0');
|
1012 |
|
|
v.lrr := '0'; v.lock := '0';
|
1013 |
|
|
end if;
|
1014 |
|
|
|
1015 |
|
|
|
1016 |
|
|
-- Drive signals
|
1017 |
|
|
|
1018 |
|
|
c <= v; cs <= vs; ch <= vh; -- register inputs
|
1019 |
|
|
cl <= vl;
|
1020 |
|
|
|
1021 |
|
|
|
1022 |
|
|
-- tag ram inputs
|
1023 |
|
|
dcrami.dtramin.valid <= vmask;
|
1024 |
|
|
dcrami.dtramin.tag <= newtag(TAG_HIGH downto TAG_LOW);
|
1025 |
|
|
dcrami.dtramin.lrr <= wlrr;
|
1026 |
|
|
dcrami.dtramin.lock <= wlock;
|
1027 |
|
|
dcrami.dtramin.enable <= enable;
|
1028 |
|
|
dcrami.dtramin.write <= ctwrite;
|
1029 |
|
|
dcrami.dtramin.flush <= r.flush;
|
1030 |
|
|
dcrami.dtraminsn.enable <= vs.snoop or rs.snoop;
|
1031 |
|
|
dcrami.dtraminsn.write <= csnoopwe;
|
1032 |
|
|
dcrami.dtraminsn.address<= snoopaddr;
|
1033 |
|
|
dcrami.dtraminsn.tag <= rs.addr(TAG_HIGH downto TAG_LOW);
|
1034 |
|
|
|
1035 |
|
|
-- data ram inputs
|
1036 |
|
|
dcrami.ddramin.enable <= enable;
|
1037 |
|
|
dcrami.ddramin.address <= taddr;
|
1038 |
|
|
dcrami.ddramin.data <= ddatain;
|
1039 |
|
|
dcrami.ddramin.write <= cdwrite;
|
1040 |
|
|
dcrami.ldramin.address <= laddr(LOCAL_RAM_BITS+1 downto 2);
|
1041 |
|
|
dcrami.ldramin.enable <= lramcs or lramwr;
|
1042 |
|
|
dcrami.ldramin.read <= r.lramrd or lramrd;
|
1043 |
|
|
dcrami.ldramin.write <= lramwr;
|
1044 |
|
|
|
1045 |
|
|
-- memory controller inputs
|
1046 |
|
|
mcdi.address <= r.wb.addr;
|
1047 |
|
|
mcdi.data <= r.wb.data1;
|
1048 |
|
|
mcdi.burst <= r.burst;
|
1049 |
|
|
mcdi.size <= r.wb.size;
|
1050 |
|
|
mcdi.read <= r.wb.read;
|
1051 |
|
|
mcdi.asi <= r.wb.asi;
|
1052 |
|
|
mcdi.lock <= r.wb.lock or dci.lock;
|
1053 |
|
|
mcdi.req <= r.req;
|
1054 |
|
|
mcdi.flush <= r.flush;
|
1055 |
|
|
|
1056 |
|
|
-- diagnostic instruction cache access
|
1057 |
|
|
dco.icdiag.flush <= iflush or mcdo.iflush;
|
1058 |
|
|
dco.icdiag.read <= read;
|
1059 |
|
|
dco.icdiag.tag <= not r.asi(0);
|
1060 |
|
|
dco.icdiag.addr <= r.xaddress;
|
1061 |
|
|
dco.icdiag.enable <= r.icenable;
|
1062 |
|
|
dco.dsudata <= dsudata; -- debug unit
|
1063 |
|
|
|
1064 |
|
|
-- IU data cache inputs
|
1065 |
|
|
dco.data <= rdata;
|
1066 |
|
|
dco.mexc <= mexc;
|
1067 |
|
|
dco.hold <= r.holdn;
|
1068 |
|
|
dco.mds <= mds;
|
1069 |
|
|
dco.werr <= mcdo.werr;
|
1070 |
|
|
|
1071 |
|
|
end process;
|
1072 |
|
|
|
1073 |
|
|
-- Local registers
|
1074 |
|
|
|
1075 |
|
|
reg1 : process(clk)
|
1076 |
|
|
begin if rising_edge(clk ) then r <= c; end if; end process;
|
1077 |
|
|
sn2 : if DSNOOP generate
|
1078 |
|
|
reg2 : process(clk)
|
1079 |
|
|
begin if rising_edge(clk ) then rs <= cs; end if; end process;
|
1080 |
|
|
end generate;
|
1081 |
|
|
sn3 : if DSNOOP_FAST generate
|
1082 |
|
|
reg3 : process(clk)
|
1083 |
|
|
begin if rising_edge(clk ) then rh <= ch; end if; end process;
|
1084 |
|
|
end generate;
|
1085 |
|
|
|
1086 |
|
|
reg2 : if (DSETS>1) and (DCREPLACE = lru) generate
|
1087 |
|
|
reg2 : process(clk)
|
1088 |
|
|
begin if rising_edge(clk ) then rl <= cl; end if; end process;
|
1089 |
|
|
end generate;
|
1090 |
|
|
|
1091 |
|
|
|
1092 |
|
|
-- pragma translate_off
|
1093 |
|
|
chk : process
|
1094 |
|
|
begin
|
1095 |
|
|
assert not ((DSETS > 2) and (DCREPLACE = lrr)) report
|
1096 |
|
|
"Wrong data cache configuration detected: LRR replacement requires 2 sets"
|
1097 |
|
|
severity failure;
|
1098 |
|
|
wait;
|
1099 |
|
|
end process;
|
1100 |
|
|
-- pragma translate_on
|
1101 |
|
|
|
1102 |
|
|
end ;
|
1103 |
|
|
|