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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [ICACHE.v] - Blame information for rev 48

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

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

powered by: WebSVN 2.1.0

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