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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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