OpenCores
URL https://opencores.org/ocsvn/mytwoqcache/mytwoqcache/trunk

Subversion Repositories mytwoqcache

[/] [mytwoqcache/] [trunk/] [2QCache.vhd] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 gerhardhoh
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    07:41:47 12/14/2010 
6
-- Design Name: 
7
-- Module Name:    Cache - Rtl 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE, work;
21
use IEEE.std_logic_1164.all;
22
use IEEE.std_logic_arith.all;
23
use work.global.all;
24
 
25
---- Uncomment the following library declaration if instantiating
26
---- any Xilinx primitives in this code.
27
--library UNISIM;
28
--use UNISIM.VComponents.all;
29
 
30
entity Cache is
31
  generic( constant blocksizeld: integer := 11;
32
                          constant ldways: integer := 1;
33
                          constant ldCachedWords: integer := 2);
34
  port( nReset: in std_ulogic;                                          -- System reset active low
35
        Clock: in std_ulogic;                                           -- System Clock
36 10 gerhardhoh
                  AddressIn: in std_ulogic_vector(RAMrange'high + 1 downto 0);    -- Address of memory fetch
37 11 gerhardhoh
                  DataIn: in std_ulogic_vector( 31 downto 0);                     -- Data to write
38
             IOCode: in std_ulogic_vector(2 downto 0);                                           -- operation
39 10 gerhardhoh
                                                                                  -- Bit
40
                                                                                                                                                                                                --  2    0 read
41
                                                                                                                                                                                                --       1 write
42
                                                                                                                                                                                                -- 1 0   11 word
43
                                                                                                                                                                                                --       10 halfword
44
                                                                                                                                                                                                --       01 single byte
45 11 gerhardhoh
                                                                                                                                                                                                --       00 no operation
46
                  DataOut: out std_ulogic_vector( 31 downto 0);                   -- Data read
47 10 gerhardhoh
                  done: out std_ulogic;
48 11 gerhardhoh
                  -- memory interface
49
                  AddressOut: out std_ulogic_vector(RAMrange'high downto 0);        -- memory address
50
                  DataBlockIn: in std_ulogic_vector( 2 ** ldCachedWords * 32 - 1 downto 0);   -- data from memory
51
                  reads: out std_ulogic;                                                      -- read memory
52
                  DataBlockOut: out std_ulogic_vector( 2 ** ldCachedWords * 32 - 1 downto 0); -- data to memory
53
                  Mask: out std_ulogic_vector( 2 ** ldCachedWords * 4 - 1 downto 0);          -- enables for each byte active low
54 10 gerhardhoh
                  writes: out std_ulogic;                                                     -- write memory
55 11 gerhardhoh
                  ack: in std_ulogic                                                          -- acknowledge from memory
56
                );
57
end Cache;
58
 
59 10 gerhardhoh
architecture Rtl of Cache is
60
constant ways: integer := 2 ** ldways;
61
constant ldram: integer := blocksizeld + ldways - 1;
62
constant ldqueuelength: integer := ldram;
63
 
64 11 gerhardhoh
type IOType is ( Start, busy);
65
type tType is ( inittag, startt, startt1, tagtest, tagwait, stateget, stateget1, finish, finished);
66 18 gerhardhoh
type rType is ( raminit, ramstart, ramread, ramread1, ramupdate,
67 11 gerhardhoh
                ramupdate1, ramupdate2, ramupdate3, ramflush, ramflush1, ramwait, ramwait1, ramclean, ramclean1);
68
type fType is ( queuestart, queuewait, queuewaitAm1, queuewaitAm2, queuewaitA11, queuewaitA12, queueelim);
69
subtype myint is natural range 15 downto 0;
70
type TagRAMType is record
71
  cacheAddr: std_ulogic_vector( ldram - 1 downto 0);
72
  cacheValid: std_ulogic;
73
  Tag: std_ulogic_vector( RAMrange'high downto 2 + ldCachedWords + blocksizeld);
74
  TagValid: std_ulogic;
75 10 gerhardhoh
end record;
76
type WordType is record
77 11 gerhardhoh
  Word: std_ulogic_vector(31 downto 0);
78 10 gerhardhoh
  Modified: std_ulogic_vector( 3 downto 0);
79
end record;
80 11 gerhardhoh
type WordArray is array ( 2 ** ldCachedWords - 1 downto 0) of WordType;
81
type CacheType is record
82 10 gerhardhoh
  Words: WordArray;
83
  FiFoaddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
84 11 gerhardhoh
  Am: std_ulogic;                                                        -- redifined and renamed
85
end record;
86 10 gerhardhoh
type FiFoType is record
87
  Word: std_ulogic_vector( blocksizeld - 1 downto 0);
88
  way: std_ulogic_vector( ldways downto 0);
89
  valid: std_ulogic;
90
end record;
91
 
92
type TagRAMarray is array ( ways - 1 downto 0) of TagRAMType;
93
type TagBuffer is array ( ways - 1 downto 0) of std_ulogic_vector( RAMrange'high - ldCachedWords - blocksizeld - 2 + ldram + 2 downto 0);
94
type TagFile is array ( 2 ** blocksizeld - 1 downto 0) of std_ulogic_vector( RAMrange'high - ldCachedWords - blocksizeld - 2 + ldram + 2 downto 0);
95
type TagFiles is array ( ways - 1 downto 0) of TagFile;
96
 
97
type RAMFile is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( 35 downto 0);
98
type RAMFiles is array ( 2 ** ldCachedWords - 1 downto 0) of RAMFile;
99
type RAMBuffer is array ( 2 ** ldCachedWords - 1 downto 0) of std_ulogic_vector( 35 downto 0);
100 11 gerhardhoh
type AFile is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( ldqueuelength downto 0); -- redimensioned
101 10 gerhardhoh
 
102
type myarrayf is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( ldram - 1 downto 0);
103
type myarrayA is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
104
 
105
signal RAMs: RAMFiles;
106
signal Ax: AFile;
107 11 gerhardhoh
signal tagRAM: TagFiles;
108 10 gerhardhoh
signal tagdummy, tagBuff, TagRAMIn, TagRAMOut: TagRAMarray;
109
signal RecBuff, CacheIn, CacheOut: CacheType;
110
signal blockIn, blockOut: WordArray;
111
signal DataInh: std_ulogic_vector( 31 downto 0);
112
signal A1In, A1Out, AmIn, AmOut: FiFoType;
113
signal putA1, removeA1, getA1, emptyA1, fullA1: std_ulogic;
114
signal putAm, removeAm, getAm, emptyAm, fullAm: std_ulogic;
115
signal A1Inaddr, A1Outaddr, AmInaddr, AmOutaddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
116
signal emptyf, getf, putf: std_ulogic;
117 11 gerhardhoh
signal cindex, FreeOut, FreeIn: std_ulogic_vector( ldram - 1 downto 0);
118
signal ramf: myarrayf;
119
signal counterf: unsigned( ldram downto 0);
120 10 gerhardhoh
signal firstf, lastf: unsigned( ldram - 1 downto 0);
121
signal newFiFoAddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
122 11 gerhardhoh
signal newAm: std_ulogic;  -- redifined and renamed
123 10 gerhardhoh
signal initcount: unsigned( blocksizeld - 1 downto 0);
124
signal initcount1: unsigned( ldram - 1 downto 0);
125 11 gerhardhoh
signal ramA1: myarrayA;
126
signal counterA1: unsigned( ldqueuelength downto 0);
127
signal firstA1, lastA1: unsigned( ldqueuelength - 1 downto 0);
128
signal ramAm: myarrayA;
129
signal counterAm: unsigned( ldqueuelength downto 0);
130
signal firstAm, lastAm: unsigned( ldqueuelength - 1 downto 0);
131 10 gerhardhoh
 
132
signal AddressInh: std_ulogic_vector( AddressIn'high -1 downto 0);
133 11 gerhardhoh
signal IOCodeh: std_ulogic_vector( IOCode'range);
134
signal toFlush, AddressInt: std_ulogic_vector( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
135
signal found, free, elim, del: myint;
136 10 gerhardhoh
signal stateIO: IOType;
137
signal statetag: tType;
138
signal stateram: rType;
139
signal statequeue: fType;
140 22 gerhardhoh
signal enableram, enablequeue, queuedone, readsh, writesh, doneh, preempted, isfull, flag, flag1,
141 13 gerhardhoh
       interrupt, readb, writeb, writec, writet, accdone, accqueue, accinterrupt, serviced, oldint: std_ulogic;
142 15 gerhardhoh
signal gal: std_ulogic_vector( 7 downto 0);
143 11 gerhardhoh
 
144
begin
145 10 gerhardhoh
 
146 11 gerhardhoh
 
147
 
148 10 gerhardhoh
  blockIO: process( nReset, Clock, readb, writeb) is
149
  variable s: std_ulogic;
150
  begin
151
    if nReset /= '1' then
152
           writesh <= '0';
153
                readsh <= '0';
154
                stateIO <= start;
155
    elsif rising_edge(Clock) then
156
           case stateIO is
157
                when start =>
158
                  if readb = '1' then
159
                         Mask <= ( others => '1');
160
                         readsh <= '1';
161
                    stateIO <= busy;
162
                  elsif writeb = '1' then
163
                    s := '0';
164
 
165
                    for i in blockOut'range loop
166
                      DataBlockOut( ( i + 1) * 32 - 1 downto i * 32) <= blockOut( i).word;
167
                           Mask( ( i + 1) * 4 - 1 downto i * 4) <= not blockOut( i).Modified;
168
                                s := s or blockOut( i).Modified(0) or blockOut( i).Modified(1) or
169
                                          blockOut( i).Modified(2) or blockOut( i).Modified(3);
170
                         end loop;
171
 
172
                         writesh <= s;
173
 
174
                         if s = '1' then
175
                      stateIO <= busy;
176
                         end if;
177
                  end if;
178
                when busy =>
179
                  if ack = '1' then
180
                    stateIO <= start;
181
 
182
                    if readsh = '1' then
183
                           for i in blockIn'range loop
184
                        blockIn( i).word <= DataBlockIn( ( i + 1) * 32 - 1 downto i * 32);
185
                                  blockIn( i).Modified <= ( others => '0');
186
                                end loop;
187
                    end if;
188
 
189
                    readsh <= '0';
190
                    writesh <= '0';
191
                  end if;
192
                end case;
193
         end if;
194
  end process blockIO;
195
 
196
  writes <= writesh;
197
  reads <= readsh;
198
 
199
  tagrams: process ( nReset, Clock) is
200
  variable a, b, d: myint;
201 11 gerhardhoh
  variable DataInTag, DataOutTag: TagBuffer;
202 10 gerhardhoh
  begin
203
  if rising_edge(Clock) then
204
    if nReset /= '1' then
205
           statetag <= inittag;
206
                writet <= '0';
207
                enableram <= '0';
208 13 gerhardhoh
           oldint <= '0';
209 10 gerhardhoh
                found <= 15;
210
                free <= 15;
211
                done <= '0'; -- NEW
212
                initcount <= ( others => '0');
213
                AddressInt <= ( others => '0');
214
                IOCodeh <= ( others => '0');
215
                AddressInh <= ( others => '0');
216 15 gerhardhoh
           gal <= ( others => '1');
217 10 gerhardhoh
         else
218 15 gerhardhoh
            gal <= gal( 6 downto 4) & ( gal( 3) xor gal( 7)) & ( gal( 2) xor gal( 7)) & ( gal( 1) xor gal( 7)) & gal( 0) & gal( 7);
219 13 gerhardhoh
         oldint <= interrupt;
220 10 gerhardhoh
           case statetag is
221
                  when inittag =>
222
                    for i in tagRAMIn'range loop
223
                           tagRAMIn(i).tagValid <= '0';
224
                           tagRAMIn(i).tag <= ( others => '0');
225
                           tagRAMIn(i).cacheValid <= '0';
226
                           tagRAMIn(i).cacheAddr <= ( others => '0');
227
                         end loop;
228
                         AddressInt <= std_ulogic_vector(initcount);
229
                         initcount <= initcount + 1;
230
                         if unsigned( not AddressInt) = 0 then
231
                      statetag <= startt;
232
                           writet <= '0';
233
                         else
234
                           writet <= '1';
235
                         end if;
236
                  when startt =>
237
                    if IOCode( 1 downto 0) /= "00" and AddressIn( AddressIn'high) = '0' then
238
                      -- request encountered
239
                                AddressInh <= AddressIn(AddressInh'range);
240 11 gerhardhoh
                                IOCodeh <= IOCode;
241 10 gerhardhoh
                      AddressInt <= AddressIn( AddressInt'range);
242
                                DataInh <= DataIn;
243
                      statetag <= startt1;
244
                    end if;
245
                  when startt1 =>
246
                    statetag <= tagtest;
247
                  when tagtest =>
248 11 gerhardhoh
          a := 15;
249 10 gerhardhoh
                    b := 15;
250 11 gerhardhoh
 
251
               for i in 0 to TagRAMarray'high loop
252
                      if tagRAMOut( i).tagValid = '1' then
253
                   if AddressInh(tagRAMout( i).tag'range) = tagRAMout( i).tag then
254 10 gerhardhoh
                          a := i; -- present
255 11 gerhardhoh
                                  end if;
256
                      else
257
                             b := i; -- free entry
258
                      end if;
259
               end loop;
260 10 gerhardhoh
 
261 11 gerhardhoh
                    found <= a;
262
                    free <= b;
263 15 gerhardhoh
 
264 20 gerhardhoh
            if ways  = 1 then
265
              elim <= 0;
266
            else
267
              elim <= to_integer( gal( ldways - 1 downto 0));
268
            end if;
269 16 gerhardhoh
 
270 10 gerhardhoh
                    if stateram = ramstart then
271
                      enableram <= '1';
272
                      statetag <= tagwait;
273
                         end if;
274
                  when tagwait =>
275
                    writet <= '0';
276
 
277 13 gerhardhoh
                    if interrupt = '1' and oldint = '0' then
278 10 gerhardhoh
                      enableram <= '0';
279 20 gerhardhoh
                          AddressInt <= toFlush;
280
                          statetag <= stateget;
281
                        elsif queuedone = '1' then
282 10 gerhardhoh
                      enableram <= '0';
283 20 gerhardhoh
                          statetag <= finish;
284
                        end if;
285 10 gerhardhoh
                  when stateget =>
286
                         statetag <= stateget1;
287
                  when stateget1 =>
288 20 gerhardhoh
                     enableram <= '1';
289 10 gerhardhoh
                         tagDummy <= tagRAMOut;
290
 
291
                         for i in tagRAMIn'range loop
292
                           if del = i then
293 20 gerhardhoh
                         tagRAMIn( i).tagvalid <= '0';
294 10 gerhardhoh
                             tagRAMIn( i).cacheValid <= '0';
295
                             tagRAMIn( i).tag <= ( others => '0');
296
                             tagRAMIn( i).cacheAddr <= ( others => '0');
297 20 gerhardhoh
                                 writet <= '1';
298 10 gerhardhoh
                           else
299
                             tagRAMIn( i) <= tagRAMOut( i);
300
                           end if;
301
                         end loop;
302
 
303
                         statetag <= tagwait;
304
                  when finish =>
305
                    if doneh = '1' then
306
                           tagRAMIn <= tagBuff;
307 20 gerhardhoh
                           writet <= '1';
308
                       AddressInt <= AddressInh( AddressInt'range);
309
                           done <= '1';
310
                       statetag <= finished;
311 10 gerhardhoh
                    end if;
312
                  when finished => -- NEW
313
                    writet <= '0';
314
                    done <= '0';
315
                    statetag <= startt;
316
                end case;
317
 
318
         for i in tagRAM'range loop
319
      DataInTag( i) := TagRAMIn( i).TagValid & TagRAMIn( i).Tag & TagRAMIn( i).cacheValid & TagRAMIn( i).cacheAddr;
320
 
321
           if writet = '1' then
322
                  tagRAM(i)(to_integer( AddressInt)) <= DataInTag( i);
323
                else
324
                  DataOutTag( i) := tagRAM(i)(to_integer( AddressInt));
325
 
326
             TagRAMOut( i).cacheAddr <= DataOutTag( i)( ldram - 1 downto 0);
327
             TagRAMOut( i).cacheValid <= DataOutTag( i)( ldram);
328
             TagRAMOut( i).Tag <= DataOutTag( i)( DataOutTag( 0)'high - 1 downto ldram + 1);
329
             TagRAMOut( i).TagValid <= DataOutTag( i)( DataOutTag( 0)'high);
330
                end if;
331
         end loop;
332
         end if;
333
  end if;
334
  end Process tagrams;
335
 
336
  dataram: process (nReset, Clock, enableram) is
337
  variable en, acc, hi: std_ulogic;
338
  variable f, g: std_ulogic_vector( CacheIn.FiFoAddr'length downto 0);
339
  variable a, b: RAMBuffer;
340
  variable index, index1: integer;
341
 
342 11 gerhardhoh
  variable address: std_ulogic_vector( ldram - 1 downto 0);
343
  variable uaddress: unsigned( ldram - 1 downto 0);
344 10 gerhardhoh
  variable datum:  std_ulogic_vector( FreeIn'range);
345 11 gerhardhoh
  variable w: std_ulogic;
346 10 gerhardhoh
  begin
347
  if rising_edge(Clock) then
348
    if nReset /= '1' then
349
           enablequeue <= '0';
350
           stateram <= raminit;
351
                writec <= '0';
352
                writeb <= '0';
353
                readb <= '0';
354
                getf <= '0';
355
                putf <= '0'; -- NEW inserted
356
                doneh <= '0';
357
                accinterrupt <= '0';
358
                accqueue <= '0';
359 20 gerhardhoh
                isfull <= '0';
360
                flag <= '0';
361 22 gerhardhoh
                flag1 <= '1';
362 10 gerhardhoh
                initcount1 <= ( others => '0');
363
                FreeIn <= ( others => '0');
364 11 gerhardhoh
                firstf <= ( others => '0');
365
                lastf <= ( others => '0');
366
                counterf <= ( others => '0');
367 10 gerhardhoh
         else
368 13 gerhardhoh
           hi := accinterrupt or (interrupt and not oldint);
369 10 gerhardhoh
                acc := accqueue or queuedone;
370 13 gerhardhoh
                en := enablequeue and not acc;
371 10 gerhardhoh
 
372
                if ldCachedWords = 0 then
373
                  index := 0;
374
                else
375
                  index := to_integer( AddressInh( ldCachedWords + 1 downto 2));
376
                end if;
377
 
378
           case stateram is
379
                  when raminit =>
380
                         FreeIn <= std_ulogic_vector( initcount1);
381 20 gerhardhoh
             initcount1 <= initcount1 + 1;
382
 
383 10 gerhardhoh
                         if unsigned( not FreeIn) = 0 then
384
                           stateram <= ramstart;
385
                           putf <= '0';
386
                         else
387
                           putf <= '1';
388
                         end if;
389
                  when ramstart =>
390 20 gerhardhoh
                     if enableram = '1' then -- UPDATE
391
                           if isfull = '0' then
392
                             tagBuff <= tagRAMOut;
393
                           end if;
394
                           if found /= 15 then
395 22 gerhardhoh
                              tagBuff <= tagRAMOut;
396 18 gerhardhoh
                                  cindex <= tagRAMOut( found).cacheAddr;
397 20 gerhardhoh
                                  isfull <= '0';
398 10 gerhardhoh
                                  stateram <= ramupdate;
399 20 gerhardhoh
                           elsif free /= 15 then
400 10 gerhardhoh
                                  en := '1';
401 20 gerhardhoh
                                  if emptyf = '1' and isfull = '0' then
402
                                    isfull <= '1';
403 22 gerhardhoh
                                tagBuff <= tagRAMOut;
404 20 gerhardhoh
                                    stateram <= ramwait;
405
                                  else
406
                                    cindex <= FreeOut;
407 21 gerhardhoh
                                        if isfull = '1' then
408
                                      tagBuff( free).cacheAddr <= FreeOut;
409
                                      tagBuff( free).cacheValid <= '1';
410
                                      tagBuff( free).tag <= AddressInh( tagBuff( free).tag'range);
411
                                      tagBuff( free).tagValid <= '1';
412
                                        else
413
                                      tagRAMOut( free).cacheAddr <= FreeOut;
414
                                      tagRAMOut( free).cacheValid <= '1';
415
                                      tagRAMOut( free).tag <= AddressInh( tagRAMOut( free).tag'range);
416
                                      tagRAMOut( free).tagValid <= '1';
417 22 gerhardhoh
                                          flag1 <= '1';
418 21 gerhardhoh
                                        end if;
419 20 gerhardhoh
                                    isfull <= '0';
420
                                    getf <= '1';
421
                                    if IOCodeh = "111" and ldCachedWords = 0 then
422
                                      stateram <= ramupdate2;
423
                                    else
424
                                      readb <= '1';
425
                                  AddressOut <= AddressInh( AddressOut'range);
426
                                      stateram <= ramread;
427
                                    end if;
428
                                  end if;
429 10 gerhardhoh
                                else
430 18 gerhardhoh
                                  cindex <= tagRAMOut( elim).cacheAddr;
431 20 gerhardhoh
                                  isfull <= '0';
432 15 gerhardhoh
                                  stateram <= ramupdate;
433 10 gerhardhoh
                                end if;
434
                         end if;
435
                  when ramupdate =>
436
                    stateram <= ramupdate1;
437
                  when ramupdate1 =>
438 20 gerhardhoh
                     cacheIn <= cacheOut;
439 10 gerhardhoh
                         blockOut <= cacheOut.Words;
440
                         RecBuff <= cacheOut;
441
                         en := '1';
442 20 gerhardhoh
                         if found /= 15 then
443
                           stateram <= ramupdate2;
444
                         else
445
                           AddressOut <= tagBuff( elim).tag & AddressInh( AddressInt'range) & ( ldCachedWords + 1 downto 0 => '0');
446
                       writeb <= '1';
447
                           flag <= '1';
448
                           stateram <= ramflush;
449
                         end if;
450 10 gerhardhoh
                  when ramwait =>
451
                    if hi = '1' then
452 20 gerhardhoh
                          stateram <= ramwait1;
453
                        end if;
454 10 gerhardhoh
                  when ramwait1 =>
455 20 gerhardhoh
                         writec <= '0';
456
 
457 10 gerhardhoh
                         if del /= 15 and enableram = '1' then
458 11 gerhardhoh
                           if toflush = AddressInh( toflush'range) then -- inserted, tagline could match flushing tagline !!!!
459 20 gerhardhoh
                         tagBuff( del).tagvalid <= '0';
460 10 gerhardhoh
                             tagBuff( del).cacheValid <= '0';
461
                             tagBuff( del).tag <= ( others => '0');
462
                             tagBuff( del).cacheAddr <= ( others => '0');
463 20 gerhardhoh
                           end if;
464 10 gerhardhoh
                           cindex <= tagdummy( del).cacheAddr;
465 20 gerhardhoh
                           FreeIn <= tagdummy( del).cacheAddr;
466
                           putf <= tagdummy( del).cacheValid;
467 10 gerhardhoh
                           stateram <= ramclean;
468
                         end if;
469
                  when ramread =>
470
                    readb <= '0';
471 20 gerhardhoh
                        getf <= '0';
472 22 gerhardhoh
                        if flag1 = '1' then
473
                          tagBuff <= tagRAMOut;
474
                          flag1 <= '0';
475
                        end if;
476 10 gerhardhoh
                    stateram <= ramread1;
477
                  when ramread1 =>
478
                    if readsh = '0' then
479
                           for i in blockIn'range loop
480
                                  cacheIn.Words( i) <= blockIn( i);
481
                                end loop;
482
                      stateram <= ramupdate2;
483
                         end if;
484
                  when ramupdate2 =>
485 22 gerhardhoh
                        if flag1 = '1' then
486
                          tagBuff <= tagRAMOut;
487
                          flag1 <= '0';
488
                        end if;
489 10 gerhardhoh
                    if IOCodeh(2) = '1' then
490
                           if IOCodeh(1) = '1' then
491
                                  If IOCodeh(0) = '1' then
492
                                    cacheIn.Words( index).Word <= DataInh;
493 20 gerhardhoh
                                        cacheIn.Words( index).Modified <= "1111";
494 10 gerhardhoh
                                  elsif AddressInh(1) = '1' then
495
                                    cacheIn.Words( index).Word( 31 downto 16) <= DataInh( 15 downto 0);
496 20 gerhardhoh
                                        cacheIn.Words( index).Modified( 3 downto 2) <= "11";
497 10 gerhardhoh
                                  else
498
                                    cacheIn.Words( index).Word( 15 downto 0) <= DataInh( 15 downto 0);
499 20 gerhardhoh
                                        cacheIn.Words( index).Modified( 1 downto 0) <= "11";
500 10 gerhardhoh
                                  end if;
501
                                else
502
                                  if AddressInh(1) = '0' then
503
                                    if AddressInh(0) = '0' then
504
                                           cacheIn.Words( index).Word( 7 downto 0) <= DataInh( 7 downto 0);
505 20 gerhardhoh
                                           cacheIn.Words( index).Modified(0) <= '1';
506 10 gerhardhoh
                                    else
507
                                           cacheIn.Words( index).Word( 15 downto 8) <= DataInh( 7 downto 0);
508 20 gerhardhoh
                                           cacheIn.Words( index).Modified(1) <= '1';
509 10 gerhardhoh
                                         end if;
510
                                  else
511
                                    if AddressInh(0) = '0' then
512
                                           cacheIn.Words( index).Word( 23 downto 16) <= DataInh( 7 downto 0);
513 20 gerhardhoh
                                           cacheIn.Words( index).Modified(2) <= '1';
514 10 gerhardhoh
                                    else
515
                                           cacheIn.Words( index).Word( 31 downto 24) <= DataInh( 7 downto 0);
516 20 gerhardhoh
                                           cacheIn.Words( index).Modified(3) <= '1';
517 10 gerhardhoh
                                         end if;
518
                                  end if;
519
                                end if;
520
                         else
521
                           DataOut <= cacheIn.Words( index).Word;
522
                         end if;
523
 
524
                         cacheIn.FiFoAddr <= newFiFoAddr;
525
                         cacheIn.Am <= newAm;
526
 
527
                         getf <= '0';
528
                         writec <= '1';
529 20 gerhardhoh
 
530
                         if hi = '1' then
531
                           stateram <= ramwait1;
532
                         elsif acc = '1' then
533
                           doneh <= '1';
534
                           stateram <= ramupdate3;
535
                         end if;
536 10 gerhardhoh
                  when ramupdate3 =>
537
                    hi := '0';
538 20 gerhardhoh
                        acc := '0';
539
                        en := '0';
540
                        writec <= '0';
541 10 gerhardhoh
                    doneh <= '0';
542 20 gerhardhoh
                        stateram <= ramstart;
543 10 gerhardhoh
                  when ramclean =>
544
                    putf <= '0';
545
                    stateram <= ramclean1;
546
                  when ramclean1 =>
547
                         if del /= 15 then
548
                           blockOut <= cacheOut.words;
549 20 gerhardhoh
                           writeb <= tagdummy( del).tagValid;
550
                           AddressOut <= tagdummy( del).tag & toFlush & ( ldCachedWords + 1 downto 0 => '0');
551 10 gerhardhoh
                           stateram <= ramflush;
552
                         end if;
553
                  when ramflush =>
554
                    writeb <= '0';
555
                         for i in blockIn'range loop
556
                      cacheIn.Words( i).Word <= ( others => '0');
557 20 gerhardhoh
                          cacheIn.Words( i).Modified <= ( others => '0');
558 10 gerhardhoh
                         end loop;
559
 
560
                         stateram <= ramflush1;
561
                  when ramflush1 =>
562
                         if writesh = '0' then
563 20 gerhardhoh
                           if flag = '1' then
564
                                 tagBuff( elim).tag <= AddressInh( tagBuff( elim).tag'range);
565
                                 tagBuff( elim).tagValid <= '1';
566
                                 flag <= '0';
567
                                 if IOCodeh = "111" and ldCachedWords = 0 then
568
                                   stateram <= ramupdate2;
569
                                 else
570
                                   readb <= '1';
571
                                   AddressOut <= AddressInh( AddressOut'range);
572
                                   stateram <= ramread;
573
                                 end if;
574
                           elsif isfull = '1' then
575
                             hi := '0';
576
                                 stateram <= ramstart;
577
                           elsif acc = '1' then
578
                                 doneh <= '1';
579
                             stateram <= ramupdate3;
580
                           end if;
581 10 gerhardhoh
                         end if;
582
                end case;
583
 
584
                accinterrupt <= hi;
585
                enablequeue <= en;
586
                accqueue <= acc;
587
 
588
         f := CacheIn.Am & CacheIn.FiFoAddr;
589
         if writec = '1' then
590
           Ax( to_integer( cindex)) <= f;
591
         else
592
           g := Ax( to_integer( cindex));
593
                CacheOut.FiFoAddr <= g( g'high - 1 downto g'low);
594
                CacheOut.Am <= g( g'high);
595
         end if;
596
 
597
         for i in RAMBuffer'range loop
598
           a( i) := CacheIn.Words( i).Modified & CacheIn.Words( i).Word;
599
                if writec = '1' then
600
                  RAMs( i)( to_integer( cindex)) <= a( i);
601
                else
602
                  b( i) := RAMs( i)( to_integer( cindex));
603
                  CacheOut.Words( i).Word <= b( i)( 31 downto 0);
604
                  CacheOut.Words( i).Modified <= b( i)( 35 downto 32);
605
                end if;
606
         end loop;
607
 
608 11 gerhardhoh
         if putf = '1' then
609
           address := std_ulogic_vector( firstf);
610
                datum := FreeIn;
611
                firstf <= firstf + 1;
612
                counterf <= counterf + 1;
613 10 gerhardhoh
                w := '1';
614
         else
615 11 gerhardhoh
           uaddress := lastf;
616
           if getf = '1' and counterf /= 0 then
617 10 gerhardhoh
             counterf <= counterf - 1;
618 11 gerhardhoh
                  uaddress := uaddress + 1;
619 10 gerhardhoh
           end if;
620 11 gerhardhoh
                lastf <= uaddress;
621 10 gerhardhoh
                address := std_ulogic_vector( uaddress);
622 11 gerhardhoh
                w := '0';
623
         end if;
624 10 gerhardhoh
 
625
         if w = '1' then
626 11 gerhardhoh
           ramf( to_integer( address)) <= datum;
627 10 gerhardhoh
         else
628 11 gerhardhoh
           FreeOut <= ramf( to_integer( address));
629
         end if;
630 10 gerhardhoh
 
631
         end if;
632
  end if;
633
  end process dataram;
634
 
635
  emptyf <= '1' when counterf = 0 else '0';
636
 
637
  queues: process( nReset, Clock, enablequeue) is
638
  variable acc, hi: std_ulogic;
639
  variable A1OutBuff, AmOutBuff: std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
640 11 gerhardhoh
  variable addressA1: std_ulogic_vector( ldqueuelength - 1 downto 0);
641
  variable diff, uaddressA1: unsigned( ldqueuelength - 1 downto 0);
642 10 gerhardhoh
  variable datumA1:  std_ulogic_vector( A1OutBuff'range);
643 11 gerhardhoh
  variable wA1: std_ulogic;
644
  variable addressAm: std_ulogic_vector( ldqueuelength - 1 downto 0);
645
  variable uaddressAm: unsigned( ldqueuelength - 1 downto 0);
646 10 gerhardhoh
  variable datumAm:  std_ulogic_vector( AmOutBuff'range);
647 11 gerhardhoh
  variable wAm: std_ulogic;
648 10 gerhardhoh
  begin
649
  if rising_edge(Clock) then
650
    if nReset /= '1' then
651
                del <= 15;
652
           statequeue <= queuestart;
653
           queuedone <= '0';
654
                interrupt <= '0';
655
                accdone <= '0';
656
                preempted <= '0';
657 11 gerhardhoh
                firstA1 <= ( others => '0');
658
                A1Outaddr <= ( others => '0');
659
                lastA1 <= ( others => '0');
660 10 gerhardhoh
                counterA1 <= ( others => '0');
661 11 gerhardhoh
                firstAm <= ( others => '0');
662
                AmOutaddr <= ( others => '0');
663
                lastAm <= ( others => '0');
664 10 gerhardhoh
                counterAm <= ( others => '0');
665
                getA1 <= '0'; -- NEW
666
                getAm <= '0'; -- NEW
667
                removeA1 <= '0'; -- NEW
668
                removeAm <= '0'; -- NEW
669
                putA1 <= '0'; -- NEW
670 11 gerhardhoh
                putAm <= '0'; -- NEW
671 20 gerhardhoh
        serviced <= '0';
672 10 gerhardhoh
         else
673 13 gerhardhoh
           hi := interrupt;
674 20 gerhardhoh
           acc := accdone or doneh;
675 10 gerhardhoh
 
676 20 gerhardhoh
           diff := firstA1 - unsigned( RecBuff.FiFoAddr);
677 10 gerhardhoh
 
678
           case statequeue is
679
                  when queuestart =>
680
                         getA1 <= '0';
681
 
682
                    if enablequeue = '1' then
683
                           if found /= 15 then
684
                                  if RecBuff.Am = '1' or                                -- in Am
685
                                    ( RecBuff.Am = '0' and diff( diff'high) = '0') then -- in lower half of A1
686 20 gerhardhoh
                                     queuedone <= '1';
687 10 gerhardhoh
                                         newFiFoAddr <= RecBuff.FiFoAddr;
688
                                         newAm <= RecBuff.Am;
689 20 gerhardhoh
                                 statequeue <= queuewait;
690 10 gerhardhoh
                                  elsif fullAm = '1' then
691
                                    -- Am full
692
                                         if AmOut.valid = '1' then
693
                                           del <= to_integer( AmOut.way);
694 20 gerhardhoh
                                           toFlush <= AmOut.word;
695
                                           getAm <= '1';
696 10 gerhardhoh
                                           hi := '1';
697
                                           statequeue <= queuewait;
698
                                         end if;
699
                                  else
700
                                    AmIn.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
701 20 gerhardhoh
                                        AmIn.way <= std_ulogic_vector(to_unsigned( found, ldways + 1));
702
                                        AmIn.valid <= '1';
703
                                        putAm <= '1';
704
                                        A1Inaddr <= RecBuff.FiFoAddr;
705
                                        removeA1 <= '1';
706
                                        statequeue <= queuewaitAm1;
707 10 gerhardhoh
                                  end if;
708
                                elsif free /= 15 then
709 20 gerhardhoh
                                  if fullA1 = '1' or (isfull = '1' and emptyA1 = '0' and serviced = '0') then
710 10 gerhardhoh
                                    -- remove last entry from A1
711
                                         if A1Out.valid = '1' then
712
                                           del <= to_integer( A1Out.way);
713
                                           toFlush <= A1Out.word;
714
                                           getA1 <= '1';
715
                                           hi := '1';
716 20 gerhardhoh
                       serviced <= '1';
717 10 gerhardhoh
                                           statequeue <= queuewait;
718
                                         end if;
719 20 gerhardhoh
                                  elsif emptyAm = '0' and isfull = '1' and serviced = '0' then
720 10 gerhardhoh
                                    -- remove last entry from Am
721
                                         if AmOut.valid = '1' then
722
                                           del <= to_integer( AmOut.way);
723
                                           toFlush <= AmOut.word;
724
                                           getAm <= '1';
725
                                           hi := '1';
726 20 gerhardhoh
                       serviced <= '1';
727 10 gerhardhoh
                                           statequeue <= queuewait;
728
                                         end if;
729
                                  else
730
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
731
                                         A1In.way <= std_ulogic_vector(to_unsigned( free, ldways + 1));
732
                                         A1In.valid <= '1';
733
                                         putA1 <= '1';
734 20 gerhardhoh
                     serviced <= '0';
735 10 gerhardhoh
                                         statequeue <= queuewaitA11;
736
                                  end if;
737
                                elsif elim /= 15 then
738
                                  if fullA1 = '1' then
739
                                    if A1Out.valid = '1' then
740
                                           if not ( to_integer( A1Out.way) = elim and
741
                                                        A1Out.word = AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords)) then
742
                                             del <= to_integer( A1Out.way);
743
                                             toFlush <= A1Out.word;
744
                                             statequeue <= queueelim;
745
                                           end if;
746
 
747
                                           getA1 <= '1';
748
                                         end if;
749
                                  else
750 20 gerhardhoh
                    if getA1 = '1' then
751
                      preempted <= '1';
752
                    end if;
753
                                        getA1 <= '0'; -- NEW, inserted the only bug!!!!!!!!!!!!!!
754 10 gerhardhoh
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
755 20 gerhardhoh
                                        A1In.way <= std_ulogic_vector(to_unsigned( elim, ldways + 1));
756
                                        A1In.valid <= '1';
757
                                        putA1 <= '1';
758
                                        statequeue <= queueelim;
759 10 gerhardhoh
                                  end if;
760
                                end if;
761
                         end if;
762
                  when queuewait =>
763 20 gerhardhoh
                        removeA1 <= '0';
764
                        removeAm <= '0';
765 10 gerhardhoh
                    getAm <= '0';
766
                    getA1 <= '0';
767 20 gerhardhoh
                        queuedone <= '0';
768 10 gerhardhoh
 
769 20 gerhardhoh
            if hi = '1' then
770
              hi := '0';
771
                          statequeue <= queuestart;
772
                elsif acc = '1' then
773
                          acc := '0';
774
                          del <= 15;
775
                          statequeue <= queuestart;
776
                        end if;
777 10 gerhardhoh
                  when queuewaitAm1 =>
778
                    putAm <= '0';
779 20 gerhardhoh
                        removeA1 <= '0';
780
                        statequeue <= queuewaitAm2;
781 10 gerhardhoh
                  when queuewaitAm2 =>
782 20 gerhardhoh
                        newFiFoAddr <= AmOutAddr;
783
                        newAm <= '1';
784
                        queuedone <= '1';
785
                        statequeue <= queuewait;
786 10 gerhardhoh
                  when queuewaitA11 =>
787
                    putA1 <= '0';
788 20 gerhardhoh
                        statequeue <= queuewaitA12;
789 10 gerhardhoh
                  when queuewaitA12 =>
790 20 gerhardhoh
                        newFiFoAddr <= A1OutAddr;
791
                        newAm <= '0';
792
                        removeA1 <= '0';
793
                        removeAm <= '0';
794
                        queuedone <= '1';
795 10 gerhardhoh
                    preempted <= '0';
796 20 gerhardhoh
                        statequeue <= queuewait;
797 10 gerhardhoh
                  when queueelim =>
798
                    putA1 <= '0';
799 20 gerhardhoh
                        getA1 <= '0';
800 10 gerhardhoh
 
801 20 gerhardhoh
                        if RecBuff.Am = '1' and preempted = '0' then
802
                          AmInAddr <= RecBuff.FiFoAddr;
803
                          removeAm <= '1';
804
                        elsif preempted = '0' then
805
                          A1InAddr <= RecBuff.FiFoAddr;
806
                          removeA1 <= '1';
807
                        end if;
808 10 gerhardhoh
 
809 20 gerhardhoh
                        if getA1 = '1' then
810
                          hi := '1';
811
                          preempted <= '1';
812
                          statequeue <= queuewait;
813
                        else
814
                          statequeue <= queuewaitA12;
815
                        end if;
816 10 gerhardhoh
                end case;
817
 
818
                interrupt <= hi;
819
                accdone <= acc;
820
 
821 11 gerhardhoh
         if putA1 = '1' or removeA1 = '1' then
822
           if removeA1 = '0' then
823
             addressA1 := std_ulogic_vector( firstA1);
824 10 gerhardhoh
                  datumA1 := A1In.valid & A1In.way & A1In.Word;
825 11 gerhardhoh
                  firstA1 <= firstA1 + 1;
826
                  counterA1 <= counterA1 + 1;
827
                  A1Outaddr <= std_ulogic_vector( firstA1);
828
                else
829
                  addressA1 := A1Inaddr( addressA1'range);
830
                  datumA1 := ( others => '0');
831 10 gerhardhoh
                end if;
832 11 gerhardhoh
                wA1 := '1';
833
         else
834
           uaddressA1 := lastA1;
835
           if (getA1 = '1' or A1Out.valid = '0') and counterA1 /= 0 then
836
             counterA1 <= counterA1 - 1;
837
             uaddressA1 := uaddressA1 + 1;
838 10 gerhardhoh
           end if;
839
           lastA1 <= uaddressA1;
840
           addressA1 := std_ulogic_vector( uaddressA1);
841 11 gerhardhoh
           wA1 := '0';
842 10 gerhardhoh
         end if;
843
 
844
         if wA1 = '1' then
845 11 gerhardhoh
           ramA1( to_integer( addressA1)) <= datumA1;
846 10 gerhardhoh
         else
847 11 gerhardhoh
           A1OutBuff := ramA1( to_integer( addressA1));
848 10 gerhardhoh
 
849
      A1Out.Word <= A1OutBuff( blocksizeld - 1 downto 0);
850
      A1Out.way <= A1OutBuff( blocksizeld + ldways downto blocksizeld);
851
                A1Out.valid <= A1OutBuff( blocksizeld + ldways + 1);
852 11 gerhardhoh
         end if;
853 10 gerhardhoh
 
854 11 gerhardhoh
         if putAm = '1' or removeAm = '1' then
855
           if removeAm = '0' then
856
             addressAm := std_ulogic_vector( firstAm);
857 10 gerhardhoh
                  datumAm := AmIn.valid & AmIn.way & AmIn.Word;
858 11 gerhardhoh
                  firstAm <= firstAm + 1;
859
                  counterAm <= counterAm + 1;
860
                  AmOutaddr <= std_ulogic_vector( firstAm);
861
                else
862
                  addressAm := AmInaddr( addressAm'range);
863
                  datumAm := ( others => '0');
864 10 gerhardhoh
                end if;
865 11 gerhardhoh
                wAm := '1';
866
         else
867
           uaddressAm := lastAm;
868
           if (getAm = '1' or AmOut.valid = '0') and counterAm /= 0 then
869
             counterAm <= counterAm - 1;
870
             uaddressAm := uaddressAm + 1;
871 10 gerhardhoh
           end if;
872
           lastAm <= uaddressAm;
873
           addressAm := std_ulogic_vector( uaddressAm);
874 11 gerhardhoh
           wAm := '0';
875 10 gerhardhoh
         end if;
876 11 gerhardhoh
 
877 10 gerhardhoh
         if wAm = '1' then
878 11 gerhardhoh
           ramAm( to_integer( addressAm)) <= datumAm;
879 10 gerhardhoh
         else
880
           AmOutBuff := ramAm( to_integer( addressAm));
881 11 gerhardhoh
 
882 10 gerhardhoh
      AmOut.Word <= AmOutBuff( blocksizeld - 1 downto 0);
883
      AmOut.way <= AmOutBuff( blocksizeld + ldways downto blocksizeld);
884
                AmOut.valid <= AmOutBuff( blocksizeld + ldways + 1);
885
         end if;
886 11 gerhardhoh
         end if;
887 10 gerhardhoh
  end if;
888
  end process queues;
889
 
890
  fullA1 <= counterA1( counterA1'high);
891 11 gerhardhoh
  emptyA1 <= '1' when counterA1 = 0 else '0';
892 10 gerhardhoh
 
893
  fullAm <= counterAm( counterAm'high);
894 11 gerhardhoh
  emptyAm <= '1' when counterAm = 0 else '0';
895 10 gerhardhoh
 
896 11 gerhardhoh
end Rtl;
897
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.