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

Subversion Repositories m32632

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

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

powered by: WebSVN 2.1.0

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