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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_15/] [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 1200 markom
// 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 1200 markom
        mbist_si_i, mbist_so_o, mbist_ctrl_i,
126 1063 lampret
`endif
127
 
128 504 lampret
        // IC i/f
129 660 lampret
        icimmu_rty_i, icimmu_err_i, icimmu_tag_i, icimmu_adr_o, icimmu_cycstb_o, icimmu_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 1200 markom
input                   mbist_si_i;
172
input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
173
output                  mbist_so_o;
174 1063 lampret
`endif
175
 
176
//
177 504 lampret
// IC I/F
178
//
179 617 lampret
input                           icimmu_rty_i;
180 504 lampret
input                           icimmu_err_i;
181
input   [3:0]                    icimmu_tag_i;
182
output  [aw-1:0]         icimmu_adr_o;
183 660 lampret
output                          icimmu_cycstb_o;
184 504 lampret
output                          icimmu_ci_o;
185
 
186
//
187
// Internal wires and regs
188
//
189
wire                            itlb_spr_access;
190
wire    [31:`OR1200_IMMU_PS]    itlb_ppn;
191
wire                            itlb_hit;
192
wire                            itlb_uxe;
193
wire                            itlb_sxe;
194
wire    [31:0]                   itlb_dat_o;
195
wire                            itlb_en;
196
wire                            itlb_ci;
197
wire                            itlb_done;
198
wire                            fault;
199
wire                            miss;
200 942 lampret
wire                            page_cross;
201 504 lampret
reg     [31:0]                   icpu_adr_o;
202 1161 lampret
reg     [31:`OR1200_IMMU_PS]    icpu_vpn_r;
203 788 lampret
`ifdef OR1200_NO_IMMU
204
`else
205 636 lampret
reg                             itlb_en_r;
206 958 lampret
reg                             dis_spr_access;
207 788 lampret
`endif
208 504 lampret
 
209
//
210
// Implemented bits inside match and translate registers
211
//
212
// itlbwYmrX: vpn 31-10  v 0
213
// itlbwYtrX: ppn 31-10  uxe 7  sxe 6
214
//
215
// itlb memory width:
216
// 19 bits for ppn
217
// 13 bits for vpn
218
// 1 bit for valid
219
// 2 bits for protection
220
// 1 bit for cache inhibit
221
 
222
//
223
// icpu_adr_o
224
//
225
`ifdef OR1200_REGISTERED_OUTPUTS
226
always @(posedge rst or posedge clk)
227
        if (rst)
228
                icpu_adr_o <= #1 32'h0000_0100;
229
        else
230
                icpu_adr_o <= #1 icpu_adr_i;
231
`else
232
Unsupported !!!
233
`endif
234
 
235 1161 lampret
//
236
// Page cross
237
//
238
// Asserted when CPU address crosses page boundary. Most of the time it is zero.
239
//
240
assign page_cross = icpu_adr_i[31:`OR1200_IMMU_PS] != icpu_vpn_r;
241
 
242
//
243
// Register icpu_adr_i's VPN for use when IMMU is not enabled but PPN is expected to come
244
// one clock cycle after offset part.
245
//
246
always @(posedge clk or posedge rst)
247
        if (rst)
248
                icpu_vpn_r <= #1 {31-`OR1200_IMMU_PS{1'b0}};
249
        else
250
                icpu_vpn_r <= #1 icpu_adr_i[31:`OR1200_IMMU_PS];
251
 
252 504 lampret
`ifdef OR1200_NO_IMMU
253
 
254
//
255
// Put all outputs in inactive state
256
//
257
assign spr_dat_o = 32'h00000000;
258
assign icimmu_adr_o = icpu_adr_i;
259
assign icpu_tag_o = icimmu_tag_i;
260 1161 lampret
assign icimmu_cycstb_o = icpu_cycstb_i & ~page_cross;
261 617 lampret
assign icpu_rty_o = icimmu_rty_i;
262 504 lampret
assign icpu_err_o = icimmu_err_i;
263 660 lampret
assign icimmu_ci_o = `OR1200_IMMU_CI;
264 1063 lampret
`ifdef OR1200_BIST
265 1200 markom
assign mbist_so_o = mbist_si_i;
266 1063 lampret
`endif
267 504 lampret
`else
268
 
269
//
270
// ITLB SPR access
271
//
272
// 1200 - 12FF  itlbmr w0
273
// 1200 - 123F  itlbmr w0 [63:0]
274
//
275
// 1300 - 13FF  itlbtr w0
276
// 1300 - 133F  itlbtr w0 [63:0]
277
//
278 958 lampret
assign itlb_spr_access = spr_cs & ~dis_spr_access;
279 504 lampret
 
280
//
281 958 lampret
// Disable ITLB SPR access
282
//
283
// This flop is used to mask ITLB miss/fault exception
284
// during first clock cycle of accessing ITLB SPR. In
285
// subsequent clock cycles it is assumed that ITLB SPR
286
// access was accomplished and that normal instruction fetching
287
// can proceed.
288
//
289
// spr_cs sets dis_spr_access and icpu_rty_o clears it.
290
//
291
always @(posedge clk or posedge rst)
292
        if (rst)
293
                dis_spr_access <= #1 1'b0;
294
        else if (!icpu_rty_o)
295
                dis_spr_access <= #1 1'b0;
296
        else if (spr_cs)
297
                dis_spr_access <= #1 1'b1;
298
 
299
//
300 504 lampret
// Tags:
301
//
302
// OR1200_DTAG_TE - TLB miss Exception
303
// OR1200_DTAG_PE - Page fault Exception
304
//
305
assign icpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : icimmu_tag_i;
306
 
307
//
308 617 lampret
// icpu_rty_o
309
//
310
// assign icpu_rty_o = !icpu_err_o & icimmu_rty_i;
311 977 lampret
assign icpu_rty_o = icimmu_rty_i | itlb_spr_access & immu_en;
312 617 lampret
 
313
//
314 504 lampret
// icpu_err_o
315
//
316
assign icpu_err_o = miss | fault | icimmu_err_i;
317
 
318
//
319 958 lampret
// Assert itlb_en_r after one clock cycle and when there is no
320
// ITLB SPR access
321 636 lampret
//
322
always @(posedge clk or posedge rst)
323
        if (rst)
324
                itlb_en_r <= #1 1'b0;
325
        else
326 958 lampret
                itlb_en_r <= #1 itlb_en & ~itlb_spr_access;
327 636 lampret
 
328
//
329 958 lampret
// ITLB lookup successful
330 504 lampret
//
331 958 lampret
assign itlb_done = itlb_en_r & ~page_cross;
332 504 lampret
 
333
//
334
// Cut transfer if something goes wrong with translation. If IC is disabled,
335
// use delayed signals.
336
//
337 977 lampret
// assign icimmu_cycstb_o = (!ic_en & immu_en) ? ~(miss | fault) & icpu_cycstb_i & ~page_cross : (miss | fault) ? 1'b0 : icpu_cycstb_i & ~page_cross; // DL
338
assign icimmu_cycstb_o = immu_en ? ~(miss | fault) & icpu_cycstb_i & ~page_cross & itlb_done : icpu_cycstb_i & ~page_cross;
339 504 lampret
 
340
//
341
// Cache Inhibit
342
//
343 1053 lampret
// Cache inhibit is not really needed for instruction memory subsystem.
344
// If we would do it, we would do it like this.
345
// assign icimmu_ci_o = immu_en ? itlb_done & itlb_ci : `OR1200_IMMU_CI;
346
// However this causes a async combinational loop so we stick to
347
// no cache inhibit.
348
assign icimmu_ci_o = `OR1200_IMMU_CI;
349 504 lampret
 
350 942 lampret
 
351
//
352 504 lampret
// Physical address is either translated virtual address or
353
// simply equal when IMMU is disabled
354
//
355 977 lampret
assign icimmu_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
356 504 lampret
 
357
//
358
// Output to SPRS unit
359
//
360 958 lampret
assign spr_dat_o = spr_cs ? itlb_dat_o : 32'h00000000;
361 504 lampret
 
362
//
363
// Page fault exception logic
364
//
365 617 lampret
assign fault = itlb_done &
366 504 lampret
                        (  (!supv & !itlb_uxe)          // Execute in user mode not enabled
367
                        || (supv & !itlb_sxe));         // Execute in supv mode not enabled
368
 
369
//
370
// TLB Miss exception logic
371
//
372 617 lampret
assign miss = itlb_done & !itlb_hit;
373 504 lampret
 
374
//
375
// ITLB Enable
376
//
377 660 lampret
assign itlb_en = immu_en & icpu_cycstb_i;
378 504 lampret
 
379
//
380
// Instantiation of ITLB
381
//
382
or1200_immu_tlb or1200_immu_tlb(
383
        // Rst and clk
384
        .clk(clk),
385
        .rst(rst),
386
 
387
        // I/F for translation
388
        .tlb_en(itlb_en),
389
        .vaddr(icpu_adr_i),
390
        .hit(itlb_hit),
391
        .ppn(itlb_ppn),
392
        .uxe(itlb_uxe),
393
        .sxe(itlb_sxe),
394
        .ci(itlb_ci),
395
 
396 1063 lampret
`ifdef OR1200_BIST
397
        // RAM BIST
398 1200 markom
        .mbist_si_i(mbist_si_i),
399
        .mbist_so_o(mbist_so_o),
400
        .mbist_ctrl_i(mbist_ctrl_i),
401 1063 lampret
`endif
402
 
403 504 lampret
        // SPR access
404
        .spr_cs(itlb_spr_access),
405
        .spr_write(spr_write),
406
        .spr_addr(spr_addr),
407
        .spr_dat_i(spr_dat_i),
408
        .spr_dat_o(itlb_dat_o)
409
);
410
 
411
`endif
412
 
413
endmodule

powered by: WebSVN 2.1.0

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