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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [rtl/] [verilog/] [components/] [or1200r2/] [or1200_immu_top.v] - Blame information for rev 41

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 unneback
//////////////////////////////////////////////////////////////////////
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
    // SR Interface
133
    boot_adr_sel_i,
134
 
135
        // SPR access
136
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
137
 
138
`ifdef OR1200_BIST
139
        // RAM BIST
140
        mbist_si_i, mbist_so_o, mbist_ctrl_i,
141
`endif
142
 
143
        // QMEM i/f
144
        qmemimmu_rty_i, qmemimmu_err_i, qmemimmu_tag_i, qmemimmu_adr_o, qmemimmu_cycstb_o, qmemimmu_ci_o
145
);
146
 
147
parameter dw = `OR1200_OPERAND_WIDTH;
148
parameter aw = `OR1200_OPERAND_WIDTH;
149
 
150
//
151
// I/O
152
//
153
 
154
//
155
// Clock and reset
156
//
157
input                           clk;
158
input                           rst;
159
 
160
//
161
// CPU I/F
162
//
163
input                           ic_en;
164
input                           immu_en;
165
input                           supv;
166
input   [aw-1:0]         icpu_adr_i;
167
input                           icpu_cycstb_i;
168
output  [aw-1:0]         icpu_adr_o;
169
output  [3:0]                    icpu_tag_o;
170
output                          icpu_rty_o;
171
output                          icpu_err_o;
172
 
173
//
174
// SR Interface
175
//
176
input                           boot_adr_sel_i;
177
 
178
//
179
// SPR access
180
//
181
input                           spr_cs;
182
input                           spr_write;
183
input   [aw-1:0]         spr_addr;
184
input   [31:0]                   spr_dat_i;
185
output  [31:0]                   spr_dat_o;
186
 
187
`ifdef OR1200_BIST
188
//
189
// RAM BIST
190
//
191
input mbist_si_i;
192
input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
193
output mbist_so_o;
194
`endif
195
 
196
//
197
// IC I/F
198
//
199
input                           qmemimmu_rty_i;
200
input                           qmemimmu_err_i;
201
input   [3:0]                    qmemimmu_tag_i;
202
output  [aw-1:0]         qmemimmu_adr_o;
203
output                          qmemimmu_cycstb_o;
204
output                          qmemimmu_ci_o;
205
 
206
//
207
// Internal wires and regs
208
//
209
wire                            itlb_spr_access;
210
wire    [31:`OR1200_IMMU_PS]    itlb_ppn;
211
wire                            itlb_hit;
212
wire                            itlb_uxe;
213
wire                            itlb_sxe;
214
wire    [31:0]                   itlb_dat_o;
215
wire                            itlb_en;
216
wire                            itlb_ci;
217
wire                            itlb_done;
218
wire                            fault;
219
wire                            miss;
220
wire                            page_cross;
221
reg             [31:0]           icpu_adr_default;
222
wire    [31:0]           icpu_adr_boot;
223
reg                                     icpu_adr_select;
224
reg             [31:0]           icpu_adr_o;
225
reg     [31:`OR1200_IMMU_PS]    icpu_vpn_r;
226
`ifdef OR1200_NO_IMMU
227
`else
228
reg                             itlb_en_r;
229
reg                             dis_spr_access_frst_clk;
230
reg                             dis_spr_access_scnd_clk;
231
`endif
232
 
233
//
234
// Implemented bits inside match and translate registers
235
//
236
// itlbwYmrX: vpn 31-10  v 0
237
// itlbwYtrX: ppn 31-10  uxe 7  sxe 6
238
//
239
// itlb memory width:
240
// 19 bits for ppn
241
// 13 bits for vpn
242
// 1 bit for valid
243
// 2 bits for protection
244
// 1 bit for cache inhibit
245
 
246
//
247
// icpu_adr_o
248
//
249
`ifdef OR1200_REGISTERED_OUTPUTS
250
always @(posedge rst or posedge clk)
251
        if (rst) begin
252
                icpu_adr_default <= #1 32'h0000_0100;
253
        icpu_adr_select  <= #1 1'b1;
