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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [CACHE_LOGIK.v] - Blame information for rev 13

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: CACHE_LOGIK.v
7 12 ns32kum
// Version:  1.1 bug fix
8
// History:  1.0 first release of 30 Mai 2015
9
// Date:     7 October 2015
10 9 ns32kum
//
11
// Copyright (C) 2015 Udo Moeller
12
// 
13
// This source file may be used and distributed without 
14
// restriction provided that this copyright statement is not 
15
// removed from the file and that any derivative work contains 
16
// the original copyright notice and the associated disclaimer.
17
// 
18
// This source file is free software; you can redistribute it 
19
// and/or modify it under the terms of the GNU Lesser General 
20
// Public License as published by the Free Software Foundation;
21
// either version 2.1 of the License, or (at your option) any 
22
// later version. 
23
// 
24
// This source is distributed in the hope that it will be 
25
// useful, but WITHOUT ANY WARRANTY; without even the implied 
26
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
27
// PURPOSE. See the GNU Lesser General Public License for more 
28
// details. 
29
// 
30
// You should have received a copy of the GNU Lesser General 
31
// Public License along with this source; if not, download it 
32
// from http://www.opencores.org/lgpl.shtml 
33
// 
34
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35
//
36
//      Modules contained in this file:
37
//      1. DEBUG_AE     Debug unit for address compare in data cache
38
//      2. MMU_UP               MMU memory update and initalization controller
39
//      3. DCA_CONTROL  Data cache valid memory update and initalization controller
40
//      4. MMU_MATCH    MMU virtual address match detector
41
//      5. CA_MATCH             Cache tag match detector
42
//      6. DCACHE_SM    Data cache state machine
43
//
44 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 9 ns32kum
 
46 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47 9 ns32kum
//
48
//      1. DEBUG_AE     Debug unit for address compare in data cache
49
//
50 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51 9 ns32kum
module DEBUG_AE ( DBG_IN, READ, WRITE, USER, VIRTUELL, ACC_OK, VADR_R, MMU_Q, ENBYTE, DBG_HIT );
52
 
53
        input   [40:2]  DBG_IN;
54
 
55
        input                   READ,WRITE;
56
        input                   USER;
57
        input                   VIRTUELL;
58
        input                   ACC_OK;
59
        input   [31:2]  VADR_R;
60
        input   [19:0]   MMU_Q;
61
        input    [3:0]   ENBYTE;
62
 
63
        output                  DBG_HIT;
64
 
65
        wire                    sd,ud,crd,cwr,vnp;
66
        wire                    make;
67
        wire                    virt_adr,real_adr,page_adr;
68
        wire                    byte_en;
69
 
70
        assign sd  = DBG_IN[40];
71
        assign ud  = DBG_IN[39];
72
        assign crd = DBG_IN[38];
73
        assign cwr = DBG_IN[37];
74
        assign vnp = DBG_IN[36];
75
 
76
        assign make =  ((ud & USER) | (sd & ~USER))             // compare USER or SUPERVISOR
77
                                 & (VIRTUELL == vnp)                            // compare real or virtual address
78
                                 & ((cwr & WRITE) | (crd & READ));      // compare READ or WRITE
79
 
80
        assign virt_adr = (MMU_Q                 == DBG_IN[31:12]);
81
        assign real_adr = (VADR_R[31:12] == DBG_IN[31:12]);
82
        assign page_adr = (VADR_R[11:2]  == DBG_IN[11:2]);
83
 
84
        assign byte_en  = |(ENBYTE & DBG_IN[35:32]);
85
 
86
        assign DBG_HIT  =  ACC_OK               // all valid
87
                                         & make                 // selection is valid
88
                                         & (VIRTUELL ? virt_adr : real_adr)     & page_adr      // address
89
                                         & byte_en;             // Byte Enable
90
 
91
endmodule
92
 
93 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94 9 ns32kum
//
95
//      2. MMU_UP               MMU memory update and initalization controller
96
//
97 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98 9 ns32kum
module MMU_UP ( BCLK, BRESET, NEW_PTB, PTB1, IVAR, WR_MRAM, VADR, VADR_R, MVALID, UPDATE,
99
                                WE_MV, WADR_MV, RADR_MV, DAT_MV, NEW_PTB_RUN );
100
 
101
        input                   BCLK;
102
        input                   BRESET;
103
        input                   NEW_PTB;        // the MMU memory is cleared. Pulse of one BCLK cycle, Op-Dec is waiting
104
        input                   PTB1;           // which one
105
        input                   IVAR;
106
        input                   WR_MRAM;        // BCLK : update MRAM and MMU_VAL
107
        input  [19:16]  VADR,VADR_R;    // For update
108
        input   [31:0]   MVALID,UPDATE;
109
 
110
        output                  WE_MV;          // Write Enable MMU Valid
111
        output   [3:0]   WADR_MV,RADR_MV;
112
        output  [31:0]   DAT_MV;
113
        output                  NEW_PTB_RUN;
114
 
115
        reg                             neue_ptb,wr_flag,old_rst,run_over;
116
        reg              [3:0]   count;
117
 
118
        wire    [15:0]   new_val;
119
 
120
        assign WE_MV   = wr_flag | WR_MRAM | IVAR;      // write on falling edge BCLK
121
        assign RADR_MV = run_over ? count : VADR;
