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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_5/] [or1200/] [rtl/] [verilog/] [or1200_dmmu_top.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Data 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 DMMU 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 788 lampret
// Revision 1.5  2002/02/14 15:34:02  simons
48
// Lapsus fixed.
49
//
50 668 simons
// Revision 1.4  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.3  2002/01/28 01:16:00  lampret
54
// 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.
55
//
56 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
57
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
58
//
59 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
60
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
61
//
62 504 lampret
// Revision 1.6  2001/10/21 17:57:16  lampret
63
// 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.
64
//
65
// Revision 1.5  2001/10/14 13:12:09  lampret
66
// MP3 version.
67
//
68
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
69
// no message
70
//
71
// Revision 1.1  2001/08/17 08:03:35  lampret
72
// *** empty log message ***
73
//
74
// Revision 1.2  2001/07/22 03:31:53  lampret
75
// Fixed RAM's oen bug. Cache bypass under development.
76
//
77
// Revision 1.1  2001/07/20 00:46:03  lampret
78
// Development version of RTL. Libraries are missing.
79
//
80
//
81
 
82
// synopsys translate_off
83
`include "timescale.v"
84
// synopsys translate_on
85
`include "or1200_defines.v"
86
 
87
//
88
// Data MMU
89
//
90
 
91
module or1200_dmmu_top(
92
        // Rst and clk
93
        clk, rst,
94
 
95
        // CPU i/f
96 660 lampret
        dc_en, dmmu_en, supv, dcpu_adr_i, dcpu_cycstb_i, dcpu_we_i,
97 504 lampret
        dcpu_tag_o, dcpu_err_o,
98
 
99
        // SPR access
100
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
101
 
102
        // DC i/f
103 660 lampret
        dcdmmu_err_i, dcdmmu_tag_i, dcdmmu_adr_o, dcdmmu_cycstb_o, dcdmmu_ci_o
104 504 lampret
);
105
 
106
parameter dw = `OR1200_OPERAND_WIDTH;
107
parameter aw = `OR1200_OPERAND_WIDTH;
108
 
109
//
110
// I/O
111
//
112
 
113
//
114
// Clock and reset
115
//
116
input                           clk;
117
input                           rst;
118
 
119
//
120
// CPU I/F
121
//
122
input                           dc_en;
123
input                           dmmu_en;
124
input                           supv;
125
input   [aw-1:0]         dcpu_adr_i;
126 660 lampret
input                           dcpu_cycstb_i;
127 504 lampret
input                           dcpu_we_i;
128
output  [3:0]                    dcpu_tag_o;
129
output                          dcpu_err_o;
130
 
131
//
132
// SPR access
133
//
134
input                           spr_cs;
135
input                           spr_write;
136
input   [aw-1:0]         spr_addr;
137
input   [31:0]                   spr_dat_i;
138
output  [31:0]                   spr_dat_o;
139
 
140
//
141
// DC I/F
142
//
143
input                           dcdmmu_err_i;
144
input   [3:0]                    dcdmmu_tag_i;
145
output  [aw-1:0]         dcdmmu_adr_o;
146 660 lampret
output                          dcdmmu_cycstb_o;
147 504 lampret
output                          dcdmmu_ci_o;
148
 
149
//
150
// Internal wires and regs
151
//
152
wire                            dtlb_spr_access;
153
wire    [31:`OR1200_DMMU_PS]    dtlb_ppn;
154
wire                            dtlb_hit;
155
wire                            dtlb_uwe;
156
wire                            dtlb_ure;
157
wire                            dtlb_swe;
158
wire                            dtlb_sre;
159
wire    [31:0]                   dtlb_dat_o;
160
wire                            dtlb_en;
161
wire                            dtlb_ci;
162
wire                            fault;
163
wire                            miss;
164 788 lampret
`ifdef OR1200_NO_DMMU
165
`else
166
reg                             dtlb_done;
167 660 lampret
reg     [31:`OR1200_DMMU_PS]    dcpu_vpn_r;
168 788 lampret
`endif
169 504 lampret
 
170
//
171
// Implemented bits inside match and translate registers
172
//
173
// dtlbwYmrX: vpn 31-10  v 0
174
// dtlbwYtrX: ppn 31-10  swe 9  sre 8  uwe 7  ure 6
175
//
176
// dtlb memory width:
177
// 19 bits for ppn
178
// 13 bits for vpn
179
// 1 bit for valid
180
// 4 bits for protection
181
// 1 bit for cache inhibit
182
 
183
`ifdef OR1200_NO_DMMU
184
 
185
//
186
// Put all outputs in inactive state
187
//
188
assign spr_dat_o = 32'h00000000;
189
assign dcdmmu_adr_o = dcpu_adr_i;
190
assign dcpu_tag_o = dcdmmu_tag_i;
191 668 simons
assign dcdmmu_cycstb_o = dcpu_cycstb_i;
192 504 lampret
assign dcpu_err_o = dcdmmu_err_i;
193 660 lampret
assign dcdmmu_ci_o = `OR1200_DMMU_CI;
194 504 lampret
 
195
`else
196
 
197
//
198
// DTLB SPR access
199
//
200
// 0A00 - 0AFF  dtlbmr w0
201
// 0A00 - 0A3F  dtlbmr w0 [63:0]
202
//
203
// 0B00 - 0BFF  dtlbtr w0
204
// 0B00 - 0B3F  dtlbtr w0 [63:0]
205
//
206
assign dtlb_spr_access = spr_cs;
207
 
208
//
209
// Tags:
210
//
211
// OR1200_DTAG_TE - TLB miss Exception
212
// OR1200_DTAG_PE - Page fault Exception
213
//
214
assign dcpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : dcdmmu_tag_i;
215
 
216
//
217
// dcpu_err_o
218
//
219
assign dcpu_err_o = miss | fault | dcdmmu_err_i;
220
 
221
//
222 617 lampret
// Assert dtlb_done one clock cycle after new address and dtlb_en must be active.
223 504 lampret
//
224 617 lampret
always @(posedge clk or posedge rst)
225 504 lampret
        if (rst)
226 617 lampret
                dtlb_done <= #1 1'b0;
227
        else if (dtlb_en)
228 660 lampret
                dtlb_done <= #1 dcpu_cycstb_i;
229 504 lampret
        else
230 617 lampret
                dtlb_done <= #1 1'b0;
231 504 lampret
 
232
//
233 660 lampret
// Cut transfer if something goes wrong with translation. Also delayed signals because of translation delay.
234 504 lampret
//
235 660 lampret
assign dcdmmu_cycstb_o = (!dc_en & dmmu_en) ? ~(miss | fault) & dtlb_done & dcpu_cycstb_i : ~(miss | fault) & dcpu_cycstb_i;
236
//assign dcdmmu_cycstb_o = (dmmu_en) ? ~(miss | fault) & dcpu_cycstb_i : (miss | fault) ? 1'b0 : dcpu_cycstb_i;
237 504 lampret
 
238
//
239
// Cache Inhibit
240
//
241 660 lampret
assign dcdmmu_ci_o = dmmu_en ? dtlb_done & dtlb_ci : `OR1200_DMMU_CI;
242 504 lampret
 
243
//
244 660 lampret
// Register dcpu_adr_i's VPN for use when DMMU is not enabled but PPN is expected to come
245
// one clock cycle after offset part.
246
//
247
always @(posedge clk or posedge rst)
248
        if (rst)
249
                dcpu_vpn_r <= #1 {31-`OR1200_DMMU_PS{1'b0}};
250
        else
251
                dcpu_vpn_r <= #1 dcpu_adr_i[31:`OR1200_DMMU_PS];
252
 
253
//
254 504 lampret
// Physical address is either translated virtual address or
255
// simply equal when DMMU is disabled
256
//
257 660 lampret
// assign dcdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : {dcpu_vpn_r, dcpu_adr_i[`OR1200_DMMU_PS-1:0]};
258 504 lampret
assign dcdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : dcpu_adr_i;
259
 
260
//
261
// Output to SPRS unit
262
//
263
assign spr_dat_o = dtlb_spr_access ? dtlb_dat_o : 32'h00000000;
264
 
265
//
266
// Page fault exception logic
267
//
268 617 lampret
assign fault = dtlb_done &
269 504 lampret
                        (  (!dcpu_we_i & !supv & !dtlb_ure) // Load in user mode not enabled
270
                        || (!dcpu_we_i & supv & !dtlb_sre) // Load in supv mode not enabled
271
                        || (dcpu_we_i & !supv & !dtlb_uwe) // Store in user mode not enabled
272
                        || (dcpu_we_i & supv & !dtlb_swe) ); // Store in supv mode not enabled
273
 
274
//
275
// TLB Miss exception logic
276
//
277 617 lampret
assign miss = dtlb_done & !dtlb_hit;
278 504 lampret
 
279
//
280
// DTLB Enable
281
//
282 660 lampret
assign dtlb_en = dmmu_en & dcpu_cycstb_i;
283 504 lampret
 
284
//
285
// Instantiation of DTLB
286
//
287
or1200_dmmu_tlb or1200_dmmu_tlb(
288
        // Rst and clk
289
        .clk(clk),
290
        .rst(rst),
291
 
292
        // I/F for translation
293
        .tlb_en(dtlb_en),
294
        .vaddr(dcpu_adr_i),
295
        .hit(dtlb_hit),
296
        .ppn(dtlb_ppn),
297
        .uwe(dtlb_uwe),
298
        .ure(dtlb_ure),
299
        .swe(dtlb_swe),
300
        .sre(dtlb_sre),
301
        .ci(dtlb_ci),
302
 
303
        // SPR access
304
        .spr_cs(dtlb_spr_access),
305
        .spr_write(spr_write),
306
        .spr_addr(spr_addr),
307
        .spr_dat_i(spr_dat_i),
308
        .spr_dat_o(dtlb_dat_o)
309
);
310
 
311
`endif
312
 
313
endmodule

powered by: WebSVN 2.1.0

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