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 1161

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

powered by: WebSVN 2.1.0

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