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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_21/] [or1200/] [rtl/] [verilog/] [or1200_immu_top.v] - Blame information for rev 958

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

powered by: WebSVN 2.1.0

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