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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_21/] [or1200/] [rtl/] [verilog/] [or1200_dmmu_top.v] - Blame information for rev 1778

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 1214 simons
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
48
// Added embedded memory QMEM.
49
//
50 1171 lampret
// Revision 1.7  2002/10/17 20:04:40  lampret
51
// Added BIST scan. Special VS RAMs need to be used to implement BIST.
52
//
53 1063 lampret
// Revision 1.6  2002/03/29 15:16:55  lampret
54
// Some of the warnings fixed.
55
//
56 788 lampret
// Revision 1.5  2002/02/14 15:34:02  simons
57
// Lapsus fixed.
58
//
59 668 simons
// Revision 1.4  2002/02/11 04:33:17  lampret
60
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
61
//
62 660 lampret
// Revision 1.3  2002/01/28 01:16:00  lampret
63
// 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.
64
//
65 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
66
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
67
//
68 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
69
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
70
//
71 504 lampret
// Revision 1.6  2001/10/21 17:57:16  lampret
72
// 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.
73
//
74
// Revision 1.5  2001/10/14 13:12:09  lampret
75
// MP3 version.
76
//
77
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
78
// no message
79
//
80
// Revision 1.1  2001/08/17 08:03:35  lampret
81
// *** empty log message ***
82
//
83
// Revision 1.2  2001/07/22 03:31:53  lampret
84
// Fixed RAM's oen bug. Cache bypass under development.
85
//
86
// Revision 1.1  2001/07/20 00:46:03  lampret
87
// Development version of RTL. Libraries are missing.
88
//
89
//
90
 
91
// synopsys translate_off
92
`include "timescale.v"
93
// synopsys translate_on
94
`include "or1200_defines.v"
95
 
96
//
97
// Data MMU
98
//
99
 
100
module or1200_dmmu_top(
101
        // Rst and clk
102
        clk, rst,
103
 
104
        // CPU i/f
105 660 lampret
        dc_en, dmmu_en, supv, dcpu_adr_i, dcpu_cycstb_i, dcpu_we_i,
106 504 lampret
        dcpu_tag_o, dcpu_err_o,
107
 
108
        // SPR access
109
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
110
 
111 1063 lampret
`ifdef OR1200_BIST
112
        // RAM BIST
113 1214 simons
        mbist_si_i, mbist_so_o, mbist_ctrl_i,
114 1063 lampret
`endif
115
 
116 504 lampret
        // DC i/f
117 1171 lampret
        qmemdmmu_err_i, qmemdmmu_tag_i, qmemdmmu_adr_o, qmemdmmu_cycstb_o, qmemdmmu_ci_o
118 504 lampret
);
119
 
120
parameter dw = `OR1200_OPERAND_WIDTH;
121
parameter aw = `OR1200_OPERAND_WIDTH;
122
 
123
//
124
// I/O
125
//
126
 
127
//
128
// Clock and reset
129
//
130
input                           clk;
131
input                           rst;
132
 
133
//
134
// CPU I/F
135
//
136
input                           dc_en;
137
input                           dmmu_en;
138
input                           supv;
139
input   [aw-1:0]         dcpu_adr_i;
140 660 lampret
input                           dcpu_cycstb_i;
141 504 lampret
input                           dcpu_we_i;
142
output  [3:0]                    dcpu_tag_o;
143
output                          dcpu_err_o;
144
 
145
//
146
// SPR access
147
//
148
input                           spr_cs;
149
input                           spr_write;
150
input   [aw-1:0]         spr_addr;
151
input   [31:0]                   spr_dat_i;
152
output  [31:0]                   spr_dat_o;
153
 
154 1063 lampret
`ifdef OR1200_BIST
155 504 lampret
//
156 1063 lampret
// RAM BIST
157
//
158 1214 simons
input mbist_si_i;
159
input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
160
output mbist_so_o;
161 1063 lampret
`endif
162
 
