| 1 |
10 |
unneback |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// OR1200's DC FSM ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
| 6 |
|
|
//// http://www.opencores.org/cores/or1k/ ////
|
| 7 |
|
|
//// ////
|
| 8 |
|
|
//// Description ////
|
| 9 |
|
|
//// Data cache state machine ////
|
| 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 |
|
|
// Revision 1.8 2004/04/05 08:29:57 lampret
|
| 48 |
|
|
// Merged branch_qmem into main tree.
|
| 49 |
|
|
//
|
| 50 |
|
|
// Revision 1.7.4.1 2003/07/08 15:36:37 lampret
|
| 51 |
|
|
// Added embedded memory QMEM.
|
| 52 |
|
|
//
|
| 53 |
|
|
// Revision 1.7 2002/03/29 15:16:55 lampret
|
| 54 |
|
|
// Some of the warnings fixed.
|
| 55 |
|
|
//
|
| 56 |
|
|
// Revision 1.6 2002/03/28 19:10:40 lampret
|
| 57 |
|
|
// Optimized cache controller FSM.
|
| 58 |
|
|
//
|
| 59 |
|
|
// Revision 1.1.1.1 2002/03/21 16:55:45 lampret
|
| 60 |
|
|
// First import of the "new" XESS XSV environment.
|
| 61 |
|
|
//
|
| 62 |
|
|
//
|
| 63 |
|
|
// Revision 1.5 2002/02/11 04:33:17 lampret
|
| 64 |
|
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
| 65 |
|
|
//
|
| 66 |
|
|
// Revision 1.4 2002/02/01 19:56:54 lampret
|
| 67 |
|
|
// Fixed combinational loops.
|
| 68 |
|
|
//
|
| 69 |
|
|
// Revision 1.3 2002/01/28 01:15:59 lampret
|
| 70 |
|
|
// 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.
|
| 71 |
|
|
//
|
| 72 |
|
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
| 73 |
|
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
| 74 |
|
|
//
|
| 75 |
|
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
| 76 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
| 77 |
|
|
//
|
| 78 |
|
|
// Revision 1.9 2001/10/21 17:57:16 lampret
|
| 79 |
|
|
// 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.
|
| 80 |
|
|
//
|
| 81 |
|
|
// Revision 1.8 2001/10/19 23:28:46 lampret
|
| 82 |
|
|
// Fixed some synthesis warnings. Configured with caches and MMUs.
|
| 83 |
|
|
//
|
| 84 |
|
|
// Revision 1.7 2001/10/14 13:12:09 lampret
|
| 85 |
|
|
// MP3 version.
|
| 86 |
|
|
//
|
| 87 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:35 igorm
|
| 88 |
|
|
// no message
|
| 89 |
|
|
//
|
| 90 |
|
|
// Revision 1.2 2001/08/09 13:39:33 lampret
|
| 91 |
|
|
// Major clean-up.
|
| 92 |
|
|
//
|
| 93 |
|
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
| 94 |
|
|
// Development version of RTL. Libraries are missing.
|
| 95 |
|
|
//
|
| 96 |
|
|
//
|
| 97 |
|
|
|
| 98 |
|
|
// synopsys translate_off
|
| 99 |
|
|
`include "timescale.v"
|
| 100 |
|
|
// synopsys translate_on
|
| 101 |
|
|
`include "or1200_defines.v"
|
| 102 |
|
|
|
| 103 |
|
|
`define OR1200_DCFSM_IDLE 3'd0
|
| 104 |
|
|
`define OR1200_DCFSM_CLOAD 3'd1
|
| 105 |
|
|
`define OR1200_DCFSM_LREFILL3 3'd2
|
| 106 |
|
|
`define OR1200_DCFSM_CSTORE 3'd3
|
| 107 |
|
|
`define OR1200_DCFSM_SREFILL4 3'd4
|
| 108 |
|
|
|
| 109 |
|
|
//
|
| 110 |
|
|
// Data cache FSM for cache line of 16 bytes (4x singleword)
|
| 111 |
|
|
//
|
| 112 |
|
|
|
| 113 |
|
|
module or1200_dc_fsm(
|
| 114 |
|
|
// Clock and reset
|
| 115 |
|
|
clk, rst,
|
| 116 |
|
|
|
| 117 |
|
|
// Internal i/f to top level DC
|
| 118 |
|
|
dc_en, dcqmem_cycstb_i, dcqmem_ci_i, dcqmem_we_i, dcqmem_sel_i,
|
| 119 |
|
|
tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
|
| 120 |
|
|
dcram_we, biu_read, biu_write, first_hit_ack, first_miss_ack, first_miss_err,
|
| 121 |
|
|
burst, tag_we, dc_addr
|
| 122 |
|
|
);
|
| 123 |
|
|
|
| 124 |
|
|
//
|
| 125 |
|
|
// I/O
|
| 126 |
|
|
//
|
| 127 |
|
|
input clk;
|
| 128 |
|
|
input rst;
|
| 129 |
|
|
input dc_en;
|
| 130 |
|
|
input dcqmem_cycstb_i;
|
| 131 |
|
|
input dcqmem_ci_i;
|
| 132 |
|
|
input dcqmem_we_i;
|
| 133 |
|
|
input [3:0] dcqmem_sel_i;
|
| 134 |
|
|
input tagcomp_miss;
|
| 135 |
|
|
input biudata_valid;
|
| 136 |
|
|
input biudata_error;
|
| 137 |
|
|
input [31:0] start_addr;
|
| 138 |
|
|
output [31:0] saved_addr;
|
| 139 |
|
|
output [3:0] dcram_we;
|
| 140 |
|
|
output biu_read;
|
| 141 |
|
|
output biu_write;
|
| 142 |
|
|
output first_hit_ack;
|
| 143 |
|
|
output first_miss_ack;
|
| 144 |
|
|
output first_miss_err;
|
| 145 |
|
|
output burst;
|
| 146 |
|
|
output tag_we;
|
| 147 |
|
|
output [31:0] dc_addr;
|
| 148 |
|
|
|
| 149 |
|
|
//
|
| 150 |
|
|
// Internal wires and regs
|
| 151 |
|
|
//
|
| 152 |
|
|
reg [31:0] saved_addr_r;
|
| 153 |
|
|
reg [2:0] state;
|
| 154 |
|
|
reg [2:0] cnt;
|
| 155 |
|
|
reg hitmiss_eval;
|
| 156 |
|
|
reg store;
|
| 157 |
|
|
reg load;
|
| 158 |
|
|
reg cache_inhibit;
|
| 159 |
|
|
wire first_store_hit_ack;
|
| 160 |
|
|
|
| 161 |
|
|
//
|
| 162 |
|
|
// Generate of DCRAM write enables
|
| 163 |
|
|
//
|
| 164 |
|
|
assign dcram_we = {4{load & biudata_valid & !cache_inhibit}} | {4{first_store_hit_ack}} & dcqmem_sel_i;
|
| 165 |
|
|
assign tag_we = biu_read & biudata_valid & !cache_inhibit;
|
| 166 |
|
|
|
| 167 |
|
|
//
|
| 168 |
|
|
// BIU read and write
|
| 169 |
|
|
//
|
| 170 |
|
|
assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
|
| 171 |
|
|
assign biu_write = store;
|
| 172 |
|
|
|
| 173 |
|
|
assign dc_addr = (biu_read | biu_write) & !hitmiss_eval ? saved_addr : start_addr;
|
| 174 |
|
|
assign saved_addr = saved_addr_r;
|
| 175 |
|
|
|
| 176 |
|
|
//
|
| 177 |
|
|
// Assert for cache hit first word ready
|
| 178 |
|
|
// Assert for store cache hit first word ready
|
| 179 |
|
|
// Assert for cache miss first word stored/loaded OK
|
| 180 |
|
|
// Assert for cache miss first word stored/loaded with an error
|
| 181 |
|
|
//
|
| 182 |
|
|
assign first_hit_ack = (state == `OR1200_DCFSM_CLOAD) & !tagcomp_miss & !cache_inhibit & !dcqmem_ci_i | first_store_hit_ack;
|
| 183 |
|
|
assign first_store_hit_ack = (state == `OR1200_DCFSM_CSTORE) & !tagcomp_miss & biudata_valid & !cache_inhibit & !dcqmem_ci_i;
|
| 184 |
|
|
assign first_miss_ack = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_valid;
|
| 185 |
|
|
assign first_miss_err = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_error;
|
| 186 |
|
|
|
| 187 |
|
|
//
|
| 188 |
|
|
// Assert burst when doing reload of complete cache line
|
| 189 |
|
|
//
|
| 190 |
|
|
assign burst = (state == `OR1200_DCFSM_CLOAD) & tagcomp_miss & !cache_inhibit
|
| 191 |
|
|
| (state == `OR1200_DCFSM_LREFILL3)
|
| 192 |
|
|
`ifdef OR1200_DC_STORE_REFILL
|
| 193 |
|
|
| (state == `OR1200_DCFSM_SREFILL4)
|
| 194 |
|
|
`endif
|
| 195 |
|
|
;
|
| 196 |
|
|
|
| 197 |
|
|
//
|
| 198 |
|
|
// Main DC FSM
|
| 199 |
|
|
//
|
| 200 |
|
|
always @(posedge clk or posedge rst) begin
|
| 201 |
|
|
if (rst) begin
|
| 202 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 203 |
|
|
saved_addr_r <= #1 32'b0;
|
| 204 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 205 |
|
|
store <= #1 1'b0;
|
| 206 |
|
|
load <= #1 1'b0;
|
| 207 |
|
|
cnt <= #1 3'b000;
|
| 208 |
|
|
cache_inhibit <= #1 1'b0;
|
| 209 |
|
|
end
|
| 210 |
|
|
else
|
| 211 |
|
|
case (state) // synopsys parallel_case
|
| 212 |
|
|
`OR1200_DCFSM_IDLE :
|
| 213 |
|
|
if (dc_en & dcqmem_cycstb_i & dcqmem_we_i) begin // store
|
| 214 |
|
|
state <= #1 `OR1200_DCFSM_CSTORE;
|
| 215 |
|
|
saved_addr_r <= #1 start_addr;
|
| 216 |
|
|
hitmiss_eval <= #1 1'b1;
|
| 217 |
|
|
store <= #1 1'b1;
|
| 218 |
|
|
load <= #1 1'b0;
|
| 219 |
|
|
cache_inhibit <= #1 1'b0;
|
| 220 |
|
|
end
|
| 221 |
|
|
else if (dc_en & dcqmem_cycstb_i) begin // load
|
| 222 |
|
|
state <= #1 `OR1200_DCFSM_CLOAD;
|
| 223 |
|
|
saved_addr_r <= #1 start_addr;
|
| 224 |
|
|
hitmiss_eval <= #1 1'b1;
|
| 225 |
|
|
store <= #1 1'b0;
|
| 226 |
|
|
load <= #1 1'b1;
|
| 227 |
|
|
cache_inhibit <= #1 1'b0;
|
| 228 |
|
|
end
|
| 229 |
|
|
else begin // idle
|
| 230 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 231 |
|
|
store <= #1 1'b0;
|
| 232 |
|
|
load <= #1 1'b0;
|
| 233 |
|
|
cache_inhibit <= #1 1'b0;
|
| 234 |
|
|
end
|
| 235 |
|
|
`OR1200_DCFSM_CLOAD: begin // load
|
| 236 |
|
|
if (dcqmem_cycstb_i & dcqmem_ci_i)
|
| 237 |
|
|
cache_inhibit <= #1 1'b1;
|
| 238 |
|
|
if (hitmiss_eval)
|
| 239 |
|
|
saved_addr_r[31:13] <= #1 start_addr[31:13];
|
| 240 |
|
|
if ((hitmiss_eval & !dcqmem_cycstb_i) || // load aborted (usually caused by DMMU)
|
| 241 |
|
|
(biudata_error) || // load terminated with an error
|
| 242 |
|
|
((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin // load from cache-inhibited area
|
| 243 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 244 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 245 |
|
|
load <= #1 1'b0;
|
| 246 |
|
|
cache_inhibit <= #1 1'b0;
|
| 247 |
|
|
end
|
| 248 |
|
|
else if (tagcomp_miss & biudata_valid) begin // load missed, finish current external load and refill
|
| 249 |
|
|
state <= #1 `OR1200_DCFSM_LREFILL3;
|
| 250 |
|
|
saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
|
| 251 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 252 |
|
|
cnt <= #1 `OR1200_DCLS-2;
|
| 253 |
|
|
cache_inhibit <= #1 1'b0;
|
| 254 |
|
|
end
|
| 255 |
|
|
else if (!tagcomp_miss & !dcqmem_ci_i) begin // load hit, finish immediately
|
| 256 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 257 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 258 |
|
|
load <= #1 1'b0;
|
| 259 |
|
|
cache_inhibit <= #1 1'b0;
|
| 260 |
|
|
end
|
| 261 |
|
|
else // load in-progress
|
| 262 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 263 |
|
|
end
|
| 264 |
|
|
`OR1200_DCFSM_LREFILL3 : begin
|
| 265 |
|
|
if (biudata_valid && (|cnt)) begin // refill ack, more loads to come
|
| 266 |
|
|
cnt <= #1 cnt - 3'd1;
|
| 267 |
|
|
saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
|
| 268 |
|
|
end
|
| 269 |
|
|
else if (biudata_valid) begin // last load of line refill
|
| 270 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 271 |
|
|
load <= #1 1'b0;
|
| 272 |
|
|
end
|
| 273 |
|
|
end
|
| 274 |
|
|
`OR1200_DCFSM_CSTORE: begin // store
|
| 275 |
|
|
if (dcqmem_cycstb_i & dcqmem_ci_i)
|
| 276 |
|
|
cache_inhibit <= #1 1'b1;
|
| 277 |
|
|
if (hitmiss_eval)
|
| 278 |
|
|
saved_addr_r[31:13] <= #1 start_addr[31:13];
|
| 279 |
|
|
if ((hitmiss_eval & !dcqmem_cycstb_i) || // store aborted (usually caused by DMMU)
|
| 280 |
|
|
(biudata_error) || // store terminated with an error
|
| 281 |
|
|
((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin // store to cache-inhibited area
|
| 282 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 283 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 284 |
|
|
store <= #1 1'b0;
|
| 285 |
|
|
cache_inhibit <= #1 1'b0;
|
| 286 |
|
|
end
|
| 287 |
|
|
`ifdef OR1200_DC_STORE_REFILL
|
| 288 |
|
|
else if (tagcomp_miss & biudata_valid) begin // store missed, finish write-through and doq load refill
|
| 289 |
|
|
state <= #1 `OR1200_DCFSM_SREFILL4;
|
| 290 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 291 |
|
|
store <= #1 1'b0;
|
| 292 |
|
|
load <= #1 1'b1;
|
| 293 |
|
|
cnt <= #1 `OR1200_DCLS-1;
|
| 294 |
|
|
cache_inhibit <= #1 1'b0;
|
| 295 |
|
|
end
|
| 296 |
|
|
`endif
|
| 297 |
|
|
else if (biudata_valid) begin // store hit, finish write-through
|
| 298 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 299 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 300 |
|
|
store <= #1 1'b0;
|
| 301 |
|
|
cache_inhibit <= #1 1'b0;
|
| 302 |
|
|
end
|
| 303 |
|
|
else // store write-through in-progress
|
| 304 |
|
|
hitmiss_eval <= #1 1'b0;
|
| 305 |
|
|
end
|
| 306 |
|
|
`ifdef OR1200_DC_STORE_REFILL
|
| 307 |
|
|
`OR1200_DCFSM_SREFILL4 : begin
|
| 308 |
|
|
if (biudata_valid && (|cnt)) begin // refill ack, more loads to come
|
| 309 |
|
|
cnt <= #1 cnt - 1'd1;
|
| 310 |
|
|
saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
|
| 311 |
|
|
end
|
| 312 |
|
|
else if (biudata_valid) begin // last load of line refill
|
| 313 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 314 |
|
|
load <= #1 1'b0;
|
| 315 |
|
|
end
|
| 316 |
|
|
end
|
| 317 |
|
|
`endif
|
| 318 |
|
|
default:
|
| 319 |
|
|
state <= #1 `OR1200_DCFSM_IDLE;
|
| 320 |
|
|
endcase
|
| 321 |
|
|
end
|
| 322 |
|
|
|
| 323 |
|
|
endmodule
|