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 1063

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

powered by: WebSVN 2.1.0

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