163
//
164 504 lampret
// DC I/F
165
//
166 1171 lampret
input                           qmemdmmu_err_i;
167
input   [3:0]                    qmemdmmu_tag_i;
168
output  [aw-1:0]         qmemdmmu_adr_o;
169
output                          qmemdmmu_cycstb_o;
170
output                          qmemdmmu_ci_o;
171 504 lampret
 
172
//
173
// Internal wires and regs
174
//
175
wire                            dtlb_spr_access;
176
wire    [31:`OR1200_DMMU_PS]    dtlb_ppn;
177
wire                            dtlb_hit;
178
wire                            dtlb_uwe;
179
wire                            dtlb_ure;
180
wire                            dtlb_swe;
181
wire                            dtlb_sre;
182
wire    [31:0]                   dtlb_dat_o;
183
wire                            dtlb_en;
184
wire                            dtlb_ci;
185
wire                            fault;
186
wire                            miss;
187 788 lampret
`ifdef OR1200_NO_DMMU
188
`else
189
reg                             dtlb_done;
190 660 lampret
reg     [31:`OR1200_DMMU_PS]    dcpu_vpn_r;
191 788 lampret
`endif
192 504 lampret
 
193
//
194
// Implemented bits inside match and translate registers
195
//
196
// dtlbwYmrX: vpn 31-10  v 0
197
// dtlbwYtrX: ppn 31-10  swe 9  sre 8  uwe 7  ure 6
198
//
199
// dtlb memory width:
200
// 19 bits for ppn
201
// 13 bits for vpn
202
// 1 bit for valid
203
// 4 bits for protection
204
// 1 bit for cache inhibit
205
 
206
`ifdef OR1200_NO_DMMU
207
 
208
//
209
// Put all outputs in inactive state
210
//
211
assign spr_dat_o = 32'h00000000;
212 1171 lampret
assign qmemdmmu_adr_o = dcpu_adr_i;
213
assign dcpu_tag_o = qmemdmmu_tag_i;
214
assign qmemdmmu_cycstb_o = dcpu_cycstb_i;
215
assign dcpu_err_o = qmemdmmu_err_i;
216
assign qmemdmmu_ci_o = `OR1200_DMMU_CI;
217 1063 lampret
`ifdef OR1200_BIST
218 1214 simons
assign mbist_so_o = mbist_si_i;
219 1063 lampret
`endif
220 504 lampret
 
221
`else
222
 
223
//
224
// DTLB SPR access
225
//
226
// 0A00 - 0AFF  dtlbmr w0
227
// 0A00 - 0A3F  dtlbmr w0 [63:0]
228
//
229
// 0B00 - 0BFF  dtlbtr w0
230
// 0B00 - 0B3F  dtlbtr w0 [63:0]
231
//
232
assign dtlb_spr_access = spr_cs;
233
 
234
//
235
// Tags:
236
//
237
// OR1200_DTAG_TE - TLB miss Exception
238
// OR1200_DTAG_PE - Page fault Exception
239
//
240 1171 lampret
assign dcpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : qmemdmmu_tag_i;
241 504 lampret
 
242
//
243
// dcpu_err_o
244
//
245 1171 lampret
assign dcpu_err_o = miss | fault | qmemdmmu_err_i;
246 504 lampret
 
247
//
248 617 lampret
// Assert dtlb_done one clock cycle after new address and dtlb_en must be active.
249 504 lampret
//
250 617 lampret
always @(posedge clk or posedge rst)
251 504 lampret
        if (rst)
252 617 lampret
                dtlb_done <= #1 1'b0;
253
        else if (dtlb_en)
254 660 lampret
                dtlb_done <= #1 dcpu_cycstb_i;
255 504 lampret
        else
256 617 lampret
                dtlb_done <= #1 1'b0;
257 504 lampret
 
