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

Subversion Repositories or1k

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

powered by: WebSVN 2.1.0

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