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

Subversion Repositories or1k

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

Go to most recent revision | 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 668 simons
// Revision 1.4  2002/02/11 04:33:17  lampret
48
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
49
//
50 660 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
// Data MMU
86
//
87
 
88
module or1200_dmmu_top(
89
        // Rst and clk
90
        clk, rst,
91
 
92
        // CPU i/f
93 660 lampret
        dc_en, dmmu_en, supv, dcpu_adr_i, dcpu_cycstb_i, dcpu_we_i,
94 504 lampret
        dcpu_tag_o, dcpu_err_o,
95
 
96
        // SPR access
97
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
98
 
99
        // DC i/f
100 660 lampret
        dcdmmu_err_i, dcdmmu_tag_i, dcdmmu_adr_o, dcdmmu_cycstb_o, dcdmmu_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                           dc_en;
120
input                           dmmu_en;
121
input                           supv;
122
input   [aw-1:0]         dcpu_adr_i;
123 660 lampret
input                           dcpu_cycstb_i;
124 504 lampret
input                           dcpu_we_i;
125
output  [3:0]                    dcpu_tag_o;
126
output                          dcpu_err_o;
127
 
128
//
129
// SPR access
130
//
131
input                           spr_cs;
132
input                           spr_write;
133
input   [aw-1:0]         spr_addr;
134
input   [31:0]                   spr_dat_i;
135
output  [31:0]                   spr_dat_o;
136
 
137
//
138
// DC I/F
139
//
140
input                           dcdmmu_err_i;
141
input   [3:0]                    dcdmmu_tag_i;
142
output  [aw-1:0]         dcdmmu_adr_o;
143 660 lampret
output                          dcdmmu_cycstb_o;
144 504 lampret
output                          dcdmmu_ci_o;
145
 
146
//
147
// Internal wires and regs
148
//
149
wire                            dtlb_spr_access;
150
wire    [31:`OR1200_DMMU_PS]    dtlb_ppn;
151
wire                            dtlb_hit;
152
wire                            dtlb_uwe;
153
wire                            dtlb_ure;
154
wire                            dtlb_swe;
155
wire                            dtlb_sre;
156
wire    [31:0]                   dtlb_dat_o;
157
wire                            dtlb_en;
158
wire                            dtlb_ci;
159 617 lampret
reg                             dtlb_done;
160 504 lampret
wire                            fault;
161
wire                            miss;
162 660 lampret
reg     [31:`OR1200_DMMU_PS]    dcpu_vpn_r;
163 504 lampret
 
164
//
165
// Implemented bits inside match and translate registers
166
//
167
// dtlbwYmrX: vpn 31-10  v 0
168
// dtlbwYtrX: ppn 31-10  swe 9  sre 8  uwe 7  ure 6
169
//
170
// dtlb memory width:
171
// 19 bits for ppn
172
// 13 bits for vpn
173
// 1 bit for valid
174
// 4 bits for protection
175
// 1 bit for cache inhibit
176
 
177
`ifdef OR1200_NO_DMMU
178
 
179
//
180
// Put all outputs in inactive state
181
//
182
assign spr_dat_o = 32'h00000000;
183
assign dcdmmu_adr_o = dcpu_adr_i;
184
assign dcpu_tag_o = dcdmmu_tag_i;
185 668 simons
assign dcdmmu_cycstb_o = dcpu_cycstb_i;
186 504 lampret
assign dcpu_err_o = dcdmmu_err_i;
187 660 lampret
assign dcdmmu_ci_o = `OR1200_DMMU_CI;
188 504 lampret
 
189
`else
190
 
191
//
192
// DTLB SPR access
193
//
194
// 0A00 - 0AFF  dtlbmr w0
195
// 0A00 - 0A3F  dtlbmr w0 [63:0]
196
//
197
// 0B00 - 0BFF  dtlbtr w0
198
// 0B00 - 0B3F  dtlbtr w0 [63:0]
199
//
200
assign dtlb_spr_access = spr_cs;
201
 
202
//
203
// Tags:
204
//
205
// OR1200_DTAG_TE - TLB miss Exception
206
// OR1200_DTAG_PE - Page fault Exception
207
//
208
assign dcpu_tag_o = miss ? `OR1200_DTAG_TE : fault ? `OR1200_DTAG_PE : dcdmmu_tag_i;
209
 
210
//
211
// dcpu_err_o
212
//
213
assign dcpu_err_o = miss | fault | dcdmmu_err_i;
214
 
215
//
216 617 lampret
// Assert dtlb_done one clock cycle after new address and dtlb_en must be active.
217 504 lampret
//
218 617 lampret
always @(posedge clk or posedge rst)
219 504 lampret
        if (rst)
220 617 lampret
                dtlb_done <= #1 1'b0;
221
        else if (dtlb_en)
222 660 lampret
                dtlb_done <= #1 dcpu_cycstb_i;
223 504 lampret
        else
224 617 lampret
                dtlb_done <= #1 1'b0;
225 504 lampret
 
226
//
227 660 lampret
// Cut transfer if something goes wrong with translation. Also delayed signals because of translation delay.
228 504 lampret
//
229 660 lampret
assign dcdmmu_cycstb_o = (!dc_en & dmmu_en) ? ~(miss | fault) & dtlb_done & dcpu_cycstb_i : ~(miss | fault) & dcpu_cycstb_i;
230
//assign dcdmmu_cycstb_o = (dmmu_en) ? ~(miss | fault) & dcpu_cycstb_i : (miss | fault) ? 1'b0 : dcpu_cycstb_i;
231 504 lampret
 
232
//
233
// Cache Inhibit
234
//
235 660 lampret
assign dcdmmu_ci_o = dmmu_en ? dtlb_done & dtlb_ci : `OR1200_DMMU_CI;
236 504 lampret
 
237
//
238 660 lampret
// Register dcpu_adr_i's VPN for use when DMMU is not enabled but PPN is expected to come
239
// one clock cycle after offset part.
240
//
241
always @(posedge clk or posedge rst)
242
        if (rst)
243
                dcpu_vpn_r <= #1 {31-`OR1200_DMMU_PS{1'b0}};
244
        else
245
                dcpu_vpn_r <= #1 dcpu_adr_i[31:`OR1200_DMMU_PS];
246
 
247
//
248 504 lampret
// Physical address is either translated virtual address or
249
// simply equal when DMMU is disabled
250
//
251 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]};
252 504 lampret
assign dcdmmu_adr_o = dmmu_en ? {dtlb_ppn, dcpu_adr_i[`OR1200_DMMU_PS-1:0]} : dcpu_adr_i;
253
 
254
//
255
// Output to SPRS unit
256
//
257
assign spr_dat_o = dtlb_spr_access ? dtlb_dat_o : 32'h00000000;
258
 
259
//
260
// Page fault exception logic
261
//
262 617 lampret
assign fault = dtlb_done &
263 504 lampret
                        (  (!dcpu_we_i & !supv & !dtlb_ure) // Load in user mode not enabled
264
                        || (!dcpu_we_i & supv & !dtlb_sre) // Load in supv mode not enabled
265
                        || (dcpu_we_i & !supv & !dtlb_uwe) // Store in user mode not enabled
266
                        || (dcpu_we_i & supv & !dtlb_swe) ); // Store in supv mode not enabled
267
 
268
//
269
// TLB Miss exception logic
270
//
271 617 lampret
assign miss = dtlb_done & !dtlb_hit;
272 504 lampret
 
273
//
274
// DTLB Enable
275
//
276 660 lampret
assign dtlb_en = dmmu_en & dcpu_cycstb_i;
277 504 lampret
 
278
//
279
// Instantiation of DTLB
280
//
281
or1200_dmmu_tlb or1200_dmmu_tlb(
282
        // Rst and clk
283
        .clk(clk),
284
        .rst(rst),
285
 
286
        // I/F for translation
287
        .tlb_en(dtlb_en),
288
        .vaddr(dcpu_adr_i),
289
        .hit(dtlb_hit),
290
        .ppn(dtlb_ppn),
291
        .uwe(dtlb_uwe),
292
        .ure(dtlb_ure),
293
        .swe(dtlb_swe),
294
        .sre(dtlb_sre),
295
        .ci(dtlb_ci),
296
 
297
        // SPR access
298
        .spr_cs(dtlb_spr_access),
299
        .spr_write(spr_write),
300
        .spr_addr(spr_addr),
301
        .spr_dat_i(spr_dat_i),
302
        .spr_dat_o(dtlb_dat_o)
303
);
304
 
305
`endif
306
 
307
endmodule

powered by: WebSVN 2.1.0

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