258
//
259 660 lampret
// Cut transfer if something goes wrong with translation. Also delayed signals because of translation delay.
260 504 lampret
//
261 1171 lampret
assign qmemdmmu_cycstb_o = (!dc_en & dmmu_en) ? ~(miss | fault) & dtlb_done & dcpu_cycstb_i : ~(miss | fault) & dcpu_cycstb_i;
262
//assign qmemdmmu_cycstb_o = (dmmu_en) ? ~(miss | fault) & dcpu_cycstb_i : (miss | fault) ? 1'b0 : dcpu_cycstb_i;
263 504 lampret
 
264
//
265
// Cache Inhibit
266
//
267 1171 lampret
assign qmemdmmu_ci_o = dmmu_en ? dtlb_done & dtlb_ci : `OR1200_DMMU_CI;
268 504 lampret
 
269
//
270 660 lampret
// Register dcpu_adr_i's VPN for use when DMMU is not enabled but PPN is expected to come
271
// one clock cycle after offset part.
272
//
273
always @(posedge clk or posedge rst)
274
        if (rst)
275
                dcpu_vpn_r <= #1 {31-`OR1200_DMMU_PS{1'b0}};
276
        else
277
                dcpu_vpn_r <= #1 dcpu_adr_i[31:`OR1200_DMMU_PS];
278
 
279
//
280 504 lampret
// Physical address is either translated virtual address or
281
// simply equal when DMMU is disabled
282
//
283 1171 lampret
// assign qmemdmmu_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]};
284
assign qmemdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : dcpu_adr_i;
285 504 lampret
 
286
//
287
// Output to SPRS unit
288
//
289
assign spr_dat_o = dtlb_spr_access ? dtlb_dat_o : 32'h00000000;
290
 
291
//
292
// Page fault exception logic
293
//
294 617 lampret
assign fault = dtlb_done &
295 504 lampret
                        (  (!dcpu_we_i & !supv & !dtlb_ure) // Load in user mode not enabled
296
                        || (!dcpu_we_i & supv & !dtlb_sre) // Load in supv mode not enabled
297
                        || (dcpu_we_i & !supv & !dtlb_uwe) // Store in user mode not enabled
298
                        || (dcpu_we_i & supv & !dtlb_swe) ); // Store in supv mode not enabled
299
 
300
//
301
// TLB Miss exception logic
302
//
303 617 lampret
assign miss = dtlb_done & !dtlb_hit;
304 504 lampret
 
305
//
306
// DTLB Enable
307
//
308 660 lampret
assign dtlb_en = dmmu_en & dcpu_cycstb_i;
309 504 lampret
 
310
//
311
// Instantiation of DTLB
312
//
313
or1200_dmmu_tlb or1200_dmmu_tlb(
314
        // Rst and clk
315
        .clk(clk),
316
        .rst(rst),
317
 
318
        // I/F for translation
319
        .tlb_en(dtlb_en),
320
        .vaddr(dcpu_adr_i),
321
        .hit(dtlb_hit),
322
        .ppn(dtlb_ppn),
323
        .uwe(dtlb_uwe),
324
        .ure(dtlb_ure),
325
        .swe(dtlb_swe),
326
        .sre(dtlb_sre),
327
        .ci(dtlb_ci),
328
 
329 1063 lampret
`ifdef OR1200_BIST
330
        // RAM BIST
331 1214 simons
        .mbist_si_i(mbist_si_i),
332
        .mbist_so_o(mbist_so_o),
333
        .mbist_ctrl_i(mbist_ctrl_i),
334 1063 lampret
`endif
335
 
336 504 lampret
        // SPR access
337
        .spr_cs(dtlb_spr_access),
338
        .spr_write(spr_write),
339
        .spr_addr(spr_addr),
340
        .spr_dat_i(spr_dat_i),
341
        .spr_dat_o(dtlb_dat_o)
342
);
343
 
344
`endif
345
 
346
endmodule

powered by: WebSVN 2.1.0

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