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

Subversion Repositories or1k

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

powered by: WebSVN 2.1.0

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