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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_27/] [or1200/] [rtl/] [verilog/] [or1200_immu_top.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Instruction 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 IMMU blocks.                           ////
10
////                                                              ////
11
////  To Do:                                                      ////
12 1053 lampret
////   - cache inhibit                                            ////
13 504 lampret
////                                                              ////
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 1267 lampret
// Revision 1.12.4.2  2003/12/09 11:46:48  simons
48
// Mbist nameing changed, Artisan ram instance signal names fixed, some synthesis waning fixed.
49
//
50
// Revision 1.12.4.1  2003/07/08 15:36:37  lampret
51
// Added embedded memory QMEM.
52
//
53 1200 markom
// Revision 1.12  2003/06/06 02:54:47  lampret
54
// When OR1200_NO_IMMU and OR1200_NO_IC are not both defined or undefined at the same time, results in a IC bug. Fixed.
55
//
56 1161 lampret
// Revision 1.11  2002/10/17 20:04:40  lampret
57
// Added BIST scan. Special VS RAMs need to be used to implement BIST.
58
//
59 1063 lampret
// Revision 1.10  2002/09/16 03:08:56  lampret
60
// Disabled cache inhibit atttribute.
61
//
62 1053 lampret
// Revision 1.9  2002/08/18 19:54:17  lampret
63
// Added store buffer.
64
//
65 977 lampret
// Revision 1.8  2002/08/14 06:23:50  lampret
66
// Disabled ITLB translation when 1) doing access to ITLB SPRs or 2) crossing page. This modification was tested only with parts of IMMU test - remaining test cases needs to be run.
67
//
68 958 lampret
// Revision 1.7  2002/08/12 05:31:30  lampret
69
// Delayed external access at page crossing.
70
//
71 942 lampret
// Revision 1.6  2002/03/29 15:16:56  lampret
72
// Some of the warnings fixed.
73
//
74 788 lampret
// Revision 1.5  2002/02/11 04:33:17  lampret
75
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
76
//
77 660 lampret
// Revision 1.4  2002/02/01 19:56:54  lampret
78
// Fixed combinational loops.
79
//
80 636 lampret
// Revision 1.3  2002/01/28 01:16:00  lampret
81
// 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.
82
//
83 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
84
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
85
//
86 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
87
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
88
//
89 504 lampret
// Revision 1.6  2001/10/21 17:57:16  lampret
90
// 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.
91
//
92
// Revision 1.5  2001/10/14 13:12:09  lampret
93
// MP3 version.
94
//
95
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
96
// no message
97
//
98
// Revision 1.1  2001/08/17 08:03:35  lampret
99
// *** empty log message ***
100
//
101
// Revision 1.2  2001/07/22 03:31:53  lampret
102
// Fixed RAM's oen bug. Cache bypass under development.
103
//
104
// Revision 1.1  2001/07/20 00:46:03  lampret
105
// Development version of RTL. Libraries are missing.
106
//
107
//
108
 
109
// synopsys translate_off
110
`include "timescale.v"
111
// synopsys translate_on
112
`include "or1200_defines.v"
113
 
114
//
115
// Insn MMU
116
//
117
 
118
module or1200_immu_top(
119
        // Rst and clk
120
        clk, rst,
121
 
122
        // CPU i/f
123 660 lampret
        ic_en, immu_en, supv, icpu_adr_i, icpu_cycstb_i,
124 617 lampret
        icpu_adr_o, icpu_tag_o, icpu_rty_o, icpu_err_o,
125 504 lampret
 
126
        // SPR access
127
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
128
 
129 1063 lampret
`ifdef OR1200_BIST
130
        // RAM BIST
131 1200 markom
        mbist_si_i, mbist_so_o, mbist_ctrl_i,
132 1063 lampret
`endif
133
 
134 1267 lampret
        // QMEM i/f
135
        qmemimmu_rty_i, qmemimmu_err_i, qmemimmu_tag_i, qmemimmu_adr_o, qmemimmu_cycstb_o, qmemimmu_ci_o
136 504 lampret
);
137
 
138
parameter dw = `OR1200_OPERAND_WIDTH;
139
parameter aw = `OR1200_OPERAND_WIDTH;
140
 
141
//
142
// I/O
143
//
144
 
145
//
146
// Clock and reset
147
//
148
input                           clk;
149
input                           rst;
150
 
151
//
152
// CPU I/F
153
//
154
input                           ic_en;
155
input                           immu_en;
156
input                           supv;
157
input   [aw-1:0]         icpu_adr_i;
158 660 lampret
input                           icpu_cycstb_i;
159 504 lampret
output  [aw-1:0]         icpu_adr_o;
160
output  [3:0]                    icpu_tag_o;
161 617 lampret
output                          icpu_rty_o;
162 504 lampret
output                          icpu_err_o;
163
 
164
//
165
// SPR access
166
//
167
input                           spr_cs;
168
input                           spr_write;
169
input   [aw-1:0]         spr_addr;
170
input   [31:0]                   spr_dat_i;
171
output  [31:0]                   spr_dat_o;
172
 
173 1063 lampret
`ifdef OR1200_BIST
174 504 lampret
//
175 1063 lampret
// RAM BIST
176
//
177 1267 lampret
input mbist_si_i;
178
input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
179
output mbist_so_o;
180 1063 lampret
`endif
181
 
182
//
183 504 lampret
// IC I/F
184
//
185 1267 lampret
input                           qmemimmu_rty_i;
186
input                           qmemimmu_err_i;
187
input   [3:0]                    qmemimmu_tag_i;
188
output  [aw-1:0]         qmemimmu_adr_o;
189
output                          qmemimmu_cycstb_o;
190
output                          qmemimmu_ci_o;
191 504 lampret
 
192
//
193
// Internal wires and regs
194
//
195
wire                            itlb_spr_access;
196
wire    [31:`OR1200_IMMU_PS]    itlb_ppn;
197
wire                            itlb_hit;
198
wire                            itlb_uxe;
199
wire                            itlb_sxe;
200
wire    [31:0]                   itlb_dat_o;
201
wire                            itlb_en;
202
wire                            itlb_ci;
203
wire                            itlb_done;
204
wire                            fault;
205
wire                            miss;
206 942 lampret
wire                            page_cross;
207 504 lampret
reg     [31:0]                   icpu_adr_o;
208 1161 lampret
reg     [31:`OR1200_IMMU_PS]    icpu_vpn_r;
209 788 lampret
`ifdef OR1200_NO_IMMU
210
`else
211 636 lampret
reg                             itlb_en_r;
212 958 lampret
reg                             dis_spr_access;
213 788 lampret
`endif
214 504 lampret
 
215
//
216
// Implemented bits inside match and translate registers
217
//
218
// itlbwYmrX: vpn 31-10  v 0
219
// itlbwYtrX: ppn 31-10  uxe 7  sxe 6
220
//
221
// itlb memory width:
222
// 19 bits for ppn
223
// 13 bits for vpn
224
// 1 bit for valid
225
// 2 bits for protection
226
// 1 bit for cache inhibit
227
 
228
//
229
// icpu_adr_o
230
//
231
`ifdef OR1200_REGISTERED_OUTPUTS
232
always @(posedge rst or posedge clk)
233
        if (rst)
234
                icpu_adr_o <= #1 32'h0000_0100;
235
        else
236
                icpu_adr_o <= #1 icpu_adr_i;
237
`else
238
Unsupported !!!
239
`endif
240
 
241 1161 lampret
//
242
// Page cross
243
//
244
// Asserted when CPU address crosses page boundary. Most of the time it is zero.
245
//
246
assign page_cross = icpu_adr_i[31:`OR1200_IMMU_PS] != icpu_vpn_r;
247
 
248
//
249
// Register icpu_adr_i's VPN for use when IMMU is not enabled but PPN is expected to come
250
// one clock cycle after offset part.
251
//
252
always @(posedge clk or posedge rst)
253
        if (rst)
254
                icpu_vpn_r <= #1 {31-`OR1200_IMMU_PS{1'b0}};
255
        else
256
                icpu_vpn_r <= #1 icpu_adr_i[31:`OR1200_IMMU_PS];
257
 
258 504 lampret
`ifdef OR1200_NO_IMMU
259
 
260
//
261
// Put all outputs in inactive state
262
//
263
assign spr_dat_o = 32'h00000000;
264 1267 lampret
assign qmemimmu_adr_o = icpu_adr_i;
265
assign icpu_tag_o = qmemimmu_tag_i;
266
assign qmemimmu_cycstb_o = icpu_cycstb_i & ~page_cross;
267
assign icpu_rty_o = qmemimmu_rty_i;
268
assign icpu_err_o = qmemimmu_err_i;
269
assign qmemimmu_ci_o = `OR1200_IMMU_CI;
270 1063 lampret
`ifdef OR1200_BIST
271 1200 markom
assign mbist_so_o = mbist_si_i;
272 1063 lampret
`endif
273 504 lampret
`else
274
 
275
//
276
// ITLB SPR access
277
//
278
// 1200 - 12FF  itlbmr w0
279
// 1200 - 123F  itlbmr w0 [63:0]
280
//
281
// 1300 - 13FF  itlbtr w0
282
// 1300 - 133F  itlbtr w0 [63:0]
283
//
284 958 lampret
assign itlb_spr_access = spr_cs & ~dis_spr_access;
285 504 lampret
 
286
//
287 958 lampret
// Disable ITLB SPR access
288
//
289
// This flop is used to mask ITLB miss/fault exception
290
// during first clock cycle of accessing ITLB SPR. In
291
// subsequent clock cycles it is assumed that ITLB SPR
292
// access was accomplished and that normal instruction fetching
293
// can proceed.
294
//
295
// spr_cs sets dis_spr_access and icpu_rty_o clears it.
296
//
297
always @(posedge clk or posedge rst)
298
        if (rst)
299
                dis_spr_access <= #1 1'b0;
300
        else if (!icpu_rty_o)
301
                dis_spr_access <= #1 1'b0;
302
        else if (spr_cs)
303
                dis_spr_access <= #1 1'b1;
304
 
305
//
306 504 lampret
// Tags:
307
//
308
// OR1200_DTAG_TE - TLB miss Exception
309
// OR1200_DTAG_PE - Page fault Exception
310
//
311 1267 lampret
assign icpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : qmemimmu_tag_i;
312 504 lampret
 
313
//
314 617 lampret
// icpu_rty_o
315
//
316 1267 lampret
// assign icpu_rty_o = !icpu_err_o & qmemimmu_rty_i;
317
assign icpu_rty_o = qmemimmu_rty_i | itlb_spr_access & immu_en;
318 617 lampret
 
319
//
320 504 lampret
// icpu_err_o
321
//
322 1267 lampret
assign icpu_err_o = miss | fault | qmemimmu_err_i;
323 504 lampret
 
324
//
325 958 lampret
// Assert itlb_en_r after one clock cycle and when there is no
326
// ITLB SPR access
327 636 lampret
//
328
always @(posedge clk or posedge rst)
329
        if (rst)
330
                itlb_en_r <= #1 1'b0;
331
        else
332 958 lampret
                itlb_en_r <= #1 itlb_en & ~itlb_spr_access;
333 636 lampret
 
334
//
335 958 lampret
// ITLB lookup successful
336 504 lampret
//
337 958 lampret
assign itlb_done = itlb_en_r & ~page_cross;
338 504 lampret
 
339
//
340
// Cut transfer if something goes wrong with translation. If IC is disabled,
341
// use delayed signals.
342
//
343 1267 lampret
// assign qmemimmu_cycstb_o = (!ic_en & immu_en) ? ~(miss | fault) & icpu_cycstb_i & ~page_cross : (miss | fault) ? 1'b0 : icpu_cycstb_i & ~page_cross; // DL
344
assign qmemimmu_cycstb_o = immu_en ? ~(miss | fault) & icpu_cycstb_i & ~page_cross & itlb_done : icpu_cycstb_i & ~page_cross;
345 504 lampret
 
346
//
347
// Cache Inhibit
348
//
349 1053 lampret
// Cache inhibit is not really needed for instruction memory subsystem.
350
// If we would do it, we would do it like this.
351 1267 lampret
// assign qmemimmu_ci_o = immu_en ? itlb_done & itlb_ci : `OR1200_IMMU_CI;
352 1053 lampret
// However this causes a async combinational loop so we stick to
353
// no cache inhibit.
354 1267 lampret
assign qmemimmu_ci_o = `OR1200_IMMU_CI;
355 504 lampret
 
356 942 lampret
 
357
//
358 504 lampret
// Physical address is either translated virtual address or
359
// simply equal when IMMU is disabled
360
//
361 1267 lampret
assign qmemimmu_adr_o = itlb_done ? {itlb_ppn, icpu_adr_i[`OR1200_IMMU_PS-1:0]} : {icpu_vpn_r, icpu_adr_i[`OR1200_IMMU_PS-1:0]}; // DL: immu_en
362 504 lampret
 
363
//
364
// Output to SPRS unit
365
//
366 958 lampret
assign spr_dat_o = spr_cs ? itlb_dat_o : 32'h00000000;
367 504 lampret
 
368
//
369
// Page fault exception logic
370
//
371 617 lampret
assign fault = itlb_done &
372 504 lampret
                        (  (!supv & !itlb_uxe)          // Execute in user mode not enabled
373
                        || (supv & !itlb_sxe));         // Execute in supv mode not enabled
374
 
375
//
376
// TLB Miss exception logic
377
//
378 617 lampret
assign miss = itlb_done & !itlb_hit;
379 504 lampret
 
380
//
381
// ITLB Enable
382
//
383 660 lampret
assign itlb_en = immu_en & icpu_cycstb_i;
384 504 lampret
 
385
//
386
// Instantiation of ITLB
387
//
388
or1200_immu_tlb or1200_immu_tlb(
389
        // Rst and clk
390
        .clk(clk),
391
        .rst(rst),
392
 
393
        // I/F for translation
394
        .tlb_en(itlb_en),
395
        .vaddr(icpu_adr_i),
396
        .hit(itlb_hit),
397
        .ppn(itlb_ppn),
398
        .uxe(itlb_uxe),
399
        .sxe(itlb_sxe),
400
        .ci(itlb_ci),
401
 
402 1063 lampret
`ifdef OR1200_BIST
403
        // RAM BIST
404 1200 markom
        .mbist_si_i(mbist_si_i),
405
        .mbist_so_o(mbist_so_o),
406
        .mbist_ctrl_i(mbist_ctrl_i),
407 1063 lampret
`endif
408
 
409 504 lampret
        // SPR access
410
        .spr_cs(itlb_spr_access),
411
        .spr_write(spr_write),
412
        .spr_addr(spr_addr),
413
        .spr_dat_i(spr_dat_i),
414
        .spr_dat_o(itlb_dat_o)
415
);
416
 
417
`endif
418
 
419
endmodule

powered by: WebSVN 2.1.0

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