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 660

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

powered by: WebSVN 2.1.0

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