122
        assign WADR_MV = wr_flag ? (count - 4'b0001) : VADR_R;
123 11 ns32kum
        assign DAT_MV  = wr_flag ? {MVALID[31:16],new_val} : UPDATE;    // Only the matching entries are cleared : PTB0/PTB1
124 9 ns32kum
 
125
        // [31:16] Address-Space memory, [15:0] Valid memory
126 11 ns32kum
        assign new_val = neue_ptb ? (PTB1 ? (MVALID[15:0] & ~MVALID[31:16]) : (MVALID[15:0] & MVALID[31:16])) : 16'h0;
127 9 ns32kum
 
128
        always @(posedge BCLK or negedge BRESET)
129
                if (!BRESET) neue_ptb <= 1'b0;
130
                        else neue_ptb <= NEW_PTB | (neue_ptb & run_over);
131
 
132
        always @(posedge BCLK) old_rst <= BRESET;       // after Reset all will be set to 0 
133
 
134
        always @(posedge BCLK) run_over <= ((~old_rst | NEW_PTB) | (run_over & (count != 4'hF))) & BRESET;
135
 
136
        always @(posedge BCLK) count <= run_over ? count + 4'h1 : 4'h0;
137
 
138
        always @(posedge BCLK) wr_flag <= run_over;
139
 
140
        assign NEW_PTB_RUN = wr_flag;   // Info to Op-Dec
141
 
142
endmodule
143
 
144 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
145 9 ns32kum
//
146
//      3. DCA_CONTROL  Data cache valid memory update and initalization controller
147
//
148 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
149
module DCA_CONTROL ( BCLK, MCLK, BRESET, CUPDATE, DRAM_ACC, CA_SET, HIT_ALL, WRCFG, VADR_R, UPDATE, INVAL_A, WRITE,
150 9 ns32kum
                                         WCTRL, KILL, WRCRAM0, WRCRAM1, WE_CV, WADR_CV, DAT_CV, INIT_CA_RUN, WRSET0, WRSET1 );
151
 
152
        input                   BCLK;
153
        input                   MCLK;
154
        input                   BRESET;
155
        input                   CUPDATE;        // State CUPDATE : Cache is filled from DRAM
156
        input                   DRAM_ACC;
157
        input                   CA_SET;
158
        input                   HIT_ALL;        // a complete cache hit !
159
        input                   WRCFG;          // static signal : GND or VDD
160
        input   [11:7]  VADR_R;
161
        input   [23:0]   UPDATE;
162
        input                   INVAL_A;
163
        input                   WRITE;
164 11 ns32kum
        input    [1:0]   WCTRL;          // [1] : Read Burst Signal from DRAM controller, MCLK aligned. [0] : Cache inhibit
165 9 ns32kum
        input                   KILL;           // valid Ram must be updated because of collision ... or CINV
166
 
167
        output                  WRCRAM0,WRCRAM1;
168
        output                  WE_CV;
169
        output   [4:0]   WADR_CV;
170
        output  [23:0]   DAT_CV;
171
        output                  INIT_CA_RUN;
172
        output                  WRSET0,WRSET1;
173
 
174
        reg              [1:0]   state;
175
        reg              [4:0]   acount;
176
        reg                             ca_set_d;
177
 
178
        reg                             dly_bclk,zero,wr_puls;
179
        reg              [2:0]   count,refer;
180
 
181
        wire                    countf;
182
 
183
        // physical address is stored in TAG-RAM
184
 
185
        assign WRCRAM0 = (CUPDATE & ~WCTRL[0]) & ~CA_SET;
186
        assign WRCRAM1 = (CUPDATE & ~WCTRL[0]) &  CA_SET;
187
 
188
        // Load Valid RAM :
189
 
190
        assign WE_CV   = state[1] | HIT_ALL | (CUPDATE & ~WCTRL[0]) | KILL; // Hit All for "Last" Update
191
        assign WADR_CV = state[1] ? acount : VADR_R;
192
        assign DAT_CV  = state[1] ? 24'h0 : UPDATE;
193
 
194
        // Clear of Cache-Valid RAMs : 32 clocks of BCLK
195
 
196
        assign countf = (acount == 5'h1F);
197
 
198
        always @(posedge BCLK)
199
                casex ({BRESET,INVAL_A,countf,state[1:0]})
200
                  5'b0xx_xx : state <= 2'b01;
201
                  5'b1xx_01 : state <= 2'b10;           // start counter
202
                  5'b10x_00 : state <= 2'b00;           // wait ...
203
                  5'b11x_00 : state <= 2'b10;
204
                  5'b1x0_10 : state <= 2'b10;
205
                  5'b1x1_10 : state <= 2'b00;
206
                  default   : state <= 2'b0;
207
                endcase
208
 
209
        always @(posedge BCLK) if (!state[1]) acount <= 5'h0; else acount <= acount + 5'h01;
210
 
211
        assign INIT_CA_RUN = state[1];
212
 
213
        always @(posedge BCLK) if (DRAM_ACC) ca_set_d <= CA_SET;
214
 
215
        // WRITE Control in data RAMs
216
        assign WRSET0 = ( ~CA_SET & WRITE & HIT_ALL & wr_puls) | (WCTRL[1] & ~ca_set_d);
217
        assign WRSET1 = (  CA_SET & WRITE & HIT_ALL & wr_puls) | (WCTRL[1] &  ca_set_d);
218
 
219
        // ++++++++++++ Special circuit for Timing of write pulse for data RAM of data cache +++++++++
220
 
221
        always @(negedge MCLK) dly_bclk <= BCLK;
222
 
223
        always @(negedge MCLK) zero <= BCLK & ~dly_bclk;
224
 
225
        always @(posedge MCLK) if (zero) count <= 3'd0; else count <= count + 3'd1;
226
 
227
        //    count at zero , ref Wert
228
        // 1 : --- always on    5 : 100  001
229
        // 2 : 001  000                 6 : 101  010
230
        // 3 : 010  010                 7 : 110  011
231
        // 4 : 011  000                 8 : 111  100
232 11 ns32kum
        always @(posedge MCLK) if (zero) refer <= {(count == 3'd7),((count == 3'd5) | (count[1:0] == 2'b10)),(count[2] & ~count[0])};
233 9 ns32kum
 
234
        always @(posedge MCLK) wr_puls <= (count == refer) | WRCFG;
235
 
236
endmodule
237
 
238 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
239 9 ns32kum
//
240
//      4. MMU_MATCH    MMU virtual address match detector
241
//
242 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
243 9 ns32kum
module MMU_MATCH ( USER, READ, WRITE, RMW, MCR_FLAGS, MVALID, VADR_R, MMU_VA, IVAR,
244
                                   VIRTUELL, MMU_HIT , UPDATE, PROT_ERROR, CI, SEL_PTB1 );
245
 
246
        input                   USER;
247
        input                   READ;
248
        input                   WRITE;
249
        input                   RMW;
250
        input    [2:0]   MCR_FLAGS;
251
        input   [31:0]   MVALID;
252
        input  [31:12]  VADR_R;
253
        input  [31:16]  MMU_VA;
254
        input    [1:0]   IVAR;   // Invalidate Entry
255
 
256
        output                  VIRTUELL;       // only for Adress-Mux
257
        output                  MMU_HIT;
258
        output  [31:0]   UPDATE;
259
        output  reg             PROT_ERROR;     // if valid must suppress write in Write Buffer and cache
260
        output                  CI,SEL_PTB1;
261
 
262
        reg             [15:0]   maske;
263
 
264
        wire                    adr_space,as_sorte,match,alles_ok;
265
        wire    [15:0]   val_bits,as_bits;
266
        wire                    ena_prot;
267
        wire                    zugriff;
268
 
269
        assign zugriff = READ | WRITE;
270
 
271
        always @(VADR_R)
272
                case (VADR_R[15:12])
273
                  4'h0 : maske = 16'h0001;
274
                  4'h1 : maske = 16'h0002;
275
                  4'h2 : maske = 16'h0004;
276
                  4'h3 : maske = 16'h0008;
277
                  4'h4 : maske = 16'h0010;
278
                  4'h5 : maske = 16'h0020;
279
                  4'h6 : maske = 16'h0040;
280
                  4'h7 : maske = 16'h0080;
281
                  4'h8 : maske = 16'h0100;
282
                  4'h9 : maske = 16'h0200;
283
                  4'hA : maske = 16'h0400;
284
                  4'hB : maske = 16'h0800;
285
                  4'hC : maske = 16'h1000;
286
                  4'hD : maske = 16'h2000;
287
                  4'hE : maske = 16'h4000;
288
                  4'hF : maske = 16'h8000;
289
                endcase
290
 
291
        assign VIRTUELL = USER ? MCR_FLAGS[0] : MCR_FLAGS[1];
292
 
293 11 ns32kum
        assign adr_space = IVAR[1] ? IVAR[0] : (MCR_FLAGS[2] & USER);    // adr_space = IVARx ? 1 or 0 : DualSpace & TU
294 9 ns32kum
 
295
        assign as_sorte = ((MVALID[31:16] & maske) != 16'h0);
296
 
297 11 ns32kum
        assign match = (VADR_R[31:20] == MMU_VA[31:20]) & (adr_space == as_sorte) & ((MVALID[15:0] & maske) != 16'h0000);
298 9 ns32kum
 
299 11 ns32kum
        assign alles_ok = match & ( ~WRITE | MMU_VA[17] ) & ~PROT_ERROR;        // Modified - Flag : reload the PTE
300 9 ns32kum
 
301
        // if MMU_HIT = 0 then there is no Write-Buffer access abd no update of cache !
302
        assign MMU_HIT = zugriff ? ( VIRTUELL ? alles_ok : 1'b1 ) : 1'b0 ;      // MMU off : then always HIT
303
 
304
        assign val_bits = IVAR[1] ? (MVALID[15:0] & (match ? ~maske : 16'hFFFF)) : (MVALID[15:0] | maske);
305 11 ns32kum
        assign as_bits  = IVAR[1] ? MVALID[31:16] : (adr_space ? (MVALID[31:16] | maske) : (MVALID[31:16] & ~maske));
306 9 ns32kum
 
307
        assign UPDATE = {as_bits,val_bits};
308
 
309
        assign ena_prot = zugriff & VIRTUELL & match;
310
 
311
        // A Protection error must suppress write in WB and cache
312
        always @(ena_prot or MMU_VA or USER or WRITE or RMW)
313
                case ({ena_prot,MMU_VA[19:18]})
314
                   3'b100 : PROT_ERROR = USER | WRITE | RMW;    // Only Supervisor READ
315
                   3'b101 : PROT_ERROR = USER;                                  // no USER access
316
                   3'b110 : PROT_ERROR = USER & (WRITE | RMW);  // USER only READ
317
                  default : PROT_ERROR = 1'b0;
318
                endcase
319
 
320
        assign CI = VIRTUELL & MMU_VA[16];
321
        assign SEL_PTB1 = adr_space;            // For PTE update
322
 
323
endmodule
324
 
325 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
326 9 ns32kum
//
327
//      5. CA_MATCH             Cache tag match detector
328
//
329 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
330
module CA_MATCH ( CVALID, IOSEL, ADDR, TAG0, TAG1, CFG, WRITE, MMU_HIT, CI, INVAL_L, KDET, ENDRAM, DC_ILO,
331 9 ns32kum
                                  CA_HIT, CA_SET, UPDATE, IO_SPACE, USE_CA, WB_ACC, KILL );
332
 
333
        input   [23:0]   CVALID;
334
        input    [3:0]   IOSEL;
335
        input   [27:4]  ADDR;
336
        input  [27:12]  TAG0,TAG1;
337
        input    [1:0]   CFG;    // LDC , DC
338
        input                   WRITE;
339
        input                   MMU_HIT;
340
        input                   CI;
341
        input                   INVAL_L;        // invalid cache line
342
        input                   KDET;
343
        input                   ENDRAM;
344
        input                   DC_ILO;         // CBITI/SBITI special case
345
 
346
        output                  CA_HIT;
347
        output                  CA_SET; // if no Hit then says SET where to store
348
        output  [23:0]   UPDATE; // Update Information for CVALID memory 
349
        output                  IO_SPACE;
350
        output                  USE_CA;
351
        output                  WB_ACC;
352
        output                  KILL;
353
 
354
        reg              [7:0]   maske;
355
 
356
        wire                    match_0,match_1;
357
        wire                    valid_0,valid_1;
358
        wire                    select;
359
        wire                    clear;
360
        wire     [7:0]   update_0,update_1,lastinfo;
361
        wire                    sel_dram;
362
 
363
        always @(ADDR)
364
                case (ADDR[6:4])
365
                  3'h0 : maske = 8'h01;
366
                  3'h1 : maske = 8'h02;
367
                  3'h2 : maske = 8'h04;
368
                  3'h3 : maske = 8'h08;
369
                  3'h4 : maske = 8'h10;
370
                  3'h5 : maske = 8'h20;
371
                  3'h6 : maske = 8'h40;
372
                  3'h7 : maske = 8'h80;
373
                endcase
374
 
375
        assign valid_0 = (( CVALID[7:0] & maske) != 8'h00);
376
        assign valid_1 = ((CVALID[15:8] & maske) != 8'h00);
377
 
378
        assign match_0 = ( TAG0 == ADDR[27:12] );       // 4KB
379
        assign match_1 = ( TAG1 == ADDR[27:12] );       // 4KB
380
 
381
        assign CA_HIT = ((valid_0 & match_0) | (valid_1 & match_1)) & ~DC_ILO & CFG[0];
382
 
383
        // which SET is written in cache miss ? If both are valid the last used is not taken
384 11 ns32kum
        assign select = (valid_1 & valid_0) ? ~((CVALID[23:16] & maske) != 8'h00) : valid_0;    // Last-used field = CVALID[23:16]
385 9 ns32kum
 
386
        assign CA_SET = CA_HIT ? (valid_1 & match_1) : select;
387
 
388
        assign clear = INVAL_L | KDET;  // INVAL_L is from CINV
389
 
390
        assign update_0 = CA_SET ? CVALID[7:0] : (clear ? (CVALID[7:0] & ~maske) : (CVALID[7:0] | maske));
391 11 ns32kum
        assign update_1 = CA_SET ? (clear ? (CVALID[15:8] & ~maske) : (CVALID[15:8] | maske)) : CVALID[15:8];
392 9 ns32kum
 
393 11 ns32kum
        assign lastinfo = CA_HIT ? (CA_SET ? (CVALID[23:16] | maske) : (CVALID[23:16] & ~maske)) : CVALID[23:16];
394 9 ns32kum
 
395
        assign UPDATE = {lastinfo,update_1,update_0};
396
 
397
        assign KILL = clear & CA_HIT & ~CFG[1];         // only if cache is not locked
398
 
399
        assign sel_dram = (IOSEL == 4'b0000) & ENDRAM;  // at the moment the first 256 MB of memory
400
        assign IO_SPACE = ~sel_dram;                                    // not DRAM or DRAM ist off
401
        assign USE_CA   = ~CI & ~DC_ILO & CFG[0] & ~CFG[1];      // CI ? ILO ? Cache on ? Locked Cache ? 
402
        assign WB_ACC   = WRITE & MMU_HIT & sel_dram;
403
 
404
endmodule
405
 
406 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
407 9 ns32kum
//
408
//      6. DCACHE_SM    Data cache state machine
409
//
410 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411
module DCACHE_SM ( BCLK, BRESET, IO_SPACE, MDONE, IO_READY, MMU_HIT, CA_HIT, READ, WRITE, ZTEST, RMW, CAPDAT, VADR_R, IC_VA,
412
                                   USE_CA, PTB_WR, PTB_SEL, SEL_PTB1, CPU_OUT, USER, PROT_ERROR, WB_ACC, ENWR, ADR_EQU, IC_PREQ, FILLRAM, ICTODC,
413 12 ns32kum
                                   RWVAL, VIRTUELL, QWATWO,
414 11 ns32kum
                                   DRAM_ACC, DRAM_WR, IO_ACC, IO_RD, IO_WR, PTE_MUX, PD_MUX, PKEEP, PTE_ADR, PTE_DAT, HIT_ALL, ACC_OK,
415
                                   ABORT, PROTECT, IACC_STAT, ABO_LEVEL1, WR_MRAM, CUPDATE, AUX_DAT, NEW_PTB, PTB_ONE, MMU_DIN, IC_SIGS, KOMUX,
416 9 ns32kum
                                   KDET, DMA_MUX, HLDA, RWVFLAG, PTE_STAT );
417
 
418
        input                   BCLK;
419
        input                   BRESET;
420
        input                   IO_SPACE;
421
        input                   MDONE;          // Memory Done : feedback from DRAM Controller, BCLK aligned !
422
        input                   IO_READY;
423
        input                   MMU_HIT,CA_HIT;
424
        input                   READ,WRITE,ZTEST,RMW;
425
        input   [31:0]   CAPDAT;
426
        input  [31:12]  VADR_R,IC_VA;
427
        input                   USE_CA;
428
        input                   PTB_WR,PTB_SEL;
429
        input                   SEL_PTB1;
430
        input  [27:12]  CPU_OUT;        // used for PTB0/1
431
        input                   USER;
432
        input                   PROT_ERROR;
433
        input                   WB_ACC;
434
        input                   ENWR;           // Enable WRITE from DRAM
435
        input                   ADR_EQU;
436
        input                   IC_PREQ;
437
        input                   FILLRAM;
438
        input    [3:0]   ICTODC;         // multiple signals from ICACHE, especially DMA
439
        input    [1:0]   RWVAL;          // RDVAL+WRVAL Operation
440
        input                   VIRTUELL;       // for RDVAL/WRVAL
441 12 ns32kum
        input                   QWATWO;
442 9 ns32kum
 
443
        output  reg             DRAM_ACC,DRAM_WR;
444
        output                  IO_ACC,IO_RD,IO_WR;
445
        output                  PTE_MUX,PD_MUX,PKEEP;
446
        output  [27:0]   PTE_ADR;
447
        output  [19:0]   PTE_DAT;
448
        output                  HIT_ALL;
449
        output                  ACC_OK;
450
        output                  ABORT,PROTECT;
451
        output   [3:1]  IACC_STAT;
452
        output                  ABO_LEVEL1;
453
        output                  WR_MRAM;
454
        output                  CUPDATE;
455
        output                  AUX_DAT;
456
        output  reg             NEW_PTB;
457
        output  reg             PTB_ONE;
458
        output  [23:0]   MMU_DIN;
459
        output   [1:0]   IC_SIGS;
460
        output                  KOMUX;
461
        output                  KDET;           // Signal for detection of collision
462
        output                  DMA_MUX;
463
        output                  HLDA;           // active low
464
        output                  RWVFLAG;        // RDVAL/WRVAL result
465
        output   [1:0]   PTE_STAT;
466
 
467
        reg                             IO_WR,IO_RD;
468
        reg              [1:0]   pl_dat;
469
        reg              [6:0]   new_state;
470
        reg              [2:0]   cap_dat;        // only for analyse of timing
471
        reg                             mem_done;
472
        reg                             rd_done;
473
        reg              [2:0]   pstate;
474
        reg                             pte_run_wr;
475
        reg              [1:0]   prot_level1;
476
        reg                             card_flag;
477
        reg        [27:12]      ptb0,ptb1;
478
        reg                             write_ok;
479
        reg                             icp_acc;
480
        reg                             pte_modi;
481
        reg              [2:0]   ko_state;
482
        reg                             dma_run;
483
        reg                             dma_kdet;
484
        reg                             rwv_bit;
485
        reg                             prot_i;
486
        reg                             rd_rdy;
487
 
488
        wire   [27:12]  ptb10;
489
        wire   [31:12]  virtual_adr;
490
        wire                    io_busy;
491
        wire                    dram_go;
492
        wire                    pte_sel;
493
        wire                    pte_acc;
494
        wire                    do_ca_rd,pte_go,do_ic_p;
495
        wire                    valid,valid_a,refer,modi;
496
        wire                    level1,level2;
497
        wire                    rd_level2;
498
        wire                    wr_req;
499
        wire                    wr_dram;
500
        wire                    wr_icmram;
501
        wire                    rd_ende;
502
        wire                    pte_dat_8;
503
        wire                    pte_wr_sig;
504
        wire                    run_dc;
505
        wire                    kostart;
506
        wire                    dma;
507
        wire                    dma_go;
508
        wire                    zugriff;
509
        wire                    mmu_hit_i;
510
        wire                    do_zt;
511
        wire                    zt_ok;
512
        wire     [1:0]   acc_level;
513
        wire                    user_ptw,wr_ptw;
514
        wire                    pte_puls;
515
 
516
        always @(posedge BCLK) cap_dat <= CAPDAT[2:0];
517
 
518
        // if USER not virtual then ZTEST is quickly done
519
        assign zugriff = READ | WRITE | (ZTEST & VIRTUELL);
520
        assign mmu_hit_i = MMU_HIT & ~ZTEST;
521
 
522
        // WB_ACC is a successful WRITE access, ICTODC[0] is coherent Logik release : >=3 entries in FIFO
523 11 ns32kum
        assign wr_req = WB_ACC & ((ENWR & ICTODC[0]) | (DRAM_WR & ADR_EQU));     // release done by DRAM signal ENWR
524 9 ns32kum
 
525
        assign rd_ende = CA_HIT | rd_rdy;       // CA_HIT only when Cache activ !
526
 
527
        always @(        zugriff        // READ or WRITE or ZTEST , global control
528
                          or PROT_ERROR // must not be
529
                        //
530
                          or IO_SPACE   // access of IO world
531
                          or io_busy    // is access already running ?
532
                        //
533
                          or mmu_hit_i  // Hit in MMU , now only a READ can happen
534
                          or READ
535
                          or wr_req
536
                          or rd_ende    // Cache Hit
537
                        //
538
                          or DRAM_ACC   // DRAM Access : shows an active state
539
                          or pte_acc    // PTE access is running
540
                        //
541
                          or IC_PREQ    // PTE Request from ICACHE
542
                        //
543
                          or dma                // DMA Request
544
                          or dma_run )  // DMA running
545
                        //                                       #_#                      #_#                                               #_#                                     #_#
546 11 ns32kum
                casex ({zugriff,PROT_ERROR,IO_SPACE,io_busy,mmu_hit_i,READ,wr_req,rd_ende,DRAM_ACC,pte_acc,IC_PREQ,dma,dma_run})
547 9 ns32kum
                // MMU Miss : PTE load from memory , valid too if WRITE and M=0
548
                  13'b10_xx_0xxx_x0_x_x0 : new_state = 7'b0001010;      // start PTE access
549
                // IO-Address selected : external access starts if not busy because of WRITE
550
                  13'b10_10_1xxx_x0_x_x0 : new_state = 7'b0000001;
551
                // DRAM access : Cache Miss at READ : 
552
                  13'b10_0x_1100_00_x_x0 : new_state = 7'b0010010;
553
                // DRAM access : WRITE
554
                  13'b10_0x_101x_x0_x_x0 : new_state = 7'b0000100;
555
                // PTE Request ICACHE , IO access with WRITE is stored - parallel DRAM access possible
556
                  13'b0x_xx_xxxx_x0_1_00 : new_state = 7'b0101010;      // no access
557 11 ns32kum
                  13'b10_0x_1101_x0_1_x0 : new_state = 7'b0101010;      // if successful READ a PTE access can happen in parallel
558 9 ns32kum
                // DMA access. Attention : no IO-Write access in background and no ICACHE PTE access !
559
                  13'b0x_x0_xxxx_xx_0_10 : new_state = 7'b1000000;      // DMA access is started
560
                  default                                : new_state = 7'b0;
561
                endcase
562
 
563
        assign IO_ACC   = new_state[0];  // to load registers for data, addr und BE, signal one pulse
564
        assign dram_go  = new_state[1] | rd_level2 ;
565
        assign wr_dram  = new_state[2]; // pulse only
566
        assign pte_go   = new_state[3];
567
        assign do_ca_rd = new_state[4];
568
        assign do_ic_p  = new_state[5];
569
        assign dma_go   = new_state[6];
570
 
571
        // ZTEST logic is for the special case when a write access is crossing page boundaries
572
 
573
        assign do_zt = ZTEST & ~icp_acc;
574
 
575 11 ns32kum
        // 0 is pass , 1 is blocked. RWVAL[0] is 1 if WRVAL. Level 1 can only be blocked, otherwise ABORT or Level 2 is following.
576
        always @(posedge BCLK) if (mem_done) rwv_bit <= level2 ? ~(cap_dat[2] & (~RWVAL[0] | cap_dat[1])) : 1'b1;
577 9 ns32kum
 
578
        assign RWVFLAG = VIRTUELL & rwv_bit;
579
 
580 11 ns32kum
        assign zt_ok = mem_done & (RWVAL[1] ? (~cap_dat[2] | (RWVAL[0] & ~cap_dat[1]) | level2)  // Level 2 always ok
581 9 ns32kum
                                                                                : (cap_dat[0] & ~prot_i & level2) );     // "normal" access
582
 
583
        // PTE access logic, normal state machine
584
        // Updates to the PTEs are normal WRITE request to DRAM, therefore no MDONE at Write
585
 
586
        assign modi  = ~CAPDAT[8] & WRITE & write_ok & ~icp_acc;        // is "1" if the Modified Bit must be set
587
        assign refer = CAPDAT[7] | do_zt;       // Assumption "R" Bit is set if RDVAL/WRVAL and page border test
588
        assign valid = (do_zt & RWVAL[1]) ? (cap_dat[2] & (cap_dat[1] | ~RWVAL[0]) & cap_dat[0] & level1)
589
                                                                          : (cap_dat[0] & ~prot_i);
590
 
591
        always @(posedge BCLK) mem_done <= MDONE & pte_acc;
592
 
593
        always @(posedge BCLK or negedge BRESET)
594
                if (!BRESET) pstate <= 3'h0;
595
                  else
596
                        casex ({pte_go,mem_done,valid,refer,modi,pte_run_wr,pstate})
597
                          9'b0x_xxxx_000 : pstate <= 3'd0;      // nothing to do
598
                          9'b1x_xxxx_000 : pstate <= 3'd4;      // start
599
                          9'bx0_xxxx_100 : pstate <= 3'd4;      // wait for Level 1
600
                          9'bx1_0xxx_100 : pstate <= 3'd0;      // THAT'S ABORT ! 
601
                          9'bx1_11xx_100 : pstate <= 3'd6;      // PTE Level 1 was referenced , next is Level 2
602
                          9'bx1_10xx_100 : pstate <= 3'd5;      // for writing of modified Level 1 : R=1
603
                          9'bxx_xxx0_101 : pstate <= 3'd5;      // write must wait
604
                          9'bxx_xxx1_101 : pstate <= 3'd6;      // one wait cycle
605
                          9'bx0_xxxx_110 : pstate <= 3'd6;      // wait for Level 2
606
                          9'bx1_0xxx_110 : pstate <= 3'd0;      // THAT'S ABORT !
607
                          9'bx1_10xx_110 : pstate <= 3'd7;      // Update neccesary : R=0
608
                          9'bx1_110x_110 : pstate <= 3'd0;      // all ok - end
609
                          9'bx1_111x_110 : pstate <= 3'd7;      // Update neccesary : M=0
610
                          9'bxx_xxx0_111 : pstate <= 3'd7;      // write must wait
611
                          9'bxx_xxx1_111 : pstate <= 3'd0;      // continues to end of DRAM write
612
                          default            : pstate <= 3'd0;
613
                        endcase
614
 
615
        assign pte_acc =  pstate[2];
616
        assign level1  = ~pstate[1];
617
        assign level2  =  pstate[1];
618
 
619 11 ns32kum
        assign valid_a = (ZTEST & RWVAL[1]) ? (cap_dat[2] & (cap_dat[1] | ~RWVAL[0]) & ~cap_dat[0] & level1)
620 9 ns32kum
                                                                                : ~cap_dat[0];   // not do_zt because of icp_acc in ABORT
621
 
622
        assign ABORT   =   mem_done & valid_a & ~icp_acc;
623 11 ns32kum
        assign PROTECT = ((mem_done & prot_i  & ~icp_acc) | PROT_ERROR) & ~(ZTEST & RWVAL[1]);  // no Protection-Error at RDVAL/WRVAL
624 9 ns32kum
 
625
        assign IACC_STAT[1] = mem_done & ~cap_dat[0] & icp_acc;
626
        assign IACC_STAT[2] = level1;
627
        assign IACC_STAT[3] = mem_done & prot_i & icp_acc;
628
 
629
        assign ABO_LEVEL1 = level1;     // is stored in case of ABORT in ADDR_UNIT
630
 
631
        assign rd_level2 = (pstate == 3'd5) | (mem_done & (pstate == 3'd4) & refer & valid);
632
 
633
        assign WR_MRAM   = mem_done &  (pstate == 3'd6) & valid & ~icp_acc & ~ZTEST;
634
        assign wr_icmram = mem_done &  (pstate == 3'd6) & valid &  icp_acc;
635
 
636
        // Signals to the Instruction Cache
637
        // pte_acc combined with icp_acc for STATISTIK.
638
        assign IC_SIGS = {(pte_acc & icp_acc),wr_icmram};
639
 
640
        assign PTE_MUX = pte_go | (pte_acc & ~pstate[1]);
641
 
642
        assign pte_puls = mem_done & pte_acc & ~pstate[1];
643
        assign PTE_STAT = {(pte_puls & icp_acc),(pte_puls & ~icp_acc)}; // only for statistic
644
 
645 11 ns32kum
        assign PD_MUX =  ((pstate == 3'd4) & mem_done & valid & ~refer)         // switch data-MUX, write level 1 too
646 9 ns32kum
                                   | ((pstate == 3'd6) & mem_done & valid & (~refer | modi))    // write level 2
647
                                   | (((pstate == 3'd5) | (pstate == 3'd7)) & ~pte_run_wr);
648
 
649
        assign pte_wr_sig = ENWR & PD_MUX;
650
 
651
        always @(posedge BCLK) pte_run_wr <= pte_wr_sig;        // Ok-Signal for pstate State-machine
652
 
653
        assign PKEEP = (pstate == 3'd6) | ((pstate == 3'd7) & ~pte_run_wr);     // keep the DRAM address
654
 
655 11 ns32kum
        // If there is a PTE still in the data cache it must be deleted. If MMU Bits are set by the pte engine a following
656 9 ns32kum
        // READ would deliver wrong data if cache hit. Therefore access of the Tags.
657
        always @(posedge BCLK or negedge BRESET)
658
                if (!BRESET) ko_state <= 3'b000;
659
                  else
660
                        casex ({kostart,ko_state})
661
                          4'b0_000 : ko_state <= 3'b000;
662
                          4'b1_000 : ko_state <= 3'b110;
663
                          4'bx_110 : ko_state <= 3'b111;
664
                          4'bx_111 : ko_state <= 3'b100;
665
                          4'bx_100 : ko_state <= 3'b000;
666
                          default  : ko_state <= 3'b000;
667
                        endcase
668
 
669
        assign kostart = pte_go | rd_level2;
670
 
671 12 ns32kum
        // ko_state[2] suppresses ACC_OK at READ
672
        assign run_dc = (~ko_state[2] | QWATWO) & ~dma_run;     // Bugfix of 7.10.2015
673
        assign KOMUX  =   ko_state[1]                   |  DMA_MUX;
674
        assign KDET   =   ko_state[0]                    |  dma_kdet;
675 9 ns32kum
 
676 11 ns32kum
        assign HIT_ALL = MMU_HIT & CA_HIT & run_dc & ~pte_acc;  // for Update "Last-Set" , MMU_HIT contains ZUGRIFF
677 9 ns32kum
 
678
        always @(posedge BCLK or negedge BRESET)
679
                if (!BRESET) card_flag <= 1'b0;
680
                        else card_flag <= (do_ca_rd & ~rd_rdy) | (card_flag & ~MDONE);
681
 
682
        assign CUPDATE = card_flag & USE_CA & MDONE;
683
 
684
        always @(posedge BCLK) rd_rdy <= card_flag & MDONE;
685
 
686 11 ns32kum
        // The cache RAM can not provide fast enough the data after an Update. In this case a secondary data path is activated
687 9 ns32kum
        assign AUX_DAT = rd_rdy;
688
 
689
        // DRAM interface :
690
 
691
        always @(posedge BCLK)                          DRAM_WR  <= wr_dram | pte_wr_sig; // pulse
692
        always @(posedge BCLK) if (dram_go) DRAM_ACC <= 1'b1;
693
                                                         else
694
                                                                DRAM_ACC <= DRAM_ACC & ~MDONE & BRESET;
695
        // IO interface :
696
 
697
        always @(posedge BCLK)
698
          begin
699
                if (IO_ACC) IO_RD <= READ;  else IO_RD <= IO_RD & ~IO_READY & BRESET;
700
                if (IO_ACC) IO_WR <= WRITE; else IO_WR <= IO_WR & ~IO_READY & BRESET;
701
          end
702
 
703 11 ns32kum
        assign io_busy = IO_RD | IO_WR | rd_done;       // access is gone in next clock cycle, therefore blocked with "rd_done"
704 9 ns32kum
 
705 11 ns32kum
        always @(posedge BCLK) rd_done <= IO_RD & IO_READY;     // For READ one clock later for data to come through
706 9 ns32kum
 
707
        assign dma = ICTODC[2]; // external request HOLD after FF in ICACHE
708
 
709 11 ns32kum
        always @(posedge BCLK) dma_run <= (dma_go | (dma_run & dma)) & BRESET;  // stops the data access until HOLD becomes inactive
710 9 ns32kum
 
711
        assign HLDA = ~(ICTODC[1] & dma_run);   // Signal for system that the CPU has stopped accesses
712
 
713
        always @(posedge BCLK) dma_kdet <= FILLRAM;
714
        assign DMA_MUX = FILLRAM | dma_kdet;
715
 
716
        // global feedback to ADDR_UNIT, early feedback to Op-Dec : you can continue
717
 
718
        assign ACC_OK = ZTEST ? (~VIRTUELL | zt_ok)
719 11 ns32kum
                                                  : (IO_SPACE ? ((IO_ACC & WRITE) | rd_done) : (wr_dram | (READ & MMU_HIT & rd_ende & run_dc)) );
720 9 ns32kum
 
721
        // PTB1 and PTB0
722
 
723
        always @(posedge BCLK) if (PTB_WR && !PTB_SEL) ptb0 <= CPU_OUT[27:12];
724
        always @(posedge BCLK) if (PTB_WR &&  PTB_SEL) ptb1 <= CPU_OUT[27:12];
725
 
726
        always @(posedge BCLK) NEW_PTB <= PTB_WR;                       // to MMU Update Block
727
        always @(posedge BCLK) if (PTB_WR) PTB_ONE <= PTB_SEL;
728
 
729
        assign ptb10 = SEL_PTB1 ? ptb1 : ptb0;
730
 
731
        // Address multiplex between ICACHE=1 and DCACHE=0 :
732
        always @(posedge BCLK) if (pte_go) icp_acc <= do_ic_p;
733
 
734
        assign pte_sel = pte_go ? do_ic_p : icp_acc;
735
 
736
        assign virtual_adr = pte_sel ? IC_VA : VADR_R;
737
 
738
        // The 2 Address-LSB's : no full access : USE_CA = 0    
739 11 ns32kum
        assign PTE_ADR = rd_level2 ? {CAPDAT[27:12],virtual_adr[21:12],2'b00} : {ptb10,virtual_adr[31:22],2'b00};
740 9 ns32kum
 
741
        // PTE_DAT[8] is used for update of MMU_RAM.
742
        assign pte_dat_8 = (level2 & WRITE & write_ok & ~icp_acc) | CAPDAT[8];
743
        always @(posedge BCLK) pte_modi = pte_dat_8;
744
        assign PTE_DAT = {4'h3,CAPDAT[15:9],pte_modi,1'b1,CAPDAT[6:0]};  // the top 4 bits are Byte-Enable
745
 
746
        // The data for the MMU-RAM : 24 Bits , [6]=Cache Inhibit
747
        assign MMU_DIN = {pl_dat,pte_dat_8,CAPDAT[6],CAPDAT[31:12]};
748
 
749
        // Protection field
750
 
751
        always @(posedge BCLK) if (mem_done && (pstate[2:0] == 3'd4)) prot_level1 <= cap_dat[2:1];
752
 
753
        always @(prot_level1 or cap_dat)
754
                casex ({prot_level1,cap_dat[2]})
755
                  3'b11_x : pl_dat = cap_dat[2:1];
756
                  3'b10_1 : pl_dat = 2'b10;
757
                  3'b10_0 : pl_dat = cap_dat[2:1];
758
                  3'b01_1 : pl_dat = 2'b01;
759
                  3'b01_0 : pl_dat = cap_dat[2:1];
760
                  3'b00_x : pl_dat = 2'b00;
761
                endcase
762
 
763 11 ns32kum
        always @(USER or pl_dat)        // is used if no PTE update is neccesary for M-Bit if writing is not allowed
764 9 ns32kum
                casex ({USER,pl_dat})
765
                  3'b1_11 : write_ok = 1'b1;
766
                  3'b0_1x : write_ok = 1'b1;
767
                  3'b0_01 : write_ok = 1'b1;
768
                  default : write_ok = 1'b0;
769
                endcase
770
 
771
        assign acc_level = level2 ? pl_dat : cap_dat[2:1];
772
        assign user_ptw = icp_acc ? ICTODC[3] : USER;
773
        assign wr_ptw = ~icp_acc & (WRITE | RMW | (ZTEST & ~RWVAL[1])); // only data cache can write
774
 
775
        always @(acc_level or user_ptw or wr_ptw)
776
                case (acc_level)
777
                        2'b00 : prot_i = user_ptw | wr_ptw;
778
                        2'b01 : prot_i = user_ptw;
779
                        2'b10 : prot_i = user_ptw & wr_ptw;
780
                        2'b11 : prot_i = 1'b0;
781
                endcase
782
 
783
endmodule
784
 

powered by: WebSVN 2.1.0

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