Line 42... |
Line 42... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.2 2001/07/22 03:31:53 lampret
|
|
// Fixed RAM's oen bug. Cache bypass under development.
|
|
//
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
// Development version of RTL. Libraries are missing.
|
// Development version of RTL. Libraries are missing.
|
//
|
//
|
//
|
//
|
|
|
`include "general.h"
|
`include "timescale.v"
|
|
`include "defines.v"
|
|
|
|
//
|
// Data cache
|
// Data cache
|
|
//
|
|
|
|
module dc(
|
|
// Rst, clk and clock control
|
|
clk, rst, clkdiv_by_2,
|
|
|
|
// External i/f
|
|
dcbiu_rdy, dcbiu_datain, dcbiu_dataout, dcbiu_addr, dcbiu_read, dcbiu_write, dcbiu_sel,
|
|
|
module dc(clk, rst, clkdiv_by_2, dcbiu_rdy, dclsu_addr, dclsu_lsuop, dclsu_datain, dcbiu_datain,
|
// Inernal i/f
|
dclsu_dataout, dcbiu_dataout, dcbiu_addr, dcbiu_read, dcbiu_write, dclsu_stall, dcbiu_sel,
|
dc_en, dclsu_addr, dclsu_lsuop, dclsu_datain, dclsu_dataout, dclsu_stall,
|
tp2w, tp3w, tpdw
|
|
|
// Trace
|
|
tp2w
|
);
|
);
|
|
|
parameter dw = `OPERAND_WIDTH;
|
parameter dw = `OPERAND_WIDTH;
|
|
|
|
//
|
|
// I/O
|
|
//
|
|
|
|
//
|
|
// Clock and reset
|
|
//
|
input clk;
|
input clk;
|
input rst;
|
input rst;
|
input clkdiv_by_2;
|
input clkdiv_by_2;
|
|
|
|
//
|
|
// External I/F
|
|
//
|
input dcbiu_rdy;
|
input dcbiu_rdy;
|
|
input [dw-1:0] dcbiu_datain;
|
|
output [31:0] dcbiu_addr;
|
|
output dcbiu_read;
|
|
output dcbiu_write;
|
|
output [3:0] dcbiu_sel;
|
|
|
|
|
|
//
|
|
// Internal I/F
|
|
//
|
|
input dc_en;
|
input [31:0] dclsu_addr;
|
input [31:0] dclsu_addr;
|
input [`LSUOP_WIDTH-1:0] dclsu_lsuop;
|
input [`LSUOP_WIDTH-1:0] dclsu_lsuop;
|
input [dw-1:0] dclsu_datain;
|
input [dw-1:0] dclsu_datain;
|
input [dw-1:0] dcbiu_datain;
|
|
|
|
output [dw-1:0] dclsu_dataout;
|
output [dw-1:0] dclsu_dataout;
|
output [dw-1:0] dcbiu_dataout;
|
output [dw-1:0] dcbiu_dataout;
|
output [31:0] dcbiu_addr;
|
|
output dcbiu_read;
|
|
output dcbiu_write;
|
|
output dclsu_stall;
|
output dclsu_stall;
|
output [3:0] dcbiu_sel;
|
|
|
|
|
//
|
|
// Trace
|
|
//
|
input [`TP2W_WIDTH-1:0] tp2w;
|
input [`TP2W_WIDTH-1:0] tp2w;
|
input [`TP3W_WIDTH-1:0] tp3w;
|
|
input [31:0] tpdw;
|
|
|
|
|
//
|
|
// Internal wires and regs
|
|
//
|
wire [18:0] tag;
|
wire [18:0] tag;
|
wire [dw-1:0] to_dcram;
|
wire [dw-1:0] to_dcram;
|
wire [dw-1:0] from_dcram;
|
wire [dw-1:0] from_dcram;
|
wire [dw-1:0] to_mem2reg;
|
wire [dw-1:0] to_mem2reg;
|
wire [31:0] saved_addr;
|
wire [31:0] saved_addr;
|
Line 96... |
Line 131... |
wire refill_start;
|
wire refill_start;
|
wire refill_rest;
|
wire refill_rest;
|
wire [`LSUOP_WIDTH-1:0] dcfsm_lsuop;
|
wire [`LSUOP_WIDTH-1:0] dcfsm_lsuop;
|
wire dcfsm_read;
|
wire dcfsm_read;
|
wire dcfsm_write;
|
wire dcfsm_write;
|
wire dc_en;
|
|
wire [1:0] mem2reg_addr;
|
wire [1:0] mem2reg_addr;
|
|
|
reg hit;
|
reg hit;
|
reg [1:0] valid_div;
|
reg [1:0] valid_div;
|
reg [3:0] dcbiu_sel;
|
reg [3:0] dcbiu_sel;
|
reg [1:0] bypass_wait;
|
reg [1:0] bypass_wait;
|
|
|
wire queue;
|
wire queue;
|
wire cntrbusy;
|
wire cntrbusy;
|
wire dcbiu_valid;
|
wire dcbiu_valid;
|
|
|
|
//
|
|
// Simple assignments
|
|
//
|
assign dcbiu_addr = dc_addr;
|
assign dcbiu_addr = dc_addr;
|
assign dctag_we = refill;
|
assign dctag_we = refill;
|
|
|
|
//
|
|
// Data to BIU is from DCRAM when DC is enabled or from LSU when
|
|
// DC is disabled
|
|
//
|
assign dcbiu_dataout = (dc_en) ? from_dcram : lsu_datain_memaligned;
|
assign dcbiu_dataout = (dc_en) ? from_dcram : lsu_datain_memaligned;
|
|
|
// Bypases of DC
|
//
|
assign dc_en = 1'b0;
|
// Bypases of the DC when DC is disabled
|
|
//
|
assign dcfsm_lsuop = (dc_en) ? dclsu_lsuop : `LSUOP_NOP;
|
assign dcfsm_lsuop = (dc_en) ? dclsu_lsuop : `LSUOP_NOP;
|
assign dcbiu_read = (dc_en) ? dcfsm_read : (dclsu_lsuop && ~dclsu_lsuop[3]);
|
assign dcbiu_read = (dc_en) ? dcfsm_read : (dclsu_lsuop && ~dclsu_lsuop[3]);
|
assign dcbiu_write = (dc_en) ? dcfsm_write : (dclsu_lsuop && dclsu_lsuop[3]);
|
assign dcbiu_write = (dc_en) ? dcfsm_write : (dclsu_lsuop && dclsu_lsuop[3]);
|
always @(dc_en or dclsu_lsuop or dclsu_addr)
|
always @(dc_en or dclsu_lsuop or dclsu_addr)
|
casex({dc_en, dclsu_lsuop, dclsu_addr[1:0]})
|
casex({dc_en, dclsu_lsuop, dclsu_addr[1:0]})
|
Line 139... |
Line 180... |
default : dcbiu_sel <= #1 4'b0000;
|
default : dcbiu_sel <= #1 4'b0000;
|
endcase
|
endcase
|
|
|
assign mem2reg_addr = (dc_en) ? saved_addr[1:0] : dclsu_addr[1:0];
|
assign mem2reg_addr = (dc_en) ? saved_addr[1:0] : dclsu_addr[1:0];
|
|
|
|
//
|
// Wait for DC bypass acess
|
// Wait for DC bypass acess
|
|
//
|
always @(posedge rst or posedge clk)
|
always @(posedge rst or posedge clk)
|
if (rst)
|
if (rst)
|
bypass_wait <= #1 2'b0;
|
bypass_wait <= #1 2'b0;
|
else if (dcbiu_valid)
|
else if (dcbiu_valid)
|
bypass_wait <= #1 2'b0;
|
bypass_wait <= #1 2'b0;
|
else if (dcbiu_read | dcbiu_write)
|
else if (dcbiu_read | dcbiu_write)
|
bypass_wait <= #1 {bypass_wait, 1'b1};
|
bypass_wait <= #1 {bypass_wait, 1'b1};
|
else
|
else
|
bypass_wait <= #1 2'b00;
|
bypass_wait <= #1 2'b00;
|
|
|
// assign dc_stall = dcfsm_read | dcfsm_write | refill_start; // can't remember if it works
|
//
|
|
// Queue
|
|
//
|
assign queue = (refill && dcfsm_lsuop && !refill_first & !refill_rest) ? 1'b1 : 1'b0;
|
assign queue = (refill && dcfsm_lsuop && !refill_first & !refill_rest) ? 1'b1 : 1'b0;
|
|
|
// assign dclsu_stall = refill_start | (refill_first & ~dcbiu_valid)| refill_rest | queue; // kind of working
|
//
|
|
// DC/LSU stall
|
|
//
|
assign dclsu_stall = refill_start | (refill_first & ~dcbiu_valid)| refill_rest | queue | cntrbusy | (~dc_en & bypass_wait[1] & ~dcbiu_valid);
|
assign dclsu_stall = refill_start | (refill_first & ~dcbiu_valid)| refill_rest | queue | cntrbusy | (~dc_en & bypass_wait[1] & ~dcbiu_valid);
|
|
|
|
//
|
// Select between claddr generated by DC FSM and addr[3:2] generated by LSU
|
// Select between claddr generated by DC FSM and addr[3:2] generated by LSU
|
|
//
|
assign dc_addr = (refill == 1'b1) ? saved_addr : dclsu_addr;
|
assign dc_addr = (refill == 1'b1) ? saved_addr : dclsu_addr;
|
|
|
|
//
|
// Select between input data generated by LSU or by BIU
|
// Select between input data generated by LSU or by BIU
|
|
//
|
assign to_dcram = (refill == 1'b1) ? dcbiu_datain : lsu_datain_memaligned;
|
assign to_dcram = (refill == 1'b1) ? dcbiu_datain : lsu_datain_memaligned;
|
|
|
|
//
|
// Select between data generated by DCRAM or passed by BIU
|
// Select between data generated by DCRAM or passed by BIU
|
|
//
|
assign to_mem2reg = (refill_first == 1'b1) | (~dc_en) ? dcbiu_datain : from_dcram;
|
assign to_mem2reg = (refill_first == 1'b1) | (~dc_en) ? dcbiu_datain : from_dcram;
|
|
|
|
//
|
// Tag comparison
|
// Tag comparison
|
|
//
|
always @(tag or saved_addr) begin
|
always @(tag or saved_addr) begin
|
if (tag == saved_addr[31:13])
|
if (tag == saved_addr[31:13])
|
hit <= #1 1'b1;
|
hit <= #1 1'b1;
|
else
|
else
|
hit <= #1 1'b0;
|
hit <= #1 1'b0;
|
end
|
end
|
|
|
|
//
|
// Valid_div counts RISC clock cycles by modulo 4
|
// Valid_div counts RISC clock cycles by modulo 4
|
|
//
|
always @(posedge clk or posedge rst)
|
always @(posedge clk or posedge rst)
|
if (rst)
|
if (rst)
|
valid_div <= #1 2'b0;
|
valid_div <= #1 2'b0;
|
else
|
else
|
valid_div <= #1 valid_div + 'd1;
|
valid_div <= #1 valid_div + 'd1;
|
|
|
|
//
|
// dcbiu_valid is one RISC clock cycle long dcbiu_rdy.
|
// dcbiu_valid is one RISC clock cycle long dcbiu_rdy.
|
// dcbiu_rdy is two or four RISC clock cycles long because memory
|
// dcbiu_rdy is two or four RISC clock cycles long because memory
|
// controller works at 1/2 or 1/4 of RISC clock freq (at 1/2 if
|
// controller works at 1/2 or 1/4 of RISC clock freq (at 1/2 if
|
// clkdiv_by_2 is asserted).
|
// clkdiv_by_2 is asserted).
|
|
//
|
assign dcbiu_valid = dcbiu_rdy & (valid_div[1] | clkdiv_by_2) & valid_div[0];
|
assign dcbiu_valid = dcbiu_rdy & (valid_div[1] | clkdiv_by_2) & valid_div[0];
|
|
|
|
//
|
// Generate refill_start that signals to frz_logic a cache linefill is about to begin
|
// Generate refill_start that signals to frz_logic a cache linefill is about to begin
|
|
//
|
assign refill_start = (refill_prepare & ~hit) ? 1'b1 : 1'b0;
|
assign refill_start = (refill_prepare & ~hit) ? 1'b1 : 1'b0;
|
|
|
dtlb dtlb(
|
//
|
.clk(clk),
|
// Instantiation of DC Finite State Machine
|
.rst(rst),
|
//
|
.we(1'b0),
|
|
.tlb_en(1'b1),
|
|
.datain(dclsu_datain),
|
|
.vaddr(saved_addr),
|
|
.paddr(),
|
|
.cache_en(),
|
|
.tlb_miss(),
|
|
.tp3w(tp3w),
|
|
.tpdw(tpdw)
|
|
);
|
|
|
|
dc_fsm dc_fsm(
|
dc_fsm dc_fsm(
|
.clk(clk),
|
.clk(clk),
|
.rst(rst),
|
.rst(rst),
|
.lsu_op(dcfsm_lsuop),
|
.lsu_op(dcfsm_lsuop),
|
.miss(~hit),
|
.miss(~hit),
|
Line 221... |
Line 271... |
.biu_write(dcfsm_write),
|
.biu_write(dcfsm_write),
|
.refill_rest(refill_rest),
|
.refill_rest(refill_rest),
|
.cntrbusy(cntrbusy)
|
.cntrbusy(cntrbusy)
|
);
|
);
|
|
|
// Regfile-to-memory aligner
|
//
|
|
// Instantiation of Regfile-to-memory aligner
|
|
//
|
reg2mem reg2mem(
|
reg2mem reg2mem(
|
.addr(dc_addr[1:0]),
|
.addr(dc_addr[1:0]),
|
.lsu_op(dclsu_lsuop),
|
.lsu_op(dclsu_lsuop),
|
.regdata(dclsu_datain),
|
.regdata(dclsu_datain),
|
.memdata(lsu_datain_memaligned)
|
.memdata(lsu_datain_memaligned)
|
);
|
);
|
|
|
|
//
|
|
// Instantiation of DC main memory
|
|
//
|
dc_ram dc_ram(
|
dc_ram dc_ram(
|
.clk(clk),
|
.clk(clk),
|
|
.rst(rst),
|
.addr(dc_addr[12:2]),
|
.addr(dc_addr[12:2]),
|
.we(dcram_we),
|
.we(dcram_we),
|
.datain(to_dcram),
|
.datain(to_dcram),
|
.dataout(from_dcram),
|
.dataout(from_dcram)
|
.tp2w(tp2w),
|
|
.tpdw(tpdw)
|
|
);
|
);
|
|
|
|
//
|
|
// Instantiation of DC TAG memory
|
|
//
|
dc_tag dc_tag(
|
dc_tag dc_tag(
|
.clk(clk),
|
.clk(clk),
|
|
.rst(rst),
|
.addr(dc_addr[12:4]),
|
.addr(dc_addr[12:4]),
|
.we(dctag_we),
|
.we(dctag_we),
|
.datain(dc_addr[31:13]),
|
.datain(dc_addr[31:13]),
|
.dataout(tag),
|
.dataout(tag)
|
.tp2w(tp2w),
|
|
.tpdw(tpdw)
|
|
);
|
);
|
|
|
// Memory-to-regfile aligner
|
//
|
|
// Instatiation of Memory-to-regfile aligner
|
|
//
|
mem2reg mem2reg(
|
mem2reg mem2reg(
|
.addr(mem2reg_addr[1:0]),
|
.addr(mem2reg_addr[1:0]),
|
.lsu_op(dclsu_lsuop),
|
.lsu_op(dclsu_lsuop),
|
.memdata(to_mem2reg),
|
.memdata(to_mem2reg),
|
.regdata(dclsu_dataout)
|
.regdata(dclsu_dataout)
|