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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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