254
    end
255
        else if (icpu_adr_select) begin
256
                icpu_adr_default <= #1 icpu_adr_boot;
257
        icpu_adr_select  <= #1 1'b0;
258
    end
259
    else begin
260
        icpu_adr_default <= #1 icpu_adr_i;
261
    end
262
 
263
assign icpu_adr_boot = {(boot_adr_sel_i ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), 12'h100} ;
264
 
265
always @(icpu_adr_boot or icpu_adr_default or icpu_adr_select)
266
    if (icpu_adr_select)
267
        icpu_adr_o = icpu_adr_boot ;
268
    else
269
        icpu_adr_o = icpu_adr_default ;
270
`else
271
Unsupported !!!
272
`endif
273
 
274
//
275
// Page cross
276
//
277
// Asserted when CPU address crosses page boundary. Most of the time it is zero.
278
//
279
assign page_cross = icpu_adr_i[31:`OR1200_IMMU_PS] != icpu_vpn_r;
280
 
281
//
282
// Register icpu_adr_i's VPN for use when IMMU is not enabled but PPN is expected to come
283
// one clock cycle after offset part.
284
//
285
always @(posedge clk or posedge rst)
286
        if (rst)
287
                icpu_vpn_r <= #1 {32-`OR1200_IMMU_PS{1'b0}};
288
        else
289
                icpu_vpn_r <= #1 icpu_adr_i[31:`OR1200_IMMU_PS];
290
 
291
`ifdef OR1200_NO_IMMU
292
 
293
//
294
// Put all outputs in inactive state
295
//
296
assign spr_dat_o = 32'h00000000;
297
assign qmemimmu_adr_o = icpu_adr_i;
298
assign icpu_tag_o = qmemimmu_tag_i;
299
assign qmemimmu_cycstb_o = icpu_cycstb_i & ~page_cross;
300
assign icpu_rty_o = qmemimmu_rty_i;
301
assign icpu_err_o = qmemimmu_err_i;
302
assign qmemimmu_ci_o = `OR1200_IMMU_CI;
303
`ifdef OR1200_BIST
304
assign mbist_so_o = mbist_si_i;
305
`endif
306
`else
307
 
308
//
309
// ITLB SPR access
310
//
311
// 1200 - 12FF  itlbmr w0
312
// 1200 - 123F  itlbmr w0 [63:0]
313
//
314
// 1300 - 13FF  itlbtr w0
315
// 1300 - 133F  itlbtr w0 [63:0]
316
//
317
assign itlb_spr_access = spr_cs & ~dis_spr_access_scnd_clk;
318
 
319
//
320
// Disable ITLB SPR access
321
//
322
// This flops are used to mask ITLB miss/fault exception
323
// during first & second clock cycles of accessing ITLB SPR. In
324
// subsequent clock cycles it is assumed that ITLB SPR
325
// access was accomplished and that normal instruction fetching
326
// can proceed.
327
//
328
// spr_cs sets dis_spr_access_frst_clk and icpu_rty_o clears it.
329
// dis_spr_access_frst_clk  sets dis_spr_access_scnd_clk and 
330
// icpu_rty_o clears it.
331
//
332
always @(posedge clk or posedge rst)
333
        if (rst)
334
                dis_spr_access_frst_clk  <= #1 1'b0;
335
        else if (!icpu_rty_o)
336
                dis_spr_access_frst_clk  <= #1 1'b0;
337
        else if (spr_cs)
338
                dis_spr_access_frst_clk  <= #1 1'b1;
339
 
340
always @(posedge clk or posedge rst)
341
        if (rst)
342
                dis_spr_access_scnd_clk  <= #1 1'b0;
343
        else if (!icpu_rty_o)
344
                dis_spr_access_scnd_clk  <= #1 1'b0;
345
        else if (dis_spr_access_frst_clk)
346
                dis_spr_access_scnd_clk  <= #1 1'b1;
347
 
348
//
349
// Tags:
350
//
351
// OR1200_DTAG_TE - TLB miss Exception
352
// OR1200_DTAG_PE - Page fault Exception
353
//
354
assign icpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : qmemimmu_tag_i;
355
 
356
//
357
// icpu_rty_o
358
//
359
// assign icpu_rty_o = !icpu_err_o & qmemimmu_rty_i;
360
assign icpu_rty_o = qmemimmu_rty_i | itlb_spr_access & immu_en;
361
 
362
//
363
// icpu_err_o
364
//
365
assign icpu_err_o = miss | fault | qmemimmu_err_i;
366
 
367
//
368
// Assert itlb_en_r after one clock cycle and when there is no
369
// ITLB SPR access
370
//
371
always @(posedge clk or posedge rst)
372
        if (rst)
373
                itlb_en_r <= #1 1'b0;
374
        else
375
                itlb_en_r <= #1 itlb_en & ~itlb_spr_access;
376
 
377
//
378
// ITLB lookup successful
379
//
380
assign itlb_done = itlb_en_r & ~page_cross;
381
 
382
//
383
// Cut transfer if something goes wrong with translation. If IC is disabled,
384
// use delayed signals.
385
//
386
// 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
387
assign qmemimmu_cycstb_o = immu_en ? ~(miss | fault) & icpu_cycstb_i & ~page_cross & itlb_done : icpu_cycstb_i & ~page_cross;
388
 
389
//
390
// Cache Inhibit
391
//
392
// Cache inhibit is not really needed for instruction memory subsystem.
393
// If we would doq it, we would doq it like this.
394
// assign qmemimmu_ci_o = immu_en ? itlb_done & itlb_ci : `OR1200_IMMU_CI;
395
// However this causes a async combinational loop so we stick to
396
// no cache inhibit.
397
assign qmemimmu_ci_o = `OR1200_IMMU_CI;
398
 
399
 
400
//
401
// Physical address is either translated virtual address or
402
// simply equal when IMMU is disabled
403
//
404
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
405
 
406
reg     [31:0]                  spr_dat_o;
407
//
408
// Output to SPRS unit
409
//
410
//always @(posedge clk `OR1200_RST_EVENT)
411
//    if (rst == `OR1200_RST_ACT)
412
   always @ (posedge clk or posedge rst)
413
     if (rst)
414
        spr_dat_o <= #1 32'h0000_0000;
415
    else if (spr_cs & !dis_spr_access_scnd_clk)
416
        spr_dat_o <= #1 itlb_dat_o;
417
 
418
//
419
// Page fault exception logic
420
//
421
assign fault = itlb_done &
422
                        (  (!supv & !itlb_uxe)          // Execute in user mode not enabled
423
                        || (supv & !itlb_sxe));         // Execute in supv mode not enabled
424
 
425
//
426
// TLB Miss exception logic
427
//
428
assign miss = itlb_done & !itlb_hit;
429
 
430
//
431
// ITLB Enable
432
//
433
assign itlb_en = immu_en & icpu_cycstb_i;
434
 
435
//
436
// Instantiation of ITLB
437
//
438
or1200_immu_tlb or1200_immu_tlb(
439
        // Rst and clk
440
        .clk(clk),
441
        .rst(rst),
442
 
443
        // I/F for translation
444
        .tlb_en(itlb_en),
445
        .vaddr(icpu_adr_i),
446
        .hit(itlb_hit),
447
        .ppn(itlb_ppn),
448
        .uxe(itlb_uxe),
449
        .sxe(itlb_sxe),
450
        .ci(itlb_ci),
451
 
452
`ifdef OR1200_BIST
453
        // RAM BIST
454
        .mbist_si_i(mbist_si_i),
455
        .mbist_so_o(mbist_so_o),
456
        .mbist_ctrl_i(mbist_ctrl_i),
457
`endif
458
 
459
        // SPR access
460
        .spr_cs(itlb_spr_access),
461
        .spr_write(spr_write),
462
        .spr_addr(spr_addr),
463
        .spr_dat_i(spr_dat_i),
464
        .spr_dat_o(itlb_dat_o)
465
);
466
 
467
`endif
468
 
469
endmodule

powered by: WebSVN 2.1.0

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