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

Subversion Repositories mytwoqcache

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

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 10 gerhardhoh
type rType is ( raminit, ramstart, ramstart1, ramcheck, ramcheck1, ramcheck2, 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
signal enableram, enablequeue, queuedone, readsh, writesh, doneh, preempted,
141 11 gerhardhoh
       interrupt, readb, writeb, writec, writet, accdone, accqueue, accinterrupt: std_ulogic;
142
 
143
begin
144 10 gerhardhoh
 
145 11 gerhardhoh
 
146
 
147 10 gerhardhoh
  blockIO: process( nReset, Clock, readb, writeb) is
148
  variable s: std_ulogic;
149
  begin
150
    if nReset /= '1' then
151
           writesh <= '0';
152
                readsh <= '0';
153
                stateIO <= start;
154
    elsif rising_edge(Clock) then
155
           case stateIO is
156
                when start =>
157
                  if readb = '1' then
158
                         Mask <= ( others => '1');
159
                         readsh <= '1';
160
                    stateIO <= busy;
161
                  elsif writeb = '1' then
162
                    s := '0';
163
 
164
                    for i in blockOut'range loop
165
                      DataBlockOut( ( i + 1) * 32 - 1 downto i * 32) <= blockOut( i).word;
166
                           Mask( ( i + 1) * 4 - 1 downto i * 4) <= not blockOut( i).Modified;
167
                                s := s or blockOut( i).Modified(0) or blockOut( i).Modified(1) or
168
                                          blockOut( i).Modified(2) or blockOut( i).Modified(3);
169
                         end loop;
170
 
171
                         writesh <= s;
172
 
173
                         if s = '1' then
174
                      stateIO <= busy;
175
                         end if;
176
                  end if;
177
                when busy =>
178
                  if ack = '1' then
179
                    stateIO <= start;
180
 
181
                    if readsh = '1' then
182
                           for i in blockIn'range loop
183
                        blockIn( i).word <= DataBlockIn( ( i + 1) * 32 - 1 downto i * 32);
184
                                  blockIn( i).Modified <= ( others => '0');
185
                                end loop;
186
                    end if;
187
 
188
                    readsh <= '0';
189
                    writesh <= '0';
190
                  end if;
191
                end case;
192
         end if;
193
  end process blockIO;
194
 
195
  writes <= writesh;
196
  reads <= readsh;
197
 
198
  tagrams: process ( nReset, Clock) is
199
  variable a, b, d: myint;
200 11 gerhardhoh
  variable DataInTag, DataOutTag: TagBuffer;
201 10 gerhardhoh
  begin
202
  if rising_edge(Clock) then
203
    if nReset /= '1' then
204
           statetag <= inittag;
205
                writet <= '0';
206
                enableram <= '0';
207
                found <= 15;
208
                free <= 15;
209
                done <= '0'; -- NEW
210
                initcount <= ( others => '0');
211
                AddressInt <= ( others => '0');
212
                IOCodeh <= ( others => '0');
213
                AddressInh <= ( others => '0');
214
         else
215
 
216
           case statetag is
217
                  when inittag =>
218
                    for i in tagRAMIn'range loop
219
                           tagRAMIn(i).tagValid <= '0';
220
                           tagRAMIn(i).tag <= ( others => '0');
221
                           tagRAMIn(i).cacheValid <= '0';
222
                           tagRAMIn(i).cacheAddr <= ( others => '0');
223
                         end loop;
224
                         AddressInt <= std_ulogic_vector(initcount);
225
                         initcount <= initcount + 1;
226
                         if unsigned( not AddressInt) = 0 then
227
                      statetag <= startt;
228
                           writet <= '0';
229
                         else
230
                           writet <= '1';
231
                         end if;
232
                  when startt =>
233
                    if IOCode( 1 downto 0) /= "00" and AddressIn( AddressIn'high) = '0' then
234
                      -- request encountered
235
                                AddressInh <= AddressIn(AddressInh'range);
236 11 gerhardhoh
                                IOCodeh <= IOCode;
237 10 gerhardhoh
                      AddressInt <= AddressIn( AddressInt'range);
238
                                DataInh <= DataIn;
239
                      statetag <= startt1;
240
                    end if;
241
                  when startt1 =>
242
                    statetag <= tagtest;
243
                  when tagtest =>
244 11 gerhardhoh
          a := 15;
245 10 gerhardhoh
                    b := 15;
246 11 gerhardhoh
 
247
               for i in 0 to TagRAMarray'high loop
248
                      if tagRAMOut( i).tagValid = '1' then
249
                   if AddressInh(tagRAMout( i).tag'range) = tagRAMout( i).tag then
250 10 gerhardhoh
                          a := i; -- present
251 11 gerhardhoh
                                  end if;
252
                      else
253
                             b := i; -- free entry
254
                      end if;
255
               end loop;
256 10 gerhardhoh
 
257 11 gerhardhoh
                    found <= a;
258
                    free <= b;
259
 
260 10 gerhardhoh
                    if stateram = ramstart then
261
                      enableram <= '1';
262
                      statetag <= tagwait;
263
                         end if;
264
                  when tagwait =>
265
                    writet <= '0';
266
 
267
                    if interrupt = '1' then
268
                      enableram <= '0';
269
                           AddressInt <= toFlush;
270
                                statetag <= stateget;
271
                         elsif queuedone = '1' then
272
                      enableram <= '0';
273
                           statetag <= finish;
274
                         end if;
275
                  when stateget =>
276
                         statetag <= stateget1;
277
                  when stateget1 =>
278
                    enableram <= '1';
279
                         tagDummy <= tagRAMOut;
280
 
281
                         for i in tagRAMIn'range loop
282
                           if del = i then
283
                        tagRAMIn( i).tagvalid <= '0';
284
                             tagRAMIn( i).cacheValid <= '0';
285
                             tagRAMIn( i).tag <= ( others => '0');
286
                             tagRAMIn( i).cacheAddr <= ( others => '0');
287
                                  writet <= '1';
288
                           else
289
                             tagRAMIn( i) <= tagRAMOut( i);
290
                           end if;
291
                         end loop;
292
 
293
                         statetag <= tagwait;
294
                  when finish =>
295
                    if doneh = '1' then
296
                           tagRAMIn <= tagBuff;
297
                                writet <= '1';
298
                      AddressInt <= AddressInh( AddressInt'range);
299
                                done <= '1';
300
                      statetag <= finished;
301
                    end if;
302
                  when finished => -- NEW
303
                    writet <= '0';
304
                    done <= '0';
305
                    statetag <= startt;
306
                end case;
307
 
308
         for i in tagRAM'range loop
309
      DataInTag( i) := TagRAMIn( i).TagValid & TagRAMIn( i).Tag & TagRAMIn( i).cacheValid & TagRAMIn( i).cacheAddr;
310
 
311
           if writet = '1' then
312
                  tagRAM(i)(to_integer( AddressInt)) <= DataInTag( i);
313
                else
314
                  DataOutTag( i) := tagRAM(i)(to_integer( AddressInt));
315
 
316
             TagRAMOut( i).cacheAddr <= DataOutTag( i)( ldram - 1 downto 0);
317
             TagRAMOut( i).cacheValid <= DataOutTag( i)( ldram);
318
             TagRAMOut( i).Tag <= DataOutTag( i)( DataOutTag( 0)'high - 1 downto ldram + 1);
319
             TagRAMOut( i).TagValid <= DataOutTag( i)( DataOutTag( 0)'high);
320
                end if;
321
         end loop;
322
         end if;
323
  end if;
324
  end Process tagrams;
325
 
326
  dataram: process (nReset, Clock, enableram) is
327
  variable en, acc, hi: std_ulogic;
328
  variable f, g: std_ulogic_vector( CacheIn.FiFoAddr'length downto 0);
329
  variable a, b: RAMBuffer;
330
  variable index, index1: integer;
331
 
332 11 gerhardhoh
  variable address: std_ulogic_vector( ldram - 1 downto 0);
333
  variable uaddress: unsigned( ldram - 1 downto 0);
334 10 gerhardhoh
  variable datum:  std_ulogic_vector( FreeIn'range);
335 11 gerhardhoh
  variable w: std_ulogic;
336 10 gerhardhoh
  begin
337
  if rising_edge(Clock) then
338
    if nReset /= '1' then
339
           enablequeue <= '0';
340
           stateram <= raminit;
341
                writec <= '0';
342
                writeb <= '0';
343
                readb <= '0';
344
                getf <= '0';
345
                putf <= '0'; -- NEW inserted
346
                doneh <= '0';
347
                elim <= 15;
348
                accinterrupt <= '0';
349
                accqueue <= '0';
350
                initcount1 <= ( others => '0');
351
                FreeIn <= ( others => '0');
352 11 gerhardhoh
                firstf <= ( others => '0');
353
                lastf <= ( others => '0');
354
                counterf <= ( others => '0');
355 10 gerhardhoh
         else
356
           hi := accinterrupt or interrupt;
357
                acc := accqueue or queuedone;
358
                en := enablequeue and ( hi nor acc);
359
 
360
                if ldCachedWords = 0 then
361
                  index := 0;
362
                else
363
                  index := to_integer( AddressInh( ldCachedWords + 1 downto 2));
364
                end if;
365
 
366
           case stateram is
367
                  when raminit =>
368
                         FreeIn <= std_ulogic_vector( initcount1);
369
          initcount1    <= initcount1 + 1;
370
 
371
                         if unsigned( not FreeIn) = 0 then
372
                           stateram <= ramstart;
373
                           putf <= '0';
374
                         else
375
                           putf <= '1';
376
                         end if;
377
                  when ramstart =>
378
                    if enableram = '1' then -- UPDATE
379
                           tagBuff <= tagRAMOut;
380
                                elim <= 15;
381
                                stateram <= ramstart1;
382 11 gerhardhoh
                         end if;
383 10 gerhardhoh
                  when ramstart1 =>
384
                    if enableram = '1' then
385
                                if found /= 15 then
386
                                  cindex <= tagBuff( found).cacheAddr;
387
                                  stateram <= ramupdate;
388
                                elsif free /= 15 then
389
                                  en := '1';
390
                                  stateram <= ramwait;
391
                                else
392
                                  elim <= 0;
393
                                  stateram <= ramcheck;
394
                                end if;
395
                         end if;
396
                  when ramcheck =>
397
                         cindex <= tagBuff( elim).cacheAddr;
398
                    stateram <= ramcheck1;
399
                  when ramcheck1 =>
400
                    stateram <= ramcheck2;
401
                  when ramcheck2 =>
402
                    if cacheOut.Am = '0' or elim = ways - 1 then
403
                           RecBuff <= cacheOut;
404
                                en := '1';
405
                      stateram <= ramwait;
406
                         else
407
                           elim <= elim + 1;
408
                      stateram <= ramcheck;
409
                         end if;
410
                  when ramupdate =>
411
                    stateram <= ramupdate1;
412
                  when ramupdate1 =>
413
                    cacheIn <= cacheOut;
414
                         blockOut <= cacheOut.Words;
415
                         RecBuff <= cacheOut;
416
                         en := '1';
417
                         stateram <= ramwait;
418
                  when ramwait =>
419
                         doneh <= '0';
420
 
421
                    if hi = '1' then
422
                                stateram <= ramwait1;
423
                         elsif acc = '1' then
424
                           if found /= 15 then
425
                                  cindex <= tagBuff( found).cacheAddr;
426
                                  cacheIn <= RecBuff;
427
                                  blockOut <= RecBuff.Words;
428
                                  stateram <= ramupdate2;
429
                                elsif free /= 15 then
430
                                  cindex <= FreeOut;
431
                                  tagBuff( free).cacheAddr <= FreeOut;
432
                                  tagBuff( free).cacheValid <= '1';
433
                                  tagBuff( free).tag <= AddressInh( tagBuff( free).tag'range);
434
                                  tagBuff( free).tagValid <= '1';
435
                                  getf <= '1';
436
                                  if IOCodeh = "111" and ldCachedWords = 0 then
437
                                    stateram <= ramupdate2;
438
                                  else
439
                                    readb <= '1';
440
                               AddressOut <= AddressInh( AddressOut'range);
441
                                    stateram <= ramread;
442
                                  end if;
443
                                else
444
                                  cindex <= tagBuff( elim).cacheAddr;
445
                                  cacheIn <= RecBuff;
446
                                  blockOut <= RecBuff.Words;
447
                                  AddressOut <= tagBuff( elim).tag & AddressInh( AddressInt'range) & ( ldCachedWords + 1 downto 0 => '0');
448
                        writeb <= '1';
449
                                  stateram <= ramflush;
450
                                end if;
451
                         end if;
452
                  when ramwait1 =>
453
                         if del /= 15 and enableram = '1' then
454 11 gerhardhoh
                           if toflush = AddressInh( toflush'range) then -- inserted, tagline could match flushing tagline !!!!
455 10 gerhardhoh
                        tagBuff( del).tagvalid <= '0';
456
                             tagBuff( del).cacheValid <= '0';
457
                             tagBuff( del).tag <= ( others => '0');
458
                             tagBuff( del).cacheAddr <= ( others => '0');
459
                                end if;
460
                           cindex <= tagdummy( del).cacheAddr;
461
                                FreeIn <= tagdummy( del).cacheAddr;
462
                                putf <= tagdummy( del).cacheValid;
463
                           stateram <= ramclean;
464
                         end if;
465
                  when ramread =>
466
                    readb <= '0';
467
                         getf <= '0';
468
                    stateram <= ramread1;
469
                  when ramread1 =>
470
                    if readsh = '0' then
471
                           for i in blockIn'range loop
472
                                  cacheIn.Words( i) <= blockIn( i);
473
                                end loop;
474
                      stateram <= ramupdate2;
475
                         end if;
476
                  when ramupdate2 =>
477
                    if IOCodeh(2) = '1' then
478
                           if IOCodeh(1) = '1' then
479
                                  If IOCodeh(0) = '1' then
480
                                    cacheIn.Words( index).Word <= DataInh;
481
                                         cacheIn.Words( index).Modified <= "1111";
482
                                  elsif AddressInh(1) = '1' then
483
                                    cacheIn.Words( index).Word( 31 downto 16) <= DataInh( 15 downto 0);
484
                                         cacheIn.Words( index).Modified( 3 downto 2) <= "11";
485
                                  else
486
                                    cacheIn.Words( index).Word( 15 downto 0) <= DataInh( 15 downto 0);
487
                                         cacheIn.Words( index).Modified( 1 downto 0) <= "11";
488
                                  end if;
489
                                else
490
                                  if AddressInh(1) = '0' then
491
                                    if AddressInh(0) = '0' then
492
                                           cacheIn.Words( index).Word( 7 downto 0) <= DataInh( 7 downto 0);
493
                                                cacheIn.Words( index).Modified(0) <= '1';
494
                                    else
495
                                           cacheIn.Words( index).Word( 15 downto 8) <= DataInh( 7 downto 0);
496
                                                cacheIn.Words( index).Modified(1) <= '1';
497
                                         end if;
498
                                  else
499
                                    if AddressInh(0) = '0' then
500
                                           cacheIn.Words( index).Word( 23 downto 16) <= DataInh( 7 downto 0);
501
                                                cacheIn.Words( index).Modified(2) <= '1';
502
                                    else
503
                                           cacheIn.Words( index).Word( 31 downto 24) <= DataInh( 7 downto 0);
504
                                                cacheIn.Words( index).Modified(3) <= '1';
505
                                         end if;
506
                                  end if;
507
                                end if;
508
                         else
509
                           DataOut <= cacheIn.Words( index).Word;
510
                         end if;
511
 
512
                         cacheIn.FiFoAddr <= newFiFoAddr;
513
                         cacheIn.Am <= newAm;
514
 
515
                         getf <= '0';
516
                         writec <= '1';
517
                         doneh <= '1';
518
 
519
                         stateram <= ramupdate3;
520
                  when ramupdate3 =>
521
                    hi := '0';
522
                         acc := '0';
523
                         en := '0';
524
                         writec <= '0';
525
                    doneh <= '0';
526
                         stateram <= ramstart;
527
                  when ramclean =>
528
                    putf <= '0';
529
                    stateram <= ramclean1;
530
                  when ramclean1 =>
531
                         if del /= 15 then
532
                           blockOut <= cacheOut.words;
533
                                writeb <= tagdummy( del).tagValid;
534
                                AddressOut <= tagdummy( del).tag & toFlush & ( ldCachedWords + 1 downto 0 => '0');
535
                           stateram <= ramflush;
536
                         end if;
537
                  when ramflush =>
538
                    writeb <= '0';
539
                         for i in blockIn'range loop
540
                      cacheIn.Words( i).Word <= ( others => '0');
541
                           cacheIn.Words( i).Modified <= ( others => '0');
542
                         end loop;
543
 
544
                         stateram <= ramflush1;
545
                  when ramflush1 =>
546
                         if writesh = '0' then
547
                           if del /= 15 and hi = '1' then
548
                                  doneh <= '1';
549
                                  en := '1';
550
                                  hi := '0';
551
                             stateram <= ramwait;
552
                                else
553
                                  tagBuff( elim).tag <= AddressInh( tagBuff( elim).tag'range);
554
                                  tagBuff( elim).tagValid <= '1';
555
                                  if IOCodeh = "111" and ldCachedWords = 0 then
556
                                    stateram <= ramupdate2;
557
                                  else
558
                                    readb <= '1';
559
                                    AddressOut <= AddressInh( AddressOut'range);
560
                                    stateram <= ramread;
561
                                  end if;
562
                                end if;
563
                         end if;
564
                end case;
565
 
566
                accinterrupt <= hi;
567
                enablequeue <= en;
568
                accqueue <= acc;
569
 
570
         f := CacheIn.Am & CacheIn.FiFoAddr;
571
         if writec = '1' then
572
           Ax( to_integer( cindex)) <= f;
573
         else
574
           g := Ax( to_integer( cindex));
575
                CacheOut.FiFoAddr <= g( g'high - 1 downto g'low);
576
                CacheOut.Am <= g( g'high);
577
         end if;
578
 
579
         for i in RAMBuffer'range loop
580
           a( i) := CacheIn.Words( i).Modified & CacheIn.Words( i).Word;
581
                if writec = '1' then
582
                  RAMs( i)( to_integer( cindex)) <= a( i);
583
                else
584
                  b( i) := RAMs( i)( to_integer( cindex));
585
                  CacheOut.Words( i).Word <= b( i)( 31 downto 0);
586
                  CacheOut.Words( i).Modified <= b( i)( 35 downto 32);
587
                end if;
588
         end loop;
589
 
590 11 gerhardhoh
         if putf = '1' then
591
           address := std_ulogic_vector( firstf);
592
                datum := FreeIn;
593
                firstf <= firstf + 1;
594
                counterf <= counterf + 1;
595 10 gerhardhoh
                w := '1';
596
         else
597 11 gerhardhoh
           uaddress := lastf;
598
           if getf = '1' and counterf /= 0 then
599 10 gerhardhoh
             counterf <= counterf - 1;
600 11 gerhardhoh
                  uaddress := uaddress + 1;
601 10 gerhardhoh
           end if;
602 11 gerhardhoh
                lastf <= uaddress;
603 10 gerhardhoh
                address := std_ulogic_vector( uaddress);
604 11 gerhardhoh
                w := '0';
605
         end if;
606 10 gerhardhoh
 
607
         if w = '1' then
608 11 gerhardhoh
           ramf( to_integer( address)) <= datum;
609 10 gerhardhoh
         else
610 11 gerhardhoh
           FreeOut <= ramf( to_integer( address));
611
         end if;
612 10 gerhardhoh
 
613
         end if;
614
  end if;
615
  end process dataram;
616
 
617
  emptyf <= '1' when counterf = 0 else '0';
618
 
619
  queues: process( nReset, Clock, enablequeue) is
620
  variable acc, hi: std_ulogic;
621
  variable A1OutBuff, AmOutBuff: std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
622 11 gerhardhoh
  variable addressA1: std_ulogic_vector( ldqueuelength - 1 downto 0);
623
  variable diff, uaddressA1: unsigned( ldqueuelength - 1 downto 0);
624 10 gerhardhoh
  variable datumA1:  std_ulogic_vector( A1OutBuff'range);
625 11 gerhardhoh
  variable wA1: std_ulogic;
626
  variable addressAm: std_ulogic_vector( ldqueuelength - 1 downto 0);
627
  variable uaddressAm: unsigned( ldqueuelength - 1 downto 0);
628 10 gerhardhoh
  variable datumAm:  std_ulogic_vector( AmOutBuff'range);
629 11 gerhardhoh
  variable wAm: std_ulogic;
630 10 gerhardhoh
  begin
631
  if rising_edge(Clock) then
632
    if nReset /= '1' then
633
                del <= 15;
634
           statequeue <= queuestart;
635
           queuedone <= '0';
636
                interrupt <= '0';
637
                accdone <= '0';
638
                preempted <= '0';
639 11 gerhardhoh
                firstA1 <= ( others => '0');
640
                A1Outaddr <= ( others => '0');
641
                lastA1 <= ( others => '0');
642 10 gerhardhoh
                counterA1 <= ( others => '0');
643 11 gerhardhoh
                firstAm <= ( others => '0');
644
                AmOutaddr <= ( others => '0');
645
                lastAm <= ( others => '0');
646 10 gerhardhoh
                counterAm <= ( others => '0');
647
                getA1 <= '0'; -- NEW
648
                getAm <= '0'; -- NEW
649
                removeA1 <= '0'; -- NEW
650
                removeAm <= '0'; -- NEW
651
                putA1 <= '0'; -- NEW
652 11 gerhardhoh
                putAm <= '0'; -- NEW
653 10 gerhardhoh
         else
654
           hi := '0';
655
                acc := accdone or doneh;
656
 
657
                diff := firstA1 - unsigned( RecBuff.FiFoAddr);
658
 
659
           case statequeue is
660
                  when queuestart =>
661
                         getA1 <= '0';
662
 
663
                    if enablequeue = '1' then
664
                           if found /= 15 then
665
                                  if RecBuff.Am = '1' or                                -- in Am
666
                                    ( RecBuff.Am = '0' and diff( diff'high) = '0') then -- in lower half of A1
667
                                    queuedone <= '1';
668
                                         newFiFoAddr <= RecBuff.FiFoAddr;
669
                                         newAm <= RecBuff.Am;
670
                               statequeue <= queuewait;
671
                                  elsif fullAm = '1' then
672
                                    -- Am full
673
                                         if AmOut.valid = '1' then
674
                                           del <= to_integer( AmOut.way);
675
                                                toFlush <= AmOut.word;
676
                                                getAm <= '1';
677
                                           hi := '1';
678
                                           statequeue <= queuewait;
679
                                         end if;
680
                                  else
681
                                    AmIn.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
682
                                         AmIn.way <= std_ulogic_vector(to_unsigned( found, ldways + 1));
683
                                         AmIn.valid <= '1';
684
                                         putAm <= '1';
685
                                         A1Inaddr <= RecBuff.FiFoAddr;
686
                                         removeA1 <= '1';
687
                                         statequeue <= queuewaitAm1;
688
                                  end if;
689
                                elsif free /= 15 then
690
                                  if fullA1 = '1' or (emptyf = '1' and emptyA1 = '0') then
691
                                    -- remove last entry from A1
692
                                         if A1Out.valid = '1' then
693
                                           del <= to_integer( A1Out.way);
694
                                           toFlush <= A1Out.word;
695
                                           getA1 <= '1';
696
                                           hi := '1';
697
                                           statequeue <= queuewait;
698
                                         end if;
699
                                  elsif fullAm = '1' and emptyf = '1' then
700
                                    -- remove last entry from Am
701
                                         if AmOut.valid = '1' then
702
                                           del <= to_integer( AmOut.way);
703
                                           toFlush <= AmOut.word;
704
                                           getAm <= '1';
705
                                           hi := '1';
706
                                           statequeue <= queuewait;
707
                                         end if;
708
                                  else
709
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
710
                                         A1In.way <= std_ulogic_vector(to_unsigned( free, ldways + 1));
711
                                         A1In.valid <= '1';
712
                                         putA1 <= '1';
713
                                         statequeue <= queuewaitA11;
714
                                  end if;
715
                                elsif elim /= 15 then
716
                                  if fullA1 = '1' then
717
                                    if A1Out.valid = '1' then
718
                                           if not ( to_integer( A1Out.way) = elim and
719
                                                        A1Out.word = AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords)) then
720
                                             del <= to_integer( A1Out.way);
721
                                             toFlush <= A1Out.word;
722
                                             statequeue <= queueelim;
723
                                           end if;
724
 
725
                                           getA1 <= '1';
726
                                         end if;
727
                                  else
728 12 gerhardhoh
                            if getA1 = '1' then
729
                              preempted <= '1';
730
                            end if;
731 10 gerhardhoh
                                         getA1 <= '0'; -- NEW, inserted the only bug!!!!!!!!!!!!!!
732
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
733
                                         A1In.way <= std_ulogic_vector(to_unsigned( elim, ldways + 1));
734
                                         A1In.valid <= '1';
735
                                         putA1 <= '1';
736
                                         statequeue <= queueelim;
737
                                  end if;
738
                                end if;
739
                         end if;
740
                  when queuewait =>
741
                         removeA1 <= '0';
742
                         removeAm <= '0';
743
                    getAm <= '0';
744
                    getA1 <= '0';
745
                         queuedone <= '0';
746
 
747
               if acc = '1' then
748
                           acc := '0';
749
                                del <= 15;
750
                           statequeue <= queuestart;
751
                         end if;
752
                  when queuewaitAm1 =>
753
                    putAm <= '0';
754
                         removeA1 <= '0';
755
                         statequeue <= queuewaitAm2;
756
                  when queuewaitAm2 =>
757
                         newFiFoAddr <= AmOutAddr;
758
                         newAm <= '1';
759
                         queuedone <= '1';
760
                         statequeue <= queuewait;
761
                  when queuewaitA11 =>
762
                    putA1 <= '0';
763
                         statequeue <= queuewaitA12;
764
                  when queuewaitA12 =>
765
                         newFiFoAddr <= A1OutAddr;
766
                         newAm <= '0';
767
                         removeA1 <= '0';
768
                         removeAm <= '0';
769
                         queuedone <= '1';
770
                    preempted <= '0';
771
                         statequeue <= queuewait;
772
                  when queueelim =>
773
                    putA1 <= '0';
774
                         getA1 <= '0';
775
 
776
                         if RecBuff.Am = '1' and preempted = '0' then
777
                           AmInAddr <= RecBuff.FiFoAddr;
778
                           removeAm <= '1';
779
                         elsif preempted = '0' then
780
                           A1InAddr <= RecBuff.FiFoAddr;
781
                           removeA1 <= '1';
782
                         end if;
783
 
784
                         if getA1 = '1' then
785
                           hi := '1';
786
                                preempted <= '1';
787
                           statequeue <= queuewait;
788
                         else
789
                           statequeue <= queuewaitA12;
790
                         end if;
791
                end case;
792
 
793
                interrupt <= hi;
794
                accdone <= acc;
795
 
796 11 gerhardhoh
         if putA1 = '1' or removeA1 = '1' then
797
           if removeA1 = '0' then
798
             addressA1 := std_ulogic_vector( firstA1);
799 10 gerhardhoh
                  datumA1 := A1In.valid & A1In.way & A1In.Word;
800 11 gerhardhoh
                  firstA1 <= firstA1 + 1;
801
                  counterA1 <= counterA1 + 1;
802
                  A1Outaddr <= std_ulogic_vector( firstA1);
803
                else
804
                  addressA1 := A1Inaddr( addressA1'range);
805
                  datumA1 := ( others => '0');
806 10 gerhardhoh
                end if;
807 11 gerhardhoh
                wA1 := '1';
808
         else
809
           uaddressA1 := lastA1;
810
           if (getA1 = '1' or A1Out.valid = '0') and counterA1 /= 0 then
811
             counterA1 <= counterA1 - 1;
812
             uaddressA1 := uaddressA1 + 1;
813 10 gerhardhoh
           end if;
814
           lastA1 <= uaddressA1;
815
           addressA1 := std_ulogic_vector( uaddressA1);
816 11 gerhardhoh
           wA1 := '0';
817 10 gerhardhoh
         end if;
818
 
819
         if wA1 = '1' then
820 11 gerhardhoh
           ramA1( to_integer( addressA1)) <= datumA1;
821 10 gerhardhoh
         else
822 11 gerhardhoh
           A1OutBuff := ramA1( to_integer( addressA1));
823 10 gerhardhoh
 
824
      A1Out.Word <= A1OutBuff( blocksizeld - 1 downto 0);
825
      A1Out.way <= A1OutBuff( blocksizeld + ldways downto blocksizeld);
826
                A1Out.valid <= A1OutBuff( blocksizeld + ldways + 1);
827 11 gerhardhoh
         end if;
828 10 gerhardhoh
 
829 11 gerhardhoh
         if putAm = '1' or removeAm = '1' then
830
           if removeAm = '0' then
831
             addressAm := std_ulogic_vector( firstAm);
832 10 gerhardhoh
                  datumAm := AmIn.valid & AmIn.way & AmIn.Word;
833 11 gerhardhoh
                  firstAm <= firstAm + 1;
834
                  counterAm <= counterAm + 1;
835
                  AmOutaddr <= std_ulogic_vector( firstAm);
836
                else
837
                  addressAm := AmInaddr( addressAm'range);
838
                  datumAm := ( others => '0');
839 10 gerhardhoh
                end if;
840 11 gerhardhoh
                wAm := '1';
841
         else
842
           uaddressAm := lastAm;
843
           if (getAm = '1' or AmOut.valid = '0') and counterAm /= 0 then
844
             counterAm <= counterAm - 1;
845
             uaddressAm := uaddressAm + 1;
846 10 gerhardhoh
           end if;
847
           lastAm <= uaddressAm;
848
           addressAm := std_ulogic_vector( uaddressAm);
849 11 gerhardhoh
           wAm := '0';
850 10 gerhardhoh
         end if;
851 11 gerhardhoh
 
852 10 gerhardhoh
         if wAm = '1' then
853 11 gerhardhoh
           ramAm( to_integer( addressAm)) <= datumAm;
854 10 gerhardhoh
         else
855
           AmOutBuff := ramAm( to_integer( addressAm));
856 11 gerhardhoh
 
857 10 gerhardhoh
      AmOut.Word <= AmOutBuff( blocksizeld - 1 downto 0);
858
      AmOut.way <= AmOutBuff( blocksizeld + ldways downto blocksizeld);
859
                AmOut.valid <= AmOutBuff( blocksizeld + ldways + 1);
860
         end if;
861 11 gerhardhoh
         end if;
862 10 gerhardhoh
  end if;
863
  end process queues;
864
 
865
  fullA1 <= counterA1( counterA1'high);
866 11 gerhardhoh
  emptyA1 <= '1' when counterA1 = 0 else '0';
867 10 gerhardhoh
 
868
  fullAm <= counterAm( counterAm'high);
869 11 gerhardhoh
  emptyAm <= '1' when counterAm = 0 else '0';
870 10 gerhardhoh
 
871 11 gerhardhoh
end Rtl;
872
 

powered by: WebSVN 2.1.0

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