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 660

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

powered by: WebSVN 2.1.0

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