2011-10-26 08:02:47 +02:00
|
|
|
package Top {
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import Node._;
|
|
|
|
import Constants._;
|
|
|
|
import scala.math._;
|
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// interface between D$ and processor/DTLB
|
2011-10-26 08:02:47 +02:00
|
|
|
class ioDmem(view: List[String] = null) extends Bundle(view) {
|
2011-11-13 00:00:45 +01:00
|
|
|
// val dtlb_busy = Bool('input);
|
|
|
|
val dtlb_miss = Bool('input);
|
2011-10-26 08:02:47 +02:00
|
|
|
val req_val = Bool('input);
|
|
|
|
val req_rdy = Bool('output);
|
2011-11-02 01:59:27 +01:00
|
|
|
val req_cmd = Bits(4, 'input);
|
|
|
|
val req_type = Bits(3, 'input);
|
2011-11-12 03:18:47 +01:00
|
|
|
val req_idx = Bits(PGIDX_BITS, 'input);
|
|
|
|
val req_ppn = Bits(PPN_BITS, 'input);
|
|
|
|
// val req_addr = UFix(PADDR_BITS, 'input);
|
2011-10-26 08:02:47 +02:00
|
|
|
val req_data = Bits(64, 'input);
|
2011-11-04 23:40:41 +01:00
|
|
|
val req_tag = Bits(5, 'input);
|
|
|
|
val resp_miss = Bool('output);
|
2011-10-26 08:02:47 +02:00
|
|
|
val resp_val = Bool('output);
|
|
|
|
val resp_data = Bits(64, 'output);
|
2011-11-10 20:26:13 +01:00
|
|
|
val resp_tag = Bits(12, 'output);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
// interface between D$ and next level in memory hierarchy
|
2011-10-26 08:02:47 +02:00
|
|
|
class ioDcache(view: List[String] = null) extends Bundle(view) {
|
2011-11-09 23:52:17 +01:00
|
|
|
val req_addr = UFix(PADDR_BITS, 'input);
|
2011-10-26 08:02:47 +02:00
|
|
|
val req_tag = UFix(3, 'input);
|
|
|
|
val req_val = Bool('input);
|
|
|
|
val req_rdy = Bool('output);
|
|
|
|
val req_wdata = Bits(128, 'input);
|
|
|
|
val req_rw = Bool('input);
|
|
|
|
val resp_data = Bits(128, 'output);
|
2011-11-10 08:18:14 +01:00
|
|
|
// val resp_tag = Bits(3, 'output);
|
2011-10-26 08:02:47 +02:00
|
|
|
val resp_val = Bool('output);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ioDCacheDM extends Bundle() {
|
|
|
|
val cpu = new ioDmem();
|
|
|
|
val mem = new ioDcache().flip();
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
class rocketDCacheStoreGen extends Component {
|
|
|
|
val io = new Bundle {
|
|
|
|
val req_type = Bits(3, 'input);
|
|
|
|
val req_addr_lsb = Bits(3, 'input);
|
|
|
|
val req_data = Bits(64, 'input);
|
|
|
|
val store_wmask = Bits(64, 'output);
|
|
|
|
val store_data = Bits(64, 'output);
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate write mask and store data signals based on store type and address LSBs
|
|
|
|
val wmask_b =
|
|
|
|
Mux(io.req_addr_lsb === UFix(0, 3), Bits("b0000_0001", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(1, 3), Bits("b0000_0010", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(2, 3), Bits("b0000_0100", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(3, 3), Bits("b0000_1000", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(4, 3), Bits("b0001_0000", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(5, 3), Bits("b0010_0000", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(6, 3), Bits("b0100_0000", 8),
|
|
|
|
Mux(io.req_addr_lsb === UFix(7, 3), Bits("b1000_0000", 8),
|
|
|
|
UFix(0, 8)))))))));
|
|
|
|
|
|
|
|
val wmask_h =
|
|
|
|
Mux(io.req_addr_lsb(2,1) === UFix(0, 2), Bits("b0000_0011", 8),
|
|
|
|
Mux(io.req_addr_lsb(2,1) === UFix(1, 2), Bits("b0000_1100", 8),
|
|
|
|
Mux(io.req_addr_lsb(2,1) === UFix(2, 2), Bits("b0011_0000", 8),
|
|
|
|
Mux(io.req_addr_lsb(2,1) === UFix(3, 2), Bits("b1100_0000", 8),
|
|
|
|
UFix(0, 8)))));
|
|
|
|
|
|
|
|
val wmask_w =
|
|
|
|
Mux(io.req_addr_lsb(2) === UFix(0, 1), Bits("b0000_1111", 8),
|
|
|
|
Mux(io.req_addr_lsb(2) === UFix(1, 1), Bits("b1111_0000", 8),
|
|
|
|
UFix(0, 8)));
|
|
|
|
|
|
|
|
val wmask_d =
|
|
|
|
Bits("b1111_1111", 8);
|
|
|
|
|
|
|
|
val store_wmask_byte =
|
|
|
|
Mux(io.req_type === MT_B, wmask_b,
|
|
|
|
Mux(io.req_type === MT_H, wmask_h,
|
|
|
|
Mux(io.req_type === MT_W, wmask_w,
|
|
|
|
Mux(io.req_type === MT_D, wmask_d,
|
|
|
|
UFix(0, 8)))));
|
|
|
|
|
|
|
|
io.store_wmask :=
|
|
|
|
Cat(Fill(8, store_wmask_byte(7)),
|
|
|
|
Fill(8, store_wmask_byte(6)),
|
|
|
|
Fill(8, store_wmask_byte(5)),
|
|
|
|
Fill(8, store_wmask_byte(4)),
|
|
|
|
Fill(8, store_wmask_byte(3)),
|
|
|
|
Fill(8, store_wmask_byte(2)),
|
|
|
|
Fill(8, store_wmask_byte(1)),
|
|
|
|
Fill(8, store_wmask_byte(0)));
|
|
|
|
|
|
|
|
io.store_data :=
|
|
|
|
Mux(io.req_type === MT_B, Fill(8, io.req_data( 7,0)),
|
|
|
|
Mux(io.req_type === MT_H, Fill(4, io.req_data(15,0)),
|
|
|
|
Mux(io.req_type === MT_W, Fill(2, io.req_data(31,0)),
|
|
|
|
Mux(io.req_type === MT_D, io.req_data,
|
|
|
|
UFix(0, 64)))));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
// state machine to flush (write back dirty lines, invalidate clean ones) the D$
|
2011-11-09 23:52:17 +01:00
|
|
|
class rocketDCacheDM_flush(lines: Int) extends Component {
|
2011-10-26 08:02:47 +02:00
|
|
|
val io = new ioDCacheDM();
|
2011-11-09 23:52:17 +01:00
|
|
|
val dcache = new rocketDCacheDM(lines);
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
val addrbits = PADDR_BITS;
|
2011-10-26 08:02:47 +02:00
|
|
|
val indexbits = ceil(log10(lines)/log10(2)).toInt;
|
|
|
|
val offsetbits = 6;
|
|
|
|
val tagmsb = addrbits - 1;
|
|
|
|
val taglsb = indexbits+offsetbits;
|
2011-11-12 03:18:47 +01:00
|
|
|
val tagbits = tagmsb-taglsb+1;
|
2011-10-26 08:02:47 +02:00
|
|
|
val indexmsb = taglsb-1;
|
|
|
|
val indexlsb = offsetbits;
|
|
|
|
val offsetmsb = indexlsb-1;
|
|
|
|
val offsetlsb = 3;
|
|
|
|
|
|
|
|
val flush_count = Reg(resetVal = UFix(0, indexbits));
|
|
|
|
val flush_resp_count = Reg(resetVal = UFix(0, indexbits));
|
|
|
|
val flushing = Reg(resetVal = Bool(false));
|
|
|
|
val flush_waiting = Reg(resetVal = Bool(false));
|
2011-11-04 23:40:41 +01:00
|
|
|
val r_cpu_req_tag = Reg(resetVal = Bits(0, 5));
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
when (io.cpu.req_val && io.cpu.req_rdy && (io.cpu.req_cmd === M_FLA))
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
|
|
|
r_cpu_req_tag <== io.cpu.req_tag;
|
|
|
|
flushing <== Bool(true);
|
|
|
|
flush_waiting <== Bool(true);
|
|
|
|
}
|
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
when (dcache.io.cpu.req_rdy && (flush_count === ~Bits(0, indexbits))) {
|
|
|
|
flushing <== Bool(false);
|
|
|
|
}
|
|
|
|
when (dcache.io.cpu.resp_val && (dcache.io.cpu.resp_tag === r_cpu_req_tag) && (flush_resp_count === ~Bits(0, indexbits))) {
|
|
|
|
flush_waiting <== Bool(false);
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
when (flushing && dcache.io.cpu.req_rdy) {
|
|
|
|
flush_count <== flush_count + UFix(1,1);
|
|
|
|
}
|
|
|
|
when (flush_waiting && dcache.io.cpu.resp_val && (dcache.io.cpu.resp_tag(5,0) === r_cpu_req_tag)) {
|
|
|
|
flush_resp_count <== flush_resp_count + UFix(1,1);
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-11-02 01:59:27 +01:00
|
|
|
dcache.io.cpu.req_val := (io.cpu.req_val && (io.cpu.req_cmd != M_FLA) && !flush_waiting) || flushing;
|
2011-11-09 23:52:17 +01:00
|
|
|
dcache.io.cpu.req_cmd := Mux(flushing, M_FLA, io.cpu.req_cmd);
|
2011-11-12 03:18:47 +01:00
|
|
|
dcache.io.cpu.req_idx := Mux(flushing, Cat(flush_count, Bits(0,offsetbits)), io.cpu.req_idx);
|
|
|
|
dcache.io.cpu.req_ppn := Mux(flushing, UFix(0,PPN_BITS), io.cpu.req_ppn);
|
|
|
|
// dcache.io.cpu.req_addr :=
|
|
|
|
// Mux(flushing, Cat(Bits(0,tagmsb-taglsb+1), flush_count, Bits(0,offsetbits)).toUFix,
|
|
|
|
// io.cpu.req_addr);
|
2011-10-26 08:02:47 +02:00
|
|
|
dcache.io.cpu.req_tag := Mux(flushing, r_cpu_req_tag, io.cpu.req_tag);
|
2011-11-02 01:59:27 +01:00
|
|
|
dcache.io.cpu.req_type := io.cpu.req_type;
|
2011-10-26 08:02:47 +02:00
|
|
|
dcache.io.cpu.req_data ^^ io.cpu.req_data;
|
2011-11-13 00:00:45 +01:00
|
|
|
// dcache.io.cpu.dtlb_busy := io.cpu.dtlb_busy;
|
|
|
|
dcache.io.cpu.dtlb_miss := io.cpu.dtlb_miss;
|
2011-10-26 08:02:47 +02:00
|
|
|
dcache.io.mem ^^ io.mem;
|
|
|
|
|
|
|
|
io.cpu.req_rdy := dcache.io.cpu.req_rdy && !flush_waiting;
|
2011-11-04 23:40:41 +01:00
|
|
|
io.cpu.resp_miss := dcache.io.cpu.resp_miss;
|
2011-10-26 08:02:47 +02:00
|
|
|
io.cpu.resp_data := dcache.io.cpu.resp_data;
|
|
|
|
io.cpu.resp_tag := dcache.io.cpu.resp_tag;
|
|
|
|
io.cpu.resp_val := dcache.io.cpu.resp_val &
|
|
|
|
!(flush_waiting && (io.cpu.resp_tag === r_cpu_req_tag) && (flush_count != ~Bits(0, addrbits)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
class rocketDCacheDM(lines: Int) extends Component {
|
2011-10-31 23:37:37 +01:00
|
|
|
val io = new ioDCacheDM();
|
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
val addrbits = PADDR_BITS;
|
2011-10-31 23:37:37 +01:00
|
|
|
val indexbits = ceil(log10(lines)/log10(2)).toInt;
|
2011-11-12 03:18:47 +01:00
|
|
|
val offsetbits = 6; // 64 byte cache lines = 2^6 bytes
|
|
|
|
val tagmsb = PADDR_BITS-1;
|
2011-10-31 23:37:37 +01:00
|
|
|
val taglsb = indexbits+offsetbits;
|
2011-11-12 03:18:47 +01:00
|
|
|
val tagbits = tagmsb-taglsb+1;
|
2011-10-31 23:37:37 +01:00
|
|
|
val indexmsb = taglsb-1;
|
|
|
|
val indexlsb = offsetbits;
|
|
|
|
val offsetmsb = indexlsb-1;
|
|
|
|
val offsetlsb = 3;
|
|
|
|
|
|
|
|
val s_reset :: s_ready :: s_replay_load :: s_start_writeback :: s_writeback :: s_req_refill :: s_refill :: s_resolve_miss :: Nil = Enum(8) { UFix() };
|
|
|
|
val state = Reg(resetVal = s_reset);
|
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// idx arrives one clock cycle prior to ppn b/c of DTLB
|
|
|
|
val r_cpu_req_idx = Reg(resetVal = Bits(0, PGIDX_BITS));
|
|
|
|
val r_cpu_req_ppn = Reg(resetVal = Bits(0, PPN_BITS));
|
2011-10-31 23:37:37 +01:00
|
|
|
val r_cpu_req_val = Reg(resetVal = Bool(false));
|
2011-11-02 01:59:27 +01:00
|
|
|
val r_cpu_req_cmd = Reg(resetVal = Bits(0,4));
|
|
|
|
val r_cpu_req_type = Reg(resetVal = Bits(0,3));
|
|
|
|
val r_cpu_req_tag = Reg(resetVal = Bits(0,5));
|
2011-11-12 03:18:47 +01:00
|
|
|
val r_cpu_resp_val = Reg(resetVal = Bool(false));
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
val p_store_data = Reg(resetVal = Bits(0,64));
|
|
|
|
val p_store_idx = Reg(resetVal = Bits(0,PGIDX_BITS));
|
|
|
|
val p_store_type = Reg(resetVal = Bits(0,3));
|
|
|
|
val p_store_valid = Reg(resetVal = Bool(false));
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
val req_store = (io.cpu.req_cmd === M_XWR);
|
|
|
|
val r_req_load = (r_cpu_req_cmd === M_XRD) || (r_cpu_req_cmd === M_PRD);
|
|
|
|
val r_req_store = (r_cpu_req_cmd === M_XWR);
|
|
|
|
val r_req_flush = (r_cpu_req_cmd === M_FLA);
|
|
|
|
val r_req_ptw_load = (r_cpu_req_cmd === M_PRD);
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
when (io.cpu.req_val && io.cpu.req_rdy) {
|
|
|
|
r_cpu_req_idx <== io.cpu.req_idx;
|
2011-11-02 01:59:27 +01:00
|
|
|
r_cpu_req_cmd <== io.cpu.req_cmd;
|
|
|
|
r_cpu_req_type <== io.cpu.req_type;
|
2011-10-31 23:37:37 +01:00
|
|
|
r_cpu_req_tag <== io.cpu.req_tag;
|
|
|
|
}
|
2011-11-04 23:40:41 +01:00
|
|
|
|
2011-11-13 00:00:45 +01:00
|
|
|
when ((state === s_ready) && r_cpu_req_val && !io.cpu.dtlb_miss) {
|
2011-11-12 03:18:47 +01:00
|
|
|
r_cpu_req_ppn <== io.cpu.req_ppn;
|
2011-11-04 23:40:41 +01:00
|
|
|
}
|
2011-10-31 23:37:37 +01:00
|
|
|
when (io.cpu.req_rdy) {
|
|
|
|
r_cpu_req_val <== io.cpu.req_val;
|
2011-11-13 00:00:45 +01:00
|
|
|
}
|
|
|
|
otherwise {
|
2011-10-31 23:37:37 +01:00
|
|
|
r_cpu_req_val <== Bool(false);
|
|
|
|
}
|
2011-11-13 00:00:45 +01:00
|
|
|
when (((state === s_resolve_miss) && r_req_load) || (state === s_replay_load)) {
|
|
|
|
r_cpu_resp_val <== Bool(true);
|
|
|
|
}
|
|
|
|
otherwise {
|
|
|
|
r_cpu_resp_val <== Bool(false);
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// refill counter
|
2011-10-31 23:37:37 +01:00
|
|
|
val rr_count = Reg(resetVal = UFix(0,2));
|
|
|
|
val rr_count_next = rr_count + UFix(1);
|
|
|
|
when (((state === s_refill) && io.mem.resp_val) || ((state === s_writeback) && io.mem.req_rdy)) {
|
|
|
|
rr_count <== rr_count_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tag array
|
2011-11-12 03:18:47 +01:00
|
|
|
val tag_addr =
|
|
|
|
Mux((state === s_ready), io.cpu.req_idx(PGIDX_BITS-1,offsetbits),
|
|
|
|
r_cpu_req_idx(PGIDX_BITS-1,offsetbits)).toUFix;
|
2011-11-07 09:58:25 +01:00
|
|
|
val tag_we =
|
2011-11-04 23:40:41 +01:00
|
|
|
((state === s_refill) && io.mem.req_rdy && (rr_count === UFix(3,2))) ||
|
2011-11-12 03:18:47 +01:00
|
|
|
((state === s_resolve_miss) && r_req_flush);
|
2011-11-12 09:25:06 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
val tag_array = new rocketSRAMsp(lines, tagbits);
|
|
|
|
tag_array.io.a := tag_addr;
|
|
|
|
tag_array.io.d := r_cpu_req_ppn;
|
2011-11-07 09:58:25 +01:00
|
|
|
tag_array.io.we := tag_we;
|
|
|
|
tag_array.io.bweb := ~Bits(0,tagbits);
|
2011-11-13 00:00:45 +01:00
|
|
|
tag_array.io.ce := (state === s_ready) || (state === s_start_writeback) || (state === s_writeback);
|
2011-11-12 03:18:47 +01:00
|
|
|
val tag_rdata = tag_array.io.q;
|
2011-11-07 09:58:25 +01:00
|
|
|
|
2011-10-31 23:37:37 +01:00
|
|
|
// valid bit array
|
|
|
|
val vb_array = Reg(resetVal = Bits(0, lines));
|
2011-11-12 03:18:47 +01:00
|
|
|
// val vb_rdata = Reg(vb_array(tag_raddr));
|
|
|
|
when (tag_we && !r_req_flush) {
|
|
|
|
vb_array <== vb_array.bitSet(r_cpu_req_idx(PGIDX_BITS-1,offsetbits).toUFix, UFix(1,1));
|
2011-10-31 23:37:37 +01:00
|
|
|
}
|
2011-11-12 03:18:47 +01:00
|
|
|
when (tag_we && r_req_flush) {
|
|
|
|
vb_array <== vb_array.bitSet(r_cpu_req_idx(PGIDX_BITS-1,offsetbits).toUFix, UFix(0,1));
|
2011-10-31 23:37:37 +01:00
|
|
|
}
|
2011-11-13 00:00:45 +01:00
|
|
|
val vb_rdata = Reg(vb_array(tag_addr).toBool);
|
|
|
|
val tag_valid = r_cpu_req_val && vb_rdata;
|
|
|
|
// val tag_valid = Reg(vb_array(tag_addr)).toBool;
|
2011-11-12 03:18:47 +01:00
|
|
|
val tag_match = (tag_rdata === io.cpu.req_ppn);
|
|
|
|
val addr_match = (r_cpu_req_idx(PGIDX_BITS-1,offsetbits) === p_store_idx(PGIDX_BITS-1,offsetbits));
|
|
|
|
val ldst_conflict = r_cpu_req_val && r_req_load && p_store_valid && addr_match;
|
2011-11-01 00:47:31 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// write the pending store data when the cache is idle, when the next command isn't a load
|
|
|
|
// or when there's a load to the same address (in which case there's a 2 cycle delay:
|
|
|
|
// once cycle to write the store data and another to read the data back)
|
2011-11-13 00:00:45 +01:00
|
|
|
val drain_store = !io.cpu.dtlb_miss && p_store_valid && (!io.cpu.req_val || req_store || ldst_conflict);
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// write pending store data from a store which missed
|
|
|
|
// after the cache line refill has completed
|
|
|
|
val resolve_store = (state === s_resolve_miss) && r_req_store;
|
|
|
|
|
2011-10-31 23:37:37 +01:00
|
|
|
// dirty bit array
|
|
|
|
val db_array = Reg(resetVal = Bits(0, lines));
|
2011-11-12 03:18:47 +01:00
|
|
|
// val db_rdata = Reg(db_array(tag_raddr));
|
|
|
|
val tag_dirty = Reg(db_array(tag_addr)).toBool;
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
when (io.cpu.req_val && io.cpu.req_rdy && req_store) {
|
|
|
|
p_store_idx <== io.cpu.req_idx;
|
|
|
|
p_store_data <== io.cpu.req_data;
|
|
|
|
p_store_type <== io.cpu.req_type;
|
|
|
|
p_store_valid <== Bool(true);
|
|
|
|
}
|
2011-11-13 00:00:45 +01:00
|
|
|
// cancel store if there's a DTLB miss
|
|
|
|
when (r_cpu_req_val && r_req_store && io.cpu.dtlb_miss)
|
|
|
|
{
|
|
|
|
p_store_valid <== Bool(false);
|
|
|
|
}
|
2011-11-12 03:18:47 +01:00
|
|
|
when (drain_store) {
|
2011-10-31 23:37:37 +01:00
|
|
|
p_store_valid <== Bool(false);
|
2011-11-12 03:18:47 +01:00
|
|
|
db_array <== db_array.bitSet(p_store_idx(PGIDX_BITS-1,offsetbits).toUFix, UFix(1,1));
|
|
|
|
}
|
|
|
|
when (resolve_store) {
|
|
|
|
db_array <== db_array.bitSet(p_store_idx(PGIDX_BITS-1,offsetbits).toUFix, UFix(1,1));
|
2011-10-31 23:37:37 +01:00
|
|
|
}
|
|
|
|
when (tag_we) {
|
2011-11-12 03:18:47 +01:00
|
|
|
db_array <== db_array.bitSet(r_cpu_req_idx(PGIDX_BITS-1,offsetbits).toUFix, UFix(0,1));
|
2011-10-31 23:37:37 +01:00
|
|
|
}
|
2011-11-12 03:18:47 +01:00
|
|
|
|
|
|
|
// generate write mask and data signals for stores
|
|
|
|
val storegen = new rocketDCacheStoreGen();
|
|
|
|
storegen.io.req_addr_lsb := p_store_idx(2,0);
|
|
|
|
storegen.io.req_data := p_store_data;
|
|
|
|
storegen.io.req_type := p_store_type
|
|
|
|
val store_data = Fill(2, storegen.io.store_data);
|
|
|
|
val store_wmask_d = storegen.io.store_wmask;
|
|
|
|
val store_idx_sel = p_store_idx(offsetlsb).toBool;
|
2011-11-12 09:25:06 +01:00
|
|
|
val store_wmask = Mux(store_idx_sel, Cat(store_wmask_d, Bits(0,64)), Cat(Bits(0,64), store_wmask_d));
|
2011-10-31 23:37:37 +01:00
|
|
|
|
|
|
|
// data array
|
2011-11-07 09:58:25 +01:00
|
|
|
val data_array = new rocketSRAMsp(lines*4, 128);
|
|
|
|
data_array.io.a :=
|
2011-11-12 03:18:47 +01:00
|
|
|
Mux(drain_store || resolve_store, p_store_idx(PGIDX_BITS-1, offsetmsb-1),
|
|
|
|
Mux((state === s_writeback) && io.mem.req_rdy, Cat(r_cpu_req_idx(PGIDX_BITS-1, offsetbits), rr_count_next),
|
|
|
|
Mux((state === s_start_writeback) || (state === s_writeback) || (state === s_refill), Cat(r_cpu_req_idx(PGIDX_BITS-1, offsetbits), rr_count),
|
|
|
|
Mux((state === s_resolve_miss) || (state === s_replay_load), r_cpu_req_idx(PGIDX_BITS-1, offsetmsb-1),
|
|
|
|
io.cpu.req_idx(PGIDX_BITS-1, offsetmsb-1))))).toUFix;
|
2011-11-07 09:58:25 +01:00
|
|
|
|
2011-11-12 09:25:06 +01:00
|
|
|
data_array.io.d := Mux((state === s_refill), io.mem.resp_data, store_data);
|
2011-11-12 03:18:47 +01:00
|
|
|
data_array.io.we := ((state === s_refill) && io.mem.resp_val) || drain_store || resolve_store;
|
|
|
|
data_array.io.bweb := Mux((state === s_refill), ~Bits(0,128), store_wmask);
|
2011-11-07 09:58:25 +01:00
|
|
|
data_array.io.ce := Bool(true); // FIXME
|
|
|
|
val data_array_rdata = data_array.io.q;
|
2011-11-01 00:47:31 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
// signal a load miss when the data isn't present in the cache and when it's in the pending store data register
|
|
|
|
// (causes the cache to block for 2 cycles and the load instruction is replayed)
|
|
|
|
val hit = tag_valid && tag_match;
|
2011-11-13 00:00:45 +01:00
|
|
|
val load_miss = !io.cpu.dtlb_miss && (state === s_ready) && r_cpu_req_val && r_req_load && (!hit || (p_store_valid && addr_match));
|
2011-11-04 23:40:41 +01:00
|
|
|
|
2011-10-31 23:37:37 +01:00
|
|
|
// output signals
|
2011-11-12 03:18:47 +01:00
|
|
|
// busy when there's a load to the same address as a pending store, or on a cache miss, or when executing a flush
|
2011-11-13 00:00:45 +01:00
|
|
|
io.cpu.req_rdy := !io.cpu.dtlb_miss && (state === s_ready) && !ldst_conflict && (!r_cpu_req_val || (hit && !r_req_flush));
|
|
|
|
io.cpu.resp_val := !io.cpu.dtlb_miss && ((state === s_ready) && hit && r_req_load && !(p_store_valid && addr_match)) ||
|
2011-11-12 03:18:47 +01:00
|
|
|
((state === s_resolve_miss) && r_req_flush) ||
|
|
|
|
r_cpu_resp_val;
|
2011-10-31 23:37:37 +01:00
|
|
|
|
2011-11-12 03:18:47 +01:00
|
|
|
io.cpu.resp_miss := load_miss;
|
|
|
|
// tag MSB distinguishes between loads destined for the PTW and CPU
|
|
|
|
io.cpu.resp_tag := Cat(r_req_ptw_load, r_cpu_req_type, r_cpu_req_idx(2,0), r_cpu_req_tag);
|
2011-10-31 23:37:37 +01:00
|
|
|
io.cpu.resp_data :=
|
2011-11-12 03:18:47 +01:00
|
|
|
Mux(r_cpu_req_idx(offsetlsb).toBool, data_array_rdata(127, 64),
|
2011-10-31 23:37:37 +01:00
|
|
|
data_array_rdata(63,0));
|
|
|
|
|
2011-11-01 01:17:36 +01:00
|
|
|
io.mem.req_val := (state === s_req_refill) || (state === s_writeback);
|
|
|
|
io.mem.req_rw := (state === s_writeback);
|
2011-10-31 23:37:37 +01:00
|
|
|
io.mem.req_wdata := data_array_rdata;
|
2011-11-01 01:17:36 +01:00
|
|
|
io.mem.req_tag := UFix(0);
|
|
|
|
io.mem.req_addr :=
|
2011-11-12 03:18:47 +01:00
|
|
|
Mux(state === s_writeback, Cat(tag_rdata, r_cpu_req_idx(PGIDX_BITS-1, offsetbits), rr_count),
|
|
|
|
Cat(r_cpu_req_ppn, r_cpu_req_idx(PGIDX_BITS-1, offsetbits), Bits(0,2))).toUFix;
|
2011-10-31 23:37:37 +01:00
|
|
|
|
|
|
|
// control state machine
|
|
|
|
switch (state) {
|
|
|
|
is (s_reset) {
|
|
|
|
state <== s_ready;
|
|
|
|
}
|
|
|
|
is (s_ready) {
|
2011-11-13 00:00:45 +01:00
|
|
|
when (io.cpu.dtlb_miss) {
|
|
|
|
state <== s_ready;
|
|
|
|
}
|
2011-11-01 00:47:31 +01:00
|
|
|
when (ldst_conflict) {
|
2011-10-31 23:37:37 +01:00
|
|
|
state <== s_replay_load;
|
|
|
|
}
|
2011-11-12 03:18:47 +01:00
|
|
|
when (!r_cpu_req_val || (hit && !r_req_flush)) {
|
2011-10-31 23:37:37 +01:00
|
|
|
state <== s_ready;
|
|
|
|
}
|
|
|
|
when (tag_valid & tag_dirty) {
|
|
|
|
state <== s_start_writeback;
|
|
|
|
}
|
2011-11-12 03:18:47 +01:00
|
|
|
when (r_req_flush) {
|
2011-10-31 23:37:37 +01:00
|
|
|
state <== s_resolve_miss;
|
|
|
|
}
|
|
|
|
otherwise {
|
|
|
|
state <== s_req_refill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is (s_replay_load) {
|
|
|
|
state <== s_ready;
|
|
|
|
}
|
|
|
|
is (s_start_writeback) {
|
|
|
|
state <== s_writeback;
|
|
|
|
}
|
|
|
|
is (s_writeback) {
|
|
|
|
when (io.mem.req_rdy && (rr_count === UFix(3,2))) {
|
2011-11-12 03:18:47 +01:00
|
|
|
when (r_req_flush) {
|
|
|
|
state <== s_resolve_miss;
|
|
|
|
}
|
|
|
|
otherwise {
|
|
|
|
state <== s_req_refill;
|
|
|
|
}
|
2011-10-31 23:37:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is (s_req_refill)
|
|
|
|
{
|
|
|
|
when (io.mem.req_rdy) { state <== s_refill; }
|
|
|
|
}
|
|
|
|
is (s_refill) {
|
|
|
|
when (io.mem.resp_val && (rr_count === UFix(3,2))) { state <== s_resolve_miss; }
|
|
|
|
}
|
|
|
|
is (s_resolve_miss) {
|
|
|
|
state <== s_ready;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|