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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [or1200/] [rtl/] [verilog/] [or1200_immu_top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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