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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [DCACHE.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 9 ns32kum
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
//
3
// This file is part of the M32632 project
4
// http://opencores.org/project,m32632
5
//
6 23 ns32kum
//      Filename:       DCACHE.v
7
//      Version:        2.0
8
//      History:        1.1 bug fix of 7 October 2015
9
//                              1.0 first release of 30 Mai 2015
10
//      Date:           14 August 2016
11 9 ns32kum
//
12 23 ns32kum
// Copyright (C) 2016 Udo Moeller
13 9 ns32kum
// 
14
// This source file may be used and distributed without 
15
// restriction provided that this copyright statement is not 
16
// removed from the file and that any derivative work contains 
17
// the original copyright notice and the associated disclaimer.
18
// 
19
// This source file is free software; you can redistribute it 
20
// and/or modify it under the terms of the GNU Lesser General 
21
// Public License as published by the Free Software Foundation;
22
// either version 2.1 of the License, or (at your option) any 
23
// later version. 
24
// 
25
// This source is distributed in the hope that it will be 
26
// useful, but WITHOUT ANY WARRANTY; without even the implied 
27
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
28
// PURPOSE. See the GNU Lesser General Public License for more 
29
// details. 
30
// 
31
// You should have received a copy of the GNU Lesser General 
32
// Public License along with this source; if not, download it 
33
// from http://www.opencores.org/lgpl.shtml 
34
// 
35
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36
//
37
//      Modules contained in this file:
38
//      DCACHE          the data cache of M32632
39
//
40 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 9 ns32kum
 
42 23 ns32kum
module DCACHE(  BCLK, MCLK,     WRCFG, DRAMSZ, MDONE, BRESET, PTB_WR, PTB_SEL, IO_READY, REG_OUT, PSR_USER, WRITE, READ, RMW,
43
                                QWATWO, WAMUX, ENWR, IC_PREQ, DMA_CHK, CFG, CINVAL, DMA_AA, DP_Q, DRAM_Q, IC_VA, ICTODC, IO_Q, IVAR,
44
                                MCR_FLAGS, PACKET, SIZE, VADR,  WADDR, WCTRL, IO_RD, IO_WR, DRAM_ACC, DRAM_WR, INIT_RUN, PTE_STAT, KDET,
45
                                HLDA, ACC_STAT, DP_DI, DRAM_A, DRAM_DI, IACC_STAT, IC_SIGS, IO_A, IO_BE, IO_DI, KOLLI_A, MMU_DIN, ZTEST,
46 9 ns32kum
                                RWVAL, RWVFLAG, DBG_IN, DBG_HIT, ENDRAM );
47
 
48
input                   BCLK;
49
input                   MCLK;
50
input                   WRCFG;
51 23 ns32kum
input    [2:0]   DRAMSZ;
52 9 ns32kum
input                   MDONE;
53
input                   BRESET;
54
input                   PTB_WR;
55
input                   PTB_SEL;
56
input                   IO_READY;
57
input                   REG_OUT;
58
input                   PSR_USER;
59
input                   WRITE;
60
input                   READ;
61
input                   ZTEST;
62
input                   RMW;
63 12 ns32kum
input                   QWATWO;
64 9 ns32kum
input                   WAMUX;
65
input                   ENWR;
66
input                   IC_PREQ;
67 23 ns32kum
input                   DMA_CHK;
68 9 ns32kum
input    [1:0]   CFG;
69
input    [1:0]   CINVAL;
70
input   [27:4]  DMA_AA;
71
input   [63:0]   DP_Q;
72
input   [31:0]   DRAM_Q;
73
input  [31:12]  IC_VA;
74
input    [3:0]   ICTODC;
75
input   [31:0]   IO_Q;
76
input    [1:0]   IVAR;
77
input    [3:0]   MCR_FLAGS;
78
input    [3:0]   PACKET;
79
input    [1:0]   SIZE;
80
input   [31:0]   VADR;
81
input   [11:2]  WADDR;
82
input    [2:0]   WCTRL;
83
input    [2:0]   RWVAL;
84
input   [40:2]  DBG_IN;
85
input                   ENDRAM;
86
 
87
output                  IO_RD;
88
output                  IO_WR;
89
output                  DRAM_ACC;
90
output                  DRAM_WR;
91
output                  INIT_RUN;
92
output   [1:0]   PTE_STAT;
93
output                  KDET;
94
output                  HLDA;
95
output                  RWVFLAG;
96
output   [5:0]   ACC_STAT;
97
output  [31:0]   DP_DI;
98
output   [3:1]  IACC_STAT;
99
output   [1:0]   IC_SIGS;
100
output  [27:4]  KOLLI_A;
101
output  [23:0]   MMU_DIN;
102
output reg      [27:0]   DRAM_A;
103
output reg      [35:0]   DRAM_DI;
104
output reg      [31:0]   IO_A;
105
output reg       [3:0]   IO_BE;
106
output reg      [31:0]   IO_DI;
107
output                  DBG_HIT;
108
 
109
reg             [31:0]   DFFE_IOR;
110
reg             [31:0]   CAPDAT;
111
reg             [31:0]   VADR_R;
112
reg                             AUX_ALT;
113
reg                             DFF_QWEXT;
114
 
115
wire    [27:4]  ADDR;
116
wire                    ADR_EQU;
117
wire                    AUX_DAT;
118
wire                    CA_HIT;
119
wire                    CA_SET;
120
wire                    CUPDATE;
121
wire                    DMA_MUX;
122
wire     [3:0]   ENBYTE;
123
wire                    HIT_ALL;
124
wire                    INIT_CA_RUN;
125
wire                    IO_ACC;
126
wire                    IO_SPACE;
127
wire                    KOMUX;
128
wire                    MMU_HIT;
129
wire                    NEW_PTB;
130
wire                    PTB_ONE;
131
wire    [27:0]   PTE_ADR;
132
wire   [31:12]  RADR;
133
wire    [11:4]  TAGA;
134
wire    [23:0]   UPDATE_C;
135
wire    [31:0]   UPDATE_M;
136
wire                    USE_CA;
137
wire                    USER;
138
wire                    WB_ACC;
139
wire                    WEMV;
140
wire                    WR_MRAM;
141
wire    [31:0]   WRDATA;
142
wire                    VIRT_A;
143
wire                    PTE_MUX;
144
wire                    WE_CV;
145
wire    [23:0]   DAT_CV;
146
wire     [4:0]   WADR_CV;
147
wire                    WRSET0;
148
wire     [3:0]   BE_SET;
149
wire    [31:0]   DAT_SET;
150
wire     [9:0]   A_SET;
151
wire                    WRSET1;
152
wire                    SEL_PTB1;
153
wire                    CI;
154
wire    [27:0]   ADR_MX;
155
wire                    LD_DRAM_A;
156
wire                    VIRTUELL;
157
wire                    NEW_PTB_RUN;
158
wire                    KILL;
159
wire                    LAST_MUX;
160
wire    [31:0]   SET_DAT;
161
wire    [31:0]   ALT_DAT;
162
wire    [31:0]   DAT_MV;
163
wire     [3:0]   RADR_MV;
164
wire     [3:0]   WADR_MV;
165
wire    [31:0]   LAST_DAT;
166
wire                    WRCRAM0;
167
wire                    WRCRAM1;
168
wire                    PROT_ERROR;
169
wire                    AUX_QW;
170
wire                    PD_MUX;
171
wire    [19:0]   PTE_DAT;
172
wire                    PKEEP;
173
 
174
// +++++++++++++++++++ Memories ++++++++++++++++++++
175
 
176
reg              [7:0]   DATA0_D [0:1023];        // Data Set 0 : 4 kBytes
177
reg              [7:0]   DATA0_C [0:1023];
178
reg              [7:0]   DATA0_B [0:1023];
179
reg              [7:0]   DATA0_A [0:1023];
180
reg             [31:0]   SET_DAT0;
181
 
182
reg              [7:0]   DATA1_D [0:1023];        // Data Set 1 : 4 kBytes
183
reg              [7:0]   DATA1_C [0:1023];
184
reg              [7:0]   DATA1_B [0:1023];
185
reg              [7:0]   DATA1_A [0:1023];
186
reg             [31:0]   SET_DAT1;
187
 
188
reg             [15:0]   TAGSET_0 [0:255];        // Tag Set for Data Set 0 : 256 entries of 16 bits
189
reg             [15:0]   TAG0;
190
 
191
reg             [15:0]   TAGSET_1 [0:255];        // Tag Set for Data Set 1 : 256 entries of 16 bits
192
reg             [15:0]   TAG1;
193
 
194 23 ns32kum
wire    [23:0]   CVALID;
195 9 ns32kum
 
196
reg             [35:0]   MMU_TAGS [0:255];        // Tag Set for MMU : 256 entries of 36 bits
197
reg             [35:0]   MMU_Q;
198
 
199
reg             [31:0]   MMU_VALID [0:15];        // Valid bits for MMU Tag Set : 16 entries of 32 bits
200
reg             [31:0]   MVALID;
201
 
202
assign  ADR_EQU = ({RADR[27:12],VADR_R[11:4]} == DRAM_A[27:4]); // Limited to 256 MB
203
 
204
assign  ALT_DAT = AUX_ALT ? DFFE_IOR : CAPDAT ;
205
 
206
assign  RADR    = VIRT_A ? MMU_Q[19:0] : VADR_R[31:12] ;
207
 
208
assign  ADR_MX  = PTE_MUX ? PTE_ADR : {RADR[27:12],VADR_R[11:2],USE_CA,CA_SET} ;
209
 
210
assign  KOLLI_A = DMA_MUX ? DMA_AA : DRAM_A[27:4] ;
211
 
212
assign  SET_DAT = CA_SET ? SET_DAT1 : SET_DAT0 ;
213
 
214
assign  VIRT_A  = ~CINVAL[0] & VIRTUELL;
215
 
216
assign  USER    = ~MCR_FLAGS[3] & PSR_USER;
217
 
218
assign  DAT_SET = WRITE ? WRDATA : DRAM_Q ;
219
 
220
assign  BE_SET  = ENBYTE | {~WRITE,~WRITE,~WRITE,~WRITE};
221
 
222 12 ns32kum
assign  ADDR    = KDET ? KOLLI_A : {RADR[27:12],VADR_R[11:4]} ;
223 9 ns32kum
 
224
assign  A_SET   = WAMUX ? WADDR : VADR_R[11:2] ;
225
 
226
assign  TAGA    = KOMUX ? KOLLI_A[11:4] : VADR[11:4] ;
227
 
228
assign  INIT_RUN = NEW_PTB_RUN | INIT_CA_RUN;
229
 
230
assign  LAST_MUX = AUX_ALT | AUX_DAT | AUX_QW;
231
 
232
assign  LAST_DAT = LAST_MUX ? ALT_DAT : SET_DAT ;
233
 
234
assign  LD_DRAM_A = ~(DRAM_ACC | PKEEP);
235
 
236
assign  ACC_STAT[4] = IO_ACC;
237
assign  ACC_STAT[5] = CA_HIT;
238
 
239
always @(posedge BCLK)
240
        if (IO_ACC)
241
                begin
242
                        IO_BE <= ENBYTE;
243
                        IO_DI <= WRDATA;
244
                        IO_A  <= {RADR[31:12],VADR_R[11:0]};
245
                end
246
 
247
always @(posedge BCLK) if (LD_DRAM_A) DRAM_A[27:0] <= ADR_MX[27:0];
248
 
249
always @(posedge BCLK) if (IO_RD) DFFE_IOR <= IO_Q;
250
 
251
always @(posedge BCLK)
252
        begin
253
                DRAM_DI   <= {(PD_MUX ? PTE_DAT[19:16] : ENBYTE),WRDATA[31:16],
254
                                          (PD_MUX ? PTE_DAT[15:0]  : WRDATA[15:0])};
255
                AUX_ALT   <= DFF_QWEXT | IO_RD;
256
                DFF_QWEXT <= IO_RD & SIZE[0] & SIZE[1];
257
                VADR_R    <= VADR;
258
        end
259
 
260
always @(posedge MCLK) if (WCTRL[2]) CAPDAT <= DRAM_Q;
261
 
262
// +++++++++++++++++++++++++  Cache Valid  +++++++++++++++++++
263
 
264 23 ns32kum
NEU_VALID       VALID_RAM(
265
        .BCLK(BCLK),
266
        .VALIN(DAT_CV),
267
        .WADR(WADR_CV),
268
        .WREN(WE_CV),
269
        .RADR(TAGA[11:7]),
270
        .VALOUT(CVALID) );
271 9 ns32kum
 
272
// +++++++++++++++++++++++++  Tag Set 0  +++++++++++++++++++++
273
 
274
always @(posedge BCLK) TAG0 <= TAGSET_0[TAGA];
275
 
276
always @(negedge BCLK) if (WRCRAM0) TAGSET_0[VADR_R[11:4]] <= RADR[27:12];
277
 
278
// +++++++++++++++++++++++++  Tag Set 1  +++++++++++++++++++++
279
 
280
always @(posedge BCLK) TAG1 <= TAGSET_1[TAGA];
281
 
282
always @(negedge BCLK) if (WRCRAM1) TAGSET_1[VADR_R[11:4]] <= RADR[27:12];
283
 
284
// +++++++++++++++++++++++++  Data Set 0  ++++++++++++++++++++
285
 
286
always @(posedge BCLK)
287
        begin
288
                SET_DAT0[31:24] <= DATA0_D[VADR[11:2]];
289
                SET_DAT0[23:16] <= DATA0_C[VADR[11:2]];
290
                SET_DAT0[15:8]  <= DATA0_B[VADR[11:2]];
291
                SET_DAT0[7:0]    <= DATA0_A[VADR[11:2]];
292
        end
293
 
294
always @(posedge MCLK)
295
        if (WRSET0)
296
                begin
297
                        if (BE_SET[3]) DATA0_D[A_SET] <= DAT_SET[31:24];
298
                        if (BE_SET[2]) DATA0_C[A_SET] <= DAT_SET[23:16];
299
                        if (BE_SET[1]) DATA0_B[A_SET] <= DAT_SET[15:8];
300
                        if (BE_SET[0]) DATA0_A[A_SET] <= DAT_SET[7:0];
301
                end
302
 
303
// +++++++++++++++++++++++++  Data Set 1  ++++++++++++++++++++
304
 
305
always @(posedge BCLK)
306
        begin
307
                SET_DAT1[31:24] <= DATA1_D[VADR[11:2]];
308
                SET_DAT1[23:16] <= DATA1_C[VADR[11:2]];
309
                SET_DAT1[15:8]  <= DATA1_B[VADR[11:2]];
310
                SET_DAT1[7:0]    <= DATA1_A[VADR[11:2]];
311
        end
312
 
313
always @(posedge MCLK)
314
        if (WRSET1)
315
                begin
316
                        if (BE_SET[3]) DATA1_D[A_SET] <= DAT_SET[31:24];
317
                        if (BE_SET[2]) DATA1_C[A_SET] <= DAT_SET[23:16];
318
                        if (BE_SET[1]) DATA1_B[A_SET] <= DAT_SET[15:8];
319
                        if (BE_SET[0]) DATA1_A[A_SET] <= DAT_SET[7:0];
320
                end
321
 
322
DCACHE_SM       DC_SM(
323
        .BCLK(BCLK),
324
        .BRESET(BRESET),
325
        .VIRTUELL(VIRTUELL),
326
        .IO_SPACE(IO_SPACE),
327
        .MDONE(MDONE),
328
        .MMU_HIT(MMU_HIT),
329
        .CA_HIT(CA_HIT),
330
        .READ(READ),
331
        .WRITE(WRITE),
332
        .ZTEST(ZTEST),
333
        .RMW(RMW),
334 12 ns32kum
        .QWATWO(QWATWO),
335 9 ns32kum
        .USE_CA(USE_CA),
336
        .PTB_WR(PTB_WR),
337
        .PTB_SEL(PTB_SEL),
338
        .SEL_PTB1(SEL_PTB1),
339
        .IO_READY(IO_READY),
340
        .USER(USER),
341
        .PROTECT(ACC_STAT[3]),
342
        .PROT_ERROR(PROT_ERROR),
343
        .ENWR(ENWR),
344
        .WB_ACC(WB_ACC),
345
        .ADR_EQU(ADR_EQU),
346
        .IC_PREQ(IC_PREQ),
347
        .CAPDAT(CAPDAT[31:0]),
348
        .CPU_OUT(DP_Q[59:44]),
349 23 ns32kum
        .DMA_CHK(DMA_CHK),
350 9 ns32kum
        .IC_VA(IC_VA),
351
        .ICTODC(ICTODC),
352
        .VADR_R(VADR_R[31:12]),
353
        .NEW_PTB(NEW_PTB),
354
        .PTB_ONE(PTB_ONE),
355
        .DRAM_ACC(DRAM_ACC),
356
        .DRAM_WR(DRAM_WR),
357
        .IO_ACC(IO_ACC),
358
        .IO_RD(IO_RD),
359
        .IO_WR(IO_WR),
360
        .PTE_STAT(PTE_STAT),
361
        .ABORT(ACC_STAT[1]),
362
        .WR_MRAM(WR_MRAM),
363
        .CUPDATE(CUPDATE),
364
        .AUX_DAT(AUX_DAT),
365
        .PTE_MUX(PTE_MUX),
366
        .ACC_OK(ACC_STAT[0]),
367
        .ABO_LEVEL1(ACC_STAT[2]),
368
        .IACC_STAT(IACC_STAT),
369
        .KOMUX(KOMUX),
370
        .KDET(KDET),
371
        .HIT_ALL(HIT_ALL),
372
        .DMA_MUX(DMA_MUX),
373
        .HLDA(HLDA),
374
        .RWVAL(RWVAL[1:0]),
375
        .RWVFLAG(RWVFLAG),
376
        .IC_SIGS(IC_SIGS),
377
        .MMU_DIN(MMU_DIN),
378
        .PD_MUX(PD_MUX),
379
        .PKEEP(PKEEP),
380
        .PTE_ADR(PTE_ADR),
381
        .PTE_DAT(PTE_DAT));
382
 
383
CA_MATCH        DCA_COMPARE(
384
        .INVAL_L(CINVAL[0]),
385
        .CI(CI),
386
        .MMU_HIT(MMU_HIT),
387
        .WRITE(WRITE),
388
        .KDET(KDET),
389 23 ns32kum
        .ADDR({RADR[31:28],ADDR}),
390 9 ns32kum
        .CFG(CFG),
391
        .ENDRAM(ENDRAM),
392
        .CVALID(CVALID),
393
        .TAG0(TAG0),
394
        .TAG1(TAG1),
395
        .CA_HIT(CA_HIT),
396
        .CA_SET(CA_SET),
397
        .WB_ACC(WB_ACC),
398
        .USE_CA(USE_CA),
399 23 ns32kum
        .DRAMSZ(DRAMSZ),
400 9 ns32kum
        .IO_SPACE(IO_SPACE),
401
        .KILL(KILL),
402
        .DC_ILO(RWVAL[2]),
403
        .UPDATE(UPDATE_C));
404
 
405
DCA_CONTROL     DCA_CTRL(
406
        .BCLK(BCLK),
407
        .MCLK(MCLK),
408
        .BRESET(BRESET),
409
        .CA_SET(CA_SET),
410
        .HIT_ALL(HIT_ALL),
411
        .UPDATE(UPDATE_C),
412
        .VADR_R(ADDR[11:7]),
413
        .DRAM_ACC(DRAM_ACC),
414
        .CUPDATE(CUPDATE),
415
        .KILL(KILL),
416
        .WRITE(WRITE),
417
        .WRCFG(WRCFG),
418
        .WCTRL(WCTRL[1:0]),
419
        .INVAL_A(CINVAL[1]),
420
        .DAT_CV(DAT_CV),
421
        .WADR_CV(WADR_CV),
422
        .WE_CV(WE_CV),
423
        .INIT_CA_RUN(INIT_CA_RUN),
424
        .WRCRAM0(WRCRAM0),
425
        .WRCRAM1(WRCRAM1),
426
        .WRSET0(WRSET0),
427
        .WRSET1(WRSET1));
428
 
429
MMU_MATCH       MMU_COMPARE(
430
        .USER(USER),
431
        .WRITE(WRITE),
432
        .READ(READ),
433
        .RMW(RMW),
434
        .IVAR(IVAR),
435
        .MCR_FLAGS(MCR_FLAGS[2:0]),
436
        .MMU_VA(MMU_Q[35:20]),
437
        .MVALID(MVALID),
438
        .VADR_R(VADR_R[31:12]),
439
        .MMU_HIT(MMU_HIT),
440
        .PROT_ERROR(PROT_ERROR),
441
        .VIRTUELL(VIRTUELL),
442
        .CI(CI),
443
        .SEL_PTB1(SEL_PTB1),
444
        .UPDATE(UPDATE_M));
445
 
446
MMU_UP  MMU_CTRL(
447
        .BCLK(BCLK),
448
        .BRESET(BRESET),
449
        .NEW_PTB(NEW_PTB),
450
        .IVAR(IVAR[1]),
451
        .PTB1(PTB_ONE),
452
        .WR_MRAM(WR_MRAM),
453
        .MVALID(MVALID),
454
        .UPDATE(UPDATE_M),
455
        .VADR(VADR[19:16]),
456
        .VADR_R(VADR_R[19:16]),
457
        .WE_MV(WEMV),
458
        .NEW_PTB_RUN(NEW_PTB_RUN),
459
        .DAT_MV(DAT_MV),
460
        .RADR_MV(RADR_MV),
461
        .WADR_MV(WADR_MV));
462
 
463
// +++++++++++++++++++++++++  MMU Valid  +++++++++++++++++++++
464
 
465
always @(posedge BCLK) MVALID <= MMU_VALID[RADR_MV];
466
 
467
always @(negedge BCLK) if (WEMV) MMU_VALID[WADR_MV] <= DAT_MV;
468
 
469
// +++++++++++++++++++++++++  MMU Tags  ++++++++++++++++++++++
470
 
471
always @(posedge BCLK) MMU_Q <= MMU_TAGS[VADR[19:12]];
472
 
473
always @(negedge BCLK) if (WR_MRAM) MMU_TAGS[VADR_R[19:12]] <= {VADR_R[31:20],MMU_DIN[23:0]};
474
 
475
RD_ALIGNER      RD_ALI(
476
        .BCLK(BCLK),
477
        .ACC_OK(ACC_STAT[0]),
478
        .REG_OUT(REG_OUT),
479
        .PACKET(PACKET),
480
        .RDDATA(LAST_DAT),
481
        .SIZE(SIZE),
482
        .CA_HIT(CA_HIT),
483
        .DP_DI(DP_DI),
484
        .AUX_QW(AUX_QW));
485
 
486
WR_ALIGNER      WR_ALI(
487
        .DP_Q(DP_Q),
488
        .PACKET(PACKET),
489
        .SIZE(SIZE),
490
        .ENBYTE(ENBYTE),
491
        .WRDATA(WRDATA));
492
 
493
DEBUG_AE DBGAE(
494
        .DBG_IN(DBG_IN),
495
        .READ(READ),
496
        .WRITE(WRITE),
497
        .USER(USER),
498
        .VIRTUELL(VIRTUELL),
499
        .ACC_OK(ACC_STAT[0]),
500
        .VADR_R(VADR_R[31:2]),
501
        .MMU_Q(MMU_Q[19:0]),
502
        .ENBYTE(ENBYTE),
503
        .DBG_HIT(DBG_HIT));
504
 
505
endmodule

powered by: WebSVN 2.1.0

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