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

Subversion Repositories or1k

[/] [or1k/] [branches/] [branch_qmem/] [or1200/] [rtl/] [verilog/] [or1200_dmmu_top.v] - Blame information for rev 1063

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

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Data MMU top level                                 ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Instantiation of all DMMU blocks.                           ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 1063 lampret
// Revision 1.6  2002/03/29 15:16:55  lampret
48
// Some of the warnings fixed.
49
//
50 788 lampret
// Revision 1.5  2002/02/14 15:34:02  simons
51
// Lapsus fixed.
52
//
53 668 simons
// Revision 1.4  2002/02/11 04:33:17  lampret
54
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
55
//
56 660 lampret
// Revision 1.3  2002/01/28 01:16:00  lampret
57
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
58
//
59 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
60
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
61
//
62 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
63
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
64
//
65 504 lampret
// Revision 1.6  2001/10/21 17:57:16  lampret
66
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
67
//
68
// Revision 1.5  2001/10/14 13:12:09  lampret
69
// MP3 version.
70
//
71
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
72
// no message
73
//
74
// Revision 1.1  2001/08/17 08:03:35  lampret
75
// *** empty log message ***
76
//
77
// Revision 1.2  2001/07/22 03:31:53  lampret
78
// Fixed RAM's oen bug. Cache bypass under development.
79
//
80
// Revision 1.1  2001/07/20 00:46:03  lampret
81
// Development version of RTL. Libraries are missing.
82
//
83
//
84
 
85
// synopsys translate_off
86
`include "timescale.v"
87
// synopsys translate_on
88
`include "or1200_defines.v"
89
 
90
//
91
// Data MMU
92
//
93
 
94
module or1200_dmmu_top(
95
        // Rst and clk
96
        clk, rst,
97
 
98
        // CPU i/f
99 660 lampret
        dc_en, dmmu_en, supv, dcpu_adr_i, dcpu_cycstb_i, dcpu_we_i,
100 504 lampret
        dcpu_tag_o, dcpu_err_o,
101
 
102
        // SPR access
103
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
104
 
105 1063 lampret
`ifdef OR1200_BIST
106
        // RAM BIST
107
        scanb_rst, scanb_si, scanb_so, scanb_en, scanb_clk,
108
`endif
109
 
110 504 lampret
        // DC i/f
111 660 lampret
        dcdmmu_err_i, dcdmmu_tag_i, dcdmmu_adr_o, dcdmmu_cycstb_o, dcdmmu_ci_o
112 504 lampret
);
113
 
114
parameter dw = `OR1200_OPERAND_WIDTH;
115
parameter aw = `OR1200_OPERAND_WIDTH;
116
 
117
//
118
// I/O
119
//
120
 
121
//
122
// Clock and reset
123
//
124
input                           clk;
125
input                           rst;
126
 
127
//
128
// CPU I/F
129
//
130
input                           dc_en;
131
input                           dmmu_en;
132
input                           supv;
133
input   [aw-1:0]         dcpu_adr_i;
134 660 lampret
input                           dcpu_cycstb_i;
135 504 lampret
input                           dcpu_we_i;
136
output  [3:0]                    dcpu_tag_o;
137
output                          dcpu_err_o;
138
 
139
//
140
// SPR access
141
//
142
input                           spr_cs;
143
input                           spr_write;
144
input   [aw-1:0]         spr_addr;
145
input   [31:0]                   spr_dat_i;
146
output  [31:0]                   spr_dat_o;
147
 
148 1063 lampret
`ifdef OR1200_BIST
149 504 lampret
//
150 1063 lampret
// RAM BIST
151
//
152
input                           scanb_rst,
153
                                scanb_si,
154
                                scanb_en,
155
                                scanb_clk;
156
output                          scanb_so;
157
`endif
158
 
159
//
160 504 lampret
// DC I/F
161
//
162
input                           dcdmmu_err_i;
163
input   [3:0]                    dcdmmu_tag_i;
164
output  [aw-1:0]         dcdmmu_adr_o;
165 660 lampret
output                          dcdmmu_cycstb_o;
166 504 lampret
output                          dcdmmu_ci_o;
167
 
168
//
169
// Internal wires and regs
170
//
171
wire                            dtlb_spr_access;
172
wire    [31:`OR1200_DMMU_PS]    dtlb_ppn;
173
wire                            dtlb_hit;
174
wire                            dtlb_uwe;
175
wire                            dtlb_ure;
176
wire                            dtlb_swe;
177
wire                            dtlb_sre;
178
wire    [31:0]                   dtlb_dat_o;
179
wire                            dtlb_en;
180
wire                            dtlb_ci;
181
wire                            fault;
182
wire                            miss;
183 788 lampret
`ifdef OR1200_NO_DMMU
184
`else
185
reg                             dtlb_done;
186 660 lampret
reg     [31:`OR1200_DMMU_PS]    dcpu_vpn_r;
187 788 lampret
`endif
188 504 lampret
 
189
//
190
// Implemented bits inside match and translate registers
191
//
192
// dtlbwYmrX: vpn 31-10  v 0
193
// dtlbwYtrX: ppn 31-10  swe 9  sre 8  uwe 7  ure 6
194
//
195
// dtlb memory width:
196
// 19 bits for ppn
197
// 13 bits for vpn
198
// 1 bit for valid
199
// 4 bits for protection
200
// 1 bit for cache inhibit
201
 
202
`ifdef OR1200_NO_DMMU
203
 
204
//
205
// Put all outputs in inactive state
206
//
207
assign spr_dat_o = 32'h00000000;
208
assign dcdmmu_adr_o = dcpu_adr_i;
209
assign dcpu_tag_o = dcdmmu_tag_i;
210 668 simons
assign dcdmmu_cycstb_o = dcpu_cycstb_i;
211 504 lampret
assign dcpu_err_o = dcdmmu_err_i;
212 660 lampret
assign dcdmmu_ci_o = `OR1200_DMMU_CI;
213 1063 lampret
`ifdef OR1200_BIST
214
assign scanb_so = scanb_si;
215
`endif
216 504 lampret
 
217
`else
218
 
219
//
220
// DTLB SPR access
221
//
222
// 0A00 - 0AFF  dtlbmr w0
223
// 0A00 - 0A3F  dtlbmr w0 [63:0]
224
//
225
// 0B00 - 0BFF  dtlbtr w0
226
// 0B00 - 0B3F  dtlbtr w0 [63:0]
227
//
228
assign dtlb_spr_access = spr_cs;
229
 
230
//
231
// Tags:
232
//
233
// OR1200_DTAG_TE - TLB miss Exception
234
// OR1200_DTAG_PE - Page fault Exception
235
//
236
assign dcpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : dcdmmu_tag_i;
237
 
238
//
239
// dcpu_err_o
240
//
241
assign dcpu_err_o = miss | fault | dcdmmu_err_i;
242
 
243
//
244 617 lampret
// Assert dtlb_done one clock cycle after new address and dtlb_en must be active.
245 504 lampret
//
246 617 lampret
always @(posedge clk or posedge rst)
247 504 lampret
        if (rst)
248 617 lampret
                dtlb_done <= #1 1'b0;
249
        else if (dtlb_en)
250 660 lampret
                dtlb_done <= #1 dcpu_cycstb_i;
251 504 lampret
        else
252 617 lampret
                dtlb_done <= #1 1'b0;
253 504 lampret
 
254
//
255 660 lampret
// Cut transfer if something goes wrong with translation. Also delayed signals because of translation delay.
256 504 lampret
//
257 660 lampret
assign dcdmmu_cycstb_o = (!dc_en & dmmu_en) ? ~(miss | fault) & dtlb_done & dcpu_cycstb_i : ~(miss | fault) & dcpu_cycstb_i;
258
//assign dcdmmu_cycstb_o = (dmmu_en) ? ~(miss | fault) & dcpu_cycstb_i : (miss | fault) ? 1'b0 : dcpu_cycstb_i;
259 504 lampret
 
260
//
261
// Cache Inhibit
262
//
263 660 lampret
assign dcdmmu_ci_o = dmmu_en ? dtlb_done & dtlb_ci : `OR1200_DMMU_CI;
264 504 lampret
 
265
//
266 660 lampret
// Register dcpu_adr_i's VPN for use when DMMU is not enabled but PPN is expected to come
267
// one clock cycle after offset part.
268
//
269
always @(posedge clk or posedge rst)
270
        if (rst)
271
                dcpu_vpn_r <= #1 {31-`OR1200_DMMU_PS{1'b0}};
272
        else
273
                dcpu_vpn_r <= #1 dcpu_adr_i[31:`OR1200_DMMU_PS];
274
 
275
//
276 504 lampret
// Physical address is either translated virtual address or
277
// simply equal when DMMU is disabled
278
//
279 660 lampret
// assign dcdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : {dcpu_vpn_r, dcpu_adr_i[`OR1200_DMMU_PS-1:0]};
280 504 lampret
assign dcdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : dcpu_adr_i;
281
 
282
//
283
// Output to SPRS unit
284
//
285
assign spr_dat_o = dtlb_spr_access ? dtlb_dat_o : 32'h00000000;
286
 
287
//
288
// Page fault exception logic
289
//
290 617 lampret
assign fault = dtlb_done &
291 504 lampret
                        (  (!dcpu_we_i & !supv & !dtlb_ure) // Load in user mode not enabled
292
                        || (!dcpu_we_i & supv & !dtlb_sre) // Load in supv mode not enabled
293
                        || (dcpu_we_i & !supv & !dtlb_uwe) // Store in user mode not enabled
294
                        || (dcpu_we_i & supv & !dtlb_swe) ); // Store in supv mode not enabled
295
 
296
//
297
// TLB Miss exception logic
298
//
299 617 lampret
assign miss = dtlb_done & !dtlb_hit;
300 504 lampret
 
301
//
302
// DTLB Enable
303
//
304 660 lampret
assign dtlb_en = dmmu_en & dcpu_cycstb_i;
305 504 lampret
 
306
//
307
// Instantiation of DTLB
308
//
309
or1200_dmmu_tlb or1200_dmmu_tlb(
310
        // Rst and clk
311
        .clk(clk),
312
        .rst(rst),
313
 
314
        // I/F for translation
315
        .tlb_en(dtlb_en),
316
        .vaddr(dcpu_adr_i),
317
        .hit(dtlb_hit),
318
        .ppn(dtlb_ppn),
319
        .uwe(dtlb_uwe),
320
        .ure(dtlb_ure),
321
        .swe(dtlb_swe),
322
        .sre(dtlb_sre),
323
        .ci(dtlb_ci),
324
 
325 1063 lampret
`ifdef OR1200_BIST
326
        // RAM BIST
327
        .scanb_rst(scanb_rst),
328
        .scanb_si(scanb_si),
329
        .scanb_so(scanb_so),
330
        .scanb_en(scanb_en),
331
        .scanb_clk(scanb_clk),
332
`endif
333
 
334 504 lampret
        // SPR access
335
        .spr_cs(dtlb_spr_access),
336
        .spr_write(spr_write),
337
        .spr_addr(spr_addr),
338
        .spr_dat_i(spr_dat_i),
339
        .spr_dat_o(dtlb_dat_o)
340
);
341
 
342
`endif
343
 
344
endmodule

powered by: WebSVN 2.1.0

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